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

Introduce transactionAutoCommitTimeout and transactionCleanupTimeout configuration values for transactions #42940

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

dsplayerX
Copy link
Contributor

@dsplayerX dsplayerX commented Jun 18, 2024

Purpose

Introduces new configurations to prevent premature commits of long-running transactions before reaching the commit phase.

Related #42922

Approach

This PR introduces two new configurations values for transactions, transactionAutoCommitTimeout and transactionCleanupTimeout.

ballerinai-transaction PR: ballerina-platform/module-ballerinai-transaction#549

Samples

You can change the Config.toml with these two new configs as below.

[ballerina.lang.transaction]
transactionAutoCommitTimeout=120
transactionCleanupTimeout=600

Remarks

ballerinai-transaction PR: ballerina-platform/module-ballerinai-transaction#549

Check List

  • Read the Contributing Guide
  • Updated Change Log
  • Checked Tooling Support (#)
  • Added necessary tests
    • Unit Tests
    • Spec Conformance Tests
    • Integration Tests
    • Ballerina By Example Tests
  • Increased Test Coverage
  • Added necessary documentation
    • API documentation
    • Module documentation in Module.md files
    • Ballerina By Examples

This commit introduces two new configurations values for transactions, `transactionAutoCommitTimeout` and `transactionCleanupTimeout`
Copy link

codecov bot commented Jun 18, 2024

Codecov Report

Attention: Patch coverage is 0% with 16 lines in your changes missing coverage. Please review.

Project coverage is 77.29%. Comparing base (02e0001) to head (a6332d8).
Report is 157 commits behind head on master.

Current head a6332d8 differs from pull request most recent head 7e1c5e4

Please upload reports for the commit 7e1c5e4 to get more accurate results.

Files Patch % Lines
...ntime/transactions/TransactionResourceManager.java 0.00% 16 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master   #42940      +/-   ##
============================================
- Coverage     77.29%   77.29%   -0.01%     
- Complexity    51350    51357       +7     
============================================
  Files          2932     2932              
  Lines        204512   204545      +33     
  Branches      26692    26716      +24     
============================================
+ Hits         158084   158103      +19     
- Misses        37838    37846       +8     
- Partials       8590     8596       +6     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@dsplayerX dsplayerX changed the title [WIP] Introduce transactionAutoCommitTimeout and transactionCleanupTimeout configuration values for transactions Introduce transactionAutoCommitTimeout and transactionCleanupTimeout configuration values for transactions Jun 18, 2024
@chiranSachintha
Copy link
Member

Shall we add test for this change.

@ThisaruGuruge
Copy link
Member

Can we do this fix for 8.x as well?

@dsplayerX dsplayerX force-pushed the fix_42922_long_running_trans branch from 877c337 to 14805cf Compare June 19, 2024 09:04
@dsplayerX
Copy link
Contributor Author

Shall we add test for this change.

@chiranSachintha Could you suggest a way to add test cases please?

@chiranSachintha
Copy link
Member

@chiranSachintha Could you suggest a way to add test cases please?

You can write an external function for the getTransactionAutoCommitTimeout function from the Ballerina side and then test it by sending values as a configurable variable. You can check the test cases here.

Comment on lines 224 to 233
private static int parseTimeoutValue(Object value, int defaultValue) {
if (!(value instanceof Number number)) {
return defaultValue;
}
int timeoutValue = number.intValue();
if (timeoutValue <= 0) {
return defaultValue;
}
return timeoutValue;
}
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
private static int parseTimeoutValue(Object value, int defaultValue) {
if (!(value instanceof Number number)) {
return defaultValue;
}
int timeoutValue = number.intValue();
if (timeoutValue <= 0) {
return defaultValue;
}
return timeoutValue;
}
private static int parseTimeoutValue(Object value, int defaultValue) {
if (value instanceof Number number) {
int timeoutValue = number.intValue();
if (timeoutValue > 0) {
return timeoutValue;
}
}
return defaultValue;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

IMO, I think returning the parsed value at the bottom of the method makes it clear that the method’s primary purpose is to return a valid timeout value if possible, and only return the default value if the parsing or validation fails.

Copy link
Member

Choose a reason for hiding this comment

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

The advantage of this refactoring is this reduces the number of return statements and keeps the code concise.

@dsplayerX dsplayerX force-pushed the fix_42922_long_running_trans branch from 7e1c5e4 to dba23db Compare June 21, 2024 14:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants