Skip to content

Conversation

janlindstrom
Copy link
Contributor

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

Description

Added warning messages for applier FK failures. Warnings are printed by default and can be disabled using
set global wsrep_mode=APPLIER_DISABLE_FK_WARNINGS;

Ported to MariaDB jan.lindstrom@galeracluster.com

Release Notes

TODO: What should the release notes say about this change?
Include any changed system variables, status variables or behaviour. Optionally list any https://mariadb.com/kb/ pages that need changing.

How can this PR be tested?

TODO: modify the automated test suite to verify that the PR causes MariaDB to behave as intended.
Consult the documentation on "Writing good test cases".

If the changes are not amenable to automated testing, please explain why not and carefully describe how to test manually.

Basing the PR against the correct MariaDB version

  • This is a new feature or a refactoring, and the PR is based against the main branch.
  • [ x] This is a bug fix, and the PR is based against the earliest maintained branch in which the bug can be reproduced.

PR quality check

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

Added warning messages for applier FK failures. Warnings are
printed by default and can be disabled using
set global wsrep_mode=APPLIER_DISABLE_FK_WARNINGS;

Ported to MariaDB jan.lindstrom@galeracluster.com
@janlindstrom janlindstrom self-assigned this Oct 6, 2025
@janlindstrom janlindstrom requested a review from dr-m October 6, 2025 12:06
@svoj svoj added the Codership Codership Galera label Oct 6, 2025
SET GLOBAL DEBUG_DBUG = "";
SET DEBUG_SYNC = 'RESET';
connection node_1;
call mtr.add_suppression("WSREP: Foreign key check table:.*");
Copy link
Contributor

Choose a reason for hiding this comment

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

.* at the end of the regular expression is redundant, because there is no implied $ anchor. Shouldn’t there also be a search_pattern_in_file.inc for ensuring that the message is present?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

Comment on lines 782 to 784
fputs("\nBut in child table ", ef);
ut_print_name(ef, trx, foreign->foreign_table_name);
fputs(fk_table_str.c_str(), ef);
fprintf(ef, ", in index %s", foreign->foreign_index->name());
Copy link
Contributor

Choose a reason for hiding this comment

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

Please, let’s avoid using any std::string and use a single my_printf_error or similar for this. See how the function dict_table_open_failed() is displaying table names.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I do not see reason for this because function already used std::string see line 771 i.e. fk_str = dict_print_info_on_foreign_key_in_create_format(...)

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, it was already suboptimal, and since the time the code was originally written, we are aware of a more efficient way of displaying InnoDB table names. One thing that I overlooked yesterday is the conversion from my_charset_filename to system_charset_info (UTF-8). A test case for this must involve table names that include some non-alphanumeric characters, such as - or $. The test case also needs to search for these messages in the SHOW ENGINE INNODB STATUS output.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will revert changes to here as they are not needed, I rather change only wsrep code and change InnoDB as less as possible.

Comment on lines +1030 to +1038
void wsrep_fk_warn(const std::string warn_msg,
const trx_t* trx,
const dict_table_t *table,
const dict_index_t *index,
const dberr_t err)
{
std::string fk_warn= "Foreign key check table: %s index: %s failed for ";
fk_warn+= warn_msg;
fk_warn+=" err: %s";
Copy link
Contributor

Choose a reason for hiding this comment

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

Please avoid the use of std::string. It can lead to significant memory heap fragmentation.

The message is very confusing, because CHECK TABLE looks like a SQL statement. Why is the name of the failing constraint not being displayed? That together with the referencing table name should be sufficient diagnostics.

Copy link
Contributor Author

@janlindstrom janlindstrom Oct 8, 2025

Choose a reason for hiding this comment

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

Maybe it causes heap fragmentation, but std::string is used also in InnoDB codebase already, this function is called only when some foreign key action fails in applier, this means that foreign key action was successful on originating node in cluster and now write set of this action was successfully certified but execution failed for some reason when write set is applied in other node. In some cases this means that cluster nodes are inconsistent state leading to inconsistency voting (i.e. what was majority of nodes decision on this write set). Meaning that this error printing should not be any regular or frequent thing. In case there is lock wait as this is applier it will kill conflicting local transactions, thus there is possibility that two conflicting foreign key actions arrive from different nodes in cluster in same time and they are executed in order of their sequence number, if there still is lock wait or deadlock error write set action is replayed.

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

Successfully merging this pull request may close these issues.

4 participants