diff --git a/utilities/transactions/pessimistic_transaction.cc b/utilities/transactions/pessimistic_transaction.cc index 68b8b4f1a7..e01ea0a8c9 100644 --- a/utilities/transactions/pessimistic_transaction.cc +++ b/utilities/transactions/pessimistic_transaction.cc @@ -148,7 +148,7 @@ Status WriteCommittedTxn::CommitBatch(WriteBatch* batch) { if (can_commit) { txn_state_.store(AWAITING_COMMIT); - s = db_->Write(write_options_, batch); + s = CommitBatchInternal(batch); if (s.ok()) { txn_state_.store(COMMITED); } @@ -305,6 +305,11 @@ Status WriteCommittedTxn::CommitWithoutPrepareInternal() { return s; } +Status WriteCommittedTxn::CommitBatchInternal(WriteBatch* batch) { + Status s = db_->Write(write_options_, batch); + return s; +} + Status WriteCommittedTxn::CommitInternal() { // We take the commit-time batch and append the Commit marker. // The Memtable will ignore the Commit marker in non-recovery mode diff --git a/utilities/transactions/pessimistic_transaction.h b/utilities/transactions/pessimistic_transaction.h index 88f0a4a61f..40d1414157 100644 --- a/utilities/transactions/pessimistic_transaction.h +++ b/utilities/transactions/pessimistic_transaction.h @@ -49,6 +49,9 @@ class PessimisticTransaction : public TransactionBaseImpl { Status Commit() override; + // It is basically Commit without going through Prepare phase. The write batch + // is also directly provided instead of expecting txn to gradually batch the + // transactions writes to an internal write batch. virtual Status CommitBatch(WriteBatch* batch) = 0; Status Rollback() override = 0; @@ -114,6 +117,8 @@ class PessimisticTransaction : public TransactionBaseImpl { virtual Status CommitWithoutPrepareInternal() = 0; + virtual Status CommitBatchInternal(WriteBatch* batch) = 0; + virtual Status CommitInternal() = 0; void Initialize(const TransactionOptions& txn_options); @@ -195,6 +200,8 @@ class WriteCommittedTxn : public PessimisticTransaction { Status CommitWithoutPrepareInternal() override; + Status CommitBatchInternal(WriteBatch* batch) override; + Status CommitInternal() override; Status ValidateSnapshot(ColumnFamilyHandle* column_family, const Slice& key, diff --git a/utilities/transactions/write_prepared_txn.cc b/utilities/transactions/write_prepared_txn.cc index 211e217240..07c66690af 100644 --- a/utilities/transactions/write_prepared_txn.cc +++ b/utilities/transactions/write_prepared_txn.cc @@ -51,9 +51,21 @@ Status WritePreparedTxn::PrepareInternal() { } Status WritePreparedTxn::CommitWithoutPrepareInternal() { - // TODO(myabandeh) Implement this - throw std::runtime_error("Commit not Implemented"); - return Status::OK(); + return CommitBatchInternal(GetWriteBatch()->GetWriteBatch()); +} + +Status WritePreparedTxn::CommitBatchInternal(WriteBatch* batch) { + const bool disable_memtable = true; + const uint64_t no_log_ref = 0; + uint64_t seq_used; + auto s = db_impl_->WriteImpl(write_options_, batch, nullptr, nullptr, + no_log_ref, !disable_memtable, &seq_used); + uint64_t& prepare_seq = seq_used; + uint64_t& commit_seq = seq_used; + // TODO(myabandeh): skip AddPrepared + wpt_db_->AddPrepared(prepare_seq); + wpt_db_->AddCommitted(prepare_seq, commit_seq); + return s; } Status WritePreparedTxn::CommitInternal() { diff --git a/utilities/transactions/write_prepared_txn.h b/utilities/transactions/write_prepared_txn.h index b7cc6ba1b0..13afabe724 100644 --- a/utilities/transactions/write_prepared_txn.h +++ b/utilities/transactions/write_prepared_txn.h @@ -54,6 +54,8 @@ class WritePreparedTxn : public PessimisticTransaction { Status CommitWithoutPrepareInternal() override; + Status CommitBatchInternal(WriteBatch* batch) override; + Status CommitInternal() override; // TODO(myabandeh): verify that the current impl work with values being