Skip to content

Commit

Permalink
Prevents indexing of WAL files
Browse files Browse the repository at this point in the history
  • Loading branch information
sakno committed Feb 14, 2024
1 parent 5b65018 commit b288ab1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -218,17 +218,9 @@ public void Format(Span<byte> output)
}
}

private sealed class VersionedFileReader : FileReader
private sealed class VersionedFileReader(SafeFileHandle handle, long fileOffset, int bufferSize, MemoryAllocator<byte> allocator, ulong version) : FileReader(handle, fileOffset, bufferSize, allocator)
{
private long version;

internal VersionedFileReader(SafeFileHandle handle, long fileOffset, int bufferSize, MemoryAllocator<byte> allocator, long version)
: base(handle, fileOffset, bufferSize, allocator)
{
this.version = version;
}

internal void VerifyVersion(long expected)
internal void VerifyVersion(ulong expected)
{
if (version != expected)
Reset();
Expand All @@ -251,7 +243,7 @@ internal abstract class ConcurrentStorageAccess : Disposable
private VersionedFileReader?[] readers;

// This field is used to control 'freshness' of the read buffers
private long version; // volatile
private ulong version; // volatile

private protected ConcurrentStorageAccess(string fileName, int fileOffset, int bufferSize, MemoryAllocator<byte> allocator, int readersCount, WriteMode writeMode, long initialSize)
{
Expand All @@ -273,14 +265,18 @@ private protected ConcurrentStorageAccess(string fileName, int fileOffset, int b

Handle = File.OpenHandle(fileName, fileMode, FileAccess.ReadWrite, FileShare.Read, options, initialSize);

if (fileMode is FileMode.CreateNew)
{
File.SetAttributes(Handle, FileAttributes.NotContentIndexed);
}

this.fileOffset = fileOffset;
writer = new(Handle, fileOffset, bufferSize, allocator);
readers = new VersionedFileReader[readersCount];
this.allocator = allocator;
FileName = fileName;
version = long.MinValue;

if (readersCount is 1)
if (readers.Length is 1)
readers[0] = new(Handle, fileOffset, bufferSize, allocator, version);

autoFlush = writeMode is WriteMode.AutoFlush;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
namespace DotNext.Net.Cluster.Consensus.Raft;

using Buffers;
using Threading;
using BoxedClusterMemberId = Runtime.BoxedValue<ClusterMemberId>;
using IntegrityException = IO.Log.IntegrityException;

Expand Down Expand Up @@ -68,9 +67,19 @@ private NodeState(string fileName, MemoryAllocator<byte> allocator, bool integri
{
handle = File.OpenHandle(fileName, FileMode.CreateNew, FileAccess.Write, FileShare.None, FileOptions.WriteThrough, Capacity);
buffer.Span.Clear();

FileAttributes attributes;
if (integrityCheck)
{
attributes = FileAttributes.NotContentIndexed | FileAttributes.IntegrityStream;
WriteInt64LittleEndian(Checksum, Hash(Data));
}
else
{
attributes = FileAttributes.NotContentIndexed;
}

File.SetAttributes(handle, attributes);
RandomAccess.Write(handle, buffer.Span, 0L);
}

Expand Down

0 comments on commit b288ab1

Please sign in to comment.