Skip to content

kv: use one-phase commit for single-group txns#382

Merged
bootjp merged 6 commits intomainfrom
feature/reduce-lock
Mar 21, 2026
Merged

kv: use one-phase commit for single-group txns#382
bootjp merged 6 commits intomainfrom
feature/reduce-lock

Conversation

@bootjp
Copy link
Copy Markdown
Owner

@bootjp bootjp commented Mar 21, 2026

No description provided.

@bootjp bootjp requested a review from Copilot March 21, 2026 06:27
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces a significant optimization for single-group transactions by implementing a one-phase commit mechanism. This change streamlines the transaction lifecycle for these specific cases, improving efficiency by reducing the number of steps required for a successful commit. The core idea is to bypass the traditional two-phase commit overhead when a transaction's operations are confined to a single transactional group, leading to faster and more resource-efficient operations.

Highlights

  • One-Phase Commit for Single-Group Transactions: Implemented a one-phase commit protocol for transactions that involve only a single group of keys, optimizing the commit process by reducing overhead.
  • Transaction Phase Handling: Introduced a new pb.Phase_NONE to signify one-phase transactions, updating various components to correctly process and manage these transactions.
  • Optimized Transaction Cleanup: Modified the transaction manager to avoid unnecessary abort cleanup for one-phase transactions, as they do not leave behind intents.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a significant optimization by implementing a one-phase commit protocol for single-group transactions, which avoids the overhead of the two-phase commit process. The changes are logical and well-structured across the coordinator, FSM, and transaction manager. The new Phase_NONE transaction type is handled correctly, and the decision to skip abort cleanup for these transactions is sound. The accompanying tests are thorough and cover the new functionality well. I've found one critical issue that will prevent the code from compiling, which I've detailed in a specific comment.

Comment thread kv/coordinator.go
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Implements a one-phase commit path for single-group transactions, reducing transactional overhead by applying user mutations directly at a commit timestamp (without writing txn intents/locks/commit records) while keeping existing multi-phase behavior intact.

Changes:

  • Build/dispatch single-group txns as a single pb.Request with Phase_NONE (one-phase txn) instead of PREPARE+COMMIT.
  • Teach the KV FSM to treat IsTxn && Phase_NONE as a one-phase txn and apply mutations directly (no txn artifacts).
  • Update cleanup/forwarding logic to account for one-phase txns and add tests to verify behavior.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
kv/transaction.go Skips abort cleanup for one-phase txns; refactors abort request construction into a helper.
kv/fsm.go Adds one-phase txn handling (Phase_NONE) and applies user mutations directly at commitTS.
kv/coordinator.go Switches single-group txn dispatch/redirect to emit a single one-phase request.
kv/fsm_txn_test.go Verifies one-phase txns commit data without leaving txn lock/intent/commit artifacts.
kv/coordinator_txn_test.go Verifies coordinator emits a single Phase_NONE txn request with meta + mutations.
adapter/internal.go / adapter/internal_test.go Ensures forwarded one-phase txns get a valid CommitTS assigned in txn meta.

Comment thread kv/fsm.go Outdated
@bootjp
Copy link
Copy Markdown
Owner Author

bootjp commented Mar 21, 2026

@copilot open a new pull request to apply changes based on the comments in this thread

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 21, 2026

@bootjp I've opened a new pull request, #383, to work on those changes. Once the pull request is ready, I'll request review from you.

Copilot AI and others added 3 commits March 21, 2026 06:37
[WIP] Implement one-phase commit for single-group transactions
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated no new comments.

@bootjp bootjp merged commit 10a46af into main Mar 21, 2026
11 checks passed
@bootjp bootjp deleted the feature/reduce-lock branch March 21, 2026 06:47
bootjp added a commit that referenced this pull request Apr 30, 2026
All four Gemini findings addressed.

#189 -- pendingWideColumnTTL slice bounded.
The orphan-TTL buffer is now capped at maxPendingWideColumnTTL =
1,000,000 entries (~50 MiB). Records past the cap are dropped and
the warn sink reports the count at Finalize. Real production state
(where wide-column type encoders eventually claim every TTL) is far
under the cap; the bound only protects against malformed or
adversarial snapshots.

#217 -- db_0 hardcoding fixed.
NewRedisDB now takes a dbIndex parameter; the per-encoder root
"<outRoot>/redis/db_<idx>/" is computed from it. Two encoders with
the same outRoot but different indices no longer collide.
TestRedisDB_PerDBIndexRoutesIntoOwnDirectory locks in the
distinction.

#218 -- MkdirAll cached.
Added dirsCreated map[string]struct{} on RedisDB. ensureDir()
checks the map before MkdirAll so repeated writes (one per blob
record) collapse to a map lookup. For a 10M-key dump this saves
~10M stat+mkdir(EEXIST) round-trips.
TestRedisDB_DirsCreatedCachesMkdirAll asserts the cache is
populated exactly once per directory.

#382 -- ENOSPC handling.
Added IsBlobAtomicWriteOutOfSpace as the explicit ENOSPC probe.
IsBlobAtomicWriteRetriable continues to report only
io.ErrShortWrite as retriable -- ENOSPC is intentionally NOT
retriable (a backup against a full disk should surface to the
operator rather than spin). The two-function split lets the
master pipeline render the right alarm message.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants