Skip to content

Commit

Permalink
Merge pull request #42950 from dsplayerX/fix_42922_8.7-stage
Browse files Browse the repository at this point in the history
[2201.8.7-stage] Introduce `transactionAutoCommitTimeout` and `transactionCleanupTimeout` configuration values for transactions
  • Loading branch information
chiranSachintha authored Jun 20, 2024
2 parents 96aca13 + 6a11f66 commit dfabb78
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,6 @@ public class TransactionConstants {

public static final String ANN_NAME_TRX_PARTICIPANT_CONFIG = "Participant";
public static final String TIMESTAMP_OBJECT_VALUE_FIELD = "timeValue";
public static final int DEFAULT_TRX_AUTO_COMMIT_TIMEOUT = 120;
public static final int DEFAULT_TRX_CLEANUP_TIMEOUT = 600;
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@
import javax.transaction.xa.Xid;

import static io.ballerina.runtime.api.constants.RuntimeConstants.BALLERINA_BUILTIN_PKG_PREFIX;
import static io.ballerina.runtime.transactions.TransactionConstants.DEFAULT_TRX_AUTO_COMMIT_TIMEOUT;
import static io.ballerina.runtime.transactions.TransactionConstants.DEFAULT_TRX_CLEANUP_TIMEOUT;
import static io.ballerina.runtime.transactions.TransactionConstants.TRANSACTION_PACKAGE_ID;
import static io.ballerina.runtime.transactions.TransactionConstants.TRANSACTION_PACKAGE_NAME;
import static io.ballerina.runtime.transactions.TransactionConstants.TRANSACTION_PACKAGE_VERSION;
Expand All @@ -84,6 +86,8 @@ public class TransactionResourceManager {
private static final String ATOMIKOS_LOG_BASE_PROPERTY = "com.atomikos.icatch.log_base_dir";
private static final String ATOMIKOS_LOG_NAME_PROPERTY = "com.atomikos.icatch.log_base_name";
private static final String ATOMIKOS_REGISTERED_PROPERTY = "com.atomikos.icatch.registered";
public static final String TRANSACTION_AUTO_COMMIT_TIMEOUT_KEY = "transactionAutoCommitTimeout";
public static final String TRANSACTION_CLEANUP_TIMEOUT_KEY = "transactionCleanupTimeout";

private static final Logger log = LoggerFactory.getLogger(TransactionResourceManager.class);
private Map<String, List<BallerinaTransactionContext>> resourceRegistry;
Expand Down Expand Up @@ -186,6 +190,48 @@ private String getTransactionLogDirectory() {
}
}

/**
* This method gets the user specified config for the transaction auto commit timeout. Default is 120.
*
* @return int transaction auto commit timeout value
*/
public static int getTransactionAutoCommitTimeout() {
VariableKey transactionAutoCommitTimeoutKey = new VariableKey(TRANSACTION_PACKAGE_ID,
TRANSACTION_AUTO_COMMIT_TIMEOUT_KEY, PredefinedTypes.TYPE_INT, false);
Object value = ConfigMap.get(transactionAutoCommitTimeoutKey);
if (value == null) {
return DEFAULT_TRX_AUTO_COMMIT_TIMEOUT;
}
return parseTimeoutValue(value, DEFAULT_TRX_AUTO_COMMIT_TIMEOUT);
}

/**
* This method gets the user specified config for cleaning up dead transactions. Default is 600.
*
* @return int transaction cleanup after value
*/
public static int getTransactionCleanupTimeout() {
VariableKey transactionCleanupTimeoutKey = new VariableKey(TRANSACTION_PACKAGE_ID,
TRANSACTION_CLEANUP_TIMEOUT_KEY,
PredefinedTypes.TYPE_INT, false);
Object value = ConfigMap.get(transactionCleanupTimeoutKey);
if (value == null) {
return DEFAULT_TRX_CLEANUP_TIMEOUT;
}
return parseTimeoutValue(value, DEFAULT_TRX_CLEANUP_TIMEOUT);
}

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;
}

/**
* This method will register connection resources with a particular transaction.
*
Expand Down
4 changes: 4 additions & 0 deletions langlib/lang.transaction/src/main/ballerina/transaction.bal
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ import ballerina/jballerina.java;
configurable boolean managerEnabled = false;
# Config to specify transaction log directory.
configurable string logBase = "transaction_log_dir";
# Config to specify the timeout for auto commit.
configurable int transactionAutoCommitTimeout = 120;
# Config to specify the timeout for cleaning up dead transactions.
configurable int transactionCleanupTimeout = 600;

//TODO: remove this in Beta2 and use an anonymous record instead
# Internally used record to hold information about a transaction.
Expand Down

0 comments on commit dfabb78

Please sign in to comment.