Compute
Elastic Cloud Server
Huawei Cloud Flexus
Bare Metal Server
Auto Scaling
Image Management Service
Dedicated Host
FunctionGraph
Cloud Phone Host
Huawei Cloud EulerOS
Networking
Virtual Private Cloud
Elastic IP
Elastic Load Balance
NAT Gateway
Direct Connect
Virtual Private Network
VPC Endpoint
Cloud Connect
Enterprise Router
Enterprise Switch
Global Accelerator
Management & Governance
Cloud Eye
Identity and Access Management
Cloud Trace Service
Resource Formation Service
Tag Management Service
Log Tank Service
Config
OneAccess
Resource Access Manager
Simple Message Notification
Application Performance Management
Application Operations Management
Organizations
Optimization Advisor
IAM Identity Center
Cloud Operations Center
Resource Governance Center
Migration
Server Migration Service
Object Storage Migration Service
Cloud Data Migration
Migration Center
Cloud Ecosystem
KooGallery
Partner Center
User Support
My Account
Billing Center
Cost Center
Resource Center
Enterprise Management
Service Tickets
HUAWEI CLOUD (International) FAQs
ICP Filing
Support Plans
My Credentials
Customer Operation Capabilities
Partner Support Plans
Professional Services
Analytics
MapReduce Service
Data Lake Insight
CloudTable Service
Cloud Search Service
Data Lake Visualization
Data Ingestion Service
GaussDB(DWS)
DataArts Studio
Data Lake Factory
DataArts Lake Formation
IoT
IoT Device Access
Others
Product Pricing Details
System Permissions
Console Quick Start
Common FAQs
Instructions for Associating with a HUAWEI CLOUD Partner
Message Center
Security & Compliance
Security Technologies and Applications
Web Application Firewall
Host Security Service
Cloud Firewall
SecMaster
Anti-DDoS Service
Data Encryption Workshop
Database Security Service
Cloud Bastion Host
Data Security Center
Cloud Certificate Manager
Edge Security
Managed Threat Detection
Blockchain
Blockchain Service
Web3 Node Engine Service
Media Services
Media Processing Center
Video On Demand
Live
SparkRTC
MetaStudio
Storage
Object Storage Service
Elastic Volume Service
Cloud Backup and Recovery
Storage Disaster Recovery Service
Scalable File Service Turbo
Scalable File Service
Volume Backup Service
Cloud Server Backup Service
Data Express Service
Dedicated Distributed Storage Service
Containers
Cloud Container Engine
SoftWare Repository for Container
Application Service Mesh
Ubiquitous Cloud Native Service
Cloud Container Instance
Databases
Relational Database Service
Document Database Service
Data Admin Service
Data Replication Service
GeminiDB
GaussDB
Distributed Database Middleware
Database and Application Migration UGO
TaurusDB
Middleware
Distributed Cache Service
API Gateway
Distributed Message Service for Kafka
Distributed Message Service for RabbitMQ
Distributed Message Service for RocketMQ
Cloud Service Engine
Multi-Site High Availability Service
EventGrid
Dedicated Cloud
Dedicated Computing Cluster
Business Applications
Workspace
ROMA Connect
Message & SMS
Domain Name Service
Edge Data Center Management
Meeting
AI
Face Recognition Service
Graph Engine Service
Content Moderation
Image Recognition
Optical Character Recognition
ModelArts
ImageSearch
Conversational Bot Service
Speech Interaction Service
Huawei HiLens
Video Intelligent Analysis Service
Developer Tools
SDK Developer Guide
API Request Signing Guide
Terraform
Koo Command Line Interface
Content Delivery & Edge Computing
Content Delivery Network
Intelligent EdgeFabric
CloudPond
Intelligent EdgeCloud
Solutions
SAP Cloud
High Performance Computing
Developer Services
ServiceStage
CodeArts
CodeArts PerfTest
CodeArts Req
CodeArts Pipeline
CodeArts Build
CodeArts Deploy
CodeArts Artifact
CodeArts TestPlan
CodeArts Check
CodeArts Repo
Cloud Application Engine
MacroVerse aPaaS
KooMessage
KooPhone
KooDrive
On this page

Lock Analysis

Updated on 2024-11-26 GMT+08:00

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

  1. Write test data to a table.

    1. Create test database das_test in the destination RDS for MySQL instance. For details, see Creating a Database.
    2. Log in to the RDS for MySQL database through DAS. For details, see Logging In to a Huawei Cloud DB Instance.
    3. 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)

      );

    4. Run the following command to write test data to the shopping table:

      insert into shopping(b,c) values(1,1),(1,5),(1,9);

    NOTE:
    After data is written to the table:
    • Perform 2 to analyze and process metadata locks.
    • Perform 3 to analyze InnoDB lock waits.
    • Perform 4 to analyze a recent deadlock.
    • Perform 5 to analyze full deadlocks.

  2. Analyze and process metadata locks.

    NOTE:
    • 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.
    1. Log in to the Huawei Cloud DB instance and execute a SQL statement to create session 1.
      1. Query data in the shopping table.

        select a from shopping;

        The following result is displayed:

        Figure 1 Querying data in the test table
      2. Start a transaction and update data in the shopping table. Do not submit the transaction.

        BEGIN;

        UPDATE shopping SET b = 3 WHERE a =1;

    2. Create session 2 and execute the following statement to add an index to the shopping table:

      ALTER TABLE shopping ADD INDEX idx_name(b);

    3. Go to the DAS homepage. In the navigation pane, choose Intelligent O&M > Instance List.
    4. 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
    5. Select the target session and click Kill Session.
      Figure 3 Selecting the target metadata lock
    6. Refresh the metadata lock list. The query statement has been executed, and the DDL statement is being executed.
      NOTE:

      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

  3. Analyze InnoDB lock waits.

    NOTE:
    • 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.
    1. Log in to the Huawei Cloud DB instance and execute a SQL statement to create session 1.
      1. Query data in the shopping table.

        select a from shopping;

        The following result is displayed:

        Figure 5 Querying data in the test table
      2. Start a transaction and update data in the shopping table. Do not submit the transaction.

        BEGIN;

        UPDATE shopping SET b = 100 WHERE a < 5;

    2. Create session 2 and update the statement that has been updated in session 1:

      UPDATE shopping SET b = 3 WHERE a = 1;

    3. Create session 3 and update the statement that has been updated in session 1:

      UPDATE shopping SET b = 4 WHERE a = 2;

    4. Go to the DAS homepage. In the navigation pane, choose Intelligent O&M > Instance List.
    5. 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
    6. In session 1, run the following command to submit the transaction:

      COMMIT;

    7. Check the InnoDB lock wait. No lock wait is displayed on the page.

  4. Analyze a recent deadlock.

    NOTE:
    • 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).
    1. 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
    2. 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.

    3. Go to the DAS homepage. In the navigation pane, choose Intelligent O&M > Instance List.
    4. 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
    5. Click View Details in the Operation column to view parsed deadlocks and original logs.
      Figure 9 Details of a recent deadlock

  5. Analyze full deadlocks.

    NOTE:
    • 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.
    1. Log in to the DAS console.
    2. Click in the upper left corner and select a region and project.
    3. Click in the upper left corner. Choose Databases > Data Admin Service.
    4. In the navigation pane, choose Intelligent O&M > Instance List.
    5. Locate the target instance, click Details. Click the Locks and Transactions, Locks, and Full Deadlock Analysis tabs in sequence. Enable Full Deadlock Analysis.
    6. In the navigation pane, choose Development Tool.

      You can also click Go to Development Tool on the overview page.

    7. 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
    8. 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.

    9. View the full deadlock analysis list.
      Figure 11 Full deadlock
    10. Click View Details in the Operation column to view parsed deadlocks and original logs.
      Figure 12 Full deadlock details

We use cookies to improve our site and your experience. By continuing to browse our site you accept our cookie policy. Find out more

Feedback

Feedback

Feedback

0/500

Selected Content

Submit selected content with the feedback