Make REPAIR of a partition output the same type of message (error vs.
warning) in the error log during replication as it would do when run
directly.

Signed-off-by: Kristian Nielsen <[email protected]>
---
 mysql-test/suite/rpl/r/rpl_repair.result | 19 +++++++++++++
 mysql-test/suite/rpl/t/rpl_repair.test   | 31 +++++++++++++++++++++
 sql/ha_partition.cc                      | 34 ++++++++++++++----------
 3 files changed, 70 insertions(+), 14 deletions(-)
 create mode 100644 mysql-test/suite/rpl/r/rpl_repair.result
 create mode 100644 mysql-test/suite/rpl/t/rpl_repair.test

diff --git a/mysql-test/suite/rpl/r/rpl_repair.result 
b/mysql-test/suite/rpl/r/rpl_repair.result
new file mode 100644
index 00000000000..04c2f924c08
--- /dev/null
+++ b/mysql-test/suite/rpl/r/rpl_repair.result
@@ -0,0 +1,19 @@
+include/master-slave.inc
+[connection master]
+create table t (a int, key(a)) partition by range (a) (
+partition p0 values less than (10),
+partition p1 values less than (100)
+);
+insert into t values (5),(50);
+connection slave;
+flush tables;
+connection master;
+repair table t;
+Table  Op      Msg_type        Msg_text
+test.t repair  status  OK
+connection slave;
+SET STATEMENT sql_log_bin=0 FOR
+CALL mtr.add_suppression('[[]Warning[]] Moved 1 misplaced rows');
+connection master;
+DROP TABLE t;
+include/rpl_end.inc
diff --git a/mysql-test/suite/rpl/t/rpl_repair.test 
b/mysql-test/suite/rpl/t/rpl_repair.test
new file mode 100644
index 00000000000..e487e6540bf
--- /dev/null
+++ b/mysql-test/suite/rpl/t/rpl_repair.test
@@ -0,0 +1,31 @@
+--source include/have_partition.inc
+--source include/have_binlog_format_mixed.inc
+--source include/master-slave.inc
+ 
+create table t (a int, key(a)) partition by range (a) (
+  partition p0 values less than (10),
+  partition p1 values less than (100)
+);
+ 
+insert into t values (5),(50);
+ 
+--sync_slave_with_master
+# Simulate rows ending up in wrong partitions, to make REPAIR have
+# something to do.
+# The bug was that the repair was reported as ERROR in the error log on the
+# slave (it should be WARNING like in the interactive session on the master).
+flush tables;
+--let $datadir= `select @@datadir`
+--move_file $datadir/test/t#P#p0.MYD $datadir/test/tmp
+--move_file $datadir/test/t#P#p1.MYD $datadir/test/t#P#p0.MYD
+--move_file $datadir/test/tmp $datadir/test/t#P#p1.MYD
+ 
+--connection master
+repair table t;
+--sync_slave_with_master
+SET STATEMENT sql_log_bin=0 FOR
+  CALL mtr.add_suppression('[[]Warning[]] Moved 1 misplaced rows');
+
+--connection master
+DROP TABLE t;
+--source include/rpl_end.inc
diff --git a/sql/ha_partition.cc b/sql/ha_partition.cc
index 3c3c51f92eb..52b4a3f4f78 100644
--- a/sql/ha_partition.cc
+++ b/sql/ha_partition.cc
@@ -1430,13 +1430,11 @@ int ha_partition::handle_opt_part(THD *thd, 
HA_CHECK_OPT *check_opt,
    (modelled after mi_check_print_msg)
    TODO: move this into the handler, or rewrite mysql_admin_table.
 */
-bool print_admin_msg(THD* thd, uint len,
-                     const LEX_CSTRING *msg_type,
+bool print_admin_msg(THD* thd, uint len, bool as_error,
                      const char* db_name, String &table_name,
                      const LEX_CSTRING *op_name, const char *fmt, ...)
   ATTRIBUTE_FORMAT(printf, 7, 8);
-bool print_admin_msg(THD* thd, uint len,
-                     const LEX_CSTRING *msg_type,
+bool print_admin_msg(THD* thd, uint len, bool as_error,
                      const char* db_name, String &table_name,
                      const LEX_CSTRING *op_name, const char *fmt, ...)
 {
@@ -1447,6 +1445,7 @@ bool print_admin_msg(THD* thd, uint len,
   char name[NAME_LEN*2+2];
   char *msgbuf;
   bool error= true;
+  const LEX_CSTRING *msg_type= as_error ? &msg_error : &msg_warning;
 
   if (!(msgbuf= (char*) my_malloc(key_memory_Partition_admin, len, MYF(0))))
     return true;
@@ -1460,7 +1459,10 @@ bool print_admin_msg(THD* thd, uint len,
 
   if (!thd->vio_ok())
   {
-    sql_print_error("%s", msgbuf);
+    if (as_error)
+      sql_print_error("%s", msgbuf);
+    else
+      sql_print_warning("%s", msgbuf);
     goto err;
   }
 
@@ -1482,8 +1484,12 @@ bool print_admin_msg(THD* thd, uint len,
   protocol->store(msgbuf, msg_length, system_charset_info);
   if (protocol->write())
   {
-    sql_print_error("Failed on my_net_write, writing to stderr instead: %s",
-                    msgbuf);
+    if (as_error)
+      sql_print_error("Failed on my_net_write, writing to stderr instead: %s",
+                      msgbuf);
+    else
+      sql_print_warning("Failed on my_net_write, writing to stderr instead: 
%s",
+                        msgbuf);
     goto err;
   }
   error= false;
@@ -1547,7 +1553,7 @@ int ha_partition::handle_opt_partitions(THD *thd, 
HA_CHECK_OPT *check_opt,
                 error != HA_ADMIN_TRY_ALTER &&
                 error != HA_ERR_TABLE_READONLY)
             {
-             print_admin_msg(thd, MYSQL_ERRMSG_SIZE, &msg_error,
+             print_admin_msg(thd, MYSQL_ERRMSG_SIZE, true,
                               table_share->db.str, table->alias,
                               &opt_op_name[flag],
                               "Subpartition %s returned error",
@@ -1574,7 +1580,7 @@ int ha_partition::handle_opt_partitions(THD *thd, 
HA_CHECK_OPT *check_opt,
               error != HA_ADMIN_ALREADY_DONE &&
               error != HA_ADMIN_TRY_ALTER)
           {
-           print_admin_msg(thd, MYSQL_ERRMSG_SIZE, &msg_error,
+           print_admin_msg(thd, MYSQL_ERRMSG_SIZE, true,
                             table_share->db.str, table->alias,
                             &opt_op_name[flag], "Partition %s returned error",
                             part_elem->partition_name);
@@ -11328,7 +11334,7 @@ int ha_partition::check_misplaced_rows(uint 
read_part_id, bool do_repair)
 
       if (num_misplaced_rows > 0)
       {
-       print_admin_msg(ha_thd(), MYSQL_ERRMSG_SIZE, &msg_warning,
+       print_admin_msg(ha_thd(), MYSQL_ERRMSG_SIZE, false,
                         table_share->db.str, table->alias,
                         &opt_op_name[REPAIR_PARTS],
                         "Moved %lld misplaced rows",
@@ -11350,7 +11356,7 @@ int ha_partition::check_misplaced_rows(uint 
read_part_id, bool do_repair)
       if (!do_repair)
       {
         /* Check. */
-       print_admin_msg(ha_thd(), MYSQL_ERRMSG_SIZE, &msg_error,
+       print_admin_msg(ha_thd(), MYSQL_ERRMSG_SIZE, true,
                         table_share->db.str, table->alias,
                         &opt_op_name[CHECK_PARTS],
                         "Found a misplaced row");
@@ -11399,7 +11405,7 @@ int ha_partition::check_misplaced_rows(uint 
read_part_id, bool do_repair)
                             (uint) correct_part_id,
                             str.c_ptr_safe());
           }
-         print_admin_msg(ha_thd(), MYSQL_ERRMSG_SIZE, &msg_error,
+         print_admin_msg(ha_thd(), MYSQL_ERRMSG_SIZE, true,
                           table_share->db.str, table->alias,
                           &opt_op_name[REPAIR_PARTS],
                           "Failed to move/insert a row"
@@ -11526,7 +11532,7 @@ int ha_partition::check_for_upgrade(HA_CHECK_OPT 
*check_opt)
               !(part_buf= generate_partition_syntax_for_frm(thd, m_part_info,
                                                             &part_buf_len,
                                                             NULL, NULL)) ||
-             print_admin_msg(thd, SQL_ADMIN_MSG_TEXT_SIZE + 1, &msg_error,
+             print_admin_msg(thd, SQL_ADMIN_MSG_TEXT_SIZE + 1, true,
                              table_share->db.str,
                              table->alias,
                               &opt_op_name[CHECK_PARTS],
@@ -11536,7 +11542,7 @@ int ha_partition::check_for_upgrade(HA_CHECK_OPT 
*check_opt)
                               part_buf))
          {
            /* Error creating admin message (too long string?). */
-           print_admin_msg(thd, MYSQL_ERRMSG_SIZE, &msg_error,
+           print_admin_msg(thd, MYSQL_ERRMSG_SIZE, true,
                             table_share->db.str, table->alias,
                             &opt_op_name[CHECK_PARTS],
                             KEY_PARTITIONING_CHANGED_STR,
-- 
2.47.2

_______________________________________________
commits mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to