From 8581a93a6bdfb86b4126bd45c188244cc1465e19 Mon Sep 17 00:00:00 2001 From: Maysam Yabandeh Date: Fri, 13 Jul 2018 17:18:39 -0700 Subject: [PATCH] Per-thread unique test db names (#4135) Summary: The patch makes sure that two parallel test threads will operate on different db paths. This enables using open source tools such as gtest-parallel to run the tests of a file in parallel. Example: ``` ~/gtest-parallel/gtest-parallel ./table_test``` Pull Request resolved: https://github.com/facebook/rocksdb/pull/4135 Differential Revision: D8846653 Pulled By: maysamyabandeh fbshipit-source-id: 799bad1abb260e3d346bcb680d2ae207a852ba84 --- db/column_family_test.cc | 2 +- db/compact_files_test.cc | 2 +- db/compaction_job_stats_test.cc | 2 +- db/compaction_job_test.cc | 2 +- db/comparator_db_test.cc | 2 +- db/corruption_test.cc | 2 +- db/cuckoo_table_db_test.cc | 2 +- db/db_basic_test.cc | 2 +- db/db_test.cc | 4 +-- db/db_test2.cc | 2 +- db/db_test_util.cc | 2 +- db/deletefile_test.cc | 2 +- db/fault_injection_test.cc | 10 +++--- db/flush_job_test.cc | 2 +- db/forward_iterator_bench.cc | 2 +- db/manual_compaction_test.cc | 2 +- db/memtable_list_test.cc | 2 +- db/merge_test.cc | 7 ++-- db/obsolete_files_test.cc | 2 +- db/options_file_test.cc | 2 +- db/perf_context_test.cc | 2 +- db/plain_table_db_test.cc | 2 +- db/prefix_test.cc | 2 +- db/version_set_test.cc | 2 +- db/wal_manager_test.cc | 2 +- db/write_callback_test.cc | 2 +- env/env_basic_test.cc | 2 +- env/env_test.cc | 32 +++++++++---------- table/cuckoo_table_builder_test.cc | 22 ++++++------- table/cuckoo_table_reader_test.cc | 14 ++++---- table/table_reader_bench.cc | 6 ++-- table/table_test.cc | 6 ++-- tools/db_bench_tool.cc | 3 +- tools/db_bench_tool_test.cc | 2 +- tools/reduce_levels_test.cc | 2 +- util/auto_roll_logger_test.cc | 7 ++-- util/delete_scheduler_test.cc | 6 ++-- util/filelock_test.cc | 5 +-- util/log_write_bench.cc | 2 +- util/slice_transform_test.cc | 2 +- util/testharness.cc | 14 ++++++++ util/testharness.h | 5 +++ utilities/backupable/backupable_db_test.cc | 4 +-- utilities/blob_db/blob_db_test.cc | 2 +- .../cassandra/cassandra_functional_test.cc | 2 +- utilities/checkpoint/checkpoint_test.cc | 8 ++--- utilities/date_tiered/date_tiered_test.cc | 2 +- utilities/document/document_db_test.cc | 2 +- utilities/geodb/geodb_test.cc | 3 +- utilities/lua/rocks_lua_test.cc | 20 ++++++------ utilities/memory/memory_test.cc | 2 +- .../string_append/stringappend_test.cc | 2 +- utilities/options/options_util_test.cc | 2 +- .../persistent_cache/persistent_cache_test.cc | 2 +- utilities/redis/redis_lists_test.cc | 2 +- utilities/simulator_cache/sim_cache_test.cc | 2 +- utilities/spatialdb/spatial_db_test.cc | 2 +- .../optimistic_transaction_test.cc | 2 +- utilities/transactions/transaction_test.h | 2 +- .../write_prepared_transaction_test.cc | 2 +- utilities/ttl/ttl_test.cc | 2 +- .../write_batch_with_index_test.cc | 10 +++--- 62 files changed, 145 insertions(+), 127 deletions(-) diff --git a/db/column_family_test.cc b/db/column_family_test.cc index 528ddae93..5c2a068b3 100644 --- a/db/column_family_test.cc +++ b/db/column_family_test.cc @@ -61,7 +61,7 @@ class ColumnFamilyTestBase : public testing::Test { public: ColumnFamilyTestBase(uint32_t format) : rnd_(139), format_(format) { env_ = new EnvCounter(Env::Default()); - dbname_ = test::TmpDir() + "/column_family_test"; + dbname_ = test::PerThreadDBPath("column_family_test"); db_options_.create_if_missing = true; db_options_.fail_if_options_file_error = true; db_options_.env = env_; diff --git a/db/compact_files_test.cc b/db/compact_files_test.cc index b594abc90..499d88b3e 100644 --- a/db/compact_files_test.cc +++ b/db/compact_files_test.cc @@ -24,7 +24,7 @@ class CompactFilesTest : public testing::Test { public: CompactFilesTest() { env_ = Env::Default(); - db_name_ = test::TmpDir(env_) + "/compact_files_test"; + db_name_ = test::PerThreadDBPath("compact_files_test"); } std::string db_name_; diff --git a/db/compaction_job_stats_test.cc b/db/compaction_job_stats_test.cc index 056c381a9..0f607a198 100644 --- a/db/compaction_job_stats_test.cc +++ b/db/compaction_job_stats_test.cc @@ -98,7 +98,7 @@ class CompactionJobStatsTest : public testing::Test, CompactionJobStatsTest() : env_(Env::Default()) { env_->SetBackgroundThreads(1, Env::LOW); env_->SetBackgroundThreads(1, Env::HIGH); - dbname_ = test::TmpDir(env_) + "/compaction_job_stats_test"; + dbname_ = test::PerThreadDBPath("compaction_job_stats_test"); alternative_wal_dir_ = dbname_ + "/wal"; Options options; options.create_if_missing = true; diff --git a/db/compaction_job_test.cc b/db/compaction_job_test.cc index 2246d489f..e32b5a078 100644 --- a/db/compaction_job_test.cc +++ b/db/compaction_job_test.cc @@ -68,7 +68,7 @@ class CompactionJobTest : public testing::Test { public: CompactionJobTest() : env_(Env::Default()), - dbname_(test::TmpDir() + "/compaction_job_test"), + dbname_(test::PerThreadDBPath("compaction_job_test")), db_options_(), mutable_cf_options_(cf_options_), table_cache_(NewLRUCache(50000, 16)), diff --git a/db/comparator_db_test.cc b/db/comparator_db_test.cc index 226451464..e09fb045e 100644 --- a/db/comparator_db_test.cc +++ b/db/comparator_db_test.cc @@ -264,7 +264,7 @@ class ComparatorDBTest public: ComparatorDBTest() : env_(Env::Default()), db_(nullptr) { comparator = BytewiseComparator(); - dbname_ = test::TmpDir() + "/comparator_db_test"; + dbname_ = test::PerThreadDBPath("comparator_db_test"); BlockBasedTableOptions toptions; toptions.format_version = GetParam(); last_options_.table_factory.reset( diff --git a/db/corruption_test.cc b/db/corruption_test.cc index dbc09e753..9488c07fe 100644 --- a/db/corruption_test.cc +++ b/db/corruption_test.cc @@ -48,7 +48,7 @@ class CorruptionTest : public testing::Test { tiny_cache_ = NewLRUCache(100, 4); options_.wal_recovery_mode = WALRecoveryMode::kTolerateCorruptedTailRecords; options_.env = &env_; - dbname_ = test::TmpDir() + "/corruption_test"; + dbname_ = test::PerThreadDBPath("corruption_test"); DestroyDB(dbname_, options_); db_ = nullptr; diff --git a/db/cuckoo_table_db_test.cc b/db/cuckoo_table_db_test.cc index fe1575890..3fafa6adf 100644 --- a/db/cuckoo_table_db_test.cc +++ b/db/cuckoo_table_db_test.cc @@ -25,7 +25,7 @@ class CuckooTableDBTest : public testing::Test { public: CuckooTableDBTest() : env_(Env::Default()) { - dbname_ = test::TmpDir() + "/cuckoo_table_db_test"; + dbname_ = test::PerThreadDBPath("cuckoo_table_db_test"); EXPECT_OK(DestroyDB(dbname_, Options())); db_ = nullptr; Reopen(); diff --git a/db/db_basic_test.cc b/db/db_basic_test.cc index 31742d0bd..dc732a710 100644 --- a/db/db_basic_test.cc +++ b/db/db_basic_test.cc @@ -892,7 +892,7 @@ class TestEnv : public EnvWrapper { TEST_F(DBBasicTest, DBClose) { Options options = GetDefaultOptions(); - std::string dbname = test::TmpDir(env_) + "/db_close_test"; + std::string dbname = test::PerThreadDBPath("db_close_test"); ASSERT_OK(DestroyDB(dbname, options)); DB* db = nullptr; diff --git a/db/db_test.cc b/db/db_test.cc index 346010bcd..f565fa437 100644 --- a/db/db_test.cc +++ b/db/db_test.cc @@ -1682,7 +1682,7 @@ TEST_F(DBTest, CustomComparator) { TEST_F(DBTest, DBOpen_Options) { Options options = CurrentOptions(); - std::string dbname = test::TmpDir(env_) + "/db_options_test"; + std::string dbname = test::PerThreadDBPath("db_options_test"); ASSERT_OK(DestroyDB(dbname, options)); // Does not exist, and create_if_missing == false: error @@ -1740,7 +1740,7 @@ TEST_F(DBTest, DBOpen_Change_NumLevels) { } TEST_F(DBTest, DestroyDBMetaDatabase) { - std::string dbname = test::TmpDir(env_) + "/db_meta"; + std::string dbname = test::PerThreadDBPath("db_meta"); ASSERT_OK(env_->CreateDirIfMissing(dbname)); std::string metadbname = MetaDatabaseName(dbname, 0); ASSERT_OK(env_->CreateDirIfMissing(metadbname)); diff --git a/db/db_test2.cc b/db/db_test2.cc index a698caaa4..3cb453359 100644 --- a/db/db_test2.cc +++ b/db/db_test2.cc @@ -354,7 +354,7 @@ INSTANTIATE_TEST_CASE_P(DBTestSharedWriteBufferAcrossCFs, std::make_tuple(false, true))); TEST_F(DBTest2, SharedWriteBufferLimitAcrossDB) { - std::string dbname2 = test::TmpDir(env_) + "/db_shared_wb_db2"; + std::string dbname2 = test::PerThreadDBPath("db_shared_wb_db2"); Options options = CurrentOptions(); options.arena_block_size = 4096; // Avoid undeterministic value by malloc_usable_size(); diff --git a/db/db_test_util.cc b/db/db_test_util.cc index d3a87cb0c..5867713ae 100644 --- a/db/db_test_util.cc +++ b/db/db_test_util.cc @@ -63,7 +63,7 @@ DBTestBase::DBTestBase(const std::string path) option_config_(kDefault) { env_->SetBackgroundThreads(1, Env::LOW); env_->SetBackgroundThreads(1, Env::HIGH); - dbname_ = test::TmpDir(env_) + path; + dbname_ = test::PerThreadDBPath(env_, path); alternative_wal_dir_ = dbname_ + "/wal"; alternative_db_log_dir_ = dbname_ + "/db_log_dir"; auto options = CurrentOptions(); diff --git a/db/deletefile_test.cc b/db/deletefile_test.cc index 5b150205a..8583535fa 100644 --- a/db/deletefile_test.cc +++ b/db/deletefile_test.cc @@ -45,7 +45,7 @@ class DeleteFileTest : public testing::Test { options_.max_bytes_for_level_base = 1024*1024*1000; options_.WAL_ttl_seconds = 300; // Used to test log files options_.WAL_size_limit_MB = 1024; // Used to test log files - dbname_ = test::TmpDir() + "/deletefile_test"; + dbname_ = test::PerThreadDBPath("deletefile_test"); options_.wal_dir = dbname_ + "/wal_files"; // clean up all the files that might have been there before diff --git a/db/fault_injection_test.cc b/db/fault_injection_test.cc index 1aba2c0a3..a6328e970 100644 --- a/db/fault_injection_test.cc +++ b/db/fault_injection_test.cc @@ -107,18 +107,18 @@ class FaultInjectionTest Options options; switch (option_config_) { case kWalDir: - options.wal_dir = test::TmpDir(env_) + "/fault_test_wal"; + options.wal_dir = test::PerThreadDBPath(env_, "fault_test_wal"); break; case kDifferentDataDir: - options.db_paths.emplace_back(test::TmpDir(env_) + "/fault_test_data", - 1000000U); + options.db_paths.emplace_back( + test::PerThreadDBPath(env_, "fault_test_data"), 1000000U); break; case kSyncWal: sync_use_wal_ = true; sync_use_compact_ = false; break; case kWalDirSyncWal: - options.wal_dir = test::TmpDir(env_) + "/fault_test_wal"; + options.wal_dir = test::PerThreadDBPath(env_, "/fault_test_wal"); sync_use_wal_ = true; sync_use_compact_ = false; break; @@ -158,7 +158,7 @@ class FaultInjectionTest table_options.block_cache = tiny_cache_; options_.table_factory.reset(NewBlockBasedTableFactory(table_options)); - dbname_ = test::TmpDir() + "/fault_test"; + dbname_ = test::PerThreadDBPath("fault_test"); EXPECT_OK(DestroyDB(dbname_, options_)); diff --git a/db/flush_job_test.cc b/db/flush_job_test.cc index 4e94001ec..5535fc46b 100644 --- a/db/flush_job_test.cc +++ b/db/flush_job_test.cc @@ -27,7 +27,7 @@ class FlushJobTest : public testing::Test { public: FlushJobTest() : env_(Env::Default()), - dbname_(test::TmpDir() + "/flush_job_test"), + dbname_(test::PerThreadDBPath("flush_job_test")), options_(), db_options_(options_), table_cache_(NewLRUCache(50000, 16)), diff --git a/db/forward_iterator_bench.cc b/db/forward_iterator_bench.cc index e5af43628..113ded94b 100644 --- a/db/forward_iterator_bench.cc +++ b/db/forward_iterator_bench.cc @@ -323,7 +323,7 @@ int main(int argc, char** argv) { std::mt19937 rng{std::random_device()()}; rocksdb::Status status; - std::string path = rocksdb::test::TmpDir() + "/forward_iterator_test"; + std::string path = rocksdb::test::PerThreadDBPath("forward_iterator_test"); fprintf(stderr, "db path is %s\n", path.c_str()); rocksdb::Options options; options.create_if_missing = true; diff --git a/db/manual_compaction_test.cc b/db/manual_compaction_test.cc index 3c342c454..403e2a347 100644 --- a/db/manual_compaction_test.cc +++ b/db/manual_compaction_test.cc @@ -40,7 +40,7 @@ class ManualCompactionTest : public testing::Test { public: ManualCompactionTest() { // Get rid of any state from an old run. - dbname_ = rocksdb::test::TmpDir() + "/rocksdb_cbug_test"; + dbname_ = rocksdb::test::PerThreadDBPath("rocksdb_cbug_test"); DestroyDB(dbname_, rocksdb::Options()); } diff --git a/db/memtable_list_test.cc b/db/memtable_list_test.cc index a565eba3c..009a71886 100644 --- a/db/memtable_list_test.cc +++ b/db/memtable_list_test.cc @@ -27,7 +27,7 @@ class MemTableListTest : public testing::Test { Options options; MemTableListTest() : db(nullptr) { - dbname = test::TmpDir() + "/memtable_list_test"; + dbname = test::PerThreadDBPath("memtable_list_test"); } // Create a test db if not yet created diff --git a/db/merge_test.cc b/db/merge_test.cc index e58e0b318..15f6f5125 100644 --- a/db/merge_test.cc +++ b/db/merge_test.cc @@ -484,20 +484,19 @@ void runTest(const std::string& dbname, const bool use_ttl = false) { */ } - TEST_F(MergeTest, MergeDbTest) { - runTest(test::TmpDir() + "/merge_testdb"); + runTest(test::PerThreadDBPath("merge_testdb")); } #ifndef ROCKSDB_LITE TEST_F(MergeTest, MergeDbTtlTest) { - runTest(test::TmpDir() + "/merge_testdbttl", true); // Run test on TTL database + runTest(test::PerThreadDBPath("merge_testdbttl"), + true); // Run test on TTL database } #endif // !ROCKSDB_LITE } // namespace rocksdb - int main(int argc, char** argv) { rocksdb::use_compression = false; if (argc > 1) { diff --git a/db/obsolete_files_test.cc b/db/obsolete_files_test.cc index bc0f05b59..81e519bda 100644 --- a/db/obsolete_files_test.cc +++ b/db/obsolete_files_test.cc @@ -53,7 +53,7 @@ class ObsoleteFilesTest : public testing::Test { options_.max_bytes_for_level_base = 1024*1024*1000; options_.WAL_ttl_seconds = 300; // Used to test log files options_.WAL_size_limit_MB = 1024; // Used to test log files - dbname_ = test::TmpDir() + "/obsolete_files_test"; + dbname_ = test::PerThreadDBPath("obsolete_files_test"); options_.wal_dir = dbname_ + "/wal_files"; // clean up all the files that might have been there before diff --git a/db/options_file_test.cc b/db/options_file_test.cc index 885698256..0a9a34ff0 100644 --- a/db/options_file_test.cc +++ b/db/options_file_test.cc @@ -15,7 +15,7 @@ namespace rocksdb { class OptionsFileTest : public testing::Test { public: - OptionsFileTest() : dbname_(test::TmpDir() + "/options_file_test") {} + OptionsFileTest() : dbname_(test::PerThreadDBPath("options_file_test")) {} std::string dbname_; }; diff --git a/db/perf_context_test.cc b/db/perf_context_test.cc index d8ee80a79..c6b712cd8 100644 --- a/db/perf_context_test.cc +++ b/db/perf_context_test.cc @@ -30,7 +30,7 @@ int FLAGS_min_write_buffer_number_to_merge = 7; bool FLAGS_verbose = false; // Path to the database on file system -const std::string kDbName = rocksdb::test::TmpDir() + "/perf_context_test"; +const std::string kDbName = rocksdb::test::PerThreadDBPath("perf_context_test"); namespace rocksdb { diff --git a/db/plain_table_db_test.cc b/db/plain_table_db_test.cc index c39c247b8..dffd77ddc 100644 --- a/db/plain_table_db_test.cc +++ b/db/plain_table_db_test.cc @@ -115,7 +115,7 @@ class PlainTableDBTest : public testing::Test, void SetUp() override { mmap_mode_ = GetParam(); - dbname_ = test::TmpDir() + "/plain_table_db_test"; + dbname_ = test::PerThreadDBPath("plain_table_db_test"); EXPECT_OK(DestroyDB(dbname_, Options())); db_ = nullptr; Reopen(); diff --git a/db/prefix_test.cc b/db/prefix_test.cc index eeecdfa02..fcd3ca252 100644 --- a/db/prefix_test.cc +++ b/db/prefix_test.cc @@ -53,7 +53,7 @@ DEFINE_int32(value_size, 40, ""); DEFINE_bool(enable_print, false, "Print options generated to console."); // Path to the database on file system -const std::string kDbName = rocksdb::test::TmpDir() + "/prefix_test"; +const std::string kDbName = rocksdb::test::PerThreadDBPath("prefix_test"); namespace rocksdb { diff --git a/db/version_set_test.cc b/db/version_set_test.cc index 996de0dd6..5ce923287 100644 --- a/db/version_set_test.cc +++ b/db/version_set_test.cc @@ -458,7 +458,7 @@ class ManifestWriterTest : public testing::Test { public: ManifestWriterTest() : env_(Env::Default()), - dbname_(test::TmpDir() + "/version_set_test"), + dbname_(test::PerThreadDBPath("version_set_test")), db_options_(), mutable_cf_options_(cf_options_), table_cache_(NewLRUCache(50000, 16)), diff --git a/db/wal_manager_test.cc b/db/wal_manager_test.cc index ced28b87a..3bcc19888 100644 --- a/db/wal_manager_test.cc +++ b/db/wal_manager_test.cc @@ -32,7 +32,7 @@ class WalManagerTest : public testing::Test { public: WalManagerTest() : env_(new MockEnv(Env::Default())), - dbname_(test::TmpDir() + "/wal_manager_test"), + dbname_(test::PerThreadDBPath("wal_manager_test")), db_options_(), table_cache_(NewLRUCache(50000, 16)), write_buffer_manager_(db_options_.db_write_buffer_size), diff --git a/db/write_callback_test.cc b/db/write_callback_test.cc index 1909b8e39..07b14c29d 100644 --- a/db/write_callback_test.cc +++ b/db/write_callback_test.cc @@ -29,7 +29,7 @@ class WriteCallbackTest : public testing::Test { string dbname; WriteCallbackTest() { - dbname = test::TmpDir() + "/write_callback_testdb"; + dbname = test::PerThreadDBPath("write_callback_testdb"); } }; diff --git a/env/env_basic_test.cc b/env/env_basic_test.cc index 254c71fad..e05f61aa6 100644 --- a/env/env_basic_test.cc +++ b/env/env_basic_test.cc @@ -57,7 +57,7 @@ class EnvBasicTestWithParam : public testing::Test, std::string test_dir_; EnvBasicTestWithParam() : env_(GetParam()) { - test_dir_ = test::TmpDir(env_) + "/env_basic_test"; + test_dir_ = test::PerThreadDBPath(env_, "env_basic_test"); } void SetUp() { diff --git a/env/env_test.cc b/env/env_test.cc index 69807a81b..eda6b9d5d 100644 --- a/env/env_test.cc +++ b/env/env_test.cc @@ -156,7 +156,7 @@ TEST_F(EnvPosixTest, AreFilesSame) { const EnvOptions soptions; auto* env = Env::Default(); - std::string same_file_name = test::TmpDir(env) + "/same_file"; + std::string same_file_name = test::PerThreadDBPath(env, "same_file"); std::string same_file_link_name = same_file_name + "_link"; std::unique_ptr same_file; @@ -178,8 +178,9 @@ TEST_F(EnvPosixTest, DISABLED_FilePermission) { // Only works for Linux environment if (env_ == Env::Default()) { EnvOptions soptions; - std::vector fileNames { - test::TmpDir(env_) + "/testfile", test::TmpDir(env_) + "/testfile1"}; + std::vector fileNames{ + test::PerThreadDBPath(env_, "testfile"), + test::PerThreadDBPath(env_, "testfile1")}; unique_ptr wfile; ASSERT_OK(env_->NewWritableFile(fileNames[0], &wfile, soptions)); ASSERT_OK(env_->NewWritableFile(fileNames[1], &wfile, soptions)); @@ -214,7 +215,7 @@ TEST_F(EnvPosixTest, DISABLED_FilePermission) { TEST_F(EnvPosixTest, MemoryMappedFileBuffer) { const int kFileBytes = 1 << 15; // 32 KB std::string expected_data; - std::string fname = test::TmpDir(env_) + "/" + "testfile"; + std::string fname = test::PerThreadDBPath(env_, "testfile"); { unique_ptr wfile; const EnvOptions soptions; @@ -1067,7 +1068,7 @@ TEST_P(EnvPosixTestWithParam, InvalidateCache) { rocksdb::SyncPoint::GetInstance()->EnableProcessing(); EnvOptions soptions; soptions.use_direct_reads = soptions.use_direct_writes = direct_io_; - std::string fname = test::TmpDir(env_) + "/" + "testfile"; + std::string fname = test::PerThreadDBPath(env_, "testfile"); const size_t kSectorSize = 512; auto data = NewAligned(kSectorSize, 0); @@ -1250,10 +1251,10 @@ TEST_P(EnvPosixTestWithParam, LogBufferMaxSizeTest) { TEST_P(EnvPosixTestWithParam, Preallocation) { rocksdb::SyncPoint::GetInstance()->EnableProcessing(); - const std::string src = test::TmpDir(env_) + "/" + "testfile"; - unique_ptr srcfile; - EnvOptions soptions; - soptions.use_direct_reads = soptions.use_direct_writes = direct_io_; + const std::string src = test::PerThreadDBPath(env_, "testfile"); + unique_ptr srcfile; + EnvOptions soptions; + soptions.use_direct_reads = soptions.use_direct_writes = direct_io_; #if !defined(OS_MACOSX) && !defined(OS_WIN) && !defined(OS_SOLARIS) && !defined(OS_AIX) && !defined(OS_OPENBSD) && !defined(OS_FREEBSD) if (soptions.use_direct_writes) { rocksdb::SyncPoint::GetInstance()->SetCallBack( @@ -1312,9 +1313,8 @@ TEST_P(EnvPosixTestWithParam, ConsistentChildrenAttributes) { std::string data; for (int i = 0; i < kNumChildren; ++i) { - std::ostringstream oss; - oss << test::TmpDir(env_) << "/testfile_" << i; - const std::string path = oss.str(); + const std::string path = + test::TmpDir(env_) + "/" + "testfile_" + std::to_string(i); unique_ptr file; #if !defined(OS_MACOSX) && !defined(OS_WIN) && !defined(OS_SOLARIS) && !defined(OS_AIX) && !defined(OS_OPENBSD) && !defined(OS_FREEBSD) if (soptions.use_direct_writes) { @@ -1335,9 +1335,7 @@ TEST_P(EnvPosixTestWithParam, ConsistentChildrenAttributes) { std::vector file_attrs; ASSERT_OK(env_->GetChildrenFileAttributes(test::TmpDir(env_), &file_attrs)); for (int i = 0; i < kNumChildren; ++i) { - std::ostringstream oss; - oss << "testfile_" << i; - const std::string name = oss.str(); + const std::string name = "testfile_" + std::to_string(i); const std::string path = test::TmpDir(env_) + "/" + name; auto file_attrs_iter = std::find_if( @@ -1438,7 +1436,7 @@ TEST_P(EnvPosixTestWithParam, WritableFileWrapper) { } TEST_P(EnvPosixTestWithParam, PosixRandomRWFile) { - const std::string path = test::TmpDir(env_) + "/random_rw_file"; + const std::string path = test::PerThreadDBPath(env_, "random_rw_file"); env_->DeleteFile(path); @@ -1566,7 +1564,7 @@ class RandomRWFileWithMirrorString { }; TEST_P(EnvPosixTestWithParam, PosixRandomRWFileRandomized) { - const std::string path = test::TmpDir(env_) + "/random_rw_file_rand"; + const std::string path = test::PerThreadDBPath(env_, "random_rw_file_rand"); env_->DeleteFile(path); unique_ptr file; diff --git a/table/cuckoo_table_builder_test.cc b/table/cuckoo_table_builder_test.cc index 6c8dff0a7..0d24da719 100644 --- a/table/cuckoo_table_builder_test.cc +++ b/table/cuckoo_table_builder_test.cc @@ -153,7 +153,7 @@ class CuckooBuilderTest : public testing::Test { TEST_F(CuckooBuilderTest, SuccessWithEmptyFile) { unique_ptr writable_file; - fname = test::TmpDir() + "/EmptyFile"; + fname = test::PerThreadDBPath("EmptyFile"); ASSERT_OK(env_->NewWritableFile(fname, &writable_file, env_options_)); unique_ptr file_writer( new WritableFileWriter(std::move(writable_file), EnvOptions())); @@ -189,7 +189,7 @@ TEST_F(CuckooBuilderTest, WriteSuccessNoCollisionFullKey) { uint64_t expected_table_size = GetExpectedTableSize(keys.size()); unique_ptr writable_file; - fname = test::TmpDir() + "/NoCollisionFullKey"; + fname = test::PerThreadDBPath("NoCollisionFullKey"); ASSERT_OK(env_->NewWritableFile(fname, &writable_file, env_options_)); unique_ptr file_writer( new WritableFileWriter(std::move(writable_file), EnvOptions())); @@ -237,7 +237,7 @@ TEST_F(CuckooBuilderTest, WriteSuccessWithCollisionFullKey) { uint64_t expected_table_size = GetExpectedTableSize(keys.size()); unique_ptr writable_file; - fname = test::TmpDir() + "/WithCollisionFullKey"; + fname = test::PerThreadDBPath("WithCollisionFullKey"); ASSERT_OK(env_->NewWritableFile(fname, &writable_file, env_options_)); unique_ptr file_writer( new WritableFileWriter(std::move(writable_file), EnvOptions())); @@ -286,7 +286,7 @@ TEST_F(CuckooBuilderTest, WriteSuccessWithCollisionAndCuckooBlock) { unique_ptr writable_file; uint32_t cuckoo_block_size = 2; - fname = test::TmpDir() + "/WithCollisionFullKey2"; + fname = test::PerThreadDBPath("WithCollisionFullKey2"); ASSERT_OK(env_->NewWritableFile(fname, &writable_file, env_options_)); unique_ptr file_writer( new WritableFileWriter(std::move(writable_file), EnvOptions())); @@ -339,7 +339,7 @@ TEST_F(CuckooBuilderTest, WithCollisionPathFullKey) { uint64_t expected_table_size = GetExpectedTableSize(keys.size()); unique_ptr writable_file; - fname = test::TmpDir() + "/WithCollisionPathFullKey"; + fname = test::PerThreadDBPath("WithCollisionPathFullKey"); ASSERT_OK(env_->NewWritableFile(fname, &writable_file, env_options_)); unique_ptr file_writer( new WritableFileWriter(std::move(writable_file), EnvOptions())); @@ -389,7 +389,7 @@ TEST_F(CuckooBuilderTest, WithCollisionPathFullKeyAndCuckooBlock) { uint64_t expected_table_size = GetExpectedTableSize(keys.size()); unique_ptr writable_file; - fname = test::TmpDir() + "/WithCollisionPathFullKeyAndCuckooBlock"; + fname = test::PerThreadDBPath("WithCollisionPathFullKeyAndCuckooBlock"); ASSERT_OK(env_->NewWritableFile(fname, &writable_file, env_options_)); unique_ptr file_writer( new WritableFileWriter(std::move(writable_file), EnvOptions())); @@ -432,7 +432,7 @@ TEST_F(CuckooBuilderTest, WriteSuccessNoCollisionUserKey) { uint64_t expected_table_size = GetExpectedTableSize(user_keys.size()); unique_ptr writable_file; - fname = test::TmpDir() + "/NoCollisionUserKey"; + fname = test::PerThreadDBPath("NoCollisionUserKey"); ASSERT_OK(env_->NewWritableFile(fname, &writable_file, env_options_)); unique_ptr file_writer( new WritableFileWriter(std::move(writable_file), EnvOptions())); @@ -476,7 +476,7 @@ TEST_F(CuckooBuilderTest, WriteSuccessWithCollisionUserKey) { uint64_t expected_table_size = GetExpectedTableSize(user_keys.size()); unique_ptr writable_file; - fname = test::TmpDir() + "/WithCollisionUserKey"; + fname = test::PerThreadDBPath("WithCollisionUserKey"); ASSERT_OK(env_->NewWritableFile(fname, &writable_file, env_options_)); unique_ptr file_writer( new WritableFileWriter(std::move(writable_file), EnvOptions())); @@ -522,7 +522,7 @@ TEST_F(CuckooBuilderTest, WithCollisionPathUserKey) { uint64_t expected_table_size = GetExpectedTableSize(user_keys.size()); unique_ptr writable_file; - fname = test::TmpDir() + "/WithCollisionPathUserKey"; + fname = test::PerThreadDBPath("WithCollisionPathUserKey"); ASSERT_OK(env_->NewWritableFile(fname, &writable_file, env_options_)); unique_ptr file_writer( new WritableFileWriter(std::move(writable_file), EnvOptions())); @@ -567,7 +567,7 @@ TEST_F(CuckooBuilderTest, FailWhenCollisionPathTooLong) { hash_map = std::move(hm); unique_ptr writable_file; - fname = test::TmpDir() + "/WithCollisionPathUserKey"; + fname = test::PerThreadDBPath("WithCollisionPathUserKey"); ASSERT_OK(env_->NewWritableFile(fname, &writable_file, env_options_)); unique_ptr file_writer( new WritableFileWriter(std::move(writable_file), EnvOptions())); @@ -595,7 +595,7 @@ TEST_F(CuckooBuilderTest, FailWhenSameKeyInserted) { std::string user_key = "repeatedkey"; unique_ptr writable_file; - fname = test::TmpDir() + "/FailWhenSameKeyInserted"; + fname = test::PerThreadDBPath("FailWhenSameKeyInserted"); ASSERT_OK(env_->NewWritableFile(fname, &writable_file, env_options_)); unique_ptr file_writer( new WritableFileWriter(std::move(writable_file), EnvOptions())); diff --git a/table/cuckoo_table_reader_test.cc b/table/cuckoo_table_reader_test.cc index 65c93d196..3aeca5e13 100644 --- a/table/cuckoo_table_reader_test.cc +++ b/table/cuckoo_table_reader_test.cc @@ -215,7 +215,7 @@ class CuckooReaderTest : public testing::Test { TEST_F(CuckooReaderTest, WhenKeyExists) { SetUp(kNumHashFunc); - fname = test::TmpDir() + "/CuckooReader_WhenKeyExists"; + fname = test::PerThreadDBPath("CuckooReader_WhenKeyExists"); for (uint64_t i = 0; i < num_items; i++) { user_keys[i] = "key" + NumToStr(i); ParsedInternalKey ikey(user_keys[i], i + 1000, kTypeValue); @@ -242,7 +242,7 @@ TEST_F(CuckooReaderTest, WhenKeyExists) { TEST_F(CuckooReaderTest, WhenKeyExistsWithUint64Comparator) { SetUp(kNumHashFunc); - fname = test::TmpDir() + "/CuckooReaderUint64_WhenKeyExists"; + fname = test::PerThreadDBPath("CuckooReaderUint64_WhenKeyExists"); for (uint64_t i = 0; i < num_items; i++) { user_keys[i].resize(8); memcpy(&user_keys[i][0], static_cast(&i), 8); @@ -270,7 +270,7 @@ TEST_F(CuckooReaderTest, WhenKeyExistsWithUint64Comparator) { TEST_F(CuckooReaderTest, CheckIterator) { SetUp(2*kNumHashFunc); - fname = test::TmpDir() + "/CuckooReader_CheckIterator"; + fname = test::PerThreadDBPath("CuckooReader_CheckIterator"); for (uint64_t i = 0; i < num_items; i++) { user_keys[i] = "key" + NumToStr(i); ParsedInternalKey ikey(user_keys[i], 1000, kTypeValue); @@ -289,7 +289,7 @@ TEST_F(CuckooReaderTest, CheckIterator) { TEST_F(CuckooReaderTest, CheckIteratorUint64) { SetUp(2*kNumHashFunc); - fname = test::TmpDir() + "/CuckooReader_CheckIterator"; + fname = test::PerThreadDBPath("CuckooReader_CheckIterator"); for (uint64_t i = 0; i < num_items; i++) { user_keys[i].resize(8); memcpy(&user_keys[i][0], static_cast(&i), 8); @@ -310,7 +310,7 @@ TEST_F(CuckooReaderTest, CheckIteratorUint64) { TEST_F(CuckooReaderTest, WhenKeyNotFound) { // Add keys with colliding hash values. SetUp(kNumHashFunc); - fname = test::TmpDir() + "/CuckooReader_WhenKeyNotFound"; + fname = test::PerThreadDBPath("CuckooReader_WhenKeyNotFound"); for (uint64_t i = 0; i < num_items; i++) { user_keys[i] = "key" + NumToStr(i); ParsedInternalKey ikey(user_keys[i], i + 1000, kTypeValue); @@ -395,8 +395,8 @@ std::string GetFileName(uint64_t num) { if (FLAGS_file_dir.empty()) { FLAGS_file_dir = test::TmpDir(); } - return FLAGS_file_dir + "/cuckoo_read_benchmark" + - ToString(num/1000000) + "Mkeys"; + return test::PerThreadDBPath(FLAGS_file_dir, "cuckoo_read_benchmark") + + ToString(num / 1000000) + "Mkeys"; } // Create last level file as we are interested in measuring performance of diff --git a/table/table_reader_bench.cc b/table/table_reader_bench.cc index 9bce610fd..b05e3e052 100644 --- a/table/table_reader_bench.cc +++ b/table/table_reader_bench.cc @@ -75,9 +75,9 @@ void TableReaderBenchmark(Options& opts, EnvOptions& env_options, bool through_db, bool measured_by_nanosecond) { rocksdb::InternalKeyComparator ikc(opts.comparator); - std::string file_name = test::TmpDir() - + "/rocksdb_table_reader_benchmark"; - std::string dbname = test::TmpDir() + "/rocksdb_table_reader_bench_db"; + std::string file_name = + test::PerThreadDBPath("rocksdb_table_reader_benchmark"); + std::string dbname = test::PerThreadDBPath("rocksdb_table_reader_bench_db"); WriteOptions wo; Env* env = Env::Default(); TableBuilder* tb = nullptr; diff --git a/table/table_test.cc b/table/table_test.cc index 312b0bfcd..e7c555fe5 100644 --- a/table/table_test.cc +++ b/table/table_test.cc @@ -547,7 +547,7 @@ class DBConstructor: public Constructor { private: void NewDB() { - std::string name = test::TmpDir() + "/table_testdb"; + std::string name = test::PerThreadDBPath("table_testdb"); Options options; options.comparator = comparator_; @@ -3109,7 +3109,7 @@ TEST_F(PrefixTest, PrefixAndWholeKeyTest) { bbto.block_size = 262144; bbto.whole_key_filtering = true; - const std::string kDBPath = test::TmpDir() + "/table_prefix_test"; + const std::string kDBPath = test::PerThreadDBPath("table_prefix_test"); options.table_factory.reset(NewBlockBasedTableFactory(bbto)); DestroyDB(kDBPath, options); rocksdb::DB* db; @@ -3502,7 +3502,7 @@ TEST_P(BlockBasedTableTest, BadOptions) { bbto.block_align = true; const std::string kDBPath = - test::TmpDir() + "/block_based_table_bad_options_test"; + test::PerThreadDBPath("block_based_table_bad_options_test"); options.table_factory.reset(NewBlockBasedTableFactory(bbto)); DestroyDB(kDBPath, options); rocksdb::DB* db; diff --git a/tools/db_bench_tool.cc b/tools/db_bench_tool.cc index 7da52daa6..6b8e814d4 100644 --- a/tools/db_bench_tool.cc +++ b/tools/db_bench_tool.cc @@ -525,8 +525,7 @@ DEFINE_bool(read_cache_direct_write, true, DEFINE_bool(read_cache_direct_read, true, "Whether to use Direct IO for reading from read cache"); -DEFINE_bool(use_keep_filter, false, - "Whether to use a noop compaction filter"); +DEFINE_bool(use_keep_filter, false, "Whether to use a noop compaction filter"); static bool ValidateCacheNumshardbits(const char* flagname, int32_t value) { if (value >= 20) { diff --git a/tools/db_bench_tool_test.cc b/tools/db_bench_tool_test.cc index 687f6574f..67426066e 100644 --- a/tools/db_bench_tool_test.cc +++ b/tools/db_bench_tool_test.cc @@ -26,7 +26,7 @@ static const size_t kArgBufferSize = 100000; class DBBenchTest : public testing::Test { public: DBBenchTest() : rnd_(0xFB) { - test_path_ = test::TmpDir() + "/db_bench_test"; + test_path_ = test::PerThreadDBPath("db_bench_test"); Env::Default()->CreateDir(test_path_); db_path_ = test_path_ + "/db"; wal_path_ = test_path_ + "/wal"; diff --git a/tools/reduce_levels_test.cc b/tools/reduce_levels_test.cc index 7e1e1ac00..1718b3344 100644 --- a/tools/reduce_levels_test.cc +++ b/tools/reduce_levels_test.cc @@ -20,7 +20,7 @@ namespace rocksdb { class ReduceLevelTest : public testing::Test { public: ReduceLevelTest() { - dbname_ = test::TmpDir() + "/db_reduce_levels_test"; + dbname_ = test::PerThreadDBPath("db_reduce_levels_test"); DestroyDB(dbname_, Options()); db_ = nullptr; } diff --git a/util/auto_roll_logger_test.cc b/util/auto_roll_logger_test.cc index 6c8357df9..5a6b3abc1 100644 --- a/util/auto_roll_logger_test.cc +++ b/util/auto_roll_logger_test.cc @@ -71,9 +71,10 @@ class AutoRollLoggerTest : public testing::Test { const std::string AutoRollLoggerTest::kSampleMessage( "this is the message to be written to the log file!!"); -const std::string AutoRollLoggerTest::kTestDir(test::TmpDir() + "/db_log_test"); -const std::string AutoRollLoggerTest::kLogFile(test::TmpDir() + - "/db_log_test/LOG"); +const std::string AutoRollLoggerTest::kTestDir( + test::PerThreadDBPath("db_log_test")); +const std::string AutoRollLoggerTest::kLogFile( + test::PerThreadDBPath("db_log_test") + "/LOG"); Env* AutoRollLoggerTest::default_env = Env::Default(); // In this test we only want to Log some simple log message with diff --git a/util/delete_scheduler_test.cc b/util/delete_scheduler_test.cc index 78d5313f8..6c33f03da 100644 --- a/util/delete_scheduler_test.cc +++ b/util/delete_scheduler_test.cc @@ -31,9 +31,9 @@ class DeleteSchedulerTest : public testing::Test { const int kNumDataDirs = 3; dummy_files_dirs_.reserve(kNumDataDirs); for (size_t i = 0; i < kNumDataDirs; ++i) { - dummy_files_dirs_.emplace_back(test::TmpDir(env_) + - "/delete_scheduler_dummy_data_dir" + - ToString(i)); + dummy_files_dirs_.emplace_back( + test::PerThreadDBPath(env_, "delete_scheduler_dummy_data_dir") + + ToString(i)); DestroyAndCreateDir(dummy_files_dirs_.back()); } } diff --git a/util/filelock_test.cc b/util/filelock_test.cc index 87654a06a..de3cdd00c 100644 --- a/util/filelock_test.cc +++ b/util/filelock_test.cc @@ -19,8 +19,9 @@ class LockTest : public testing::Test { std::string file_; rocksdb::Env* env_; - LockTest() : file_(test::TmpDir() + "/db_testlock_file"), - env_(rocksdb::Env::Default()) { + LockTest() + : file_(test::PerThreadDBPath("db_testlock_file")), + env_(rocksdb::Env::Default()) { current_ = this; } diff --git a/util/log_write_bench.cc b/util/log_write_bench.cc index f42b12fc4..b4e12b948 100644 --- a/util/log_write_bench.cc +++ b/util/log_write_bench.cc @@ -31,7 +31,7 @@ DEFINE_bool(enable_sync, false, "sync after each write."); namespace rocksdb { void RunBenchmark() { - std::string file_name = test::TmpDir() + "/log_write_benchmark.log"; + std::string file_name = test::PerThreadDBPath("log_write_benchmark.log"); Env* env = Env::Default(); EnvOptions env_options = env->OptimizeForLogWrite(EnvOptions()); env_options.bytes_per_sync = FLAGS_bytes_per_sync; diff --git a/util/slice_transform_test.cc b/util/slice_transform_test.cc index 0b0e5648d..ddbb9f4bf 100644 --- a/util/slice_transform_test.cc +++ b/util/slice_transform_test.cc @@ -53,7 +53,7 @@ class SliceTransformDBTest : public testing::Test { public: SliceTransformDBTest() : env_(Env::Default()), db_(nullptr) { - dbname_ = test::TmpDir() + "/slice_transform_db_test"; + dbname_ = test::PerThreadDBPath("slice_transform_db_test"); EXPECT_OK(DestroyDB(dbname_, last_options_)); } diff --git a/util/testharness.cc b/util/testharness.cc index 7ec353762..8f5eb2a4d 100644 --- a/util/testharness.cc +++ b/util/testharness.cc @@ -9,6 +9,7 @@ #include "util/testharness.h" #include +#include namespace rocksdb { namespace test { @@ -29,6 +30,19 @@ std::string TmpDir(Env* env) { return dir; } +std::string PerThreadDBPath(std::string dir, std::string name) { + size_t tid = std::hash()(std::this_thread::get_id()); + return dir + "/" + name + "_" + std::to_string(tid); +} + +std::string PerThreadDBPath(std::string name) { + return PerThreadDBPath(test::TmpDir(), name); +} + +std::string PerThreadDBPath(Env* env, std::string name) { + return PerThreadDBPath(test::TmpDir(env), name); +} + int RandomSeed() { const char* env = getenv("TEST_RANDOM_SEED"); int result = (env != nullptr ? atoi(env) : 301); diff --git a/util/testharness.h b/util/testharness.h index 8da568123..39e77f8a9 100644 --- a/util/testharness.h +++ b/util/testharness.h @@ -24,6 +24,11 @@ namespace test { // Return the directory to use for temporary storage. std::string TmpDir(Env* env = Env::Default()); +// A path unique within the thread +std::string PerThreadDBPath(std::string name); +std::string PerThreadDBPath(Env* env, std::string name); +std::string PerThreadDBPath(std::string dir, std::string name); + // Return a randomization seed for this run. Typically returns the // same number on repeated invocations of this binary, but automated // runs may be able to vary the seed. diff --git a/utilities/backupable/backupable_db_test.cc b/utilities/backupable/backupable_db_test.cc index ab71c6616..9fdc058fd 100644 --- a/utilities/backupable/backupable_db_test.cc +++ b/utilities/backupable/backupable_db_test.cc @@ -477,8 +477,8 @@ class BackupableDBTest : public testing::Test { public: BackupableDBTest() { // set up files - std::string db_chroot = test::TmpDir() + "/backupable_db"; - std::string backup_chroot = test::TmpDir() + "/backupable_db_backup"; + std::string db_chroot = test::PerThreadDBPath("backupable_db"); + std::string backup_chroot = test::PerThreadDBPath("backupable_db_backup"); Env::Default()->CreateDir(db_chroot); Env::Default()->CreateDir(backup_chroot); dbname_ = "/tempdb"; diff --git a/utilities/blob_db/blob_db_test.cc b/utilities/blob_db/blob_db_test.cc index 5ab2656b9..bff17fb61 100644 --- a/utilities/blob_db/blob_db_test.cc +++ b/utilities/blob_db/blob_db_test.cc @@ -38,7 +38,7 @@ class BlobDBTest : public testing::Test { }; BlobDBTest() - : dbname_(test::TmpDir() + "/blob_db_test"), + : dbname_(test::PerThreadDBPath("blob_db_test")), mock_env_(new MockTimeEnv(Env::Default())), blob_db_(nullptr) { Status s = DestroyBlobDB(dbname_, Options(), BlobDBOptions()); diff --git a/utilities/cassandra/cassandra_functional_test.cc b/utilities/cassandra/cassandra_functional_test.cc index 895c25177..3e612b3ad 100644 --- a/utilities/cassandra/cassandra_functional_test.cc +++ b/utilities/cassandra/cassandra_functional_test.cc @@ -21,7 +21,7 @@ namespace rocksdb { namespace cassandra { // Path to the database on file system -const std::string kDbName = test::TmpDir() + "/cassandra_functional_test"; +const std::string kDbName = test::PerThreadDBPath("cassandra_functional_test"); class CassandraStore { public: diff --git a/utilities/checkpoint/checkpoint_test.cc b/utilities/checkpoint/checkpoint_test.cc index 520c02176..b47f240c3 100644 --- a/utilities/checkpoint/checkpoint_test.cc +++ b/utilities/checkpoint/checkpoint_test.cc @@ -47,7 +47,7 @@ class CheckpointTest : public testing::Test { CheckpointTest() : env_(Env::Default()) { env_->SetBackgroundThreads(1, Env::LOW); env_->SetBackgroundThreads(1, Env::HIGH); - dbname_ = test::TmpDir(env_) + "/checkpoint_test"; + dbname_ = test::PerThreadDBPath(env_, "checkpoint_test"); alternative_wal_dir_ = dbname_ + "/wal"; auto options = CurrentOptions(); auto delete_options = options; @@ -56,7 +56,7 @@ class CheckpointTest : public testing::Test { // Destroy it for not alternative WAL dir is used. EXPECT_OK(DestroyDB(dbname_, options)); db_ = nullptr; - snapshot_name_ = test::TmpDir(env_) + "/snapshot"; + snapshot_name_ = test::PerThreadDBPath(env_, "snapshot"); std::string snapshot_tmp_name = snapshot_name_ + ".tmp"; EXPECT_OK(DestroyDB(snapshot_name_, options)); env_->DeleteDir(snapshot_name_); @@ -274,7 +274,7 @@ TEST_F(CheckpointTest, GetSnapshotLink) { delete checkpoint; // Restore DB name - dbname_ = test::TmpDir(env_) + "/db_test"; + dbname_ = test::PerThreadDBPath(env_, "db_test"); } } @@ -450,7 +450,7 @@ TEST_F(CheckpointTest, CurrentFileModifiedWhileCheckpointing) { TEST_F(CheckpointTest, CurrentFileModifiedWhileCheckpointing2PC) { Close(); - const std::string dbname = test::TmpDir() + "/transaction_testdb"; + const std::string dbname = test::PerThreadDBPath("transaction_testdb"); ASSERT_OK(DestroyDB(dbname, CurrentOptions())); env_->DeleteDir(dbname); diff --git a/utilities/date_tiered/date_tiered_test.cc b/utilities/date_tiered/date_tiered_test.cc index fb0d52930..8e7fced58 100644 --- a/utilities/date_tiered/date_tiered_test.cc +++ b/utilities/date_tiered/date_tiered_test.cc @@ -44,7 +44,7 @@ class DateTieredTest : public testing::Test { public: DateTieredTest() { env_.reset(new SpecialTimeEnv(Env::Default())); - dbname_ = test::TmpDir() + "/date_tiered"; + dbname_ = test::PerThreadDBPath("date_tiered"); options_.create_if_missing = true; options_.env = env_.get(); date_tiered_db_.reset(nullptr); diff --git a/utilities/document/document_db_test.cc b/utilities/document/document_db_test.cc index ac73ae7e1..652f1e455 100644 --- a/utilities/document/document_db_test.cc +++ b/utilities/document/document_db_test.cc @@ -18,7 +18,7 @@ namespace rocksdb { class DocumentDBTest : public testing::Test { public: DocumentDBTest() { - dbname_ = test::TmpDir() + "/document_db_test"; + dbname_ = test::PerThreadDBPath("document_db_test"); DestroyDB(dbname_, Options()); } ~DocumentDBTest() { diff --git a/utilities/geodb/geodb_test.cc b/utilities/geodb/geodb_test.cc index a0150d64e..8477c86a3 100644 --- a/utilities/geodb/geodb_test.cc +++ b/utilities/geodb/geodb_test.cc @@ -35,7 +35,8 @@ class GeoDBTest : public testing::Test { } }; -const std::string GeoDBTest::kDefaultDbName = test::TmpDir() + "/geodb_test"; +const std::string GeoDBTest::kDefaultDbName = + test::PerThreadDBPath("geodb_test"); Options GeoDBTest::options = Options(); // Insert, Get and Remove diff --git a/utilities/lua/rocks_lua_test.cc b/utilities/lua/rocks_lua_test.cc index a78d780a6..cc9c14166 100644 --- a/utilities/lua/rocks_lua_test.cc +++ b/utilities/lua/rocks_lua_test.cc @@ -101,7 +101,7 @@ TEST_F(RocksLuaTest, Default) { // If nothing is set in the LuaCompactionFilterOptions, then // RocksDB will keep all the key / value pairs, but it will also // print our error log indicating failure. - std::string db_path = temp_dir_ + "/rocks_lua_test"; + std::string db_path = test::PerThreadDBPath(temp_dir_, "rocks_lua_test"); lua::RocksLuaCompactionFilterOptions lua_opt; @@ -116,7 +116,7 @@ TEST_F(RocksLuaTest, Default) { } TEST_F(RocksLuaTest, KeepsAll) { - std::string db_path = temp_dir_ + "/rocks_lua_test"; + std::string db_path = test::PerThreadDBPath(temp_dir_, "rocks_lua_test"); lua::RocksLuaCompactionFilterOptions lua_opt; lua_opt.error_log = std::make_shared(); @@ -145,7 +145,7 @@ TEST_F(RocksLuaTest, KeepsAll) { } TEST_F(RocksLuaTest, GetName) { - std::string db_path = temp_dir_ + "/rocks_lua_test"; + std::string db_path = test::PerThreadDBPath(temp_dir_, "rocks_lua_test"); lua::RocksLuaCompactionFilterOptions lua_opt; lua_opt.error_log = std::make_shared(); @@ -171,7 +171,7 @@ TEST_F(RocksLuaTest, GetName) { } TEST_F(RocksLuaTest, RemovesAll) { - std::string db_path = temp_dir_ + "/rocks_lua_test"; + std::string db_path = test::PerThreadDBPath(temp_dir_, "rocks_lua_test"); lua::RocksLuaCompactionFilterOptions lua_opt; lua_opt.error_log = std::make_shared(); @@ -202,7 +202,7 @@ TEST_F(RocksLuaTest, RemovesAll) { } TEST_F(RocksLuaTest, FilterByKey) { - std::string db_path = temp_dir_ + "/rocks_lua_test"; + std::string db_path = test::PerThreadDBPath(temp_dir_, "rocks_lua_test"); lua::RocksLuaCompactionFilterOptions lua_opt; lua_opt.error_log = std::make_shared(); @@ -240,7 +240,7 @@ TEST_F(RocksLuaTest, FilterByKey) { } TEST_F(RocksLuaTest, FilterByValue) { - std::string db_path = temp_dir_ + "/rocks_lua_test"; + std::string db_path = test::PerThreadDBPath(temp_dir_, "rocks_lua_test"); lua::RocksLuaCompactionFilterOptions lua_opt; lua_opt.error_log = std::make_shared(); @@ -279,7 +279,7 @@ TEST_F(RocksLuaTest, FilterByValue) { } TEST_F(RocksLuaTest, ChangeValue) { - std::string db_path = temp_dir_ + "/rocks_lua_test"; + std::string db_path = test::PerThreadDBPath(temp_dir_, "rocks_lua_test"); lua::RocksLuaCompactionFilterOptions lua_opt; lua_opt.error_log = std::make_shared(); @@ -312,7 +312,7 @@ TEST_F(RocksLuaTest, ChangeValue) { } TEST_F(RocksLuaTest, ConditionallyChangeAndFilterValue) { - std::string db_path = temp_dir_ + "/rocks_lua_test"; + std::string db_path = test::PerThreadDBPath(temp_dir_, "rocks_lua_test"); lua::RocksLuaCompactionFilterOptions lua_opt; lua_opt.error_log = std::make_shared(); @@ -357,7 +357,7 @@ TEST_F(RocksLuaTest, ConditionallyChangeAndFilterValue) { } TEST_F(RocksLuaTest, DynamicChangeScript) { - std::string db_path = temp_dir_ + "/rocks_lua_test"; + std::string db_path = test::PerThreadDBPath(temp_dir_, "rocks_lua_test"); lua::RocksLuaCompactionFilterOptions lua_opt; lua_opt.error_log = std::make_shared(); @@ -433,7 +433,7 @@ TEST_F(RocksLuaTest, DynamicChangeScript) { } TEST_F(RocksLuaTest, LuaConditionalTypeError) { - std::string db_path = temp_dir_ + "/rocks_lua_test"; + std::string db_path = test::PerThreadDBPath(temp_dir_, "rocks_lua_test"); lua::RocksLuaCompactionFilterOptions lua_opt; // Filter() error when input key's initial >= 'r' diff --git a/utilities/memory/memory_test.cc b/utilities/memory/memory_test.cc index a6d4fbc5e..8d976ef92 100644 --- a/utilities/memory/memory_test.cc +++ b/utilities/memory/memory_test.cc @@ -19,7 +19,7 @@ namespace rocksdb { class MemoryTest : public testing::Test { public: - MemoryTest() : kDbDir(test::TmpDir() + "/memory_test"), rnd_(301) { + MemoryTest() : kDbDir(test::PerThreadDBPath("memory_test")), rnd_(301) { assert(Env::Default()->CreateDirIfMissing(kDbDir).ok()); } diff --git a/utilities/merge_operators/string_append/stringappend_test.cc b/utilities/merge_operators/string_append/stringappend_test.cc index a12e130d1..54c89a03a 100644 --- a/utilities/merge_operators/string_append/stringappend_test.cc +++ b/utilities/merge_operators/string_append/stringappend_test.cc @@ -23,7 +23,7 @@ using namespace rocksdb; namespace rocksdb { // Path to the database on file system -const std::string kDbName = test::TmpDir() + "/stringappend_test"; +const std::string kDbName = test::PerThreadDBPath("stringappend_test"); namespace { // OpenDb opens a (possibly new) rocksdb database with a StringAppendOperator diff --git a/utilities/options/options_util_test.cc b/utilities/options/options_util_test.cc index 7809f2026..bf830190c 100644 --- a/utilities/options/options_util_test.cc +++ b/utilities/options/options_util_test.cc @@ -34,7 +34,7 @@ class OptionsUtilTest : public testing::Test { public: OptionsUtilTest() : rnd_(0xFB) { env_.reset(new test::StringEnv(Env::Default())); - dbname_ = test::TmpDir() + "/options_util_test"; + dbname_ = test::PerThreadDBPath("options_util_test"); } protected: diff --git a/utilities/persistent_cache/persistent_cache_test.cc b/utilities/persistent_cache/persistent_cache_test.cc index 1f26c9a4e..e3b1e39e0 100644 --- a/utilities/persistent_cache/persistent_cache_test.cc +++ b/utilities/persistent_cache/persistent_cache_test.cc @@ -132,7 +132,7 @@ std::unique_ptr NewTieredCache( } PersistentCacheTierTest::PersistentCacheTierTest() - : path_(test::TmpDir(Env::Default()) + "/cache_test") { + : path_(test::PerThreadDBPath("cache_test")) { #ifdef OS_LINUX rocksdb::SyncPoint::GetInstance()->EnableProcessing(); rocksdb::SyncPoint::GetInstance()->SetCallBack("NewRandomAccessFile:O_DIRECT", diff --git a/utilities/redis/redis_lists_test.cc b/utilities/redis/redis_lists_test.cc index 5eec308e4..961d87de7 100644 --- a/utilities/redis/redis_lists_test.cc +++ b/utilities/redis/redis_lists_test.cc @@ -39,7 +39,7 @@ class RedisListsTest : public testing::Test { }; const std::string RedisListsTest::kDefaultDbName = - test::TmpDir() + "/redis_lists_test"; + test::PerThreadDBPath("redis_lists_test"); Options RedisListsTest::options = Options(); // operator== and operator<< are defined below for vectors (lists) diff --git a/utilities/simulator_cache/sim_cache_test.cc b/utilities/simulator_cache/sim_cache_test.cc index 0e504d443..7f0f904a7 100644 --- a/utilities/simulator_cache/sim_cache_test.cc +++ b/utilities/simulator_cache/sim_cache_test.cc @@ -154,7 +154,7 @@ TEST_F(SimCacheTest, SimCacheLogging) { Flush(); } - std::string log_file = test::TmpDir(env_) + "/cache_log.txt"; + std::string log_file = test::PerThreadDBPath(env_, "cache_log.txt"); ASSERT_OK(sim_cache->StartActivityLogging(log_file, env_)); for (int i = 0; i < num_block_entries; i++) { ASSERT_EQ(Get(Key(i)), "val"); diff --git a/utilities/spatialdb/spatial_db_test.cc b/utilities/spatialdb/spatial_db_test.cc index e92c16f48..783b347d0 100644 --- a/utilities/spatialdb/spatial_db_test.cc +++ b/utilities/spatialdb/spatial_db_test.cc @@ -21,7 +21,7 @@ namespace spatial { class SpatialDBTest : public testing::Test { public: SpatialDBTest() { - dbname_ = test::TmpDir() + "/spatial_db_test"; + dbname_ = test::PerThreadDBPath("spatial_db_test"); DestroyDB(dbname_, Options()); } diff --git a/utilities/transactions/optimistic_transaction_test.cc b/utilities/transactions/optimistic_transaction_test.cc index 10632cfb2..2c196d43b 100644 --- a/utilities/transactions/optimistic_transaction_test.cc +++ b/utilities/transactions/optimistic_transaction_test.cc @@ -32,7 +32,7 @@ class OptimisticTransactionTest : public testing::Test { OptimisticTransactionTest() { options.create_if_missing = true; options.max_write_buffer_number = 2; - dbname = test::TmpDir() + "/optimistic_transaction_testdb"; + dbname = test::PerThreadDBPath("optimistic_transaction_testdb"); DestroyDB(dbname, options); Open(); diff --git a/utilities/transactions/transaction_test.h b/utilities/transactions/transaction_test.h index 97d169d88..a8c3093ec 100644 --- a/utilities/transactions/transaction_test.h +++ b/utilities/transactions/transaction_test.h @@ -60,7 +60,7 @@ class TransactionTestBase : public ::testing::Test { env = new FaultInjectionTestEnv(Env::Default()); options.env = env; options.two_write_queues = two_write_queue; - dbname = test::TmpDir() + "/transaction_testdb"; + dbname = test::PerThreadDBPath("transaction_testdb"); DestroyDB(dbname, options); txn_db_options.transaction_lock_timeout = 0; diff --git a/utilities/transactions/write_prepared_transaction_test.cc b/utilities/transactions/write_prepared_transaction_test.cc index 7558a3660..1f980a3a7 100644 --- a/utilities/transactions/write_prepared_transaction_test.cc +++ b/utilities/transactions/write_prepared_transaction_test.cc @@ -186,7 +186,7 @@ TEST(WriteBatchWithIndex, SubBatchCnt) { DB* db; Options options; options.create_if_missing = true; - const std::string dbname = test::TmpDir() + "/transaction_testdb"; + const std::string dbname = test::PerThreadDBPath("transaction_testdb"); DestroyDB(dbname, options); ASSERT_OK(DB::Open(options, dbname, &db)); ColumnFamilyHandle* cf_handle = nullptr; diff --git a/utilities/ttl/ttl_test.cc b/utilities/ttl/ttl_test.cc index f507b1c0b..ee7b317aa 100644 --- a/utilities/ttl/ttl_test.cc +++ b/utilities/ttl/ttl_test.cc @@ -43,7 +43,7 @@ class TtlTest : public testing::Test { public: TtlTest() { env_.reset(new SpecialTimeEnv(Env::Default())); - dbname_ = test::TmpDir() + "/db_ttl"; + dbname_ = test::PerThreadDBPath("db_ttl"); options_.create_if_missing = true; options_.env = env_.get(); // ensure that compaction is kicked in to always strip timestamp from kvs diff --git a/utilities/write_batch_with_index/write_batch_with_index_test.cc b/utilities/write_batch_with_index/write_batch_with_index_test.cc index 105f7517d..aa484cde9 100644 --- a/utilities/write_batch_with_index/write_batch_with_index_test.cc +++ b/utilities/write_batch_with_index/write_batch_with_index_test.cc @@ -972,7 +972,7 @@ TEST_F(WriteBatchWithIndexTest, TestGetFromBatchMerge) { options.merge_operator = MergeOperators::CreateFromStringId("stringappend"); options.create_if_missing = true; - std::string dbname = test::TmpDir() + "/write_batch_with_index_test"; + std::string dbname = test::PerThreadDBPath("write_batch_with_index_test"); DestroyDB(dbname, options); Status s = DB::Open(options, dbname, &db); @@ -1020,7 +1020,7 @@ TEST_F(WriteBatchWithIndexTest, TestGetFromBatchMerge2) { options.merge_operator = MergeOperators::CreateFromStringId("stringappend"); options.create_if_missing = true; - std::string dbname = test::TmpDir() + "/write_batch_with_index_test"; + std::string dbname = test::PerThreadDBPath("write_batch_with_index_test"); DestroyDB(dbname, options); Status s = DB::Open(options, dbname, &db); @@ -1078,7 +1078,7 @@ TEST_F(WriteBatchWithIndexTest, TestGetFromBatchAndDB) { DB* db; Options options; options.create_if_missing = true; - std::string dbname = test::TmpDir() + "/write_batch_with_index_test"; + std::string dbname = test::PerThreadDBPath("write_batch_with_index_test"); DestroyDB(dbname, options); Status s = DB::Open(options, dbname, &db); @@ -1129,7 +1129,7 @@ TEST_F(WriteBatchWithIndexTest, TestGetFromBatchAndDBMerge) { Options options; options.create_if_missing = true; - std::string dbname = test::TmpDir() + "/write_batch_with_index_test"; + std::string dbname = test::PerThreadDBPath("write_batch_with_index_test"); options.merge_operator = MergeOperators::CreateFromStringId("stringappend"); @@ -1255,7 +1255,7 @@ TEST_F(WriteBatchWithIndexTest, TestGetFromBatchAndDBMerge2) { Options options; options.create_if_missing = true; - std::string dbname = test::TmpDir() + "/write_batch_with_index_test"; + std::string dbname = test::PerThreadDBPath("write_batch_with_index_test"); options.merge_operator = MergeOperators::CreateFromStringId("stringappend");