#At file:///media/sdb2/hezx/work/mysql/bzrwork/b47298/pe/ based on revid:alik@stripped
3599 He Zhenxing 2009-09-26
BUG#47298 Semisync: always wait until timeout if no semi-sync slave available
Add an option to control whether the master should keep waiting
until timeout when it detected that there is no semi-sync slave
available.
The bool option 'rpl_semi_sync_master_wait_no_slave' is 1 by
defalt, and will keep waiting until timeout. When set to 0, the
master will switch to asynchronous replication immediately when
no semi-sync slave is available.
@ mysql-test/suite/rpl/r/rpl_semi_sync.result
Update test result after fix of bug#47298
@ mysql-test/suite/rpl/t/rpl_semi_sync.test
Fix test case after fix of bug#47298
@ plugin/semisync/semisync_master.cc
Turn off semi-sync immediately on master if no semi-sync slave available
@ plugin/semisync/semisync_master.h
Add variable to control if should keep waiting when no semisync slave is available
@ plugin/semisync/semisync_master_plugin.cc
Add option to control if should keep waiting when no semisync slave is available
Assume the semi-sync slave has already received all binlog events before the filename and position it requests to dump
@ plugin/semisync/semisync_slave_plugin.cc
Revert the behavior change made by the patch for bug#45672. Allow semi-sync slave to connect when semi-sync is disabled on master, so that the slave can start semi-sync replication once the master enables semi-sync later.
M mysql-test/suite/rpl/r/rpl_semi_sync.result
M mysql-test/suite/rpl/t/rpl_semi_sync.test
M plugin/semisync/semisync_master.cc
M plugin/semisync/semisync_master.h
M plugin/semisync/semisync_master_plugin.cc
M plugin/semisync/semisync_slave_plugin.cc
=== modified file 'mysql-test/suite/rpl/r/rpl_semi_sync.result'
--- a/mysql-test/suite/rpl/r/rpl_semi_sync.result 2009-07-07 02:44:17 +0000
+++ b/mysql-test/suite/rpl/r/rpl_semi_sync.result 2009-09-26 10:05:39 +0000
@@ -35,7 +35,7 @@ Variable_name Value
Rpl_semi_sync_master_clients 0
show status like 'Rpl_semi_sync_master_status';
Variable_name Value
-Rpl_semi_sync_master_status OFF
+Rpl_semi_sync_master_status ON
show status like 'Rpl_semi_sync_master_yes_tx';
Variable_name Value
Rpl_semi_sync_master_yes_tx 0
@@ -313,7 +313,7 @@ Variable_name Value
Rpl_semi_sync_master_clients 0
show status like 'Rpl_semi_sync_master_status';
Variable_name Value
-Rpl_semi_sync_master_status OFF
+Rpl_semi_sync_master_status ON
set global rpl_semi_sync_master_enabled= 0;
[ on slave ]
SHOW VARIABLES LIKE 'rpl_semi_sync_slave_enabled';
@@ -322,13 +322,13 @@ rpl_semi_sync_slave_enabled ON
include/start_slave.inc
[ on master ]
insert into t1 values (8);
-[ master semi-sync clients should be 0, status should be OFF ]
+[ master semi-sync clients should be 0, status should be ON ]
show status like 'Rpl_semi_sync_master_clients';
Variable_name Value
Rpl_semi_sync_master_clients 0
show status like 'Rpl_semi_sync_master_status';
Variable_name Value
-Rpl_semi_sync_master_status OFF
+Rpl_semi_sync_master_status ON
[ on slave ]
show status like 'Rpl_semi_sync_slave_status';
Variable_name Value
=== modified file 'mysql-test/suite/rpl/t/rpl_semi_sync.test'
--- a/mysql-test/suite/rpl/t/rpl_semi_sync.test 2009-07-07 02:44:17 +0000
+++ b/mysql-test/suite/rpl/t/rpl_semi_sync.test 2009-09-26 10:05:39 +0000
@@ -58,7 +58,7 @@ echo [ enable semi-sync on master ];
set global rpl_semi_sync_master_enabled = 1;
show variables like 'rpl_semi_sync_master_enabled';
-echo [ status of semi-sync on master should be OFF without any semi-sync slaves ];
+echo [ status of semi-sync on master should be ON even without any semi-sync slaves ];
show status like 'Rpl_semi_sync_master_clients';
show status like 'Rpl_semi_sync_master_status';
show status like 'Rpl_semi_sync_master_yes_tx';
=== modified file 'plugin/semisync/semisync_master.cc'
--- a/plugin/semisync/semisync_master.cc 2009-07-16 09:03:48 +0000
+++ b/plugin/semisync/semisync_master.cc 2009-09-26 10:05:39 +0000
@@ -41,6 +41,8 @@ unsigned long rpl_semi_sync_master_clien
unsigned long long rpl_semi_sync_master_net_wait_total_time = 0;
unsigned long long rpl_semi_sync_master_trx_wait_total_time = 0;
+char rpl_semi_sync_master_wait_no_slave = 1;
+
static int getWaitTime(const struct timeval& start_tv);
@@ -535,6 +537,14 @@ void ReplSemiSyncMaster::remove_slave()
{
lock();
rpl_semi_sync_master_clients--;
+
+ /* If user has chosen not to wait if no semi-sync slave available
+ and the last semi-sync slave exits, turn off semi-sync on master
+ immediately.
+ */
+ if (!rpl_semi_sync_master_wait_no_slave &&
+ rpl_semi_sync_master_clients == 0)
+ switch_off();
unlock();
}
@@ -679,7 +689,7 @@ int ReplSemiSyncMaster::commitTrx(const
"Waiting for semi-sync ACK from slave");
/* This is the real check inside the mutex. */
- if (!getMasterEnabled() || !is_on() || !rpl_semi_sync_master_clients)
+ if (!getMasterEnabled() || !is_on())
goto l_end;
if (trace_level_ & kTraceDetail)
@@ -825,7 +835,7 @@ int ReplSemiSyncMaster::commitTrx(const
l_end:
/* Update the status counter. */
- if (is_on() && rpl_semi_sync_master_clients)
+ if (is_on())
enabled_transactions_++;
else
disabled_transactions_++;
@@ -1089,7 +1099,7 @@ int ReplSemiSyncMaster::writeTranxInBinl
commit_file_name_inited_ = true;
}
- if (is_on() && rpl_semi_sync_master_clients)
+ if (is_on())
{
assert(active_tranxs_ != NULL);
if(active_tranxs_->insert_tranx_node(log_file_name, log_file_pos))
@@ -1146,7 +1156,7 @@ void ReplSemiSyncMaster::setExportStats(
{
lock();
- rpl_semi_sync_master_status = state_ && rpl_semi_sync_master_clients;
+ rpl_semi_sync_master_status = state_;
rpl_semi_sync_master_yes_transactions = enabled_transactions_;
rpl_semi_sync_master_no_transactions = disabled_transactions_;
rpl_semi_sync_master_off_times = switched_off_times_;
=== modified file 'plugin/semisync/semisync_master.h'
--- a/plugin/semisync/semisync_master.h 2009-06-15 13:30:20 +0000
+++ b/plugin/semisync/semisync_master.h 2009-09-26 10:05:39 +0000
@@ -363,4 +363,12 @@ extern unsigned long long rpl_semi_sync_
extern unsigned long long rpl_semi_sync_master_trx_wait_total_time;
extern unsigned long rpl_semi_sync_master_clients;
+/*
+ This indicates whether we should keep waiting if no semi-sync slave
+ is available.
+ 0 : stop waiting if detected no avaialable semi-sync slave.
+ 1 (default) : keep waiting until timeout even no available semi-sync slave.
+*/
+extern char rpl_semi_sync_master_wait_no_slave;
+
#endif /* SEMISYNC_MASTER_H */
=== modified file 'plugin/semisync/semisync_master_plugin.cc'
--- a/plugin/semisync/semisync_master_plugin.cc 2009-07-16 08:59:59 +0000
+++ b/plugin/semisync/semisync_master_plugin.cc 2009-09-26 10:05:39 +0000
@@ -69,8 +69,16 @@ int repl_semi_binlog_dump_start(Binlog_t
bool semi_sync_slave= repl_semisync.is_semi_sync_slave();
if (semi_sync_slave)
+ {
/* One more semi-sync slave */
repl_semisync.add_slave();
+
+ /*
+ Let's assume this semi-sync slave has already received all
+ binlog events before the filename and position it requests.
+ */
+ repl_semisync.reportReplyBinlog(param->server_id, log_file, log_pos);
+ }
sql_print_information("Start %s binlog_dump to slave (server_id: %d), pos(%s, %lu)",
semi_sync_slave ? "semi-sync" : "asynchronous",
param->server_id, log_file, (unsigned long)log_pos);
@@ -161,6 +169,13 @@ static MYSQL_SYSVAR_ULONG(timeout, rpl_s
fix_rpl_semi_sync_master_timeout, // update
10000, 0, ~0L, 1);
+static MYSQL_SYSVAR_BOOL(wait_no_slave, rpl_semi_sync_master_wait_no_slave,
+ PLUGIN_VAR_OPCMDARG,
+ "Wait until timeout when no semi-synchronous replication slave available (enabled by default). ",
+ NULL, // check
+ NULL, // update
+ 1);
+
static MYSQL_SYSVAR_ULONG(trace_level, rpl_semi_sync_master_trace_level,
PLUGIN_VAR_OPCMDARG,
"The tracing level for semi-sync replication.",
@@ -182,6 +197,7 @@ static MYSQL_THDVAR_STR(reply_log_file_p
static SYS_VAR* semi_sync_master_system_vars[]= {
MYSQL_SYSVAR(enabled),
MYSQL_SYSVAR(timeout),
+ MYSQL_SYSVAR(wait_no_slave),
MYSQL_SYSVAR(trace_level),
MYSQL_SYSVAR(reply_log_file_pos),
NULL,
=== modified file 'plugin/semisync/semisync_slave_plugin.cc'
--- a/plugin/semisync/semisync_slave_plugin.cc 2009-07-07 02:44:17 +0000
+++ b/plugin/semisync/semisync_slave_plugin.cc 2009-09-26 10:05:39 +0000
@@ -63,10 +63,11 @@ int repl_semi_slave_request_dump(Binlog_
}
row= mysql_fetch_row(res);
- if (!row || strcmp(row[1], "ON"))
+ if (!row)
{
- /* Master does not support or not configured semi-sync */
- sql_print_warning("Master server does not support or not configured semi-sync replication, fallback to asynchronous");
+ /* Master does not support semi-sync */
+ sql_print_warning("Master server does not support semi-sync, "
+ "fallback to asynchronous replication");
rpl_semi_sync_slave_status= 0;
return 0;
}
Attachment: [text/bzr-bundle] bzr/zhenxing.he@sun.com-20090926100539-fh42o1yur4c361zb.bundle
| Thread |
|---|
| • bzr commit into mysql-pe branch (zhenxing.he:3599) Bug#47298 | He Zhenxing | 26 Sep |