mirror of
http://git.haproxy.org/git/haproxy.git/
synced 2024-12-26 06:32:13 +00:00
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.
This commit is contained in:
parent
c904f7b440
commit
45f4698725
19
src/peers.c
19
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) {
|
else if (msg_head[1] == PEER_MSG_CTRL_RESYNCFINISHED) {
|
||||||
TRACE_PROTO("received control message", PEERS_EV_CTRLMSG,
|
TRACE_PROTO("received control message", PEERS_EV_CTRLMSG,
|
||||||
NULL, &msg_head[1], peers->local->id, peer->id);
|
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->learnstate = PEER_LR_ST_FINISHED;
|
||||||
peer->flags |= PEER_F_WAIT_SYNCTASK_ACK;
|
peer->flags |= PEER_F_WAIT_SYNCTASK_ACK;
|
||||||
task_wakeup(peers->sync_task, TASK_WOKEN_MSG);
|
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) {
|
else if (msg_head[1] == PEER_MSG_CTRL_RESYNCPARTIAL) {
|
||||||
TRACE_PROTO("received control message", PEERS_EV_CTRLMSG,
|
TRACE_PROTO("received control message", PEERS_EV_CTRLMSG,
|
||||||
NULL, &msg_head[1], peers->local->id, peer->id);
|
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->learnstate = PEER_LR_ST_FINISHED;
|
||||||
peer->flags |= (PEER_F_LEARN_NOTUP2DATE|PEER_F_WAIT_SYNCTASK_ACK);
|
peer->flags |= (PEER_F_LEARN_NOTUP2DATE|PEER_F_WAIT_SYNCTASK_ACK);
|
||||||
task_wakeup(peers->sync_task, TASK_WOKEN_MSG);
|
task_wakeup(peers->sync_task, TASK_WOKEN_MSG);
|
||||||
@ -2641,13 +2641,12 @@ static inline int peer_send_msgs(struct appctx *appctx,
|
|||||||
{
|
{
|
||||||
int repl;
|
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->learnstate == PEER_LR_ST_ASSIGNED) {
|
||||||
if (!peer->local) {
|
BUG_ON(peer->local);
|
||||||
repl = peer_send_resync_reqmsg(appctx, peer, peers);
|
repl = peer_send_resync_reqmsg(appctx, peer, peers);
|
||||||
if (repl <= 0)
|
if (repl <= 0)
|
||||||
return repl;
|
return repl;
|
||||||
}
|
|
||||||
peer->learnstate = PEER_LR_ST_PROCESSING;
|
peer->learnstate = PEER_LR_ST_PROCESSING;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3136,6 +3135,10 @@ switchstate:
|
|||||||
if (curpeer->flags & PEER_F_WAIT_SYNCTASK_ACK)
|
if (curpeer->flags & PEER_F_WAIT_SYNCTASK_ACK)
|
||||||
goto out;
|
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);
|
reql = peer_recv_msg(appctx, (char *)msg_head, sizeof msg_head, &msg_len, &totl);
|
||||||
if (reql <= 0) {
|
if (reql <= 0) {
|
||||||
if (reql == -1)
|
if (reql == -1)
|
||||||
|
Loading…
Reference in New Issue
Block a user