Skip to content

Commit

Permalink
Added better exception to detect broken partition
Browse files Browse the repository at this point in the history
  • Loading branch information
sakno committed Jun 9, 2024
1 parent b70aa9b commit 5e3f92e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
2 changes: 2 additions & 0 deletions src/cluster/DotNext.Net.Cluster/ExceptionMessages.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,6 @@ internal static string UnknownRaftMessageType<T>(T messageType)
internal static string LogEntryPayloadTooLarge => (string)Resources.Get();

internal static string SparseFileNotSupported => (string)Resources.Get();

internal static string InvalidPartitionFormat => (string)Resources.Get();
}
3 changes: 2 additions & 1 deletion src/cluster/DotNext.Net.Cluster/ExceptionMessages.restext
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ UnknownRaftMessageType=Unknown Raft message type {0}
PersistentStateBroken=Internal state of the WAL didn't pass the integrity check
ConcurrentMembershipUpdate=Cluster membership cannot be modified concurrently
LogEntryPayloadTooLarge=The size of the log entry is larger than specified threshold
SparseFileNotSupported=TAR archive doesn't support sparse files on the target platform
SparseFileNotSupported=TAR archive doesn't support sparse files on the target platform
InvalidPartitionFormat=Partition has invalid binary format or broken
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,8 @@ internal override void Initialize()
{
using var handle = File.OpenHandle(FileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite, FileOptions.SequentialScan);

long fileOffset;

// read header
if (RandomAccess.Read(Handle, header.Span, fileOffset: 0L) < HeaderSize)
{
Expand All @@ -516,14 +518,18 @@ internal override void Initialize()
else if (IsSealed)
{
// partition is completed, read table
var tableStart = RandomAccess.GetLength(Handle);
RandomAccess.Read(Handle, footer.Span, tableStart - footer.Length);
fileOffset = RandomAccess.GetLength(Handle);

if (fileOffset < footer.Length + HeaderSize)
throw new IntegrityException(ExceptionMessages.InvalidPartitionFormat);

fileOffset -= footer.Length;
RandomAccess.Read(Handle, footer.Span, fileOffset);
}
else
{
// read sequentially every log entry
int footerOffset;
long fileOffset;

if (PartitionNumber is 0L)
{
Expand Down

0 comments on commit 5e3f92e

Please sign in to comment.