Skip to content

Commit e96a9f5

Browse files
jameseh96daverigby
authored andcommitted
MB-43028: [1/2] Make overhead tracking safe at VBucket destruction
Cherry-picks http://review.couchbase.org/c/kv_engine/+/141492 Note: This patch is cherry-picked as the issue it resolves prevents clean forward-merging of a change _earlier_ in mad-hatter history. Merging http://review.couchbase.org/c/kv_engine/+/136495 into master uncovered santizer issues (mad-hatter CV runs an older Clang and did not identify these issues). This patch resolves one of these issues, before the above patch may be merged to master. WARNING: ThreadSanitizer: heap-use-after-free (pid=73551) Read of size 8 at 0x7b5800000310 by main thread: #0 operator() ../kv_engine/engines/ep/src/ephemeral_bucket.cc:301 (libep.so+0x00000034705f) #1 std::_Function_handler<void (long), EphemeralBucket::makeVBucket(...>::_M_invoke(std::_Any_data const&, long&&) #3 ~Checkpoint ../kv_engine/engines/ep/src/checkpoint.cc:228 (libep.so+0x00000019dc97) #10 ~CheckpointManager ../kv_engine/engines/ep/src/checkpoint_manager.h:73 (libep.so+0x00000042f782) ... #13 ~VBucket ../kv_engine/engines/ep/src/vbucket.cc:286 (libep.so+0x00000041689a) During VBucket destruction, the CheckpointManager member, and any remaining Checkpoints it holds are destroyed. This can trigger the memOverheadChangedCallback, as destroying Checkpoints reduces the memory overhead. This was unsafe, as the state member had already been destroyed as it is declared later in VBucket. Move the CheckpointManager to be declared after state, so it is destroyed first. Change-Id: I0a34d3a11cd053f18f3168d6fbbb9dc974bbd2fc Reviewed-on: http://review.couchbase.org/c/kv_engine/+/141492 Reviewed-by: Dave Rigby <[email protected]> Tested-by: Build Bot <[email protected]> Well-Formed: Build Bot <[email protected]> Reviewed-on: http://review.couchbase.org/c/kv_engine/+/141498
1 parent 02c3f75 commit e96a9f5

File tree

2 files changed

+17
-11
lines changed

2 files changed

+17
-11
lines changed

engines/ep/src/vbucket.cc

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -190,14 +190,6 @@ VBucket::VBucket(Vbid i,
190190
const nlohmann::json* replTopology,
191191
uint64_t maxVisibleSeqno)
192192
: ht(st, std::move(valFact), config.getHtSize(), config.getHtLocks()),
193-
checkpointManager(std::make_unique<CheckpointManager>(st,
194-
i,
195-
chkConfig,
196-
lastSeqno,
197-
lastSnapStart,
198-
lastSnapEnd,
199-
maxVisibleSeqno,
200-
flusherCb)),
201193
failovers(std::move(table)),
202194
opsCreate(0),
203195
opsDelete(0),
@@ -220,6 +212,14 @@ VBucket::VBucket(Vbid i,
220212
id(i),
221213
state(newState),
222214
initialState(initState),
215+
checkpointManager(std::make_unique<CheckpointManager>(st,
216+
i,
217+
chkConfig,
218+
lastSeqno,
219+
lastSnapStart,
220+
lastSnapEnd,
221+
maxVisibleSeqno,
222+
flusherCb)),
223223
replicationTopology(std::make_unique<nlohmann::json>()),
224224
purge_seqno(purgeSeqno),
225225
takeover_backed_up(false),

engines/ep/src/vbucket.h

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -837,9 +837,6 @@ class VBucket : public std::enable_shared_from_this<VBucket> {
837837

838838
HashTable ht;
839839

840-
/// Manager of this vBucket's checkpoints. unique_ptr for pimpl.
841-
std::unique_ptr<CheckpointManager> checkpointManager;
842-
843840
/**
844841
* Searches for a 'valid' StoredValue in the VBucket.
845842
*
@@ -2442,6 +2439,15 @@ class VBucket : public std::enable_shared_from_this<VBucket> {
24422439

24432440
vbucket_state_t initialState;
24442441

2442+
public:
2443+
/**
2444+
* Manager of this vBucket's checkpoints. unique_ptr for pimpl.
2445+
* Declared after state as Checkpoint destruction may update stats
2446+
* based on the vbucket's current state.
2447+
*/
2448+
std::unique_ptr<CheckpointManager> checkpointManager;
2449+
2450+
private:
24452451
/**
24462452
* The replication topology, set as part of SET_VBUCKET_STATE.
24472453
* It is encoded as nlohmann::json array of (max 2) replication chains.

0 commit comments

Comments
 (0)