snapshot_checker.cc 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. #include "db/snapshot_checker.h"
  6. #ifdef ROCKSDB_LITE
  7. #include <assert.h>
  8. #endif // ROCKSDB_LITE
  9. #include "utilities/transactions/write_prepared_txn_db.h"
  10. namespace ROCKSDB_NAMESPACE {
  11. #ifdef ROCKSDB_LITE
  12. WritePreparedSnapshotChecker::WritePreparedSnapshotChecker(
  13. WritePreparedTxnDB* /*txn_db*/) {}
  14. SnapshotCheckerResult WritePreparedSnapshotChecker::CheckInSnapshot(
  15. SequenceNumber /*sequence*/, SequenceNumber /*snapshot_sequence*/) const {
  16. // Should never be called in LITE mode.
  17. assert(false);
  18. return SnapshotCheckerResult::kInSnapshot;
  19. }
  20. #else
  21. WritePreparedSnapshotChecker::WritePreparedSnapshotChecker(
  22. WritePreparedTxnDB* txn_db)
  23. : txn_db_(txn_db){};
  24. SnapshotCheckerResult WritePreparedSnapshotChecker::CheckInSnapshot(
  25. SequenceNumber sequence, SequenceNumber snapshot_sequence) const {
  26. bool snapshot_released = false;
  27. // TODO(myabandeh): set min_uncommitted
  28. bool in_snapshot = txn_db_->IsInSnapshot(
  29. sequence, snapshot_sequence, kMinUnCommittedSeq, &snapshot_released);
  30. if (snapshot_released) {
  31. return SnapshotCheckerResult::kSnapshotReleased;
  32. }
  33. return in_snapshot ? SnapshotCheckerResult::kInSnapshot
  34. : SnapshotCheckerResult::kNotInSnapshot;
  35. }
  36. #endif // ROCKSDB_LITE
  37. DisableGCSnapshotChecker DisableGCSnapshotChecker::instance_;
  38. } // namespace ROCKSDB_NAMESPACE