From fdb2ad5fb8e7d4a743bba23967a4a464f9c29ead Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 15 Oct 2010 15:42:06 +0200 Subject: MWL#116: Efficient group commit: PBXT part Implement the commit_ordered() API in PBXT, getting consistent commit ordering with other engines and binlog. Make pbxt_support_xa default in MariaDB debug build (as the bug that causes assert in MySQL is fixed in MariaDB). --- tests/consistent_snapshot.pl | 107 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 107 insertions(+) create mode 100755 tests/consistent_snapshot.pl (limited to 'tests/consistent_snapshot.pl') 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(<do(<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"; -- cgit v1.2.1