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