YugabyteDB (2.13.0.0-b42, bfc6a6643e7399ac8a0e81d06a3ee6d6571b33ab)

Coverage Report

Created: 2022-03-09 17:30

/Users/deen/code/yugabyte-db/src/yb/rocksdb/utilities/optimistic_transaction_db.h
Line
Count
Source (jump to first uncovered line)
1
//  Copyright (c) 2011-present, Facebook, Inc.  All rights reserved.
2
//  This source code is licensed under the BSD-style license found in the
3
//  LICENSE file in the root directory of this source tree. An additional grant
4
//  of patent rights can be found in the PATENTS file in the same directory.
5
//
6
// The following only applies to changes made to this file as part of YugaByte development.
7
//
8
// Portions Copyright (c) YugaByte, Inc.
9
//
10
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
11
// in compliance with the License.  You may obtain a copy of the License at
12
//
13
// http://www.apache.org/licenses/LICENSE-2.0
14
//
15
// Unless required by applicable law or agreed to in writing, software distributed under the License
16
// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
17
// or implied.  See the License for the specific language governing permissions and limitations
18
// under the License.
19
//
20
21
#pragma once
22
#ifndef ROCKSDB_LITE
23
24
#include <string>
25
#include <vector>
26
27
#include "yb/rocksdb/comparator.h"
28
#include "yb/rocksdb/db.h"
29
30
namespace rocksdb {
31
32
class Transaction;
33
34
// Database with Transaction support.
35
//
36
// See optimistic_transaction.h and examples/transaction_example.cc
37
38
// Options to use when starting an Optimistic Transaction
39
struct OptimisticTransactionOptions {
40
  // Setting set_snapshot=true is the same as calling SetSnapshot().
41
  bool set_snapshot = false;
42
43
  // Should be set if the DB has a non-default comparator.
44
  // See comment in WriteBatchWithIndex constructor.
45
  const Comparator* cmp = BytewiseComparator();
46
};
47
48
class OptimisticTransactionDB {
49
 public:
50
  // Open an OptimisticTransactionDB similar to DB::Open().
51
  static Status Open(const Options& options, const std::string& dbname,
52
                     OptimisticTransactionDB** dbptr);
53
54
  static Status Open(const DBOptions& db_options, const std::string& dbname,
55
                     const std::vector<ColumnFamilyDescriptor>& column_families,
56
                     std::vector<ColumnFamilyHandle*>* handles,
57
                     OptimisticTransactionDB** dbptr);
58
59
19
  virtual ~OptimisticTransactionDB() {}
60
61
  // Starts a new Transaction.
62
  //
63
  // Caller is responsible for deleting the returned transaction when no
64
  // longer needed.
65
  //
66
  // If old_txn is not null, BeginTransaction will reuse this Transaction
67
  // handle instead of allocating a new one.  This is an optimization to avoid
68
  // extra allocations when repeatedly creating transactions.
69
  virtual Transaction* BeginTransaction(
70
      const WriteOptions& write_options,
71
      const OptimisticTransactionOptions& txn_options =
72
          OptimisticTransactionOptions(),
73
      Transaction* old_txn = nullptr) = 0;
74
75
  // Return the underlying Database that was opened
76
  virtual DB* GetBaseDB() = 0;
77
78
 protected:
79
  // To Create an OptimisticTransactionDB, call Open()
80
19
  explicit OptimisticTransactionDB(DB* db) {}
81
0
  OptimisticTransactionDB() {}
82
83
 private:
84
  // No copying allowed
85
  OptimisticTransactionDB(const OptimisticTransactionDB&);
86
  void operator=(const OptimisticTransactionDB&);
87
};
88
89
}  // namespace rocksdb
90
91
#endif  // ROCKSDB_LITE