]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
WIP/MEDIUM: peers: Start resynchro of a stick-table from a random bucket 20251118-peers-refactoring-4
authorChristopher Faulet <cfaulet@haproxy.com>
Tue, 18 Nov 2025 15:08:18 +0000 (16:08 +0100)
committerChristopher Faulet <cfaulet@haproxy.com>
Tue, 18 Nov 2025 15:08:18 +0000 (16:08 +0100)
include/haproxy/peers-t.h
src/peers.c

index f1ae7652ebc81cfdefc6ccc2d0491673cd2e2b58..f9a521bcf646f56c0d2c94c7396ca8f34141e0bc 100644 (file)
@@ -134,7 +134,8 @@ static forceinline char *peer_show_flags(char *buf, size_t len, const char *deli
 struct shared_table {
        struct stktable *table;       /* stick table to sync */
        struct stksess *ts;           /* next sticky session to send (only during a full resync) */
-       unsigned int bucket;          /* current bucket explored (only during a full resync) */
+       unsigned int init_bucket;     /* starting bucket (only during a full resync) */
+       unsigned int bucket;          /* current bucket (only during a full resync) */
        unsigned int resync_end;      /* date to stop resync (session with expiration beyond this date are ignored during resync) */
        int local_id;
        int remote_id;
index 3dfaae71e87f3fa73d82927c05193ddf619e9cd8..1e2537d6cc56fc43819e68a52be9d5e0513f85dd 100644 (file)
@@ -1615,7 +1615,7 @@ int peer_send_resync_updates(struct appctx *appctx, struct peer *p, struct share
        new_pushed = 1;
 
        /* This stick-table was already fully sync */
-       if (st->bucket >= CONFIG_HAP_TBL_BUCKETS)
+       if (st->ts == NULL && st->bucket == st->init_bucket && tick_isset(st->resync_end))
                goto out;
 
        /* Be sure to set the stop point to not resync infinitly */
@@ -1637,6 +1637,8 @@ int peer_send_resync_updates(struct appctx *appctx, struct peer *p, struct share
                        HA_RWLOCK_RDUNLOCK(STK_TABLE_LOCK, &st->table->buckets[st->bucket].sh_lock);
                        st->bucket++;
                        if (st->bucket >= CONFIG_HAP_TBL_BUCKETS)
+                               st->bucket = 0;
+                       if (st->bucket == st->init_bucket)
                                break;
                        goto next;
                }
@@ -2610,7 +2612,7 @@ static inline int peer_treat_awaited_msg(struct appctx *appctx, struct peer *pee
                        for (st = peer->tables; st; st = st->next) {
                                st->ts = NULL;
                                st->bucket = 0;
-                               st->resync_end = TICK_ETERNITY;
+                               st->bucket = st->init_bucket = statistical_prng_range(CONFIG_HAP_TBL_BUCKETS - 1);
                                st->flags = 0;
                        }
 
@@ -2984,7 +2986,7 @@ static inline void init_connected_peer(struct peer *peer, struct peers *peers)
                st->last_get = st->last_acked = 0;
                st->last_pushed = HA_ATOMIC_LOAD(&st->update);
                st->ts = NULL;
-               st->bucket = 0;
+               st->bucket = st->init_bucket = statistical_prng_range(CONFIG_HAP_TBL_BUCKETS - 1);
                st->resync_end = TICK_ETERNITY;
                st->flags = 0;
        }