]> git.proxmox.com Git - ceph.git/blame - ceph/src/rocksdb/utilities/transactions/transaction_util.h
update sources to ceph Nautilus 14.2.1
[ceph.git] / ceph / src / rocksdb / utilities / transactions / transaction_util.h
CommitLineData
7c673cae 1// Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
11fdf7f2
TL
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).
7c673cae
FG
5
6#pragma once
7
8#ifndef ROCKSDB_LITE
9
10#include <string>
11#include <unordered_map>
12
11fdf7f2
TL
13#include "db/read_callback.h"
14
7c673cae
FG
15#include "rocksdb/db.h"
16#include "rocksdb/slice.h"
17#include "rocksdb/status.h"
18#include "rocksdb/types.h"
19
20namespace rocksdb {
21
22struct TransactionKeyMapInfo {
23 // Earliest sequence number that is relevant to this transaction for this key
24 SequenceNumber seq;
25
26 uint32_t num_writes;
27 uint32_t num_reads;
28
29 bool exclusive;
30
31 explicit TransactionKeyMapInfo(SequenceNumber seq_no)
32 : seq(seq_no), num_writes(0), num_reads(0), exclusive(false) {}
33};
34
35using TransactionKeyMap =
36 std::unordered_map<uint32_t,
37 std::unordered_map<std::string, TransactionKeyMapInfo>>;
38
39class DBImpl;
40struct SuperVersion;
41class WriteBatchWithIndex;
42
43class TransactionUtil {
44 public:
11fdf7f2 45 // Verifies there have been no commits to this key in the db since this
7c673cae
FG
46 // sequence number.
47 //
48 // If cache_only is true, then this function will not attempt to read any
49 // SST files. This will make it more likely this function will
50 // return an error if it is unable to determine if there are any conflicts.
51 //
52 // Returns OK on success, BUSY if there is a conflicting write, or other error
53 // status for any unexpected errors.
54 static Status CheckKeyForConflicts(DBImpl* db_impl,
55 ColumnFamilyHandle* column_family,
56 const std::string& key,
11fdf7f2
TL
57 SequenceNumber snap_seq, bool cache_only,
58 ReadCallback* snap_checker = nullptr);
7c673cae
FG
59
60 // For each key,SequenceNumber pair in the TransactionKeyMap, this function
61 // will verify there have been no writes to the key in the db since that
62 // sequence number.
63 //
64 // Returns OK on success, BUSY if there is a conflicting write, or other error
65 // status for any unexpected errors.
66 //
67 // REQUIRED: this function should only be called on the write thread or if the
68 // mutex is held.
69 static Status CheckKeysForConflicts(DBImpl* db_impl,
70 const TransactionKeyMap& keys,
71 bool cache_only);
72
73 private:
74 static Status CheckKey(DBImpl* db_impl, SuperVersion* sv,
11fdf7f2
TL
75 SequenceNumber earliest_seq, SequenceNumber snap_seq,
76 const std::string& key, bool cache_only,
77 ReadCallback* snap_checker = nullptr);
7c673cae
FG
78};
79
80} // namespace rocksdb
81
82#endif // ROCKSDB_LITE