Modified: pecl/mysqlnd_ms/trunk/mysqlnd_ms_switch.c =================================================================== --- pecl/mysqlnd_ms/trunk/mysqlnd_ms_switch.c 2011-12-13 07:59:17 UTC (rev 320933) +++ pecl/mysqlnd_ms/trunk/mysqlnd_ms_switch.c 2011-12-13 09:20:15 UTC (rev 320934) @@ -457,10 +457,10 @@ DBG_ENTER("mysqlnd_ms_select_servers_all"); BEGIN_ITERATE_OVER_SERVER_LIST(el, master_list); - zend_llist_add_element(selected_masters, &el); + zend_llist_add_element(selected_masters, &el); END_ITERATE_OVER_SERVER_LIST; BEGIN_ITERATE_OVER_SERVER_LIST(el, slave_list); - zend_llist_add_element(selected_slaves, &el); + zend_llist_add_element(selected_slaves, &el); END_ITERATE_OVER_SERVER_LIST; DBG_RETURN(PASS); @@ -618,6 +618,7 @@ error_buf[sizeof(error_buf) - 1] = '\0'; SET_CLIENT_ERROR(MYSQLND_MS_ERROR_INFO(conn), CR_UNKNOWN_ERROR, UNKNOWN_SQLSTATE, error_buf); php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", error_buf); + stgy->last_used_conn = conn; goto end; } if (!connection && (0 == zend_llist_count(output_masters) && 0 == zend_llist_count(output_slaves))) { @@ -632,6 +633,7 @@ DBG_ERR(error_buf); SET_CLIENT_ERROR(MYSQLND_MS_ERROR_INFO(conn), CR_UNKNOWN_ERROR, UNKNOWN_SQLSTATE, error_buf); php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", error_buf); + stgy->last_used_conn = conn; goto end; } } Modified: pecl/mysqlnd_ms/trunk/tests/mysqlnd_ms_enable_rw_rr.phpt =================================================================== --- pecl/mysqlnd_ms/trunk/tests/mysqlnd_ms_enable_rw_rr.phpt 2011-12-13 07:59:17 UTC (rev 320933) +++ pecl/mysqlnd_ms/trunk/tests/mysqlnd_ms_enable_rw_rr.phpt 2011-12-13 09:20:15 UTC (rev 320934) @@ -71,13 +71,15 @@ --EXPECTF-- [E_WARNING] mysqli::query(): (mysqlnd_ms) Couldn't find the appropriate slave connection. 0 slaves to choose from. Something is wrong in %s on line %d [E_WARNING] mysqli::query(): (mysqlnd_ms) No connection selected by the last filter in %s on line %d +[005] [2000] (mysqlnd_ms) No connection selected by the last filter [E_WARNING] mysqli::query(): (mysqlnd_ms) Couldn't find the appropriate slave connection. 0 slaves to choose from. Something is wrong in %s on line %d [E_WARNING] mysqli::query(): (mysqlnd_ms) No connection selected by the last filter in %s on line %d +[007] [2000] (mysqlnd_ms) No connection selected by the last filter Role: master1 %d %d - [008] wrong thread id! Role: master2 %d %d -done! + [008] wrong thread id! +done! \ No newline at end of file Added: pecl/mysqlnd_ms/trunk/tests/mysqlnd_ms_enable_rw_rr_failover.phpt =================================================================== --- pecl/mysqlnd_ms/trunk/tests/mysqlnd_ms_enable_rw_rr_failover.phpt (rev 0) +++ pecl/mysqlnd_ms/trunk/tests/mysqlnd_ms_enable_rw_rr_failover.phpt 2011-12-13 09:20:15 UTC (rev 320934) @@ -0,0 +1,79 @@ +--TEST-- +RW-split, random, no slaves, fail over +--SKIPIF-- + array( + 'master' => array($master_host, $master_host), + 'slave' => array(), + 'pick' => array("roundrobin"), + 'failover' => 'master', + ), +); +if ($error = mst_create_config("test_mysqlnd_ms_enable_rw_random.ini", $settings)) + die(sprintf("SKIP %s\n", $error)); + +?> +--INI-- +mysqlnd_ms.enable=1 +mysqlnd_ms.multi_master=1 +mysqlnd_ms.disable_rw_split=0 +mysqlnd_ms.ini_file=test_mysqlnd_ms_enable_rw_random.ini +--FILE-- +thread_id); + @mst_mysqli_query(4, $link, "SET @myrole='master2'", MYSQLND_MS_MASTER_SWITCH); + $connections['master2'] = array($link->thread_id); + + $res = mst_mysqli_query(5, $link, "SELECT @myrole AS _role"); + $connections['master1'][] = $link->thread_id; + if ($res && ($row = $res->fetch_assoc()) && ($row['_role'] != 'master1')) + printf("[006] [%d] %s, wrong results\n", $link->errno, $link->error); + + mst_mysqli_query(7, $link, "SELECT @myrole AS _role"); + $connections['master2'][] = $link->thread_id; + + foreach ($connections as $role => $ids) { + printf("Role: %s\n", $role); + $last_thread_id = NULL; + foreach ($ids as $k => $thread_id) { + printf(" %d\n", $thread_id); + if (is_null($last_thread_id)) { + $last_thread_id = $thread_id; + } else if ($last_thread_id != $thread_id) { + printf(" [008] wrong thread id!\n"); + } + } + } + print "done!"; +?> +--CLEAN-- + +--EXPECTF-- +Role: master1 + %d + %d +Role: master2 + %d + %d +done! \ No newline at end of file Modified: pecl/mysqlnd_ms/trunk/tests/mysqlnd_ms_multi_master_no_slaves_r.phpt =================================================================== --- pecl/mysqlnd_ms/trunk/tests/mysqlnd_ms_multi_master_no_slaves_r.phpt 2011-12-13 07:59:17 UTC (rev 320933) +++ pecl/mysqlnd_ms/trunk/tests/mysqlnd_ms_multi_master_no_slaves_r.phpt 2011-12-13 09:20:15 UTC (rev 320934) @@ -56,9 +56,9 @@ /* slaves - reads */ $servers = array(); - for ($i = 0; $i <= 2; $i++) { + for ($i = 0; $i <= 100; $i++) { /* ignore warning */ - if ((!($res = $link->query("SELECT 1 FROM DUAL"))) && (2000 != $link->errno)) { + if ((!($res = @$link->query("SELECT 1 FROM DUAL"))) && (2000 != $link->errno)) { printf("[005] Wrong connection error. User should always get same error for same issue, [%d] %s\n", $link->errno, $link->error); /* breaking to keep trace short */ break; @@ -89,6 +89,8 @@ printf("[clean] Cannot unlink ini file 'test_mysqlnd_ms_multi_master_no_slaves_r.ini'.\n"); ?> --EXPECTF-- +[007] Random has choosen the same slave for 100 subsequent reads + Warning: mysqli::query(): (mysqlnd_ms) Couldn't find the appropriate slave connection. 0 slaves to choose from. Something is wrong in %s on line %d Warning: mysqli::query(): (mysqlnd_ms) No connection selected by the last filter in %s on line %d Modified: pecl/mysqlnd_ms/trunk/tests/mysqlnd_ms_multi_master_no_slaves_ro.phpt =================================================================== --- pecl/mysqlnd_ms/trunk/tests/mysqlnd_ms_multi_master_no_slaves_ro.phpt 2011-12-13 07:59:17 UTC (rev 320933) +++ pecl/mysqlnd_ms/trunk/tests/mysqlnd_ms_multi_master_no_slaves_ro.phpt 2011-12-13 09:20:15 UTC (rev 320934) @@ -57,7 +57,7 @@ /* slaves - reads */ $servers = array(); - for ($i = 0; $i <= 2; $i++) { + for ($i = 0; $i <= 100; $i++) { /* ignore warning */ if ((!($res = $link->query("SELECT 1 FROM DUAL"))) && (2000 != $link->errno)) { printf("[005] Wrong connection error, [%d] %s\n", $link->errno, $link->error); @@ -74,7 +74,6 @@ if (count($servers) > 1) break; } - if (100 <= $i) { printf("[007] Random once has choosen the same server for 100 subsequent reads\n"); } else { Modified: pecl/mysqlnd_ms/trunk/tests/mysqlnd_ms_multi_master_no_slaves_rr_nf.phpt =================================================================== --- pecl/mysqlnd_ms/trunk/tests/mysqlnd_ms_multi_master_no_slaves_rr_nf.phpt 2011-12-13 07:59:17 UTC (rev 320933) +++ pecl/mysqlnd_ms/trunk/tests/mysqlnd_ms_multi_master_no_slaves_rr_nf.phpt 2011-12-13 09:20:15 UTC (rev 320934) @@ -85,10 +85,12 @@ Warning: mysqli::query(): (mysqlnd_ms) Couldn't find the appropriate slave connection. 0 slaves to choose from. Something is wrong in %s on line %d Warning: mysqli::query(): (mysqlnd_ms) No connection selected by the last filter in %s on line %d +[006] [2000] (mysqlnd_ms) No connection selected by the last filter Warning: mysqli::query(): (mysqlnd_ms) Couldn't find the appropriate slave connection. 0 slaves to choose from. Something is wrong in %s on line %d Warning: mysqli::query(): (mysqlnd_ms) No connection selected by the last filter in %s on line %d +[008] [2000] (mysqlnd_ms) No connection selected by the last filter +master[1,2]-%d has run 3 queries master[1,2]-%d has run 1 queries -master[1,2]-%d has run 3 queries -done! \ No newline at end of file +done!