diff --git a/src/replica/replica_stub.cpp b/src/replica/replica_stub.cpp index 5bad341142..6b21ba83fd 100644 --- a/src/replica/replica_stub.cpp +++ b/src/replica/replica_stub.cpp @@ -486,11 +486,11 @@ std::vector replica_stub::get_all_disk_dirs() // TaskCode: LPC_REPLICATION_INIT_LOAD // ThreadPool: THREAD_POOL_LOCAL_APP void replica_stub::load_replica(dir_node *dn, - const std::string &dir, + const std::string &replica_dir, utils::ex_lock &reps_lock, replicas &reps) { - LOG_INFO("loading replica: tag={}, dir={}", dn->tag, dir); + LOG_INFO("loading replica: tag={}, replica_dir={}", dn->tag, replica_dir); const auto *const worker = task::get_current_worker2(); if (worker != nullptr) { @@ -500,17 +500,17 @@ void replica_stub::load_replica(dir_node *dn, "among multiple threads"); } - auto rep = load_replica(dn, dir.c_str()); + auto rep = load_replica(dn, replica_dir); if (rep == nullptr) { return; } - LOG_INFO("{}@{}: load replica successfully, tag={}, dir={}, last_durable_decree={}, " + LOG_INFO("{}@{}: load replica successfully, tag={}, replica_dir={}, last_durable_decree={}, " "last_committed_decree={}, last_prepared_decree={}", rep->get_gpid(), dsn_primary_host_port(), dn->tag, - dir, + replica_dir, rep->last_durable_decree(), rep->last_committed_decree(), rep->last_prepared_decree()); @@ -1972,7 +1972,7 @@ void replica_stub::open_replica( _primary_host_port_cache, group_check ? "with" : "without", dir); - rep = load_replica(dn, dir.c_str()); + rep = load_replica(dn, dir); // if load data failed, re-open the `*.ori` folder which is the origin replica dir of disk // migration @@ -1997,7 +1997,7 @@ void replica_stub::open_replica( boost::replace_first( origin_dir, replica_disk_migrator::kReplicaDirOriginSuffix, ""); dsn::utils::filesystem::rename_path(origin_tmp_dir, origin_dir); - rep = load_replica(origin_dn, origin_dir.c_str()); + rep = load_replica(origin_dn, origin_dir); FAIL_POINT_INJECT_F("mock_replica_load", [&](std::string_view) -> void {}); } @@ -2225,7 +2225,7 @@ bool replica_stub::validate_replica_dir(const std::string &dir, return true; } -replica_ptr replica_stub::load_replica(dir_node *dn, const char *replica_dir) +replica_ptr replica_stub::load_replica(dir_node *dn, const std::string &replica_dir) { FAIL_POINT_INJECT_F("mock_replica_load", [&](std::string_view) -> replica * { return nullptr; }); @@ -2234,7 +2234,7 @@ replica_ptr replica_stub::load_replica(dir_node *dn, const char *replica_dir) gpid pid; std::string hint_message; if (!validate_replica_dir(replica_dir, ai, pid, hint_message)) { - LOG_ERROR("invalid replica dir '{}', hint: {}", replica_dir, hint_message); + LOG_ERROR("invalid replica dir '{}', hint={}", replica_dir, hint_message); return nullptr; } @@ -2244,7 +2244,11 @@ replica_ptr replica_stub::load_replica(dir_node *dn, const char *replica_dir) auto *rep = new replica(this, pid, ai, dn, false); const auto err = rep->initialize_on_load(); if (err != ERR_OK) { - LOG_ERROR("{}: load replica failed, err = {}", rep->name(), err); + LOG_ERROR("{}: load replica failed, tag={}, replica_dir={}, err={}", + rep->name(), + dn->tag, + replica_dir, + err); delete rep; rep = nullptr; @@ -2258,7 +2262,7 @@ replica_ptr replica_stub::load_replica(dir_node *dn, const char *replica_dir) return nullptr; } - LOG_INFO("{}: load replica succeed", rep->name()); + LOG_INFO("{}: load replica succeed, tag={}, replica_dir={}", rep->name(), dn->tag, replica_dir); return rep; } diff --git a/src/replica/replica_stub.h b/src/replica/replica_stub.h index 2a4c796075..dc6ac4074e 100644 --- a/src/replica/replica_stub.h +++ b/src/replica/replica_stub.h @@ -393,14 +393,16 @@ class replica_stub : public serverlet, public ref_counter parse_replica_dir_name(const std::string &dir_name, gpid &pid, std::string &app_type); // Load an existing replica which is located in `dn` with `replica_dir`. Usually each - // different `dn` represents a unique disk. `dir` is the absolute path of the directory - // for a replica. - virtual replica_ptr load_replica(dir_node *dn, const char *replica_dir); + // different `dn` represents a unique disk. `replica_dir` is the absolute path of the + // directory for a replica. + virtual replica_ptr load_replica(dir_node *dn, const std::string &replica_dir); // The same as the above `load_replica` function, except that this function is to load // each replica to `reps` with protection from `reps_lock`. - void - load_replica(dir_node *dn, const std::string &dir, utils::ex_lock &reps_lock, replicas &reps); + void load_replica(dir_node *dn, + const std::string &replica_dir, + utils::ex_lock &reps_lock, + replicas &reps); // Load all replicas simultaneously from all disks to `reps`. void load_replicas(replicas &reps); diff --git a/src/replica/test/load_replicas_test.cpp b/src/replica/test/load_replicas_test.cpp index 1a5ee710c3..a6ca7aecc3 100644 --- a/src/replica/test/load_replicas_test.cpp +++ b/src/replica/test/load_replicas_test.cpp @@ -122,11 +122,11 @@ class mock_load_replica : public replica_stub } private: - void load_replica_for_test(dir_node *dn, const char *dir, replica_ptr &rep) + void load_replica_for_test(dir_node *dn, const std::string &replica_dir, replica_ptr &rep) { - ASSERT_TRUE(utils::filesystem::directory_exists(dir)); + ASSERT_TRUE(utils::filesystem::directory_exists(replica_dir)); - const auto &dir_name = get_replica_dir_name(dir); + const auto &dir_name = get_replica_dir_name(replica_dir); gpid pid; std::string app_type; @@ -165,7 +165,7 @@ class mock_load_replica : public replica_stub } // Check the absolute dir of this replica. - ASSERT_EQ(dn->replica_dir("pegasus", pid), dir); + ASSERT_EQ(dn->replica_dir("pegasus", pid), replica_dir); app_info ai; ai.app_type = "pegasus"; @@ -180,10 +180,10 @@ class mock_load_replica : public replica_stub } // Mock the process of loading a replica. - replica_ptr load_replica(dir_node *dn, const char *dir) override + replica_ptr load_replica(dir_node *dn, const std::string &replica_dir) override { replica_ptr rep; - load_replica_for_test(dn, dir, rep); + load_replica_for_test(dn, replica_dir, rep); return rep; }