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 #ifdef ROCKSDB_LITE
9 #include <assert.h>
10 #endif  // ROCKSDB_LITE
11 
12 #include "utilities/transactions/write_prepared_txn_db.h"
13 
14 namespace ROCKSDB_NAMESPACE {
15 
16 #ifdef ROCKSDB_LITE
WritePreparedSnapshotChecker(WritePreparedTxnDB *)17 WritePreparedSnapshotChecker::WritePreparedSnapshotChecker(
18     WritePreparedTxnDB* /*txn_db*/) {}
19 
CheckInSnapshot(SequenceNumber,SequenceNumber) const20 SnapshotCheckerResult WritePreparedSnapshotChecker::CheckInSnapshot(
21     SequenceNumber /*sequence*/, SequenceNumber /*snapshot_sequence*/) const {
22   // Should never be called in LITE mode.
23   assert(false);
24   return SnapshotCheckerResult::kInSnapshot;
25 }
26 
27 #else
28 
29 WritePreparedSnapshotChecker::WritePreparedSnapshotChecker(
30     WritePreparedTxnDB* txn_db)
31     : txn_db_(txn_db){};
32 
33 SnapshotCheckerResult WritePreparedSnapshotChecker::CheckInSnapshot(
34     SequenceNumber sequence, SequenceNumber snapshot_sequence) const {
35   bool snapshot_released = false;
36   // TODO(myabandeh): set min_uncommitted
37   bool in_snapshot = txn_db_->IsInSnapshot(
38       sequence, snapshot_sequence, kMinUnCommittedSeq, &snapshot_released);
39   if (snapshot_released) {
40     return SnapshotCheckerResult::kSnapshotReleased;
41   }
42   return in_snapshot ? SnapshotCheckerResult::kInSnapshot
43                      : SnapshotCheckerResult::kNotInSnapshot;
44 }
45 
46 #endif  // ROCKSDB_LITE
47 DisableGCSnapshotChecker DisableGCSnapshotChecker::instance_;
48 
49 }  // namespace ROCKSDB_NAMESPACE
50