Skip to content

Commit

Permalink
fmt 2
Browse files Browse the repository at this point in the history
  • Loading branch information
acelyc111 committed Mar 4, 2024
1 parent 8f1e2b7 commit 6d1f66f
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 30 deletions.
5 changes: 2 additions & 3 deletions src/replica/replica.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 0 additions & 2 deletions src/replica/replica.h
Original file line number Diff line number Diff line change
Expand Up @@ -286,8 +286,6 @@ class replica : public serverlet<replica>, 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;
Expand Down
2 changes: 1 addition & 1 deletion src/replica/replica_disk_migrator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/replica/replica_stub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions src/replica/replication_app_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down
3 changes: 3 additions & 0 deletions src/replica/replication_app_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ class replica_init_info

class replica_app_info
{
public:
static const std::string kAppInfo;

private:
app_info *_app;

Expand Down
6 changes: 4 additions & 2 deletions src/replica/test/replica_disk_migrate_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
4 changes: 2 additions & 2 deletions src/replica/test/replica_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
36 changes: 17 additions & 19 deletions src/shell/commands/local_partition_split.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string> 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;
Expand All @@ -144,8 +143,6 @@ bool local_partition_split(command_executor *e, shell_context *sc, arguments arg
};
std::vector<tsp> to_split_partitions;
std::set<uint32_t> exist_app_ids;
// "1.0.pegasus"
static const std::string kAppInfo = ".app-info";
std::set<std::string> 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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 6d1f66f

Please sign in to comment.