diff --git a/mysql-test/suite/galera/r/galera_sequences_recovery.result b/mysql-test/suite/galera/r/galera_sequences_recovery.result index 1125f3faf8117..11b02400960af 100644 --- a/mysql-test/suite/galera/r/galera_sequences_recovery.result +++ b/mysql-test/suite/galera/r/galera_sequences_recovery.result @@ -9,60 +9,80 @@ INSERT INTO t1(f2) values (1); INSERT INTO t1(f2) values (1); INSERT INTO t1(f2) values (1); INSERT INTO t1(f2) values (1); -INSERT INTO t1(f2) values (1); +connect node_1_ctrl, 127.0.0.1, root, , test, $NODE_MYPORT_1; +connection node_1_ctrl; +SET GLOBAL innodb_log_checkpoint_now=1; connection node_2; BEGIN; INSERT INTO t1(f2) values (2); INSERT INTO t1(f2) values (2); INSERT INTO t1(f2) values (2); +# Crash and restart the node, losing the transaction (1) Killing server ... +Performing --wsrep-recover ... +Using --wsrep-start-position when starting mysqld ... +connection node_1; +connection node_2; +# Wait for the next_not_cached_value = 11 FROM s (1) SELECT NEXTVAL(s); NEXTVAL(s) 12 +SELECT LASTVAL(s); +LASTVAL(s) +12 +SET GLOBAL innodb_log_checkpoint_now=1; connection node_1; INSERT INTO t1(f2) values (1); INSERT INTO t1(f2) values (1); INSERT INTO t1(f2) values (1); INSERT INTO t1(f2) values (1); INSERT INTO t1(f2) values (1); +INSERT INTO t1(f2) values (1); COMMIT; +SET GLOBAL innodb_log_checkpoint_now=1; SELECT LASTVAL(s); LASTVAL(s) -29 +31 +SELECT COUNT(*) FROM t1; +COUNT(*) +10 SELECT * FROM t1; f1 f2 1 1 3 1 5 1 7 1 -9 1 21 1 23 1 25 1 27 1 29 1 +31 1 connection node_2; +# Wait for the next_not_cached_value = 42 FROM s SELECT LASTVAL(s); LASTVAL(s) 12 SELECT NEXTVAL(s); NEXTVAL(s) -32 +42 SELECT * FROM t1; f1 f2 1 1 3 1 5 1 7 1 -9 1 21 1 23 1 25 1 27 1 29 1 +31 1 +SET GLOBAL innodb_log_checkpoint_now=1; connection node_1; DROP TABLE t1; DROP SEQUENCE s; +SET GLOBAL innodb_log_checkpoint_now=1; connection node_1; CREATE SEQUENCE s INCREMENT=0 CACHE=5 ENGINE=InnoDB; CREATE TABLE t1 (f1 INT PRIMARY KEY DEFAULT NEXTVAL(s), f2 INT) ENGINE=InnoDB; @@ -73,6 +93,8 @@ INSERT INTO t1(f2) values (1); INSERT INTO t1(f2) values (1); INSERT INTO t1(f2) values (1); INSERT INTO t1(f2) values (1); +connection node_1_ctrl; +SET GLOBAL innodb_log_checkpoint_now=1; connection node_2; BEGIN; INSERT INTO t1(f2) values (2); @@ -81,17 +103,51 @@ INSERT INTO t1(f2) values (2); INSERT INTO t1(f2) values (2); INSERT INTO t1(f2) values (2); INSERT INTO t1(f2) values (2); +INSERT INTO t1(f2) values (2); +INSERT INTO t1(f2) values (2); +INSERT INTO t1(f2) values (2); +INSERT INTO t1(f2) values (2); +INSERT INTO t1(f2) values (2); +INSERT INTO t1(f2) values (2); +INSERT INTO t1(f2) values (2); +INSERT INTO t1(f2) values (2); +INSERT INTO t1(f2) values (2); +connect node_2a, 127.0.0.1, root, , test, $NODE_MYPORT_2; +SET GLOBAL innodb_log_checkpoint_now=1; +SET SESSION wsrep_sync_wait=0; +# Wait for the next_not_cached_value = 31 FROM s (2a) +SELECT next_not_cached_value = 31 FROM s; +next_not_cached_value = 31 +1 +connection node_2; +# Crash and restart the node, losing the transaction (2) Killing server ... +Performing --wsrep-recover ... +Using --wsrep-start-position when starting mysqld ... connection node_1; +connection node_2; +# Wait for the next_not_cached_value = 31 FROM s (2) +SELECT LASTVAL(s); +LASTVAL(s) +NULL +connection node_1; +INSERT INTO t1(f2) values (1); INSERT INTO t1(f2) values (1); INSERT INTO t1(f2) values (1); INSERT INTO t1(f2) values (1); INSERT INTO t1(f2) values (1); INSERT INTO t1(f2) values (1); +INSERT INTO t1(f2) values (1); +INSERT INTO t1(f2) values (1); +INSERT INTO t1(f2) values (1); +INSERT INTO t1(f2) values (1); +SELECT COUNT(*) FROM t1; +COUNT(*) +15 COMMIT; SELECT LASTVAL(s); LASTVAL(s) -19 +29 SELECT * FROM t1; f1 f2 1 1 @@ -104,10 +160,20 @@ f1 f2 15 1 17 1 19 1 +21 1 +23 1 +25 1 +27 1 +29 1 +SET GLOBAL innodb_log_checkpoint_now=1; connection node_2; +# Wait for the next_not_cached_value = 31 FROM s +SELECT LASTVAL(s); +LASTVAL(s) +NULL SELECT NEXTVAL(s); NEXTVAL(s) -22 +32 SELECT * FROM t1; f1 f2 1 1 @@ -120,13 +186,60 @@ f1 f2 15 1 17 1 19 1 +21 1 +23 1 +25 1 +27 1 +29 1 +SET GLOBAL innodb_log_checkpoint_now=1; connection node_1; +# Wait for the next_not_cached_value = 41 FROM s SELECT LASTVAL(s); LASTVAL(s) -19 +29 SELECT NEXTVAL(s); NEXTVAL(s) -33 +41 +SET GLOBAL innodb_log_checkpoint_now=1; +connection node_2; +# Wait for the next_not_cached_value = 52 FROM s +SELECT LASTVAL(s); +LASTVAL(s) +32 +SELECT * from t1; +f1 f2 +1 1 +3 1 +5 1 +7 1 +9 1 +11 1 +13 1 +15 1 +17 1 +19 1 +21 1 +23 1 +25 1 +27 1 +29 1 connection node_1; +SELECT * FROM t1; +f1 f2 +1 1 +3 1 +5 1 +7 1 +9 1 +11 1 +13 1 +15 1 +17 1 +19 1 +21 1 +23 1 +25 1 +27 1 +29 1 DROP TABLE t1; DROP SEQUENCE s; diff --git a/mysql-test/suite/galera/t/galera_sequences.cnf b/mysql-test/suite/galera/t/galera_sequences.cnf index 8701e86db5f0e..8a8dfb4e06395 100644 --- a/mysql-test/suite/galera/t/galera_sequences.cnf +++ b/mysql-test/suite/galera/t/galera_sequences.cnf @@ -1,9 +1,11 @@ !include ../galera_2nodes.cnf [mysqld.1] +wsrep-auto-increment-control=OFF auto-increment-increment=2 auto-increment-offset=1 [mysqld.2] +wsrep-auto-increment-control=OFF auto-increment-increment=2 auto-increment-offset=2 diff --git a/mysql-test/suite/galera/t/galera_sequences_bf_kill.cnf b/mysql-test/suite/galera/t/galera_sequences_bf_kill.cnf index 8701e86db5f0e..8a8dfb4e06395 100644 --- a/mysql-test/suite/galera/t/galera_sequences_bf_kill.cnf +++ b/mysql-test/suite/galera/t/galera_sequences_bf_kill.cnf @@ -1,9 +1,11 @@ !include ../galera_2nodes.cnf [mysqld.1] +wsrep-auto-increment-control=OFF auto-increment-increment=2 auto-increment-offset=1 [mysqld.2] +wsrep-auto-increment-control=OFF auto-increment-increment=2 auto-increment-offset=2 diff --git a/mysql-test/suite/galera/t/galera_sequences_recovery.cnf b/mysql-test/suite/galera/t/galera_sequences_recovery.cnf index 8701e86db5f0e..ea1ca6df9f0f5 100644 --- a/mysql-test/suite/galera/t/galera_sequences_recovery.cnf +++ b/mysql-test/suite/galera/t/galera_sequences_recovery.cnf @@ -1,9 +1,14 @@ !include ../galera_2nodes.cnf [mysqld.1] +wsrep-auto-increment-control=OFF auto-increment-increment=2 auto-increment-offset=1 +wsrep_provider_options='pc.weight=2;pc.ignore_sb=true' +wsrep-sync-wait=15 [mysqld.2] +wsrep-auto-increment-control=OFF auto-increment-increment=2 auto-increment-offset=2 +wsrep-sync-wait=15 diff --git a/mysql-test/suite/galera/t/galera_sequences_recovery.test b/mysql-test/suite/galera/t/galera_sequences_recovery.test index 4b59d0ad1afed..ff0f6b89bc952 100644 --- a/mysql-test/suite/galera/t/galera_sequences_recovery.test +++ b/mysql-test/suite/galera/t/galera_sequences_recovery.test @@ -5,6 +5,7 @@ --source include/galera_cluster.inc --source include/have_sequence.inc --source include/big_test.inc +--source include/no_protocol.inc --disable_ps2_protocol @@ -22,7 +23,10 @@ INSERT INTO t1(f2) values (1); INSERT INTO t1(f2) values (1); INSERT INTO t1(f2) values (1); INSERT INTO t1(f2) values (1); -INSERT INTO t1(f2) values (1); + +--connect node_1_ctrl, 127.0.0.1, root, , test, $NODE_MYPORT_1 +--connection node_1_ctrl +SET GLOBAL innodb_log_checkpoint_now=1; --connection node_2 BEGIN; @@ -30,14 +34,28 @@ INSERT INTO t1(f2) values (2); INSERT INTO t1(f2) values (2); INSERT INTO t1(f2) values (2); -# Crash and restart the node, losing the transaciton +--echo # Crash and restart the node, losing the transaction (1) --source include/kill_galera.inc +--let $galera_wsrep_recover_server_id=2 +--source include/galera_wsrep_recover.inc --let $start_mysqld_params = --let $_expect_file_name= $MYSQLTEST_VARDIR/tmp/mysqld.2.expect --source include/start_mysqld.inc +--connection node_1 +--let $wait_condition = SELECT VARIABLE_VALUE = 2 FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_cluster_size' +--source include/wait_condition_with_debug.inc + +--connection node_2 +--echo # Wait for the next_not_cached_value = 11 FROM s (1) +--let $wait_condition = SELECT next_not_cached_value = 11 FROM s; +--let $wait_condition_on_error_output = SELECT next_not_cached_value FROM s +--source include/wait_condition_with_debug.inc + # Check and update the last written sequence value SELECT NEXTVAL(s); +SELECT LASTVAL(s); +SET GLOBAL innodb_log_checkpoint_now=1; --connection node_1 # Update the sequence value further @@ -46,21 +64,32 @@ INSERT INTO t1(f2) values (1); INSERT INTO t1(f2) values (1); INSERT INTO t1(f2) values (1); INSERT INTO t1(f2) values (1); - +INSERT INTO t1(f2) values (1); COMMIT; +SET GLOBAL innodb_log_checkpoint_now=1; SELECT LASTVAL(s); +SELECT COUNT(*) FROM t1; SELECT * FROM t1; --connection node_2 +--let $wait_condition = SELECT COUNT(*) = 10 FROM t1 +--source include/wait_condition.inc +--echo # Wait for the next_not_cached_value = 42 FROM s +--let $wait_condition = SELECT next_not_cached_value = 42 FROM s +--let $wait_condition_on_error_output = SELECT next_not_cached_value FROM s +--source include/wait_condition_with_debug.inc + # The next value should be in sync now, but the last # value is still the same SELECT LASTVAL(s); SELECT NEXTVAL(s); SELECT * FROM t1; +SET GLOBAL innodb_log_checkpoint_now=1; --connection node_1 DROP TABLE t1; DROP SEQUENCE s; +SET GLOBAL innodb_log_checkpoint_now=1; # # Case 2: Crash a node during a transaction, bring the @@ -78,6 +107,9 @@ INSERT INTO t1(f2) values (1); INSERT INTO t1(f2) values (1); INSERT INTO t1(f2) values (1); +--connection node_1_ctrl +SET GLOBAL innodb_log_checkpoint_now=1; + --connection node_2 # Exhaust the cached values once, but no replication happens even # though the sequnce table is updated @@ -88,36 +120,107 @@ INSERT INTO t1(f2) values (2); INSERT INTO t1(f2) values (2); INSERT INTO t1(f2) values (2); INSERT INTO t1(f2) values (2); +INSERT INTO t1(f2) values (2); +INSERT INTO t1(f2) values (2); +INSERT INTO t1(f2) values (2); +INSERT INTO t1(f2) values (2); +INSERT INTO t1(f2) values (2); +INSERT INTO t1(f2) values (2); +INSERT INTO t1(f2) values (2); +INSERT INTO t1(f2) values (2); +INSERT INTO t1(f2) values (2); -# Crash and restart the node, losing the transaciton +--connect node_2a, 127.0.0.1, root, , test, $NODE_MYPORT_2 +SET GLOBAL innodb_log_checkpoint_now=1; +SET SESSION wsrep_sync_wait=0; +--echo # Wait for the next_not_cached_value = 31 FROM s (2a) +--let $wait_condition = SELECT next_not_cached_value = 31 FROM s +--let $wait_condition_on_error_output = SELECT next_not_cached_value FROM s +--source include/wait_condition_with_debug.inc + SELECT next_not_cached_value = 31 FROM s; + +--connection node_2 +--echo # Crash and restart the node, losing the transaction (2) --source include/kill_galera.inc +--let $galera_wsrep_recover_server_id=2 +--source include/galera_wsrep_recover.inc --let $start_mysqld_params = --let $_expect_file_name= $MYSQLTEST_VARDIR/tmp/mysqld.2.expect --source include/start_mysqld.inc --connection node_1 +--let $wait_condition = SELECT VARIABLE_VALUE = 2 FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_cluster_size' +--source include/wait_condition.inc + +--connection node_2 +--echo # Wait for the next_not_cached_value = 31 FROM s (2) +--let $wait_condition = SELECT next_not_cached_value = 31 FROM s +--let $wait_condition_on_error_output = SELECT next_not_cached_value FROM s +--source include/wait_condition_with_debug.inc + +SELECT LASTVAL(s); + +--connection node_1 +INSERT INTO t1(f2) values (1); +INSERT INTO t1(f2) values (1); INSERT INTO t1(f2) values (1); INSERT INTO t1(f2) values (1); INSERT INTO t1(f2) values (1); INSERT INTO t1(f2) values (1); INSERT INTO t1(f2) values (1); +INSERT INTO t1(f2) values (1); +INSERT INTO t1(f2) values (1); +INSERT INTO t1(f2) values (1); +SELECT COUNT(*) FROM t1; COMMIT; SELECT LASTVAL(s); SELECT * FROM t1; +SET GLOBAL innodb_log_checkpoint_now=1; --connection node_2 +--let $wait_condition = SELECT COUNT(*) = 15 FROM t1 +--source include/wait_condition.inc +--echo # Wait for the next_not_cached_value = 31 FROM s +--let $wait_condition = SELECT next_not_cached_value = 31 FROM s +--let $wait_condition_on_error_output = SELECT next_not_cached_value FROM s +--source include/wait_condition_with_debug.inc + # Check and update the last written sequence value, it's still # higher than the one from the other node +SELECT LASTVAL(s); SELECT NEXTVAL(s); SELECT * FROM t1; +SET GLOBAL innodb_log_checkpoint_now=1; --connection node_1 +--let $wait_condition = SELECT COUNT(*) = 15 FROM t1 +--source include/wait_condition.inc +--let $wait_condition = SELECT LASTVAL(s) = 29 +--let $wait_condition_on_error_output = SELECT LASTVAL(s) +--source include/wait_condition_with_debug.inc +--echo # Wait for the next_not_cached_value = 41 FROM s +--let $wait_condition = SELECT next_not_cached_value = 41 FROM s +--let $wait_condition_on_error_output = SELECT next_not_cached_value FROM s +--source include/wait_condition_with_debug.inc # The next value should be in sync now, but the last # value is still the same SELECT LASTVAL(s); SELECT NEXTVAL(s); +SET GLOBAL innodb_log_checkpoint_now=1; + +--connection node_2 +--let $wait_condition = SELECT LASTVAL(s) = 32 +--let $wait_condition_on_error_output = SELECT LASTVAL(s) +--source include/wait_condition_with_debug.inc +--echo # Wait for the next_not_cached_value = 52 FROM s +--let $wait_condition = SELECT next_not_cached_value = 52 FROM s +--let $wait_condition_on_error_output = SELECT next_not_cached_value FROM s +--source include/wait_condition_with_debug.inc +SELECT LASTVAL(s); +SELECT * from t1; --connection node_1 +SELECT * FROM t1; DROP TABLE t1; DROP SEQUENCE s; diff --git a/mysql-test/suite/galera/t/galera_sequences_transaction.cnf b/mysql-test/suite/galera/t/galera_sequences_transaction.cnf index 8701e86db5f0e..8a8dfb4e06395 100644 --- a/mysql-test/suite/galera/t/galera_sequences_transaction.cnf +++ b/mysql-test/suite/galera/t/galera_sequences_transaction.cnf @@ -1,9 +1,11 @@ !include ../galera_2nodes.cnf [mysqld.1] +wsrep-auto-increment-control=OFF auto-increment-increment=2 auto-increment-offset=1 [mysqld.2] +wsrep-auto-increment-control=OFF auto-increment-increment=2 auto-increment-offset=2 diff --git a/mysql-test/suite/wsrep/r/wsrep-recover-sequences.result b/mysql-test/suite/wsrep/r/wsrep-recover-sequences.result new file mode 100644 index 0000000000000..dbe1e72610810 --- /dev/null +++ b/mysql-test/suite/wsrep/r/wsrep-recover-sequences.result @@ -0,0 +1,42 @@ +CREATE SEQUENCE s INCREMENT=0 CACHE=5 ENGINE=InnoDB; +CREATE TABLE t1 (f1 INT PRIMARY KEY DEFAULT NEXTVAL(s), f2 INT) ENGINE=InnoDB; +# Reserve values 1..5 from sequence +BEGIN; +INSERT INTO t1(f2) SELECT * FROM seq_1_to_5; +# From second connection execute enough INSERTs to reserve +# new range from sequence +connect node_1a, 127.0.0.1, root, , test, $NODE_MYPORT_1; +# Reserve values 6..25 from sequence +BEGIN; +INSERT INTO t1(f2) SELECT * FROM seq_1_to_20; +# From third connection execute enough INSERTs to reserve +# new range from sequence and commit +connect node_1b, 127.0.0.1, root, , test, $NODE_MYPORT_1; +# Reserve values 26..35 from sequence +BEGIN; +INSERT INTO t1(f2) SELECT * FROM seq_1_to_10; +COMMIT; +SET GLOBAL innodb_log_checkpoint_now=1; +connection default; +# Killing server +# Kill the server +Expect seqno 4 +4 +# Next free value is 36 +SELECT NEXTVAL(s) AS EXPECT_36; +EXPECT_36 +36 +SELECT * from t1; +f1 f2 +26 1 +27 2 +28 3 +29 4 +30 5 +31 6 +32 7 +33 8 +34 9 +35 10 +DROP TABLE t1; +DROP SEQUENCE s; diff --git a/mysql-test/suite/wsrep/t/wsrep-recover-sequences.cnf b/mysql-test/suite/wsrep/t/wsrep-recover-sequences.cnf new file mode 100644 index 0000000000000..b1c96d2614d78 --- /dev/null +++ b/mysql-test/suite/wsrep/t/wsrep-recover-sequences.cnf @@ -0,0 +1,7 @@ +!include ../my.cnf + +[mysqld.1] +wsrep-on=ON +wsrep-cluster-address=gcomm:// +wsrep-provider=@ENV.WSREP_PROVIDER +binlog-format=ROW diff --git a/mysql-test/suite/wsrep/t/wsrep-recover-sequences.combinations b/mysql-test/suite/wsrep/t/wsrep-recover-sequences.combinations new file mode 100644 index 0000000000000..1ce3b45aa1a76 --- /dev/null +++ b/mysql-test/suite/wsrep/t/wsrep-recover-sequences.combinations @@ -0,0 +1,4 @@ +[binlogon] +log-bin + +[binlogoff] diff --git a/mysql-test/suite/wsrep/t/wsrep-recover-sequences.test b/mysql-test/suite/wsrep/t/wsrep-recover-sequences.test new file mode 100644 index 0000000000000..808a444a39b42 --- /dev/null +++ b/mysql-test/suite/wsrep/t/wsrep-recover-sequences.test @@ -0,0 +1,69 @@ +# +# Verify that committed sequence operations are recovered correctly +# and that sequence operations not committed are lost in recovery. +# +# After each scenario server is killed and the recovered position +# is validated. +# + +--source include/have_wsrep.inc +--source include/have_innodb.inc +--source include/have_wsrep_provider.inc +--source include/have_sequence.inc +--source include/no_protocol.inc + +# +# Binlog option for recovery run. This must be set in the test because +# combinations file causes log-bin option to be set from command line, +# not via my.cnf. +# +--let $log_bin = `SELECT @@log_bin` +if ($log_bin) { +--let $wsrep_recover_binlog_opt = --log-bin +} + +# +# Start transaction from 2-connections but do not commit them +# verify that INSERTs to table are lost and reserved sequence +# range is lost. +# +let $restart_noprint=2; + +CREATE SEQUENCE s INCREMENT=0 CACHE=5 ENGINE=InnoDB; +CREATE TABLE t1 (f1 INT PRIMARY KEY DEFAULT NEXTVAL(s), f2 INT) ENGINE=InnoDB; +--echo # Reserve values 1..5 from sequence +BEGIN; +INSERT INTO t1(f2) SELECT * FROM seq_1_to_5; + +--echo # From second connection execute enough INSERTs to reserve +--echo # new range from sequence +--connect node_1a, 127.0.0.1, root, , test, $NODE_MYPORT_1 +--echo # Reserve values 6..25 from sequence +BEGIN; +INSERT INTO t1(f2) SELECT * FROM seq_1_to_20; + +--echo # From third connection execute enough INSERTs to reserve +--echo # new range from sequence and commit +--connect node_1b, 127.0.0.1, root, , test, $NODE_MYPORT_1 +--echo # Reserve values 26..35 from sequence +BEGIN; +INSERT INTO t1(f2) SELECT * FROM seq_1_to_10; +COMMIT; +SET GLOBAL innodb_log_checkpoint_now=1; + +--connection default +--echo # Killing server +--source include/kill_mysqld.inc +--source wsrep-recover-step.inc +--echo Expect seqno 4 +--echo $wsrep_recover_start_position_seqno + +--let $restart_parameters = --wsrep-start-position=$wsrep_recover_start_position_uuid:$wsrep_recover_start_position_seqno +--source include/start_mysqld.inc +--source include/wait_wsrep_ready.inc + +--echo # Next free value is 36 +SELECT NEXTVAL(s) AS EXPECT_36; +SELECT * from t1; +DROP TABLE t1; +DROP SEQUENCE s; \ No newline at end of file