diff --git a/include/rocksdb/utilities/transaction_db.h b/include/rocksdb/utilities/transaction_db.h index b5a33d18b..15bddc9fe 100644 --- a/include/rocksdb/utilities/transaction_db.h +++ b/include/rocksdb/utilities/transaction_db.h @@ -130,6 +130,16 @@ struct TransactionOptions { size_t max_write_batch_size = 0; }; +// The per-write optimizations that do not involve transactions. TransactionDB +// implemenation might or might not make use of the specified optimizations. +struct TransactionDBWriteOptimizations { + // If it is true it means that the applicatinn guratnees that the + // key-set in the write batch do not conflict with any concurrent transaction + // and hence the concurrency control mechanism could be skipped for this + // write. + bool skip_concurrency_control = false; +}; + struct KeyLockInfo { std::string key; std::vector ids; @@ -158,6 +168,16 @@ struct DeadlockPath { class TransactionDB : public StackableDB { public: + // Optimized version of ::Write that receives more optimization request such + // as skip_concurrency_control. + using StackableDB::Write; + virtual Status Write(const WriteOptions& opts, + const TransactionDBWriteOptimizations&, + WriteBatch* updates) { + // The default implementation ignores TransactionDBWriteOptimizations and + // falls back to the un-optimized version of ::Write + return Write(opts, updates); + } // Open a TransactionDB similar to DB::Open(). // Internally call PrepareWrap() and WrapDB() static Status Open(const Options& options, diff --git a/utilities/transactions/pessimistic_transaction_db.cc b/utilities/transactions/pessimistic_transaction_db.cc index 0aad76a50..0dd48d01e 100644 --- a/utilities/transactions/pessimistic_transaction_db.cc +++ b/utilities/transactions/pessimistic_transaction_db.cc @@ -502,6 +502,16 @@ Status PessimisticTransactionDB::Write(const WriteOptions& opts, return s; } +Status WriteCommittedTxnDB::Write( + const WriteOptions& opts, + const TransactionDBWriteOptimizations& optimizations, WriteBatch* updates) { + if (optimizations.skip_concurrency_control) { + return db_impl_->Write(opts, updates); + } else { + return Write(opts, updates); + } +} + void PessimisticTransactionDB::InsertExpirableTransaction( TransactionID tx_id, PessimisticTransaction* tx) { assert(tx->GetExpirationTime() > 0); diff --git a/utilities/transactions/pessimistic_transaction_db.h b/utilities/transactions/pessimistic_transaction_db.h index 9b4ad5618..90360d7a3 100644 --- a/utilities/transactions/pessimistic_transaction_db.h +++ b/utilities/transactions/pessimistic_transaction_db.h @@ -63,7 +63,7 @@ class PessimisticTransactionDB : public TransactionDB { ColumnFamilyHandle* column_family, const Slice& key, const Slice& value) override; - using StackableDB::Write; + using TransactionDB::Write; virtual Status Write(const WriteOptions& opts, WriteBatch* updates) override; using StackableDB::CreateColumnFamily; @@ -172,6 +172,13 @@ class WriteCommittedTxnDB : public PessimisticTransactionDB { Transaction* BeginTransaction(const WriteOptions& write_options, const TransactionOptions& txn_options, Transaction* old_txn) override; + + // Optimized version of ::Write that makes use of skip_concurrency_control + // hint + using TransactionDB::Write; + virtual Status Write(const WriteOptions& opts, + const TransactionDBWriteOptimizations& optimizations, + WriteBatch* updates) override; }; } // namespace rocksdb diff --git a/utilities/transactions/write_prepared_txn_db.h b/utilities/transactions/write_prepared_txn_db.h index 0b096e4c2..587e97341 100644 --- a/utilities/transactions/write_prepared_txn_db.h +++ b/utilities/transactions/write_prepared_txn_db.h @@ -73,6 +73,14 @@ class WritePreparedTxnDB : public PessimisticTransactionDB { const TransactionOptions& txn_options, Transaction* old_txn) override; + // TODO(myabandeh): Implement this + // Optimized version of ::Write that receives more optimization request such + // as skip_concurrency_control. + // using PessimisticTransactionDB::Write; + // Status Write(const WriteOptions& opts, const + // TransactionDBWriteOptimizations&, + // WriteBatch* updates) override; + using DB::Get; virtual Status Get(const ReadOptions& options, ColumnFamilyHandle* column_family, const Slice& key,