cockroachdb / cockroachdb/cockroach
mvcc scanner: scan key limit does not bound work done when encountering lock conflicts
- Dominant language
- Go
- Stars
- 32.5k
- Forks
- 4.1k
- PR merge metrics
- PR metrics pending
Description
When an MVCC scan request specifies a key limit (e.g. `MaxKeys=300`), the expectation is that the amount of work done is roughly proportional to that limit. However, when the scanner encounters conflicting intents/locks, they don't count toward `MaxKeys` — the scanner keeps going, collecting up to `maxLockConflicts` (default 5,000) intents before stopping.
In `pebble_mvcc_scanner.go`, when the scanner encounters a conflicting intent (case 11, ~line 1018), it adds the intent to its buffer and returns `(ok=true, added=false)`. Because `added=false`, the key isn't counted toward the `maxKeys` limit. The scanner continues looking for readable keys, potentially scanning thousands of locked keys before either:
1. Finding enough readable keys to satisfy `maxKeys`, or
2. Hitting the `maxLockConflicts` cap (default 5,000) and returning `RESUME_INTENT_LIMIT`
The worst case is a fully contended key range — the scanner scans through all 5,000 intents, finds zero readable keys, and returns a `LockConflictError`.
Jira issue: CRDB-64682
Contributor guide
Assessment
This issue has not been assessed yet.