Skip to content

Conversation

@varundeepsaini
Copy link

@varundeepsaini varundeepsaini commented Dec 22, 2025

  • The Jira issue number for this PR is: MDEV-16335

Description

Currently, deadlock information is only available globally via SHOW ENGINE INNODB STATUS, so a client can never be certain that the information shown is for their own session's deadlock.

This patch stores deadlock information in the victim transaction's structure when a deadlock is detected, making it accessible via SHOW WARNINGS.

Implementation

  • Added deadlock_info fields to trx_lock_t to store per-session deadlock information
  • In Deadlock::report(), copy deadlock info to the victim transaction (only when srv_print_all_deadlocks is set)
  • In convert_error_code_to_mysql(), push deadlock info as a warning via push_warning_printf()
  • Clear deadlock info when a new transaction starts or when the transaction is freed

Release Notes

When innodb_print_all_deadlocks=ON, deadlock detail information is now available per-session via SHOW WARNINGS after a deadlock error (ER_LOCK_DEADLOCK).

How can this PR be tested?

./mtr --suite=innodb deadlock_session_info

Basing the PR against the correct MariaDB version

  • This is a new feature and the PR is based against the main branch.

PR quality check

  • I checked the CODING_STANDARDS.md file and my PR conforms to this where appropriate.
  • For any trivial modifications to the PR, I am ok with the reviewer making the changes themselves.

@CLAassistant
Copy link

CLAassistant commented Dec 22, 2025

CLA assistant check
All committers have signed the CLA.

@varundeepsaini varundeepsaini marked this pull request as draft December 22, 2025 19:46
@varundeepsaini varundeepsaini force-pushed the MDEV-16335-deadlock-info-show-warnings branch 2 times, most recently from cc12800 to 67920e9 Compare December 22, 2025 21:07
@varundeepsaini varundeepsaini force-pushed the MDEV-16335-deadlock-info-show-warnings branch from 67920e9 to 19592c6 Compare December 22, 2025 21:23
@varundeepsaini varundeepsaini force-pushed the MDEV-16335-deadlock-info-show-warnings branch from 63a7517 to 0cf376f Compare December 24, 2025 05:04
@varundeepsaini varundeepsaini marked this pull request as ready for review December 24, 2025 05:22
static_cast<size_t>(len),
lock_latest_err_file);
if (deadlock_info_len && deadlock_info[deadlock_info_len - 1] == '\n')
--deadlock_info_len;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We cannot read more than ftell returned: deadlock_info is a temporary file and we access it under lock.
We can put assert

ut_ad(len >= deadlock_info_len);

maybe +1 somewhere -- please check.

Then this if is not needed, as well as zero assignment.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What we know is that fread can return only less bytes than ftell did:
https://en.cppreference.com/w/c/io/fread#:~:text=stream%20to%20read-,Return%20value,-Number%20of%20objects

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

5 participants