From 22368965a092863f1be31da88e9d6126aa50ce39 Mon Sep 17 00:00:00 2001 From: Yanqin Jin Date: Fri, 3 Aug 2018 13:55:32 -0700 Subject: [PATCH] Modify verification logic of ObsoleteOptionsFileTest (#4218) Summary: The current verification logic does not consider the case in which multiple threads (foreground and background) may execute `PurgeObsoleteFiles` function simultaneously. Each invocation will trigger the callback adding elements to a vector. Then we verify the elements in the vector, which can fail sometimes. The solution is to give up checking the elements. Instead, we check the number of OPTIONS file in the database dir. Pull Request resolved: https://github.com/facebook/rocksdb/pull/4218 Differential Revision: D9128727 Pulled By: riversand963 fbshipit-source-id: 2b13b705fb21bc0ddd41940c4ec9b6b0c8d88224 --- db/obsolete_files_test.cc | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/db/obsolete_files_test.cc b/db/obsolete_files_test.cc index 81e519bda..05cadd6e8 100644 --- a/db/obsolete_files_test.cc +++ b/db/obsolete_files_test.cc @@ -227,16 +227,24 @@ TEST_F(ObsoleteFilesTest, DeleteObsoleteOptionsFile) { } ASSERT_OK(dbi->EnableFileDeletions(true /* force */)); ASSERT_EQ(optsfiles_nums.size(), optsfiles_keep.size()); - int size = static_cast(optsfiles_nums.size()); - int kept_opts_files_count = 0; - for (int i = 0; i != size; ++i) { - if (optsfiles_keep[i]) { - ++kept_opts_files_count; - } - } - ASSERT_EQ(2, kept_opts_files_count); CloseDB(); + + std::vector files; + int opts_file_count = 0; + ASSERT_OK(env_->GetChildren(dbname_, &files)); + for (const auto& file : files) { + uint64_t file_num; + Slice dummy_info_log_name_prefix; + FileType type; + WalFileType log_type; + if (ParseFileName(file, &file_num, dummy_info_log_name_prefix, &type, + &log_type) && + type == kOptionsFile) { + opts_file_count++; + } + } + ASSERT_EQ(2, opts_file_count); } } //namespace rocksdb