db_crashtest preserves expected values file for failed crash tests (#7534)

Summary:
If crash test fails, don't delete the `expected_values_file` for later
debug. More details: https://github.com/facebook/rocksdb/issues/7530

Pull Request resolved: https://github.com/facebook/rocksdb/pull/7534

Test Plan: local host

Reviewed By: ajkr

Differential Revision: D24239655

Pulled By: jay-zhuang

fbshipit-source-id: 3566f91a30aae1e27d2f51d910cddd08edb7d4cf
main
Jay Zhuang 4 years ago committed by Facebook GitHub Bot
parent f548a2a03c
commit 9e03e4dd52
  1. 25
      tools/db_crashtest.py

@ -25,7 +25,6 @@ import argparse
# for txn:
# default_params < {blackbox,whitebox}_default_params < txn_params < args
expected_values_file = tempfile.NamedTemporaryFile()
default_params = {
"acquire_snapshot_one_in": 10000,
@ -59,7 +58,7 @@ default_params = {
"destroy_db_initially": 0,
"enable_pipelined_write": lambda: random.randint(0, 1),
"enable_compaction_filter": lambda: random.choice([0, 0, 0, 1]),
"expected_values_path": expected_values_file.name,
"expected_values_path": lambda: setup_expected_values_file(),
"flush_one_in": 1000000,
"file_checksum_impl": lambda: random.choice(["none", "crc32c", "xxh64", "big"]),
"get_live_files_one_in": 1000000,
@ -159,6 +158,24 @@ def get_dbname(test_name):
os.mkdir(dbname)
return dbname
expected_values_file = None
def setup_expected_values_file():
global expected_values_file
if expected_values_file is not None:
return expected_values_file
expected_file_name = "rocksdb_crashtest_" + "expected"
test_tmpdir = os.environ.get(_TEST_DIR_ENV_VAR)
if test_tmpdir is None or test_tmpdir == "":
expected_values_file = tempfile.NamedTemporaryFile(
prefix=expected_file_name, delete=False).name
else:
# if tmpdir is specified, store the expected_values_file in the same dir
expected_values_file = test_tmpdir + "/" + expected_file_name
if os.path.exists(expected_values_file):
os.remove(expected_values_file)
open(expected_values_file, 'a').close()
return expected_values_file
def is_direct_io_supported(dbname):
with tempfile.NamedTemporaryFile(dir=dbname) as f:
@ -618,6 +635,10 @@ def main():
blackbox_crash_main(args, unknown_args)
if args.test_type == 'whitebox':
whitebox_crash_main(args, unknown_args)
# Only delete the `expected_values_file` if test passes
if os.path.exists(expected_values_file):
os.remove(expected_values_file)
if __name__ == '__main__':
main()

Loading…
Cancel
Save