MySQL :: MySQL 8.4 Reference Manual :: 7.9.3 The LOCK_ORDER Tool (original) (raw)

7.9.3 The LOCK_ORDER Tool

The MySQL server is a multithreaded application that uses numerous internal locking and lock-related primitives, such as mutexes, rwlocks (including prlocks and sxlocks), conditions, and files. Within the server, the set of lock-related objects changes with implementation of new features and code refactoring for performance improvements. As with any multithreaded application that uses locking primitives, there is always a risk of encountering a deadlock during execution when multiple locks are held at once. For MySQL, the effect of a deadlock is catastrophic, causing a complete loss of service.

To enable detection of lock-acquisition deadlocks and enforcement that runtime execution is free of them, MySQL supportsLOCK_ORDER tooling. This enables a lock-order dependency graph to be defined as part of server design, and server runtime checking to ensure that lock acquisition is acyclic and that execution paths comply with the graph.

This section provides information about using theLOCK_ORDER tool, but only at a basic level. For complete details, see the Lock Order section of the MySQL Server Doxygen documentation, available athttps://dev.mysql.com/doc/index-other.html.

The LOCK_ORDER tool is intended for debugging the server, not for production use.

To use the LOCK_ORDER tool, follow this procedure:

  1. Build MySQL from source, configuring it with the-DWITH_LOCK_ORDER=ON CMake option so that the build includesLOCK_ORDER tooling.
    Note
    With the WITH_LOCK_ORDER option enabled, MySQL builds require theflex program.
  2. To run the server with the LOCK_ORDER tool enabled, enable thelock_order system variable at server startup. Several other system variables forLOCK_ORDER configuration are available as well.
  3. For MySQL test suite operation,mysql-test-run.pl has a--lock-order option that controls whether to enable the LOCK_ORDER tool during test case execution.

The system variables described following configure operation of the LOCK_ORDER tool, assuming that MySQL has been built to include LOCK_ORDER tooling. The primary variable is lock_order, which indicates whether to enable theLOCK_ORDER tool at runtime:

Note

In general, it is intended that theLOCK_ORDER tool be configured by executingmysql-test-run.pl with the--lock-order option, and formysql-test-run.pl to setLOCK_ORDER system variables to appropriate values.

All LOCK_ORDER system variables must be set at server startup. At runtime, their values are visible but cannot be changed.

Some system variables exist in pairs, such aslock_order_debug_loop andlock_order_trace_loop. For such pairs, the variables are distinguished as follows when the condition occurs with which they are associated:

Table 7.8 LOCK_ORDER System Variable Summary