CLEANUP: listener/config: remove the special case for shards==1
authorWilly Tarreau <w@1wt.eu>
Fri, 3 Feb 2023 13:53:34 +0000 (14:53 +0100)
committerWilly Tarreau <w@1wt.eu>
Fri, 3 Feb 2023 17:00:21 +0000 (18:00 +0100)
In fact this case is already handled by the regular shards code, there
is no need to special-case it.

src/cfgparse.c

index 75d0b56..fc8c7f2 100644 (file)
@@ -2968,52 +2968,47 @@ init_proxies_list_stage1:
 
                        /* apply thread masks and groups to all receivers */
                        list_for_each_entry(li, &bind_conf->listeners, by_bind) {
-                               if (bind_conf->settings.shards <= 1) {
-                                       li->rx.bind_thread = thread_set_first_tmask(&bind_conf->thread_set);
-                                       li->rx.bind_tgroup = thread_set_first_group(&bind_conf->thread_set);
-                               } else {
-                                       struct listener *new_li;
-                                       int shard, shards, todo, done, bit;
-                                       ulong mask;
-
-                                       shards = bind_conf->settings.shards;
-                                       todo = my_popcountl(thread_set_first_tmask(&bind_conf->thread_set));
-
-                                       /* no more shards than total threads */
-                                       if (shards > todo)
-                                               shards = todo;
-
-                                       shard = done = bit = 0;
-                                       new_li = li;
-
-                                       while (1) {
-                                               mask = 0;
-                                               while (done < todo) {
-                                                       /* enlarge mask to cover next bit of bind_thread */
-                                                       while (!(thread_set_first_tmask(&bind_conf->thread_set) & (1UL << bit)))
-                                                               bit++;
-                                                       mask |= (1UL << bit);
+                               struct listener *new_li;
+                               int shard, shards, todo, done, bit;
+                               ulong mask;
+
+                               shards = bind_conf->settings.shards;
+                               todo = my_popcountl(thread_set_first_tmask(&bind_conf->thread_set));
+
+                               /* no more shards than total threads */
+                               if (shards > todo)
+                                       shards = todo;
+
+                               shard = done = bit = 0;
+                               new_li = li;
+
+                               while (1) {
+                                       mask = 0;
+                                       while (done < todo) {
+                                               /* enlarge mask to cover next bit of bind_thread */
+                                               while (!(thread_set_first_tmask(&bind_conf->thread_set) & (1UL << bit)))
                                                        bit++;
-                                                       done += shards;
-                                               }
+                                               mask |= (1UL << bit);
+                                               bit++;
+                                               done += shards;
+                                       }
 
-                                               new_li->rx.bind_thread = thread_set_first_tmask(&bind_conf->thread_set) & mask;
-                                               new_li->rx.bind_tgroup = thread_set_first_group(&bind_conf->thread_set);
-                                               done -= todo;
-
-                                               shard++;
-                                               if (shard >= shards)
-                                                       break;
-
-                                               /* create another listener for new shards */
-                                               new_li = clone_listener(li);
-                                               if (!new_li) {
-                                                       ha_alert("Out of memory while trying to allocate extra listener for shard %d in %s %s\n",
-                                                                shard, proxy_type_str(curproxy), curproxy->id);
-                                                       cfgerr++;
-                                                       err_code |= ERR_FATAL | ERR_ALERT;
-                                                       goto out;
-                                               }
+                                       new_li->rx.bind_thread = thread_set_first_tmask(&bind_conf->thread_set) & mask;
+                                       new_li->rx.bind_tgroup = thread_set_first_group(&bind_conf->thread_set);
+                                       done -= todo;
+
+                                       shard++;
+                                       if (shard >= shards)
+                                               break;
+
+                                       /* create another listener for new shards */
+                                       new_li = clone_listener(li);
+                                       if (!new_li) {
+                                               ha_alert("Out of memory while trying to allocate extra listener for shard %d in %s %s\n",
+                                                        shard, proxy_type_str(curproxy), curproxy->id);
+                                               cfgerr++;
+                                               err_code |= ERR_FATAL | ERR_ALERT;
+                                               goto out;
                                        }
                                }
                        }