File intermediate buffers should be flushed on all flushes.

This commit is contained in:
Ahmed Yasin Koculu
2022-08-04 00:40:20 +02:00
parent cfaad22e62
commit b2ed7d166c
5 changed files with 13 additions and 13 deletions
@@ -139,7 +139,7 @@ public sealed class CompressedFileRandomAccessDevice : IRandomAccessDevice
CompressedBlockPositions.Add(offset);
CompressedBlockLengths.Add(compressedBytes.Length);
FileStream.Write(compressedBytes);
FileStream.Flush();
FileStream.Flush(true);
DecompressedBlocks.TryRemove(nextBlock.BlockIndex, out _);
++NextBlockIndex;
LastBlockLength = 0;
@@ -219,7 +219,7 @@ public sealed class CompressedFileRandomAccessDevice : IRandomAccessDevice
DecompressedBlocks.Clear();
if (FileStream == null)
return;
FileStream.Flush();
FileStream.Flush(true);
FileStream.Dispose();
FileStream = null;
if (Writable)
@@ -274,7 +274,7 @@ public sealed class CompressedFileRandomAccessDevice : IRandomAccessDevice
}
bw.Write(positions.Count);
bw.Write(offset);
FileStream.Flush();
FileStream.Flush(true);
}
(List<long> positions, List<int> lengths) ReadCompressedBlockPositionsAndLengths()
@@ -46,7 +46,7 @@ public sealed class FileRandomAccessDevice : IRandomAccessDevice
{
var pos = FileStream.Position;
FileStream.Write(bytes);
FileStream.Flush();
FileStream.Flush(true);
return pos;
}
@@ -81,7 +81,7 @@ public sealed class FileRandomAccessDevice : IRandomAccessDevice
{
if (FileStream == null)
return;
FileStream.Flush();
FileStream.Flush(true);
FileStream.Dispose();
FileStream = null;
if (Writable)
+1 -1
View File
@@ -160,7 +160,7 @@ public sealed class CompressedFileStream : Stream, IDisposable
BinaryChunkWriter.Write(tailBlock.Length);
var bytes = tailBlock.GetBytes(0, tailBlock.Length);
BinaryChunkWriter.Write(bytes);
TailStream.Flush();
TailStream.Flush(true);
LastWrittenTailIndex = tailBlock.BlockIndex;
LastWrittenTailLength = tailBlock.Length;
}
+2 -2
View File
@@ -133,7 +133,7 @@ public sealed class FileSystemWriteAheadLog<TKey, TValue> : IWriteAheadLog<TKey,
private void Flush()
{
if (FileStream.CanWrite)
FileStream.Flush();
FileStream.Flush(true);
}
public long ReplaceWriteAheadLog(TKey[] keys, TValue[] values, bool disableBackup)
@@ -147,7 +147,7 @@ public sealed class FileSystemWriteAheadLog<TKey, TValue> : IWriteAheadLog<TKey,
FilePath + ".full",
() =>
{
FileStream.Flush();
FileStream.Flush(true);
FileStream.Seek(0, SeekOrigin.Begin);
var existingLength = (int)FileStream.Length;
var bytes = new byte[existingLength];
+5 -5
View File
@@ -51,7 +51,7 @@ public static class IncrementalLogAppender
fs.Write(BitConverter.GetBytes(fs.Length));
fs.Write(BitConverter.GetBytes(fs.Length));
fs.Write(BitConverter.GetBytes(fs.Length));
fs.Flush();
fs.Flush(true);
}
// first append the additional data.
@@ -59,17 +59,17 @@ public static class IncrementalLogAppender
fs.Seek(0, SeekOrigin.End);
fs.Write(bytes);
fs.Flush();
fs.Flush(true);
// now write the file length-stamps.
// what happens if a crash happens with partial write of the fs Length?
// To prevent that, we write and flush the length-stamp three times with separate flushes..
fs.Position = 0;
fs.Write(BitConverter.GetBytes(fs.Length));
fs.Flush();
fs.Flush(true);
fs.Write(BitConverter.GetBytes(fs.Length));
fs.Flush();
fs.Flush(true);
fs.Write(BitConverter.GetBytes(fs.Length));
fs.Flush();
fs.Flush(true);
}
}