]> git.proxmox.com Git - ceph.git/blame - ceph/src/rocksdb/db/read_callback.h
import quincy beta 17.1.0
[ceph.git] / ceph / src / rocksdb / db / read_callback.h
CommitLineData
11fdf7f2
TL
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
6#pragma once
7
8#include "rocksdb/types.h"
9
f67539c2 10namespace ROCKSDB_NAMESPACE {
11fdf7f2
TL
11
12class ReadCallback {
13 public:
20effc67 14 explicit ReadCallback(SequenceNumber last_visible_seq)
494da23a
TL
15 : max_visible_seq_(last_visible_seq) {}
16 ReadCallback(SequenceNumber last_visible_seq, SequenceNumber min_uncommitted)
17 : max_visible_seq_(last_visible_seq), min_uncommitted_(min_uncommitted) {}
18
11fdf7f2
TL
19 virtual ~ReadCallback() {}
20
21 // Will be called to see if the seq number visible; if not it moves on to
22 // the next seq number.
494da23a
TL
23 virtual bool IsVisibleFullCheck(SequenceNumber seq) = 0;
24
25 inline bool IsVisible(SequenceNumber seq) {
26 assert(min_uncommitted_ > 0);
27 assert(min_uncommitted_ >= kMinUnCommittedSeq);
28 if (seq < min_uncommitted_) { // handles seq == 0 as well
29 assert(seq <= max_visible_seq_);
30 return true;
31 } else if (max_visible_seq_ < seq) {
32 assert(seq != 0);
33 return false;
34 } else {
35 assert(seq != 0); // already handled in the first if-then clause
36 return IsVisibleFullCheck(seq);
37 }
38 }
39
40 inline SequenceNumber max_visible_seq() { return max_visible_seq_; }
41
f67539c2 42 // Refresh to a more recent visible seq
494da23a
TL
43 virtual void Refresh(SequenceNumber seq) { max_visible_seq_ = seq; }
44
494da23a
TL
45 protected:
46 // The max visible seq, it is usually the snapshot but could be larger if
47 // transaction has its own writes written to db.
48 SequenceNumber max_visible_seq_ = kMaxSequenceNumber;
49 // Any seq less than min_uncommitted_ is committed.
50 const SequenceNumber min_uncommitted_ = kMinUnCommittedSeq;
11fdf7f2
TL
51};
52
f67539c2 53} // namespace ROCKSDB_NAMESPACE