Skip to content

scheduler can read locks by rocksdb cursor #18208

@you06

Description

@you06

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.

Image

Image

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.

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

let mut reader = ReaderWithStats::new(
SnapshotReader::new_with_ctx(TimeStamp::zero(), snapshot, &ctx),
context.statistics,
);

let mut reader = ReaderWithStats::new(
SnapshotReader::new_with_ctx(self.lock_ts, snapshot, &self.ctx),
context.statistics,
);

let mut reader = ReaderWithStats::new(
SnapshotReader::new_with_ctx(self.start_ts, snapshot, &self.ctx),
context.statistics,
);

let mut reader = ReaderWithStats::new(
SnapshotReader::new_with_ctx(self.start_ts, snapshot, &self.ctx),
context.statistics,
);

let mut reader = ReaderWithStats::new(
SnapshotReader::new_with_ctx(start_ts, snapshot, &ctx),
context.statistics,
);

let mut reader = ReaderWithStats::new(
SnapshotReader::new_with_ctx(self.start_ts, snapshot, &self.ctx),
context.statistics,
);

let mut reader = ReaderWithStats::new(
SnapshotReader::new_with_ctx(self.start_ts, snapshot, &self.ctx),
context.statistics,
);

Metadata

Metadata

Assignees

No one assigned

    Labels

    type/enhancementThe issue or PR belongs to an enhancement.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions