Skip to content

Commit ac72f5f

Browse files
committed
MB-35612: replace needs to check for pending operation
The replace path was missing a check for the key having a pending operation. In the bug report in the case of a sync-delete in progress replace views the StoredValue as deleted and incorrectly returns KEY_ENOENT. Change-Id: I62af9207edf41f77230243c844fcfbc0bf703e25 Reviewed-on: http://review.couchbase.org/113578 Reviewed-by: Dave Rigby <[email protected]> Tested-by: Build Bot <[email protected]>
1 parent cf07104 commit ac72f5f

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

engines/ep/src/vbucket.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1599,6 +1599,10 @@ ENGINE_ERROR_CODE VBucket::replace(
15991599
auto* v = htRes.selectSVToModify(itm);
16001600
auto& hbl = htRes.getHBL();
16011601

1602+
if (v && v->isPending()) {
1603+
return ENGINE_SYNC_WRITE_IN_PROGRESS;
1604+
}
1605+
16021606
if (v && v->isCompleted()) {
16031607
v = nullptr;
16041608
}

engines/ep/tests/module_tests/evp_store_durability_test.cc

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ class DurabilityEPBucketTest : public STParameterizedBucketTest {
171171
void verifyCollectionItemCount(VBucket& vb,
172172
CollectionID cID,
173173
uint64_t expectedValue);
174+
174175
};
175176

176177
/**
@@ -204,6 +205,17 @@ class DurabilityBucketTest : public STParameterizedBucketTest {
204205
*/
205206
void testTakeoverDestinationHandlesPreparedSyncWrites(
206207
cb::durability::Level level);
208+
209+
// Call a number of operations where we expect a sync_write in progress
210+
// error
211+
void checkForSyncWriteInProgess(Item& pendingItem) {
212+
auto* anotherClient = create_mock_cookie();
213+
ASSERT_EQ(ENGINE_SYNC_WRITE_IN_PROGRESS,
214+
store->set(pendingItem, anotherClient, {}));
215+
ASSERT_EQ(ENGINE_SYNC_WRITE_IN_PROGRESS,
216+
store->replace(pendingItem, anotherClient, {}));
217+
destroy_mock_cookie(anotherClient);
218+
}
207219
};
208220

209221
class DurabilityEphemeralBucketTest : public STParameterizedBucketTest {
@@ -625,6 +637,8 @@ TEST_P(DurabilityBucketTest, SyncWriteSyncDelete) {
625637
ENGINE_EWOULDBLOCK,
626638
store->deleteItem(key, cas, vbid, cookie, reqs, nullptr, delInfo));
627639

640+
checkForSyncWriteInProgess(*pending);
641+
628642
EXPECT_EQ(1, vb.getNumItems());
629643
EXPECT_EQ(1, vb.ht.getNumPreparedSyncWrites());
630644

0 commit comments

Comments
 (0)