Skip to content

Commit c74542d

Browse files
committed
fix(shell)
1 parent 4e0b0b6 commit c74542d

File tree

2 files changed

+44
-9
lines changed

2 files changed

+44
-9
lines changed

src/meta/meta_data.h

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,41 @@ 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+
} \
577+
} while (0)
578+
579+
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+
} \
585+
} while (0)
586+
552587
inline void maintain_drops(/*inout*/ configuration_update_request &request, partition_configuration &pc, bool is_group_check)
553588
{
554589
auto t = request.type;

src/meta/server_state.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2095,8 +2095,10 @@ 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_drops(request, pc, true);
2099-
maintain_drops(request, pc, false);
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);
21002102

21012103
RESET_IP_AND_HOST_PORT(request.config, primary);
21022104
CLEAR_IP_AND_HOST_PORT(request.config, secondaries);
@@ -2158,7 +2160,9 @@ void server_state::downgrade_primary_to_inactive(std::shared_ptr<app_state> &app
21582160
SET_OBJ_IP_AND_HOST_PORT(request, node, pc, primary);
21592161
request.config.ballot++;
21602162
RESET_IP_AND_HOST_PORT(request.config, primary);
2161-
maintain_drops(request, pc, false);
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);
21622166

21632167
cc.stage = config_status::pending_remote_sync;
21642168
cc.pending_sync_request = req;
@@ -2295,12 +2299,8 @@ void server_state::on_update_configuration(
22952299
msg->release_ref();
22962300
return;
22972301
} else {
2298-
partition_configuration pc;
2299-
pc.hp_primary = cfg_request->hp_node;
2300-
pc.primary = cfg_request->node;
2301-
pc.hp_secondaries = cfg_request->config.hp_secondaries;
2302-
pc.secondaries = cfg_request->config.secondaries;
2303-
maintain_drops(*cfg_request, pc, false);
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);
23042304
}
23052305

23062306
if (response.err != ERR_IO_PENDING) {

0 commit comments

Comments
 (0)