Lock Analysis
Intelligent O&M provides metadata lock, InnoDB lock wait, recent deadlock, and full deadlock analysis. This section describes how to perform lock analysis on an RDS for MySQL instance.
Prerequisites
You have created an RDS for MySQL instance.
Procedure
- Write test data to a table.
- Create test database das_test in the destination RDS for MySQL instance. For details, see Creating a Database.
- Log in to the RDS for MySQL database through DAS. For details, see Logging In to a Huawei Cloud DB Instance.
- Run the following SQL statement to create the shopping table in the das_test database:
CREATE TABLE shopping (
a int NOT NULL AUTO_INCREMENT,
b int,
c int,
PRIMARY KEY (a),
UNIQUE KEY u_k (b, c)
);
- Run the following command to write test data to the shopping table:
insert into shopping(b,c) values(1,1),(1,5),(1,9);
- Analyze and process metadata locks.
- Metadata locks are used to ensure consistency between DDL and DML operations. Executing DDL operations on a table generates metadata write locks. If there is a metadata lock, all subsequent SELECT, DML, and DDL operations on the table will be blocked, causing a backlog of connections.
- Metadata locks are displayed in real time, so you can quickly locate and terminate sessions holding metadata locks to restore blocked operations.
- This function is unavailable for DML locks. You can view and analyze them on the InnoDB Locks page.
- Up to 1,000 records can be displayed.
- Log in to the Huawei Cloud DB instance and execute a SQL statement to create session 1.
- Query data in the shopping table.
select a from shopping;
The following result is displayed:
Figure 1 Querying data in the test table
- Start a transaction and update data in the shopping table. Do not submit the transaction.
BEGIN;
UPDATE shopping SET b = 3 WHERE a =1;
- Query data in the shopping table.
- Create session 2 and execute the following statement to add an index to the shopping table:
ALTER TABLE shopping ADD INDEX idx_name(b);
- Go to the DAS homepage. In the navigation pane, choose Intelligent O&M > Instance List.
- Locate the target instance, click Details. Click the Locks and Transactions, Locks, and Metadata Locks tabs in sequence. Metadata locks of the current instance are displayed.
Figure 2 Metadata locks
- Select the target session and click Kill Session.
Figure 3 Selecting the target metadata lock
- Refresh the metadata lock list. The query statement has been executed, and the DDL statement is being executed.
If the shopping table contains a small amount of data, the DDL statement will be executed successfully immediately after the session is killed.
Figure 4 Metadata lock list updated after the session is killed
- Analyze InnoDB lock waits.
- InnoDB lock waits generated before DML operations are displayed in real time. You can quickly locate the session waits and any blocks that happened when multiple sessions update the same piece of data at the same time. You can also terminate the source session that holds locks to restore blocked operations.
- This function is unavailable for DDL locks. You can view and analyze them on the Metadata Locks page.
- Log in to the Huawei Cloud DB instance and execute a SQL statement to create session 1.
- Query data in the shopping table.
select a from shopping;
The following result is displayed:
Figure 5 Querying data in the test table
- Start a transaction and update data in the shopping table. Do not submit the transaction.
BEGIN;
UPDATE shopping SET b = 100 WHERE a < 5;
- Query data in the shopping table.
- Create session 2 and update the statement that has been updated in session 1:
- Create session 3 and update the statement that has been updated in session 1:
- Go to the DAS homepage. In the navigation pane, choose Intelligent O&M > Instance List.
- Locate the target instance, click Details. Click the Locks and Transactions, Locks, and InnoDB Locks tabs in sequence. InnoDB lock waits of the current instance are displayed.
Figure 6 InnoDB lock waits
- In session 1, run the following command to submit the transaction:
- Check the InnoDB lock wait. No lock wait is displayed on the page.
- Analyze a recent deadlock.
- DAS analyzes the latest deadlock log displayed in the output of SHOW ENGINE INNODB STATUS. If there are multiple deadlocks, only the latest one is analyzed.
- Enable innodb_deadlock_detect (only for RDS for MySQL 5.7).
- Log in to the Huawei Cloud DB instance and execute the following SQL statement to query data in the shopping table.
select a from shopping;
The following result is displayed:
Figure 7 Querying data in the test table
- Use the SQL Query module to query sessions 1 and 2. Simulate a deadlock.
Table 1 Simulating a deadlock Session 1
Session 2
begin;
begin;
insert into shopping(b,c) values(1,8);
-
-
insert into shopping(b,c) values(1,8);
insert into shopping(b,c) values(1,6);
-
-
A deadlock is generated.
- Go to the DAS homepage. In the navigation pane, choose Intelligent O&M > Instance List.
- Locate the target instance, click Details. Click the Locks and Transactions, Locks, and Deadlock Analysis tabs in sequence. Click Create Lock Analysis, refresh the page, and check the list.
Figure 8 Recent deadlock
- Click View Details in the Operation column to view parsed deadlocks and original logs.
Figure 9 Details of a recent deadlock
- Analyze full deadlocks.
- DAS analyzes error logs at regular intervals, parses deadlock information, and performs comprehensive deadlock analysis.
- Dependency parameters:
- Enable innodb_deadlock_detect (only for RDS for MySQL 5.7).
- Enable innodb_print_all_deadlocks and set log_error_verbosity (only for RDS for MySQL of versions other than 5.7) to 3.
- Up to 10,000 records can be displayed.
- Log in to the DAS console.
- Click in the upper left corner and select a region and project.
- Click in the upper left corner. Choose Databases > Data Admin Service.
- In the navigation pane, choose Intelligent O&M > Instance List.
- Locate the target instance, click Details. Click the Locks and Transactions, Locks, and Full Deadlock Analysis tabs in sequence. Enable Full Deadlock Analysis.
- In the navigation pane, choose Development Tool.
You can also click Go to Development Tool on the overview page.
- Select the target database, click Log In in the Operation column, and run the following SQL statement to query data in the shopping table.
select a from shopping;
The following result is displayed:
Figure 10 Querying data in the test table
- Use the SQL Query module to query sessions 1 and 2. Simulate a deadlock.
Table 2 Simulating a deadlock Session 1
Session 2
begin;
begin;
insert into shopping(b,c) values(1,8);
-
-
insert into shopping(b,c) values(1,8);
insert into shopping(b,c) values(1,6);
-
-
A deadlock is generated.
- View the full deadlock analysis list.
Figure 11 Full deadlock
- Click View Details in the Operation column to view parsed deadlocks and original logs.
Figure 12 Full deadlock details
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