Use CreateLoggerFromOptions function (#5427)

Summary:
Use `CreateLoggerFromOptions` function to reduce code duplication.

Test plan (on my machine)
```
$make clean && make -j32 db_secondary_test
$KEEP_DB=1 ./db_secondary_test
```
Verify all info logs of the secondary instance are properly logged.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/5427

Differential Revision: D15748922

Pulled By: riversand963

fbshipit-source-id: bad7261df1b8373efc504f141efc7871e375a311
main
Yanqin Jin 6 years ago committed by Facebook Github Bot
parent 5efa0d6b0d
commit 641cc8d541
  1. 35
      db/db_impl/db_impl_secondary.cc

@ -521,39 +521,14 @@ Status DB::OpenAsSecondary(
} }
DBOptions tmp_opts(db_options); DBOptions tmp_opts(db_options);
Status s;
if (nullptr == tmp_opts.info_log) { if (nullptr == tmp_opts.info_log) {
Env* env = tmp_opts.env; s = CreateLoggerFromOptions(secondary_path, tmp_opts, &tmp_opts.info_log);
assert(env != nullptr); if (!s.ok()) {
std::string secondary_abs_path; tmp_opts.info_log = nullptr;
env->GetAbsolutePath(secondary_path, &secondary_abs_path);
std::string fname = InfoLogFileName(secondary_path, secondary_abs_path,
tmp_opts.db_log_dir);
env->CreateDirIfMissing(secondary_path);
if (tmp_opts.log_file_time_to_roll > 0 || tmp_opts.max_log_file_size > 0) {
AutoRollLogger* result = new AutoRollLogger(
env, secondary_path, tmp_opts.db_log_dir, tmp_opts.max_log_file_size,
tmp_opts.log_file_time_to_roll, tmp_opts.info_log_level);
Status s = result->GetStatus();
if (!s.ok()) {
delete result;
} else {
tmp_opts.info_log.reset(result);
}
}
if (nullptr == tmp_opts.info_log) {
env->RenameFile(
fname, OldInfoLogFileName(secondary_path, env->NowMicros(),
secondary_abs_path, tmp_opts.db_log_dir));
Status s = env->NewLogger(fname, &(tmp_opts.info_log));
if (tmp_opts.info_log != nullptr) {
tmp_opts.info_log->SetInfoLogLevel(tmp_opts.info_log_level);
}
} }
} }
assert(tmp_opts.info_log != nullptr);
handles->clear(); handles->clear();
DBImplSecondary* impl = new DBImplSecondary(tmp_opts, dbname); DBImplSecondary* impl = new DBImplSecondary(tmp_opts, dbname);
impl->versions_.reset(new ReactiveVersionSet( impl->versions_.reset(new ReactiveVersionSet(
@ -563,7 +538,7 @@ Status DB::OpenAsSecondary(
impl->column_family_memtables_.reset( impl->column_family_memtables_.reset(
new ColumnFamilyMemTablesImpl(impl->versions_->GetColumnFamilySet())); new ColumnFamilyMemTablesImpl(impl->versions_->GetColumnFamilySet()));
impl->mutex_.Lock(); impl->mutex_.Lock();
Status s = impl->Recover(column_families, true, false, false); s = impl->Recover(column_families, true, false, false);
if (s.ok()) { if (s.ok()) {
for (auto cf : column_families) { for (auto cf : column_families) {
auto cfd = auto cfd =

Loading…
Cancel
Save