@@ -9414,8 +9414,8 @@ TEST_P(CommitBypassMemtableTest, ThresholdTxnDBOption) {
9414
9414
ASSERT_OK(txn1->Commit());
9415
9415
ASSERT_TRUE(commit_bypass_memtable);
9416
9416
9417
- // Below threshold
9418
- for (auto num_ops : {threshold, threshold + 1 }) {
9417
+ // Test threshold behavior
9418
+ for (auto num_ops : {threshold - 1, threshold }) {
9419
9419
commit_bypass_memtable = false;
9420
9420
txn_opts.commit_bypass_memtable = false;
9421
9421
auto txn = txn_db->BeginTransaction(wopts, txn_opts, txn1);
@@ -9427,16 +9427,16 @@ TEST_P(CommitBypassMemtableTest, ThresholdTxnDBOption) {
9427
9427
}
9428
9428
ASSERT_OK(txn->Prepare());
9429
9429
ASSERT_OK(txn->Commit());
9430
- ASSERT_EQ (commit_bypass_memtable, num_ops > threshold);
9430
+ ASSERT_EQ(commit_bypass_memtable, num_ops >= threshold);
9431
9431
delete txn;
9432
9432
}
9433
9433
9434
9434
// Repeat the same test with updates to two CFs
9435
9435
std::vector<std::string> cfs = {"pk", "sk"};
9436
9436
CreateColumnFamilies(cfs, options);
9437
9437
9438
- // Below threshold
9439
- for (auto num_ops : {threshold, threshold + 1 }) {
9438
+ // Test threshold behavior with CFs
9439
+ for (auto num_ops : {threshold - 1, threshold }) {
9440
9440
commit_bypass_memtable = false;
9441
9441
txn_opts.commit_bypass_memtable = false;
9442
9442
auto txn_cf = txn_db->BeginTransaction(wopts, txn_opts, nullptr);
@@ -9447,11 +9447,129 @@ TEST_P(CommitBypassMemtableTest, ThresholdTxnDBOption) {
9447
9447
}
9448
9448
ASSERT_OK(txn_cf->Prepare());
9449
9449
ASSERT_OK(txn_cf->Commit());
9450
- ASSERT_EQ (commit_bypass_memtable, num_ops > threshold);
9450
+ ASSERT_EQ(commit_bypass_memtable, num_ops >= threshold);
9451
9451
delete txn_cf;
9452
9452
}
9453
9453
}
9454
9454
9455
+ TEST_P(CommitBypassMemtableTest, OptimizeLargeTxnCommitThreshold) {
9456
+ // Tests TransactionOptions::large_txn_commit_optimize_threshold
9457
+ const uint32_t threshold = 10;
9458
+ SetUpTransactionDB();
9459
+ bool commit_bypass_memtable = false;
9460
+ SyncPoint::GetInstance()->SetCallBack(
9461
+ "WriteCommittedTxn::CommitInternal:bypass_memtable",
9462
+ [&](void* arg) { commit_bypass_memtable = *(static_cast<bool*>(arg)); });
9463
+ SyncPoint::GetInstance()->EnableProcessing();
9464
+
9465
+ // Test with transaction option only
9466
+ WriteOptions wopts;
9467
+ TransactionOptions txn_opts;
9468
+ txn_opts.large_txn_commit_optimize_threshold = threshold;
9469
+
9470
+ // Test with transaction below threshold
9471
+ auto txn1 = txn_db->BeginTransaction(wopts, txn_opts, nullptr);
9472
+ ASSERT_OK(txn1->SetName("xid1"));
9473
+ ASSERT_OK(txn1->Put("k1", "v1"));
9474
+ ASSERT_OK(txn1->Prepare());
9475
+ ASSERT_OK(txn1->Commit());
9476
+ ASSERT_FALSE(commit_bypass_memtable);
9477
+ delete txn1;
9478
+
9479
+ // Test with transaction at threshold
9480
+ txn1 = txn_db->BeginTransaction(wopts, txn_opts, nullptr);
9481
+ ASSERT_OK(txn1->SetName("xid2"));
9482
+ for (uint32_t i = 0; i < threshold; ++i) {
9483
+ ASSERT_OK(
9484
+ txn1->Put("key" + std::to_string(i), "value" + std::to_string(i)));
9485
+ }
9486
+ ASSERT_OK(txn1->Prepare());
9487
+ ASSERT_OK(txn1->Commit());
9488
+ ASSERT_TRUE(commit_bypass_memtable);
9489
+ delete txn1;
9490
+
9491
+ // Test with both DB option and transaction option - transaction option should
9492
+ // take precedence
9493
+ SetUpTransactionDB(/*threshold=*/threshold * 2);
9494
+
9495
+ // Transaction option is lower than DB option, should use transaction option
9496
+ txn_opts.large_txn_commit_optimize_threshold = threshold;
9497
+ txn1 = txn_db->BeginTransaction(wopts, txn_opts, nullptr);
9498
+ ASSERT_OK(txn1->SetName("xid3"));
9499
+ for (uint32_t i = 0; i < threshold; ++i) {
9500
+ ASSERT_OK(
9501
+ txn1->Put("key" + std::to_string(i), "value" + std::to_string(i)));
9502
+ }
9503
+ ASSERT_OK(txn1->Prepare());
9504
+ commit_bypass_memtable = false;
9505
+ ASSERT_OK(txn1->Commit());
9506
+ ASSERT_TRUE(commit_bypass_memtable);
9507
+ delete txn1;
9508
+
9509
+ // Transaction option is higher than DB option, should use transaction option
9510
+ txn_opts.large_txn_commit_optimize_threshold = threshold * 3;
9511
+ txn1 = txn_db->BeginTransaction(wopts, txn_opts, nullptr);
9512
+ ASSERT_OK(txn1->SetName("xid4"));
9513
+ for (uint32_t i = 0; i < threshold * 3 - 1; ++i) {
9514
+ ASSERT_OK(
9515
+ txn1->Put("key" + std::to_string(i), "value" + std::to_string(i)));
9516
+ }
9517
+ ASSERT_OK(txn1->Prepare());
9518
+ commit_bypass_memtable = false;
9519
+ ASSERT_OK(txn1->Commit());
9520
+ ASSERT_FALSE(commit_bypass_memtable);
9521
+ delete txn1;
9522
+
9523
+ SetUpTransactionDB();
9524
+ // Test with multiple column families
9525
+ std::vector<std::string> cfs = {"pk", "sk"};
9526
+ CreateColumnFamilies(cfs, options);
9527
+
9528
+ txn_opts.large_txn_commit_optimize_threshold = threshold;
9529
+
9530
+ // Below threshold
9531
+ auto txn_cf = txn_db->BeginTransaction(wopts, txn_opts, nullptr);
9532
+ ASSERT_OK(txn_cf->SetName("xid_cf_below"));
9533
+ for (uint32_t i = 0; i < threshold - 1; ++i) {
9534
+ ASSERT_OK(txn_cf->Put(handles_[i % 2], "key" + std::to_string(i),
9535
+ "value" + std::to_string(i)));
9536
+ }
9537
+ ASSERT_OK(txn_cf->Prepare());
9538
+ commit_bypass_memtable = false;
9539
+ ASSERT_OK(txn_cf->Commit());
9540
+ ASSERT_FALSE(commit_bypass_memtable);
9541
+ delete txn_cf;
9542
+
9543
+ // At threshold
9544
+ txn_cf = txn_db->BeginTransaction(wopts, txn_opts, nullptr);
9545
+ ASSERT_OK(txn_cf->SetName("xid_cf_at_threshold"));
9546
+ for (uint32_t i = 0; i < threshold; ++i) {
9547
+ ASSERT_OK(txn_cf->Put(handles_[i % 2], "key" + std::to_string(i),
9548
+ "value" + std::to_string(i)));
9549
+ }
9550
+ ASSERT_OK(txn_cf->Prepare());
9551
+ commit_bypass_memtable = false;
9552
+ ASSERT_OK(txn_cf->Commit());
9553
+ ASSERT_TRUE(commit_bypass_memtable);
9554
+ delete txn_cf;
9555
+
9556
+ // Test that commit_bypass_memtable takes precedence over
9557
+ // large_txn_commit_optimize_threshold
9558
+ txn_opts.large_txn_commit_optimize_threshold =
9559
+ threshold * 10; // High threshold
9560
+ txn_opts.commit_bypass_memtable = true; // Should override threshold
9561
+
9562
+ txn_cf = txn_db->BeginTransaction(wopts, txn_opts, nullptr);
9563
+ ASSERT_OK(txn_cf->SetName("xid_cf_precedence"));
9564
+ ASSERT_OK(txn_cf->Put(handles_[0], "key1", "value1")); // Just one operation
9565
+ ASSERT_OK(txn_cf->Prepare());
9566
+ commit_bypass_memtable = false;
9567
+ ASSERT_OK(txn_cf->Commit());
9568
+ ASSERT_TRUE(commit_bypass_memtable); // Should be true because of
9569
+ // commit_bypass_memtable
9570
+ delete txn_cf;
9571
+ }
9572
+
9455
9573
TEST_P(CommitBypassMemtableTest, AtomicFlushTest) {
9456
9574
const uint32_t threshold = 10;
9457
9575
SetUpTransactionDB(/*threshold=*/threshold, /*atomic_flush=*/true);
0 commit comments