From 3cc594e05c7d745927007af9a055ca94b379d449 Mon Sep 17 00:00:00 2001 From: Christopher Faulet Date: Thu, 25 Apr 2024 10:29:32 +0200 Subject: [PATCH] MINOR: peers: Use a static variable to wait a resync on reload 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 | 7 +++---- src/peers.c | 18 +++++++++--------- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/include/haproxy/peers-t.h b/include/haproxy/peers-t.h index 7ee339047a..85206ebeec 100644 --- a/include/haproxy/peers-t.h +++ b/include/haproxy/peers-t.h @@ -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; diff --git a/src/peers.c b/src/peers.c index 2fab8bfadd..29d3684e2c 100644 --- a/src/peers.c +++ b/src/peers.c @@ -3565,7 +3565,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) { @@ -3580,7 +3580,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. @@ -3597,10 +3597,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)); @@ -3611,10 +3611,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); } @@ -3644,17 +3644,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); }