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