2017-08-03 17:46:47 +02:00
|
|
|
// 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"
|
2017-08-08 01:07:40 +02:00
|
|
|
#include "utilities/transactions/pessimistic_transaction.h"
|
2017-08-17 01:49:11 +02:00
|
|
|
#include "utilities/transactions/pessimistic_transaction_db.h"
|
|
|
|
#include "utilities/transactions/transaction_base.h"
|
2017-08-03 17:46:47 +02:00
|
|
|
#include "utilities/transactions/transaction_util.h"
|
|
|
|
|
|
|
|
namespace rocksdb {
|
|
|
|
|
2017-08-17 01:49:11 +02:00
|
|
|
class WritePreparedTxnDB;
|
2017-08-03 17:46:47 +02:00
|
|
|
|
|
|
|
// 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
|
2017-08-08 01:07:40 +02:00
|
|
|
// Prepare phase in 2PC (WritePreparedTxn) or before that
|
2017-08-03 17:46:47 +02:00
|
|
|
// (WriteUnpreparedTxnImpl).
|
2017-08-08 01:07:40 +02:00
|
|
|
class WritePreparedTxn : public PessimisticTransaction {
|
2017-08-03 17:46:47 +02:00
|
|
|
public:
|
2017-08-17 01:49:11 +02:00
|
|
|
WritePreparedTxn(WritePreparedTxnDB* db, const WriteOptions& write_options,
|
|
|
|
const TransactionOptions& txn_options);
|
2017-08-03 17:46:47 +02:00
|
|
|
|
2017-08-08 01:07:40 +02:00
|
|
|
virtual ~WritePreparedTxn() {}
|
2017-08-03 17:46:47 +02:00
|
|
|
|
2017-09-11 17:58:52 +02:00
|
|
|
using Transaction::Get;
|
|
|
|
virtual Status Get(const ReadOptions& options,
|
|
|
|
ColumnFamilyHandle* column_family, const Slice& key,
|
|
|
|
PinnableSlice* value) override;
|
|
|
|
|
2017-08-03 17:46:47 +02:00
|
|
|
private:
|
2017-09-29 01:43:04 +02:00
|
|
|
friend class WritePreparedTransactionTest_BasicRecoveryTest_Test;
|
|
|
|
|
2017-08-08 01:07:40 +02:00
|
|
|
Status PrepareInternal() override;
|
|
|
|
|
|
|
|
Status CommitWithoutPrepareInternal() override;
|
|
|
|
|
2017-09-09 00:53:51 +02:00
|
|
|
Status CommitBatchInternal(WriteBatch* batch) override;
|
|
|
|
|
2017-08-08 01:07:40 +02:00
|
|
|
Status CommitInternal() override;
|
|
|
|
|
2017-10-03 04:46:42 +02:00
|
|
|
Status RollbackInternal() override;
|
|
|
|
|
2017-08-03 17:46:47 +02:00
|
|
|
// 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
|
2017-08-08 01:07:40 +02:00
|
|
|
WritePreparedTxn(const WritePreparedTxn&);
|
|
|
|
void operator=(const WritePreparedTxn&);
|
2017-08-17 01:49:11 +02:00
|
|
|
|
|
|
|
WritePreparedTxnDB* wpt_db_;
|
2017-08-03 17:46:47 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace rocksdb
|
|
|
|
|
|
|
|
#endif // ROCKSDB_LITE
|