diff --git a/transaction-ballerina/commons.bal b/transaction-ballerina/commons.bal index acb11e78..58c998be 100644 --- a/transaction-ballerina/commons.bal +++ b/transaction-ballerina/commons.bal @@ -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 { @@ -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) >= transactionAutoCommitTimeout) { if (twopcTxn.state != TXN_STATE_ABORTED && twopcTxn.state != TXN_STATE_COMMITTED) { if (twopcTxn.state != TXN_STATE_PREPARED) { boolean prepareSuccessful = @@ -85,7 +87,7 @@ function cleanupTransactions() returns error? { } } } - if (time:utcDiffSeconds(time:utcNow(), twopcTxn.createdTime) >= 600) { + if (time:utcDiffSeconds(time:utcNow(), twopcTxn.createdTime) >= transactionCleanupTimeout) { // We don't want dead transactions hanging around removeParticipatedTransaction(participatedTxnId); } @@ -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) >= 120) { + if (time:utcDiffSeconds(time:utcNow(), twopcTxn.createdTime) >= transactionAutoCommitTimeout) { if (twopcTxn.state != TXN_STATE_ABORTED) { // Commit the transaction since prepare hasn't been received var result = twopcTxn.twoPhaseCommit(); @@ -117,7 +119,7 @@ function cleanupTransactions() returns error? { } } } - if (time:utcDiffSeconds(time:utcNow(), twopcTxn.createdTime) >= 600) { + if (time:utcDiffSeconds(time:utcNow(), twopcTxn.createdTime) >= transactionCleanupTimeout) { // We don't want dead transactions hanging around removeInitiatedTransaction(twopcTxn.transactionId); } diff --git a/transaction-ballerina/internal.bal b/transaction-ballerina/internal.bal index 4feead91..6118a0af 100644 --- a/transaction-ballerina/internal.bal +++ b/transaction-ballerina/internal.bal @@ -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; diff --git a/transaction-native/src/main/java/org/ballerinalang/stdlib/transaction/Utils.java b/transaction-native/src/main/java/org/ballerinalang/stdlib/transaction/Utils.java index 010ea316..58cf8857 100644 --- a/transaction-native/src/main/java/org/ballerinalang/stdlib/transaction/Utils.java +++ b/transaction-native/src/main/java/org/ballerinalang/stdlib/transaction/Utils.java @@ -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(); + } }