Skip to content

Commit

Permalink
Fix to delta log for recovery (#856)
Browse files Browse the repository at this point in the history
* Fix to delta log for recovery
* If we are in fast-commit, we may not write every metadata to disk. However, when we are deleting files on disk, we have to write metadata for the new start location on disk so we know where to scan forward from.
  • Loading branch information
badrishc authored Aug 2, 2023
1 parent 979beeb commit 44428db
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 7 deletions.
7 changes: 6 additions & 1 deletion cs/src/core/FasterLog/FasterLog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2072,8 +2072,13 @@ private void UpdateCommittedState(FasterLogRecoveryInfo recoveryInfo)
private void WriteCommitMetadata(FasterLogRecoveryInfo recoveryInfo)
{
// TODO: can change to write this in separate thread for fast commit

// If we are in fast-commit, we may not write every metadata to disk. However, when we are deleting files
// on disk, we have to write metadata for the new start location on disk so we know where to scan forward from.
bool forceWriteMetadata = fastCommitMode && (allocator.BeginAddress < recoveryInfo.BeginAddress);
logCommitManager.Commit(recoveryInfo.BeginAddress, recoveryInfo.UntilAddress,
recoveryInfo.ToByteArray(), recoveryInfo.CommitNum);
recoveryInfo.ToByteArray(), recoveryInfo.CommitNum, forceWriteMetadata);

// If not fast committing, set committed state as we commit metadata explicitly only after metadata commit
if (!fastCommitMode)
UpdateCommittedState(recoveryInfo);
Expand Down
3 changes: 2 additions & 1 deletion cs/src/core/FasterLog/ILogCommitManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ public interface ILogCommitManager : IDisposable
/// <param name="untilAddress">Address committed until (for information only, not necessary to persist)</param>
/// <param name="commitMetadata">Commit metadata - should be persisted</param>
/// <param name="commitNum">commit num</param>
void Commit(long beginAddress, long untilAddress, byte[] commitMetadata, long commitNum);
/// <param name="forceWriteMetadata">force writing of metadata in case of fast commit</param>
void Commit(long beginAddress, long untilAddress, byte[] commitMetadata, long commitNum, bool forceWriteMetadata);

/// <summary>
/// Return commit metadata
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,9 @@ public DeviceLogCommitCheckpointManager(INamedDeviceFactory deviceFactory, strin
#region ILogCommitManager

/// <inheritdoc />
public unsafe void Commit(long beginAddress, long untilAddress, byte[] commitMetadata, long commitNum)
public unsafe void Commit(long beginAddress, long untilAddress, byte[] commitMetadata, long commitNum, bool forceWriteMetadata)
{
if (fastCommitThrottleFreq > 0 && (commitCount++ % fastCommitThrottleFreq != 0)) return;
if (!forceWriteMetadata && fastCommitThrottleFreq > 0 && (commitCount++ % fastCommitThrottleFreq != 0)) return;

using var device = deviceFactory.Get(checkpointNamingScheme.FasterLogCommitMetadata(commitNum));

Expand Down
13 changes: 10 additions & 3 deletions cs/src/core/Index/Recovery/DeltaLog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,15 @@ public unsafe bool GetNext(out long physicalAddress, out int entryLength, out De

if (entryLength == 0)
{
if (_currentOffset == 0)
{
// We found a hole at beginning of page, this must imply end of delta log
return false;
}

// Hole at end of page, skip to next page
currentAddress = (1 + (currentAddress >> LogPageSizeBits)) << LogPageSizeBits;
if (Utility.MonotonicUpdate(ref nextAddress, currentAddress, out _))
if (!Utility.MonotonicUpdate(ref nextAddress, currentAddress, out _))
return false;
else
continue;
Expand All @@ -239,7 +246,7 @@ public unsafe bool GetNext(out long physicalAddress, out int entryLength, out De
if (entryLength < 0 || (_currentOffset + recordSize > PageSize))
{
currentAddress = (1 + (currentAddress >> LogPageSizeBits)) << LogPageSizeBits;
if (Utility.MonotonicUpdate(ref nextAddress, currentAddress, out _))
if (!Utility.MonotonicUpdate(ref nextAddress, currentAddress, out _))
return false;
else
continue;
Expand All @@ -249,7 +256,7 @@ public unsafe bool GetNext(out long physicalAddress, out int entryLength, out De
if (!VerifyBlockChecksum((byte*)physicalAddress, entryLength))
{
currentAddress = (1 + (currentAddress >> LogPageSizeBits)) << LogPageSizeBits;
if (Utility.MonotonicUpdate(ref nextAddress, currentAddress, out _))
if (!Utility.MonotonicUpdate(ref nextAddress, currentAddress, out _))
return false;
else
continue;
Expand Down

0 comments on commit 44428db

Please sign in to comment.