From 641cc8d541685cad1629bd99bc08ca958458d456 Mon Sep 17 00:00:00 2001 From: Yanqin Jin Date: Mon, 10 Jun 2019 15:53:46 -0700 Subject: [PATCH] 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 --- db/db_impl/db_impl_secondary.cc | 35 +++++---------------------------- 1 file changed, 5 insertions(+), 30 deletions(-) diff --git a/db/db_impl/db_impl_secondary.cc b/db/db_impl/db_impl_secondary.cc index eb8c4c9873..2737df0ae8 100644 --- a/db/db_impl/db_impl_secondary.cc +++ b/db/db_impl/db_impl_secondary.cc @@ -521,39 +521,14 @@ Status DB::OpenAsSecondary( } DBOptions tmp_opts(db_options); + Status s; if (nullptr == tmp_opts.info_log) { - Env* env = tmp_opts.env; - assert(env != nullptr); - std::string secondary_abs_path; - 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); - } + s = CreateLoggerFromOptions(secondary_path, tmp_opts, &tmp_opts.info_log); + if (!s.ok()) { + tmp_opts.info_log = nullptr; } } - assert(tmp_opts.info_log != nullptr); - handles->clear(); DBImplSecondary* impl = new DBImplSecondary(tmp_opts, dbname); impl->versions_.reset(new ReactiveVersionSet( @@ -563,7 +538,7 @@ Status DB::OpenAsSecondary( impl->column_family_memtables_.reset( new ColumnFamilyMemTablesImpl(impl->versions_->GetColumnFamilySet())); impl->mutex_.Lock(); - Status s = impl->Recover(column_families, true, false, false); + s = impl->Recover(column_families, true, false, false); if (s.ok()) { for (auto cf : column_families) { auto cfd =