Add skip_cc option to TransactionDB::Write

Summary:
Compared to DB::Write, TransactionDB::Write has the additional overhead of creating and initializing an internal transaction object, as well as the overhead of locking/unlocking the keys. This patch extends the TransactionDB::Write with an skip_cc option to allow the users to indicate that the write batch do not conflict with others and the concurrency control and its overhead can be skipped. TransactionDB::Write by default calls DB::Write when skip_cc is set, which works for WriteCommitted WritePolicy. Any other flavor of TransactionDB that is not compatible with this default behavior (such as WritePreparedTxnDB) can extend ::Write and implement their own approach for taking into account the skip_cc optimization.
Closes https://github.com/facebook/rocksdb/pull/3457

Differential Revision: D6877318

Pulled By: maysamyabandeh

fbshipit-source-id: 56f4e21db87ff71492db4e376fb7c2b03dfeab6b
main
Maysam Yabandeh 7 years ago committed by Facebook Github Bot
parent 8f8eb4f1c0
commit 8feee28020
  1. 20
      include/rocksdb/utilities/transaction_db.h
  2. 10
      utilities/transactions/pessimistic_transaction_db.cc
  3. 9
      utilities/transactions/pessimistic_transaction_db.h
  4. 8
      utilities/transactions/write_prepared_txn_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<TransactionID> 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,

@ -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);

@ -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

@ -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,

Loading…
Cancel
Save