From f80f1635ecdcd998460345c726949a779ccbfb6e Mon Sep 17 00:00:00 2001 From: Christopher Faulet Date: Wed, 24 Apr 2024 09:32:55 +0200 Subject: [PATCH] MINOR: peers: Don't set TEACH flags on a peer from the sync task The TEACH flags only concerns the peer applet. There is no reason to set it from the sync task. It is confusing. And at the end, after some refactoring/fixes, setting these flags directly from the peer applet will allow us to immediatly performing the corresponding teach processing, while for now we must wait the sync task acknowledges the changes. --- src/peers.c | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/src/peers.c b/src/peers.c index bd34b4485..cd7366a78 100644 --- a/src/peers.c +++ b/src/peers.c @@ -1073,6 +1073,9 @@ void __peer_session_deinit(struct peer *peer) peer->remote_table = peer->last_local_table = peer->stop_local_table = NULL; peer->appctx = NULL; + /* reset teaching flags to 0 */ + peer->flags &= PEER_TEACH_RESET; + /* Mark peer as released */ peer->flags &= PEER_STATE_RESET; peer->flags |= PEER_F_ST_RELEASED; @@ -2845,6 +2848,9 @@ static inline void init_accepted_peer(struct peer *peer, struct peers *peers) /* Init confirm counter */ peer->confirm = 0; + /* reset teaching flags to 0 */ + peer->flags &= PEER_TEACH_RESET; + peer->flags &= PEER_STATE_RESET; peer->flags |= PEER_F_ST_ACCEPTED; @@ -2927,6 +2933,15 @@ static inline void init_connected_peer(struct peer *peer, struct peers *peers) /* Init confirm counter */ peer->confirm = 0; + /* reset teaching flags to 0 */ + peer->flags &= PEER_TEACH_RESET; + + if (peer->local) { + /* flag to start to teach lesson */ + peer->flags |= PEER_F_TEACH_PROCESS; + + } + peer->flags &= PEER_STATE_RESET; peer->flags |= PEER_F_ST_CONNECTED; } @@ -3388,11 +3403,9 @@ static void __process_peer_state(struct peers *peers, struct peer *peer) /* reschedule a resync */ peers->resync_timeout = tick_add(now_ms, MS_TO_TICKS(5000)); } - peer->flags &= PEER_TEACH_RESET; peer->flags &= PEER_LEARN_RESET; } if (peer->flags & PEER_F_ST_ACCEPTED) { - peer->flags &= PEER_TEACH_RESET; peer->flags &= PEER_LEARN_RESET; /* if current peer is local */ @@ -3418,13 +3431,9 @@ static void __process_peer_state(struct peers *peers, struct peer *peer) peer->flags &= PEER_TEACH_RESET; peer->flags &= PEER_LEARN_RESET; - /* If current peer is local */ - if (peer->local) { - /* flag to start to teach lesson */ - peer->flags |= PEER_F_TEACH_PROCESS; - } - else if ((peers->flags & PEERS_RESYNC_STATEMASK) == PEERS_RESYNC_FROMREMOTE && - !(peers->flags & PEERS_F_RESYNC_ASSIGN)) { + if (!peer->local && + (peers->flags & PEERS_RESYNC_STATEMASK) == PEERS_RESYNC_FROMREMOTE && + !(peers->flags & PEERS_F_RESYNC_ASSIGN)) { /* If peer is remote and resync from remote is needed, and no peer currently assigned */