diff options
author | unknown <knielsen@knielsen-hq.org> | 2011-01-31 15:40:58 +0100 |
---|---|---|
committer | unknown <knielsen@knielsen-hq.org> | 2011-01-31 15:40:58 +0100 |
commit | 4d964073698526a14d8f302149754923a6174f65 (patch) | |
tree | 6a3c5529d55b0c437efe3c832a1762d721c4afa3 /tests | |
parent | e8230faa0f7530249649596e6fa16c08384509ce (diff) | |
parent | fdb2ad5fb8e7d4a743bba23967a4a464f9c29ead (diff) | |
download | mariadb-git-4d964073698526a14d8f302149754923a6174f65.tar.gz |
Merge MWL#116, PBXT part into mariadb-5.2-rpl
This makes PBXT implement the commit_ordered() method, so that cross-engine
START TRANSACTION WITH CONSISTENT SNAPSHOT works actually consistent with
XtraDB.
Also mark the version number to show this is the -rpl feature preview.
Diffstat (limited to 'tests')
-rwxr-xr-x | tests/consistent_snapshot.pl | 107 |
1 files changed, 107 insertions, 0 deletions
diff --git a/tests/consistent_snapshot.pl b/tests/consistent_snapshot.pl new file mode 100755 index 00000000000..9e53eaea6a1 --- /dev/null +++ b/tests/consistent_snapshot.pl @@ -0,0 +1,107 @@ +#! /usr/bin/perl + +# Test START TRANSACTION WITH CONSISTENT SNAPSHOT. +# With MWL#116, this is implemented so it is actually consistent. + +use strict; +use warnings; + +use DBI; + +my $UPDATERS= 10; +my $READERS= 5; + +my $ROWS= 50; +my $DURATION= 20; + +my $stop_time= time() + $DURATION; + +sub my_connect { + my $dbh= DBI->connect("dbi:mysql:mysql_socket=/tmp/mysql.sock;database=test", + "root", undef, { RaiseError=>1, PrintError=>0, AutoCommit=>0}); + $dbh->do("SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ"); + $dbh->do("SET SESSION autocommit = 0"); + return $dbh; +} + +sub my_setup { + my $dbh= my_connect(); + + $dbh->do("DROP TABLE IF EXISTS test_consistent_snapshot1, test_consistent_snapshot2"); + $dbh->do(<<TABLE); +CREATE TABLE test_consistent_snapshot1 ( + a INT PRIMARY KEY, + b INT NOT NULL +) ENGINE=InnoDB +TABLE + $dbh->do(<<TABLE); +CREATE TABLE test_consistent_snapshot2( + a INT PRIMARY KEY, + b INT NOT NULL +) ENGINE=PBXT +TABLE + + for (my $i= 0; $i < $ROWS; $i++) { + my $value= int(rand()*1000); + $dbh->do("INSERT INTO test_consistent_snapshot1 VALUES (?, ?)", undef, + $i, $value); + $dbh->do("INSERT INTO test_consistent_snapshot2 VALUES (?, ?)", undef, + $i, -$value); + } + $dbh->commit(); + $dbh->disconnect(); +} + +sub my_updater { + my $dbh= my_connect(); + + while (time() < $stop_time) { + my $i1= int(rand()*$ROWS); + my $i2= int(rand()*$ROWS); + my $v= int(rand()*99)-49; + $dbh->do("UPDATE test_consistent_snapshot1 SET b = b + ? WHERE a = ?", + undef, $v, $i1); + $dbh->do("UPDATE test_consistent_snapshot2 SET b = b - ? WHERE a = ?", + undef, $v, $i2); + $dbh->commit(); + } + + $dbh->disconnect(); + exit(0); +} + +sub my_reader { + my $dbh= my_connect(); + + my $iteration= 0; + while (time() < $stop_time) { + $dbh->do("START TRANSACTION WITH CONSISTENT SNAPSHOT"); + my $s1= $dbh->selectrow_arrayref("SELECT SUM(b) FROM test_consistent_snapshot1"); + $s1= $s1->[0]; + my $s2= $dbh->selectrow_arrayref("SELECT SUM(b) FROM test_consistent_snapshot2"); + $s2= $s2->[0]; + $dbh->commit(); + if ($s1 + $s2 != 0) { + print STDERR "Found inconsistency, s1=$s1 s2=$s2 iteration=$iteration\n"; + last; + } + ++$iteration; + } + + $dbh->disconnect(); + exit(0); +} + +my_setup(); + +for (1 .. $UPDATERS) { + fork() || my_updater(); +} + +for (1 .. $READERS) { + fork() || my_reader(); +} + +waitpid(-1, 0) for (1 .. ($UPDATERS + $READERS)); + +print "All checks done\n"; |