Skip to content

Commit

Permalink
Fix test
Browse files Browse the repository at this point in the history
Signed-off-by: Yang Zhang <[email protected]>
  • Loading branch information
v01dstar committed Sep 18, 2024
1 parent d6bc9d9 commit 3d6c365
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
19 changes: 19 additions & 0 deletions db/db_impl/db_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5288,6 +5288,25 @@ Status DestroyDB(const std::string& dbname, const Options& options,
env->DeleteDir(soptions.wal_dir).PermitUncheckedError();
}

// Delete info logs in the db_log_dir
if (!soptions.db_log_dir.empty()) {
std::vector<std::string> log_files;
soptions.fs->GetChildren(soptions.db_log_dir, io_opts, &log_files,
/*IODebugContext*=*/nullptr);
InfoLogPrefix info_log_prefix(!soptions.db_log_dir.empty(), dbname);
for (const auto& log_file : log_files) {
if (ParseFileName(log_file, &number, info_log_prefix.prefix, &type) &&
type == kInfoLogFile) {
Status del = env->DeleteFile(soptions.db_log_dir + "/" + log_file);
if (!del.ok() && result.ok()) {
result = del;
}
}
}
// Ignore error in case dir contains other files
env->DeleteDir(soptions.db_log_dir).PermitUncheckedError();
}

// Ignore error since state is already gone
env->UnlockFile(lock).PermitUncheckedError();
env->DeleteFile(lockname).PermitUncheckedError();
Expand Down
10 changes: 0 additions & 10 deletions db/db_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2685,7 +2685,6 @@ TEST_F(DBTest, PurgeInfoLogs) {
options.keep_log_file_num = 5;
options.create_if_missing = true;
options.env = env_;
env_->DeleteDir(dbname_);
for (int mode = 0; mode <= 1; mode++) {
if (mode == 1) {
options.db_log_dir = dbname_ + "_logs";
Expand Down Expand Up @@ -2715,15 +2714,6 @@ TEST_F(DBTest, PurgeInfoLogs) {
std::vector<std::string> db_files;
ASSERT_TRUE(env_->GetChildren(dbname_, &db_files).IsNotFound());
ASSERT_TRUE(db_files.empty());

if (mode == 1) {
// Cleaning up
ASSERT_OK(env_->GetChildren(options.db_log_dir, &files));
for (std::string file : files) {
ASSERT_OK(env_->DeleteFile(options.db_log_dir + "/" + file));
}
ASSERT_OK(env_->DeleteDir(options.db_log_dir));
}
}
}

Expand Down

0 comments on commit 3d6c365

Please sign in to comment.