提交 4d913cfb 编写于 作者: Y Yueh-Hsuan Chiang

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
上级 983c93d7
......@@ -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);
......
......@@ -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) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册