From 6d1f66fb0f4f2fd74e1bdbccebf072584586ecfd Mon Sep 17 00:00:00 2001 From: Yingchun Lai Date: Mon, 4 Mar 2024 19:34:49 +0800 Subject: [PATCH] fmt 2 --- src/replica/replica.cpp | 5 ++- src/replica/replica.h | 2 -- src/replica/replica_disk_migrator.cpp | 2 +- src/replica/replica_stub.cpp | 2 +- src/replica/replication_app_base.cpp | 1 + src/replica/replication_app_base.h | 3 ++ .../test/replica_disk_migrate_test.cpp | 6 ++-- src/replica/test/replica_test.cpp | 4 +-- src/shell/commands/local_partition_split.cpp | 36 +++++++++---------- 9 files changed, 31 insertions(+), 30 deletions(-) diff --git a/src/replica/replica.cpp b/src/replica/replica.cpp index 4c4ddbcff9..d73d03c16d 100644 --- a/src/replica/replica.cpp +++ b/src/replica/replica.cpp @@ -265,8 +265,6 @@ METRIC_DEFINE_counter(replica, namespace dsn { namespace replication { -const std::string replica::kAppInfo = ".app-info"; - replica::replica(replica_stub *stub, gpid gpid, const app_info &app, @@ -693,7 +691,8 @@ uint32_t replica::query_data_version() const error_code replica::store_app_info(app_info &info, const std::string &path) { replica_app_info new_info((app_info *)&info); - const auto &info_path = path.empty() ? utils::filesystem::path_combine(_dir, kAppInfo) : path; + const auto &info_path = + path.empty() ? utils::filesystem::path_combine(_dir, replica_app_info::kAppInfo) : path; auto err = new_info.store(info_path); if (dsn_unlikely(err != ERR_OK)) { LOG_ERROR_PREFIX("failed to save app_info to {}, error = {}", info_path, err); diff --git a/src/replica/replica.h b/src/replica/replica.h index 83e78105aa..3053c0ec2a 100644 --- a/src/replica/replica.h +++ b/src/replica/replica.h @@ -286,8 +286,6 @@ class replica : public serverlet, public ref_counter, public replica_ba METRIC_DEFINE_INCREMENT(backup_file_upload_successful_count) METRIC_DEFINE_INCREMENT_BY(backup_file_upload_total_bytes) - static const std::string kAppInfo; - protected: // this method is marked protected to enable us to mock it in unit tests. virtual decree max_gced_decree_no_lock() const; diff --git a/src/replica/replica_disk_migrator.cpp b/src/replica/replica_disk_migrator.cpp index 0017c58720..47d48d0669 100644 --- a/src/replica/replica_disk_migrator.cpp +++ b/src/replica/replica_disk_migrator.cpp @@ -266,7 +266,7 @@ bool replica_disk_migrator::migrate_replica_app_info(const replica_disk_migrate_ const auto &store_info_err = _replica->store_app_info( _replica->_app_info, - utils::filesystem::path_combine(_target_replica_dir, replica::kAppInfo)); + utils::filesystem::path_combine(_target_replica_dir, replica_app_info::kAppInfo)); if (store_info_err != ERR_OK) { LOG_ERROR_PREFIX("disk migration(origin={}, target={}) stores app info failed({})", req.origin_disk, diff --git a/src/replica/replica_stub.cpp b/src/replica/replica_stub.cpp index 06a6bc48a5..313ce775be 100644 --- a/src/replica/replica_stub.cpp +++ b/src/replica/replica_stub.cpp @@ -1927,7 +1927,7 @@ replica *replica_stub::load_replica(dir_node *dn, const char *dir) dsn::app_info info; replica_app_info info2(&info); - std::string path = utils::filesystem::path_combine(dir, replica::kAppInfo); + std::string path = utils::filesystem::path_combine(dir, replica_app_info::kAppInfo); auto err = info2.load(path); if (ERR_OK != err) { LOG_ERROR("load app-info from {} failed, err = {}", path, err); diff --git a/src/replica/replication_app_base.cpp b/src/replica/replication_app_base.cpp index 4157d7c5ec..668ef4e91f 100644 --- a/src/replica/replication_app_base.cpp +++ b/src/replica/replication_app_base.cpp @@ -68,6 +68,7 @@ namespace dsn { namespace replication { +const std::string replica_app_info::kAppInfo = ".app-info"; const std::string replica_init_info::kInitInfo = ".init-info"; const std::string kms_info::kKmsInfo = ".kms-info"; diff --git a/src/replica/replication_app_base.h b/src/replica/replication_app_base.h index 1280794f5a..6d2408ee49 100644 --- a/src/replica/replication_app_base.h +++ b/src/replica/replication_app_base.h @@ -76,6 +76,9 @@ class replica_init_info class replica_app_info { +public: + static const std::string kAppInfo; + private: app_info *_app; diff --git a/src/replica/test/replica_disk_migrate_test.cpp b/src/replica/test/replica_disk_migrate_test.cpp index 2436b83521..ce2ed30d42 100644 --- a/src/replica/test/replica_disk_migrate_test.cpp +++ b/src/replica/test/replica_disk_migrate_test.cpp @@ -251,8 +251,10 @@ TEST_P(replica_disk_migrate_test, disk_migrate_replica_run) request.target_disk, request.pid, replica_init_info::kInitInfo); - const std::string kTargetAppInfoFile = fmt::format( - "./{}/{}.replica.disk.migrate.tmp/{}", request.target_disk, request.pid, replica::kAppInfo); + const std::string kTargetAppInfoFile = fmt::format("./{}/{}.replica.disk.migrate.tmp/{}", + request.target_disk, + request.pid, + replica_app_info::kAppInfo); init_migration_target_dir(fake_migrate_rpc); ASSERT_TRUE(utils::filesystem::directory_exists(kTargetDataDir)); diff --git a/src/replica/test/replica_test.cpp b/src/replica/test/replica_test.cpp index fa6373c265..c97ba945da 100644 --- a/src/replica/test/replica_test.cpp +++ b/src/replica/test/replica_test.cpp @@ -226,8 +226,8 @@ class replica_test : public replica_test_base dsn::app_info info; replica_app_info replica_info(&info); - auto path = dsn::utils::filesystem::path_combine(_mock_replica->_dir, - dsn::replication::replica::kAppInfo); + auto path = dsn::utils::filesystem::path_combine( + _mock_replica->_dir, dsn::replication::replica_app_info::kAppInfo); std::cout << "the path of .app-info file is " << path << std::endl; // load new max_replica_count from file diff --git a/src/shell/commands/local_partition_split.cpp b/src/shell/commands/local_partition_split.cpp index 3c66a659de..91ba589b78 100644 --- a/src/shell/commands/local_partition_split.cpp +++ b/src/shell/commands/local_partition_split.cpp @@ -115,27 +115,26 @@ bool local_partition_split(command_executor *e, shell_context *sc, arguments arg return false; } - static const std::string data_dir_postfix("/replica/reps"); - static const std::string split_dir_postfix("split"); for (const auto &src_data_dir : src_data_dirs) { std::vector replica_dirs; - const auto data_dir_replica_dirs = src_data_dir + data_dir_postfix; - const auto split_data_dir_replica_dirs = src_data_dir + split_dir_postfix; - if (!dsn::utils::filesystem::get_subdirectories( - data_dir_replica_dirs, replica_dirs, false)) { + const auto kDataDirReplicaDirs = src_data_dir + "/replica/reps"; + const auto kSplitDataDirReplicaDirs = src_data_dir + "split"; + + // Find all replica directories. + if (!dsn::utils::filesystem::get_subdirectories(kDataDirReplicaDirs, replica_dirs, false)) { fmt::print(stderr, "invalid command, get sub-directories from '{}' failed\n", - data_dir_replica_dirs); + kDataDirReplicaDirs); continue; } - // Create split directory. - if (!dsn::utils::filesystem::create_directory(split_data_dir_replica_dirs)) { - fmt::print(stderr, "create split directory {} failed\n", split_data_dir_replica_dirs); + // Create split temporary directory. + if (!dsn::utils::filesystem::create_directory(kSplitDataDirReplicaDirs)) { + fmt::print(stderr, "create split directory '{}' failed\n", kSplitDataDirReplicaDirs); continue; } - // Gather replicas to split. + // Gather partitions to split. struct tsp { std::string replica_dir; @@ -144,8 +143,6 @@ bool local_partition_split(command_executor *e, shell_context *sc, arguments arg }; std::vector to_split_partitions; std::set exist_app_ids; - // "1.0.pegasus" - static const std::string kAppInfo = ".app-info"; std::set ordered_replica_dirs(replica_dirs.begin(), replica_dirs.end()); for (const auto &replica_dir : ordered_replica_dirs) { auto fname = dsn::utils::filesystem::get_file_name(replica_dir); @@ -193,7 +190,8 @@ bool local_partition_split(command_executor *e, shell_context *sc, arguments arg dsn::app_info info; dsn::replication::replica_app_info info2(&info); - std::string path = dsn::utils::filesystem::path_combine(replica_dir, kAppInfo); + std::string path = dsn::utils::filesystem::path_combine( + replica_dir, dsn::replication::replica_app_info::kAppInfo); auto err = info2.load(path); if (dsn::ERR_OK != err) { fmt::print(stderr, "load app-info from {} failed, err = {}\n", path, err); @@ -328,7 +326,7 @@ bool local_partition_split(command_executor *e, shell_context *sc, arguments arg for (int i = 0; i < kSplitCount; i++) { // Split temporary dir. auto dst_tmp_rdb_dir = fmt::format("{}/{}.{}.pegasus", - split_data_dir_replica_dirs, + kSplitDataDirReplicaDirs, dst_app_id, tsp.pidx + i * tsp.ai.partition_count); @@ -419,7 +417,7 @@ bool local_partition_split(command_executor *e, shell_context *sc, arguments arg for (int i = 0; i < kSplitCount; i++) { const auto new_data_dir_replica_dirs = fmt::format("{}/{}.{}.pegasus", - data_dir_replica_dirs, + kDataDirReplicaDirs, dst_app_id, tsp.pidx + i * tsp.ai.partition_count); // Create the new directory. @@ -452,7 +450,7 @@ bool local_partition_split(command_executor *e, shell_context *sc, arguments arg _meta_cf = handles_opened[1]; const auto dst_tmp_rdb_dir = fmt::format("{}/{}.{}.pegasus", - split_data_dir_replica_dirs, + kSplitDataDirReplicaDirs, dst_app_id, tsp.pidx + i * tsp.ai.partition_count); if (dsn::utils::filesystem::directory_exists(dst_tmp_rdb_dir)) { @@ -537,8 +535,8 @@ bool local_partition_split(command_executor *e, shell_context *sc, arguments arg // new_ai.create_second = dsn_now_s(); // TODO(yingchun): all // partitions must be the same! dsn::replication::replica_app_info rai(&new_ai); - const auto rai_path = - dsn::utils::filesystem::path_combine(new_data_dir_replica_dirs, kAppInfo); + const auto rai_path = dsn::utils::filesystem::path_combine( + new_data_dir_replica_dirs, dsn::replication::replica_app_info::kAppInfo); err = rai.store(rai_path.c_str()); if (err != dsn::ERR_OK) { fmt::print(stderr, "{}: write replica_app_info '{}' failed\n", err, rai_path);