Commit 8024f8c6 authored by Marko Mäkelä's avatar Marko Mäkelä

MDEV-18272 InnoDB fails to rollback after exceeding FOREIGN KEY recursion depth

row_mysql_handle_errors(): Correct the wrong error handling for
the code DB_FOREIGN_EXCEED_MAX_CASCADE that was introduced in

https://github.com/mysql/mysql-server/commit/c0923d396aef46799883390e9dcf7bbf173e4a03

    commit 35f5429e
    Author: Jimmy Yang <jimmy.yang@oracle.com>
    Date:   Wed Oct 6 06:55:34 2010 -0700

        Manual port Bug #Bug #54582 "stack overflow when opening many tables
        linked with foreign keys at once" from mysql-5.1-security to
        mysql-5.5-security again.

        rb://391 approved by Heikki

No known test case exists for repeating the bug before MariaDB 10.2.
The scenario should be that DB_FOREIGN_EXCEED_MAX_CASCADE is returned,
then InnoDB wrongly skips the rollback to the start of the current
row operation, and finally the SQL layer commits the transaction.
Normally the SQL layer would roll back either the entire transaction or
to the start of the statement. In the faulty scenario, InnoDB would
leave the transaction in an inconsistent state, and the SQL layer could
commit the transaction.
parent cb11b3fb
/***************************************************************************** /*****************************************************************************
Copyright (c) 2000, 2014, Oracle and/or its affiliates. All Rights Reserved. Copyright (c) 2000, 2014, Oracle and/or its affiliates. All Rights Reserved.
Copyright (c) 2019, MariaDB Corporation.
This program is free software; you can redistribute it and/or modify it under This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software the terms of the GNU General Public License as published by the Free Software
...@@ -572,8 +573,7 @@ row_mysql_handle_errors( ...@@ -572,8 +573,7 @@ row_mysql_handle_errors(
switch (err) { switch (err) {
case DB_LOCK_WAIT_TIMEOUT: case DB_LOCK_WAIT_TIMEOUT:
if (row_rollback_on_timeout) { if (row_rollback_on_timeout) {
trx_general_rollback_for_mysql(trx, NULL); goto rollback;
break;
} }
/* fall through */ /* fall through */
case DB_DUPLICATE_KEY: case DB_DUPLICATE_KEY:
...@@ -586,6 +586,7 @@ row_mysql_handle_errors( ...@@ -586,6 +586,7 @@ row_mysql_handle_errors(
case DB_TOO_MANY_CONCURRENT_TRXS: case DB_TOO_MANY_CONCURRENT_TRXS:
case DB_OUT_OF_FILE_SPACE: case DB_OUT_OF_FILE_SPACE:
case DB_INTERRUPTED: case DB_INTERRUPTED:
rollback_to_savept:
if (savept) { if (savept) {
/* Roll back the latest, possibly incomplete /* Roll back the latest, possibly incomplete
insertion or update */ insertion or update */
...@@ -609,6 +610,7 @@ row_mysql_handle_errors( ...@@ -609,6 +610,7 @@ row_mysql_handle_errors(
case DB_DEADLOCK: case DB_DEADLOCK:
case DB_LOCK_TABLE_FULL: case DB_LOCK_TABLE_FULL:
rollback:
/* Roll back the whole transaction; this resolution was added /* Roll back the whole transaction; this resolution was added
to version 3.23.43 */ to version 3.23.43 */
...@@ -638,14 +640,14 @@ row_mysql_handle_errors( ...@@ -638,14 +640,14 @@ row_mysql_handle_errors(
"InnoDB: you dump the tables, look at\n" "InnoDB: you dump the tables, look at\n"
"InnoDB: " REFMAN "forcing-innodb-recovery.html" "InnoDB: " REFMAN "forcing-innodb-recovery.html"
" for help.\n", stderr); " for help.\n", stderr);
break; goto rollback_to_savept;
case DB_FOREIGN_EXCEED_MAX_CASCADE: case DB_FOREIGN_EXCEED_MAX_CASCADE:
fprintf(stderr, "InnoDB: Cannot delete/update rows with" fprintf(stderr, "InnoDB: Cannot delete/update rows with"
" cascading foreign key constraints that exceed max" " cascading foreign key constraints that exceed max"
" depth of %lu\n" " depth of %lu\n"
"Please drop excessive foreign constraints" "Please drop excessive foreign constraints"
" and try again\n", (ulong) DICT_FK_MAX_RECURSIVE_LOAD); " and try again\n", (ulong) DICT_FK_MAX_RECURSIVE_LOAD);
break; goto rollback_to_savept;
default: default:
fprintf(stderr, "InnoDB: unknown error code %lu\n", fprintf(stderr, "InnoDB: unknown error code %lu\n",
(ulong) err); (ulong) err);
......
/***************************************************************************** /*****************************************************************************
Copyright (c) 2000, 2014, Oracle and/or its affiliates. All Rights Reserved. Copyright (c) 2000, 2014, Oracle and/or its affiliates. All Rights Reserved.
Copyright (c) 2019, MariaDB Corporation.
This program is free software; you can redistribute it and/or modify it under This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software the terms of the GNU General Public License as published by the Free Software
...@@ -574,8 +575,7 @@ row_mysql_handle_errors( ...@@ -574,8 +575,7 @@ row_mysql_handle_errors(
switch (err) { switch (err) {
case DB_LOCK_WAIT_TIMEOUT: case DB_LOCK_WAIT_TIMEOUT:
if (row_rollback_on_timeout) { if (row_rollback_on_timeout) {
trx_general_rollback_for_mysql(trx, NULL); goto rollback;
break;
} }
/* fall through */ /* fall through */
case DB_DUPLICATE_KEY: case DB_DUPLICATE_KEY:
...@@ -588,6 +588,7 @@ row_mysql_handle_errors( ...@@ -588,6 +588,7 @@ row_mysql_handle_errors(
case DB_TOO_MANY_CONCURRENT_TRXS: case DB_TOO_MANY_CONCURRENT_TRXS:
case DB_OUT_OF_FILE_SPACE: case DB_OUT_OF_FILE_SPACE:
case DB_INTERRUPTED: case DB_INTERRUPTED:
rollback_to_savept:
if (savept) { if (savept) {
/* Roll back the latest, possibly incomplete /* Roll back the latest, possibly incomplete
insertion or update */ insertion or update */
...@@ -611,6 +612,7 @@ row_mysql_handle_errors( ...@@ -611,6 +612,7 @@ row_mysql_handle_errors(
case DB_DEADLOCK: case DB_DEADLOCK:
case DB_LOCK_TABLE_FULL: case DB_LOCK_TABLE_FULL:
rollback:
/* Roll back the whole transaction; this resolution was added /* Roll back the whole transaction; this resolution was added
to version 3.23.43 */ to version 3.23.43 */
...@@ -640,14 +642,14 @@ row_mysql_handle_errors( ...@@ -640,14 +642,14 @@ row_mysql_handle_errors(
"InnoDB: you dump the tables, look at\n" "InnoDB: you dump the tables, look at\n"
"InnoDB: " REFMAN "forcing-innodb-recovery.html" "InnoDB: " REFMAN "forcing-innodb-recovery.html"
" for help.\n", stderr); " for help.\n", stderr);
break; goto rollback_to_savept;
case DB_FOREIGN_EXCEED_MAX_CASCADE: case DB_FOREIGN_EXCEED_MAX_CASCADE:
fprintf(stderr, "InnoDB: Cannot delete/update rows with" fprintf(stderr, "InnoDB: Cannot delete/update rows with"
" cascading foreign key constraints that exceed max" " cascading foreign key constraints that exceed max"
" depth of %lu\n" " depth of %lu\n"
"Please drop excessive foreign constraints" "Please drop excessive foreign constraints"
" and try again\n", (ulong) DICT_FK_MAX_RECURSIVE_LOAD); " and try again\n", (ulong) DICT_FK_MAX_RECURSIVE_LOAD);
break; goto rollback_to_savept;
default: default:
fprintf(stderr, "InnoDB: unknown error code %lu\n", fprintf(stderr, "InnoDB: unknown error code %lu\n",
(ulong) err); (ulong) err);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment