snapshot_checker.h 2.1 KB

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