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).
12 #include "rocksdb/comparator.h"
13 #include "rocksdb/db.h"
14 #include "rocksdb/utilities/stackable_db.h"
20 // Database with Transaction support.
22 // See optimistic_transaction.h and examples/transaction_example.cc
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;
29 // Should be set if the DB has a non-default comparator.
30 // See comment in WriteBatchWithIndex constructor.
31 const Comparator
* cmp
= BytewiseComparator();
34 class OptimisticTransactionDB
: public StackableDB
{
36 // Open an OptimisticTransactionDB similar to DB::Open().
37 static Status
Open(const Options
& options
, const std::string
& dbname
,
38 OptimisticTransactionDB
** dbptr
);
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
);
45 virtual ~OptimisticTransactionDB() {}
47 // Starts a new Transaction.
49 // Caller is responsible for deleting the returned transaction when no
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;
61 OptimisticTransactionDB(const OptimisticTransactionDB
&) = delete;
62 void operator=(const OptimisticTransactionDB
&) = delete;
65 // To Create an OptimisticTransactionDB, call Open()
66 explicit OptimisticTransactionDB(DB
* db
) : StackableDB(db
) {}
69 } // namespace rocksdb
71 #endif // ROCKSDB_LITE