From 4e833f3df330f442e25011b82c8f7d803898a52f Mon Sep 17 00:00:00 2001 From: "Brian Fraser fraserb@gmail.com" <> Date: Mon, 15 Oct 2012 13:53:37 -0300 Subject: [PATCH 1/3] Minimal PXC compat --- lib/Sandbox.pm | 20 ++++++++++-- sandbox/load-sakila-db | 6 ++++ sandbox/servers/pxc/5.5/my.sandbox.cnf | 42 ++++++++++++++++++++++++++ sandbox/start-sandbox | 26 ++++++++++++++-- sandbox/test-env | 8 ++--- util/checksum-test-dataset | 3 +- 6 files changed, 96 insertions(+), 9 deletions(-) create mode 100644 sandbox/servers/pxc/5.5/my.sandbox.cnf diff --git a/lib/Sandbox.pm b/lib/Sandbox.pm index 88132655..a00a0a86 100644 --- a/lib/Sandbox.pm +++ b/lib/Sandbox.pm @@ -80,7 +80,7 @@ sub use { if ( $? >> 8 ) { die "Failed to execute $cmd on $server: $out"; } - return; + return $out; } sub create_dbs { @@ -203,6 +203,7 @@ sub master_is_ok { # Returns a string if there is a problem with the slave. sub slave_is_ok { my ($self, $slave, $master, $ro) = @_; + return if $self->is_cluster_node($slave); PTDEBUG && _d('Checking if slave', $slave, $port_for{$slave}, 'to', $master, $port_for{$master}, 'is ok'); @@ -345,7 +346,8 @@ sub verify_test_data { 'SELECT * FROM percona_test.checksums', 'db_tbl'); $self->{checksum_ref} = $ref unless $self->{checksum_ref}; - my @tables_in_mysql = @{$master->selectcol_arrayref('SHOW TABLES FROM mysql')}; + my @tables_in_mysql = grep { !/^innodb_(?:table|index)_stats$/ } + @{$master->selectcol_arrayref('SHOW TABLES FROM mysql')}; my @tables_in_sakila = qw(actor address category city country customer film film_actor film_category film_text inventory language payment rental staff store); @@ -396,6 +398,20 @@ sub clear_genlogs { return; } +sub is_cluster_node { + my ($self, $server) = @_; + + my $sql = "SHOW VARIABLES LIKE 'wsrep_on'"; + PTDEBUG && _d($sql); + my $row = $self->use($server, qq{-ss -e "$sql"}); + PTDEBUG && _d($row); + $row = [split " ", $row]; + + return $row && $row->[1] + ? ($row->[1] eq 'ON' || $row->[1] eq '1') + : 0; +} + 1; } # ########################################################################### diff --git a/sandbox/load-sakila-db b/sandbox/load-sakila-db index 1fbb2ceb..d7a72975 100755 --- a/sandbox/load-sakila-db +++ b/sandbox/load-sakila-db @@ -43,6 +43,12 @@ exit_status=0 /tmp/$PORT/use < sakila-db/sakila-schema.sql exit_status=$((exit_status | $?)) +# We can remove this once PXC's triggers can handle myisam tables +if [ "${2:-""}" = "cluster" ]; then + /tmp/$PORT/use -e "ALTER TABLE sakila.film_text DROP KEY idx_title_description" + /tmp/$PORT/use -e "ALTER TABLE sakila.film_text ENGINE = 'InnoDB'" +fi + /tmp/$PORT/use < sakila-db/sakila-data.sql exit_status=$((exit_status | $?)) diff --git a/sandbox/servers/pxc/5.5/my.sandbox.cnf b/sandbox/servers/pxc/5.5/my.sandbox.cnf new file mode 100644 index 00000000..8bf4a692 --- /dev/null +++ b/sandbox/servers/pxc/5.5/my.sandbox.cnf @@ -0,0 +1,42 @@ +[client] +user = msandbox +password = msandbox +port = PORT +socket = /tmp/PORT/mysql_sandboxPORT.sock + +[mysqld] +port = PORT +socket = /tmp/PORT/mysql_sandboxPORT.sock +pid-file = /tmp/PORT/data/mysql_sandboxPORT.pid +basedir = PERCONA_TOOLKIT_SANDBOX +datadir = /tmp/PORT/data +key_buffer_size = 16M +innodb_buffer_pool_size = 16M +innodb_data_home_dir = /tmp/PORT/data +innodb_log_group_home_dir = /tmp/PORT/data +innodb_data_file_path = ibdata1:10M:autoextend +innodb_log_file_size = 5M +log-bin = mysql-bin +relay_log = mysql-relay-bin +log_slave_updates +server-id = PORT +report-host = 127.0.0.1 +report-port = PORT +log-error = /tmp/PORT/data/mysqld.log +innodb_lock_wait_timeout = 3 +general_log +general_log_file = genlog + +binlog_format = ROW +wsrep_provider = LIBGALERA +wsrep_cluster_address = CLUSTER_AD +wsrep_sst_receive_address = ADDR:RECEIVE_PRT +wsrep_node_incoming_address= ADDR +wsrep_slave_threads = 2 +wsrep_cluster_name = CLUSTER_NAME +wsrep_provider_options = "gmcast.listen_addr=tcp://ADDR:LISTEN_PRT;" +wsrep_sst_method = rsync +wsrep_node_name = PORT +innodb_locks_unsafe_for_binlog = 1 +innodb_autoinc_lock_mode = 2 +wsrep-replicate-myisam diff --git a/sandbox/start-sandbox b/sandbox/start-sandbox index df1b5353..93fd2545 100755 --- a/sandbox/start-sandbox +++ b/sandbox/start-sandbox @@ -40,6 +40,28 @@ make_sandbox() { fi done + if [ "${type}" = "cluster" ]; then + cp $PERCONA_TOOLKIT_BRANCH/sandbox/servers/pxc/$version/my.sandbox.cnf /tmp/$port + + local ip="$(perl -MNet::Address::IP::Local -le 'print Net::Address::IP::Local->public')" + local libgalera="$PERCONA_TOOLKIT_SANDBOX/lib/libgalera_smm.so" + local cluster_name="${CLUSTER_NAME:-"pt_sandbox_cluster"}" + local cluster_address="gcomm://" + local listen_port=$(($port + 10)) + local receive_port=$(($port + 20)) + if [ -n "${master_port}" ]; then + local master_listen_port=$(($master_port + 10)) + cluster_address="gcomm://$ip:$master_listen_port" + fi + + sed -e "s/ADDR/$ip/g" -i.bak "/tmp/$port/my.sandbox.cnf" + sed -e "s!CLUSTER_AD!$cluster_address!g" -i.bak "/tmp/$port/my.sandbox.cnf" + sed -e "s/CLUSTER_NAME/$cluster_name/g" -i.bak "/tmp/$port/my.sandbox.cnf" + sed -e "s/RECEIVE_PRT/$receive_port/g" -i.bak "/tmp/$port/my.sandbox.cnf" + sed -e "s/LISTEN_PRT/$listen_port/g" -i.bak "/tmp/$port/my.sandbox.cnf" + sed -e "s!LIBGALERA!$libgalera!g" -i.bak "/tmp/$port/my.sandbox.cnf" + fi + for file in `grep -rl PORT /tmp/$port`; do sed -e "s/PORT/$port/g" -i.bak $file # Use ! instead of / because the replacment has / (it's a directory) @@ -116,7 +138,7 @@ type=$1 # master, slave or master-master port=$2 # sandbox port number, e.g. 12345 master_port=$3 # master port if slave or master-master -if [ "$type" != "master" ] && [ "$type" != "slave" ] && [ "$type" != "master-master" ]; then +if [ "$type" != "master" ] && [ "$type" != "slave" ] && [ "$type" != "master-master" ] && [ "$type" != "cluster" ]; then die "Invalid sandbox type: $type. Valid types are master, slave, and master-master." fi @@ -154,7 +176,7 @@ cd $PERCONA_TOOLKIT_BRANCH/sandbox # MySQL executables like PERCONA_TOOLKIT_SANDBOX/bin/mysqld_safe. if [ -z "$PERCONA_TOOLKIT_SANDBOX" ]; then - PERCONA_TOOLKIT_SANDBOX=`./mk-test-env checkconfig | grep PERCONA_TOOLKIT_SANDBOX | cut -d= -f2 | awk '{print $1}'` + PERCONA_TOOLKIT_SANDBOX=`./test-env checkconfig | grep PERCONA_TOOLKIT_SANDBOX | cut -d= -f2 | awk '{print $1}'` if [ -z "$PERCONA_TOOLKIT_SANDBOX" ]; then die "PERCONA_TOOLKIT_SANDBOX environment variable is not set." fi diff --git a/sandbox/test-env b/sandbox/test-env index b602f606..28db1274 100755 --- a/sandbox/test-env +++ b/sandbox/test-env @@ -284,17 +284,17 @@ fi case $opt in start) cd $PERCONA_TOOLKIT_BRANCH/sandbox - ./start-sandbox master 12345 + ./start-sandbox "${2:-"master"}" 12345 exit_status=$((exit_status | $?)) set_mysql_version if [ $exit_status -eq 0 ]; then - ./start-sandbox slave 12346 12345 + ./start-sandbox "${2:-"slave"}" 12346 12345 exit_status=$((exit_status | $?)) - ./start-sandbox slave 12347 12346 + ./start-sandbox "${2:-"slave"}" 12347 12346 exit_status=$((exit_status | $?)) if [ $? -eq 0 -a "$MYSQL_VERSION" '>' "4.1" ]; then echo -n "Loading sakila database... " - ./load-sakila-db 12345 + ./load-sakila-db 12345 "${2:-""}" exit_status=$((exit_status | $?)) if [ $exit_status -ne 0 ]; then echo "FAILED" diff --git a/util/checksum-test-dataset b/util/checksum-test-dataset index 3cc2dc84..e2d0bd27 100755 --- a/util/checksum-test-dataset +++ b/util/checksum-test-dataset @@ -44,7 +44,8 @@ my $dbh = DBI->connect( # Sandbox::ok() will throw "ERROR: Tables are different on master: mysql.proc" $dbh->do("UPDATE mysql.proc SET created='2012-06-05 00:00:00', modified='2012-06-05 00:00:00'"); -my @tables_in_mysql = @{$dbh->selectcol_arrayref('SHOW TABLES FROM mysql')}; +my @tables_in_mysql = grep { !/^innodb_(?:table|index)_stats$/ } + @{$dbh->selectcol_arrayref('SHOW TABLES FROM mysql')}; my @tables_in_sakila = qw( actor address category city country customer film film_actor film_category film_text inventory language payment rental staff store ); From 4449fb7cb768706b8eeddf1fabd6224a26146dd6 Mon Sep 17 00:00:00 2001 From: "Brian Fraser fraserb@gmail.com" <> Date: Tue, 16 Oct 2012 17:01:59 -0300 Subject: [PATCH 2/3] test-env start cluster: Check that the cluster size is correct --- sandbox/test-env | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/sandbox/test-env b/sandbox/test-env index 28db1274..1d78defc 100755 --- a/sandbox/test-env +++ b/sandbox/test-env @@ -292,6 +292,17 @@ case $opt in exit_status=$((exit_status | $?)) ./start-sandbox "${2:-"slave"}" 12347 12346 exit_status=$((exit_status | $?)) + + if [ "${2:-""}" = "cluster" ]; then + echo "Checking that the cluster size is correct... " + size=$(/tmp/12345/use -ss -e "SHOW STATUS LIKE 'wsrep_cluster_size'" 2>/dev/null) + if [ "${size:-""}" -ne 3 ]; then + echo "FAILED" + else + echo "OK" + fi + fi + if [ $? -eq 0 -a "$MYSQL_VERSION" '>' "4.1" ]; then echo -n "Loading sakila database... " ./load-sakila-db 12345 "${2:-""}" From 6974cc7298357eea72210ab9d512a55545339f9c Mon Sep 17 00:00:00 2001 From: Daniel Nichter Date: Tue, 16 Oct 2012 15:46:17 -0600 Subject: [PATCH 3/3] Fix wsrep_cluster_size check. --- sandbox/test-env | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sandbox/test-env b/sandbox/test-env index 1d78defc..4e0d5d27 100755 --- a/sandbox/test-env +++ b/sandbox/test-env @@ -294,9 +294,9 @@ case $opt in exit_status=$((exit_status | $?)) if [ "${2:-""}" = "cluster" ]; then - echo "Checking that the cluster size is correct... " - size=$(/tmp/12345/use -ss -e "SHOW STATUS LIKE 'wsrep_cluster_size'" 2>/dev/null) - if [ "${size:-""}" -ne 3 ]; then + echo -n "Checking that the cluster size is correct... " + size=$(/tmp/12345/use -ss -e "SHOW STATUS LIKE 'wsrep_cluster_size'" | awk '{print $2}') + if [ ${size:-0} -ne 3 ]; then echo "FAILED" else echo "OK"