]> git.proxmox.com Git - ceph.git/blob - ceph/src/rocksdb/include/rocksdb/utilities/optimistic_transaction_db.h
update sources to ceph Nautilus 14.2.1
[ceph.git] / ceph / src / rocksdb / include / rocksdb / utilities / optimistic_transaction_db.h
1 // Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
2 // This source code is licensed under both the GPLv2 (found in the
3 // COPYING file in the root directory) and Apache 2.0 License
4 // (found in the LICENSE.Apache file in the root directory).
5
6 #pragma once
7 #ifndef ROCKSDB_LITE
8
9 #include <string>
10 #include <vector>
11
12 #include "rocksdb/comparator.h"
13 #include "rocksdb/db.h"
14 #include "rocksdb/utilities/stackable_db.h"
15
16 namespace rocksdb {
17
18 class Transaction;
19
20 // Database with Transaction support.
21 //
22 // See optimistic_transaction.h and examples/transaction_example.cc
23
24 // Options to use when starting an Optimistic Transaction
25 struct OptimisticTransactionOptions {
26 // Setting set_snapshot=true is the same as calling SetSnapshot().
27 bool set_snapshot = false;
28
29 // Should be set if the DB has a non-default comparator.
30 // See comment in WriteBatchWithIndex constructor.
31 const Comparator* cmp = BytewiseComparator();
32 };
33
34 class OptimisticTransactionDB : public StackableDB {
35 public:
36 // Open an OptimisticTransactionDB similar to DB::Open().
37 static Status Open(const Options& options, const std::string& dbname,
38 OptimisticTransactionDB** dbptr);
39
40 static Status Open(const DBOptions& db_options, const std::string& dbname,
41 const std::vector<ColumnFamilyDescriptor>& column_families,
42 std::vector<ColumnFamilyHandle*>* handles,
43 OptimisticTransactionDB** dbptr);
44
45 virtual ~OptimisticTransactionDB() {}
46
47 // Starts a new Transaction.
48 //
49 // Caller is responsible for deleting the returned transaction when no
50 // longer needed.
51 //
52 // If old_txn is not null, BeginTransaction will reuse this Transaction
53 // handle instead of allocating a new one. This is an optimization to avoid
54 // extra allocations when repeatedly creating transactions.
55 virtual Transaction* BeginTransaction(
56 const WriteOptions& write_options,
57 const OptimisticTransactionOptions& txn_options =
58 OptimisticTransactionOptions(),
59 Transaction* old_txn = nullptr) = 0;
60
61 OptimisticTransactionDB(const OptimisticTransactionDB&) = delete;
62 void operator=(const OptimisticTransactionDB&) = delete;
63
64 protected:
65 // To Create an OptimisticTransactionDB, call Open()
66 explicit OptimisticTransactionDB(DB* db) : StackableDB(db) {}
67 };
68
69 } // namespace rocksdb
70
71 #endif // ROCKSDB_LITE