From 4d913cfbc3e4e888fb8b04744bb98505b8224040 Mon Sep 17 00:00:00 2001 From: Yueh-Hsuan Chiang Date: Mon, 16 Jun 2014 10:27:42 -0700 Subject: [PATCH] Fix a bug causing LOG is not created when max_log_file_size is set. Summary: Fix a bug causing LOG is not created when max_log_file_size is set. This bug is reported in issue #174. Test Plan: Add TEST(AutoRollLoggerTest, LogFileExistence). make auto_roll_logger_test ./auto_roll_logger_test Reviewers: haobo, sdong, ljin, igor, igor2 Reviewed By: igor2 Subscribers: dhruba, leveldb Differential Revision: https://reviews.facebook.net/D19053 --- util/auto_roll_logger.cc | 2 +- util/auto_roll_logger_test.cc | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/util/auto_roll_logger.cc b/util/auto_roll_logger.cc index 19c2b8ca3..4812d1c4d 100644 --- a/util/auto_roll_logger.cc +++ b/util/auto_roll_logger.cc @@ -87,6 +87,7 @@ Status CreateLoggerFromOptions( env->GetAbsolutePath(dbname, &db_absolute_path); std::string fname = InfoLogFileName(dbname, db_absolute_path, db_log_dir); + env->CreateDirIfMissing(dbname); // In case it does not exist // Currently we only support roll by time-to-roll and log size if (options.log_file_time_to_roll > 0 || options.max_log_file_size > 0) { AutoRollLogger* result = new AutoRollLogger( @@ -102,7 +103,6 @@ Status CreateLoggerFromOptions( return s; } else { // Open a log file in the same directory as the db - env->CreateDir(dbname); // In case it does not exist env->RenameFile(fname, OldInfoLogFileName(dbname, env->NowMicros(), db_absolute_path, db_log_dir)); auto s = env->NewLogger(fname, logger); diff --git a/util/auto_roll_logger_test.cc b/util/auto_roll_logger_test.cc index c49894f59..c8ec459cf 100755 --- a/util/auto_roll_logger_test.cc +++ b/util/auto_roll_logger_test.cc @@ -285,6 +285,18 @@ TEST(AutoRollLoggerTest, InfoLogLevel) { inFile.close(); } +TEST(AutoRollLoggerTest, LogFileExistence) { + rocksdb::DB* db; + rocksdb::Options options; + string deleteCmd = "rm -rf " + kTestDir; + ASSERT_EQ(system(deleteCmd.c_str()), 0); + options.max_log_file_size = 100 * 1024 * 1024; + options.create_if_missing = true; + ASSERT_OK(rocksdb::DB::Open(options, kTestDir, &db)); + ASSERT_TRUE(env->FileExists(kLogFile)); + delete db; +} + } // namespace rocksdb int main(int argc, char** argv) {