2016-02-10 00:12:00 +01:00
|
|
|
// Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
|
2017-07-16 01:03:42 +02:00
|
|
|
// 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).
|
2015-05-29 23:36:35 +02:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
#ifndef ROCKSDB_LITE
|
|
|
|
|
|
|
|
#include "rocksdb/db.h"
|
|
|
|
#include "rocksdb/options.h"
|
|
|
|
#include "rocksdb/utilities/optimistic_transaction_db.h"
|
|
|
|
|
|
|
|
namespace rocksdb {
|
|
|
|
|
|
|
|
class OptimisticTransactionDBImpl : public OptimisticTransactionDB {
|
|
|
|
public:
|
2017-05-10 23:54:35 +02:00
|
|
|
explicit OptimisticTransactionDBImpl(DB* db, bool take_ownership = true)
|
2018-04-04 00:24:23 +02:00
|
|
|
: OptimisticTransactionDB(db), db_owner_(take_ownership) {}
|
2015-05-29 23:36:35 +02:00
|
|
|
|
2017-05-10 23:54:35 +02:00
|
|
|
~OptimisticTransactionDBImpl() {
|
2018-04-04 00:24:23 +02:00
|
|
|
// Prevent this stackable from destroying
|
|
|
|
// base db
|
2017-05-10 23:54:35 +02:00
|
|
|
if (!db_owner_) {
|
2018-04-04 00:24:23 +02:00
|
|
|
db_ = nullptr;
|
2017-05-10 23:54:35 +02:00
|
|
|
}
|
|
|
|
}
|
2015-05-29 23:36:35 +02:00
|
|
|
|
2016-03-04 01:33:26 +01:00
|
|
|
Transaction* BeginTransaction(const WriteOptions& write_options,
|
|
|
|
const OptimisticTransactionOptions& txn_options,
|
|
|
|
Transaction* old_txn) override;
|
2015-05-29 23:36:35 +02:00
|
|
|
|
|
|
|
private:
|
2018-04-04 00:24:23 +02:00
|
|
|
|
|
|
|
bool db_owner_;
|
2016-03-04 01:33:26 +01:00
|
|
|
|
|
|
|
void ReinitializeTransaction(Transaction* txn,
|
|
|
|
const WriteOptions& write_options,
|
|
|
|
const OptimisticTransactionOptions& txn_options =
|
|
|
|
OptimisticTransactionOptions());
|
2015-05-29 23:36:35 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace rocksdb
|
|
|
|
#endif // ROCKSDB_LITE
|