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

kvclient: serve read-your-own-writes from the write buffer #139054

Open
arulajmani opened this issue Jan 14, 2025 · 0 comments
Open

kvclient: serve read-your-own-writes from the write buffer #139054

arulajmani opened this issue Jan 14, 2025 · 0 comments
Assignees
Labels
A-buffered-writes Related to the introduction of buffered writes 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) T-kv KV Team

Comments

@arulajmani
Copy link
Collaborator

arulajmani commented Jan 14, 2025

In service of #72614

Once we introduce a write buffer, transactions will buffer writes on the client until commit time. That means if a transaction wants to read its own writes, it must do so from the buffer (instead of going to the leaseholder).

Jira issue: CRDB-46540

@arulajmani arulajmani added A-buffered-writes Related to the introduction of buffered writes 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) T-kv KV Team labels Jan 14, 2025
@arulajmani arulajmani self-assigned this Jan 14, 2025
arulajmani added a commit to arulajmani/cockroach that referenced this issue Feb 7, 2025
This patch teaches the txnWriteBuffer to recognize when a point-read
(i.e. a Get request) should be served from its local buffer. In such
cases, we eschew sending the request to the KV layer, and instead stitch
the result back on the response path.

The approach above is fairly straightforward. The only thing we must
take care of is ensuring the correct value is returned based on the
Get request's sequence number. The logic here mirrors that of `getOne`
in `pebble_mvcc_scanner.go`. It's a bit simpler, as we don't have to
account for sequence number rollbacks here. Unlike on the server, we'll
proactively rollback writes belonging to sequence numbers that have been
ignored as part of a savepoint rollback. As a result, we can be sure
that any writes in the buffer aren't rolled back.

In a followup patch, we'll add support for Scan/Reverse requests that
overlap with a part of the butffer.

Informs cockroachdb#139054

Release note: None
arulajmani added a commit to arulajmani/cockroach that referenced this issue Feb 7, 2025
This patch teaches the txnWriteBuffer to recognize when a point-read
(i.e. a Get request) should be served from its local buffer. In such
cases, we eschew sending the request to the KV layer, and instead stitch
the result back on the response path.

The approach above is fairly straightforward. The only thing we must
take care of is ensuring the correct value is returned based on the
Get request's sequence number. The logic here mirrors that of `getOne`
in `pebble_mvcc_scanner.go`. It's a bit simpler, as we don't have to
account for sequence number rollbacks here. Unlike on the server, we'll
proactively rollback writes belonging to sequence numbers that have been
ignored as part of a savepoint rollback. As a result, we can be sure
that any writes in the buffer aren't rolled back.

In a followup patch, we'll add support for Scan/Reverse requests that
overlap with a part of the butffer.

Informs cockroachdb#139054

Release note: None
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-buffered-writes Related to the introduction of buffered writes 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) T-kv KV Team
Projects
None yet
Development

No branches or pull requests

1 participant