Skip to content

Commit

Permalink
remove targetVersion from checkpoint API, versions always progress by 1.
Browse files Browse the repository at this point in the history
  • Loading branch information
badrishc committed Mar 9, 2025
1 parent af870fb commit 2bccee7
Show file tree
Hide file tree
Showing 15 changed files with 87 additions and 114 deletions.
12 changes: 6 additions & 6 deletions libs/server/StoreWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -842,8 +842,8 @@ private async Task InitiateCheckpoint(bool full, CheckpointType checkpointType,
if (full)
{
sm = objectStore == null ?
Checkpoint.Full(store, checkpointType, -1, out checkpointResult.token) :
Checkpoint.Full(store, objectStore, checkpointType, -1, out checkpointResult.token);
Checkpoint.Full(store, checkpointType, out checkpointResult.token) :
Checkpoint.Full(store, objectStore, checkpointType, out checkpointResult.token);
}
else
{
Expand All @@ -854,14 +854,14 @@ private async Task InitiateCheckpoint(bool full, CheckpointType checkpointType,
if (tryIncremental)
{
sm = objectStore == null ?
Checkpoint.IncrementalHybridLogOnly(store, -1, checkpointResult.token) :
Checkpoint.IncrementalHybridLogOnly(store, objectStore, -1, checkpointResult.token);
Checkpoint.IncrementalHybridLogOnly(store, checkpointResult.token) :
Checkpoint.IncrementalHybridLogOnly(store, objectStore, checkpointResult.token);
}
else
{
sm = objectStore == null ?
Checkpoint.HybridLogOnly(store, checkpointType, -1, out checkpointResult.token) :
Checkpoint.HybridLogOnly(store, objectStore, checkpointType, -1, out checkpointResult.token);
Checkpoint.HybridLogOnly(store, checkpointType, out checkpointResult.token) :
Checkpoint.HybridLogOnly(store, objectStore, checkpointType, out checkpointResult.token);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ public interface IStreamingSnapshotIteratorFunctions<TKey, TValue>
/// <summary>Iteration is starting.</summary>
/// <param name="checkpointToken">Checkpoint token</param>
/// <param name="currentVersion">Current version of database</param>
/// <param name="targetVersion">Target version of database</param>
/// <param name="nextVersion">Next version of database</param>
/// <returns>True to continue iteration, else false</returns>
bool OnStart(Guid checkpointToken, long currentVersion, long targetVersion);
bool OnStart(Guid checkpointToken, long currentVersion, long nextVersion);

/// <summary>Next record in the streaming snapshot.</summary>
/// <param name="key">Reference to the current record's key</param>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace Tsavorite.core
public static class Checkpoint
{
#region Single-store APIs
public static IStateMachine Full<TKey, TValue, TStoreFunctions, TAllocator>(TsavoriteKV<TKey, TValue, TStoreFunctions, TAllocator> store, CheckpointType checkpointType, long targetVersion, out Guid guid)
public static IStateMachine Full<TKey, TValue, TStoreFunctions, TAllocator>(TsavoriteKV<TKey, TValue, TStoreFunctions, TAllocator> store, CheckpointType checkpointType, out Guid guid)
where TStoreFunctions : IStoreFunctions<TKey, TValue>
where TAllocator : IAllocator<TKey, TValue, TStoreFunctions>
{
Expand All @@ -18,44 +18,38 @@ public static IStateMachine Full<TKey, TValue, TStoreFunctions, TAllocator>(Tsav
if (checkpointType == CheckpointType.FoldOver)
{
var backend = new FoldOverSMTask<TKey, TValue, TStoreFunctions, TAllocator>(store, guid);
return new FullCheckpointSM(targetVersion, indexCheckpointTask, backend);
return new FullCheckpointSM(indexCheckpointTask, backend);
}
else if (checkpointType == CheckpointType.Snapshot)
{
var backend = new SnapshotCheckpointSMTask<TKey, TValue, TStoreFunctions, TAllocator>(store, guid);
return new FullCheckpointSM(targetVersion, indexCheckpointTask, backend);
return new FullCheckpointSM(indexCheckpointTask, backend);
}
else
{
throw new TsavoriteException("Invalid checkpoint type");
}
}

public static IStateMachine Streaming<TKey1, TValue1, TStoreFunctions1, TAllocator1, TKey2, TValue2, TStoreFunctions2, TAllocator2>(
TsavoriteKV<TKey1, TValue1, TStoreFunctions1, TAllocator1> store1,
TsavoriteKV<TKey2, TValue2, TStoreFunctions2, TAllocator2> store2,
long targetVersion, out Guid guid)
where TStoreFunctions1 : IStoreFunctions<TKey1, TValue1>
where TAllocator1 : IAllocator<TKey1, TValue1, TStoreFunctions1>
where TStoreFunctions2 : IStoreFunctions<TKey2, TValue2>
where TAllocator2 : IAllocator<TKey2, TValue2, TStoreFunctions2>
public static IStateMachine Streaming<TKey, TValue, TStoreFunctions, TAllocator>(TsavoriteKV<TKey, TValue, TStoreFunctions, TAllocator> store, out Guid guid)
where TStoreFunctions : IStoreFunctions<TKey, TValue>
where TAllocator : IAllocator<TKey, TValue, TStoreFunctions>
{
guid = Guid.NewGuid();
var backend1 = new StreamingSnapshotCheckpointSMTask<TKey1, TValue1, TStoreFunctions1, TAllocator1>(targetVersion, store1, guid);
var backend2 = new StreamingSnapshotCheckpointSMTask<TKey2, TValue2, TStoreFunctions2, TAllocator2>(targetVersion, store2, guid);
return new StreamingSnapshotCheckpointSM(targetVersion, backend1, backend2);
var backend = new StreamingSnapshotCheckpointSMTask<TKey, TValue, TStoreFunctions, TAllocator>(store, guid);
return new StreamingSnapshotCheckpointSM(backend);
}

public static IStateMachine IndexOnly<TKey, TValue, TStoreFunctions, TAllocator>(TsavoriteKV<TKey, TValue, TStoreFunctions, TAllocator> store, long targetVersion, out Guid guid)
public static IStateMachine IndexOnly<TKey, TValue, TStoreFunctions, TAllocator>(TsavoriteKV<TKey, TValue, TStoreFunctions, TAllocator> store, out Guid guid)
where TStoreFunctions : IStoreFunctions<TKey, TValue>
where TAllocator : IAllocator<TKey, TValue, TStoreFunctions>
{
guid = Guid.NewGuid();
var indexCheckpointTask = new IndexCheckpointSMTask<TKey, TValue, TStoreFunctions, TAllocator>(store, guid);
return new IndexCheckpointSM(targetVersion, indexCheckpointTask);
return new IndexCheckpointSM(indexCheckpointTask);
}

public static IStateMachine HybridLogOnly<TKey, TValue, TStoreFunctions, TAllocator>(TsavoriteKV<TKey, TValue, TStoreFunctions, TAllocator> store, CheckpointType checkpointType, long targetVersion, out Guid guid)
public static IStateMachine HybridLogOnly<TKey, TValue, TStoreFunctions, TAllocator>(TsavoriteKV<TKey, TValue, TStoreFunctions, TAllocator> store, CheckpointType checkpointType, out Guid guid)
where TStoreFunctions : IStoreFunctions<TKey, TValue>
where TAllocator : IAllocator<TKey, TValue, TStoreFunctions>
{
Expand All @@ -64,33 +58,33 @@ public static IStateMachine HybridLogOnly<TKey, TValue, TStoreFunctions, TAlloca
if (checkpointType == CheckpointType.FoldOver)
{
var backend = new FoldOverSMTask<TKey, TValue, TStoreFunctions, TAllocator>(store, guid);
return new HybridLogCheckpointSM(targetVersion, backend);
return new HybridLogCheckpointSM(backend);
}
else if (checkpointType == CheckpointType.Snapshot)
{
var backend = new SnapshotCheckpointSMTask<TKey, TValue, TStoreFunctions, TAllocator>(store, guid);
return new HybridLogCheckpointSM(targetVersion, backend);
return new HybridLogCheckpointSM(backend);
}
else
{
throw new TsavoriteException("Invalid checkpoint type");
}
}

public static IStateMachine IncrementalHybridLogOnly<TKey, TValue, TStoreFunctions, TAllocator>(TsavoriteKV<TKey, TValue, TStoreFunctions, TAllocator> store, long targetVersion, Guid guid)
public static IStateMachine IncrementalHybridLogOnly<TKey, TValue, TStoreFunctions, TAllocator>(TsavoriteKV<TKey, TValue, TStoreFunctions, TAllocator> store, Guid guid)
where TStoreFunctions : IStoreFunctions<TKey, TValue>
where TAllocator : IAllocator<TKey, TValue, TStoreFunctions>
{
var backend = new IncrementalSnapshotCheckpointSMTask<TKey, TValue, TStoreFunctions, TAllocator>(store, guid);
return new HybridLogCheckpointSM(targetVersion, backend);
return new HybridLogCheckpointSM(backend);
}
#endregion

#region Two-store APIs
public static IStateMachine Full<TKey1, TValue1, TStoreFunctions1, TAllocator1, TKey2, TValue2, TStoreFunctions2, TAllocator2>(
TsavoriteKV<TKey1, TValue1, TStoreFunctions1, TAllocator1> store1,
TsavoriteKV<TKey2, TValue2, TStoreFunctions2, TAllocator2> store2,
CheckpointType checkpointType, long targetVersion, out Guid guid)
CheckpointType checkpointType, out Guid guid)
where TStoreFunctions1 : IStoreFunctions<TKey1, TValue1>
where TAllocator1 : IAllocator<TKey1, TValue1, TStoreFunctions1>
where TStoreFunctions2 : IStoreFunctions<TKey2, TValue2>
Expand All @@ -104,33 +98,39 @@ public static IStateMachine Full<TKey1, TValue1, TStoreFunctions1, TAllocator1,
{
var backend1 = new FoldOverSMTask<TKey1, TValue1, TStoreFunctions1, TAllocator1>(store1, guid);
var backend2 = new FoldOverSMTask<TKey2, TValue2, TStoreFunctions2, TAllocator2>(store2, guid);
return new FullCheckpointSM(targetVersion, indexCheckpointTask1, indexCheckpointTask2, backend1, backend2);
return new FullCheckpointSM(indexCheckpointTask1, indexCheckpointTask2, backend1, backend2);
}
else if (checkpointType == CheckpointType.Snapshot)
{
var backend1 = new SnapshotCheckpointSMTask<TKey1, TValue1, TStoreFunctions1, TAllocator1>(store1, guid);
var backend2 = new SnapshotCheckpointSMTask<TKey2, TValue2, TStoreFunctions2, TAllocator2>(store2, guid);
return new FullCheckpointSM(targetVersion, indexCheckpointTask1, indexCheckpointTask2, backend1, backend2);
return new FullCheckpointSM(indexCheckpointTask1, indexCheckpointTask2, backend1, backend2);
}
else
{
throw new TsavoriteException("Invalid checkpoint type");
}
}

public static IStateMachine Streaming<TKey, TValue, TStoreFunctions, TAllocator>(TsavoriteKV<TKey, TValue, TStoreFunctions, TAllocator> store, long targetVersion, out Guid guid)
where TStoreFunctions : IStoreFunctions<TKey, TValue>
where TAllocator : IAllocator<TKey, TValue, TStoreFunctions>
public static IStateMachine Streaming<TKey1, TValue1, TStoreFunctions1, TAllocator1, TKey2, TValue2, TStoreFunctions2, TAllocator2>(
TsavoriteKV<TKey1, TValue1, TStoreFunctions1, TAllocator1> store1,
TsavoriteKV<TKey2, TValue2, TStoreFunctions2, TAllocator2> store2,
out Guid guid)
where TStoreFunctions1 : IStoreFunctions<TKey1, TValue1>
where TAllocator1 : IAllocator<TKey1, TValue1, TStoreFunctions1>
where TStoreFunctions2 : IStoreFunctions<TKey2, TValue2>
where TAllocator2 : IAllocator<TKey2, TValue2, TStoreFunctions2>
{
guid = Guid.NewGuid();
var backend = new StreamingSnapshotCheckpointSMTask<TKey, TValue, TStoreFunctions, TAllocator>(targetVersion, store, guid);
return new StreamingSnapshotCheckpointSM(targetVersion, backend);
var backend1 = new StreamingSnapshotCheckpointSMTask<TKey1, TValue1, TStoreFunctions1, TAllocator1>(store1, guid);
var backend2 = new StreamingSnapshotCheckpointSMTask<TKey2, TValue2, TStoreFunctions2, TAllocator2>(store2, guid);
return new StreamingSnapshotCheckpointSM(backend1, backend2);
}

public static IStateMachine IndexOnly<TKey1, TValue1, TStoreFunctions1, TAllocator1, TKey2, TValue2, TStoreFunctions2, TAllocator2>(
TsavoriteKV<TKey1, TValue1, TStoreFunctions1, TAllocator1> store1,
TsavoriteKV<TKey2, TValue2, TStoreFunctions2, TAllocator2> store2,
long targetVersion, out Guid guid)
out Guid guid)
where TStoreFunctions1 : IStoreFunctions<TKey1, TValue1>
where TAllocator1 : IAllocator<TKey1, TValue1, TStoreFunctions1>
where TStoreFunctions2 : IStoreFunctions<TKey2, TValue2>
Expand All @@ -139,13 +139,13 @@ public static IStateMachine IndexOnly<TKey1, TValue1, TStoreFunctions1, TAllocat
guid = Guid.NewGuid();
var indexCheckpointTask1 = new IndexCheckpointSMTask<TKey1, TValue1, TStoreFunctions1, TAllocator1>(store1, guid);
var indexCheckpointTask2 = new IndexCheckpointSMTask<TKey2, TValue2, TStoreFunctions2, TAllocator2>(store2, guid);
return new IndexCheckpointSM(targetVersion, indexCheckpointTask1, indexCheckpointTask2);
return new IndexCheckpointSM(indexCheckpointTask1, indexCheckpointTask2);
}

public static IStateMachine HybridLogOnly<TKey1, TValue1, TStoreFunctions1, TAllocator1, TKey2, TValue2, TStoreFunctions2, TAllocator2>(
TsavoriteKV<TKey1, TValue1, TStoreFunctions1, TAllocator1> store1,
TsavoriteKV<TKey2, TValue2, TStoreFunctions2, TAllocator2> store2,
CheckpointType checkpointType, long targetVersion, out Guid guid)
CheckpointType checkpointType, out Guid guid)
where TStoreFunctions1 : IStoreFunctions<TKey1, TValue1>
where TAllocator1 : IAllocator<TKey1, TValue1, TStoreFunctions1>
where TStoreFunctions2 : IStoreFunctions<TKey2, TValue2>
Expand All @@ -157,13 +157,13 @@ public static IStateMachine HybridLogOnly<TKey1, TValue1, TStoreFunctions1, TAll
{
var backend1 = new FoldOverSMTask<TKey1, TValue1, TStoreFunctions1, TAllocator1>(store1, guid);
var backend2 = new FoldOverSMTask<TKey2, TValue2, TStoreFunctions2, TAllocator2>(store2, guid);
return new HybridLogCheckpointSM(targetVersion, backend1, backend2);
return new HybridLogCheckpointSM(backend1, backend2);
}
else if (checkpointType == CheckpointType.Snapshot)
{
var backend1 = new SnapshotCheckpointSMTask<TKey1, TValue1, TStoreFunctions1, TAllocator1>(store1, guid);
var backend2 = new SnapshotCheckpointSMTask<TKey2, TValue2, TStoreFunctions2, TAllocator2>(store2, guid);
return new HybridLogCheckpointSM(targetVersion, backend1, backend2);
return new HybridLogCheckpointSM(backend1, backend2);
}
else
{
Expand All @@ -174,15 +174,15 @@ public static IStateMachine HybridLogOnly<TKey1, TValue1, TStoreFunctions1, TAll
public static IStateMachine IncrementalHybridLogOnly<TKey1, TValue1, TStoreFunctions1, TAllocator1, TKey2, TValue2, TStoreFunctions2, TAllocator2>(
TsavoriteKV<TKey1, TValue1, TStoreFunctions1, TAllocator1> store1,
TsavoriteKV<TKey2, TValue2, TStoreFunctions2, TAllocator2> store2,
long targetVersion, Guid guid)
Guid guid)
where TStoreFunctions1 : IStoreFunctions<TKey1, TValue1>
where TAllocator1 : IAllocator<TKey1, TValue1, TStoreFunctions1>
where TStoreFunctions2 : IStoreFunctions<TKey2, TValue2>
where TAllocator2 : IAllocator<TKey2, TValue2, TStoreFunctions2>
{
var backend1 = new IncrementalSnapshotCheckpointSMTask<TKey1, TValue1, TStoreFunctions1, TAllocator1>(store1, guid);
var backend2 = new IncrementalSnapshotCheckpointSMTask<TKey2, TValue2, TStoreFunctions2, TAllocator2>(store2, guid);
return new HybridLogCheckpointSM(targetVersion, backend1, backend2);
return new HybridLogCheckpointSM(backend1, backend2);
}
#endregion
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,11 @@ namespace Tsavorite.core
internal sealed class FullCheckpointSM : HybridLogCheckpointSM
{
/// <summary>
/// Construct a new FullCheckpointStateMachine to use the given set of checkpoint tasks,
/// drawing boundary at targetVersion.
/// Construct a new FullCheckpointStateMachine to use the given set of checkpoint tasks.
/// </summary>
/// <param name="targetVersion">upper limit (inclusive) of the version included</param>
/// <param name="tasks">Tasks</param>
public FullCheckpointSM(long targetVersion = -1, params IStateMachineTask[] tasks)
: base(targetVersion, tasks)
public FullCheckpointSM(params IStateMachineTask[] tasks)
: base(tasks)
{ }

/// <inheritdoc />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@ internal class HybridLogCheckpointSM : VersionChangeSM
/// <summary>
/// Construct a new HybridLogCheckpointStateMachine with the given tasks. Does not load any tasks by default.
/// </summary>
/// <param name="targetVersion">upper limit (inclusive) of the version included</param>
/// <param name="tasks">The tasks to load onto the state machine</param>
public HybridLogCheckpointSM(long targetVersion, params IStateMachineTask[] tasks)
: base(targetVersion, tasks) { }
public HybridLogCheckpointSM(params IStateMachineTask[] tasks)
: base(tasks) { }

/// <inheritdoc />
public override SystemState NextState(SystemState start)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ internal sealed class IndexCheckpointSM : StateMachineBase
/// <summary>
/// Create a new IndexSnapshotStateMachine
/// </summary>
public IndexCheckpointSM(long targetVersion = -1, params IStateMachineTask[] tasks)
: base(targetVersion, tasks)
public IndexCheckpointSM(params IStateMachineTask[] tasks)
: base(tasks)
{
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ internal sealed class IndexResizeSM : StateMachineBase
/// <summary>
/// Constructs a new IndexResizeStateMachine
/// </summary>
public IndexResizeSM(int targetVersion = -1, params IStateMachineTask[] tasks) : base(targetVersion, tasks)
public IndexResizeSM(params IStateMachineTask[] tasks) : base(tasks)
{
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,14 @@ namespace Tsavorite.core
internal abstract class StateMachineBase : IStateMachine
{
readonly IStateMachineTask[] tasks;
protected long toVersion;

/// <summary>
/// Construct a new SynchronizationStateMachine with the given tasks. The order of tasks given is the
/// order they are executed on each state machine.
/// </summary>
/// <param name="toVersion">To version</param>
/// <param name="tasks">The ISynchronizationTasks to run on the state machine</param>
protected StateMachineBase(long toVersion = -1, params IStateMachineTask[] tasks)
protected StateMachineBase(params IStateMachineTask[] tasks)
{
this.toVersion = toVersion;
this.tasks = tasks;
}

Expand Down
Loading

0 comments on commit 2bccee7

Please sign in to comment.