Skip to content

Commit

Permalink
Merge pull request #42998 from ballerina-platform/release-2201.8.7
Browse files Browse the repository at this point in the history
[Automated] Sync master after 2201.8.7 release
  • Loading branch information
AzeemMuzammil authored Jul 10, 2024
2 parents c63ef1c + d61748b commit 15c05f7
Show file tree
Hide file tree
Showing 6 changed files with 251 additions and 50 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,56 @@ 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);
if (!ConfigMap.containsKey(transactionAutoCommitTimeoutKey)) {
return DEFAULT_TRX_AUTO_COMMIT_TIMEOUT;
} else {
Object configValue = ConfigMap.get(transactionAutoCommitTimeoutKey);
if (configValue == null) {
return DEFAULT_TRX_AUTO_COMMIT_TIMEOUT;
}
return parseTimeoutValue(configValue, 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);
if (!ConfigMap.containsKey(transactionCleanupTimeoutKey)) {
return DEFAULT_TRX_CLEANUP_TIMEOUT;
} else {
Object configValue = ConfigMap.get(transactionCleanupTimeoutKey);
if (configValue == null) {
return DEFAULT_TRX_CLEANUP_TIMEOUT;
}
return parseTimeoutValue(configValue, DEFAULT_TRX_CLEANUP_TIMEOUT);
}
}

private static int parseTimeoutValue(Object configValue, int defaultValue) {
if (!(configValue 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
Loading

0 comments on commit 15c05f7

Please sign in to comment.