mirror of
https://github.com/ZoneTree/ZoneTree.git
synced 2026-10-20 15:51:49 +08:00
File intermediate buffers should be flushed on all flushes.
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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];
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user