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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
use crate::server::lock_manager::waiter_manager;
use crate::server::lock_manager::waiter_manager::Callback;
use crate::storage::{txn::ProcessResult, types::StorageCallback};
use std::time::Duration;
use txn_types::TimeStamp;
#[derive(Clone, Copy, PartialEq, Debug, Default)]
pub struct Lock {
pub ts: TimeStamp,
pub hash: u64,
}
#[derive(Clone, Default)]
pub struct DiagnosticContext {
pub key: Vec<u8>,
pub resource_group_tag: Vec<u8>,
}
#[derive(Clone, Copy, PartialEq, Debug)]
pub enum WaitTimeout {
Default,
Millis(u64),
}
impl WaitTimeout {
pub fn into_duration_with_ceiling(self, ceiling: u64) -> Duration {
match self {
WaitTimeout::Default => Duration::from_millis(ceiling),
WaitTimeout::Millis(ms) if ms > ceiling => Duration::from_millis(ceiling),
WaitTimeout::Millis(ms) => Duration::from_millis(ms),
}
}
pub fn from_encoded(i: i64) -> Option<WaitTimeout> {
use std::cmp::Ordering::*;
match i.cmp(&0) {
Equal => Some(WaitTimeout::Default),
Less => None,
Greater => Some(WaitTimeout::Millis(i as u64)),
}
}
}
impl From<u64> for WaitTimeout {
fn from(i: u64) -> WaitTimeout {
WaitTimeout::Millis(i)
}
}
pub trait LockManager: Clone + Send + 'static {
fn wait_for(
&self,
start_ts: TimeStamp,
cb: StorageCallback,
pr: ProcessResult,
lock: Lock,
is_first_lock: bool,
timeout: Option<WaitTimeout>,
diag_ctx: DiagnosticContext,
);
fn wake_up(
&self,
lock_ts: TimeStamp,
hashes: Vec<u64>,
commit_ts: TimeStamp,
is_pessimistic_txn: bool,
);
fn has_waiter(&self) -> bool {
true
}
fn dump_wait_for_entries(&self, cb: waiter_manager::Callback);
}
#[derive(Clone)]
pub struct DummyLockManager;
impl LockManager for DummyLockManager {
fn wait_for(
&self,
_start_ts: TimeStamp,
_cb: StorageCallback,
_pr: ProcessResult,
_lock: Lock,
_is_first_lock: bool,
_wait_timeout: Option<WaitTimeout>,
_diag_ctx: DiagnosticContext,
) {
}
fn wake_up(
&self,
_lock_ts: TimeStamp,
_hashes: Vec<u64>,
_commit_ts: TimeStamp,
_is_pessimistic_txn: bool,
) {
}
fn dump_wait_for_entries(&self, cb: Callback) {
cb(vec![])
}
}