1111
1212from operator import truediv
1313import os
14+ import random
1415import sys
1516
16- # transaction iolation level
1717class OptionException (Exception ):
1818 pass
1919
@@ -36,29 +36,26 @@ def __init__(self, op_type, txn_num, op_num):
3636 self .txn_num = txn_num
3737 self .op_num = op_num
3838
39- isolation_levels = set ()
40-
4139"""
4240Initialize supported isolation levels for different databases
4341
4442Args:
4543- db_type (str): The type of database being used.
4644
4745Returns:
48- int : the num of supported isolation levels.
46+ set : the supported isolation levels.
4947
5048"""
5149def init_isolation_levels (db_type ):
52-
53- global isolation_levels
50+ isolation_levels = list ()
5451 if 'mysql' in db_type .lower ():
55- isolation_levels = {
52+ isolation_levels = [
5653 "READ UNCOMMITTED" ,
5754 "READ COMMITTED" ,
5855 "REPEATABLE READ" ,
5956 "SERIALIZABLE"
60- }
61- return len ( isolation_levels )
57+ ]
58+ return isolation_levels
6259
6360"""
6461Initialize tables for database testing.
@@ -842,15 +839,19 @@ def write_description(file_name, txn_num, op_num, data_num):
842839"""
843840
844841def write_isolation_level (file_name , txn_num , isolation_levels ):
842+ if len (isolation_levels ) == 0 :
843+ return
844+
845845 isolation_level_descprtion = ""
846+ description = ""
846847 for i in range (txn_num ):
847- isolation_level = random ( )
848+ isolation_level = random . choice ( isolation_levels )
848849 if isolation_level_descprtion :
849850 isolation_level_descprtion += ","
850- isolation_level_descprtion += "T" + str (i + 1 ) + ":" + txn_list [ i ]. isolation_level
851+ isolation_level_descprtion += "T" + str (i + 1 ) + ":" + isolation_level
851852 description += "Txn Isolation: " + isolation_level_descprtion + "\n "
852853
853- with open (file_name , "w +" ) as file_test :
854+ with open (file_name , "a +" ) as file_test :
854855 file_test .write (description )
855856
856857
@@ -896,9 +897,12 @@ def write_isolation_level(file_name, txn_num, isolation_levels):
896897 table_num = 1
897898 sql_count , txn_count = 0 , 1
898899
900+ isolation_levels = init_isolation_levels (db_type )
899901 # description
900902 write_description (file_name , num , num , num )
901903
904+ write_isolation_level (file_name , num , isolation_levels )
905+
902906 # preparation
903907 data_num = init_table (file_name , sql_count , txn_count , table_num , db_type , test_type )
904908
0 commit comments