2013-04-05 20:44:59 +00:00
|
|
|
#! /usr/bin/env python
|
2013-03-13 06:20:14 +00:00
|
|
|
import os
|
2013-08-21 00:37:49 +00:00
|
|
|
import re
|
2013-03-13 06:20:14 +00:00
|
|
|
import sys
|
|
|
|
import time
|
2013-06-08 19:29:43 +00:00
|
|
|
import random
|
2013-03-13 06:20:14 +00:00
|
|
|
import getopt
|
|
|
|
import logging
|
2013-04-05 20:44:59 +00:00
|
|
|
import tempfile
|
2013-03-13 06:20:14 +00:00
|
|
|
import subprocess
|
2014-03-20 18:11:08 +00:00
|
|
|
import shutil
|
2013-03-13 06:20:14 +00:00
|
|
|
|
2013-08-21 00:37:49 +00:00
|
|
|
# This script runs and kills db_stress multiple times. It checks consistency
|
2014-03-20 18:11:08 +00:00
|
|
|
# in case of unsafe crashes in RocksDB.
|
2013-03-13 06:20:14 +00:00
|
|
|
|
|
|
|
def main(argv):
|
|
|
|
try:
|
|
|
|
opts, args = getopt.getopt(argv, "hd:t:i:o:b:")
|
|
|
|
except getopt.GetoptError:
|
2013-04-10 19:15:30 +00:00
|
|
|
print("db_crashtest.py -d <duration_test> -t <#threads> "
|
2013-08-21 00:37:49 +00:00
|
|
|
"-i <interval for one run> -o <ops_per_thread> "
|
|
|
|
"-b <write_buffer_size>\n")
|
2013-03-13 06:20:14 +00:00
|
|
|
sys.exit(2)
|
|
|
|
|
|
|
|
# default values, will be overridden by cmdline args
|
|
|
|
interval = 120 # time for one db_stress instance to run
|
|
|
|
duration = 6000 # total time for this script to test db_stress
|
|
|
|
threads = 32
|
2013-04-03 10:40:39 +00:00
|
|
|
# since we will be killing anyway, use large value for ops_per_thread
|
2013-06-08 19:29:43 +00:00
|
|
|
ops_per_thread = 100000000
|
2013-03-13 06:20:14 +00:00
|
|
|
write_buf_size = 4 * 1024 * 1024
|
|
|
|
|
|
|
|
for opt, arg in opts:
|
|
|
|
if opt == '-h':
|
2013-04-10 19:15:30 +00:00
|
|
|
print("db_crashtest.py -d <duration_test>"
|
|
|
|
" -t <#threads> -i <interval for one run>"
|
|
|
|
" -o <ops_per_thread> -b <write_buffer_size>\n")
|
2013-03-13 06:20:14 +00:00
|
|
|
sys.exit()
|
2013-08-21 00:37:49 +00:00
|
|
|
elif opt == "-d":
|
2013-03-13 06:20:14 +00:00
|
|
|
duration = int(arg)
|
2013-08-21 00:37:49 +00:00
|
|
|
elif opt == "-t":
|
2013-03-13 06:20:14 +00:00
|
|
|
threads = int(arg)
|
2013-08-21 00:37:49 +00:00
|
|
|
elif opt == "-i":
|
2013-03-13 06:20:14 +00:00
|
|
|
interval = int(arg)
|
2013-08-21 00:37:49 +00:00
|
|
|
elif opt == "-o":
|
2013-03-13 06:20:14 +00:00
|
|
|
ops_per_thread = int(arg)
|
2013-08-21 00:37:49 +00:00
|
|
|
elif opt == "-b":
|
2013-03-13 06:20:14 +00:00
|
|
|
write_buf_size = int(arg)
|
|
|
|
else:
|
2013-04-10 19:15:30 +00:00
|
|
|
print("db_crashtest.py -d <duration_test>"
|
|
|
|
" -t <#threads> -i <interval for one run>"
|
|
|
|
" -o <ops_per_thread> -b <write_buffer_size>\n")
|
2013-03-13 06:20:14 +00:00
|
|
|
sys.exit(2)
|
|
|
|
|
|
|
|
exit_time = time.time() + duration
|
|
|
|
|
2013-05-24 02:10:13 +00:00
|
|
|
print("Running blackbox-crash-test with \ninterval_between_crash="
|
2013-04-10 19:15:30 +00:00
|
|
|
+ str(interval) + "\ntotal-duration=" + str(duration)
|
|
|
|
+ "\nthreads=" + str(threads) + "\nops_per_thread="
|
|
|
|
+ str(ops_per_thread) + "\nwrite_buffer_size="
|
|
|
|
+ str(write_buf_size) + "\n")
|
|
|
|
|
2014-03-20 18:11:08 +00:00
|
|
|
dbname = tempfile.mkdtemp(prefix='rocksdb_crashtest_')
|
|
|
|
|
2013-03-13 06:20:14 +00:00
|
|
|
while time.time() < exit_time:
|
|
|
|
run_had_errors = False
|
|
|
|
killtime = time.time() + interval
|
2013-08-21 00:37:49 +00:00
|
|
|
|
|
|
|
cmd = re.sub('\s+', ' ', """
|
|
|
|
./db_stress
|
|
|
|
--test_batches_snapshots=1
|
|
|
|
--ops_per_thread=%s
|
|
|
|
--threads=%s
|
|
|
|
--write_buffer_size=%s
|
|
|
|
--destroy_db_initially=0
|
2014-03-04 01:10:30 +00:00
|
|
|
--reopen=20
|
2013-09-20 23:27:22 +00:00
|
|
|
--readpercent=45
|
2014-03-13 05:21:13 +00:00
|
|
|
--prefixpercent=5
|
|
|
|
--writepercent=35
|
2013-08-21 00:37:49 +00:00
|
|
|
--delpercent=5
|
2013-09-20 23:27:22 +00:00
|
|
|
--iterpercent=10
|
2013-08-21 00:37:49 +00:00
|
|
|
--db=%s
|
|
|
|
--max_key=100000000
|
|
|
|
--mmap_read=%s
|
|
|
|
--block_size=16384
|
|
|
|
--cache_size=1048576
|
|
|
|
--open_files=500000
|
|
|
|
--verify_checksum=1
|
2014-03-12 22:12:09 +00:00
|
|
|
--sync=0
|
2014-03-19 16:58:41 +00:00
|
|
|
--progress_reports=0
|
2013-08-21 00:37:49 +00:00
|
|
|
--disable_wal=0
|
2014-03-12 22:12:09 +00:00
|
|
|
--disable_data_sync=1
|
2013-08-21 00:37:49 +00:00
|
|
|
--target_file_size_base=2097152
|
|
|
|
--target_file_size_multiplier=2
|
|
|
|
--max_write_buffer_number=3
|
|
|
|
--max_background_compactions=20
|
|
|
|
--max_bytes_for_level_base=10485760
|
|
|
|
--filter_deletes=%s
|
2014-03-13 05:21:13 +00:00
|
|
|
--memtablerep=prefix_hash
|
|
|
|
--prefix_size=7
|
2014-10-27 19:11:16 +00:00
|
|
|
--set_options_one_in=10000
|
2013-08-21 00:37:49 +00:00
|
|
|
""" % (ops_per_thread,
|
|
|
|
threads,
|
|
|
|
write_buf_size,
|
2014-03-20 18:11:08 +00:00
|
|
|
dbname,
|
2013-08-21 00:37:49 +00:00
|
|
|
random.randint(0, 1),
|
|
|
|
random.randint(0, 1)))
|
|
|
|
|
|
|
|
child = subprocess.Popen([cmd],
|
2013-06-08 19:29:43 +00:00
|
|
|
stderr=subprocess.PIPE, shell=True)
|
2013-08-21 00:37:49 +00:00
|
|
|
print("Running db_stress with pid=%d: %s\n\n"
|
|
|
|
% (child.pid, cmd))
|
|
|
|
|
2014-03-11 20:44:33 +00:00
|
|
|
stop_early = False
|
2013-08-21 00:37:49 +00:00
|
|
|
while time.time() < killtime:
|
2014-03-11 20:44:33 +00:00
|
|
|
if child.poll() is not None:
|
|
|
|
print("WARNING: db_stress ended before kill: exitcode=%d\n"
|
|
|
|
% child.returncode)
|
|
|
|
stop_early = True
|
|
|
|
break
|
|
|
|
time.sleep(1)
|
2013-03-13 06:20:14 +00:00
|
|
|
|
2014-03-11 20:44:33 +00:00
|
|
|
if not stop_early:
|
|
|
|
if child.poll() is not None:
|
|
|
|
print("WARNING: db_stress ended before kill: exitcode=%d\n"
|
|
|
|
% child.returncode)
|
|
|
|
else:
|
|
|
|
child.kill()
|
|
|
|
print("KILLED %d\n" % child.pid)
|
|
|
|
time.sleep(1) # time to stabilize after a kill
|
2013-08-21 00:37:49 +00:00
|
|
|
|
|
|
|
while True:
|
|
|
|
line = child.stderr.readline().strip()
|
|
|
|
if line != '':
|
|
|
|
run_had_errors = True
|
|
|
|
print('***' + line + '^')
|
|
|
|
else:
|
2013-03-13 06:20:14 +00:00
|
|
|
break
|
|
|
|
|
2013-08-21 00:37:49 +00:00
|
|
|
if run_had_errors:
|
|
|
|
sys.exit(2)
|
|
|
|
|
|
|
|
time.sleep(1) # time to stabilize before the next run
|
2013-03-13 06:20:14 +00:00
|
|
|
|
2014-03-20 18:11:08 +00:00
|
|
|
# we need to clean up after ourselves -- only do this on test success
|
|
|
|
shutil.rmtree(dbname, True)
|
|
|
|
|
2013-03-13 06:20:14 +00:00
|
|
|
if __name__ == "__main__":
|
|
|
|
sys.exit(main(sys.argv[1:]))
|