Commit 3eb4e598 authored by John Esmet's avatar John Esmet

[t:3453] blocking row locks test generated by scripts now cover, for 0

timeout and for 1 second timeout, 1.) point q vs point q 2.) range q vs
point q 3.) range q vs range q, overlapping or boundary. Blocking
transactions that return okay after a commit still need to be tested.


git-svn-id: file:///svn/mysql/tests/mysql-test@35017 c7de825b-a66e-492c-adef-691d508d4ae1
parent a27c37e2
# 9/23/2011 Generate blocking row lock tests # 9/23/2011 Generate blocking row lock tests
import datetime import datetime
# whether or not to do a sleep hack to get
# tests to pass
do_sleep_hack = False
# generate sql write queries # generate sql write queries
def mysqlgen_select_for_update(k, kv, c, cv): def mysqlgen_select_for_update(k, kv, c, cv):
print "select * from t where %s=%s for update;" % (k, kv) print "select * from t where %s=%s for update;" % (k, kv)
def mysqlgen_select_for_update_range(k, c, where):
print "select * from t where %s%s for update;" % (k, where)
def mysqlgen_update(k, kv, c, cv): def mysqlgen_update(k, kv, c, cv):
print "update t where %s=%s set %s=%s+1;" % (k, kv, c, c); print "update t set %s=%s where %s=%s;" % (c, c, k, kv);
def mysqlgen_insert(k, kv, c, cv): def mysqlgen_update_range(k, c, where):
print "insert t values(%s, %s);" % (kv, cv) print "update t set %s=%s where %s%s;" % (c, c, k, where);
def mysqlgen_insert_ignore(k, kv, c, cv):
print "insert ignore t values(%s, %s);" % (kv, cv)
def mysqlgen_insert_on_dup_update(k, kv, c, cv): def mysqlgen_insert_on_dup_update(k, kv, c, cv):
print "insert t values(%s, %s) on duplicate key update %s=%s+1;" % (kv, cv, c, c) print "insert t values(%s, %s) on duplicate key update %s=%s;" % (kv, cv, c, c)
def mysqlgen_replace(k, kv, c, cv): def mysqlgen_replace(k, kv, c, cv):
print "replace t values(%s, %s);" % (kv, cv) print "replace t values(%s, %s);" % (kv, cv)
# genrate sql read queries # genrate sql read queries
def mysqlgen_select_star(): def mysqlgen_select_star():
print "select * from t;" print "select * from t;"
def mysqlgen_select_where(where): def mysqlgen_select_where(k, where):
print "select * from t where %s;" % where print "select * from t where %s%s;" % (k, where)
# mysql test code generation # mysql test code generation
def mysqlgen_prepare(): def mysqlgen_prepare():
print "# prepare with some common parameters" print "# prepare with some common parameters"
print "set storage_engine=tokudb;" print "set storage_engine=tokudb;"
print "connect(conn1, localhost, root);" #print "connect(conn1, localhost, root);"
#print "set autocommit=off;"
print "connect(conn2, localhost, root);" print "connect(conn2, localhost, root);"
print "connection conn1;" print "connection default;"
print "" print ""
def mysqlgen_reload_table(): def mysqlgen_reload_table():
print "# drop old table, generate new one. 4 rows" print "# drop old table, generate new one. 4 rows"
...@@ -33,70 +42,109 @@ def mysqlgen_reload_table(): ...@@ -33,70 +42,109 @@ def mysqlgen_reload_table():
print "drop table if exists t;" print "drop table if exists t;"
print "--enable_warnings" print "--enable_warnings"
print "create table t (a int primary key, b int);" print "create table t (a int primary key, b int);"
for i in range(1, 5): for i in range(1, 7):
mysqlgen_insert("a", i, "b", i*i) mysqlgen_insert_ignore("a", i, "b", i*i)
print "" print ""
def mysqlgen_cleanup(): def mysqlgen_cleanup():
print "# clean it all up" print "# clean it all up"
print "drop table t;" print "drop table t;"
print "set global tokudb_lock_timeout=30000000;" print "set global tokudb_lock_timeout=30000000;"
print "" print ""
write_point_queries = [
def expect_lock_timeout(): ("select for update", mysqlgen_select_for_update),
print "--error ER_LOCK_WAIT_TIMEOUT" ("update", mysqlgen_update),
("insert", mysqlgen_insert_ignore),
("replace", mysqlgen_replace) ]
write_range_queries = [
("select for update", mysqlgen_select_for_update_range),
("update", mysqlgen_update_range) ]
# Here's where all the magic happens # Here's where all the magic happens
print "# Tokutek" print "# Tokutek"
print "# Blocking row lock tests;" print "# Blocking row lock tests;"
print "# Generated by %s on %s;" % (__file__, datetime.date.today()) print "# Generated by %s on %s;" % (__file__, datetime.date.today())
print "" 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_prepare()
mysqlgen_reload_table() mysqlgen_reload_table()
for timeout in ["0", "1000000"]: for timeout in ["0", "1000000"]:
print "# testing with timeout %s" % timeout print "# testing with timeout %s" % timeout
print "set global tokudb_lock_timeout=%s;" % timeout print "set global tokudb_lock_timeout=%s;" % timeout
print "" print ""
for ta, qa in write_queries: print "# testing each point query vs each point query"
for tb, qb in write_queries: for ta, qa in write_point_queries:
# point vs point contention
for tb, qb in write_point_queries:
print "# testing conflict \"%s\" vs. \"%s\"" % (ta, tb) print "# testing conflict \"%s\" vs. \"%s\"" % (ta, tb)
print "connection conn1;" print "connection default;"
print "set autocommit=off;"
print "begin;" print "begin;"
print "" print ""
qa("a", "1", "b", "100")
# point lock
print "#TODO: Test point lock"
qa("a", 1, "b", 100)
print "connection conn2;" print "connection conn2;"
for k in range(1, 5): for k in range(1, 5):
if k == 1: if k == 1:
print "--error ER_LOCK_WAIT_TIMEOUT" print "--error ER_LOCK_WAIT_TIMEOUT"
qb("a", k, "b", 100) if do_sleep_hack:
print "--sleep 0.2"
# range lock qb("a", k, "b", "100")
print "#TODO: Test range lock" # Always check in the end that a commit
# allows the other transaction full access
print "connection default;"
print "commit;"
print "connection conn2;"
qb("a", "1", "b", "100")
mysqlgen_select_star()
print "connection default;"
print "" print ""
# point vs range contention
# overlapping range for rt, rq in write_range_queries:
print "#TODO: Test overlapping range locks" print "# testing range query \"%s\" vs \"%s\"" % (rt, ta)
print "connection default;"
print "begin;"
print ""
qa("a", "1", "b", "100")
print "connection conn2;"
print "--error ER_LOCK_WAIT_TIMEOUT"
if do_sleep_hack:
print "--sleep 0.2"
rq("a", "b", "<=2")
print "--error ER_LOCK_WAIT_TIMEOUT"
if do_sleep_hack:
print "--sleep 0.2"
rq("a", "b", ">=0")
rq("a", "b", ">2")
# Always check in the end that a commit
# allows the other transaction full access
print "connection default;"
print "commit;"
print "connection conn2;"
rq("a", "b", "<=2")
rq("a", "b", ">=0")
mysqlgen_select_star()
print "connection default;"
print "" print ""
for rt, rq in write_range_queries:
for rtb, rqb in write_range_queries:
print "# testing range query \"%s\" vs range query \"%s\"" % (rt, rtb)
print "connection default;"
print "begin;"
print ""
rq("a", "b", ">=2 and a<=4")
print "connection conn2;"
print "--error ER_LOCK_WAIT_TIMEOUT"
rqb("a", "b", ">=0 and a<=3")
print "--error ER_LOCK_WAIT_TIMEOUT"
rqb("a", "b", ">=3 and a<=6")
print "--error ER_LOCK_WAIT_TIMEOUT"
rqb("a", "b", "<=2")
rqb("a", "b", ">=5")
# Always check in the end that a commit # Always check in the end that a commit
# allows the other transaction full access # allows the other transaction full access
print "connection conn1;" print "connection default;"
print "commit;" print "commit;"
print "connection conn2;" print "connection conn2;"
rqb("a", "b", ">=0 and a<=3")
rqb("a", "b", ">=3 and a<=6")
rqb("a", "b", "<=2")
mysqlgen_select_star() mysqlgen_select_star()
print "connection conn1;" print "connection default;"
print "" print ""
mysqlgen_cleanup()
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