/src/rocksdb/db/read_callback.h
Line | Count | Source |
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 "db/dbformat.h" |
9 | | #include "rocksdb/types.h" |
10 | | |
11 | | namespace ROCKSDB_NAMESPACE { |
12 | | |
13 | | struct MetadataReadBounds { |
14 | | // The snapshot-visible sequence and the upper bound sampled for this read. |
15 | | // Lookups scan through the upper bound but return data only through the |
16 | | // snapshot sequence. |
17 | | SequenceNumber read_snapshot_seq; |
18 | | SequenceNumber newer_version_upper_bound_seq; |
19 | | }; |
20 | | |
21 | | class ReadCallback { |
22 | | public: |
23 | | explicit ReadCallback(SequenceNumber last_visible_seq) |
24 | 22.0k | : max_visible_seq_(last_visible_seq) {} |
25 | | ReadCallback(SequenceNumber last_visible_seq, SequenceNumber min_uncommitted) |
26 | 0 | : max_visible_seq_(last_visible_seq), min_uncommitted_(min_uncommitted) {} |
27 | | |
28 | 22.0k | virtual ~ReadCallback() {} |
29 | | |
30 | | // Will be called to see if the seq number visible; if not it moves on to |
31 | | // the next seq number. |
32 | | virtual bool IsVisibleFullCheck(SequenceNumber seq) = 0; |
33 | | |
34 | 0 | inline bool IsVisible(SequenceNumber seq) { |
35 | 0 | assert(min_uncommitted_ > 0); |
36 | 0 | assert(min_uncommitted_ >= kMinUnCommittedSeq); |
37 | 0 | if (seq < min_uncommitted_) { // handles seq == 0 as well |
38 | 0 | assert(seq <= max_visible_seq_); |
39 | 0 | return true; |
40 | 0 | } else if (max_visible_seq_ < seq) { |
41 | 0 | assert(seq != 0); |
42 | 0 | return false; |
43 | 0 | } else { |
44 | 0 | assert(seq != 0); // already handled in the first if-then clause |
45 | 0 | return IsVisibleFullCheck(seq); |
46 | 0 | } |
47 | 0 | } |
48 | | |
49 | 0 | virtual const MetadataReadBounds* GetMetadataReadBounds() const { |
50 | 0 | return nullptr; |
51 | 0 | } |
52 | | |
53 | | virtual bool NeedToTrackNewerVersions( |
54 | 0 | const bool* /*per_key_result*/ = nullptr) const { |
55 | 0 | return false; |
56 | 0 | } |
57 | | |
58 | 0 | virtual bool IsNewerVisibleForMetadataRead(SequenceNumber /*seq*/) { |
59 | | // Metadata reads with custom visibility callbacks are unsupported. The |
60 | | // timestamp callback overrides this method for regular DB reads. |
61 | 0 | return false; |
62 | 0 | } |
63 | | |
64 | | virtual void MaybeRecordNewerVersion(SequenceNumber /*seq*/, |
65 | | ValueType /*type*/, |
66 | 0 | bool* /*per_key_result*/ = nullptr) {} |
67 | | |
68 | 0 | inline SequenceNumber max_visible_seq() { return max_visible_seq_; } |
69 | | |
70 | 0 | inline SequenceNumber min_uncommitted() const { return min_uncommitted_; } |
71 | | |
72 | | // Refresh to a more recent visible seq |
73 | 0 | virtual void Refresh(SequenceNumber seq) { max_visible_seq_ = seq; } |
74 | | |
75 | | protected: |
76 | | // The max visible seq, it is usually the snapshot but could be larger if |
77 | | // transaction has its own writes written to db. |
78 | | SequenceNumber max_visible_seq_ = kMaxSequenceNumber; |
79 | | // Any seq less than min_uncommitted_ is committed. |
80 | | const SequenceNumber min_uncommitted_ = kMinUnCommittedSeq; |
81 | | }; |
82 | | |
83 | | } // namespace ROCKSDB_NAMESPACE |