Skip to content

Commit 10720a5

Browse files
committed
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
1 parent 01cbdd2 commit 10720a5

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

db/db_impl.cc

+2-1
Original file line numberDiff line numberDiff line change
@@ -4939,8 +4939,9 @@ Status DestroyDB(const std::string& dbname, const Options& options) {
49394939
if (result.ok()) {
49404940
uint64_t number;
49414941
FileType type;
4942+
InfoLogPrefix info_log_prefix(!options.db_log_dir.empty(), dbname);
49424943
for (size_t i = 0; i < filenames.size(); i++) {
4943-
if (ParseFileName(filenames[i], &number, &type) &&
4944+
if (ParseFileName(filenames[i], &number, info_log_prefix.prefix, &type) &&
49444945
type != kDBLockFile) { // Lock file will be deleted at end
49454946
Status del;
49464947
if (type == kMetaDatabase) {

db/db_test.cc

+18-3
Original file line numberDiff line numberDiff line change
@@ -6076,13 +6076,28 @@ TEST(DBTest, PurgeInfoLogs) {
60766076
int info_log_count = 0;
60776077
for (std::string file : files) {
60786078
if (file.find("LOG") != std::string::npos) {
6079-
if (mode == 1) {
6080-
env_->DeleteFile(options.db_log_dir + "/" + file);
6081-
}
60826079
info_log_count++;
60836080
}
60846081
}
60856082
ASSERT_EQ(5, info_log_count);
6083+
6084+
Destroy(&options);
6085+
// For mode (1), test DestoryDB() to delete all the logs under DB dir.
6086+
// For mode (2), no info log file should have been put under DB dir.
6087+
std::vector<std::string> db_files;
6088+
env_->GetChildren(dbname_, &db_files);
6089+
for (std::string file : db_files) {
6090+
ASSERT_TRUE(file.find("LOG") == std::string::npos);
6091+
}
6092+
6093+
if (mode == 1) {
6094+
// Cleaning up
6095+
env_->GetChildren(options.db_log_dir, &files);
6096+
for (std::string file : files) {
6097+
env_->DeleteFile(options.db_log_dir + "/" + file);
6098+
}
6099+
env_->DeleteDir(options.db_log_dir);
6100+
}
60866101
}
60876102
}
60886103

0 commit comments

Comments
 (0)