-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
MDEV-16335: Include deadlock detail information in SHOW WARNINGS #4492
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
MDEV-16335: Include deadlock detail information in SHOW WARNINGS #4492
Conversation
cc12800 to
67920e9
Compare
Signed-off-by: Varun Deep Saini <varun.23bcs10048@ms.sst.scaler.com>
67920e9 to
19592c6
Compare
63a7517 to
0cf376f
Compare
storage/innobase/lock/lock0lock.cc
Outdated
| static_cast<size_t>(len), | ||
| lock_latest_err_file); | ||
| if (deadlock_info_len && deadlock_info[deadlock_info_len - 1] == '\n') | ||
| --deadlock_info_len; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
FooBarrior
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me.
dr-m
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test for this functionality is only executed in debug-instrumented builds. I think that new functionality had better tested with all builds, so that the functionality will be better covered. For example, GNU/Linux distributions that package MariaDB themselves will likely not use CMAKE_BUILD_TYPE=Debug at all. We should test what we ship.
| deadlock_info= static_cast<char*>(ut_malloc_nokey( | ||
| static_cast<size_t>(len) + 1)); | ||
| if (!deadlock_info) | ||
| goto func_exit; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The memory will be leaked if !deadlock_info.
Why would we do all this busy work if !current_trx || victim != trx || !trx->mysql_thd?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The memory will be leaked if
!deadlock_info.
Which memory?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean in case of !deadlock_info it's not allocated, and besides ut_free is called unconditionally after func_exit. So do you mean some other memory?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, sorry, I take my words back regarding deadlock_info == nullptr.
|
|
||
| if (!srv_print_all_deadlocks) | ||
| goto func_exit; | ||
| long len= ftell(lock_latest_err_file); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is confusing, why you do these file operations? IMHO it would be better to change current print functions to produce string that is then written to both to the deadlock error file and pushed to warning.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The temporary file is a relic from MySQL 5.5 or earlier when InnoDB was written in C and there was no formatted output facility into a heap-allocated buffer. That could be fixed separately. I seemed to remember that there is an option to expose the lock_latest_err_file in the file system, but there only is the Boolean option innodb_status_file that covers the entire SHOW ENGINE INNODB STATUS output.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@janlindstrom the nearly same is done from the side of SHOW INNODB STATUS -- the file is opened, ftell'd, etc. I think this work may remain local, wihtout the requirement to refactor.
storage/innobase/lock/lock0lock.cc
Outdated
| static_cast<size_t>(len), | ||
| lock_latest_err_file); | ||
| ut_ad(deadlock_info_len <= static_cast<size_t>(len)); | ||
| if (deadlock_info[deadlock_info_len - 1] == '\n') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this will crash if deadlock_info_len is 0
|
You didn't check
|
Signed-off-by: Varun Deep Saini <varun.23bcs10048@ms.sst.scaler.com>
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
deadlock_infofields totrx_lock_tto store per-session deadlock informationDeadlock::report(), copy deadlock info to the victim transaction (only whensrv_print_all_deadlocksis set)convert_error_code_to_mysql(), push deadlock info as a warning viapush_warning_printf()Release Notes
When
innodb_print_all_deadlocks=ON, deadlock detail information is now available per-session viaSHOW WARNINGSafter a deadlock error (ER_LOCK_DEADLOCK).How can this PR be tested?
Basing the PR against the correct MariaDB version
mainbranch.PR quality check