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
This commit is contained in:
Yueh-Hsuan Chiang 2014-06-16 10:27:42 -07:00
parent 983c93d731
commit 4d913cfbc3
2 changed files with 13 additions and 1 deletions

View File

@ -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);

View File

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