Summary: This patch refactors TransactionImpl by separating the logic for pessimistic concurrency control from the implementation of how to write the data to rocksdb. The existing implementation is named WriteCommittedTxnImpl as it writes committed data to the db. A template named WritePreparedTxnImpl is also added which will be later completed to provide a an alternative implementation. Closes https://github.com/facebook/rocksdb/pull/2676 Differential Revision: D5549998 Pulled By: maysamyabandeh fbshipit-source-id: 16298e86b43ca4849324c1f35c731913c6d17becmain
parent
060ccd4f84
commit
c3d5c4d38a
@ -0,0 +1,65 @@ |
||||
// Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
|
||||
// This source code is licensed under both the GPLv2 (found in the
|
||||
// COPYING file in the root directory) and Apache 2.0 License
|
||||
// (found in the LICENSE.Apache file in the root directory).
|
||||
|
||||
#ifndef ROCKSDB_LITE |
||||
|
||||
#include "utilities/transactions/write_prepared_transaction_impl.h" |
||||
|
||||
#include <map> |
||||
#include <set> |
||||
#include <string> |
||||
#include <vector> |
||||
|
||||
#include "db/column_family.h" |
||||
#include "db/db_impl.h" |
||||
#include "rocksdb/comparator.h" |
||||
#include "rocksdb/db.h" |
||||
#include "rocksdb/snapshot.h" |
||||
#include "rocksdb/status.h" |
||||
#include "rocksdb/utilities/transaction_db.h" |
||||
#include "util/string_util.h" |
||||
#include "util/sync_point.h" |
||||
#include "utilities/transactions/transaction_db_impl.h" |
||||
#include "utilities/transactions/transaction_impl.h" |
||||
#include "utilities/transactions/transaction_util.h" |
||||
|
||||
namespace rocksdb { |
||||
|
||||
struct WriteOptions; |
||||
|
||||
WritePreparedTxnImpl::WritePreparedTxnImpl( |
||||
TransactionDB* txn_db, const WriteOptions& write_options, |
||||
const TransactionOptions& txn_options) |
||||
: PessimisticTxn(txn_db, write_options, txn_options) { |
||||
PessimisticTxn::Initialize(txn_options); |
||||
} |
||||
|
||||
Status WritePreparedTxnImpl::CommitBatch(WriteBatch* batch) { |
||||
// TODO(myabandeh) Implement this
|
||||
throw std::runtime_error("CommitBatch not Implemented"); |
||||
return Status::OK(); |
||||
} |
||||
|
||||
Status WritePreparedTxnImpl::Prepare() { |
||||
// TODO(myabandeh) Implement this
|
||||
throw std::runtime_error("Prepare not Implemented"); |
||||
return Status::OK(); |
||||
} |
||||
|
||||
Status WritePreparedTxnImpl::Commit() { |
||||
// TODO(myabandeh) Implement this
|
||||
throw std::runtime_error("Commit not Implemented"); |
||||
return Status::OK(); |
||||
} |
||||
|
||||
Status WritePreparedTxnImpl::Rollback() { |
||||
// TODO(myabandeh) Implement this
|
||||
throw std::runtime_error("Rollback not Implemented"); |
||||
return Status::OK(); |
||||
} |
||||
|
||||
} // namespace rocksdb
|
||||
|
||||
#endif // ROCKSDB_LITE
|
@ -0,0 +1,70 @@ |
||||
// Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
|
||||
// This source code is licensed under both the GPLv2 (found in the
|
||||
// COPYING file in the root directory) and Apache 2.0 License
|
||||
// (found in the LICENSE.Apache file in the root directory).
|
||||
|
||||
#pragma once |
||||
|
||||
#ifndef ROCKSDB_LITE |
||||
|
||||
#include <algorithm> |
||||
#include <atomic> |
||||
#include <mutex> |
||||
#include <stack> |
||||
#include <string> |
||||
#include <unordered_map> |
||||
#include <vector> |
||||
|
||||
#include "db/write_callback.h" |
||||
#include "rocksdb/db.h" |
||||
#include "rocksdb/slice.h" |
||||
#include "rocksdb/snapshot.h" |
||||
#include "rocksdb/status.h" |
||||
#include "rocksdb/types.h" |
||||
#include "rocksdb/utilities/transaction.h" |
||||
#include "rocksdb/utilities/transaction_db.h" |
||||
#include "rocksdb/utilities/write_batch_with_index.h" |
||||
#include "util/autovector.h" |
||||
#include "utilities/transactions/transaction_base.h" |
||||
#include "utilities/transactions/transaction_impl.h" |
||||
#include "utilities/transactions/transaction_util.h" |
||||
|
||||
namespace rocksdb { |
||||
|
||||
class TransactionDBImpl; |
||||
|
||||
// This impl could write to DB also uncomitted data and then later tell apart
|
||||
// committed data from uncomitted data. Uncommitted data could be after the
|
||||
// Prepare phase in 2PC (WritePreparedTxnImpl) or before that
|
||||
// (WriteUnpreparedTxnImpl).
|
||||
class WritePreparedTxnImpl : public PessimisticTxn { |
||||
public: |
||||
WritePreparedTxnImpl(TransactionDB* db, const WriteOptions& write_options, |
||||
const TransactionOptions& txn_options); |
||||
|
||||
virtual ~WritePreparedTxnImpl() {} |
||||
|
||||
Status Prepare() override; |
||||
|
||||
Status Commit() override; |
||||
|
||||
Status CommitBatch(WriteBatch* batch) override; |
||||
|
||||
Status Rollback() override; |
||||
|
||||
private: |
||||
// TODO(myabandeh): verify that the current impl work with values being
|
||||
// written with prepare sequence number too.
|
||||
// Status ValidateSnapshot(ColumnFamilyHandle* column_family, const Slice&
|
||||
// key,
|
||||
// SequenceNumber prev_seqno, SequenceNumber*
|
||||
// new_seqno);
|
||||
|
||||
// No copying allowed
|
||||
WritePreparedTxnImpl(const WritePreparedTxnImpl&); |
||||
void operator=(const WritePreparedTxnImpl&); |
||||
}; |
||||
|
||||
} // namespace rocksdb
|
||||
|
||||
#endif // ROCKSDB_LITE
|
Loading…
Reference in new issue