Add SetLockTimeout for Transactions

Summary: MyRocks wants to be able to change the lock timeout of a transaction that has already started.  Expose existing SetLockTimeout function to users.

Test Plan: unit test

Reviewers: spetrunia, rven, sdong, yhchiang, igor

Reviewed By: igor

Subscribers: dhruba, leveldb

Differential Revision: https://reviews.facebook.net/D45987
main
agiardullo 9 years ago
parent 14456aea52
commit 0f1aab6c12
  1. 5
      include/rocksdb/utilities/transaction.h
  2. 3
      utilities/transactions/transaction_base.h
  3. 2
      utilities/transactions/transaction_impl.h
  4. 2
      utilities/transactions/transaction_test.cc

@ -258,6 +258,11 @@ class Transaction {
// write to this transaction. // write to this transaction.
virtual WriteBatchWithIndex* GetWriteBatch() = 0; 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: protected:
explicit Transaction(const TransactionDB* db) {} explicit Transaction(const TransactionDB* db) {}
Transaction() {} Transaction() {}

@ -146,6 +146,9 @@ class TransactionBaseImpl : public Transaction {
WriteBatchWithIndex* GetWriteBatch() override; WriteBatchWithIndex* GetWriteBatch() override;
virtual void SetLockTimeout(int64_t timeout) override { /* Do nothing */
}
const Snapshot* GetSnapshot() const override { const Snapshot* GetSnapshot() const override {
return snapshot_ ? snapshot_->snapshot() : nullptr; return snapshot_ ? snapshot_->snapshot() : nullptr;
} }

@ -60,7 +60,7 @@ class TransactionImpl : public TransactionBaseImpl {
// Returns the number of milliseconds a transaction can wait on acquiring a // Returns the number of milliseconds a transaction can wait on acquiring a
// lock or -1 if there is no timeout. // lock or -1 if there is no timeout.
int64_t GetLockTimeout() const { return lock_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: protected:
Status TryLock(ColumnFamilyHandle* column_family, const Slice& key, Status TryLock(ColumnFamilyHandle* column_family, const Slice& key,

@ -1530,7 +1530,9 @@ TEST_F(TransactionTest, TimeoutTest) {
delete txn1; delete txn1;
txn_options.expiration = 6000000; // 100 minutes txn_options.expiration = 6000000; // 100 minutes
txn_options.lock_timeout = 1; // 1ms
txn1 = db->BeginTransaction(write_options, txn_options); txn1 = db->BeginTransaction(write_options, txn_options);
txn1->SetLockTimeout(100);
TransactionOptions txn_options2; TransactionOptions txn_options2;
txn_options2.expiration = 10; // 10ms txn_options2.expiration = 10; // 10ms

Loading…
Cancel
Save