@@ -48,7 +48,8 @@ void DurabilityActiveStreamTest::setUp(bool startCheckpointProcessorTask) {
4848
4949 // Enable SyncReplication and flow-control (Producer BufferLog)
5050 setupProducer ({{" enable_synchronous_replication" , " true" },
51- {" connection_buffer_size" , " 52428800" }},
51+ {" connection_buffer_size" , " 52428800" },
52+ {" consumer_name" , " test_consumer" }},
5253 startCheckpointProcessorTask);
5354 ASSERT_TRUE (stream->public_supportSyncReplication ());
5455}
@@ -474,7 +475,7 @@ TEST_P(DurabilityActiveStreamTest, RemoveUnknownSeqnoAckAtDestruction) {
474475 // Our topology gives replica name as "replica" an our producer/stream has
475476 // name "test_producer". Simulate a seqno ack by calling the vBucket level
476477 // function.
477- stream->seqnoAck (" test_producer " , 1 );
478+ stream->seqnoAck (producer-> getConsumerName () , 1 );
478479
479480 // An unknown seqno ack should not have committed the item
480481 EXPECT_EQ (0 , vb->getNumItems ());
@@ -487,7 +488,7 @@ TEST_P(DurabilityActiveStreamTest, RemoveUnknownSeqnoAckAtDestruction) {
487488 // connections. We verify that the seqno ack does not exist in the map
488489 // by performing the topology change that would commit the prepare if it
489490 // did.
490- EXPECT_EQ (ENGINE_SUCCESS, stream->seqnoAck (" test_producer " , 1 ));
491+ EXPECT_EQ (ENGINE_SUCCESS, stream->seqnoAck (producer-> getConsumerName () , 1 ));
491492
492493 // If the seqno ack still existed in the queuedSeqnoAcks map then it would
493494 // result in a commit on topology change
@@ -496,11 +497,60 @@ TEST_P(DurabilityActiveStreamTest, RemoveUnknownSeqnoAckAtDestruction) {
496497 vbucket_state_active,
497498 {{" topology" ,
498499 nlohmann::json::array (
499- {{" active" , " replica1" , " test_producer " }})}});
500+ {{" active" , " replica1" , producer-> getConsumerName () }})}});
500501
501502 EXPECT_EQ (0 , vb->getNumItems ());
502503}
503504
505+ TEST_P (DurabilityActiveStreamTest, RemoveCorrectQueuedAckAtStreamSetDead) {
506+ auto vb = engine->getVBucket (vbid);
507+
508+ const auto key = makeStoredDocKey (" key" );
509+ const auto & value = " value" ;
510+ auto item = makePendingItem (
511+ key,
512+ value,
513+ cb::durability::Requirements (cb::durability::Level::Majority,
514+ 1 /* timeout*/ ));
515+ VBQueueItemCtx ctx;
516+ ctx.durability =
517+ DurabilityItemCtx{item->getDurabilityReqs (), nullptr /* cookie*/ };
518+
519+ EXPECT_EQ (MutationStatus::WasClean, public_processSet (*vb, *item, ctx));
520+ flushVBucketToDiskIfPersistent (vbid, 1 );
521+
522+ // We don't include prepares in the numItems stat (should not exist in here)
523+ EXPECT_EQ (0 , vb->getNumItems ());
524+
525+ // Our topology gives replica name as "replica" an our producer/stream has
526+ // name "test_producer". Simulate a seqno ack by calling the vBucket level
527+ // function.
528+ stream->seqnoAck (producer->getConsumerName (), 1 );
529+
530+ // Disconnect the ActiveStream. Should remove the queued seqno ack
531+ stream->setDead (END_STREAM_DISCONNECTED);
532+
533+ stream = std::make_shared<MockActiveStream>(engine.get (),
534+ producer,
535+ 0 /* flags*/ ,
536+ 0 /* opaque*/ ,
537+ *vb,
538+ 0 /* st_seqno*/ ,
539+ ~0 /* en_seqno*/ ,
540+ 0x0 /* vb_uuid*/ ,
541+ 0 /* snap_start_seqno*/ ,
542+ ~0 /* snap_end_seqno*/ );
543+ producer->createCheckpointProcessorTask ();
544+ producer->scheduleCheckpointProcessorTask ();
545+ stream->setActive ();
546+
547+ // Should not throw a monotonic exception as the ack should have been
548+ // removed by setDead.
549+ stream->seqnoAck (producer->getConsumerName (), 1 );
550+
551+ producer->cancelCheckpointCreatorTask ();
552+ }
553+
504554void DurabilityActiveStreamTest::setUpSendSetInsteadOfCommitTest () {
505555 auto vb = engine->getVBucket (vbid);
506556
0 commit comments