Skip to content

Commit 0370862

Browse files
committed
refactor(fqdn): refactor func maintain_drops to process rpc_address and rpc_hostport
1 parent c74542d commit 0370862

File tree

2 files changed

+42
-76
lines changed

2 files changed

+42
-76
lines changed

src/meta/meta_data.h

Lines changed: 37 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -549,80 +549,50 @@ inline int count_partitions(const app_mapper &apps)
549549

550550
void when_update_replicas(config_type::type t, const std::function<void(bool)> &func);
551551

552-
#define MAINTAIN_DROP_NODE_IMPL(config, node_value, drops_field, type) \
553-
do { \
554-
auto action = [&](bool is_adding) { \
555-
auto it = std::find(config.drops_field.begin(), config.drops_field.end(), node_value); \
556-
if (is_adding) { \
557-
if (it != config.drops_field.end()) { \
558-
config.drops_field.erase(it); \
559-
} \
560-
} else { \
561-
CHECK(it == config.drops_field.end(), \
562-
"the node({}) cannot be in drops set before this update", node_value); \
563-
config.drops_field.push_back(node_value); \
564-
if (config.drops_field.size() > 3) { \
565-
config.drops_field.erase(config.drops_field.begin()); \
566-
} \
567-
} \
568-
}; \
569-
when_update_replicas(type, action); \
570-
} while (0)
571-
572-
#define MAINTAIN_DROP_NODE(config, node, drops_field, type) \
573-
do { \
574-
if (config.node) { \
575-
MAINTAIN_DROP_NODE_IMPL(config, config.node, drops_field, type); \
576-
} \
552+
#define MAINTAIN_DROP_NODE(obj, field, type) \
553+
do { \
554+
auto obj_copy = obj; \
555+
if (obj.primary) { \
556+
maintain_drops(obj_copy.field, obj.primary, type); \
557+
} \
558+
if (obj.__isset.hp_primary && obj.hp_primary) { \
559+
maintain_drops(obj_copy.hp_##field, obj.hp_primary, type); \
560+
} \
577561
} while (0)
578562

579563

580-
#define MAINTAIN_DROP_NODES(config, nodes, drops_field, type) \
581-
do { \
582-
for (const auto &secondary : config.nodes) { \
583-
MAINTAIN_DROP_NODE_IMPL(config, secondary, drops_field, type); \
584-
} \
564+
#define MAINTAIN_DROP_NODES(obj, field, type) \
565+
do { \
566+
auto obj_copy = obj; \
567+
for (const auto &secondary : obj.secondaries) { \
568+
maintain_drops(obj_copy.field, secondary, type); \
569+
} \
570+
if (obj.__isset.hp_secondaries) { \
571+
for (const auto &secondary : obj.hp_secondaries) { \
572+
maintain_drops(obj_copy.hp_##field, secondary, type); \
573+
} \
574+
} \
585575
} while (0)
586-
587-
inline void maintain_drops(/*inout*/ configuration_update_request &request, partition_configuration &pc, bool is_group_check)
576+
577+
template <typename T>
578+
void maintain_drops(/*inout*/ std::vector<T> &drops, const T &node, config_type::type t)
588579
{
589-
auto t = request.type;
590-
auto make_proc = [](auto &drops, const auto &node) {
591-
return [&drops, &node](bool is_adding) {
592-
auto it = std::find(drops.begin(), drops.end(), node);
593-
if (is_adding) {
594-
if (it != drops.end()) {
595-
drops.erase(it);
596-
}
597-
} else {
598-
CHECK(it == drops.end(),
599-
"the node({}) cannot be in drops set before this update",
600-
node);
601-
drops.push_back(node);
602-
if (drops.size() > 3) {
603-
drops.erase(drops.begin());
604-
}
580+
auto action = [&drops, &node](bool is_adding) {
581+
auto it = std::find(drops.begin(), drops.end(), node);
582+
if (is_adding) {
583+
if (it != drops.end()) {
584+
drops.erase(it);
585+
}
586+
} else {
587+
CHECK(
588+
it == drops.end(), "the node({}) cannot be in drops set before this update", node);
589+
drops.push_back(node);
590+
if (drops.size() > 3) {
591+
drops.erase(drops.begin());
605592
}
606-
};
607-
};
608-
609-
if (is_group_check) {
610-
for (const auto &secondary : pc.hp_secondaries) {
611-
when_update_replicas(t, make_proc(request.config.hp_last_drops, secondary));
612-
}
613-
614-
for (const auto &secondary : pc.secondaries) {
615-
when_update_replicas(t, make_proc(request.config.last_drops, secondary));
616-
}
617-
} else {
618-
if (pc.hp_primary) {
619-
when_update_replicas(t, make_proc(request.config.hp_last_drops, pc.hp_primary));
620-
}
621-
622-
if (pc.primary) {
623-
when_update_replicas(t, make_proc(request.config.last_drops, pc.primary));
624593
}
625-
}
594+
};
595+
when_update_replicas(t, action);
626596
}
627597

628598
// Try to construct a replica-group by current replica-infos of a gpid

src/meta/server_state.cpp

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2095,10 +2095,9 @@ void server_state::drop_partition(std::shared_ptr<app_state> &app, int pidx)
20952095
request.type = config_type::CT_DROP_PARTITION;
20962096
SET_OBJ_IP_AND_HOST_PORT(request, node, pc, primary);
20972097

2098-
MAINTAIN_DROP_NODES(request.config, hp_secondaries, hp_last_drops, request.type);
2099-
MAINTAIN_DROP_NODES(request.config, secondaries, last_drops, request.type);
2100-
MAINTAIN_DROP_NODE(request.config, hp_primary, hp_last_drops, request.type);
2101-
MAINTAIN_DROP_NODE(request.config, primary, last_drops, request.type);
2098+
request.config = pc;
2099+
MAINTAIN_DROP_NODES(request.config, last_drops, request.type);
2100+
MAINTAIN_DROP_NODE(request.config, last_drops, request.type);
21022101

21032102
RESET_IP_AND_HOST_PORT(request.config, primary);
21042103
CLEAR_IP_AND_HOST_PORT(request.config, secondaries);
@@ -2160,9 +2159,7 @@ void server_state::downgrade_primary_to_inactive(std::shared_ptr<app_state> &app
21602159
SET_OBJ_IP_AND_HOST_PORT(request, node, pc, primary);
21612160
request.config.ballot++;
21622161
RESET_IP_AND_HOST_PORT(request.config, primary);
2163-
MAINTAIN_DROP_NODE(request.config, hp_primary, hp_last_drops, request.type);
2164-
MAINTAIN_DROP_NODE(request.config, primary, last_drops, request.type);
2165-
// maintain_drops(request, pc, false);
2162+
MAINTAIN_DROP_NODE(request.config, last_drops, request.type);
21662163

21672164
cc.stage = config_status::pending_remote_sync;
21682165
cc.pending_sync_request = req;
@@ -2299,8 +2296,7 @@ void server_state::on_update_configuration(
22992296
msg->release_ref();
23002297
return;
23012298
} else {
2302-
MAINTAIN_DROP_NODES(cfg_request->config, hp_node, hp_last_drops, cfg_request->type);
2303-
MAINTAIN_DROP_NODES(cfg_request->config, node, last_drops, cfg_request->type);
2299+
MAINTAIN_DROP_NODES(cfg_request->config, last_drops, cfg_request->type);
23042300
}
23052301

23062302
if (response.err != ERR_IO_PENDING) {

0 commit comments

Comments
 (0)