Skip to content

Relax visibility of Coordinator's methods for use by other ScalarDB components #2612

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

Merged
merged 7 commits into from
May 8, 2025

Conversation

komamitsu
Copy link
Contributor

@komamitsu komamitsu commented Apr 25, 2025

Description

com.scalar.db.transaction.consensuscommit.Coordinator has some implementation that are not public or reusable. For example, the current implementation doesn't allow external ScalarDB components to directly look up a state by the parent ID for the coordinator group commit. It's sometimes useful for optimization (e.g., for caching coordinator state records using parent IDs as keys) in external components.

It's possible to inherit Coordinator class in those external components and implements the same logic by themselves, but it would result in duplicated logics and implementations over multiple components.

This PR makes those logics and implementations accessible in Coordinator class so that they can be reused when necessary.

Related issues and/or PRs

None

Changes made

  • Extracted the implementation for getting a state by ID as public Optional<Coordinator.State> getStateByIdOnly(String id) to make it reusable
  • Made Coordinator.State#getChildIds() public

Checklist

The following is a best-effort checklist. If any items in this checklist are not applicable to this PR or are dependent on other, unmerged PRs, please still mark the checkboxes after you have read and understood each item.

  • 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)

None

Release notes

N/A

@komamitsu komamitsu requested a review from Copilot April 25, 2025 13:45
Copy link

@Copilot 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

This PR relaxes the visibility of certain Coordinator methods to allow reusability by other ScalarDB components. Key changes include:

  • Extracting and making public the getStateByIdOnly method for state retrieval.
  • Updating Coordinator and its tests to support both normal transaction IDs and group commit IDs.
  • Adjusting the visibility of State#getChildIds and adding an overloaded State constructor.

Reviewed Changes

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

File Description
core/src/test/java/com/scalar/db/transaction/consensuscommit/CoordinatorTest.java Added tests for the new getStateByIdOnly method with coverage for normal and group commit scenarios.
core/src/main/java/com/scalar/db/transaction/consensuscommit/Coordinator.java Refactored state retrieval to use getStateByIdOnly and updated State’s API by making getChildIds public and adding a new constructor.

Copy link
Collaborator

@brfrn169 brfrn169 left a comment

Choose a reason for hiding this comment

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

The change looks good to me. Left a question. Please take a look when you have time!

Comment on lines 136 to 139
public Optional<Coordinator.State> getStateByIdOnly(String id) throws CoordinatorException {
Get get = createGetWith(id);
return get(get);
}
Copy link
Collaborator

@brfrn169 brfrn169 Apr 29, 2025

Choose a reason for hiding this comment

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

I feel that the already exposed getState() method behaves the same way when the ID is not a full ID for the coordinator group commit.
So, we need this method purely for performance reasons, without checking the ID format. Is that correct?

Copy link
Contributor Author

@komamitsu komamitsu Apr 30, 2025

Choose a reason for hiding this comment

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

@brfrn169 Sorry for lack of explanation. The current implementation doesn't allow external components to directly look up a state by the parent ID for the coordinator group commit. It's sometimes useful for optimization (e.g., for caching coordinator state records using parent IDs as keys) in external components.

I realized the method names introduced in this PR were a bit unclear from the use case perspective. I updated them in 496c8f8. I hope it clarifies the code.

I also updated the description of the PR.

to clarify the use cases
@komamitsu komamitsu requested a review from brfrn169 April 30, 2025 02:52
Copy link
Collaborator

@brfrn169 brfrn169 left a comment

Choose a reason for hiding this comment

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

LGTM! Thank you!

Copy link
Contributor

@Torch3333 Torch3333 left a comment

Choose a reason for hiding this comment

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

LGTM, thank you!

Copy link
Contributor

@feeblefakie feeblefakie left a comment

Choose a reason for hiding this comment

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

LGTM! Thank you!

@komamitsu komamitsu merged commit 1b441e0 into master May 8, 2025
55 checks passed
@komamitsu komamitsu deleted the update-coordinator-for-ssr branch May 8, 2025 07:50
feeblefakie added a commit that referenced this pull request May 8, 2025
…omponents (#2612)

Co-authored-by: Hiroyuki Yamada <mogwaing@gmail.com>
Co-authored-by: Toshihiro Suzuki <brfrn169@gmail.com>
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