]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: peers: Use a static variable to wait a resync on reload
authorChristopher Faulet <cfaulet@haproxy.com>
Thu, 25 Apr 2024 08:29:32 +0000 (10:29 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Thu, 25 Apr 2024 16:29:58 +0000 (18:29 +0200)
When a process is reloaded, the old process must performed a synchronisation
with the new process. To do so, the sync task notify the local peer to
proceed and waits. Internally, the sync task used PEERS_F_DONOTSTOP flag to
know it should wait. However, this flag was only set/unset in a single
function. There is no real reason to set a flag to do so. A static variable
set to 1 when the resync starts and to 0 when it is finished is enough.

include/haproxy/peers-t.h
src/peers.c

index 7ee339047a17cd146d0edc2c101cf1768780335a..85206ebeecb0b94868d7791ca481e929fd990809 100644 (file)
@@ -56,8 +56,7 @@ enum peer_learn_state {
 #define PEERS_F_RESYNC_LOCAL_FINISHED     0x00000001 /* Learn from local peer finished or no more needed */
 #define PEERS_F_RESYNC_REMOTE_FINISHED    0x00000002 /* Learn from remote peer finished or no more needed */
 #define PEERS_F_RESYNC_ASSIGN             0x00000004 /* A peer was assigned to learn our lesson */
-#define PEERS_F_DONOTSTOP                 0x00000008 /* Main table sync task block process during soft stop to push data to new process */
-/* unsued 0x00000010..0x00080000 */
+/* unsued 0x00000008..0x00080000 */
 #define PEERS_F_DBG_RESYNC_LOCALTIMEOUT   0x00100000 /* Timeout waiting for a full resync from a local node was experienced at lest once (for debugging purpose) */
 #define PEERS_F_DBG_RESYNC_REMOTETIMEOUT  0x00200000 /* Timeout waiting for a full resync from a remote node was experienced at lest once (for debugging purpose) */
 #define PEERS_F_DBG_RESYNC_LOCALABORT     0x00400000 /* Session aborted learning from a local node was experienced at lest once (for debugging purpose) */
@@ -84,12 +83,12 @@ static forceinline char *peers_show_flags(char *buf, size_t len, const char *del
        /* prologue */
        _(0);
        /* flags */
-       _(PEERS_F_RESYNC_LOCAL_FINISHED, _(PEERS_F_RESYNC_REMOTE_FINISHED, _(PEERS_F_RESYNC_ASSIGN, _(PEERS_F_DONOTSTOP,
+       _(PEERS_F_RESYNC_LOCAL_FINISHED, _(PEERS_F_RESYNC_REMOTE_FINISHED, _(PEERS_F_RESYNC_ASSIGN,
         _(PEERS_F_DBG_RESYNC_LOCALTIMEOUT, _(PEERS_F_DBG_RESYNC_REMOTETIMEOUT,
         _(PEERS_F_DBG_RESYNC_LOCALABORT, _(PEERS_F_DBG_RESYNC_REMOTEABORT,
        _(PEERS_F_DBG_RESYNC_LOCALFINISHED, _(PEERS_F_DBG_RESYNC_REMOTEFINISHED,
        _(PEERS_F_DBG_RESYNC_LOCALPARTIAL, _(PEERS_F_DBG_RESYNC_REMOTEPARTIAL,
-       _(PEERS_F_DBG_RESYNC_LOCALASSIGN, _(PEERS_F_DBG_RESYNC_REMOTEABORT))))))))))))));
+       _(PEERS_F_DBG_RESYNC_LOCALASSIGN, _(PEERS_F_DBG_RESYNC_REMOTEABORT)))))))))))));
        /* epilogue */
        _(~0U);
        return buf;
index d854780711aa996d9002795205714faca869a2a8..3e2b450b8b5c402002aed0f0c8123691b139c50e 100644 (file)
@@ -3560,7 +3560,7 @@ static void __process_stopping_peer_sync(struct task *task, struct peers *peers,
 {
        struct peer *ps;
        struct shared_table *st;
-
+       static int dont_stop = 0;
 
        /* For each peer */
        for (ps = peers->remote; ps; ps = ps->next) {
@@ -3575,7 +3575,7 @@ static void __process_stopping_peer_sync(struct task *task, struct peers *peers,
                 */
                ps->flags &= ~PEER_F_WAIT_SYNCTASK_ACK;
 
-               if ((state & TASK_WOKEN_SIGNAL) && !(peers->flags & PEERS_F_DONOTSTOP)) {
+               if ((state & TASK_WOKEN_SIGNAL) && !dont_stop) {
                        /* we're killing a connection, we must apply a random delay before
                         * retrying otherwise the other end will do the same and we can loop
                         * for a while.
@@ -3592,10 +3592,10 @@ static void __process_stopping_peer_sync(struct task *task, struct peers *peers,
 
        /* We've just received the signal */
        if (state & TASK_WOKEN_SIGNAL) {
-               if (!(peers->flags & PEERS_F_DONOTSTOP)) {
+               if (!dont_stop) {
                        /* add DO NOT STOP flag if not present */
                        _HA_ATOMIC_INC(&jobs);
-                       peers->flags |= PEERS_F_DONOTSTOP;
+                       dont_stop = 1;
 
                        /* Set resync timeout for the local peer and request a immediate reconnect */
                        peers->resync_timeout = tick_add(now_ms, MS_TO_TICKS(PEER_RESYNC_TIMEOUT));
@@ -3606,10 +3606,10 @@ static void __process_stopping_peer_sync(struct task *task, struct peers *peers,
        ps = peers->local;
        HA_SPIN_LOCK(PEER_LOCK, &ps->lock);
        if (ps->flags & PEER_F_LOCAL_TEACH_COMPLETE) {
-               if (peers->flags & PEERS_F_DONOTSTOP) {
+               if (dont_stop) {
                        /* resync of new process was complete, current process can die now */
                        _HA_ATOMIC_DEC(&jobs);
-                       peers->flags &= ~PEERS_F_DONOTSTOP;
+                       dont_stop = 0;
                        for (st = ps->tables; st ; st = st->next)
                                HA_ATOMIC_DEC(&st->table->refcnt);
                }
@@ -3639,17 +3639,17 @@ static void __process_stopping_peer_sync(struct task *task, struct peers *peers,
                        }
                        else  {
                                /* connect to the local peer if we must push a local sync */
-                               if (peers->flags & PEERS_F_DONOTSTOP) {
+                               if (dont_stop) {
                                        peer_session_create(peers, ps);
                                }
                        }
                }
                else {
                        /* Other error cases */
-                       if (peers->flags & PEERS_F_DONOTSTOP) {
+                       if (dont_stop) {
                                /* unable to resync new process, current process can die now */
                                _HA_ATOMIC_DEC(&jobs);
-                               peers->flags &= ~PEERS_F_DONOTSTOP;
+                               dont_stop = 0;
                                for (st = ps->tables; st ; st = st->next)
                                        HA_ATOMIC_DEC(&st->table->refcnt);
                        }