2018-05-31 19:42:44 +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 "utilities/transactions/write_prepared_txn.h"
|
2018-06-27 21:05:29 +02:00
|
|
|
#include "utilities/transactions/write_unprepared_txn_db.h"
|
2018-05-31 19:42:44 +02:00
|
|
|
|
|
|
|
namespace rocksdb {
|
|
|
|
|
2018-06-27 21:05:29 +02:00
|
|
|
class WriteUnpreparedTxnDB;
|
|
|
|
class WriteUnpreparedTxn;
|
|
|
|
|
|
|
|
class WriteUnpreparedTxnReadCallback : public ReadCallback {
|
|
|
|
public:
|
|
|
|
WriteUnpreparedTxnReadCallback(WritePreparedTxnDB* db,
|
|
|
|
SequenceNumber snapshot,
|
|
|
|
SequenceNumber min_uncommitted,
|
|
|
|
WriteUnpreparedTxn* txn)
|
|
|
|
: db_(db),
|
|
|
|
snapshot_(snapshot),
|
|
|
|
min_uncommitted_(min_uncommitted),
|
|
|
|
txn_(txn) {}
|
|
|
|
|
|
|
|
virtual bool IsVisible(SequenceNumber seq) override;
|
|
|
|
virtual SequenceNumber MaxUnpreparedSequenceNumber() override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
WritePreparedTxnDB* db_;
|
|
|
|
SequenceNumber snapshot_;
|
|
|
|
SequenceNumber min_uncommitted_;
|
|
|
|
WriteUnpreparedTxn* txn_;
|
|
|
|
};
|
|
|
|
|
2018-05-31 19:42:44 +02:00
|
|
|
class WriteUnpreparedTxn : public WritePreparedTxn {
|
2018-06-27 21:05:29 +02:00
|
|
|
public:
|
|
|
|
WriteUnpreparedTxn(WriteUnpreparedTxnDB* db,
|
|
|
|
const WriteOptions& write_options,
|
|
|
|
const TransactionOptions& txn_options);
|
|
|
|
|
|
|
|
virtual ~WriteUnpreparedTxn() {}
|
|
|
|
|
|
|
|
// Get and GetIterator needs to be overridden so that a ReadCallback to
|
|
|
|
// handle read-your-own-write is used.
|
|
|
|
using Transaction::Get;
|
|
|
|
virtual Status Get(const ReadOptions& options,
|
|
|
|
ColumnFamilyHandle* column_family, const Slice& key,
|
|
|
|
PinnableSlice* value) override;
|
|
|
|
|
|
|
|
using Transaction::GetIterator;
|
|
|
|
virtual Iterator* GetIterator(const ReadOptions& options) override;
|
|
|
|
virtual Iterator* GetIterator(const ReadOptions& options,
|
|
|
|
ColumnFamilyHandle* column_family) override;
|
|
|
|
|
|
|
|
const std::map<SequenceNumber, size_t>& GetUnpreparedSequenceNumbers();
|
|
|
|
|
|
|
|
private:
|
|
|
|
friend class WriteUnpreparedTransactionTest_ReadYourOwnWrite_Test;
|
2018-07-07 02:17:36 +02:00
|
|
|
friend class WriteUnpreparedTxnDB;
|
2018-06-27 21:05:29 +02:00
|
|
|
|
|
|
|
WriteUnpreparedTxnDB* wupt_db_;
|
2018-05-31 19:42:44 +02:00
|
|
|
|
2018-06-27 21:05:29 +02:00
|
|
|
// Ordered list of unprep_seq sequence numbers that we have already written
|
|
|
|
// to DB.
|
|
|
|
//
|
|
|
|
// This maps unprep_seq => prepare_batch_cnt for each prepared batch written
|
|
|
|
// by this transactioin.
|
|
|
|
std::map<SequenceNumber, size_t> unprep_seqs_;
|
2018-05-31 19:42:44 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace rocksdb
|
|
|
|
|
|
|
|
#endif // ROCKSDB_LITE
|