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.
This commit is contained in:
Christopher Faulet 2024-04-25 10:29:32 +02:00
parent b328edbeab
commit 3cc594e05c
2 changed files with 12 additions and 13 deletions

View 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;

View File

@ -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);
}