MDEV-26053 : TRUNCATE on table with Foreign Key Constraint no longer replicated to other nodes
Problem was that there was extra condition !thd->lex->no_write_to_binlog before call to begin TOI. It seems that this variable is not initialized. TRUNCATE does not support [NO_WRITE_TO_BINLOG | LOCAL] keywords, thus we should not check this condition. All this was hidden in a macro, so I decided to remove those macros that were used only a few places with actual function calls.
This commit is contained in:
parent
5b0a76078a
commit
d3b35598fc
@ -23,8 +23,6 @@
|
||||
#define DBUG_ASSERT_IF_WSREP(A) DBUG_ASSERT(A)
|
||||
|
||||
#define WSREP_MYSQL_DB (char *)"mysql"
|
||||
#define WSREP_TO_ISOLATION_BEGIN_IF(db_, table_, table_list_) \
|
||||
if (WSREP_ON && WSREP(thd) && wsrep_to_isolation_begin(thd, db_, table_, table_list_))
|
||||
|
||||
#define WSREP_TO_ISOLATION_BEGIN(db_, table_, table_list_) \
|
||||
if (WSREP_ON && WSREP(thd) && wsrep_to_isolation_begin(thd, db_, table_, table_list_)) \
|
||||
@ -48,10 +46,6 @@
|
||||
if (WSREP(thd) && !thd->lex->no_write_to_binlog \
|
||||
&& wsrep_to_isolation_begin(thd, db_, table_, table_list_)) goto wsrep_error_label;
|
||||
|
||||
#define WSREP_TO_ISOLATION_BEGIN_FK_TABLES(db_, table_, table_list_, fk_tables) \
|
||||
if (WSREP(thd) && !thd->lex->no_write_to_binlog \
|
||||
&& wsrep_to_isolation_begin(thd, db_, table_, table_list_, NULL, fk_tables))
|
||||
|
||||
#define WSREP_DEBUG(...) \
|
||||
if (wsrep_debug) WSREP_LOG(sql_print_information, ##__VA_ARGS__)
|
||||
#define WSREP_INFO(...) WSREP_LOG(sql_print_information, ##__VA_ARGS__)
|
||||
@ -75,7 +69,6 @@
|
||||
#define WSREP_ERROR(...)
|
||||
#define WSREP_TO_ISOLATION_BEGIN(db_, table_, table_list_) do { } while(0)
|
||||
#define WSREP_TO_ISOLATION_BEGIN_ALTER(db_, table_, table_list_, alter_info_)
|
||||
#define WSREP_TO_ISOLATION_BEGIN_FK_TABLES(db_, table_, table_list_, fk_tables_)
|
||||
#define WSREP_TO_ISOLATION_END
|
||||
#define WSREP_TO_ISOLATION_BEGIN_WRTCHK(db_, table_, table_list_)
|
||||
#define WSREP_SYNC_WAIT(thd_, before_)
|
||||
|
47
mysql-test/suite/galera/r/galera_fk_truncate.result
Normal file
47
mysql-test/suite/galera/r/galera_fk_truncate.result
Normal file
@ -0,0 +1,47 @@
|
||||
connection node_2;
|
||||
connection node_1;
|
||||
CREATE TABLE author (
|
||||
id SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
||||
name VARCHAR(100) NOT NULL
|
||||
) ENGINE = InnoDB;
|
||||
CREATE TABLE book (
|
||||
id MEDIUMINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
||||
title VARCHAR(200) NOT NULL,
|
||||
author_id SMALLINT UNSIGNED NOT NULL,
|
||||
CONSTRAINT `fk_book_author`
|
||||
FOREIGN KEY (author_id) REFERENCES author (id)
|
||||
ON DELETE CASCADE
|
||||
ON UPDATE RESTRICT
|
||||
) ENGINE = InnoDB;
|
||||
INSERT INTO author (name) VALUES ('Abdul Alhazred');
|
||||
INSERT INTO book (title, author_id) VALUES ('Necronomicon', LAST_INSERT_ID());
|
||||
TRUNCATE TABLE book;
|
||||
SELECT * FROM author;
|
||||
id name
|
||||
1 Abdul Alhazred
|
||||
SELECT * FROM book;
|
||||
id title author_id
|
||||
connection node_2;
|
||||
SELECT * FROM author;
|
||||
id name
|
||||
1 Abdul Alhazred
|
||||
SELECT * FROM book;
|
||||
id title author_id
|
||||
INSERT INTO author (name) VALUES ('Abdul Alhazred');
|
||||
INSERT INTO book (title, author_id) VALUES ('Necronomicon', LAST_INSERT_ID());
|
||||
TRUNCATE TABLE book;
|
||||
SELECT * FROM author;
|
||||
id name
|
||||
1 Abdul Alhazred
|
||||
2 Abdul Alhazred
|
||||
SELECT * FROM book;
|
||||
id title author_id
|
||||
connection node_1;
|
||||
TRUNCATE TABLE book;
|
||||
SELECT * FROM author;
|
||||
id name
|
||||
1 Abdul Alhazred
|
||||
2 Abdul Alhazred
|
||||
SELECT * FROM book;
|
||||
id title author_id
|
||||
DROP TABLE book, author;
|
39
mysql-test/suite/galera/t/galera_fk_truncate.test
Normal file
39
mysql-test/suite/galera/t/galera_fk_truncate.test
Normal file
@ -0,0 +1,39 @@
|
||||
--source include/galera_cluster.inc
|
||||
|
||||
CREATE TABLE author (
|
||||
id SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
||||
name VARCHAR(100) NOT NULL
|
||||
) ENGINE = InnoDB;
|
||||
|
||||
CREATE TABLE book (
|
||||
id MEDIUMINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
||||
title VARCHAR(200) NOT NULL,
|
||||
author_id SMALLINT UNSIGNED NOT NULL,
|
||||
CONSTRAINT `fk_book_author`
|
||||
FOREIGN KEY (author_id) REFERENCES author (id)
|
||||
ON DELETE CASCADE
|
||||
ON UPDATE RESTRICT
|
||||
) ENGINE = InnoDB;
|
||||
|
||||
INSERT INTO author (name) VALUES ('Abdul Alhazred');
|
||||
INSERT INTO book (title, author_id) VALUES ('Necronomicon', LAST_INSERT_ID());
|
||||
|
||||
TRUNCATE TABLE book;
|
||||
SELECT * FROM author;
|
||||
SELECT * FROM book;
|
||||
|
||||
--connection node_2
|
||||
SELECT * FROM author;
|
||||
SELECT * FROM book;
|
||||
INSERT INTO author (name) VALUES ('Abdul Alhazred');
|
||||
INSERT INTO book (title, author_id) VALUES ('Necronomicon', LAST_INSERT_ID());
|
||||
TRUNCATE TABLE book;
|
||||
SELECT * FROM author;
|
||||
SELECT * FROM book;
|
||||
|
||||
--connection node_1
|
||||
TRUNCATE TABLE book;
|
||||
SELECT * FROM author;
|
||||
SELECT * FROM book;
|
||||
|
||||
DROP TABLE book, author;
|
@ -466,16 +466,17 @@ static bool wsrep_toi_replication(THD *thd, TABLE_LIST *tables)
|
||||
/* now TOI replication, with no locks held */
|
||||
if (keys.empty())
|
||||
{
|
||||
WSREP_TO_ISOLATION_BEGIN_WRTCHK(NULL, NULL, tables);
|
||||
} else {
|
||||
WSREP_TO_ISOLATION_BEGIN_FK_TABLES(NULL, NULL, tables, &keys) {
|
||||
if (!thd->lex->no_write_to_binlog &&
|
||||
wsrep_to_isolation_begin(thd, NULL, NULL, tables))
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!thd->lex->no_write_to_binlog &&
|
||||
wsrep_to_isolation_begin(thd, NULL, NULL, tables, NULL, &keys))
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
||||
wsrep_error_label:
|
||||
return true;
|
||||
}
|
||||
#endif /* WITH_WSREP */
|
||||
|
||||
|
@ -424,15 +424,13 @@ bool Sql_cmd_truncate_table::truncate_table(THD *thd, TABLE_LIST *table_ref)
|
||||
{
|
||||
if (keys.empty())
|
||||
{
|
||||
WSREP_TO_ISOLATION_BEGIN_IF(table_ref->db.str, table_ref->table_name.str, NULL)
|
||||
{
|
||||
if (wsrep_to_isolation_begin(thd, table_ref->db.str, table_ref->table_name.str, NULL))
|
||||
DBUG_RETURN(TRUE);
|
||||
}
|
||||
} else {
|
||||
WSREP_TO_ISOLATION_BEGIN_FK_TABLES(NULL, NULL, table_ref, &keys)
|
||||
{
|
||||
}
|
||||
else
|
||||
{
|
||||
if (wsrep_to_isolation_begin(thd, NULL, NULL, table_ref, NULL, &keys))
|
||||
DBUG_RETURN(TRUE);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2164,8 +2164,9 @@ int wsrep_to_isolation_begin(THD *thd, const char *db_, const char *table_,
|
||||
{
|
||||
/*
|
||||
No isolation for applier or replaying threads.
|
||||
*/
|
||||
if (!wsrep_thd_is_local(thd)) return 0;
|
||||
*/
|
||||
if (!wsrep_thd_is_local(thd))
|
||||
return 0;
|
||||
|
||||
int ret= 0;
|
||||
mysql_mutex_lock(&thd->LOCK_thd_data);
|
||||
|
Loading…
x
Reference in New Issue
Block a user