]> git.proxmox.com Git - ceph.git/blob - ceph/src/rocksdb/utilities/transactions/lock/range/range_tree/lib/locktree/txnid_set.cc
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / rocksdb / utilities / transactions / lock / range / range_tree / lib / locktree / txnid_set.cc
1 /* -*- mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2 // vim: ft=cpp:expandtab:ts=8:sw=4:softtabstop=4:
3 #ifndef ROCKSDB_LITE
4 #ifndef OS_WIN
5 #ident "$Id$"
6 /*======
7 This file is part of PerconaFT.
8
9
10 Copyright (c) 2006, 2015, Percona and/or its affiliates. All rights reserved.
11
12 PerconaFT is free software: you can redistribute it and/or modify
13 it under the terms of the GNU General Public License, version 2,
14 as published by the Free Software Foundation.
15
16 PerconaFT is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
20
21 You should have received a copy of the GNU General Public License
22 along with PerconaFT. If not, see <http://www.gnu.org/licenses/>.
23
24 ----------------------------------------
25
26 PerconaFT is free software: you can redistribute it and/or modify
27 it under the terms of the GNU Affero General Public License, version 3,
28 as published by the Free Software Foundation.
29
30 PerconaFT is distributed in the hope that it will be useful,
31 but WITHOUT ANY WARRANTY; without even the implied warranty of
32 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33 GNU Affero General Public License for more details.
34
35 You should have received a copy of the GNU Affero General Public License
36 along with PerconaFT. If not, see <http://www.gnu.org/licenses/>.
37
38 ----------------------------------------
39
40 Licensed under the Apache License, Version 2.0 (the "License");
41 you may not use this file except in compliance with the License.
42 You may obtain a copy of the License at
43
44 http://www.apache.org/licenses/LICENSE-2.0
45
46 Unless required by applicable law or agreed to in writing, software
47 distributed under the License is distributed on an "AS IS" BASIS,
48 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
49 See the License for the specific language governing permissions and
50 limitations under the License.
51 ======= */
52
53 #ident \
54 "Copyright (c) 2006, 2015, Percona and/or its affiliates. All rights reserved."
55
56 #include "txnid_set.h"
57
58 #include "../db.h"
59
60 namespace toku {
61
62 int find_by_txnid(const TXNID &txnid_a, const TXNID &txnid_b);
63 int find_by_txnid(const TXNID &txnid_a, const TXNID &txnid_b) {
64 if (txnid_a < txnid_b) {
65 return -1;
66 } else if (txnid_a == txnid_b) {
67 return 0;
68 } else {
69 return 1;
70 }
71 }
72
73 void txnid_set::create(void) {
74 // lazily allocate the underlying omt, since it is common
75 // to create a txnid set and never put anything in it.
76 m_txnids.create_no_array();
77 }
78
79 void txnid_set::destroy(void) { m_txnids.destroy(); }
80
81 // Return true if the given transaction id is a member of the set.
82 // Otherwise, return false.
83 bool txnid_set::contains(TXNID txnid) const {
84 TXNID find_txnid;
85 int r = m_txnids.find_zero<TXNID, find_by_txnid>(txnid, &find_txnid, nullptr);
86 return r == 0 ? true : false;
87 }
88
89 // Add a given txnid to the set
90 void txnid_set::add(TXNID txnid) {
91 int r = m_txnids.insert<TXNID, find_by_txnid>(txnid, txnid, nullptr);
92 invariant(r == 0 || r == DB_KEYEXIST);
93 }
94
95 // Delete a given txnid from the set.
96 void txnid_set::remove(TXNID txnid) {
97 uint32_t idx;
98 int r = m_txnids.find_zero<TXNID, find_by_txnid>(txnid, nullptr, &idx);
99 if (r == 0) {
100 r = m_txnids.delete_at(idx);
101 invariant_zero(r);
102 }
103 }
104
105 // Return the size of the set
106 uint32_t txnid_set::size(void) const { return m_txnids.size(); }
107
108 // Get the ith id in the set, assuming that the set is sorted.
109 TXNID txnid_set::get(uint32_t i) const {
110 TXNID txnid;
111 int r = m_txnids.fetch(i, &txnid);
112 if (r == EINVAL) /* Shouldn't happen, avoid compiler warning */
113 return TXNID_NONE;
114 invariant_zero(r);
115 return txnid;
116 }
117
118 } /* namespace toku */
119 #endif // OS_WIN
120 #endif // ROCKSDB_LITE