diff --git a/LiteDB/Engine/Disks/FileDiskService.cs b/LiteDB/Engine/Disks/FileDiskService.cs index bcb3ca530..777d8ab93 100644 --- a/LiteDB/Engine/Disks/FileDiskService.cs +++ b/LiteDB/Engine/Disks/FileDiskService.cs @@ -208,6 +208,10 @@ public void WriteJournal(ICollection pages) _journal.Write(buffer, 0, BasePage.PAGE_SIZE); } +#if !NET35 + _journal.Flush(true); +#endif + // journal file will be unlocked only in ClearJournal } @@ -267,6 +271,16 @@ public IEnumerable ReadJournal() _journal.TryUnlock(0, 1); } + /// + /// Ensures all pages from the OS cache are persisted on medium + /// + public void Flush() + { +#if !NET35 + _stream.Flush(true); +#endif + } + /// /// Clear journal file (set size to 0 length) /// diff --git a/LiteDB/Engine/Disks/IDiskService.cs b/LiteDB/Engine/Disks/IDiskService.cs index cc526a139..f7693a999 100644 --- a/LiteDB/Engine/Disks/IDiskService.cs +++ b/LiteDB/Engine/Disks/IDiskService.cs @@ -51,6 +51,11 @@ public interface IDiskService : IDisposable /// void ClearJournal(); + /// + /// Ensures all pages from the OS cache are persisted on medium + /// + void Flush(); + /// /// Lock datafile returning lock position /// diff --git a/LiteDB/Engine/Disks/StreamDiskService.cs b/LiteDB/Engine/Disks/StreamDiskService.cs index 017838744..ce2b546d7 100644 --- a/LiteDB/Engine/Disks/StreamDiskService.cs +++ b/LiteDB/Engine/Disks/StreamDiskService.cs @@ -149,6 +149,13 @@ public void Unlock(LockState state) { } + /// + /// No flush implemented + /// + public void Flush() + { + } + #endregion } diff --git a/LiteDB/Engine/Services/TransactionService.cs b/LiteDB/Engine/Services/TransactionService.cs index 298c4ae9b..13aef2677 100644 --- a/LiteDB/Engine/Services/TransactionService.cs +++ b/LiteDB/Engine/Services/TransactionService.cs @@ -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(); }