Skip to content

Commit

Permalink
Switch back to MySQL-python for CentOS 8.0 and convert to python3 [no…
Browse files Browse the repository at this point in the history
…n-RocksDB part]

Summary:
In order to get python tests to work in CentOS 8.0:
1. Default `python` has been removed in CentOS 8.0, so all invocations should explicitly call `python2` or `python3`.
2. Switch MySQL-db to PyMySQL: CentOS 8.0 doesn't have MySQLdb-python package available and some MTR tests need it, so I'm switching to PyMySQL (python2-pymysql). Fortunately PyMySQL has a MySQL-db compatible-mode so switching is relatively easy. I've already added necessary packages in sandcastle so that's why the tests are passing there
3. Catch InternalError for ER_DEADLOCK instead of OperationalError: This is a behavioral difference between PyMySQL and MySQL-db. This appears to be fixed in latest PyMySQL but in the current version in CentOS 8.0 it still has that bug and throws InternalError. I've changed the code to expect both.
4. Reduce contention and iterations in certain test cases as PyMySQL is slower
5. Avoid sending super long queries as it'll get truncated in PyMySQL
6. Update CR.* to CR.CR_* as the prefix for CR codes in PyMySQL is CR_ while MySQLdb has no prefix

Porting notes:

Should fix individual tests on the next rebase.

Differential Revision: D20578783
  • Loading branch information
yizhang82 authored and Herman Lee committed Nov 18, 2023
1 parent ad4700d commit 9d0dda0
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 8 deletions.
8 changes: 4 additions & 4 deletions mysql-test/suite/innodb_stress/include/innodb_stress.inc
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ if ($do_checksum)
{
# populate the table and store its checksum before any load.
let $exec =
$PYTHON $MYSQL_TEST_DIR/suite/innodb_stress/t/load_generator.py $pid_file $kill_db_after
/usr/bin/python3 $MYSQL_TEST_DIR/suite/innodb_stress/t/load_generator.py $pid_file $kill_db_after
$num_records 0 0 $user $master_host $MASTER_MYPORT
$table 0 $max_rows $MYSQL_TMP_DIR/load_generator 0 0 0;
exec $exec >> $MYSQL_TMP_DIR/load_generator/errors.log;
Expand Down Expand Up @@ -68,14 +68,14 @@ while ($num_crashes)
if ($use_blob)
{
let $exec =
$PYTHON $MYSQL_TEST_DIR/suite/innodb_stress/t/load_generator.py $pid_file $kill_db_after
/usr/bin/python3 $MYSQL_TEST_DIR/suite/innodb_stress/t/load_generator.py $pid_file $kill_db_after
$num_records $num_workers $num_transactions $user $master_host $MASTER_MYPORT
$table 1 $max_rows $MYSQL_TMP_DIR/load_generator 0 $checksum $secondary_index_checks;
}
if (!$use_blob)
{
let $exec =
$PYTHON $MYSQL_TEST_DIR/suite/innodb_stress/t/load_generator.py $pid_file $kill_db_after
/usr/bin/python3 $MYSQL_TEST_DIR/suite/innodb_stress/t/load_generator.py $pid_file $kill_db_after
$num_records $num_workers $num_transactions $user $master_host $MASTER_MYPORT
$table 0 $max_rows $MYSQL_TMP_DIR/load_generator 0 $checksum $secondary_index_checks;
}
Expand Down Expand Up @@ -106,7 +106,7 @@ $table 0 $max_rows $MYSQL_TMP_DIR/load_generator 0 $checksum $secondary_index_ch
--echo applying fake updates to the slave
let $slave_pid_file = `SELECT @@pid_file`;
let $slave_exec =
$PYTHON $MYSQL_TEST_DIR/suite/innodb_stress/t/load_generator.py $slave_pid_file $kill_db_after
/usr/bin/python3 $MYSQL_TEST_DIR/suite/innodb_stress/t/load_generator.py $slave_pid_file $kill_db_after
0 $num_workers $num_transactions $user $master_host $SLAVE_MYPORT
$table 0 $max_rows $MYSQL_TMP_DIR/load_generator_slave 1 $checksum $secondary_index_checks;
exec $slave_exec >> $MYSQL_TMP_DIR/load_generator/errors.log;
Expand Down
6 changes: 5 additions & 1 deletion mysql-test/suite/innodb_stress/t/load_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ def populate_table(con, num_records_before, do_blob, log):

for i in range(start_id, num_records_before):
msg = get_msg(do_blob, i)
# print("length is %d, complen is %d" % (len(msg), len(zlib.compress(msg, 6))), file=log)
stmt = """
INSERT INTO t1(id,msg_prefix,msg,msg_length,msg_checksum) VALUES (%d,'%s','%s',%d,'%s')
""" % (i+1, msg[0:255], msg, len(msg), sha1(msg))
Expand Down Expand Up @@ -223,6 +224,8 @@ def validate_msg(self, msg_prefix, msg, msg_length, msg_checksum, idx):
prefix_match = msg_prefix == msg[0:255]

checksum = sha1(msg)
if type(msg_checksum) == bytes:
msg_checksum = msg_checksum.decode('ascii')
checksum_match = checksum == msg_checksum

len_match = len(msg) == msg_length
Expand Down Expand Up @@ -363,6 +366,7 @@ def runme(self):
except mysql.connector.Error as e:
if e.args[0] in [2006, 2013, 2055]: # server is killed
print("mysqld down, transaction %d" % self.xid)
print("mysqld down, transaction %d" % self.xid, file=self.log)
return
elif e.args[0] in [1213, 1205]: # deadlock or lock wait timeout, ignore
return
Expand Down Expand Up @@ -403,7 +407,7 @@ def runme(self):
server_pid = int(open(pid_file).read())
log = open('%s/main.log' % LG_TMP_DIR, 'a')

# print "kill_db_after = ",kill_db_after," num_records_before = ", \
# print( "kill_db_after = ",kill_db_after," num_records_before = ", \)
#num_records_before, " num_workers= ",num_workers, "num_xactions_per_worker =",\
#num_xactions_per_worker, "user = ",user, "host =", host,"port = ",port,\
#" db = ", db, " server_pid = ", server_pid
Expand Down
1 change: 1 addition & 0 deletions mysql-test/t/admission_control_multi_query.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import time
import sys
import MySQLdb
from MySQLdb.constants import *
import argparse
import random
import threading
Expand Down
2 changes: 1 addition & 1 deletion mysql-test/t/admission_control_multi_query.test
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ grant all on test.* to test_user@localhost;
use test_db;
create table t1 (a int primary key, b int) engine=InnoDB;

let $exec = python $MYSQL_TEST_DIR/t/admission_control_multi_query.py --user='test_user' --host=127.0.0.1 --port=$MASTER_MYPORT --database='test_db';
let $exec = /usr/bin/python3 $MYSQL_TEST_DIR/t/admission_control_multi_query.py --user='test_user' --host=127.0.0.1 --port=$MASTER_MYPORT --database='test_db';
exec $exec > $MYSQLTEST_VARDIR/tmp/admission_control_multi_query.output;

drop database test_db;
Expand Down
2 changes: 1 addition & 1 deletion mysql-test/t/admission_control_multi_query_weighted.test
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ grant all on test.* to test_user@localhost;
use test_db;
create table t1 (a int primary key, b int) engine=InnoDB;

let $exec = python $MYSQL_TEST_DIR/t/admission_control_multi_query.py --user='test_user' --host=127.0.0.1 --port=$MASTER_MYPORT --database='test_db' --weighted-queues;
let $exec = /usr/bin/python3 $MYSQL_TEST_DIR/t/admission_control_multi_query.py --user='test_user' --host=127.0.0.1 --port=$MASTER_MYPORT --database='test_db' --weighted-queues;
exec $exec > $MYSQLTEST_VARDIR/tmp/admission_control_multi_query.output;

drop database test_db;
Expand Down
2 changes: 1 addition & 1 deletion mysql-test/t/slocket_listen.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/python3
from socket import socket, AF_UNIX, SOCK_DGRAM
from select import select
from os import unlink, getcwd, stat
Expand Down

0 comments on commit 9d0dda0

Please sign in to comment.