diff --git a/LiteDB/Engine/Disk/DiskService.cs b/LiteDB/Engine/Disk/DiskService.cs index 8d9105d74..594d73d8b 100644 --- a/LiteDB/Engine/Disk/DiskService.cs +++ b/LiteDB/Engine/Disk/DiskService.cs @@ -111,7 +111,7 @@ private void Initialize(Stream stream, Collation collation, long initialSize) stream.SetLength(initialSize); } - stream.FlushToDisk(); + stream.Flush(); } /// @@ -297,7 +297,7 @@ public void Write(IEnumerable pages, FileOrigin origin) stream.Write(page.Array, page.Offset, PAGE_SIZE); } - stream.FlushToDisk(); + stream.Flush(); } /// diff --git a/LiteDB/Engine/Disk/DiskWriterQueue.cs b/LiteDB/Engine/Disk/DiskWriterQueue.cs index ad1933bbb..1117ff3db 100644 --- a/LiteDB/Engine/Disk/DiskWriterQueue.cs +++ b/LiteDB/Engine/Disk/DiskWriterQueue.cs @@ -110,7 +110,7 @@ private void ExecuteQueue() } // after this I will have 100% sure data are safe on log file - _stream.FlushToDisk(); + _stream.Flush(); } catch (IOException) { diff --git a/LiteDB/Engine/Disk/StreamFactory/FileStreamFactory.cs b/LiteDB/Engine/Disk/StreamFactory/FileStreamFactory.cs index d3ae1b3c7..49f0607b4 100644 --- a/LiteDB/Engine/Disk/StreamFactory/FileStreamFactory.cs +++ b/LiteDB/Engine/Disk/StreamFactory/FileStreamFactory.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections; -using System.Collections.Concurrent; -using System.Collections.Generic; -using System.IO; +using System.IO; using static LiteDB.Constants; namespace LiteDB.Engine @@ -41,11 +37,12 @@ public Stream GetStream(bool canWrite, bool sequencial) var isNewFile = write && this.Exists() == false; var stream = new FileStream(_filename, - _readonly ? System.IO.FileMode.Open : System.IO.FileMode.OpenOrCreate, + _readonly ? FileMode.Open : FileMode.OpenOrCreate, write ? FileAccess.ReadWrite : FileAccess.Read, write ? FileShare.Read : FileShare.ReadWrite, PAGE_SIZE, - sequencial ? FileOptions.SequentialScan : FileOptions.RandomAccess); + // FILE_FLAG_NO_BUFFERING = 0x20000000 + (sequencial ? FileOptions.SequentialScan : FileOptions.RandomAccess) | FileOptions.WriteThrough | (FileOptions)0x20000000); if (isNewFile && _hidden) { diff --git a/LiteDB/Engine/Disk/Streams/AesStream.cs b/LiteDB/Engine/Disk/Streams/AesStream.cs index d0b2fcb75..b1c20304b 100644 --- a/LiteDB/Engine/Disk/Streams/AesStream.cs +++ b/LiteDB/Engine/Disk/Streams/AesStream.cs @@ -121,7 +121,7 @@ public AesStream(string password, Stream stream) } _stream.Position = PAGE_SIZE; - _stream.FlushToDisk(); + _stream.Flush(); using (var ms = new MemoryStream(new byte[16])) using (var tempStream = new CryptoStream(ms, _decryptor, CryptoStreamMode.Read)) diff --git a/LiteDB/Utils/Extensions/StreamExtensions.cs b/LiteDB/Utils/Extensions/StreamExtensions.cs deleted file mode 100644 index 3b037e6e6..000000000 --- a/LiteDB/Utils/Extensions/StreamExtensions.cs +++ /dev/null @@ -1,24 +0,0 @@ -using System; -using System.IO; -using static LiteDB.Constants; - -namespace LiteDB -{ - internal static class StreamExtensions - { - /// - /// If Stream are FileStream, flush content direct to disk (avoid OS cache) - /// - public static void FlushToDisk(this Stream stream) - { - if (stream is FileStream fstream) - { - fstream.Flush(true); - } - else - { - stream.Flush(); - } - } - } -} \ No newline at end of file