1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
use crate::utils::MonotonicSeq;
/// Oracle is a trait that centralizes the generation & maintenance of various
/// sequence numbers. These sequence numbers are mostly related to the lifecycle
/// of a transaction commit.
pub(crate) trait Oracle: Send + Sync + 'static {
/// The sequence number of the most recent write that has been fully committed.
/// For reads with dirty=false, the maximum visible sequence number is capped
/// at last_committed_seq.
fn last_committed_seq(&self) -> u64;
/// The sequence number of the most recent write that has been fully durable
/// flushed to the remote storage.
fn last_remote_persisted_seq(&self) -> u64;
}
pub(crate) struct DbOracle {
pub(crate) last_seq: MonotonicSeq,
pub(crate) last_committed_seq: MonotonicSeq,
pub(crate) last_remote_persisted_seq: MonotonicSeq,
}
impl DbOracle {
pub(crate) fn new(
last_seq: MonotonicSeq,
last_committed_seq: MonotonicSeq,
last_remote_persisted_seq: MonotonicSeq,
) -> Self {
Self {
last_seq,
last_committed_seq,
last_remote_persisted_seq,
}
}
}
impl Oracle for DbOracle {
fn last_committed_seq(&self) -> u64 {
self.last_committed_seq.load()
}
fn last_remote_persisted_seq(&self) -> u64 {
self.last_remote_persisted_seq.load()
}
}
pub(crate) struct DbReaderOracle {
pub(crate) last_remote_persisted_seq: MonotonicSeq,
}
impl DbReaderOracle {
/// for the read-only db instance (DbReader), only the last remote persisted sequence number
/// is needed to be tracked, and last_seq and last_remote_persisted_seq are considered to be
/// the same as last_committed_seq.
pub(crate) fn new(last_remote_persisted_seq: MonotonicSeq) -> Self {
Self {
last_remote_persisted_seq,
}
}
}
impl Oracle for DbReaderOracle {
fn last_committed_seq(&self) -> u64 {
self.last_remote_persisted_seq.load()
}
fn last_remote_persisted_seq(&self) -> u64 {
self.last_remote_persisted_seq.load()
}
}