Commit aa9db4c1 authored by Nirbhay Choubey's avatar Nirbhay Choubey

MDEV-11817: Altering a table with more rows than ..

.. wsrep_max_ws_rows causes cluster to break when running
Galera cluster in TOI mode

Problem:
While copying records to temporary table during ALTER TABLE,
if there are more than wsrep_max_wsrep_rows records, the
command fails.

Fix:
Since, the temporary table records are not placed into the
binary log, wsrep_affected_rows must not be incremented.
Added a test.
parent 17cc6198
...@@ -113,3 +113,23 @@ INSERT INTO t1 (f2) VALUES (2); ...@@ -113,3 +113,23 @@ INSERT INTO t1 (f2) VALUES (2);
ERROR HY000: wsrep_max_ws_rows exceeded ERROR HY000: wsrep_max_ws_rows exceeded
DROP TABLE t1; DROP TABLE t1;
DROP TABLE ten; DROP TABLE ten;
#
# MDEV-11817: Altering a table with more rows than
# wsrep_max_ws_rows causes cluster to break when running
# Galera cluster in TOI mode
#
CREATE TABLE t1(c1 INT)ENGINE = INNODB;
SET GLOBAL wsrep_max_ws_rows= DEFAULT;
INSERT INTO t1 VALUES(1);
INSERT INTO t1 SELECT * FROM t1;
SET GLOBAL wsrep_max_ws_rows= 1;
ALTER TABLE t1 CHANGE COLUMN c1 c1 BIGINT;
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`c1` bigint(20) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1
SELECT COUNT(*) FROM t1;
COUNT(*)
2
DROP TABLE t1;
...@@ -146,10 +146,31 @@ INSERT INTO t1 (f2) VALUES (1); ...@@ -146,10 +146,31 @@ INSERT INTO t1 (f2) VALUES (1);
--error ER_ERROR_DURING_COMMIT --error ER_ERROR_DURING_COMMIT
INSERT INTO t1 (f2) VALUES (2); INSERT INTO t1 (f2) VALUES (2);
DROP TABLE t1;
DROP TABLE ten;
--echo #
--echo # MDEV-11817: Altering a table with more rows than
--echo # wsrep_max_ws_rows causes cluster to break when running
--echo # Galera cluster in TOI mode
--echo #
--connection node_1
CREATE TABLE t1(c1 INT)ENGINE = INNODB;
SET GLOBAL wsrep_max_ws_rows= DEFAULT;
INSERT INTO t1 VALUES(1);
INSERT INTO t1 SELECT * FROM t1;
SET GLOBAL wsrep_max_ws_rows= 1;
ALTER TABLE t1 CHANGE COLUMN c1 c1 BIGINT;
--connection node_2
SHOW CREATE TABLE t1;
SELECT COUNT(*) FROM t1;
DROP TABLE t1;
--connection node_1
--disable_query_log --disable_query_log
--eval SET GLOBAL wsrep_max_ws_rows = $wsrep_max_ws_rows_orig --eval SET GLOBAL wsrep_max_ws_rows = $wsrep_max_ws_rows_orig
--enable_query_log --enable_query_log
DROP TABLE t1; --source include/galera_end.inc
DROP TABLE ten;
...@@ -5726,6 +5726,8 @@ static int write_locked_table_maps(THD *thd) ...@@ -5726,6 +5726,8 @@ static int write_locked_table_maps(THD *thd)
typedef bool Log_func(THD*, TABLE*, bool, const uchar*, const uchar*); typedef bool Log_func(THD*, TABLE*, bool, const uchar*, const uchar*);
static int check_wsrep_max_ws_rows();
static int binlog_log_row(TABLE* table, static int binlog_log_row(TABLE* table,
const uchar *before_record, const uchar *before_record,
const uchar *after_record, const uchar *after_record,
...@@ -5765,6 +5767,13 @@ static int binlog_log_row(TABLE* table, ...@@ -5765,6 +5767,13 @@ static int binlog_log_row(TABLE* table,
bool const has_trans= thd->lex->sql_command == SQLCOM_CREATE_TABLE || bool const has_trans= thd->lex->sql_command == SQLCOM_CREATE_TABLE ||
table->file->has_transactions(); table->file->has_transactions();
error= (*log_func)(thd, table, has_trans, before_record, after_record); error= (*log_func)(thd, table, has_trans, before_record, after_record);
/*
Now that the record has been logged, increment wsrep_affected_rows and
also check whether its within the allowable limits (wsrep_max_ws_rows).
*/
if (error == 0)
error= check_wsrep_max_ws_rows();
} }
} }
return error ? HA_ERR_RBR_LOGGING_FAILED : 0; return error ? HA_ERR_RBR_LOGGING_FAILED : 0;
...@@ -5923,7 +5932,7 @@ int handler::ha_write_row(uchar *buf) ...@@ -5923,7 +5932,7 @@ int handler::ha_write_row(uchar *buf)
DBUG_RETURN(error); /* purecov: inspected */ DBUG_RETURN(error); /* purecov: inspected */
DEBUG_SYNC_C("ha_write_row_end"); DEBUG_SYNC_C("ha_write_row_end");
DBUG_RETURN(check_wsrep_max_ws_rows()); DBUG_RETURN(0);
} }
...@@ -5954,7 +5963,7 @@ int handler::ha_update_row(const uchar *old_data, uchar *new_data) ...@@ -5954,7 +5963,7 @@ int handler::ha_update_row(const uchar *old_data, uchar *new_data)
rows_changed++; rows_changed++;
if (unlikely(error= binlog_log_row(table, old_data, new_data, log_func))) if (unlikely(error= binlog_log_row(table, old_data, new_data, log_func)))
return error; return error;
return check_wsrep_max_ws_rows(); return 0;
} }
int handler::ha_delete_row(const uchar *buf) int handler::ha_delete_row(const uchar *buf)
...@@ -5981,7 +5990,7 @@ int handler::ha_delete_row(const uchar *buf) ...@@ -5981,7 +5990,7 @@ int handler::ha_delete_row(const uchar *buf)
rows_changed++; rows_changed++;
if (unlikely(error= binlog_log_row(table, buf, 0, log_func))) if (unlikely(error= binlog_log_row(table, buf, 0, log_func)))
return error; return error;
return check_wsrep_max_ws_rows(); return 0;
} }
......
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