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).
7 #include "rocksdb/types.h"
11 enum class SnapshotCheckerResult
: int {
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,
19 // Callback class that control GC of duplicate keys in flush/compaction.
20 class SnapshotChecker
{
22 virtual ~SnapshotChecker() {}
23 virtual SnapshotCheckerResult
CheckInSnapshot(
24 SequenceNumber sequence
, SequenceNumber snapshot_sequence
) const = 0;
27 class DisableGCSnapshotChecker
: public SnapshotChecker
{
29 virtual ~DisableGCSnapshotChecker() {}
30 virtual SnapshotCheckerResult
CheckInSnapshot(
31 SequenceNumber
/*sequence*/,
32 SequenceNumber
/*snapshot_sequence*/) const override
{
33 // By returning kNotInSnapshot, we prevent all the values from being GCed
34 return SnapshotCheckerResult::kNotInSnapshot
;
36 static DisableGCSnapshotChecker
* Instance() { return &instance_
; }
39 static DisableGCSnapshotChecker instance_
;
40 explicit DisableGCSnapshotChecker() {}
43 class WritePreparedTxnDB
;
45 // Callback class created by WritePreparedTxnDB to check if a key
46 // is visible by a snapshot.
47 class WritePreparedSnapshotChecker
: public SnapshotChecker
{
49 explicit WritePreparedSnapshotChecker(WritePreparedTxnDB
* txn_db
);
50 virtual ~WritePreparedSnapshotChecker() {}
52 virtual SnapshotCheckerResult
CheckInSnapshot(
53 SequenceNumber sequence
, SequenceNumber snapshot_sequence
) const override
;
57 const WritePreparedTxnDB
* const txn_db_
;
58 #endif // !ROCKSDB_LITE
61 } // namespace rocksdb