Skip to content

Commit 2d66a5e

Browse files
committed
Remove CheckpointManager arg from Checkpoint::queueDirty()
Change-Id: Iee5283e66b0d830a1d548db1c4af2beab28b41c9 Reviewed-on: http://review.couchbase.org/c/kv_engine/+/156744 Tested-by: Build Bot <[email protected]> Reviewed-by: Richard de Mellow <[email protected]>
1 parent 4bfcb20 commit 2d66a5e

File tree

3 files changed

+24
-25
lines changed

3 files changed

+24
-25
lines changed

engines/ep/src/checkpoint.cc

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ std::ostream& operator<<(std::ostream& os, const CheckpointCursor& c) {
156156
}
157157

158158
Checkpoint::Checkpoint(
159+
CheckpointManager& manager,
159160
EPStats& st,
160161
uint64_t id,
161162
uint64_t snapStart,
@@ -165,7 +166,8 @@ Checkpoint::Checkpoint(
165166
Vbid vbid,
166167
CheckpointType checkpointType,
167168
const std::function<void(int64_t)>& memOverheadChangedCallback)
168-
: stats(st),
169+
: manager(manager),
170+
stats(st),
169171
checkpointId(id),
170172
snapStartSeqno(snapStart),
171173
snapEndSeqno(snapEnd),
@@ -206,8 +208,7 @@ Checkpoint::~Checkpoint() {
206208
memOverheadChangedCallback(-getMemoryOverhead());
207209
}
208210

209-
QueueDirtyResult Checkpoint::queueDirty(const queued_item& qi,
210-
CheckpointManager* checkpointManager) {
211+
QueueDirtyResult Checkpoint::queueDirty(const queued_item& qi) {
211212
if (getState() != CHECKPOINT_OPEN) {
212213
throw std::logic_error(
213214
"Checkpoint::queueDirty: checkpointState "
@@ -289,7 +290,7 @@ QueueDirtyResult Checkpoint::queueDirty(const queued_item& qi,
289290
// this Checkpoint and see if the existing item for this key is
290291
// to the "left" of the cursor (i.e. has already been
291292
// processed).
292-
for (auto& cursor : checkpointManager->cursors) {
293+
for (auto& cursor : manager.cursors) {
293294
if ((*(cursor.second->currentCheckpoint)).get() != this) {
294295
// Cursor is in another checkpoint, doesn't need
295296
// updating here
@@ -346,20 +347,16 @@ QueueDirtyResult Checkpoint::queueDirty(const queued_item& qi,
346347
// a single item (we de-dupe below). Track this in an
347348
// AggregatedFlushStats in CheckpointManager so that we can
348349
// undo these stat updates if the flush fails.
349-
auto backupPCursor = checkpointManager->cursors.find(
350+
auto backupPCursor = manager.cursors.find(
350351
CheckpointManager::backupPCursorName);
351352

352-
if (backupPCursor == checkpointManager->cursors.end()) {
353+
if (backupPCursor == manager.cursors.end()) {
353354
decrCursorIfSameKey();
354355

355356
// We're not mid-flush, don't need to adjust any stats
356357
continue;
357358
}
358359

359-
// We'd normally use "mutation_id" here which is basically
360-
// the seqno but the backupPCursor may be in a different
361-
// checkpoint and we'd fail a bunch of sanity checks trying
362-
// to read it.
363360
auto backupPCursorSeqno =
364361
(*(*backupPCursor->second).currentPos)
365362
->getBySeqno();
@@ -368,8 +365,8 @@ QueueDirtyResult Checkpoint::queueDirty(const queued_item& qi,
368365
// the stats we'll use the new item and the flush
369366
// will pick up the new item too so we have to match
370367
// the original (oldItem) increment with a decrement
371-
checkpointManager->persistenceFailureStatOvercounts
372-
.accountItem(*oldItem);
368+
manager.persistenceFailureStatOvercounts.accountItem(
369+
*oldItem);
373370
}
374371

375372
decrCursorIfSameKey();
@@ -457,7 +454,7 @@ QueueDirtyResult Checkpoint::queueDirty(const queued_item& qi,
457454
if (qi->getOperation() == queue_op::checkpoint_start ||
458455
qi->getOperation() == queue_op::checkpoint_end ||
459456
qi->getOperation() == queue_op::set_vbucket_state) {
460-
checkpointManager->notifyFlusher();
457+
manager.notifyFlusher();
461458
}
462459

463460
return rv;

engines/ep/src/checkpoint.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,8 @@ class Checkpoint {
398398
friend class CheckpointManagerTestIntrospector;
399399

400400
public:
401-
Checkpoint(EPStats& st,
401+
Checkpoint(CheckpointManager& manager,
402+
EPStats& st,
402403
uint64_t id,
403404
uint64_t snapStart,
404405
uint64_t snapEnd,
@@ -486,12 +487,9 @@ class Checkpoint {
486487
/**
487488
* Queue an item to be written to persistent layer.
488489
* @param item the item to be persisted
489-
* @param checkpointManager the checkpoint manager to which this checkpoint belongs
490-
* @param bySeqno the by sequence number assigned to this mutation
491490
* @return a result indicating the status of the operation.
492491
*/
493-
QueueDirtyResult queueDirty(const queued_item& qi,
494-
CheckpointManager* checkpointManager);
492+
QueueDirtyResult queueDirty(const queued_item& qi);
495493

496494
/**
497495
* @return true if the item can be de-duplicated, false otherwise
@@ -677,6 +675,9 @@ class Checkpoint {
677675
*/
678676
CheckpointIndexKeyType makeIndexKey(const queued_item& item) const;
679677

678+
// Reference to the CheckpointManager that owns this Checkpoint
679+
CheckpointManager& manager;
680+
680681
EPStats& stats;
681682
uint64_t checkpointId;
682683
uint64_t snapStartSeqno;

engines/ep/src/checkpoint_manager.cc

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ void CheckpointManager::addNewCheckpoint_UNLOCKED(
135135
oldOpenCkpt.getHighSeqno());
136136
queued_item qi = createCheckpointItem(
137137
oldOpenCkpt.getId(), vbucketId, queue_op::checkpoint_end);
138-
oldOpenCkpt.queueDirty(qi, this);
138+
oldOpenCkpt.queueDirty(qi);
139139
++numItems;
140140
oldOpenCkpt.setState(CHECKPOINT_CLOSED);
141141

@@ -203,7 +203,8 @@ void CheckpointManager::addOpenCheckpoint(
203203
checkpointList.back()->getState() ==
204204
checkpoint_state::CHECKPOINT_CLOSED);
205205

206-
auto ckpt = std::make_unique<Checkpoint>(stats,
206+
auto ckpt = std::make_unique<Checkpoint>(*this,
207+
stats,
207208
id,
208209
snapStart,
209210
snapEnd,
@@ -217,12 +218,12 @@ void CheckpointManager::addOpenCheckpoint(
217218
// at creation. So, the cursor will point at the first actual non-meta item
218219
// after the first cursor-increment.
219220
queued_item qi = createCheckpointItem(0, Vbid(0xffff), queue_op::empty);
220-
ckpt->queueDirty(qi, this);
221+
ckpt->queueDirty(qi);
221222
// Note: We don't include the empty-item in 'numItems'
222223

223224
// This item represents the start of the new checkpoint
224225
qi = createCheckpointItem(id, vbucketId, queue_op::checkpoint_start);
225-
ckpt->queueDirty(qi, this);
226+
ckpt->queueDirty(qi);
226227
++numItems;
227228

228229
checkpointList.push_back(std::move(ckpt));
@@ -836,7 +837,7 @@ bool CheckpointManager::queueDirty(
836837
}
837838
}
838839

839-
QueueDirtyResult result = openCkpt->queueDirty(qi, this);
840+
QueueDirtyResult result = openCkpt->queueDirty(qi);
840841

841842
if (result.status == QueueDirtyStatus::FailureDuplicateItem) {
842843
// Could not queue into the current checkpoint as it already has a
@@ -857,7 +858,7 @@ bool CheckpointManager::queueDirty(
857858
// Note this uses the lastBySeqno for snapStart / End.
858859
checkOpenCheckpoint_UNLOCKED(lh, /*force*/ true, false);
859860
openCkpt = &getOpenCheckpoint_UNLOCKED(lh);
860-
result = openCkpt->queueDirty(qi, this);
861+
result = openCkpt->queueDirty(qi);
861862
if (result.status != QueueDirtyStatus::SuccessNewItem) {
862863
throw std::logic_error("CheckpointManager::queueDirty(vb:" +
863864
vbucketId.to_string() +
@@ -940,7 +941,7 @@ void CheckpointManager::queueSetVBState(VBucket& vb) {
940941
vbstate.toItem(*item);
941942

942943
auto& openCkpt = getOpenCheckpoint_UNLOCKED(lh);
943-
const auto result = openCkpt.queueDirty(item, this);
944+
const auto result = openCkpt.queueDirty(item);
944945

945946
if (result.status == QueueDirtyStatus::SuccessNewItem) {
946947
++numItems;

0 commit comments

Comments
 (0)