提交 0f1aab6c 编写于 作者: A agiardullo

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
上级 14456aea
......@@ -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() {}
......
......@@ -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;
}
......
......@@ -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,
......
......@@ -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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册