-
Notifications
You must be signed in to change notification settings - Fork 38
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
Conversation
There was a problem hiding this 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. |
There was a problem hiding this 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!
public Optional<Coordinator.State> getStateByIdOnly(String id) throws CoordinatorException { | ||
Get get = createGetWith(id); | ||
return get(get); | ||
} |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Thank you!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thank you!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Thank you!
…omponents (#2612) Co-authored-by: Hiroyuki Yamada <mogwaing@gmail.com> Co-authored-by: Toshihiro Suzuki <brfrn169@gmail.com>
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
public Optional<Coordinator.State> getStateByIdOnly(String id)
to make it reusableCoordinator.State#getChildIds()
publicChecklist
Additional notes (optional)
None
Release notes
N/A