MINOR: peers: Split resync process function to separate running/stopping states

The function responsible to deal with resynchro between all peers is now split
in two subfunctions. The first one is used when HAProxy is running while the
other one is used in soft-stop case.

This patch is required to be able to refactor locking mechanism of the peers.
This commit is contained in:
Christopher Faulet 2024-03-22 14:20:32 +01:00
parent 98583c4256
commit 4078893049

View File

@ -3403,26 +3403,15 @@ static struct appctx *peer_session_create(struct peers *peers, struct peer *peer
return NULL;
}
/*
* Task processing function to manage re-connect, peer session
* tasks wakeup on local update and heartbeat. Let's keep it exported so that it
* resolves in stack traces and "show tasks".
*/
struct task *process_peer_sync(struct task * task, void *context, unsigned int state)
static void __process_running_peer_sync(struct task *task, struct peers *peers, unsigned int state)
{
struct peers *peers = context;
struct peer *ps;
struct shared_table *st;
task->expire = TICK_ETERNITY;
/* Acquire lock for all peers of the section */
for (ps = peers->remote; ps; ps = ps->next)
HA_SPIN_LOCK(PEER_LOCK, &ps->lock);
if (!stopping) {
/* Normal case (not soft stop)*/
/* resync timeout set to TICK_ETERNITY means we just start
* a new process and timer was not initialized.
* We must arm this timer to switch to a request to a remote
@ -3571,9 +3560,21 @@ struct task *process_peer_sync(struct task * task, void *context, unsigned int s
if (!tick_is_expired(peers->resync_timeout, now_ms))
task->expire = tick_first(task->expire, peers->resync_timeout);
}
} /* !stopping */
else {
/* soft stop case */
/* Release lock for all peers of the section */
for (ps = peers->remote; ps; ps = ps->next)
HA_SPIN_UNLOCK(PEER_LOCK, &ps->lock);
}
static void __process_stopping_peer_sync(struct task *task, struct peers *peers, unsigned int state)
{
struct peer *ps;
struct shared_table *st;
/* Acquire lock for all peers of the section */
for (ps = peers->remote; ps; ps = ps->next)
HA_SPIN_LOCK(PEER_LOCK, &ps->lock);
if (state & TASK_WOKEN_SIGNAL) {
/* We've just received the signal */
if (!(peers->flags & PEERS_F_DONOTSTOP)) {
@ -3666,12 +3667,34 @@ struct task *process_peer_sync(struct task * task, void *context, unsigned int s
}
}
}
} /* stopping */
/* Release lock for all peers of the section */
for (ps = peers->remote; ps; ps = ps->next)
HA_SPIN_UNLOCK(PEER_LOCK, &ps->lock);
}
/*
* Task processing function to manage re-connect, peer session
* tasks wakeup on local update and heartbeat. Let's keep it exported so that it
* resolves in stack traces and "show tasks".
*/
struct task *process_peer_sync(struct task * task, void *context, unsigned int state)
{
struct peers *peers = context;
task->expire = TICK_ETERNITY;
if (!stopping) {
/* Normal case (not soft stop)*/
__process_running_peer_sync(task, peers, state);
}
else {
/* soft stop case */
__process_stopping_peer_sync(task, peers, state);
} /* stopping */
/* Wakeup for re-connect */
return task;
}