Bug #74141 reset master should reset gtid state and not error out when binlog is off
Submitted: 29 Sep 2014 17:33 Modified: 8 Jun 2015 11:14
Reporter: Sven Sandberg Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Replication Severity:S2 (Serious)
Version:5.7 OS:Any
Assigned to: CPU Architecture:Any

[29 Sep 2014 17:33] Sven Sandberg
Description:
The GTID state (GTID_EXECUTED and GTID_PURGED) can be reset using RESET MASTER.

RESET MASTER only works when the binary log is enabled. If the binary log is disabled, RESET MASTER fails with an error. This did not limit the GTID feature in 5.6, since GTIDs could only be enabled when the binary log was enabled.

However, since WL#6559 was pushed to 5.7.5, GTIDs can be enabled even when the binary log is disabled. So in this case there is no way to reset the GTID state.

How to repeat:
Run the server with GTID_MODE=ON and log-bin disabled, see that RESET MASTER fails.

Suggested fix:
 8909 Sven Sandberg	2014-09-29
      (no message)
     @ sql/binlog.cc
        - Fix whitespace
        - Remove pointless call to gtid_state->init
     @ sql/rpl_master.cc
        - Remove the ER_FLUSH_MASTER_BINLOG_CLOSED error.
        - Reset the GTID state if the binary log is disabled.
=== modified file 'sql/binlog.cc'
--- sql/binlog.cc	revid:annamalai.gurusami@oracle.com-20140923080047-y0nz0emspzjlsham
+++ sql/binlog.cc	revid:sven.sandberg@oracle.com-20140929173315-w0wg3u6tyxgvi376
@@ -4362,14 +4362,11 @@
   */
   if (!is_relay_log)
   {
-    if(gtid_state->clear(thd))
+    if (gtid_state->clear(thd))
     {
       error= 1;
       goto err;
     }
-    // don't clear global_sid_map because it's used by the relay log too
-    if (gtid_state->init() != 0)
-      goto err;
   }
 #endif
 

=== modified file 'sql/rpl_master.cc'
--- sql/rpl_master.cc	revid:annamalai.gurusami@oracle.com-20140923080047-y0nz0emspzjlsham
+++ sql/rpl_master.cc	revid:sven.sandberg@oracle.com-20140929173315-w0wg3u6tyxgvi376
@@ -527,15 +527,16 @@
 */
 int reset_master(THD* thd)
 {
-  if (!mysql_bin_log.is_open())
-  {
-    my_message(ER_FLUSH_MASTER_BINLOG_CLOSED,
-               ER(ER_FLUSH_MASTER_BINLOG_CLOSED), MYF(ME_BELL+ME_WAITTANG));
-    return 1;
-  }
-
-  if (mysql_bin_log.reset_logs(thd))
-    return 1;
+  if (mysql_bin_log.is_open())
+  {
+    if (mysql_bin_log.reset_logs(thd))
+      return 1;
+  }
+  else
+  {
+    if (gtid_state->clear(thd))
+      return 1;
+  }
   (void) RUN_HOOK(binlog_transmit, after_reset_master, (thd, 0 /* flags */));
   return 0;
 }
[8 Jun 2015 11:14] David Moss
The following was noted in the 5.7.8 changelog:
When using RESET MASTER, the GTID state (gtid_executed and gtid_purged) is reset. On a server with log_bin=OFF, using RESET MASTER fails because the binary log is not enabled. However, since MySQL 5.7.5, GTIDs can be enabled even when the binary log is disabled. So in this case there was no way to reset the GTID state. The fix ensures that RESET MASTER can be executed on a server with GTIDs enabled and log_bin=OFF, enabling you to reset the GTID state.