/src/rocksdb/utilities/transactions/snapshot_checker.cc
Line | Count | Source |
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). |
5 | | |
6 | | #include "db/snapshot_checker.h" |
7 | | |
8 | | #include "port/lang.h" |
9 | | #include "utilities/transactions/write_prepared_txn_db.h" |
10 | | |
11 | | namespace ROCKSDB_NAMESPACE { |
12 | | |
13 | | WritePreparedSnapshotChecker::WritePreparedSnapshotChecker( |
14 | | WritePreparedTxnDB* txn_db) |
15 | 0 | : txn_db_(txn_db) {} |
16 | | |
17 | | SnapshotCheckerResult WritePreparedSnapshotChecker::CheckInSnapshot( |
18 | 0 | SequenceNumber sequence, SequenceNumber snapshot_sequence) const { |
19 | 0 | bool snapshot_released = false; |
20 | | // TODO(myabandeh): set min_uncommitted |
21 | 0 | bool in_snapshot = txn_db_->IsInSnapshot( |
22 | 0 | sequence, snapshot_sequence, kMinUnCommittedSeq, &snapshot_released); |
23 | 0 | if (snapshot_released) { |
24 | 0 | return SnapshotCheckerResult::kSnapshotReleased; |
25 | 0 | } |
26 | 0 | return in_snapshot ? SnapshotCheckerResult::kInSnapshot |
27 | 0 | : SnapshotCheckerResult::kNotInSnapshot; |
28 | 0 | } |
29 | | |
30 | 0 | DisableGCSnapshotChecker* DisableGCSnapshotChecker::Instance() { |
31 | 0 | STATIC_AVOID_DESTRUCTION(DisableGCSnapshotChecker, instance); |
32 | 0 | return &instance; |
33 | 0 | } |
34 | | |
35 | | bool DataIsDefinitelyInSnapshot(SequenceNumber seqno, SequenceNumber snapshot, |
36 | 3.69k | const SnapshotChecker* snapshot_checker) { |
37 | 3.69k | return ((seqno) <= (snapshot) && |
38 | 3.69k | (snapshot_checker == nullptr || |
39 | 0 | LIKELY(snapshot_checker->CheckInSnapshot((seqno), (snapshot)) == |
40 | 3.69k | SnapshotCheckerResult::kInSnapshot))); |
41 | 3.69k | } |
42 | | |
43 | | bool DataIsDefinitelyNotInSnapshot(SequenceNumber seqno, |
44 | | SequenceNumber snapshot, |
45 | 0 | const SnapshotChecker* snapshot_checker) { |
46 | 0 | return ((seqno) > (snapshot) || |
47 | 0 | (snapshot_checker != nullptr && |
48 | 0 | UNLIKELY(snapshot_checker->CheckInSnapshot((seqno), (snapshot)) == |
49 | 0 | SnapshotCheckerResult::kNotInSnapshot))); |
50 | 0 | } |
51 | | } // namespace ROCKSDB_NAMESPACE |