YugabyteDB (2.13.1.0-b60, 21121d69985fbf76aa6958d8f04a9bfa936293b5)

Coverage Report

Created: 2022-03-22 16:43

/Users/deen/code/yugabyte-db/src/yb/rocksdb/utilities/transactions/transaction_util.h
Line
Count
Source
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
23
#ifndef ROCKSDB_LITE
24
25
#include <string>
26
#include <unordered_map>
27
28
#include "yb/rocksdb/db.h"
29
#include "yb/util/slice.h"
30
#include "yb/rocksdb/status.h"
31
#include "yb/rocksdb/types.h"
32
33
namespace rocksdb {
34
35
struct TransactionKeyMapInfo {
36
  // Earliest sequence number that is relevant to this transaction for this key
37
  SequenceNumber seq;
38
39
  uint32_t num_writes;
40
  uint32_t num_reads;
41
42
  explicit TransactionKeyMapInfo(SequenceNumber seq_no)
43
3.36k
      : seq(seq_no), num_writes(0), num_reads(0) {}
44
};
45
46
using TransactionKeyMap =
47
    std::unordered_map<uint32_t,
48
                       std::unordered_map<std::string, TransactionKeyMapInfo>>;
49
50
class DBImpl;
51
struct SuperVersion;
52
class WriteBatchWithIndex;
53
54
class TransactionUtil {
55
 public:
56
  // Verifies there have been no writes to this key in the db since this
57
  // sequence number.
58
  //
59
  // If cache_only is true, then this function will not attempt to read any
60
  // SST files.  This will make it more likely this function will
61
  // return an error if it is unable to determine if there are any conflicts.
62
  //
63
  // Returns OK on success, BUSY if there is a conflicting write, or other error
64
  // status for any unexpected errors.
65
  static Status CheckKeyForConflicts(DBImpl* db_impl,
66
                                     ColumnFamilyHandle* column_family,
67
                                     const std::string& key,
68
                                     SequenceNumber key_seq, bool cache_only);
69
70
  // For each key,SequenceNumber pair in the TransactionKeyMap, this function
71
  // will verify there have been no writes to the key in the db since that
72
  // sequence number.
73
  //
74
  // Returns OK on success, BUSY if there is a conflicting write, or other error
75
  // status for any unexpected errors.
76
  //
77
  // REQUIRED: this function should only be called on the write thread or if the
78
  // mutex is held.
79
  static Status CheckKeysForConflicts(DBImpl* db_impl,
80
                                      const TransactionKeyMap& keys,
81
                                      bool cache_only);
82
83
 private:
84
  static Status CheckKey(DBImpl* db_impl, SuperVersion* sv,
85
                         SequenceNumber earliest_seq, SequenceNumber key_seq,
86
                         const std::string& key, bool cache_only);
87
};
88
89
}  // namespace rocksdb
90
91
#endif  // ROCKSDB_LITE