- MariaDB Cookbook
- Daniel Bartholomew
- 526字
- 2021-07-16 12:19:27
Configuring the Aria two-step deadlock detection
A deadlock is when there are two competing actions and both are waiting for the other to finish and so neither of them ever finish. The Aria storage engine is able to automatically detect and deal with deadlocks. To make effective use of this feature, we should configure it with the settings that work well for our needs.
How to do it...
- Run the following command to show the current settings for Aria's two-step deadlock detection:
SHOW VARIABLES LIKE 'deadlock_%'\G
- If our settings are set to the default values, the output of the previous command will be as shown in the following screenshot:
- Change the variables to our desired values, as follows:
SET GLOBAL deadlock_search_depth_short = 3; SET GLOBAL deadlock_search_depth_long = 10; SET GLOBAL deadlock_timeout_long = 10000000; SET GLOBAL deadlock_timeout_short = 5000;
- Make the changes permanent by adding the following lines of code to the bottom of our
my.cnf
ormy.ini
file (or to an existing[mysqld]
section):[mysqld] deadlock_search_depth_short = 3 deadlock_search_depth_long = 10 deadlock_timeout_long = 10000000 deadlock_timeout_short = 5000
How it works...
If the Aria storage engine attempts to create a lock and is unable to do so, the possibility of having a deadlock exists. We only want to kill actual deadlocks and not a situation that will resolve itself in an amount of time for which we are comfortable waiting.
To detect deadlocks, whenever Aria cannot create a lock on a table, it first creates a wait-for graph of the possible deadlock with a search depth equal to deadlock_search_depth_short
. If, after the search, the lock on the table still exists and Aria cannot determine if it is a deadlock, it will wait for the number of microseconds defined by the value of deadlock_timeout_short
and then try again. If it is still unsuccessful, Aria will create a wait-for graph with a search depth equal to the value of deadlock_search_depth_long
, and if a deadlock has still not been identified, Aria will wait for the number of microseconds defined by the value of deadlock_timeout_long
and then time out with an error.
If a deadlock is detected at any point during the previous steps, Aria will determine the thread responsible for it and kill it, thereby releasing the deadlock and allowing a lock to be made and released as normal.
There's more...
It's important to remember that the deadlock_timeout_short
and deadlock_timeout_long
variables are defined in microseconds, not milliseconds or seconds. So a value of 10000000
is equal to ten seconds and a value of 5000
is equal to five-thousandths of a second.
For many users, the default timeout values of 50000000
(50 seconds) for the long timeout and 10000
(one-hundredth of a second) for the short timeout are perfectly adequate. The same is also true for the default values of the search depth variables. That said, it might be useful to experiment with different values if we're experiencing a lot of timeouts.
See also
- The full documentation of Aria two-step deadlock detection is available at https://mariadb.com/kb/en/aria-two-step-deadlock-detection/
- The syntax documentation of the various deadlock options is available at https://mariadb.com/kb/en/aria-server-system-variables/
- For more information on wait-for graphs and deadlocks, refer to http://en.wikipedia.org/wiki/Wait-for_graph and http://en.wikipedia.org/wiki/Deadlock
- 微服務設計(第2版)
- UI圖標創意設計
- Apache ZooKeeper Essentials
- Visual Basic 6.0程序設計計算機組裝與維修
- Python入門很簡單
- Microsoft Dynamics 365 Extensions Cookbook
- 少年輕松趣編程:用Scratch創作自己的小游戲
- R語言游戲數據分析與挖掘
- Mastering Kotlin
- 假如C語言是我發明的:講給孩子聽的大師編程課
- SQL Server 2016數據庫應用與開發習題解答與上機指導
- Python編程實戰
- Visual C#通用范例開發金典
- Python深度學習原理、算法與案例
- Illustrator CS6設計與應用任務教程