From 9c932816cfcce84a0770dd788445f1f2eb739e50 Mon Sep 17 00:00:00 2001 From: Aravind Ramesh <Aravind.Ramesh@wdc.com> Date: Tue, 30 Nov 2021 14:55:11 -0800 Subject: [PATCH] db_stress: db_stress segmentation fault (#9219) Summary: db_stress asserts/seg-faults with below command (on debug and release builds) ``` "rm -rf /tmp/rocksdbtest*; db_stress --ops_per_thread=1000 --reopen=5" ======================================= Error opening unique id file for append: IO error: No such file or directory: While open a file for appending: /tmp/rocksdbtest-0/dbstress/.unique_ids: No such file or directory Choosing random keys with no overwrite Creating 2621440 locks Starting continuous_verification_thread 2021/11/15-08:46:49 Initializing worker threads 2021/11/15-08:46:49 Starting database operations 2021/11/15-08:46:49 Reopening database for the 1th time WARNING: prefix_size is non-zero but memtablerep != prefix_hash DB path: [/tmp/rocksdbtest-0/dbstress] Segmentation fault ======================================= ``` StressTest() constructor deletes the directory "dbstress" because the option --destroy_db_initially is true by default in db_stress. This Seg fault happens on a new database, UniqueIdVerifier's constructor tries to read the ".unique_ids" file, if the file is not present, ReopenWritableFile() tries to create .unique_ids file, but fails as the directory db_stress is not available. The data_file_writer_ is set as an invalid(null) pointer and in subsequent calls (~UniqueIdVerifier() and UniqueIdVerifier::Verify()) it accesses this null pointer and crashes. This patch creates db_stress directory if it is missing, so the .unique_ids file is created. Signed-off-by: Aravind Ramesh <aravind.ramesh@wdc.com> Pull Request resolved: https://github.com/facebook/rocksdb/pull/9219 Reviewed By: ajkr Differential Revision: D32730151 Pulled By: pdillinger fbshipit-source-id: f47baba56b380d93c3ba5608904756e86bbf14f5 --- db_stress_tool/db_stress_listener.cc | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/db_stress_tool/db_stress_listener.cc b/db_stress_tool/db_stress_listener.cc index 9968f5465..290d49008 100644 --- a/db_stress_tool/db_stress_listener.cc +++ b/db_stress_tool/db_stress_listener.cc @@ -31,6 +31,13 @@ UniqueIdVerifier::UniqueIdVerifier(const std::string& db_name) FileSystem& fs = *FileSystem::Default(); IOOptions opts; + Status st = fs.CreateDirIfMissing(db_name, opts, nullptr); + if (!st.ok()) { + fprintf(stderr, "Failed to create directory %s: %s\n", + db_name.c_str(), st.ToString().c_str()); + exit(1); + } + { std::unique_ptr<FSSequentialFile> reader; Status s =