Skip to content

Commit d6df83b

Browse files
committed
MB-41407: [BP] Do not use old StoredValue after soft delete
Backport of http://review.couchbase.org/c/kv_engine/+/139274 . Fixes tsan-identified race between EphemeralVBucket::pageOut and EphemeralVBucket::StaleItemDeleter immediately deleting the newly stale item. softDeleteStoredValue may lead to the existing item being marked stale. At this point, is is no longer safe to use the old stored value, as the StaleItemDeleter may delete it at any time. Change-Id: I89101bb26dec6ae99b58f7b4df3e1203cdb7b8d9 Reviewed-on: http://review.couchbase.org/c/kv_engine/+/141012 Tested-by: Build Bot <[email protected]> Reviewed-by: Dave Rigby <[email protected]> Well-Formed: Build Bot <[email protected]>
1 parent 1ae8f00 commit d6df83b

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

engines/ep/src/ephemeral_vb.cc

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,20 +107,24 @@ bool EphemeralVBucket::pageOut(
107107
if (!eligibleToPageOut(lh, *v)) {
108108
return false;
109109
}
110+
auto cid = v->getKey().getCollectionID();
110111
VBQueueItemCtx queueCtx;
111112
v->setRevSeqno(v->getRevSeqno() + 1);
112-
StoredValue* newSv;
113113
DeletionStatus status;
114114
VBNotifyCtx notifyCtx;
115-
std::tie(newSv, status, notifyCtx) = softDeleteStoredValue(
115+
// After soft delete it is no longer safe to manipulate v the original
116+
// StoredValue v.
117+
// If v was made stale (because a range lock covers it) it may be
118+
// deleted at any time. Only the new SV ptr which has been returned should
119+
// be handled now.
120+
std::tie(v, status, notifyCtx) = softDeleteStoredValue(
116121
lh, *v, /*onlyMarkDeleted*/ false, queueCtx, 0);
117122

118123
switch (status) {
119124
case DeletionStatus::Success:
120-
ht.updateMaxDeletedRevSeqno(newSv->getRevSeqno());
125+
ht.updateMaxDeletedRevSeqno(v->getRevSeqno());
121126
notifyNewSeqno(notifyCtx);
122-
doCollectionsStats(readHandle, v->getKey().getCollectionID(),
123-
notifyCtx);
127+
doCollectionsStats(readHandle, cid, notifyCtx);
124128
autoDeleteCount++;
125129
return true;
126130

0 commit comments

Comments
 (0)