Skip to content

Commit 3b35805

Browse files
authored
Store delta log tail address (#861)
* Store delta log tail address * fix + comment
1 parent 5bee94b commit 3b35805

File tree

4 files changed

+20
-6
lines changed

4 files changed

+20
-6
lines changed

cs/src/core/Index/Common/Contexts.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,9 @@ public struct HybridLogRecoveryInfo
396396

397397

398398
/// <summary>
399-
/// Tail address of delta file
399+
/// Tail address of delta file: -1 indicates this is not a delta checkpoint metadata
400+
/// At recovery, this value denotes the delta tail address excluding the metadata record for the checkpoint
401+
/// because we create the metadata before writing to the delta file.
400402
/// </summary>
401403
public long deltaTailAddress;
402404

@@ -415,7 +417,7 @@ public void Initialize(Guid token, long _version)
415417
startLogicalAddress = 0;
416418
finalLogicalAddress = 0;
417419
snapshotFinalLogicalAddress = 0;
418-
deltaTailAddress = 0;
420+
deltaTailAddress = -1; // indicates this is not a delta checkpoint metadata
419421
headAddress = 0;
420422

421423
checkpointTokens = new();
@@ -564,6 +566,11 @@ internal void Recover(Guid token, ICheckpointManager checkpointManager, out byte
564566
throw new FasterException("Invalid log commit metadata for ID " + token.ToString());
565567
using StreamReader s = new(new MemoryStream(metadata));
566568
Initialize(s);
569+
if (scanDelta && deltaLog != null && deltaTailAddress >= 0)
570+
{
571+
// Adjust delta tail address to include the metadata record
572+
deltaTailAddress = deltaLog.NextAddress;
573+
}
567574
var cookie = s.ReadToEnd();
568575
commitCookie = cookie.Length == 0 ? null : Convert.FromBase64String(cookie);
569576
}

cs/src/core/Index/Recovery/ICheckpointManager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public interface ICheckpointManager : IDisposable
8686
/// </summary>
8787
/// <param name="logToken">Token</param>
8888
/// <param name="deltaLog">Delta log</param>
89-
/// <param name="scanDelta"> whether or not to scan through the delta log to acquire latest entry</param>
89+
/// <param name="scanDelta"> whether or not to scan through the delta log to acquire latest entry. make sure the delta log points to the tail address immediately following the returned metadata.</param>
9090
/// <param name="recoverTo"> version upper bound to scan for in the delta log. Function will return the largest version metadata no greater than the given version.</param>
9191
/// <returns>Metadata, or null if invalid</returns>
9292
byte[] GetLogCheckpointMetadata(Guid logToken, DeltaLog deltaLog, bool scanDelta = false, long recoverTo = -1);

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,10 @@ public struct LogFileInfo
150150
/// Hybrid log file end address
151151
/// </summary>
152152
public long hybridLogFileEndAddress;
153+
/// <summary>
154+
/// Delta log tail address
155+
/// </summary>
156+
public long deltaLogTailAddress;
153157
}
154158

155159
public partial class FasterKV<Key, Value> : FasterBase, IFasterKV<Key, Value>
@@ -188,19 +192,21 @@ public long GetLatestCheckpointVersion()
188192
/// Get size of snapshot files for token
189193
/// </summary>
190194
/// <param name="token"></param>
195+
/// <param name="version"></param>
191196
/// <returns></returns>
192-
public LogFileInfo GetLogFileSize(Guid token)
197+
public LogFileInfo GetLogFileSize(Guid token, long version = -1)
193198
{
194199
using var current = new HybridLogCheckpointInfo();
195200
// We find the latest checkpoint metadata for the given token, including scanning the delta log for the latest metadata
196201
current.Recover(token, checkpointManager, hlog.LogPageSizeBits,
197-
out var _, true);
202+
out var _, true, version);
198203
long snapshotDeviceOffset = hlog.GetPage(current.info.snapshotStartFlushedLogicalAddress) << hlog.LogPageSizeBits;
199204
return new LogFileInfo
200205
{
201206
snapshotFileEndAddress = current.info.snapshotFinalLogicalAddress - snapshotDeviceOffset,
202207
hybridLogFileStartAddress = hlog.GetPage(current.info.beginAddress) << hlog.LogPageSizeBits,
203-
hybridLogFileEndAddress = current.info.flushedLogicalAddress
208+
hybridLogFileEndAddress = current.info.flushedLogicalAddress,
209+
deltaLogTailAddress = current.info.deltaTailAddress,
204210
};
205211
}
206212

cs/src/core/Index/Synchronization/HybridLogCheckpointTask.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,7 @@ public override void GlobalBeforeEnteringState<Key, Value>(SystemState next, Fas
346346
break;
347347
case Phase.PERSISTENCE_CALLBACK:
348348
CollectMetadata(next, faster);
349+
faster._hybridLogCheckpoint.info.deltaTailAddress = faster._hybridLogCheckpoint.deltaLog.TailAddress;
349350
faster.WriteHybridLogIncrementalMetaInfo(faster._hybridLogCheckpoint.deltaLog);
350351
faster._hybridLogCheckpoint.info.deltaTailAddress = faster._hybridLogCheckpoint.deltaLog.TailAddress;
351352
faster._lastSnapshotCheckpoint = faster._hybridLogCheckpoint.Transfer();

0 commit comments

Comments
 (0)