From 5c224d1b70ca873fc77afbd809c2380fc67d5934 Mon Sep 17 00:00:00 2001 From: Yueh-Hsuan Chiang <yhchiang@fb.com> Date: Fri, 22 May 2015 12:10:51 -0700 Subject: [PATCH] Fixed two bugs on logging file deletion. Summary: This patch fixes the following two bugs on logging file deletion. 1. Previously, file deletion failure was only logged in INFO_LEVEL. This patch changes it to ERROR_LEVEL and does some code clean. 2. EventLogger previously will always generate the same log on table file deletion even when file deletion is not successful. Now the resulting status of file deletion will also be logged. Test Plan: make all check Reviewers: sdong, igor Reviewed By: igor Subscribers: dhruba, leveldb Differential Revision: https://reviews.facebook.net/D38817 --- db/db_impl.cc | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/db/db_impl.cc b/db/db_impl.cc index 02e10b4b9..7c03df3b0 100644 --- a/db/db_impl.cc +++ b/db/db_impl.cc @@ -686,30 +686,36 @@ void DBImpl::PurgeObsoleteFiles(const JobContext& state) { // evict from cache TableCache::Evict(table_cache_.get(), number); fname = TableFileName(db_options_.db_paths, number, path_id); - event_logger_.Log() << "job" << state.job_id << "event" - << "table_file_deletion" - << "file_number" << number; } else { fname = ((type == kLogFile) ? db_options_.wal_dir : dbname_) + "/" + to_delete; } -#ifdef ROCKSDB_LITE - Status s = env_->DeleteFile(fname); - Log(InfoLogLevel::DEBUG_LEVEL, db_options_.info_log, - "[JOB %d] Delete %s type=%d #%" PRIu64 " -- %s\n", state.job_id, - fname.c_str(), type, number, s.ToString().c_str()); -#else // not ROCKSDB_LITE +#ifndef ROCKSDB_LITE if (type == kLogFile && (db_options_.WAL_ttl_seconds > 0 || - db_options_.WAL_size_limit_MB > 0)) { + db_options_.WAL_size_limit_MB > 0)) { wal_manager_.ArchiveWALFile(fname, number); - } else { - Status s = env_->DeleteFile(fname); + continue; + } +#endif // !ROCKSDB_LITE + auto file_deletion_status = env_->DeleteFile(fname); + if (file_deletion_status.ok()) { Log(InfoLogLevel::DEBUG_LEVEL, db_options_.info_log, "[JOB %d] Delete %s type=%d #%" PRIu64 " -- %s\n", state.job_id, - fname.c_str(), type, number, s.ToString().c_str()); + fname.c_str(), type, number, + file_deletion_status.ToString().c_str()); + } else { + Log(InfoLogLevel::ERROR_LEVEL, db_options_.info_log, + "[JOB %d] Failed to delete %s type=%d #%" PRIu64 " -- %s\n", + state.job_id, fname.c_str(), type, number, + file_deletion_status.ToString().c_str()); + } + if (type == kTableFile) { + event_logger_.Log() << "job" << state.job_id << "event" + << "table_file_deletion" + << "file_number" << number + << "status" << file_deletion_status.ToString(); } -#endif // ROCKSDB_LITE } // Delete old info log files.