2017-10-06 17:26:38 +00:00
|
|
|
// Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
|
|
|
|
// This source code is licensed under both the GPLv2 (found in the
|
|
|
|
// COPYING file in the root directory) and Apache 2.0 License
|
|
|
|
// (found in the LICENSE.Apache file in the root directory).
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
#include "rocksdb/types.h"
|
|
|
|
|
2020-02-20 20:07:53 +00:00
|
|
|
namespace ROCKSDB_NAMESPACE {
|
2017-10-06 17:26:38 +00:00
|
|
|
|
2019-01-16 17:48:10 +00:00
|
|
|
enum class SnapshotCheckerResult : int {
|
|
|
|
kInSnapshot = 0,
|
|
|
|
kNotInSnapshot = 1,
|
|
|
|
// In case snapshot is released and the checker has no clue whether
|
|
|
|
// the given sequence is visible to the snapshot.
|
|
|
|
kSnapshotReleased = 2,
|
|
|
|
};
|
|
|
|
|
|
|
|
// Callback class that control GC of duplicate keys in flush/compaction.
|
2017-10-18 16:09:31 +00:00
|
|
|
class SnapshotChecker {
|
|
|
|
public:
|
|
|
|
virtual ~SnapshotChecker() {}
|
2019-01-16 17:48:10 +00:00
|
|
|
virtual SnapshotCheckerResult CheckInSnapshot(
|
|
|
|
SequenceNumber sequence, SequenceNumber snapshot_sequence) const = 0;
|
2017-10-18 16:09:31 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class DisableGCSnapshotChecker : public SnapshotChecker {
|
|
|
|
public:
|
|
|
|
virtual ~DisableGCSnapshotChecker() {}
|
2019-01-16 17:48:10 +00:00
|
|
|
virtual SnapshotCheckerResult CheckInSnapshot(
|
2018-08-23 17:04:10 +00:00
|
|
|
SequenceNumber /*sequence*/,
|
|
|
|
SequenceNumber /*snapshot_sequence*/) const override {
|
2019-01-16 17:48:10 +00:00
|
|
|
// By returning kNotInSnapshot, we prevent all the values from being GCed
|
|
|
|
return SnapshotCheckerResult::kNotInSnapshot;
|
2017-10-18 16:09:31 +00:00
|
|
|
}
|
2022-05-17 16:39:22 +00:00
|
|
|
static DisableGCSnapshotChecker* Instance();
|
2017-10-18 16:09:31 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
explicit DisableGCSnapshotChecker() {}
|
|
|
|
};
|
|
|
|
|
2017-10-06 17:26:38 +00:00
|
|
|
class WritePreparedTxnDB;
|
|
|
|
|
|
|
|
// Callback class created by WritePreparedTxnDB to check if a key
|
|
|
|
// is visible by a snapshot.
|
2017-10-18 16:09:31 +00:00
|
|
|
class WritePreparedSnapshotChecker : public SnapshotChecker {
|
2017-10-06 17:26:38 +00:00
|
|
|
public:
|
2017-10-18 16:09:31 +00:00
|
|
|
explicit WritePreparedSnapshotChecker(WritePreparedTxnDB* txn_db);
|
|
|
|
virtual ~WritePreparedSnapshotChecker() {}
|
2017-10-06 17:26:38 +00:00
|
|
|
|
2019-01-16 17:48:10 +00:00
|
|
|
virtual SnapshotCheckerResult CheckInSnapshot(
|
|
|
|
SequenceNumber sequence, SequenceNumber snapshot_sequence) const override;
|
2017-10-06 17:26:38 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
const WritePreparedTxnDB* const txn_db_;
|
|
|
|
};
|
|
|
|
|
2020-02-20 20:07:53 +00:00
|
|
|
} // namespace ROCKSDB_NAMESPACE
|