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
use crate::storage::kv::WriteData;
use crate::storage::lock_manager::LockManager;
use crate::storage::mvcc::{MvccTxn, SnapshotReader};
use crate::storage::txn::commands::{
Command, CommandExt, ReleasedLocks, ResponsePolicy, TypedCommand, WriteCommand, WriteContext,
WriteResult,
};
use crate::storage::txn::{cleanup, commit, Result};
use crate::storage::{ProcessResult, Snapshot};
use txn_types::{Key, TimeStamp};
command! {
ResolveLockLite:
cmd_ty => (),
display => "kv::resolve_lock_lite", (),
content => {
start_ts: TimeStamp,
commit_ts: TimeStamp,
resolve_keys: Vec<Key>,
}
}
impl CommandExt for ResolveLockLite {
ctx!();
tag!(resolve_lock_lite);
ts!(start_ts);
command_method!(is_sys_cmd, bool, true);
write_bytes!(resolve_keys: multiple);
gen_lock!(resolve_keys: multiple);
}
impl<S: Snapshot, L: LockManager> WriteCommand<S, L> for ResolveLockLite {
fn process_write(self, snapshot: S, context: WriteContext<'_, L>) -> Result<WriteResult> {
let mut txn = MvccTxn::new(self.start_ts, context.concurrency_manager);
let mut reader =
SnapshotReader::new(self.start_ts, snapshot, !self.ctx.get_not_fill_cache());
let rows = self.resolve_keys.len();
let mut released_locks = ReleasedLocks::new(self.start_ts, self.commit_ts);
for key in self.resolve_keys {
released_locks.push(if !self.commit_ts.is_zero() {
commit(&mut txn, &mut reader, key, self.commit_ts)?
} else {
cleanup(&mut txn, &mut reader, key, TimeStamp::zero(), false)?
});
}
released_locks.wake_up(context.lock_mgr);
context.statistics.add(&reader.take_statistics());
let write_data = WriteData::from_modifies(txn.into_modifies());
Ok(WriteResult {
ctx: self.ctx,
to_be_write: write_data,
rows,
pr: ProcessResult::Res,
lock_info: None,
lock_guards: vec![],
response_policy: ResponsePolicy::OnApplied,
})
}
}