@@ -1573,6 +1573,94 @@ TEST_P(STEphemeralItemPagerTest, ReplicaNotPaged) {
15731573 }
15741574}
15751575
1576+ /* *
1577+ * Test fixture for Ephemeral item pager tests with
1578+ * ephemeral_full_policy=auto_delete.
1579+ */
1580+ class STEphemeralAutoDeleteItemPagerTest : public STItemPagerTest {};
1581+
1582+ // Test covers MB-60046. A pending and committed key must not find itself auto
1583+ // deleted, else the delete of the commit will be rejected by the DCP replica
1584+ // and cause disconnects.
1585+ TEST_P (STEphemeralAutoDeleteItemPagerTest, MB_60046) {
1586+ setVBucketState (
1587+ vbid,
1588+ vbucket_state_active,
1589+ {{" topology" , nlohmann::json::array ({{" active" , " replica" }})}});
1590+
1591+ auto setActive = [this ](int count) {
1592+ auto item =
1593+ make_item (vbid,
1594+ makeStoredDocKey (" active_" + std::to_string (count)),
1595+ std::string (512 , ' V' ));
1596+ item.setFreqCounterValue (0 );
1597+ storeItem (item);
1598+ };
1599+
1600+ int count = 0 ;
1601+ do {
1602+ setActive (++count);
1603+ } while (store->getPageableMemCurrent () <
1604+ store->getPageableMemHighWatermark ());
1605+
1606+ auto key = makeStoredDocKey (" active_" + std::to_string (count));
1607+ // Now make the last key written in the loop also pending.
1608+ ASSERT_EQ (cb::engine_errc::would_block,
1609+ storeItem (*makePendingItem (key, " pending-value" )));
1610+
1611+ std::vector<queued_item> items;
1612+ auto & vb = *store->getVBucket (vbid);
1613+ auto cursor = vb.checkpointManager ->registerCursorBySeqno (
1614+ " test" , 1 , CheckpointCursor::Droppable::No);
1615+ ASSERT_FALSE (cursor.tryBackfill ) << *vb.checkpointManager ;
1616+ vb.checkpointManager ->getNextItemsForCursor (cursor.cursor .lock ().get (),
1617+ items);
1618+ EXPECT_NE (0 , items.size ()) << *vb.checkpointManager ;
1619+ bool pendingFound{false };
1620+ bool committedFound{false };
1621+ for (const auto & item : items) {
1622+ if (item->getKey () == key) {
1623+ if (item->isPending ()) {
1624+ ASSERT_FALSE (pendingFound);
1625+ pendingFound = true ;
1626+ } else {
1627+ ASSERT_FALSE (committedFound);
1628+ committedFound = true ;
1629+ }
1630+ }
1631+ }
1632+
1633+ // Both pending and committed must be seen before we trigger auto-delete
1634+ ASSERT_TRUE (pendingFound);
1635+ ASSERT_TRUE (committedFound);
1636+ items.clear ();
1637+
1638+ // Now trigger the auto-delete paging
1639+ runHighMemoryPager ();
1640+
1641+ // Iterate through the checkpoint and check all deletes.
1642+ vb.checkpointManager ->getNextItemsForCursor (cursor.cursor .lock ().get (),
1643+ items);
1644+ // Should be some new mutations (deletes)
1645+ EXPECT_NE (0 , items.size ()) << *vb.checkpointManager ;
1646+
1647+ int deleteCount{0 };
1648+ for (const auto & item : items) {
1649+ if (item->getKey () == key) {
1650+ // The key should not be found in the new batch of items. The
1651+ // original commit+pending were in the first batch and not expected
1652+ // to see again. Prior to the fix, a delete(key) was seen here.
1653+ FAIL () << *item;
1654+ }
1655+ if (item->isDeleted ()) {
1656+ ++deleteCount;
1657+ }
1658+ }
1659+
1660+ // We certainly should see deletes.
1661+ ASSERT_NE (0 , deleteCount);
1662+ }
1663+
15761664/* *
15771665 * Test fixture for expiry pager tests - enables the Expiry Pager (in addition
15781666 * to what the parent class does).
@@ -2685,6 +2773,11 @@ INSTANTIATE_TEST_SUITE_P(PersistentFullValue,
26852773 STParameterizedBucketTest::persistentConfigValues (),
26862774 STParameterizedBucketTest::PrintToStringParamName);
26872775
2776+ INSTANTIATE_TEST_SUITE_P (EphemeralAutoDelete,
2777+ STEphemeralAutoDeleteItemPagerTest,
2778+ STParameterizedBucketTest::ephAutoDeleteConfigValues (),
2779+ STParameterizedBucketTest::PrintToStringParamName);
2780+
26882781#else
26892782GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST (STItemPagerTest);
26902783GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST (MultiPagingVisitorTest);
@@ -2694,4 +2787,6 @@ GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(STValueEvictionExpiryPagerTest);
26942787GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST (MB_32669);
26952788GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST (STEphemeralItemPagerTest);
26962789GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST (MB_36087);
2790+ GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST (
2791+ STEphemeralAutoDeleteItemPagerTest);
26972792#endif
0 commit comments