Skip to content

Commit f4982c3

Browse files
manudhundidaverigby
authored andcommitted
MB-29381: Allow DCP rollback on vbuckets in pending state
We currently allow rollbacks on only replica vbuckets. This was added recently (on 4.6.0 with http://review.couchbase.org/#/c/69725). But during vbucket move, the new master is initially created in pending state, items streamed over from old master and finally a takeover stream is created. If there is a rollback during the takeover, then we should still allow it on the vbucket which in the pending state. (Backport of MB-26037 / commit 496d9b9). Change-Id: Ie57aed02d574be7b8a3852da5a948ef688676770 Reviewed-on: http://review.couchbase.org/93110 Well-Formed: Build Bot <[email protected]> Reviewed-by: Paolo Cocchi <[email protected]> Reviewed-by: Trond Norbye <[email protected]> Tested-by: Build Bot <[email protected]>
1 parent 3102e46 commit f4982c3

File tree

2 files changed

+26
-13
lines changed

2 files changed

+26
-13
lines changed

src/ep.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4008,7 +4008,8 @@ TaskStatus EventuallyPersistentStore::rollback(uint16_t vbid,
40084008
}
40094009

40104010
ReaderLockHolder rlh(vb->getStateLock());
4011-
if (vb->getState() == vbucket_state_replica) {
4011+
if ((vb->getState() == vbucket_state_replica) ||
4012+
(vb->getState() == vbucket_state_pending)) {
40124013
uint64_t prevHighSeqno =
40134014
static_cast<uint64_t>(vb->checkpointManager.getHighSeqno());
40144015
if (rollbackSeqno != 0) {

tests/module_tests/evp_store_rollback_test.cc

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,17 @@
2424
#include "programs/engine_testapp/mock_server.h"
2525

2626
class RollbackTest : public EventuallyPersistentStoreTest,
27-
public ::testing::WithParamInterface<std::string>
27+
public ::testing::WithParamInterface<
28+
std::tuple<std::string, std::string>>
2829
{
2930
void SetUp() override {
3031
EventuallyPersistentStoreTest::SetUp();
32+
if (std::get<1>(GetParam()) == "pending") {
33+
vbStateAtRollback = vbucket_state_pending;
34+
} else {
35+
vbStateAtRollback = vbucket_state_replica;
36+
}
37+
3138
// Start vbucket as active to allow us to store items directly to it.
3239
store->setVBucketState(vbid, vbucket_state_active, false);
3340

@@ -86,11 +93,11 @@ class RollbackTest : public EventuallyPersistentStoreTest,
8693

8794
// Test - rollback to seqno of item_v1 and verify that the previous value
8895
// of the item has been restored.
89-
store->setVBucketState(vbid, vbucket_state_replica, false);
96+
store->setVBucketState(vbid, vbStateAtRollback, false);
9097
ASSERT_EQ(TaskStatus::Complete,
9198
store->rollback(vbid, item_v1.getBySeqno()));
9299
auto result = store->public_getInternal(a, vbid, /*cookie*/nullptr,
93-
vbucket_state_replica, {});
100+
vbStateAtRollback, {});
94101
ASSERT_EQ(ENGINE_SUCCESS, result.getStatus());
95102
EXPECT_EQ(item_v1, *result.getValue())
96103
<< "Fetched item after rollback should match item_v1";
@@ -122,7 +129,7 @@ class RollbackTest : public EventuallyPersistentStoreTest,
122129

123130
// Test - rollback to seqno of item_v1 and verify that the previous value
124131
// of the item has been restored.
125-
store->setVBucketState(vbid, vbucket_state_replica, false);
132+
store->setVBucketState(vbid, vbStateAtRollback, false);
126133
ASSERT_EQ(TaskStatus::Complete,
127134
store->rollback(vbid, item_v1.getBySeqno()));
128135
ASSERT_EQ(item_v1.getBySeqno(), store->getVBucket(vbid)->getHighSeqno());
@@ -182,7 +189,7 @@ class RollbackTest : public EventuallyPersistentStoreTest,
182189

183190

184191
// Rollback should succeed, but rollback to 0
185-
store->setVBucketState(vbid, vbucket_state_replica, false);
192+
store->setVBucketState(vbid, vbStateAtRollback, false);
186193
EXPECT_EQ(TaskStatus::Complete, store->rollback(vbid, rollback));
187194

188195
// These keys should be gone after the rollback
@@ -208,6 +215,7 @@ class RollbackTest : public EventuallyPersistentStoreTest,
208215

209216
protected:
210217
int64_t initial_seqno;
218+
vbucket_state_t vbStateAtRollback;
211219
};
212220

213221
TEST_P(RollbackTest, RollbackAfterMutation) {
@@ -259,7 +267,7 @@ TEST_P(RollbackTest, RollbackToMiddleOfAnUnPersistedSnapshot) {
259267
auto item_v2 = store_item(vbid, "rollback-cp-2", "gone");
260268

261269
/* do rollback */
262-
store->setVBucketState(vbid, vbucket_state_replica, false);
270+
store->setVBucketState(vbid, vbStateAtRollback, false);
263271
EXPECT_EQ(TaskStatus::Complete, store->rollback(vbid, rollbackReqSeqno));
264272

265273
/* confirm that we have rolled back to the disk snapshot */
@@ -333,10 +341,14 @@ TEST_P(RollbackTest, RollbackOnActive) {
333341
EXPECT_EQ(TaskStatus::Abort, store->rollback(vbid, 0 /*rollbackReqSeqno*/));
334342
}
335343

336-
// Test cases which run in both Full and Value eviction
337-
INSTANTIATE_TEST_CASE_P(FullAndValueEviction,
344+
static auto allConfigValues = ::testing::Values(
345+
std::make_tuple(std::string("value_only"), std::string("replica")),
346+
std::make_tuple(std::string("full_eviction"), std::string("replica")),
347+
std::make_tuple(std::string("value_only"), std::string("pending")),
348+
std::make_tuple(std::string("full_eviction"), std::string("pending")));
349+
350+
// Test cases which run in both Full and Value eviction on replica and pending
351+
// vbucket states
352+
INSTANTIATE_TEST_CASE_P(FullAndValueEvictionOnReplicaAndPending,
338353
RollbackTest,
339-
::testing::Values("value_only", "full_eviction"),
340-
[] (const ::testing::TestParamInfo<std::string>& info) {
341-
return info.param;
342-
});
354+
allConfigValues, );

0 commit comments

Comments
 (0)