diff --git a/include/rocksdb/utilities/transaction.h b/include/rocksdb/utilities/transaction.h index 4127e9b2b..052570758 100644 --- a/include/rocksdb/utilities/transaction.h +++ b/include/rocksdb/utilities/transaction.h @@ -258,6 +258,11 @@ class Transaction { // write to this transaction. virtual WriteBatchWithIndex* GetWriteBatch() = 0; + // Change the value of TransactionOptions.lock_timeout (in milliseconds) for + // this transaction. + // Has no effect on OptimisticTransactions. + virtual void SetLockTimeout(int64_t timeout) = 0; + protected: explicit Transaction(const TransactionDB* db) {} Transaction() {} diff --git a/utilities/transactions/transaction_base.h b/utilities/transactions/transaction_base.h index 9cd324e57..f48603d65 100644 --- a/utilities/transactions/transaction_base.h +++ b/utilities/transactions/transaction_base.h @@ -146,6 +146,9 @@ class TransactionBaseImpl : public Transaction { WriteBatchWithIndex* GetWriteBatch() override; + virtual void SetLockTimeout(int64_t timeout) override { /* Do nothing */ + } + const Snapshot* GetSnapshot() const override { return snapshot_ ? snapshot_->snapshot() : nullptr; } diff --git a/utilities/transactions/transaction_impl.h b/utilities/transactions/transaction_impl.h index 2d11ac0c0..6b0901dcd 100644 --- a/utilities/transactions/transaction_impl.h +++ b/utilities/transactions/transaction_impl.h @@ -60,7 +60,7 @@ class TransactionImpl : public TransactionBaseImpl { // Returns the number of milliseconds a transaction can wait on acquiring a // lock or -1 if there is no timeout. int64_t GetLockTimeout() const { return lock_timeout_; } - void SetLockTimeout(int64_t timeout) { lock_timeout_ = timeout; } + void SetLockTimeout(int64_t timeout) override { lock_timeout_ = timeout; } protected: Status TryLock(ColumnFamilyHandle* column_family, const Slice& key, diff --git a/utilities/transactions/transaction_test.cc b/utilities/transactions/transaction_test.cc index e9d6a196f..bb7caa95a 100644 --- a/utilities/transactions/transaction_test.cc +++ b/utilities/transactions/transaction_test.cc @@ -1530,7 +1530,9 @@ TEST_F(TransactionTest, TimeoutTest) { delete txn1; txn_options.expiration = 6000000; // 100 minutes + txn_options.lock_timeout = 1; // 1ms txn1 = db->BeginTransaction(write_options, txn_options); + txn1->SetLockTimeout(100); TransactionOptions txn_options2; txn_options2.expiration = 10; // 10ms