-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Description
Development Task
When handling commit and resolve_lock operations, TiKV reads the related locks before writing. The read is performed through multiple individual get operations, which results in numerous slow seek operations in RocksDB. Below is a CPU profile and resolve-lock scheduler metrics during the lock resolution period.
The root cause of this behavior is that the reader is not running in scan mode (self.lock_cursor is none). So the near_seek operation doesn't work.
tikv/src/storage/mvcc/reader/reader.rs
Lines 243 to 254 in caf82d2
| let res = if let Some(ref mut cursor) = self.lock_cursor { | |
| match cursor.get(key, &mut self.statistics.lock)? { | |
| Some(v) => Some(Lock::parse(v)?), | |
| None => None, | |
| } | |
| } else { | |
| self.statistics.lock.get += 1; | |
| match self.snapshot.get_cf(CF_LOCK, key)? { | |
| Some(v) => Some(Lock::parse(&v)?), | |
| None => None, | |
| } | |
| }; |
Usages need to be optimized
tikv/src/storage/txn/commands/resolve_lock.rs
Lines 86 to 89 in caf82d2
| let mut reader = ReaderWithStats::new( | |
| SnapshotReader::new_with_ctx(TimeStamp::zero(), snapshot, &ctx), | |
| context.statistics, | |
| ); |
tikv/src/storage/txn/commands/commit.rs
Lines 58 to 61 in caf82d2
| let mut reader = ReaderWithStats::new( | |
| SnapshotReader::new_with_ctx(self.lock_ts, snapshot, &self.ctx), | |
| context.statistics, | |
| ); |
tikv/src/storage/txn/commands/prewrite.rs
Lines 540 to 543 in caf82d2
| let mut reader = ReaderWithStats::new( | |
| SnapshotReader::new_with_ctx(self.start_ts, snapshot, &self.ctx), | |
| context.statistics, | |
| ); |
tikv/src/storage/txn/commands/rollback.rs
Lines 53 to 56 in f0fc694
| let mut reader = ReaderWithStats::new( | |
| SnapshotReader::new_with_ctx(self.start_ts, snapshot, &self.ctx), | |
| context.statistics, | |
| ); |
tikv/src/storage/txn/commands/acquire_pessimistic_lock.rs
Lines 91 to 94 in f0fc694
| let mut reader = ReaderWithStats::new( | |
| SnapshotReader::new_with_ctx(start_ts, snapshot, &ctx), | |
| context.statistics, | |
| ); |
tikv/src/storage/txn/commands/check_secondary_locks.rs
Lines 155 to 158 in f0fc694
| let mut reader = ReaderWithStats::new( | |
| SnapshotReader::new_with_ctx(self.start_ts, snapshot, &self.ctx), | |
| context.statistics, | |
| ); |
tikv/src/storage/txn/commands/flush.rs
Lines 79 to 82 in f0fc694
| let mut reader = ReaderWithStats::new( | |
| SnapshotReader::new_with_ctx(self.start_ts, snapshot, &self.ctx), | |
| context.statistics, | |
| ); |

