Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

kv: replicate unreplicated locks before lease transfers, splits, and merges #75456

Open
nvanbenschoten opened this issue Jan 24, 2022 · 2 comments
Assignees
Labels
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) O-support Would prevent or help troubleshoot a customer escalation - bugs, missing observability/tooling, docs P-3 Issues/test failures with no fix SLA T-kv KV Team

Comments

@nvanbenschoten
Copy link
Member

nvanbenschoten commented Jan 24, 2022

Currently, a cooperative lease transfer discards the entire lock table on the outgoing leaseholder and rebuilds the lock table on the incoming leaseholder lazily. This means that any unreplicated lock on the outgoing leaseholder will be lost. This causes the best-effort mutual exclusion provided by unreplicated locks (those acquired using implicit or explicit SELECT ... FOR UPDATE) to be less reliable. This can in turn lead to transaction retries and other surprising behavior.

To avoid this, we could ship the unreplicated locks from the outgoing leaseholder to the incoming leaseholder through the lease transfer Raft proposal. This would be similar to #60521, where we started including more information in the handoff between leaseholders during cooperative lease changes.

If we make this change, we will also want to consider the corresponding situations with range splits and merges.


EDIT: in #100193, we added support for replicated locks. Instead of shipping unreplicated locks between leaseholders using a new mechanism, it probably makes sense to instead flush unreplicated locks to the replicated state machine (push them through raft) ahead of performing a lease transfer, a split, or a merge.

Jira issue: CRDB-12681

Epic CRDB-23101

@nvanbenschoten
Copy link
Member Author

We have no near-term plans to ship unreplicated key-level locks between leaseholders. Instead, we implemented replicated key-level locks (#100193) in v23.2. This new form of lock is replicated through Raft immediately upon acquisition, similar to other writes. Consequently, they are not lost during lease transfers, range splits, or range merges. Replicated locks were added for READ COMMITTED isolation, but can also be used in SERIALIZABLE isolation.

To do this, users who are running v23.2 can configure the enable_durable_locking_for_serializable session variable in any of the various ways that session variables are configured. For example, a transaction that wants replicated FOR UPDATE locks can be written like:

BEGIN;
SET LOCAL enable_durable_locking_for_serializable = true;
SELECT ... FOR UPDATE;
...
COMMIT;

There is a latency cost to this, which is proportional to the raft replication round-trip time. We are hoping to hide this latency using a pipelining technique in v24.1 (#117978).

@exalate-issue-sync exalate-issue-sync bot added the P-3 Issues/test failures with no fix SLA label Feb 29, 2024
@nvanbenschoten
Copy link
Member Author

Now that we support replicated key-level locks (#100193), the natural way to implementing this would be to "flush" unreplicated locks to the replicated state machine before lease transfers, splits, and merges. I'll repurpose this issue for that different approach for solving the same problem.

@nvanbenschoten nvanbenschoten changed the title kv: ship unreplicated locks between leaseholders on cooperative lease transfer kv: replicate unreplicated locks before lease transfers, splits, and merges Apr 19, 2024
@lunevalex lunevalex added the O-support Would prevent or help troubleshoot a customer escalation - bugs, missing observability/tooling, docs label Jul 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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) O-support Would prevent or help troubleshoot a customer escalation - bugs, missing observability/tooling, docs P-3 Issues/test failures with no fix SLA T-kv KV Team
Projects
None yet
Development

No branches or pull requests

4 participants