Analyzing InnoDB Semaphore Crashes and a DBA Diagnostic Tool
The article explains why InnoDB semaphore waits exceeding 600 seconds trigger server crashes, details the lock structures and functions involved, shows how buffer pool pressure and metadata statistics cause contention, and introduces a small DBA utility that parses MySQL error logs to reveal the relationships between threads, locks, and transactions.
When InnoDB detects a semaphore wait longer than 600 seconds, the background thread srv_error_monitor_thread will panic after ten consecutive checks, preventing the server from hanging indefinitely.
The log shows a MySQL 5.5.40 instance where thread 139998697924352 holds an X‑lock on a data‑dictionary latch for over 900 seconds, while another thread waits at dict0dict.c:305 and btr0sea.c:1134.
These locks occur in the functions dict_table_stats_lock (triggered by innodb_stats_on_metadata) and btr_search_drop_page_hash_index (used by the Adaptive Hash Index during buffer‑pool eviction). The global AHI lock btr_search_latch becomes a hotspot, especially when the buffer pool is full.
The article provides a concise summary: enabling metadata statistics updates and insufficient buffer‑pool space cause the data‑dictionary lock to block many operations, while AHI lock contention during page eviction leads to the final semaphore timeout and crash.
To help DBAs diagnose such issues, the author created a small command‑line program mysqldba. Example usage: mysqldba doctor -f /Users/hongbin/workbench/mysqld_safe.log The tool extracts semaphore crash events, counts service starts, identifies which threads waited on which RW‑latches, and correlates writer threads with their transaction information. It can also monitor live logs for the keyword “a writer (thread id …) has reserved it in mode” and capture transaction details on‑the‑fly.
Additional commands include: mysqldba -uxxx -pxxx doctor -w which watches the MySQL error log in real time and records relevant transaction data.
For more information and to access the source code, visit the GitHub repository: https://github.com/kevinbin/mysqldba .
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Aikesheng Open Source Community
The Aikesheng Open Source Community provides stable, enterprise‑grade MySQL open‑source tools and services, releases a premium open‑source component each year (1024), and continuously operates and maintains them.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
