]> git.proxmox.com Git - ceph.git/blob - ceph/src/rocksdb/db/read_callback.h
import 14.2.4 nautilus point release
[ceph.git] / ceph / src / rocksdb / db / read_callback.h
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
10 namespace rocksdb {
11
12 class ReadCallback {
13 public:
14 ReadCallback(SequenceNumber last_visible_seq)
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
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.
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
42 virtual void Refresh(SequenceNumber seq) { max_visible_seq_ = seq; }
43
44 // Refer to DBIter::CanReseekToSkip
45 virtual bool CanReseekToSkip() { return true; }
46
47 protected:
48 // The max visible seq, it is usually the snapshot but could be larger if
49 // transaction has its own writes written to db.
50 SequenceNumber max_visible_seq_ = kMaxSequenceNumber;
51 // Any seq less than min_uncommitted_ is committed.
52 const SequenceNumber min_uncommitted_ = kMinUnCommittedSeq;
53 };
54
55 } // namespace rocksdb