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

Optimize Coordinator#getStateForGroupCommit() by first looking up the coordinator table with parent transaction ID #2331

Merged
merged 4 commits into from
Nov 14, 2024

Conversation

komamitsu
Copy link
Contributor

@komamitsu komamitsu commented Nov 8, 2024

Description

The current implementation of Coordinator.getStateForGroupCommit() checks transaction states that were stored with the Group Commit feature enabled in the following order:

  1. First, it tries to find a record whose tx_id is the full transaction ID, returning the state if it's found. This record type is created when a transaction is delayed and committed individually.
  2. Next, it tris to find a record whose tx_id is the parent transaction ID, returning the state if it's found and the tx_sub_ids contains the child transaction ID. This record type is created when a transaction gets commit-ready in time and group-committed.

This order is optimized for lazy-recovery, which is more likely to happen if the commit timing is delayed after PREPARE record is created. However, basically lazy-recovery doesn't happen so often.

We may create a new system that frequently looks up the coordinator table in the future. In that case, it might need to prioritize first finding group-committed transactions, not just delayed individually committed transaction. The current order doesn't fit this scenario.

This PR changes the lookup order to prioritize group-committed transactions first.

Related issues and/or PRs

None

Changes made

  • Change the order of GET operations with full transaction ID and parent ID in Coordinator#getStateForGroupCommit().
  • Update the unit test along with the change.

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.
  • 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 changed the title Optimize GET op for group-commit Coordinator State Optimize GET operation for group-committed Coordinator State Nov 8, 2024
@komamitsu komamitsu changed the title Optimize GET operation for group-committed Coordinator State Optimize Coordinator#getStateForGroupCommit() by first looking up the coordinator table with parent transaction ID Nov 8, 2024
@komamitsu komamitsu marked this pull request as ready for review November 8, 2024 11:18
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.

The code looks good!
I left a suggestion on the comment.
PTAL!

}
return Optional.empty();
});
// The current implementation is optimized for cases where the target transaction is properly
Copy link
Contributor

Choose a reason for hiding this comment

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

The comment is a bit hard to follow to me, so can it be something like this?
Please also verify if it is correct.

The current implementation is optimized for a case where most transactions are group-committed.
Specifically, Coordinator first checks a transaction state by using a parent ID with one read operation.
If it cannot find it, which means the transaction is delayed and not included in a group, it will issue an additional read operation by using the full ID.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@feeblefakie Thanks! It seems better.

How about the following version revised based on your suggestion?

The current implementation is optimized for cases where most transactions are group-committed. It first looks up a transaction state by the parent ID with a single read operation. If no matching transaction state is found (i.e., the transaction was delayed and committed individually), it issues an additional read operation using the full ID.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated the comment in 1b62d3c

Copy link
Contributor

Choose a reason for hiding this comment

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

It looks good!
Just one thing. Let's use consistent wording (using xxx ID).

The current implementation is optimized for cases where most transactions are group-committed. It first looks up a transaction state using the parent ID with a single read operation. If no matching transaction state is found (i.e., the transaction was delayed and committed individually), it issues an additional read operation using the full ID.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks! Fixed it in 6e3ece2.

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.

Left a comment on the Javadoc comment, other than that LGTM! Thank you!

@komamitsu komamitsu merged commit 812afc0 into master Nov 14, 2024
48 checks passed
@komamitsu komamitsu deleted the optimize-get-group-committed-coordinator-state branch November 14, 2024 05:24
feeblefakie pushed a commit that referenced this pull request Nov 14, 2024
…he coordinator table with parent transaction ID (#2331)
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