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

Enable setting of transaction expiration handler in active transaction management #1395

Conversation

brfrn169
Copy link
Collaborator

Description

This PR enables the setting of the transaction expiration handler in active transaction management.

Related issues and/or PRs

N/A

Changes made

  • Enabled the setting of the transaction expiration handler in ActiveTransactionManagedDistributedTransactionManager and ActiveTransactionManagedTwoPhaseCommitTransactionManager

Checklist

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

N/A

Release notes

N/A

@brfrn169 brfrn169 self-assigned this Dec 20, 2023
});
}

public void setTransactionExpirationHandler(BiConsumer<String, DistributedTransaction> handler) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We will be able to set a transaction expiration handler after this change.

Copy link
Contributor

Choose a reason for hiding this comment

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

@brfrn169 Can you tell me how the custom handler would be like?

Copy link
Collaborator Author

@brfrn169 brfrn169 Dec 21, 2023

Choose a reason for hiding this comment

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

I'm going to use it for the ScalarDB Auth thing. Theoretically, we can do anything for expired transactions with this handler. For example, we can output detail logs for the expired transactions.

});
}

public void setTransactionExpirationHandler(
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ditto.

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.

Although I left a question, LGTM! Thank you!

@@ -32,6 +34,17 @@ public abstract class ActiveTransactionManagedDistributedTransactionManager

private final ActiveExpiringMap<String, ActiveTransaction> activeTransactions;

private final AtomicReference<BiConsumer<String, DistributedTransaction>>
Copy link
Contributor

Choose a reason for hiding this comment

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

Just a question.
I think we also have this expiration handler in ScalarDB Cluster, but I'm wondering if we need to have it in both sides: ScalarDB core and ScalarDB Cluster.
If the core implements it, the one in ScalarDB Cluster is not necessary?

Copy link
Collaborator Author

@brfrn169 brfrn169 Dec 21, 2023

Choose a reason for hiding this comment

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

Sorry, I can't remember the expiration handler in ScalarDB Cluster. Please give me some more information about that?

new AtomicReference<>(
(id, t) -> {
try {
t.rollback();
Copy link
Contributor

Choose a reason for hiding this comment

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

[minor] I think this rollback is always necessary and any custom expiration handler must call it. But users of setTransactionExpirationHandler() can pass a custom expiration handler that doesn't call rollback by mistake. Another option would be to add a callback like this?

private final AtomicReference<BiConsumer<String, DistributedTransaction>> transactionExpirationCallback = new AtomicReference<>((id, t) -> {});
private final BiConsumer<String, DistributedTransaction>
      transactionExpirationHandler =
              (id, t) -> {
                try {
                   transactionExpirationCallback.get().accept(id, t);
                }
                catch (Throwable t) {
                  // Warning
                }
                try {
                  t.rollback();
                } catch (Exception e) {
                  logger.warn("Rollback failed. transaction ID: {}", id, e);
                }
              };

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good point. I agree that rollback is always necessary, which is why the default handler executes rollback. This feature is advanced and is primarily intended for internal use. Additionally, I don't plan to document it. Therefore, if a user sets a custom handler that doesn't rollback the expired transaction, I believe it falls under the user's responsibility. Thanks.

Copy link
Contributor

@komamitsu komamitsu left a comment

Choose a reason for hiding this comment

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

LGTM! 👍

Left a minor comment, but it doesn't block this PR from being merged.

@brfrn169 brfrn169 merged commit 6f431ce into master Dec 21, 2023
23 checks passed
@brfrn169 brfrn169 deleted the enable-setting-of-transaction-expiration-handler-in-active-transaction-managenent branch December 21, 2023 06:01
feeblefakie pushed a commit that referenced this pull request Dec 21, 2023
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.

3 participants