Skip to content

Commit 4667e6f

Browse files
committed
MB-48841: completeCompactionExpiryBgFetch must check vbstate
Any expiry bgfetch must not be applied unless the vbucket is active. Change-Id: Icc188e54005ebb7d2235fcb735f6fc1e68b7ed9a Reviewed-on: http://review.couchbase.org/c/kv_engine/+/163662 Tested-by: Build Bot <[email protected]> Reviewed-by: Dave Rigby <[email protected]>
1 parent 102910e commit 4667e6f

File tree

3 files changed

+45
-18
lines changed

3 files changed

+45
-18
lines changed

engines/ep/src/ep_vb.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,10 @@ void EPVBucket::completeCompactionExpiryBgFetch(
242242
{ // locking scope
243243
auto docKey = key.getDocKey();
244244
folly::SharedMutex::ReadHolder rlh(getStateLock());
245+
if (getState() != vbucket_state_active) {
246+
return;
247+
}
248+
245249
auto cHandle = lockCollections(docKey);
246250
if (!cHandle.valid()) {
247251
return;

engines/ep/tests/module_tests/evp_store_test.cc

Lines changed: 39 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -677,7 +677,7 @@ TEST_P(EPBucketFullEvictionTest, ExpiryFindNonResidentItem) {
677677
}
678678

679679
void EPBucketFullEvictionTest::compactionFindsNonResidentItem(
680-
bool dropCollection) {
680+
bool dropCollection, bool switchToReplica) {
681681
EXPECT_EQ(cb::engine_errc::success,
682682
store->setVBucketState(vbid, vbucket_state_active, {}));
683683

@@ -723,34 +723,56 @@ void EPBucketFullEvictionTest::compactionFindsNonResidentItem(
723723
// We should have queued a BGFetch for the item
724724
EXPECT_EQ(1, vb->getNumItems());
725725
ASSERT_TRUE(vb->hasPendingBGFetchItems());
726+
727+
auto highSeqno = vb->getHighSeqno();
728+
if (switchToReplica) {
729+
EXPECT_EQ(cb::engine_errc::success,
730+
store->setVBucketState(vbid, vbucket_state_replica, {}));
731+
}
732+
726733
runBGFetcherTask();
727-
EXPECT_FALSE(vb->hasPendingBGFetchItems());
728734

729-
// We should have expired the item
730-
EXPECT_EQ(expectedExpiredItems, vb->numExpiredItems);
735+
if (!switchToReplica) {
736+
EXPECT_FALSE(vb->hasPendingBGFetchItems());
731737

732-
// But it still exists on disk until we flush
733-
EXPECT_EQ(1, vb->getNumItems());
738+
// We should have expired the item
739+
EXPECT_EQ(expectedExpiredItems, vb->numExpiredItems);
734740

735-
auto expectedItems = 0;
736-
if (isRocksDB() || dropCollection) {
737-
// RocksDB doesn't know if we insert or update so item counts are not
738-
// correct.
739-
// Or if we drop the collection, no expiry. Item count won't be updated
740-
// until collections are purged, so 1 is correct.
741-
expectedItems = 1;
741+
// But it still exists on disk until we flush
742+
EXPECT_EQ(1, vb->getNumItems());
743+
744+
auto expectedItems = 0;
745+
if (isRocksDB() || dropCollection) {
746+
// RocksDB doesn't know if we insert or update so item counts are
747+
// not correct. Or if we drop the collection, no expiry. Item count
748+
// won't be updated until collections are purged, so 1 is correct.
749+
expectedItems = 1;
750+
if (dropCollection) {
751+
EXPECT_EQ(highSeqno, vb->getHighSeqno());
752+
}
753+
} else {
754+
EXPECT_LT(highSeqno, vb->getHighSeqno());
755+
flushVBucketToDiskIfPersistent(vbid, 1);
756+
}
757+
EXPECT_EQ(expectedItems, vb->getNumItems());
742758
} else {
743-
flushVBucketToDiskIfPersistent(vbid, 1);
759+
EXPECT_EQ(0, vb->numExpiredItems);
760+
EXPECT_EQ(highSeqno, vb->getHighSeqno());
744761
}
745-
EXPECT_EQ(expectedItems, vb->getNumItems());
746762
}
747763

748764
TEST_P(EPBucketFullEvictionTest, CompactionFindsNonResidentItem) {
749-
compactionFindsNonResidentItem(false);
765+
compactionFindsNonResidentItem(false, false);
750766
}
751767

752768
TEST_P(EPBucketFullEvictionTest, MB_42295_dropCollectionBeforeExpiry) {
753-
compactionFindsNonResidentItem(true);
769+
compactionFindsNonResidentItem(true, false);
770+
}
771+
772+
TEST_P(EPBucketFullEvictionTest, MB_48841_switchToReplica) {
773+
// Test will switch from active to replica, bgfetch runs whilst replica and
774+
// all pending expiries must not take affect.
775+
compactionFindsNonResidentItem(false, true);
754776
}
755777

756778
/**

engines/ep/tests/module_tests/evp_store_test.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ class EPBucketTest : public STParameterizedBucketTest {
3333
// Full eviction only tests
3434
class EPBucketFullEvictionTest : public EPBucketTest {
3535
public:
36-
void compactionFindsNonResidentItem(bool dropCollection);
36+
void compactionFindsNonResidentItem(bool dropCollection,
37+
bool switchToReplica);
3738
};
3839

3940
// Full eviction only tests that run with bloom filters off

0 commit comments

Comments
 (0)