[prev in list] [next in list] [prev in thread] [next in thread]
List: pecl-cvs
Subject: [PECL-CVS] =?utf-8?q?svn:_/pecl/mysqlnd=5Fms/trunk/tests/_mysqlnd=5Fms=5Fset=5Fqos=5Fgtid=5Flost=5Fc
From: Ulf_Wendel <uw () php ! net>
Date: 2011-11-30 13:37:27
Message-ID: svn-uw-1322660247-320194-1907101277 () svn ! php ! net
[Download RAW message or body]
uw Wed, 30 Nov 2011 13:37:27 +0000
Revision: http://svn.php.net/viewvc?view=revision&revision=320194
Log:
New utility function to detect if slave is possibly real slave of a master. If so, we \
can get false-positives in some cases because we must not assume replication is \
always running and/or fast enough to provide a synchronous view, when needed. New \
test to check how QOS filter reacts if all connections are killed.
Changed paths:
A pecl/mysqlnd_ms/trunk/tests/mysqlnd_ms_set_qos_gtid_lost_connection.phpt
U pecl/mysqlnd_ms/trunk/tests/util.inc
Added: pecl/mysqlnd_ms/trunk/tests/mysqlnd_ms_set_qos_gtid_lost_connection.phpt
===================================================================
--- pecl/mysqlnd_ms/trunk/tests/mysqlnd_ms_set_qos_gtid_lost_connection.phpt \
(rev 0)
+++ pecl/mysqlnd_ms/trunk/tests/mysqlnd_ms_set_qos_gtid_lost_connection.phpt 2011-11-30 \
13:37:27 UTC (rev 320194) @@ -0,0 +1,137 @@
+--TEST--
+mysqlnd_ms_set_qos(), GTID lost connection
+--SKIPIF--
+<?php
+if (version_compare(PHP_VERSION, '5.3.99-dev', '<'))
+ die(sprintf("SKIP Requires PHP >= 5.3.99, using " . PHP_VERSION));
+
+require_once('skipif.inc');
+require_once("connect.inc");
+
+if (($master_host == $slave_host)) {
+ die("SKIP master and slave seem to the the same, see tests/README");
+}
+_skipif_check_extensions(array("mysqli"));
+_skipif_connect($master_host_only, $user, $passwd, $db, $master_port, \
$master_socket); +_skipif_connect($slave_host_only, $user, $passwd, $db, $slave_port, \
$slave_socket); +
+include_once("util.inc");
+$ret = mst_is_slave_of($slave_host_only, $slave_port, $slave_socket, \
$master_host_only, $master_port, $master_socket, $user, $passwd, $db); +if \
(is_string($ret)) + die(sprintf("SKIP Failed to check relation of configured master \
and slave, %s\n", $ret)); +
+if (true == $ret)
+ die("SKIP Configured master and slave could be part of a replication cluster\n");
+
+$sql = mst_get_gtid_sql($db);
+if ($error = mst_mysqli_setup_gtid_table($master_host_only, $user, $passwd, $db, \
$master_port, $master_socket)) + die(sprintf("SKIP Failed to setup GTID on master, \
%s\n", $error)); +
+if ($error = mst_mysqli_setup_gtid_table($slave_host_only, $user, $passwd, $db, \
$slave_port, $slave_socket)) + die(sprintf("SKIP Failed to setup GTID on slave, \
%s\n", $error)); +
+$settings = array(
+ "myapp" => array(
+ 'master' => array(
+ "master1" => array(
+ 'host' => $master_host_only,
+ 'port' => (int)$master_port,
+ 'socket' => $master_socket,
+ ),
+ ),
+ 'slave' => array(
+ "slave1" => array(
+ 'host' => $slave_host_only,
+ 'port' => (int)$slave_port,
+ 'socket' => $slave_socket,
+ ),
+ "slave2" => array(
+ 'host' => $slave_host_only,
+ 'port' => (int)$slave_port,
+ 'socket' => $slave_socket,
+ ),
+ ),
+
+ 'lazy_connections' => 1,
+
+ 'filter' => array(
+ 'roundrobin' => array(),
+ ),
+
+ 'global_transaction_id_injection' => array(
+ 'on_commit' => $sql['update'],
+ 'fetch_last_gtid' => $sql['fetch_last_gtid'],
+ 'check_for_gtid' => $sql['check_for_gtid'],
+ 'report_error' => true,
+ ),
+
+ ),
+
+);
+if ($error = mst_create_config("test_mysqlnd_ms_set_qos_gtid_lost_connection.ini", \
$settings)) + die(sprintf("SKIP %s\n", $error));
+?>
+--INI--
+mysqlnd_ms.enable=1
+mysqlnd_ms.ini_file=test_mysqlnd_ms_set_qos_gtid_lost_connection.ini
+--FILE--
+<?php
+ require_once("connect.inc");
+ require_once("util.inc");
+
+ $link = mst_mysqli_connect("myapp", $user, $passwd, $db, $port, $socket);
+ if (mysqli_connect_errno()) {
+ printf("[001] [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error());
+ }
+
+ if (!$link->query("DROP TABLE IF EXISTS test") ||
+ !$link->query("CREATE TABLE test(id INT)") ||
+ !$link->query("INSERT INTO test(id) VALUES (1)"))
+ printf("[002] [%d] %s\n", $link->errno, $link->error);
+
+ if (false === ($gtid = mysqlnd_ms_get_last_gtid($link)))
+ printf("[003] [%d] %s\n", $link->errno, $link->error);
+
+
+ /* kill master connection */
+ $link->kill($link->thread_id);
+
+ /* kill first slave connection */
+ $res = $link->query("SELECT 1 FROM DUAL");
+ $link->kill($link->thread_id);
+
+ /* kill second slave connection */
+ $res = $link->query("SELECT 1 FROM DUAL");
+ $link->kill($link->thread_id);
+
+ /* GTID */
+ /* Insert QOS filter */
+ if (true !== ($ret = mysqlnd_ms_set_qos($link, MYSQLND_MS_QOS_CONSISTENCY_SESSION, \
MYSQLND_MS_QOS_OPTION_GTID, $gtid))) { + printf("[004] [%d] %s\n", $link->errno, \
$link->error); + }
+
+ /* Whatever server the filter wants to use, its connection is closed */
+ if ($res = mst_mysqli_query(6, $link, "SELECT id FROM test"))
+ var_dump($res->fetch_all());
+
+ printf("[007] [%d] '%s'\n", $link->errno, $link->error);
+
+ print "done!";
+?>
+--CLEAN--
+<?php
+ if (!unlink("test_mysqlnd_ms_set_qos_gtid_lost_connection.ini"))
+ printf("[clean] Cannot unlink ini file \
'test_mysqlnd_ms_set_qos_gtid_lost_connection.ini'.\n"); +
+ require_once("connect.inc");
+ require_once("util.inc");
+ if ($error = mst_mysqli_drop_test_table($master_host_only, $user, $passwd, $db, \
$master_port, $master_socket)) + printf("[clean] %s\n");
+
+ if ($error = mst_mysqli_drop_gtid_table($master_host_only, $user, $passwd, $db, \
$master_port, $master_socket)) + printf("[clean] %s\n", $error));
+?>
+--XFAIL--
+Some warning, which one depends on upcoming implementation from Andrey
+--EXPECTF--
+done!
\ No newline at end of file
Modified: pecl/mysqlnd_ms/trunk/tests/util.inc
===================================================================
--- pecl/mysqlnd_ms/trunk/tests/util.inc 2011-11-30 13:18:27 UTC (rev 320193)
+++ pecl/mysqlnd_ms/trunk/tests/util.inc 2011-11-30 13:37:27 UTC (rev 320194)
@@ -15,6 +15,48 @@
2005 => true,
);
+ function mst_is_slave_of($slave_host, $slave_port, $slave_socket, $master_host, \
$master_port, $master_socket, $user, $passwd, $db) { + /* Used for skipping tests if \
master and slave are part of a replication setup + and replication could cause \
false-positives */ +
+ $slave_link = mst_mysqli_connect($slave_host, $user, $passwd, $db, $slave_port, \
$slave_socket); + if (mysqli_connect_errno()) {
+ return sprintf("[%d] %s", mysqli_connect_errno(), mysqli_connect_error());
+ }
+
+ if (!($res = $slave_link->query("SHOW SLAVE STATUS"))) {
+ return sprintf("[%d] %s", $slave_link->errno, $slave_link->error);
+ }
+
+ if (0 == $res->num_rows) {
+ return false;
+ }
+
+ if (!($row = $res->fetch_assoc())) {
+ return sprintf("[%d] %s", $slave_link->errno, $slave_link->error);
+ }
+
+ if ("localhost" == $master_host || '' == $master_host) {
+ /* not sure what port master runs on, better assume servers are related */
+ if ($row['Master_Host'] == '127.0.0.1')
+ return true;
+ }
+
+ if (('127.0.0.1' != $master_host) && ($master_host == $slave_host)) {
+ /*
+ Remote connection to two servers running on the same box.
+ If so, the slave likely replicates from 127.0.0.1 but not
+ from the hosts remote address, e.g. 192.168.2.21.
+ We can't be 100% sure they are not real master/slave, thus we better
+ assume they are.
+ */
+ if (($row['Master_Host'] == '127.0.0.1') && ($row['Master_Port'] == \
$master_port)) + return true;
+ }
+
+ return (($row['Master_Host'] == $master_host) && ($row['Master_Port'] == \
$master_port)); + }
+
function mst_mysqli_verbose_query($offset, $link, $query, $switch = NULL, $quiet = \
false, $expect_connect_warning = false, $ignore_error = false) { printf("[%03d + 01] \
Query '%s'\n", $offset, $query); $ret = mst_mysqli_query($offset, $link, $query, \
$switch = NULL, $quiet = false, $expect_connect_warning = false, $ignore_error = \
false);
--
PECL CVS Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic