Coverage Report

Created: 2025-10-26 07:13

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/rocksdb/db/snapshot_checker.h
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
#pragma once
7
#include "rocksdb/types.h"
8
9
namespace ROCKSDB_NAMESPACE {
10
11
enum class SnapshotCheckerResult : int {
12
  kInSnapshot = 0,
13
  kNotInSnapshot = 1,
14
  // In case snapshot is released and the checker has no clue whether
15
  // the given sequence is visible to the snapshot.
16
  kSnapshotReleased = 2,
17
};
18
19
// Callback class that control GC of duplicate keys in flush/compaction.
20
class SnapshotChecker {
21
 public:
22
0
  virtual ~SnapshotChecker() {}
23
  virtual SnapshotCheckerResult CheckInSnapshot(
24
      SequenceNumber sequence, SequenceNumber snapshot_sequence) const = 0;
25
};
26
27
class DisableGCSnapshotChecker : public SnapshotChecker {
28
 public:
29
0
  virtual ~DisableGCSnapshotChecker() {}
30
  SnapshotCheckerResult CheckInSnapshot(
31
      SequenceNumber /*sequence*/,
32
0
      SequenceNumber /*snapshot_sequence*/) const override {
33
    // By returning kNotInSnapshot, we prevent all the values from being GCed
34
0
    return SnapshotCheckerResult::kNotInSnapshot;
35
0
  }
36
  static DisableGCSnapshotChecker* Instance();
37
38
 protected:
39
0
  explicit DisableGCSnapshotChecker() {}
40
};
41
42
class WritePreparedTxnDB;
43
44
// Callback class created by WritePreparedTxnDB to check if a key
45
// is visible by a snapshot.
46
class WritePreparedSnapshotChecker : public SnapshotChecker {
47
 public:
48
  explicit WritePreparedSnapshotChecker(WritePreparedTxnDB* txn_db);
49
0
  virtual ~WritePreparedSnapshotChecker() {}
50
51
  SnapshotCheckerResult CheckInSnapshot(
52
      SequenceNumber sequence, SequenceNumber snapshot_sequence) const override;
53
54
 private:
55
  const WritePreparedTxnDB* const txn_db_;
56
};
57
58
bool DataIsDefinitelyInSnapshot(SequenceNumber seqno, SequenceNumber snapshot,
59
                                const SnapshotChecker* snapshot_checker);
60
61
bool DataIsDefinitelyNotInSnapshot(SequenceNumber seqno,
62
                                   SequenceNumber snapshot,
63
                                   const SnapshotChecker* snapshot_checker);
64
65
}  // namespace ROCKSDB_NAMESPACE