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) {