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
This commit is contained in:
parent
14456aea52
commit
0f1aab6c12
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user