Fix regression bug of Auto rolling logger when handling failures (#5622)

Summary:
Auto roll logger fails to handle file creation error in the correct way, which may expose to seg fault condition to users. Fix it.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/5622

Test Plan: Add a unit test on creating file under a non-existing directory. The test fails without the fix.

Differential Revision: D16460853

fbshipit-source-id: e96da4bef4f16db171ea04a11b2ec5a9448ddbde
main
sdong 5 years ago committed by Facebook Github Bot
parent 66b524a911
commit 5daa426a18
  1. 5
      logging/auto_roll_logger.cc
  2. 9
      logging/auto_roll_logger_test.cc

@ -46,9 +46,8 @@ AutoRollLogger::AutoRollLogger(Env* env, const std::string& dbname,
} }
GetExistingFiles(); GetExistingFiles();
ResetLogger(); ResetLogger();
s = TrimOldLogFiles(); if (status_.ok()) {
if (!status_.ok()) { status_ = TrimOldLogFiles();
status_ = s;
} }
} }

@ -635,6 +635,15 @@ TEST_F(AutoRollLoggerTest, LogFileExistence) {
delete db; delete db;
} }
TEST_F(AutoRollLoggerTest, FileCreateFailure) {
Options options;
options.max_log_file_size = 100 * 1024 * 1024;
options.db_log_dir = "/a/dir/does/not/exist/at/all";
std::shared_ptr<Logger> logger;
ASSERT_NOK(CreateLoggerFromOptions("", options, &logger));
ASSERT_TRUE(!logger);
}
} // namespace rocksdb } // namespace rocksdb
int main(int argc, char** argv) { int main(int argc, char** argv) {

Loading…
Cancel
Save