]> git.proxmox.com Git - ceph.git/blame - ceph/src/rocksdb/db/snapshot_checker.h
import quincy beta 17.1.0
[ceph.git] / ceph / src / rocksdb / db / snapshot_checker.h
CommitLineData
11fdf7f2
TL
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
f67539c2 9namespace ROCKSDB_NAMESPACE {
11fdf7f2 10
494da23a
TL
11enum 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.
11fdf7f2
TL
20class SnapshotChecker {
21 public:
22 virtual ~SnapshotChecker() {}
494da23a
TL
23 virtual SnapshotCheckerResult CheckInSnapshot(
24 SequenceNumber sequence, SequenceNumber snapshot_sequence) const = 0;
11fdf7f2
TL
25};
26
27class DisableGCSnapshotChecker : public SnapshotChecker {
28 public:
29 virtual ~DisableGCSnapshotChecker() {}
494da23a 30 virtual SnapshotCheckerResult CheckInSnapshot(
11fdf7f2
TL
31 SequenceNumber /*sequence*/,
32 SequenceNumber /*snapshot_sequence*/) const override {
494da23a
TL
33 // By returning kNotInSnapshot, we prevent all the values from being GCed
34 return SnapshotCheckerResult::kNotInSnapshot;
11fdf7f2
TL
35 }
36 static DisableGCSnapshotChecker* Instance() { return &instance_; }
37
38 protected:
39 static DisableGCSnapshotChecker instance_;
40 explicit DisableGCSnapshotChecker() {}
41};
42
43class WritePreparedTxnDB;
44
45// Callback class created by WritePreparedTxnDB to check if a key
46// is visible by a snapshot.
47class WritePreparedSnapshotChecker : public SnapshotChecker {
48 public:
49 explicit WritePreparedSnapshotChecker(WritePreparedTxnDB* txn_db);
50 virtual ~WritePreparedSnapshotChecker() {}
51
494da23a
TL
52 virtual SnapshotCheckerResult CheckInSnapshot(
53 SequenceNumber sequence, SequenceNumber snapshot_sequence) const override;
11fdf7f2
TL
54
55 private:
56#ifndef ROCKSDB_LITE
57 const WritePreparedTxnDB* const txn_db_;
58#endif // !ROCKSDB_LITE
59};
60
f67539c2 61} // namespace ROCKSDB_NAMESPACE