EXP: peers: Improve the update list manipulations from peers

This commit is contained in:
Christopher Faulet
2025-10-17 16:37:54 +02:00
parent 1c5a097934
commit 0cb87637e7

View File

@@ -1561,6 +1561,7 @@ int peer_send_teachmsgs(struct appctx *appctx, struct peer *p, struct shared_tab
/* We force new pushed to 1 to force identifier in update message */
new_pushed = 1;
MT_LIST_TRY_APPEND(&st->table->updates, &st->end->upd);
while (1) {
struct mt_list el1, el2;
@@ -1585,6 +1586,12 @@ int peer_send_teachmsgs(struct appctx *appctx, struct peer *p, struct shared_tab
ret = -1;
break;
}
if (el1.next == &st->end->upd || el1.next == &st->table->updates) {
mt_list_unlock_full(&st->last->upd, el1);
break;
}
el2 = mt_list_lock_next(el1.next);
/* el2 = mt_list_try_lock_next(el1.next); */
/* if (el2.next == NULL) { */
@@ -1636,7 +1643,7 @@ int peer_send_teachmsgs(struct appctx *appctx, struct peer *p, struct shared_tab
updates_sent++;
}
if (ret == 1)
if (ret == 1 || !(p->flags & PEER_F_TEACH_PROCESS))
MT_LIST_DELETE(&st->end->upd);
end:
TRACE_LEAVE(PEERS_EV_SESS_IO, appctx, p, st);
@@ -2452,9 +2459,11 @@ static inline int peer_treat_awaited_msg(struct appctx *appctx, struct peer *pee
TRACE_PROTO("Resync request message received", PEERS_EV_SESS_IO|PEERS_EV_RX_MSG|PEERS_EV_PROTO_CTRL, appctx, peer);
/* prepare tables for a global push */
for (st = peer->tables; st; st = st->next) {
MT_LIST_DELETE(&st->last->upd);
if (MT_LIST_INLIST(&st->last->upd))
MT_LIST_DELETE(&st->last->upd);
MT_LIST_INSERT(&st->table->updates, &st->last->upd);
MT_LIST_DELETE(&st->end->upd);
if (MT_LIST_INLIST(&st->end->upd))
MT_LIST_DELETE(&st->end->upd);
MT_LIST_APPEND(&st->table->updates, &st->end->upd);
st->flags = 0;
}
@@ -2499,8 +2508,10 @@ static inline int peer_treat_awaited_msg(struct appctx *appctx, struct peer *pee
return 0;
}
peer->flags |= PEER_F_SYNCHED;
for (st = peer->tables; st; st = st->next)
MT_LIST_DELETE(&st->end->upd);
for (st = peer->tables; st; st = st->next) {
if (MT_LIST_INLIST(&st->end->upd))
MT_LIST_DELETE(&st->end->upd);
}
/* reset teaching flags to 0 */
peer->flags &= ~PEER_TEACH_FLAGS;
@@ -2816,11 +2827,14 @@ static inline void init_connected_peer(struct peer *peer, struct peers *peers)
st->last_get = st->last_acked = 0;
st->flags = 0;
if (!MT_LIST_INLIST(&st->last->upd) || !(peer->flags & PEER_F_SYNCHED)) {
if (!MT_LIST_INLIST(&st->last->upd))
MT_LIST_INSERT(&st->table->updates, &st->last->upd);
else if (!(peer->flags & PEER_F_SYNCHED)) {
MT_LIST_DELETE(&st->last->upd);
MT_LIST_INSERT(&st->table->updates, &st->last->upd);
}
MT_LIST_DELETE(&st->end->upd);
if (MT_LIST_INLIST(&st->end->upd))
MT_LIST_DELETE(&st->end->upd);
}
/* Awake main task to ack the new peer state */