Skip to content

Commit 83f12ac

Browse files
committed
Modify Checkpoint state so it can only be closed
Modify Checkpoint of checkpoint.h to replace Checkpoint::setState() with Checkpoint::close(), so that we can never update a checkpoint from the closed state to the open state. Once a checkpoint has been marked closed it should be immutable. Change-Id: Ic0cae1e850205c73a768e3f8db87234e433706e0 Reviewed-on: https://review.couchbase.org/c/kv_engine/+/172723 Tested-by: Build Bot <[email protected]> Reviewed-by: Paolo Cocchi <[email protected]>
1 parent 9454c3c commit 83f12ac

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

engines/ep/src/checkpoint.h

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -335,11 +335,16 @@ class Checkpoint {
335335
}
336336

337337
/**
338-
* Set the current state of this checkpoint.
339-
* @param state the checkpoint's new state
340-
*/
341-
void setState(checkpoint_state state) {
342-
*checkpointState.wlock() = state;
338+
* Set the current state of this checkpoint to closed.
339+
*/
340+
void close() {
341+
auto& state = *checkpointState.wlock();
342+
if (state == checkpoint_state::CHECKPOINT_CLOSED) {
343+
throw std::logic_error(
344+
"Checkpoint::close() can't close a closed "
345+
"checkpoint!");
346+
}
347+
state = checkpoint_state::CHECKPOINT_CLOSED;
343348
}
344349

345350
void incNumOfCursorsInCheckpoint() {

engines/ep/src/checkpoint_manager.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ void CheckpointManager::addNewCheckpoint(
153153
oldOpenCkpt.getId(), vb.getId(), queue_op::checkpoint_end);
154154
oldOpenCkpt.queueDirty(qi);
155155
++numItems;
156-
oldOpenCkpt.setState(CHECKPOINT_CLOSED);
156+
oldOpenCkpt.close();
157157

158158
addOpenCheckpoint(snapStartSeqno,
159159
snapEndSeqno,

0 commit comments

Comments
 (0)