Revert the unintended change that DestroyDB() doesn't clean up info logs.

Summary: A previous change triggered a change by mistake: DestroyDB() will keep info logs under DB directory. Revert the unintended change.

Test Plan: Add a unit test case to verify it.

Reviewers: ljin, yhchiang, igor

Reviewed By: igor

Subscribers: leveldb

Differential Revision: https://reviews.facebook.net/D22209
main
sdong 10 years ago
parent 01cbdd2aae
commit 10720a5587
  1. 3
      db/db_impl.cc
  2. 21
      db/db_test.cc

@ -4939,8 +4939,9 @@ Status DestroyDB(const std::string& dbname, const Options& options) {
if (result.ok()) { if (result.ok()) {
uint64_t number; uint64_t number;
FileType type; FileType type;
InfoLogPrefix info_log_prefix(!options.db_log_dir.empty(), dbname);
for (size_t i = 0; i < filenames.size(); i++) { for (size_t i = 0; i < filenames.size(); i++) {
if (ParseFileName(filenames[i], &number, &type) && if (ParseFileName(filenames[i], &number, info_log_prefix.prefix, &type) &&
type != kDBLockFile) { // Lock file will be deleted at end type != kDBLockFile) { // Lock file will be deleted at end
Status del; Status del;
if (type == kMetaDatabase) { if (type == kMetaDatabase) {

@ -6076,13 +6076,28 @@ TEST(DBTest, PurgeInfoLogs) {
int info_log_count = 0; int info_log_count = 0;
for (std::string file : files) { for (std::string file : files) {
if (file.find("LOG") != std::string::npos) { if (file.find("LOG") != std::string::npos) {
if (mode == 1) {
env_->DeleteFile(options.db_log_dir + "/" + file);
}
info_log_count++; info_log_count++;
} }
} }
ASSERT_EQ(5, info_log_count); ASSERT_EQ(5, info_log_count);
Destroy(&options);
// For mode (1), test DestoryDB() to delete all the logs under DB dir.
// For mode (2), no info log file should have been put under DB dir.
std::vector<std::string> db_files;
env_->GetChildren(dbname_, &db_files);
for (std::string file : db_files) {
ASSERT_TRUE(file.find("LOG") == std::string::npos);
}
if (mode == 1) {
// Cleaning up
env_->GetChildren(options.db_log_dir, &files);
for (std::string file : files) {
env_->DeleteFile(options.db_log_dir + "/" + file);
}
env_->DeleteDir(options.db_log_dir);
}
} }
} }

Loading…
Cancel
Save