kvserver: serve reads on outgoing leaseholder and improve lease transfer latching #81161
Labels
A-kv-distribution
Relating to rebalancing and leasing.
A-kv-transactions
Relating to MVCC and the transactional model.
C-enhancement
Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception)
C-performance
Perf of queries or internals. Solution not expected to change functional behavior.
no-issue-activity
T-kv
KV Team
X-stale
Is your feature request related to a problem? Please describe.
Consider the following trace (from an internal escalation: https://github.com/cockroachlabs/support/issues/1533):
What we're seeing is a read wanting to grab a read latch at timestamp
1651156511.195997554,0
, the lease is transferred away, with start time of1651156512.469961984,0
. We could've served the read at the now-old leaseholder, but chose not to do so. When we load-balance leases away from nodes running hot (what we're seeing above), lease transfers can be more disruptive than they need to be WRT the tail -- here we'd bubble the error all the way back up to the distsender and retry at the new leaseholder, incurring an additional RTT that shows up prominently in the tail (especially if the range is experiencing a large volume of traffic).Describe the solution you'd like
Serving these reads when safe to do so. While here, we could also not acquire a non-MVCC write latch over the entire keyspan when evaluating a lease transfer (instead grabbing a write latch at the start time of the new lease). The non-MVCC write latch can be disruptive: the FIFO queuing you get for latch acquisitions + the non-MVCC latch declaration lease transfers (common during periods of high load) add to give us the property that concurrency over that keyspace will slowly drop down 1 until the lease transfer is evaluated, and then back up to what it was before. This is also bad from a latency perspective — requests that were serialized after the lease transfer have to wait for the last of the requests serialized before it to have finished, the lease transfer itself, before it’s able to start evaluation. We've noted this possibility here:
cockroach/pkg/kv/kvserver/batcheval/cmd_lease_transfer.go
Lines 46 to 55 in 609825e
As of d676d7e we've started giving non-transactional reads uncertainty timestamps, so we could improve our latching story now. This would not only prevent lease transfers from blocking earlier reads, it would also prevent earlier (potentially long-running) reads from blocking lease transfers.
Additional Context
Aside: we have a similar problem to the non-MVCC lease acquisitions for lease transfers but for split requests: #22348. The effect on observable latencies and queueing behaviour apply similarly.
+cc @cockroachdb/kv-notifications.
Jira issue: CRDB-15115
The text was updated successfully, but these errors were encountered: