@@ -549,80 +549,50 @@ inline int count_partitions(const app_mapper &apps)
549
549
550
550
void when_update_replicas (config_type::type t, const std::function<void (bool )> &func);
551
551
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
+ } \
577
561
} while (0 )
578
562
579
563
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
+ } \
585
575
} 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)
588
579
{
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 ());
605
592
}
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 ));
624
593
}
625
- }
594
+ };
595
+ when_update_replicas (t, action);
626
596
}
627
597
628
598
// Try to construct a replica-group by current replica-infos of a gpid
0 commit comments