Skip to content

Commit

Permalink
Added flushing OS cache to medium
Browse files Browse the repository at this point in the history
  • Loading branch information
mkosieradzki committed Apr 20, 2017
1 parent 66578aa commit 5ae23c2
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 0 deletions.
14 changes: 14 additions & 0 deletions LiteDB/Engine/Disks/FileDiskService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,10 @@ public void WriteJournal(ICollection<byte[]> pages)
_journal.Write(buffer, 0, BasePage.PAGE_SIZE);
}

#if !NET35
_journal.Flush(true);
#endif

// journal file will be unlocked only in ClearJournal
}

Expand Down Expand Up @@ -267,6 +271,16 @@ public IEnumerable<byte[]> ReadJournal()
_journal.TryUnlock(0, 1);
}

/// <summary>
/// Ensures all pages from the OS cache are persisted on medium
/// </summary>
public void Flush()
{
#if !NET35
_stream.Flush(true);
#endif
}

/// <summary>
/// Clear journal file (set size to 0 length)
/// </summary>
Expand Down
5 changes: 5 additions & 0 deletions LiteDB/Engine/Disks/IDiskService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ public interface IDiskService : IDisposable
/// </summary>
void ClearJournal();

/// <summary>
/// Ensures all pages from the OS cache are persisted on medium
/// </summary>
void Flush();

/// <summary>
/// Lock datafile returning lock position
/// </summary>
Expand Down
7 changes: 7 additions & 0 deletions LiteDB/Engine/Disks/StreamDiskService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,13 @@ public void Unlock(LockState state)
{
}

/// <summary>
/// No flush implemented
/// </summary>
public void Flush()
{
}

#endregion

}
Expand Down
3 changes: 3 additions & 0 deletions LiteDB/Engine/Services/TransactionService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ public void Commit()
// mark all dirty pages in clean pages (all are persisted in disk and are valid pages)
_cache.MarkDirtyAsClean();

// ensure all pages from OS cache has been persisted on medium
_disk.Flush();

// discard journal file
_disk.ClearJournal();
}
Expand Down

0 comments on commit 5ae23c2

Please sign in to comment.