@@ -629,12 +629,14 @@ TEST_P(EPBucketFullEvictionTest, xattrExpiryOnFullyEvictedItem) {
629629}
630630
631631TEST_P (EPBucketFullEvictionTest, GetMultiShouldNotExceedMutationWatermark) {
632- if (!isCouchstore ()) {
632+ // This test relies on precise memory tracking
633+ const auto & stats = engine->getEpStats ();
634+ if (!stats.isMemoryTrackingEnabled ()) {
633635 GTEST_SKIP ();
634636 }
637+
635638 ASSERT_EQ (cb::engine_errc::success,
636639 store->setVBucketState (vbid, vbucket_state_active, {}));
637- const auto & stats = engine->getEpStats ();
638640 EXPECT_LT (stats.getPreciseTotalMemoryUsed (), stats.getMaxDataSize ());
639641
640642 // Load a document of size 1MiB
@@ -662,18 +664,18 @@ TEST_P(EPBucketFullEvictionTest, GetMultiShouldNotExceedMutationWatermark) {
662664 // run bgFetch
663665 runBGFetcherTask ();
664666
665- // BGFetch should fail to allocate memory above bucekt quota (now works for
666- // couch-kvstore), however this still fails for magma
667667 auto vb = store->getVBucket (vbid);
668668 EXPECT_FALSE (vb->hasPendingBGFetchItems ());
669669 EXPECT_LE (stats.getPreciseTotalMemoryUsed (), stats.getMaxDataSize ());
670670}
671671
672672TEST_P (EPBucketFullEvictionTest, BgfetchSucceedsUntilMutationWatermark) {
673- if (!isCouchstore ()) {
673+ // This test involves adjusting the bucket quota for the backend. Since
674+ // Nexus utilises both Magma and Couchstore, manipulating the bucket quota
675+ // to accommodate one backend will result in failure for the other.
676+ if (isNexus ()) {
674677 GTEST_SKIP ();
675678 }
676-
677679 // This test relies on precise memory tracking
678680 const auto & stats = engine->getEpStats ();
679681 if (!stats.isMemoryTrackingEnabled ()) {
@@ -688,17 +690,17 @@ TEST_P(EPBucketFullEvictionTest, BgfetchSucceedsUntilMutationWatermark) {
688690
689691 // Load documents of size 1MiB
690692 const std::string value (valueSize, ' x' );
691- auto key1 = makeStoredDocKey (" key_0" );
692- auto key2 = makeStoredDocKey (" key_1" );
693+ auto key0 = makeStoredDocKey (" key_0" );
694+ auto key1 = makeStoredDocKey (" key_1" );
693695
694- // store an items
696+ // store items
697+ store_item (vbid, key0, value);
695698 store_item (vbid, key1, value);
696- store_item (vbid, key2, value);
697699 flush_vbucket_to_disk (vbid, 2 );
698700
699701 // evict items
702+ evict_key (vbid, key0);
700703 evict_key (vbid, key1);
701- evict_key (vbid, key2);
702704
703705 // check item has been removed
704706 auto options = static_cast <get_options_t >(
@@ -707,37 +709,64 @@ TEST_P(EPBucketFullEvictionTest, BgfetchSucceedsUntilMutationWatermark) {
707709 auto cookie1 = create_mock_cookie ();
708710 auto cookie2 = create_mock_cookie ();
709711
710- auto gv = store->get (key1, vbid, cookie1, options);
712+ // Couchstore sorts key pointers and retrieves the first item in the queue.
713+ // Initially, the queue is ["Key_1", "Key_0"], which is then sorted to
714+ // ["Key_0", "Key_1"]. In Magma, there is no sorting; instead, the first
715+ // item from the queue is popped and requested. When a new item is
716+ // requested, it is pushed to the front of the queue. To ensure Key_0 always
717+ // succeeds and Key_1 fails, we first request Key_1 ["Key_1"] and then
718+ // request Key_0 ["Key_0", "Key_1"].
719+ auto gv = store->get (key1, vbid, cookie2, options);
711720 EXPECT_EQ (cb::engine_errc::would_block, gv.getStatus ());
712- gv = store->get (key2 , vbid, cookie2 , options);
721+ gv = store->get (key0 , vbid, cookie1 , options);
713722 EXPECT_EQ (cb::engine_errc::would_block, gv.getStatus ());
714723
715724 // set bucket quota to current memory usage + 3MiB such that the first
716725 // bgfetch will pass and the second one will fail:
717726 // couchstore fetches value + addition overhead = ~1.3MiB
718727 // We want an additional 1MiB for fetching the first item successfully
719- engine->setMaxDataSize (stats.getPreciseTotalMemoryUsed () + (3 * valueSize));
728+ // Magma requires an addition 1MiB overhead than couchstore.
729+ if (engine->getConfiguration ().getBackend () == " magma" ) {
730+ engine->setMaxDataSize (stats.getPreciseTotalMemoryUsed () +
731+ (4 * valueSize));
732+ } else {
733+ engine->setMaxDataSize (stats.getPreciseTotalMemoryUsed () +
734+ (3 * valueSize));
735+ }
720736
721737 int callbackCounter = 0 ;
722- cookie1->setUserNotifyIoComplete (
723- [&callbackCounter](cb::engine_errc status) {
724- EXPECT_EQ (cb::engine_errc::success, status);
725- callbackCounter++;
726- });
727- cookie2->setUserNotifyIoComplete (
728- [&callbackCounter](cb::engine_errc status) {
729- EXPECT_EQ (cb::engine_errc::temporary_failure, status);
730- callbackCounter++;
731- });
738+ int numSucess = 0 ;
739+ int numFailure = 0 ;
740+ cookie1->setUserNotifyIoComplete ([&callbackCounter,
741+ &numSucess,
742+ &numFailure](cb::engine_errc status) {
743+ if (status == cb::engine_errc::success) {
744+ numSucess++;
745+ } else {
746+ numFailure++;
747+ }
748+ callbackCounter++;
749+ });
750+ cookie2->setUserNotifyIoComplete ([&callbackCounter,
751+ &numSucess,
752+ &numFailure](cb::engine_errc status) {
753+ if (status == cb::engine_errc::success) {
754+ numSucess++;
755+ } else {
756+ numFailure++;
757+ }
758+ callbackCounter++;
759+ });
732760
733761 // run bgFetch
734762 runBGFetcherTask ();
735763
736- // BGFetch should fail to allocate memory above bucekt quota (now works for
737- // couch-kvstore), however this still fails for magma
764+ // BGFetch should fail to allocate memory above bucekt quota
738765 auto vb = store->getVBucket (vbid);
739766 EXPECT_FALSE (vb->hasPendingBGFetchItems ());
740767 EXPECT_LE (stats.getPreciseTotalMemoryUsed (), stats.getMaxDataSize ());
768+ EXPECT_EQ (1 , numSucess);
769+ EXPECT_EQ (1 , numFailure);
741770 EXPECT_EQ (2 , callbackCounter);
742771
743772 destroy_mock_cookie (cookie1);
@@ -1075,7 +1104,7 @@ TEST_P(EPBucketFullEvictionTest, ExpiryFindsPrepareWithSameCas) {
10751104 vb.reset ();
10761105 // Before destroying the engine, prevent createItemCallback from becoming
10771106 // invalid
1078- createItemCallback = nullptr ;
1107+ createItemCallback = KVStoreIface::getDefaultCreateItemCallback () ;
10791108 resetEngineAndWarmup ();
10801109 createItemCallback = this ->engine ->getCreateItemCallback ();
10811110 vb = store->getVBucket (vbid);
0 commit comments