Skip to content

Commit 5cf6c45

Browse files
BenHuddlestonowend74
authored andcommitted
MB-47604: Move VBucket (in-mem) purgeSeqno update to PurgedItemContext
Add a new PurgedItemContext (MagmaImplicitCompactionPurgedItemContext) so that we can pull out the implicit compaction specific logic to update the VBucket purge seqno from compactionCore and instead update it via purgedItem/updateRollbackPurgeSeqno. Change-Id: Ie3b280ced3583f830e68366c8eb6e3d7b4b03bf6 Reviewed-on: http://review.couchbase.org/c/kv_engine/+/163189 Tested-by: Build Bot <[email protected]> Reviewed-by: Dave Rigby <[email protected]>
1 parent 907ce59 commit 5cf6c45

File tree

2 files changed

+40
-10
lines changed

2 files changed

+40
-10
lines changed

engines/ep/src/kvstore/magma-kvstore/magma-kvstore.cc

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,11 @@ bool MagmaKVStore::compactionCallBack(MagmaKVStore::MagmaCompactionCB& cbCtx,
299299
}
300300
cbCtx.ctx = makeImplicitCompactionContext(vbid);
301301
cbCtx.implicitCompaction = true;
302-
cbCtx.setCtxPurgedItemCtx();
302+
cbCtx.ctx->purgedItemCtx->rollbackPurgeSeqnoCtx =
303+
std::make_unique<MagmaImplicitCompactionPurgedItemContext>(
304+
cbCtx.ctx->getRollbackPurgeSeqno(),
305+
cbCtx.magmaDbStats,
306+
cbCtx.ctx->maybeUpdateVBucketPurgeSeqno);
303307
}
304308
return compactionCore(
305309
cbCtx, keySlice, metaSlice, valueSlice, userSanitizedItemStr);
@@ -318,13 +322,6 @@ bool MagmaKVStore::compactionCore(MagmaKVStore::MagmaCompactionCB& cbCtx,
318322
auto seqno = magmakv::getSeqNum(metaSlice);
319323
auto exptime = magmakv::getExpiryTime(metaSlice);
320324

321-
// function to update the purge seqno when we're dropping a document if this
322-
// method is being called for implicit compaction
323-
auto maybeUpdatePurgeSeqno = [&cbCtx, &seqno]() -> void {
324-
if (cbCtx.implicitCompaction) {
325-
cbCtx.ctx->maybeUpdateVBucketPurgeSeqno(seqno);
326-
}
327-
};
328325
auto vbid = cbCtx.vbid;
329326
if (cbCtx.ctx->droppedKeyCb) {
330327
// We need to check both committed and prepared documents - if the
@@ -407,7 +404,6 @@ bool MagmaKVStore::compactionCore(MagmaKVStore::MagmaCompactionCB& cbCtx,
407404

408405
if (drop) {
409406
cbCtx.ctx->stats.tombstonesPurged++;
410-
maybeUpdatePurgeSeqno();
411407
cbCtx.ctx->purgedItemCtx->purgedItem(PurgedItemType::Tombstone,
412408
seqno);
413409
return true;

engines/ep/src/kvstore/magma-kvstore/magma-kvstore_rollback_purge_seqno_ctx.h

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,38 @@ class MagmaRollbackPurgeSeqnoCtx : public RollbackPurgeSeqnoCtx {
3939

4040
protected:
4141
MagmaDbStats& dbStats;
42-
};
42+
};
43+
44+
/**
45+
* Magma implicit compaction specific update function for the rollback purge
46+
* seqno. See also MagmaRollbackPurgeSeqnoCtx and CompactionContext.
47+
*
48+
* Explicit compactions updated the in memory purge seqno at the end of a
49+
* compaction. This purge seqno is used to turn away DcpConsumers that have
50+
* fallen too far behind before we open the file to scan. Implicit compaction
51+
* is driven entirely by magma though and does not have a corresponding
52+
* completion callback. Instead, implicit compaction moves the in memory
53+
* vBucket purge seqno whenever we move the rollbackPurgeSeqno. This class
54+
* encapsulates the logic to perform the in memory update whenever we update the
55+
* rollbackPurgeSeqno.
56+
*/
57+
class MagmaImplicitCompactionPurgedItemContext
58+
: public MagmaRollbackPurgeSeqnoCtx {
59+
public:
60+
MagmaImplicitCompactionPurgedItemContext(
61+
uint64_t purgeSeqno,
62+
MagmaDbStats& dbStats,
63+
std::function<void(uint64_t)>& maybeUpdateVBucketPurgeSeqno)
64+
: MagmaRollbackPurgeSeqnoCtx(purgeSeqno, dbStats),
65+
maybeUpdateVBucketPurgeSeqno(maybeUpdateVBucketPurgeSeqno) {
66+
}
67+
68+
void updateRollbackPurgeSeqno(uint64_t seqno) override {
69+
MagmaRollbackPurgeSeqnoCtx::updateRollbackPurgeSeqno(seqno);
70+
71+
maybeUpdateVBucketPurgeSeqno(seqno);
72+
}
73+
74+
protected:
75+
std::function<void(uint64_t)>& maybeUpdateVBucketPurgeSeqno;
76+
};

0 commit comments

Comments
 (0)