Transaction::SetWriteOptions()

Summary: Add support to change write options after creating a transaction.  This is needed for MongoRocks.

Test Plan: added test

Reviewers: sdong, rven, kradhakrishnan, IslamAbdelRahman, yhchiang

Reviewed By: yhchiang

Subscribers: dhruba, leveldb

Differential Revision: https://reviews.facebook.net/D51867
main
agiardullo 9 years ago
parent 3bfd3d39a3
commit 84f98792d6
  1. 6
      include/rocksdb/utilities/transaction.h
  2. 8
      utilities/transactions/transaction_base.h
  3. 18
      utilities/transactions/transaction_test.cc

@ -350,6 +350,12 @@ class Transaction {
// Has no effect on OptimisticTransactions.
virtual void SetLockTimeout(int64_t timeout) = 0;
// Return the WriteOptions that will be used during Commit()
virtual const WriteOptions* GetWriteOptions() = 0;
// Reset the WriteOptions that will be used during Commit().
virtual void SetWriteOptions(const WriteOptions& write_options) = 0;
protected:
explicit Transaction(const TransactionDB* db) {}
Transaction() {}

@ -196,6 +196,12 @@ class TransactionBaseImpl : public Transaction {
// with writes in other transactions.
const TransactionKeyMap& GetTrackedKeys() const { return tracked_keys_; }
const WriteOptions* GetWriteOptions() override { return &write_options_; }
void SetWriteOptions(const WriteOptions& write_options) override {
write_options_ = write_options;
}
protected:
// Add a key to the list of tracked keys.
// seqno is the earliest seqno this key was involved with this transaction.
@ -208,7 +214,7 @@ class TransactionBaseImpl : public Transaction {
DB* const db_;
const WriteOptions write_options_;
WriteOptions write_options_;
const Comparator* cmp_;

@ -135,6 +135,24 @@ TEST_F(TransactionTest, FirstWriteTest2) {
delete txn;
}
TEST_F(TransactionTest, WriteOptionsTest) {
WriteOptions write_options;
write_options.sync = true;
write_options.disableWAL = true;
Transaction* txn = db->BeginTransaction(write_options);
ASSERT_TRUE(txn);
ASSERT_TRUE(txn->GetWriteOptions()->sync);
write_options.sync = false;
txn->SetWriteOptions(write_options);
ASSERT_FALSE(txn->GetWriteOptions()->sync);
ASSERT_TRUE(txn->GetWriteOptions()->disableWAL);
delete txn;
}
TEST_F(TransactionTest, WriteConflictTest) {
WriteOptions write_options;
ReadOptions read_options;

Loading…
Cancel
Save