From fa30cf8a6ecc08f60f508f7ca5c67aac424ce4f5 Mon Sep 17 00:00:00 2001 From: Badrish Chandramouli Date: Thu, 9 Jul 2020 11:12:04 -0700 Subject: [PATCH 1/2] Allow checkpoint type to be chosen per instantiation --- cs/src/core/Index/Common/Contexts.cs | 26 +++++----- cs/src/core/Index/FASTER/FASTER.cs | 48 +++++++++++++++++++ .../FullCheckpointStateMachine.cs | 6 +-- .../HybridLogCheckpointTask.cs | 3 +- .../IndexSnapshotStateMachine.cs | 7 ++- 5 files changed, 67 insertions(+), 23 deletions(-) diff --git a/cs/src/core/Index/Common/Contexts.cs b/cs/src/core/Index/Common/Contexts.cs index 03630ad72..2849b6fb5 100644 --- a/cs/src/core/Index/Common/Contexts.cs +++ b/cs/src/core/Index/Common/Contexts.cs @@ -293,14 +293,6 @@ internal void Recover(Guid token, ICheckpointManager checkpointManager) Initialize(s); } - /// - /// Reset - /// - public void Reset() - { - Initialize(default, -1); - } - /// /// Write info to byte array /// @@ -369,29 +361,30 @@ internal struct HybridLogCheckpointInfo public IDevice snapshotFileDevice; public IDevice snapshotFileObjectLogDevice; public SemaphoreSlim flushedSemaphore; - public long started; public void Initialize(Guid token, int _version, ICheckpointManager checkpointManager) { info.Initialize(token, _version); - started = 0; checkpointManager.InitializeLogCheckpoint(token); } public void Recover(Guid token, ICheckpointManager checkpointManager) { info.Recover(token, checkpointManager); - started = 0; } public void Reset() { - started = 0; flushedSemaphore = null; - info.Reset(); + info = default; if (snapshotFileDevice != null) snapshotFileDevice.Close(); if (snapshotFileObjectLogDevice != null) snapshotFileObjectLogDevice.Close(); } + + public bool IsDefault() + { + return info.guid == default; + } } internal struct IndexRecoveryInfo @@ -507,8 +500,13 @@ public void Recover(Guid token, ICheckpointManager checkpointManager) public void Reset() { - info.Reset(); + info = default; main_ht_device.Close(); } + + public bool IsDefault() + { + return info.token == default; + } } } diff --git a/cs/src/core/Index/FASTER/FASTER.cs b/cs/src/core/Index/FASTER/FASTER.cs index 4f7990e02..674a21643 100644 --- a/cs/src/core/Index/FASTER/FASTER.cs +++ b/cs/src/core/Index/FASTER/FASTER.cs @@ -208,6 +208,32 @@ public bool TakeFullCheckpoint(out Guid token, long targetVersion = -1) return result; } + /// + /// Initiate full checkpoint + /// + /// Checkpoint token + /// Checkpoint type + /// upper limit (inclusive) of the version included + /// + /// Whether we successfully initiated the checkpoint (initiation may + /// fail if we are already taking a checkpoint or performing some other + /// operation such as growing the index). + /// + public bool TakeFullCheckpoint(out Guid token, CheckpointType checkpointType, long targetVersion = -1) + { + ISynchronizationTask backend; + if (checkpointType == CheckpointType.FoldOver) + backend = new FoldOverCheckpointTask(); + else if (checkpointType == CheckpointType.Snapshot) + backend = new SnapshotCheckpointTask(); + else + throw new FasterException("Unsupported full checkpoint type"); + + var result = StartStateMachine(new FullCheckpointStateMachine(backend, targetVersion)); + token = _hybridLogCheckpointToken; + return result; + } + /// /// Initiate index checkpoint /// @@ -239,6 +265,28 @@ public bool TakeHybridLogCheckpoint(out Guid token, long targetVersion = -1) return result; } + /// + /// Take incremental hybrid log checkpoint + /// + /// Checkpoint token + /// Checkpoint type + /// upper limit (inclusive) of the version included + /// Whether we could initiate the checkpoint + public bool TakeHybridLogCheckpoint(out Guid token, CheckpointType checkpointType, long targetVersion = -1) + { + ISynchronizationTask backend; + if (checkpointType == CheckpointType.FoldOver) + backend = new FoldOverCheckpointTask(); + else if (checkpointType == CheckpointType.Snapshot) + backend = new SnapshotCheckpointTask(); + else + throw new FasterException("Unsupported checkpoint type"); + + var result = StartStateMachine(new HybridLogCheckpointStateMachine(backend, targetVersion)); + token = _hybridLogCheckpointToken; + return result; + } + /// /// Recover from the latest checkpoints /// diff --git a/cs/src/core/Index/Synchronization/FullCheckpointStateMachine.cs b/cs/src/core/Index/Synchronization/FullCheckpointStateMachine.cs index 90b6f0bc4..720bbce44 100644 --- a/cs/src/core/Index/Synchronization/FullCheckpointStateMachine.cs +++ b/cs/src/core/Index/Synchronization/FullCheckpointStateMachine.cs @@ -21,8 +21,8 @@ public void GlobalBeforeEnteringState(TaskCreationOptions.RunContinuationsAsynchronously); faster.checkpointTcs.SetResult(new LinkedCheckpointInfo { NextTask = nextTcs.Task }); diff --git a/cs/src/core/Index/Synchronization/IndexSnapshotStateMachine.cs b/cs/src/core/Index/Synchronization/IndexSnapshotStateMachine.cs index 65e7f2ae8..04cb6000d 100644 --- a/cs/src/core/Index/Synchronization/IndexSnapshotStateMachine.cs +++ b/cs/src/core/Index/Synchronization/IndexSnapshotStateMachine.cs @@ -21,7 +21,7 @@ public void GlobalBeforeEnteringState Date: Sun, 12 Jul 2020 19:33:07 -0700 Subject: [PATCH 2/2] Add custom checkpoint overloads to legacy API as well. --- cs/src/core/Index/FASTER/FASTERLegacy.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/cs/src/core/Index/FASTER/FASTERLegacy.cs b/cs/src/core/Index/FASTER/FASTERLegacy.cs index ceec88e5f..819f1a456 100644 --- a/cs/src/core/Index/FASTER/FASTERLegacy.cs +++ b/cs/src/core/Index/FASTER/FASTERLegacy.cs @@ -271,12 +271,18 @@ public ClientSession ResumeSessio /// public bool TakeFullCheckpoint(out Guid token, long targetVersion = -1) => _fasterKV.TakeFullCheckpoint(out token, targetVersion); + /// + public bool TakeFullCheckpoint(out Guid token, CheckpointType checkpointType, long targetVersion = -1) => _fasterKV.TakeFullCheckpoint(out token, checkpointType, targetVersion); + /// public bool TakeIndexCheckpoint(out Guid token) => _fasterKV.TakeIndexCheckpoint(out token); /// public bool TakeHybridLogCheckpoint(out Guid token, long targetVersion = -1) => _fasterKV.TakeHybridLogCheckpoint(out token, targetVersion); + /// + public bool TakeHybridLogCheckpoint(out Guid token, CheckpointType checkpointType, long targetVersion = -1) => _fasterKV.TakeHybridLogCheckpoint(out token, checkpointType, targetVersion); + /// public void Recover() => _fasterKV.Recover();