Skip to content

Decouple CoordinatorCommitHandler from TransactionContext and WriteSetEncoder#3658

Merged
brfrn169 merged 1 commit into
masterfrom
refactor-context-independent-commit-handler
Jun 30, 2026
Merged

Decouple CoordinatorCommitHandler from TransactionContext and WriteSetEncoder#3658
brfrn169 merged 1 commit into
masterfrom
refactor-context-independent-commit-handler

Conversation

@brfrn169

@brfrn169 brfrn169 commented Jun 26, 2026

Copy link
Copy Markdown
Collaborator

Description

CoordinatorCommitHandler writes only the Coordinator state table, yet it took a full TransactionContext and encoded the write set itself via WriteSetEncoder, tying it to the snapshot-bearing execution context. This PR decouples the handler so it operates on a transaction ID plus a pre-encoded WriteSet, moving write-set encoding ownership up to the orchestrator (CommitHandler). This sharpens the layering — the Coordinator-side state logic now depends only on what it actually writes — and lets those state writes be driven by ID.

Related issues and/or PRs

Changes made

  • CoordinatorCommitHandler: commitState / abortState / handleCommitConflict now take a transaction ID and a pre-encoded WriteSet (commitState also takes the committedAt to stamp). The handler no longer references TransactionContext or WriteSetEncoder.
  • CommitHandler (orchestrator): now owns the WriteSetEncoder, encodes the write set, and supplies committedAt before delegating. commitState / abortState are encoding delegators (not thin pass-throughs), which is documented on the class.
  • Group commit: the Emittable value is now a (fullId, WriteSet) carrier (new CoordinatorGroupCommitValue), so the Emitter is encoder-free — it derives each child ID from the carried full ID and stamps the pre-encoded write set. The group-commit entry point is named groupCommitState (distinct from the base commitState, whose signature differs) to prevent a caller from silently binding to the base direct-putState overload, and slot cancellation is ID-based (cancelGroupCommit).
  • Removed WriteSetEncoder#encodeMultiGroupWriteSet and its CoordinatorGroupCommitKeyManipulator dependency (now unused).
  • Reworked the unit tests to the ID-based signatures; commitState delegation is routed through protected hooks so the group-commit subclass asserts the 2-arg groupCommitState while the base asserts the 3-arg orchestrator-provided variant.

Checklist

  • I have commented my code, particularly in hard-to-understand areas.
  • I have updated the documentation to reflect the changes.
  • I have considered whether similar issues could occur in other products, components, or modules if this PR is for bug fixes.
  • Any remaining open issues linked to this PR are documented and up-to-date (Jira, GitHub, etc.).
  • Tests (unit, integration, etc.) have been added for the changes.
  • My changes generate no new warnings.
  • Any dependent changes in other PRs have been merged and published.

Additional notes (optional)

N/A

Release notes

N/A

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

Copy link
Copy Markdown
Contributor

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 refactors the Consensus Commit transaction commit handler to decouple CoordinatorCommitHandler from WriteSetEncoder. The orchestrators (CommitHandler and CommitHandlerWithGroupCommit) now handle write set encoding before delegating to the coordinator handlers, and the group commit emitter merges pre-encoded write sets using a new CoordinatorGroupCommitValue carrier. Feedback on the changes highlights a potential issue where commitStateWithoutWriteSet and abortStateWithoutWriteSet are not overridden in CommitHandlerWithGroupCommit, which could bypass the group committer and lead to slot leaks.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Refactors Consensus Commit coordinator-state writing to be driven by transaction ID plus a pre-encoded WriteSet, decoupling CoordinatorCommitHandler (and the group-commit emitter) from snapshot-bearing TransactionContext and from WriteSetEncoder. This supports upcoming TwoPhaseCommit flows that need to write coordinator state by ID without holding a transaction snapshot.

Changes:

  • CoordinatorCommitHandler APIs now accept (txId, WriteSet?, committedAt) for commit and (txId, WriteSet?) for abort; conflict handling is ID-based.
  • Orchestrator (CommitHandler / CommitHandlerWithGroupCommit) now owns WriteSetEncoder and supplies encoded write sets (and non-group committedAt) when delegating.
  • Group commit now buffers a (fullId, WriteSet?) carrier (CoordinatorGroupCommitValue), and the emitter merges/stamps per-child entry groups at emit time; tests updated accordingly.

Reviewed changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
core/src/main/java/com/scalar/db/transaction/consensuscommit/CommitHandler.java Moves write-set encoding (and non-group committedAt) responsibility into the orchestrator before delegating to coordinator handler.
core/src/main/java/com/scalar/db/transaction/consensuscommit/CommitHandlerWithGroupCommit.java Routes coordinator commit-state writes through group commit using encoded write sets; makes slot cancellation ID-based.
core/src/main/java/com/scalar/db/transaction/consensuscommit/CoordinatorCommitHandler.java Converts coordinator-side state writes/conflict handling to operate on txId + pre-encoded WriteSet.
core/src/main/java/com/scalar/db/transaction/consensuscommit/CoordinatorCommitHandlerWithGroupCommit.java Updates group-commit path to buffer (fullId, WriteSet) values and merge/stamp at emit time; renames APIs to avoid accidental binding.
core/src/main/java/com/scalar/db/transaction/consensuscommit/CoordinatorGroupCommitter.java Updates the group committer value type to CoordinatorGroupCommitValue.
core/src/main/java/com/scalar/db/transaction/consensuscommit/CoordinatorGroupCommitValue.java Introduces a carrier for group-commit buffering: full transaction ID + pre-encoded WriteSet.
core/src/main/java/com/scalar/db/transaction/consensuscommit/WriteSetEncoder.java Removes now-unused multi-group encoding logic and its key-manipulator dependency.
core/src/test/java/com/scalar/db/transaction/consensuscommit/CommitHandlerTest.java Updates orchestration tests to reflect ID-based coordinator handler APIs and verify orchestrator encoding delegation.
core/src/test/java/com/scalar/db/transaction/consensuscommit/CommitHandlerWithGroupCommitTest.java Adjusts group-commit orchestration assertions to target groupCommitState and ID-based cancellation.
core/src/test/java/com/scalar/db/transaction/consensuscommit/CoordinatorCommitHandlerTest.java Reworks direct coordinator-handler tests to pass IDs and pre-encoded write sets.
core/src/test/java/com/scalar/db/transaction/consensuscommit/CoordinatorCommitHandlerWithGroupCommitTest.java Reworks group-commit handler/emitter tests to use pre-encoded write sets and value carriers.
core/src/test/java/com/scalar/db/transaction/consensuscommit/CoordinatorGroupCommitterTest.java Updates group-committer tests to buffer CoordinatorGroupCommitValue instead of TransactionContext.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@brfrn169 brfrn169 force-pushed the refactor-context-independent-commit-handler branch from 5cf2d71 to 3a785d0 Compare June 26, 2026 08:34
@brfrn169 brfrn169 requested a review from Copilot June 26, 2026 08:34

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 12 out of 12 changed files in this pull request and generated 2 comments.

@brfrn169 brfrn169 force-pushed the refactor-context-independent-commit-handler branch from 3a785d0 to 2133628 Compare June 26, 2026 09:04
@brfrn169 brfrn169 requested review from a team, KodaiD, Torch3333, feeblefakie and komamitsu and removed request for a team June 26, 2026 09:04
@brfrn169 brfrn169 force-pushed the unify-commit-phase-timestamps branch from 270077c to 5f13f8b Compare June 26, 2026 09:35
@brfrn169 brfrn169 force-pushed the refactor-context-independent-commit-handler branch 2 times, most recently from ad1a28e to 130dda4 Compare June 27, 2026 02:26
@brfrn169 brfrn169 force-pushed the unify-commit-phase-timestamps branch from 5f13f8b to 3d12a9b Compare June 27, 2026 05:51
@brfrn169 brfrn169 force-pushed the refactor-context-independent-commit-handler branch from a25871a to ddf5b2a Compare June 27, 2026 05:51

@komamitsu komamitsu left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM! 👍

@feeblefakie feeblefakie left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM! Thank you!

@brfrn169 brfrn169 force-pushed the unify-commit-phase-timestamps branch from 3d12a9b to 756e519 Compare June 30, 2026 15:55
Base automatically changed from unify-commit-phase-timestamps to master June 30, 2026 16:38
…pendent

Decouple the Coordinator-side commit handler from TransactionContext and
WriteSetEncoder. CoordinatorCommitHandler now operates on a transaction id
plus a pre-encoded WriteSet, so the orchestrator (CommitHandler) owns the
WriteSetEncoder and supplies the encoded write set and committedAt.

For group commit, the Emittable value becomes a (fullId, WriteSet) carrier
(CoordinatorGroupCommitValue) so the Emitter is encoder-free: it derives each
child id from the carried full id and stamps the pre-encoded write set. The
WriteSetEncoder therefore lives only in the orchestrator layer, and
WriteSetEncoder#encodeMultiGroupWriteSet and its key-manipulator dependency
are dropped. The group-commit entry point is named groupCommitState (distinct
from the base commitState, whose signature differs) so a caller cannot
silently bind to the base direct-putState overload, and slot cancellation is
id-based (cancelGroupCommit).

Tests are reworked to the id-based signatures, with commitState delegation
routed through protected hooks so the group-commit subclass asserts the
2-arg groupCommitState (committedAt determined at emit time) while the base
asserts the 3-arg orchestrator-provided variant.
@brfrn169 brfrn169 force-pushed the refactor-context-independent-commit-handler branch from ddf5b2a to fe31825 Compare June 30, 2026 16:45
@brfrn169 brfrn169 merged commit 544a931 into master Jun 30, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants