fork of https://github.com/oxigraph/rocksdb and https://github.com/facebook/rocksdb for nextgraph and oxigraph
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
99 lines
2.8 KiB
99 lines
2.8 KiB
9 years ago
|
// Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
|
||
7 years ago
|
// 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).
|
||
10 years ago
|
|
||
|
#pragma once
|
||
|
|
||
|
#ifndef ROCKSDB_LITE
|
||
|
|
||
10 years ago
|
#include <stack>
|
||
10 years ago
|
#include <string>
|
||
|
#include <unordered_map>
|
||
|
#include <vector>
|
||
|
|
||
|
#include "db/write_callback.h"
|
||
|
#include "rocksdb/db.h"
|
||
|
#include "rocksdb/slice.h"
|
||
9 years ago
|
#include "rocksdb/snapshot.h"
|
||
10 years ago
|
#include "rocksdb/status.h"
|
||
|
#include "rocksdb/types.h"
|
||
10 years ago
|
#include "rocksdb/utilities/transaction.h"
|
||
10 years ago
|
#include "rocksdb/utilities/optimistic_transaction_db.h"
|
||
|
#include "rocksdb/utilities/write_batch_with_index.h"
|
||
9 years ago
|
#include "utilities/transactions/transaction_base.h"
|
||
10 years ago
|
#include "utilities/transactions/transaction_util.h"
|
||
10 years ago
|
|
||
|
namespace rocksdb {
|
||
|
|
||
7 years ago
|
class OptimisticTransaction : public TransactionBaseImpl {
|
||
10 years ago
|
public:
|
||
7 years ago
|
OptimisticTransaction(OptimisticTransactionDB* db,
|
||
10 years ago
|
const WriteOptions& write_options,
|
||
|
const OptimisticTransactionOptions& txn_options);
|
||
|
|
||
7 years ago
|
virtual ~OptimisticTransaction();
|
||
10 years ago
|
|
||
9 years ago
|
void Reinitialize(OptimisticTransactionDB* txn_db,
|
||
|
const WriteOptions& write_options,
|
||
|
const OptimisticTransactionOptions& txn_options);
|
||
|
|
||
9 years ago
|
Status Prepare() override;
|
||
|
|
||
10 years ago
|
Status Commit() override;
|
||
|
|
||
9 years ago
|
Status Rollback() override;
|
||
|
|
||
|
Status SetName(const TransactionName& name) override;
|
||
10 years ago
|
|
||
|
protected:
|
||
9 years ago
|
Status TryLock(ColumnFamilyHandle* column_family, const Slice& key,
|
||
8 years ago
|
bool read_only, bool exclusive,
|
||
|
bool untracked = false) override;
|
||
10 years ago
|
|
||
|
private:
|
||
9 years ago
|
OptimisticTransactionDB* const txn_db_;
|
||
|
|
||
10 years ago
|
friend class OptimisticTransactionCallback;
|
||
|
|
||
9 years ago
|
void Initialize(const OptimisticTransactionOptions& txn_options);
|
||
|
|
||
10 years ago
|
// Returns OK if it is safe to commit this transaction. Returns Status::Busy
|
||
|
// if there are read or write conflicts that would prevent us from committing
|
||
|
// OR if we can not determine whether there would be any such conflicts.
|
||
|
//
|
||
|
// Should only be called on writer thread.
|
||
|
Status CheckTransactionForConflicts(DB* db);
|
||
|
|
||
9 years ago
|
void Clear() override;
|
||
9 years ago
|
|
||
7 years ago
|
void UnlockGetForUpdate(ColumnFamilyHandle* /* unused */,
|
||
|
const Slice& /* unused */) override {
|
||
9 years ago
|
// Nothing to unlock.
|
||
|
}
|
||
|
|
||
10 years ago
|
// No copying allowed
|
||
7 years ago
|
OptimisticTransaction(const OptimisticTransaction&);
|
||
|
void operator=(const OptimisticTransaction&);
|
||
10 years ago
|
};
|
||
|
|
||
|
// Used at commit time to trigger transaction validation
|
||
|
class OptimisticTransactionCallback : public WriteCallback {
|
||
|
public:
|
||
7 years ago
|
explicit OptimisticTransactionCallback(OptimisticTransaction* txn)
|
||
10 years ago
|
: txn_(txn) {}
|
||
|
|
||
|
Status Callback(DB* db) override {
|
||
|
return txn_->CheckTransactionForConflicts(db);
|
||
|
}
|
||
|
|
||
9 years ago
|
bool AllowWriteBatching() override { return false; }
|
||
|
|
||
10 years ago
|
private:
|
||
7 years ago
|
OptimisticTransaction* txn_;
|
||
10 years ago
|
};
|
||
|
|
||
|
} // namespace rocksdb
|
||
|
|
||
|
#endif // ROCKSDB_LITE
|