From 45f46987258f051da7b2903fbd99ca154c35489b Mon Sep 17 00:00:00 2001 From: Christopher Faulet Date: Wed, 24 Apr 2024 20:55:23 +0200 Subject: [PATCH] MINOR: peers: Start learning for local peer before receiving messages A local peer assigned for leaning can immediately start to learn, without sending any request. So we can do that first, before receiving messages. This way, only PEER_LR_ST_PROCESSING state is evaluating when received messages are processed. In addition, when the resync request is sent, we are sure it is for a remote peer. --- src/peers.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/peers.c b/src/peers.c index ad9cb66e8..674cbd7f1 100644 --- a/src/peers.c +++ b/src/peers.c @@ -2532,7 +2532,7 @@ static inline int peer_treat_awaited_msg(struct appctx *appctx, struct peer *pee else if (msg_head[1] == PEER_MSG_CTRL_RESYNCFINISHED) { TRACE_PROTO("received control message", PEERS_EV_CTRLMSG, NULL, &msg_head[1], peers->local->id, peer->id); - if (peer->learnstate == PEER_LR_ST_PROCESSING || (peer->local && peer->learnstate == PEER_LR_ST_ASSIGNED)) { + if (peer->learnstate == PEER_LR_ST_PROCESSING) { peer->learnstate = PEER_LR_ST_FINISHED; peer->flags |= PEER_F_WAIT_SYNCTASK_ACK; task_wakeup(peers->sync_task, TASK_WOKEN_MSG); @@ -2542,7 +2542,7 @@ static inline int peer_treat_awaited_msg(struct appctx *appctx, struct peer *pee else if (msg_head[1] == PEER_MSG_CTRL_RESYNCPARTIAL) { TRACE_PROTO("received control message", PEERS_EV_CTRLMSG, NULL, &msg_head[1], peers->local->id, peer->id); - if (peer->learnstate == PEER_LR_ST_PROCESSING || (peer->local && peer->learnstate == PEER_LR_ST_ASSIGNED)) { + if (peer->learnstate == PEER_LR_ST_PROCESSING) { peer->learnstate = PEER_LR_ST_FINISHED; peer->flags |= (PEER_F_LEARN_NOTUP2DATE|PEER_F_WAIT_SYNCTASK_ACK); task_wakeup(peers->sync_task, TASK_WOKEN_MSG); @@ -2641,13 +2641,12 @@ static inline int peer_send_msgs(struct appctx *appctx, { int repl; - /* Need to request a resync */ + /* Need to request a resync (only possible for a remote peer at this stage) */ if (peer->learnstate == PEER_LR_ST_ASSIGNED) { - if (!peer->local) { - repl = peer_send_resync_reqmsg(appctx, peer, peers); - if (repl <= 0) - return repl; - } + BUG_ON(peer->local); + repl = peer_send_resync_reqmsg(appctx, peer, peers); + if (repl <= 0) + return repl; peer->learnstate = PEER_LR_ST_PROCESSING; } @@ -3136,6 +3135,10 @@ switchstate: if (curpeer->flags & PEER_F_WAIT_SYNCTASK_ACK) goto out; + /* local peer is assigned of a lesson, start it */ + if (curpeer->learnstate == PEER_LR_ST_ASSIGNED && curpeer->local) + curpeer->learnstate = PEER_LR_ST_PROCESSING; + reql = peer_recv_msg(appctx, (char *)msg_head, sizeof msg_head, &msg_len, &totl); if (reql <= 0) { if (reql == -1)