Proactive Termination of Idle Transactions
Scenarios
If a transaction remains idle for an extended period without being committed, rolling it back will consume database resources and degrade performance. When many idle transactions accumulate and later roll back during peak hours, the performance impact can be significant. TaurusDB supports proactive termination of idle transactions. It provides distinct configuration parameters to control different transaction types (read-only and read/write). Once an idle transaction exceeds its preset timeout threshold, the system automatically rolls it back and disconnects the session.
- Read/Write transactions: transactions that execute write operations such as INSERT, UPDATE, and DELETE
- Read-only transactions: transactions that only execute SELECT queries, or are explicitly started using START TRANSACTION READ ONLY
What Is Idle?
The lifecycle of a connection alternates between "waiting for a client command" and "executing a client command." An idle state means that the server is waiting for the client to send the next command. As long as a SQL statement is executing, regardless of how long it takes, the connection is not considered idle and will not be disconnected by any idle timeout mechanism.
TaurusDB has a two-tiered idle timeout mechanism: idle connection timeout and idle transaction timeout.
| Category | Control Parameter | Applicable Scenarios | Description | Behavior Upon Timeout |
|---|---|---|---|---|
| Idle connection timeout |
| No transaction is open, or the connection is outside of any transaction. | It is a global mechanism. Any connection that remains idle longer than this threshold will be disconnected. | Disconnecting the session |
| Idle transaction timeout |
| An uncommitted active transaction exists on the connection. | Idle connections within a transaction pose much higher resource consumption risks than general idle connections.
Therefore, in addition to the idle connection timeout, TaurusDB provides a transaction-level idle timeout mechanism to enforce shorter timeouts for connections in active transactions. | When a timeout occurs, the server executes the following actions:
|
| Comparison Item | idle_transaction_timeout Parameters | wait_timeout/interactive_timeout |
|---|---|---|
| Applicable scenarios | Connections with an uncommitted, active transaction. | All connections, regardless of whether they are inside a transaction. |
| Default value | 0 (They are disabled and must be explicitly configured.) | 28800 in units of seconds (8 hours) |
| Timeout value | Shorter timeout values can be customized separately for read-only and read/write transactions. | A uniform timeout value applied globally, regardless of transaction type. |
| Timeout behavior | The system disconnects the session and automatically rolls back the uncommitted transaction. | The system disconnects the session and automatically rolls back the uncommitted transaction. |
| Priority | Within a transaction, idle_*transaction_timeout parameters take precedence over wait_timeout. | It serves as the baseline timeout. Idle transaction timeout values cannot exceed this value. |
Prerequisites
The kernel version must be 2.0.39.230300 or later. For details about how to check the kernel version, see How Can I Check the Version of a TaurusDB Instance?
Constraints
- The default value for all three parameters is 0, meaning that the idle transaction timeout mechanism is disabled by default. It takes effect only when explicitly configured.
- Once a timeout is triggered, the uncommitted transaction is automatically rolled back. The client will not receive a descriptive application error message. It will only receive ERROR 2013.
- These parameters apply at both the SESSION and GLOBAL levels. You can customize different timeout policies for individual sessions or configure a uniform policy globally.
- After a transaction times out, the rolled back data cannot be recovered. Ensure that an appropriate retry mechanism is implemented on the application side.
- A shorter timeout is recommended for read/write transactions. Because they hold lock resources, leaving them idle for extended periods has greater impact on other transactions.
- Idle timeout is calculated only based on the duration spent waiting for a new client command. It will never be triggered during SQL execution, regardless of how long the execution takes.
- The effective idle transaction timeout value will never exceed the configured wait_timeout value. If an idle_*transaction_timeout parameter is set to a value greater than wait_timeout, the actual effective value is still wait_timeout.
Parameters
show variables like '%idle%'; +------------------------------------+------+ | Variable_name | Value | +-----------------------------------+-------+ | idle_readonly_transaction_timeout | 0 | | idle_transaction_timeout | 0 | | idle_write_transaction_timeout | 0 | +-----------------------------------+-------+
| Parameter | Level | Description |
|---|---|---|
| idle_readonly_transaction_timeout | Global, Session | Time in seconds that the server waits for idle read-only transactions before killing the connection. If this parameter is set to 0, there is no limit on the timeout for read-only transaction connections. |
| idle_transaction_timeout | Global, Session | Time in seconds that the server waits for common idle transactions before killing the connection. If this parameter is set to 0, there is no limit on the timeout for common idle transaction connections. |
| idle_write_transaction_timeout | Global, Session | Time in seconds that the server waits for idle read/write transactions before killing the connection. If this parameter is set to 0, there is no limit on the timeout for read/write transaction connections. |
The three parameters are not evaluated independently. Instead, they are verified based on their priorities:
- idle_readonly_transaction_timeout and idle_write_transaction_timeout have higher priorities than idle_transaction_timeout.
- If the value of idle_readonly_transaction_timeout or idle_write_transaction_timeout is 0, the system continues checking idle_transaction_timeout. If the value of idle_transaction_timeout is 0, the idle transaction timeout mechanism is disabled for this type of transaction.
- If all three parameters are set to 0, the idle transaction timeout mechanism is disabled and idle transactions will not be terminated.
| idle_readonly_transaction_timeout | idle_write_transaction_timeout | idle_transaction_timeout | Read-only Transaction Timeout | Read/Write Transaction Timeout |
|---|---|---|---|---|
| > 0 | > 0 | Any value | idle_readonly_transaction_timeout takes effect. | idle_write_transaction_timeout takes effect. |
| > 0 | = 0 | > 0 | idle_readonly_transaction_timeout takes effect. | idle_transaction_timeout takes effect. |
| > 0 | = 0 | = 0 | idle_readonly_transaction_timeout takes effect. | Disabled |
| = 0 | > 0 | > 0 | idle_transaction_timeout takes effect. | idle_write_transaction_timeout takes effect. |
| = 0 | > 0 | = 0 | Disabled | idle_write_transaction_timeout takes effect. |
| = 0 | = 0 | > 0 | idle_transaction_timeout takes effect. | idle_transaction_timeout takes effect. |
| = 0 | = 0 | = 0 | Disabled | Disabled |
Examples
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot