Commit 7467ee97 authored by John Esmet's avatar John Esmet

[t:3453] python script to generate the 100ish test cases blocking row

locks require. making progress, needs more love though.


git-svn-id: file:///svn/mysql/tests/mysql-test@34995 c7de825b-a66e-492c-adef-691d508d4ae1
parent 9d0dce89
# 9/23/2011 Generate blocking row lock tests
import datetime
# generate sql write queries
def mysqlgen_select_for_update(k, kv):
print "select * from t where %s=%s for update;" % (k, kv)
def mysqlgen_update(k, kv, c, cv):
print "update t where %s=%s set %s=%s+1;" % (k, kv, kv, kv);
def mysqlgen_insert(k, kv, c, cv):
print "insert t values(%s, %s);" % (kv, cv)
def mysqlgen_replace(k, kv, c, cv):
print "replace t values(%s, %s);" % (kv, cv)
# genrate sql read queries
def mysqlgen_select_star():
print "select * from t;"
def mysqlgen_select_where(where):
print "select * from t where %s;" % where
# mysql test code generation
def mysqlgen_prepare():
print "# prepare with some common parameters"
print "set storage_engine=tokudb;"
print "connect(conn1, localhost, root);"
# ONLY connection 1 should have autocommit off.
print "set autocommit=off;"
print "connect(conn2, localhost, root);"
print "connection conn1;"
print ""
def mysqlgen_reload_table():
print "# drop old table, generate new one. 4 rows"
print "--disable_warnings"
print "drop table if exists t;"
print "--enable_warnings"
print "create table t (a int primary key, b int);"
for i in range(1, 5):
mysqlgen_insert("a", i, "b", i*i)
print ""
def mysqlgen_cleanup():
print "# clean it all up"
print "drop table t;"
print "set global tokudb_lock_timeout=30000000;"
print ""
# Here's where all the magic happens
print "# Tokutek"
print "# Blocking row lock tests;"
print "# Generated by %s on %s;" % (__file__, datetime.date.today())
print ""
print "# BEGIN WRITE/WRITE CONFLICTS TESTS"
print ""
# Iterate through all possible situations. Each timeout class,
# each pair of write queries, each kind of query.
write_queries = [
("select for update", mysqlgen_select_for_update),
("update", mysqlgen_update),
("insert", mysqlgen_insert),
("replace", mysqlgen_replace) ]
mysqlgen_prepare()
mysqlgen_reload_table()
for timeout in ["0", "1000000"]:
print "# testing with timeout %s" % timeout
print "set global tokudb_lock_timeout=%s;" % timeout
print ""
for ta, qa in write_queries:
for tb, qb in write_queries:
print "# testing conflict \"%s\" vs. \"%s\"" % (ta, tb)
print "connection conn1;"
print "begin;"
print ""
# point lock
print "#TODO: Test point lock"
print ""
# range lock
print "#TODO: Test range lock"
print ""
# overlapping range
print "#TODO: Test overlapping range locks"
print ""
# Always check in the end that a commit
# allows the other transaction full access
print "connection conn1;"
print "commit;"
print "connection conn2;"
mysqlgen_select_star()
print "connection conn1;"
print ""
mysqlgen_cleanup()
......@@ -15,62 +15,49 @@ insert into t values (4, 16);
set autocommit=off;
# We need to test that reads/writes properly block when a row lock is
# obtained, so the isolation level needs to be serializable
# READ/WRITE CONFLICTS WITH SERIALIZABLE TRANSACTIONS
connect(conn1, localhost, root);
set session transaction isolation level serializable;
# First test - a point update lock should block a read, but not
# block any others
# point lock, select for update
begin;
select * from t where a=1 for update;
connect(conn2, localhost, root);
set session transaction isolation level serializable;
# Connection 2 reads, should block until the first connection commits;
# Assert that this call times out with ER_LOCK_WAIT_TIMEOUT
--error ER_LOCK_WAIT_TIMEOUT
select * from t where a=1;
select * from t where a=2;
select * from t where a=3;
select * from t where a=4;
connection conn1;
commit;
# Once we commit, it all works;
connection conn2;
select * from t;
# range lock, select for update
connection conn1;
# Second test - a range update lock should block a read
begin;
select * from t where a<=2 for update;
connection conn2;
--error ER_LOCK_WAIT_TIMEOUT
select * from t where a=1;
--error ER_LOCK_WAIT_TIMEOUT
select * from t where a=1 for update;
--error ER_LOCK_WAIT_TIMEOUT
select * from t where a>1;
--error ER_LOCK_WAIT_TIMEOUT
select * from t;
# this should pass, since we locked 1-2
select * from t where a=4;
connection conn1;
commit;
# Once we commit, it works
connection conn2;
select * from t;
# point lock, replace into
connection conn1;
# Third test - replace into should do the same
begin;
replace into t values(1, 10),(3,30);
connection conn2;
--error ER_LOCK_WAIT_TIMEOUT
select * from t where a=1;
......@@ -78,17 +65,18 @@ select * from t where a=1;
select * from t where a=3;
select * from t where a=2;
select * from t where a=4;
connection conn1;
commit;
# Once we commit, it works
connection conn2;
select * from t;
# range lock, replace into
connection conn1;
drop table t;
begin;
insert on duplicate ke
# Make sure we reset the default lock timeout, too
# Make sure we drop table and reset the default lock timeout.
connection conn1;
drop table t;
set global tokudb_lock_timeout=30000000;
select @@tokudb_lock_timeout;
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment