From 6f101303542f2259075a9abe88d836c792ead411 Mon Sep 17 00:00:00 2001 From: Igor Canadi Date: Thu, 5 Feb 2015 20:09:42 -0800 Subject: [PATCH] Fix DestroyDB Summary: When DestroyDB() finds a wal file in the DB directory, it assumes it is actually in WAL directory. This can lead to confusion, since it reports IO error when it tries to delete wal file from DB directory. For example: https://ci-builds.fb.com/job/rocksdb_clang_build/296/console This change will fix our unit tests. Test Plan: unit tests work Reviewers: yhchiang, rven, sdong Reviewed By: sdong Subscribers: dhruba, leveldb Differential Revision: https://reviews.facebook.net/D32907 --- db/db_impl.cc | 33 ++++++++++++++++++--------------- db/db_test.cc | 7 ++++--- 2 files changed, 22 insertions(+), 18 deletions(-) diff --git a/db/db_impl.cc b/db/db_impl.cc index dd627313b..3365e18a4 100644 --- a/db/db_impl.cc +++ b/db/db_impl.cc @@ -3885,23 +3885,10 @@ Status DestroyDB(const std::string& dbname, const Options& options) { const Options& soptions(SanitizeOptions(dbname, &comparator, options)); Env* env = soptions.env; std::vector filenames; - std::vector archiveFiles; - std::string archivedir = ArchivalDirectory(dbname); // Ignore error in case directory does not exist env->GetChildren(dbname, &filenames); - if (dbname != soptions.wal_dir) { - std::vector logfilenames; - env->GetChildren(soptions.wal_dir, &logfilenames); - filenames.insert(filenames.end(), logfilenames.begin(), logfilenames.end()); - archivedir = ArchivalDirectory(soptions.wal_dir); - } - - if (filenames.empty()) { - return Status::OK(); - } - FileLock* lock; const std::string lockname = LockFileName(dbname); Status result = env->LockFile(lockname, &lock); @@ -3915,8 +3902,6 @@ Status DestroyDB(const std::string& dbname, const Options& options) { Status del; if (type == kMetaDatabase) { del = DestroyDB(dbname + "/" + filenames[i], options); - } else if (type == kLogFile) { - del = env->DeleteFile(soptions.wal_dir + "/" + filenames[i]); } else { del = env->DeleteFile(dbname + "/" + filenames[i]); } @@ -3939,6 +3924,24 @@ Status DestroyDB(const std::string& dbname, const Options& options) { } } + std::vector walDirFiles; + std::string archivedir = ArchivalDirectory(dbname); + if (dbname != soptions.wal_dir) { + env->GetChildren(soptions.wal_dir, &walDirFiles); + archivedir = ArchivalDirectory(soptions.wal_dir); + } + + // Delete log files in the WAL dir + for (const auto& file : walDirFiles) { + if (ParseFileName(file, &number, &type) && type == kLogFile) { + Status del = env->DeleteFile(soptions.wal_dir + "/" + file); + if (result.ok() && !del.ok()) { + result = del; + } + } + } + + std::vector archiveFiles; env->GetChildren(archivedir, &archiveFiles); // Delete archival files. for (size_t i = 0; i < archiveFiles.size(); ++i) { diff --git a/db/db_test.cc b/db/db_test.cc index 720978021..b19d2550b 100644 --- a/db/db_test.cc +++ b/db/db_test.cc @@ -624,7 +624,7 @@ class DBTest { options.db_log_dir = test::TmpDir(env_); break; case kWalDirAndMmapReads: - options.wal_dir = test::TmpDir(env_) + "/wal"; + options.wal_dir = dbname_ + "/wal"; // mmap reads should be orthogonal to WalDir setting, so we piggyback to // this option config to test mmap reads as well options.allow_mmap_reads = true; @@ -2595,8 +2595,9 @@ TEST(DBTest, IgnoreRecoveredLog) { Options options = CurrentOptions(); options.create_if_missing = true; options.merge_operator = MergeOperators::CreateUInt64AddOperator(); - options.wal_dir = dbname_ + "/logs"; - DestroyAndReopen(options); + options.wal_dir = dbname_ + "/wal"; + Destroy(options); + Reopen(options); // fill up the DB std::string one, two;