[MDEV-26053] TRUNCATE on table with Foreign Key Constraint no longer replicated to other nodes Created: 2021-06-30 Updated: 2021-12-01 Resolved: 2021-09-17 |
|
| Status: | Closed |
| Project: | MariaDB Server |
| Component/s: | Galera, Storage Engine - InnoDB |
| Affects Version/s: | 10.4, 10.5, 10.6 |
| Fix Version/s: | 10.4.22, 10.5.13, 10.6.5 |
| Type: | Bug | Priority: | Critical |
| Reporter: | Hartmut Holzgraefe | Assignee: | Jan Lindström (Inactive) |
| Resolution: | Fixed | Votes: | 3 |
| Labels: | None | ||
| Issue Links: |
|
||||||||
| Description |
|
When using the KB example for creating a table pair with a foreign key constraint:
Then truncating the "book" table:
The table is empty as expected on the node where the TRUNCATE was executed, but not on the other nodes in the cluster. Nothing is logged in the error log, it seems as if the TRUNCATE is just silently ignored. The earliest version I can reproduce this on is MariaDB 10.5.9, so it seems to be a rather recent regression, on earlier versions it works as expected. I filed this as "critical" as it can easily lead to data inconsistencies across the cluster which may only actually be detected, and lead to problems, much later. |
| Comments |
| Comment by Hartmut Holzgraefe [ 2021-06-30 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Everything was done with wsrep_osu_method=TOI, just to clarify. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Hartmut Holzgraefe [ 2021-06-30 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Both latest 10.4 and 10.5 releases area actually affected. Latest 10.3.30 is still good though | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Jan Lindström (Inactive) [ 2021-07-01 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
It seems to be broken from 10.4 i.e. when Galera 4 was introduced. Very strange that it has not been noticed before. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Jan Lindström (Inactive) [ 2021-07-01 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
I can repeat issue with InnoDB only and using 10.3.30 :
I think now question is TRUNCATE counted as ON DELETE ? | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Jan Lindström (Inactive) [ 2021-07-01 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
marko I do not remember the rules on TRUNCATE when we have ON DELETE CASCADE constraint? | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Jan Lindström (Inactive) [ 2021-07-01 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
From Galera point of view both nodes have exactly the same rows so I can't repeat any inconsistency:
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Marko Mäkelä [ 2021-07-01 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
An attempt to TRUNCATE the referenced table does fail as expected:
Admittedly, it feels confusing to allow TRUNCATE on the referencing table when ON DELETE CASCADE or ON DELETE SET NULL actions exist. But as long as I remember, it has been like that. Already the first implementation of TRUNCATE in InnoDB is only checking that the table is not being referenced by FOREIGN KEY constraints in other tables. It does not care to check the ON DELETE CASCADE or ON DELETE SET NULL. serg, do you think that we should fix this in the earliest applicable supported version (10.2)? Should we fix it at all in GA versions? | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Hartmut Holzgraefe [ 2021-07-01 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
> do you think that we should fix this in the earliest applicable supported version (10.2)? Note that I could only reproduce this in 10.4 and up, and only in latest three 10.4 and 10.5 releases? (Also now finally tried 10.6.2 -> also affected) > Admittedly, it feels confusing to allow TRUNCATE on the referencing table when ON DELETE CASCADE or ON DELETE SET NULL actions exist. Why should TRUNCATE be different to DELETE without WHERE on the referencing table? | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Marko Mäkelä [ 2021-07-01 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
I can repeat this on earlier versions too:
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Hartmut Holzgraefe [ 2021-07-01 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
I can only repeat it with 10.4.18 to .20 and 10.5.9 to .11 (and 10.6.2, did not check the earlier 10.6.x versions yet). Earlier 10.4 and 10.5 versions work fine for me, and I could not reproduce it with 10.3 at all. I used the same configuration for all of these tests, just changed the repository URLs to different MariaDB versions before firing up VMs each time. Using default configuration each time, with just this added:
(server_id, wsrep_node_address and wsrep_node_name obviously being different on different nodes) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Valerii Kravchuk [ 2021-07-01 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
I've built both MariaDB 10.4 and Galera 4.x from current GitHub sources and in my test the table is truncated on other nodes:
These are exact commits used:
Galera was built with cmake ., while MySQL 10.4:
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Christian [ 2021-07-02 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
To me it seems that there are two issues discussed in this Ticket: The initial problem is, that a `TRUNCATE TABLE` is not executed on the replica node, if there is ANY FK constraint, even if it is `ON DELETE NO ACTION ON UPDATE NO ACTION`. That the referenced table might also not be handled correctly in case of `ON DELETE CASCADE`, or a similar action, seems to be a second issue. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Jan Lindström (Inactive) [ 2021-07-02 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
What we know about problem that TRUNCATE TABLE is not replicated to second node:
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Marko Mäkelä [ 2021-07-02 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
jplindst, if there is a Galera replication problem of TRUNCATE TABLE, then please continue handling that in this ticket, and assign this ticket to yourself. And file a separate ticket for the bug that we wrongly allow TRUNCATE on the referencing table when ON DELETE CASCADE or ON DELETE SET NULL actions exist. (Users could expect TRUNCATE to be like DELETE, but we are not executing those actions.) Because that bug has existed for many years, we need a decision from serg in which versions to fix it, or whether to fix it at all, or only based on some SQL_MODE. Maybe an acceptable work-around for users who expect such sloppy TRUNCATE would be to SET foreign_key_checks=0. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Christian [ 2021-07-05 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
also with wsrep_slave_FK_checks=OFF, TRUNCATE of tables with FKs on galera replica nodes does work. So, I guess, since it is not affected by wsrep_slave_FK_checks, it is not a galera problem. |