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

Make transaction cleanup timeouts configurable #549

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions transaction-ballerina/commons.bal
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ cache:Cache httpClientCache = new;
time:Utc currentUtc = time:utcNow();
time:Utc newTime = time:utcAddSeconds(currentUtc, 1);
time:Civil time = time:utcToCivil(newTime);
int transactionAutoCommitTimeout = getTransactionAutoCommitTimeout();
int transactionCleanupTimeout = getTransactionCleanupTimeout();
var result = check task:scheduleJobRecurByFrequency(new Cleanup(), 60, startTime = time);

class Cleanup {
Expand All @@ -59,7 +61,7 @@ function cleanupTransactions() returns error? {
//foreach var twopcTxn in participatedTransactions {
final string participatedTxnId = getParticipatedTransactionId(twopcTxn.transactionId,
twopcTxn.transactionBlockId);
if (time:utcDiffSeconds(time:utcNow(), twopcTxn.createdTime) >= 120d) {
if (time:utcDiffSeconds(time:utcNow(), twopcTxn.createdTime) >= <decimal>transactionAutoCommitTimeout) {
if (twopcTxn.state != TXN_STATE_ABORTED && twopcTxn.state != TXN_STATE_COMMITTED) {
if (twopcTxn.state != TXN_STATE_PREPARED) {
boolean prepareSuccessful =
Expand All @@ -85,7 +87,7 @@ function cleanupTransactions() returns error? {
}
}
}
if (time:utcDiffSeconds(time:utcNow(), twopcTxn.createdTime) >= <decimal>600) {
if (time:utcDiffSeconds(time:utcNow(), twopcTxn.createdTime) >= <decimal>transactionCleanupTimeout) {
// We don't want dead transactions hanging around
removeParticipatedTransaction(participatedTxnId);
}
Expand All @@ -102,7 +104,7 @@ function cleanupTransactions() returns error? {
i += 1;
//TODO:commenting due to a caching issue
//foreach var twopcTxn in initiatedTransactions {
if (time:utcDiffSeconds(time:utcNow(), twopcTxn.createdTime) >= <decimal>120) {
if (time:utcDiffSeconds(time:utcNow(), twopcTxn.createdTime) >= <decimal>transactionAutoCommitTimeout) {
if (twopcTxn.state != TXN_STATE_ABORTED) {
// Commit the transaction since prepare hasn't been received
var result = twopcTxn.twoPhaseCommit();
Expand All @@ -117,7 +119,7 @@ function cleanupTransactions() returns error? {
}
}
}
if (time:utcDiffSeconds(time:utcNow(), twopcTxn.createdTime) >= <decimal>600) {
if (time:utcDiffSeconds(time:utcNow(), twopcTxn.createdTime) >= <decimal>transactionCleanupTimeout) {
// We don't want dead transactions hanging around
removeInitiatedTransaction(twopcTxn.transactionId);
}
Expand Down
10 changes: 10 additions & 0 deletions transaction-ballerina/internal.bal
Original file line number Diff line number Diff line change
Expand Up @@ -215,3 +215,13 @@ function externToString(TimestampImpl timestamp) returns string = @java:Method {
name: "toString",
paramTypes: ["io.ballerina.runtime.api.values.BObject"]
} external;

function getTransactionAutoCommitTimeout() returns int = @java:Method {
'class: "org.ballerinalang.stdlib.transaction.Utils",
name: "getTransactionAutoCommitTimeout"
} external;

function getTransactionCleanupTimeout() returns int = @java:Method {
'class: "org.ballerinalang.stdlib.transaction.Utils",
name: "getTransactionCleanupTimeout"
} external;
Original file line number Diff line number Diff line change
Expand Up @@ -368,4 +368,12 @@ private static InetAddress getLocalHostLANAddress() throws RuntimeException {
throw new RuntimeException("Failed to determine LAN address: " + e, e);
}
}

public static int getTransactionAutoCommitTimeout() {
return TransactionResourceManager.getInstance().getTransactionAutoCommitTimeout();
}

public static int getTransactionCleanupTimeout() {
return TransactionResourceManager.getInstance().getTransactionCleanupTimeout();
}
}
Loading