2017-09-11 15:58:52 +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
|
|
|
|
|
2021-09-10 16:59:05 +00:00
|
|
|
#include "db/dbformat.h"
|
2017-09-11 15:58:52 +00:00
|
|
|
#include "rocksdb/types.h"
|
|
|
|
|
2020-02-20 20:07:53 +00:00
|
|
|
namespace ROCKSDB_NAMESPACE {
|
2017-09-11 15:58:52 +00:00
|
|
|
|
|
|
|
class ReadCallback {
|
|
|
|
public:
|
2020-08-15 02:19:36 +00:00
|
|
|
explicit ReadCallback(SequenceNumber last_visible_seq)
|
2019-04-02 21:43:03 +00:00
|
|
|
: max_visible_seq_(last_visible_seq) {}
|
|
|
|
ReadCallback(SequenceNumber last_visible_seq, SequenceNumber min_uncommitted)
|
|
|
|
: max_visible_seq_(last_visible_seq), min_uncommitted_(min_uncommitted) {}
|
2019-02-27 00:52:20 +00:00
|
|
|
|
2017-09-11 15:58:52 +00:00
|
|
|
virtual ~ReadCallback() {}
|
|
|
|
|
2018-06-27 19:05:29 +00:00
|
|
|
// Will be called to see if the seq number visible; if not it moves on to
|
|
|
|
// the next seq number.
|
2019-02-27 00:52:20 +00:00
|
|
|
virtual bool IsVisibleFullCheck(SequenceNumber seq) = 0;
|
|
|
|
|
|
|
|
inline bool IsVisible(SequenceNumber seq) {
|
2019-04-02 21:43:03 +00:00
|
|
|
assert(min_uncommitted_ > 0);
|
|
|
|
assert(min_uncommitted_ >= kMinUnCommittedSeq);
|
|
|
|
if (seq < min_uncommitted_) { // handles seq == 0 as well
|
|
|
|
assert(seq <= max_visible_seq_);
|
2019-02-27 00:52:20 +00:00
|
|
|
return true;
|
2019-04-02 21:43:03 +00:00
|
|
|
} else if (max_visible_seq_ < seq) {
|
|
|
|
assert(seq != 0);
|
2019-02-27 00:52:20 +00:00
|
|
|
return false;
|
|
|
|
} else {
|
2019-04-02 21:43:03 +00:00
|
|
|
assert(seq != 0); // already handled in the first if-then clause
|
2019-02-27 00:52:20 +00:00
|
|
|
return IsVisibleFullCheck(seq);
|
|
|
|
}
|
|
|
|
}
|
2018-06-27 19:05:29 +00:00
|
|
|
|
2019-04-02 21:43:03 +00:00
|
|
|
inline SequenceNumber max_visible_seq() { return max_visible_seq_; }
|
|
|
|
|
2019-04-12 21:36:36 +00:00
|
|
|
// Refresh to a more recent visible seq
|
2019-04-02 21:43:03 +00:00
|
|
|
virtual void Refresh(SequenceNumber seq) { max_visible_seq_ = seq; }
|
|
|
|
|
2019-02-27 00:52:20 +00:00
|
|
|
protected:
|
2019-04-02 21:43:03 +00:00
|
|
|
// The max visible seq, it is usually the snapshot but could be larger if
|
|
|
|
// transaction has its own writes written to db.
|
|
|
|
SequenceNumber max_visible_seq_ = kMaxSequenceNumber;
|
2019-02-27 00:52:20 +00:00
|
|
|
// Any seq less than min_uncommitted_ is committed.
|
2019-04-02 21:43:03 +00:00
|
|
|
const SequenceNumber min_uncommitted_ = kMinUnCommittedSeq;
|
2017-09-11 15:58:52 +00:00
|
|
|
};
|
|
|
|
|
2020-02-20 20:07:53 +00:00
|
|
|
} // namespace ROCKSDB_NAMESPACE
|