Skip to content

Commit 44428db

Browse files
authored
Fix to delta log for recovery (#856)
* 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.
1 parent 979beeb commit 44428db

File tree

4 files changed

+20
-7
lines changed

4 files changed

+20
-7
lines changed

cs/src/core/FasterLog/FasterLog.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2072,8 +2072,13 @@ private void UpdateCommittedState(FasterLogRecoveryInfo recoveryInfo)
20722072
private void WriteCommitMetadata(FasterLogRecoveryInfo recoveryInfo)
20732073
{
20742074
// TODO: can change to write this in separate thread for fast commit
2075+
2076+
// If we are in fast-commit, we may not write every metadata to disk. However, when we are deleting files
2077+
// on disk, we have to write metadata for the new start location on disk so we know where to scan forward from.
2078+
bool forceWriteMetadata = fastCommitMode && (allocator.BeginAddress < recoveryInfo.BeginAddress);
20752079
logCommitManager.Commit(recoveryInfo.BeginAddress, recoveryInfo.UntilAddress,
2076-
recoveryInfo.ToByteArray(), recoveryInfo.CommitNum);
2080+
recoveryInfo.ToByteArray(), recoveryInfo.CommitNum, forceWriteMetadata);
2081+
20772082
// If not fast committing, set committed state as we commit metadata explicitly only after metadata commit
20782083
if (!fastCommitMode)
20792084
UpdateCommittedState(recoveryInfo);

cs/src/core/FasterLog/ILogCommitManager.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ public interface ILogCommitManager : IDisposable
1919
/// <param name="untilAddress">Address committed until (for information only, not necessary to persist)</param>
2020
/// <param name="commitMetadata">Commit metadata - should be persisted</param>
2121
/// <param name="commitNum">commit num</param>
22-
void Commit(long beginAddress, long untilAddress, byte[] commitMetadata, long commitNum);
22+
/// <param name="forceWriteMetadata">force writing of metadata in case of fast commit</param>
23+
void Commit(long beginAddress, long untilAddress, byte[] commitMetadata, long commitNum, bool forceWriteMetadata);
2324

2425
/// <summary>
2526
/// Return commit metadata

cs/src/core/Index/CheckpointManagement/DeviceLogCommitCheckpointManager.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,9 @@ public DeviceLogCommitCheckpointManager(INamedDeviceFactory deviceFactory, strin
109109
#region ILogCommitManager
110110

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

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

cs/src/core/Index/Recovery/DeltaLog.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -228,8 +228,15 @@ public unsafe bool GetNext(out long physicalAddress, out int entryLength, out De
228228

229229
if (entryLength == 0)
230230
{
231+
if (_currentOffset == 0)
232+
{
233+
// We found a hole at beginning of page, this must imply end of delta log
234+
return false;
235+
}
236+
237+
// Hole at end of page, skip to next page
231238
currentAddress = (1 + (currentAddress >> LogPageSizeBits)) << LogPageSizeBits;
232-
if (Utility.MonotonicUpdate(ref nextAddress, currentAddress, out _))
239+
if (!Utility.MonotonicUpdate(ref nextAddress, currentAddress, out _))
233240
return false;
234241
else
235242
continue;
@@ -239,7 +246,7 @@ public unsafe bool GetNext(out long physicalAddress, out int entryLength, out De
239246
if (entryLength < 0 || (_currentOffset + recordSize > PageSize))
240247
{
241248
currentAddress = (1 + (currentAddress >> LogPageSizeBits)) << LogPageSizeBits;
242-
if (Utility.MonotonicUpdate(ref nextAddress, currentAddress, out _))
249+
if (!Utility.MonotonicUpdate(ref nextAddress, currentAddress, out _))
243250
return false;
244251
else
245252
continue;
@@ -249,7 +256,7 @@ public unsafe bool GetNext(out long physicalAddress, out int entryLength, out De
249256
if (!VerifyBlockChecksum((byte*)physicalAddress, entryLength))
250257
{
251258
currentAddress = (1 + (currentAddress >> LogPageSizeBits)) << LogPageSizeBits;
252-
if (Utility.MonotonicUpdate(ref nextAddress, currentAddress, out _))
259+
if (!Utility.MonotonicUpdate(ref nextAddress, currentAddress, out _))
253260
return false;
254261
else
255262
continue;

0 commit comments

Comments
 (0)