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
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 Down Expand Up @@ -186,6 +188,62 @@ 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 int getTransactionAutoCommitTimeout() {
VariableKey transactionAutoCommitTimeoutKey = new VariableKey(TRANSACTION_PACKAGE_ID,
"transactionAutoCommitTimeout", PredefinedTypes.TYPE_INT, false);
dsplayerX marked this conversation as resolved.
Show resolved Hide resolved
if (!ConfigMap.containsKey(transactionAutoCommitTimeoutKey)) {
return DEFAULT_TRX_AUTO_COMMIT_TIMEOUT;
} else {
int transactionAutoCommitTimeout;
Object value = ConfigMap.get(transactionAutoCommitTimeoutKey);
if (value instanceof Long) {
transactionAutoCommitTimeout = ((Long) value).intValue();
dsplayerX marked this conversation as resolved.
Show resolved Hide resolved
} else if (value instanceof Integer) {
transactionAutoCommitTimeout = (Integer) value;
} else {
return DEFAULT_TRX_AUTO_COMMIT_TIMEOUT;
}
if (transactionAutoCommitTimeout < 0) {
return DEFAULT_TRX_AUTO_COMMIT_TIMEOUT;
} else {
return transactionAutoCommitTimeout;
}
dsplayerX marked this conversation as resolved.
Show resolved Hide resolved
}
}

/**
* This method gets the user specified config for cleaning up dead transactions. Default is 600.
*
* @return int transaction cleanup after value
*/
public int getTransactionCleanupTimeout() {
dsplayerX marked this conversation as resolved.
Show resolved Hide resolved
VariableKey transactionCleanupTimeoutKey = new VariableKey(TRANSACTION_PACKAGE_ID, "transactionCleanupTimeout",
PredefinedTypes.TYPE_INT, false);
if (!ConfigMap.containsKey(transactionCleanupTimeoutKey)) {
return DEFAULT_TRX_CLEANUP_TIMEOUT;
} else {
int transactionCleanupTimeout;
Object value = ConfigMap.get(transactionCleanupTimeoutKey);
if (value instanceof Long) {
transactionCleanupTimeout = ((Long) value).intValue();
} else if (value instanceof Integer) {
transactionCleanupTimeout = (Integer) value;
} else {
return DEFAULT_TRX_CLEANUP_TIMEOUT;
}
if (transactionCleanupTimeout < 0) {
return DEFAULT_TRX_CLEANUP_TIMEOUT;
} else {
return transactionCleanupTimeout;
}
}
}

/**
* 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
Loading