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, ReadCallback(SequenceNumber last_visible_seq)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 ~ReadCallback()19// Callback class that control GC of duplicate keys in flush/compaction. 20 class SnapshotChecker { 21 public: 22 virtual ~SnapshotChecker() {} 23 virtual SnapshotCheckerResult CheckInSnapshot( 24 SequenceNumber sequence, SequenceNumber snapshot_sequence) const = 0; 25 }; 26 27 class DisableGCSnapshotChecker : public SnapshotChecker { 28 public: 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; 35 } 36 static DisableGCSnapshotChecker* Instance() { return &instance_; } 37 38 protected: 39 static DisableGCSnapshotChecker instance_; max_visible_seq()40 explicit DisableGCSnapshotChecker() {} 41 }; 42 Refresh(SequenceNumber seq)43class WritePreparedTxnDB; 44 45 // Callback class created by WritePreparedTxnDB to check if a key 46 // is visible by a snapshot. 47 class WritePreparedSnapshotChecker : public SnapshotChecker { 48 public: 49 explicit WritePreparedSnapshotChecker(WritePreparedTxnDB* txn_db); 50 virtual ~WritePreparedSnapshotChecker() {} 51 52 virtual SnapshotCheckerResult CheckInSnapshot( 53 SequenceNumber sequence, SequenceNumber snapshot_sequence) const override; 54 55 private: 56 #ifndef ROCKSDB_LITE 57 const WritePreparedTxnDB* const txn_db_; 58 #endif // !ROCKSDB_LITE 59 }; 60 61 } // namespace ROCKSDB_NAMESPACE 62