From a039062ef372c6e0f68fbeb3c579f96fa591f5c8 Mon Sep 17 00:00:00 2001 From: "guilhem@mysql.com" <> Date: Fri, 14 May 2004 23:08:03 +0200 Subject: [PATCH] Replication testsuite: making the master-slave synchronization less likely to fail, by adding sleep-and-retries (max 4 times) if MASTER_POS_WAIT() returns NULL in sync_with_master and sync_slave_with_master. The problem showed up only today, in MySQL 5.0 in rpl_server_id2.test, but may affect 4.x as well, so fixing it here. Note that I am also fixing 5.0 too, with the same exact patch, because I don't want to leave 5.0 broken until the next 4.0->4.1->5.0 merge. --- client/mysqltest.c | 21 ++++++++++++++++++--- mysql-test/r/rpl_server_id2.result | 1 - mysql-test/t/rpl_server_id2.test | 1 - 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/client/mysqltest.c b/client/mysqltest.c index 32fb44d178e..7dae99efde3 100644 --- a/client/mysqltest.c +++ b/client/mysqltest.c @@ -1081,7 +1081,7 @@ int do_sync_with_master2(const char* p) MYSQL_ROW row; MYSQL* mysql = &cur_con->mysql; char query_buf[FN_REFLEN+128]; - int offset = 0; + int offset= 0, tries= 0; int rpl_parse; if (!master_pos.file[0]) @@ -1096,6 +1096,9 @@ int do_sync_with_master2(const char* p) sprintf(query_buf, "select master_pos_wait('%s', %ld)", master_pos.file, master_pos.pos + offset); + +wait_for_position: + if (mysql_query(mysql, query_buf)) die("line %u: failed in %s: %d: %s", start_lineno, query_buf, mysql_errno(mysql), mysql_error(mysql)); @@ -1106,8 +1109,20 @@ int do_sync_with_master2(const char* p) if (!(row = mysql_fetch_row(res))) die("line %u: empty result in %s", start_lineno, query_buf); if (!row[0]) - die("line %u: could not sync with master ('%s' returned NULL)", - start_lineno, query_buf); + { + /* + It may be that the slave SQL thread has not started yet, though START + SLAVE has been issued ? + */ + if (tries++ == 3) + { + die("line %u: could not sync with master ('%s' returned NULL)", + start_lineno, query_buf); + } + sleep(1); /* So at most we will wait 3 seconds and make 4 tries */ + mysql_free_result(res); + goto wait_for_position; + } mysql_free_result(res); last_result=0; if (rpl_parse) diff --git a/mysql-test/r/rpl_server_id2.result b/mysql-test/r/rpl_server_id2.result index d665bb25dbb..1b5d946998c 100644 --- a/mysql-test/r/rpl_server_id2.result +++ b/mysql-test/r/rpl_server_id2.result @@ -4,7 +4,6 @@ reset master; reset slave; drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9; slave start; -drop table if exists t1; create table t1 (n int); reset master; stop slave; diff --git a/mysql-test/t/rpl_server_id2.test b/mysql-test/t/rpl_server_id2.test index dc8f733b7ed..7bbac358ada 100644 --- a/mysql-test/t/rpl_server_id2.test +++ b/mysql-test/t/rpl_server_id2.test @@ -3,7 +3,6 @@ source include/master-slave.inc; connection slave; -drop table if exists t1; create table t1 (n int); reset master; # replicate ourselves