mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-08-06 23:27:04 +02:00
BUG/MINOR: peers: peer synchronization issue (with several peers sections).
When several stick-tables were configured with several peers sections, only a part of them could be synchronized: the ones attached to the last parsed 'peers' section. This was due to the fact that, at least, the peer I/O handler refered to the wrong peer section list, in fact always the same: the last one parsed. The fact that the global peer section list was named "struct peers *peers" lead to this issue. This variable name is dangerous ;). So this patch renames global 'peers' variable to 'cfg_peers' to ensure that no such wrong references are still in use, then all the functions wich used old 'peers' variable have been modified to refer to the correct peer list. Must be backported to 1.6 and 1.7.
This commit is contained in:
parent
7784f1739c
commit
ed2b4a6b79
@ -91,7 +91,7 @@ struct peers {
|
||||
};
|
||||
|
||||
|
||||
extern struct peers *peers;
|
||||
extern struct peers *cfg_peers;
|
||||
|
||||
#endif /* _TYPES_PEERS_H */
|
||||
|
||||
|
@ -1941,7 +1941,7 @@ int cfg_parse_peers(const char *file, int linenum, char **args, int kwm)
|
||||
goto out;
|
||||
}
|
||||
|
||||
for (curpeers = peers; curpeers != NULL; curpeers = curpeers->next) {
|
||||
for (curpeers = cfg_peers; curpeers != NULL; curpeers = curpeers->next) {
|
||||
/*
|
||||
* If there are two proxies with the same name only following
|
||||
* combinations are allowed:
|
||||
@ -1959,8 +1959,8 @@ int cfg_parse_peers(const char *file, int linenum, char **args, int kwm)
|
||||
goto out;
|
||||
}
|
||||
|
||||
curpeers->next = peers;
|
||||
peers = curpeers;
|
||||
curpeers->next = cfg_peers;
|
||||
cfg_peers = curpeers;
|
||||
curpeers->conf.file = strdup(file);
|
||||
curpeers->conf.line = linenum;
|
||||
curpeers->last_change = now.tv_sec;
|
||||
@ -2040,7 +2040,7 @@ int cfg_parse_peers(const char *file, int linenum, char **args, int kwm)
|
||||
if (strcmp(newpeer->id, localpeer) == 0) {
|
||||
/* Current is local peer, it define a frontend */
|
||||
newpeer->local = 1;
|
||||
peers->local = newpeer;
|
||||
cfg_peers->local = newpeer;
|
||||
|
||||
if (!curpeers->peers_fe) {
|
||||
if ((curpeers->peers_fe = calloc(1, sizeof(struct proxy))) == NULL) {
|
||||
@ -8087,9 +8087,9 @@ int check_config_validity()
|
||||
}
|
||||
|
||||
if (curproxy->table.peers.name) {
|
||||
struct peers *curpeers = peers;
|
||||
struct peers *curpeers;
|
||||
|
||||
for (curpeers = peers; curpeers; curpeers = curpeers->next) {
|
||||
for (curpeers = cfg_peers; curpeers; curpeers = curpeers->next) {
|
||||
if (strcmp(curpeers->id, curproxy->table.peers.name) == 0) {
|
||||
free((void *)curproxy->table.peers.name);
|
||||
curproxy->table.peers.p = curpeers;
|
||||
@ -9108,15 +9108,15 @@ int check_config_validity()
|
||||
if (curproxy->table.peers.p)
|
||||
curproxy->table.peers.p->peers_fe->bind_proc |= curproxy->bind_proc;
|
||||
|
||||
if (peers) {
|
||||
struct peers *curpeers = peers, **last;
|
||||
if (cfg_peers) {
|
||||
struct peers *curpeers = cfg_peers, **last;
|
||||
struct peer *p, *pb;
|
||||
|
||||
/* Remove all peers sections which don't have a valid listener,
|
||||
* which are not used by any table, or which are bound to more
|
||||
* than one process.
|
||||
*/
|
||||
last = &peers;
|
||||
last = &cfg_peers;
|
||||
while (*last) {
|
||||
curpeers = *last;
|
||||
|
||||
|
@ -1448,7 +1448,7 @@ static void init(int argc, char **argv)
|
||||
struct peers *pr;
|
||||
struct proxy *px;
|
||||
|
||||
for (pr = peers; pr; pr = pr->next)
|
||||
for (pr = cfg_peers; pr; pr = pr->next)
|
||||
if (pr->peers_fe)
|
||||
break;
|
||||
|
||||
@ -1662,11 +1662,11 @@ static void init(int argc, char **argv)
|
||||
if (global.stats_fe)
|
||||
global.maxsock += global.stats_fe->maxconn;
|
||||
|
||||
if (peers) {
|
||||
if (cfg_peers) {
|
||||
/* peers also need to bypass global maxconn */
|
||||
struct peers *p = peers;
|
||||
struct peers *p = cfg_peers;
|
||||
|
||||
for (p = peers; p; p = p->next)
|
||||
for (p = cfg_peers; p; p = p->next)
|
||||
if (p->peers_fe)
|
||||
global.maxsock += p->peers_fe->maxconn;
|
||||
}
|
||||
@ -2653,7 +2653,7 @@ int main(int argc, char **argv)
|
||||
}
|
||||
|
||||
/* we might have to unbind some peers sections from some processes */
|
||||
for (curpeers = peers; curpeers; curpeers = curpeers->next) {
|
||||
for (curpeers = cfg_peers; curpeers; curpeers = curpeers->next) {
|
||||
if (!curpeers->peers_fe)
|
||||
continue;
|
||||
|
||||
|
40
src/peers.c
40
src/peers.c
@ -171,7 +171,7 @@ enum {
|
||||
#define PEER_MINOR_VER 1
|
||||
#define PEER_DWNGRD_MINOR_VER 0
|
||||
|
||||
struct peers *peers = NULL;
|
||||
struct peers *cfg_peers = NULL;
|
||||
static void peer_session_forceshutdown(struct appctx *appctx);
|
||||
|
||||
/* This function encode an uint64 to 'dynamic' length format.
|
||||
@ -743,19 +743,19 @@ static void peer_io_handler(struct appctx *appctx)
|
||||
/* if current peer is local */
|
||||
if (curpeer->local) {
|
||||
/* if current host need resyncfrom local and no process assined */
|
||||
if ((peers->flags & PEERS_RESYNC_STATEMASK) == PEERS_RESYNC_FROMLOCAL &&
|
||||
!(peers->flags & PEERS_F_RESYNC_ASSIGN)) {
|
||||
if ((curpeers->flags & PEERS_RESYNC_STATEMASK) == PEERS_RESYNC_FROMLOCAL &&
|
||||
!(curpeers->flags & PEERS_F_RESYNC_ASSIGN)) {
|
||||
/* assign local peer for a lesson, consider lesson already requested */
|
||||
curpeer->flags |= PEER_F_LEARN_ASSIGN;
|
||||
peers->flags |= (PEERS_F_RESYNC_ASSIGN|PEERS_F_RESYNC_PROCESS);
|
||||
curpeers->flags |= (PEERS_F_RESYNC_ASSIGN|PEERS_F_RESYNC_PROCESS);
|
||||
}
|
||||
|
||||
}
|
||||
else if ((peers->flags & PEERS_RESYNC_STATEMASK) == PEERS_RESYNC_FROMREMOTE &&
|
||||
!(peers->flags & PEERS_F_RESYNC_ASSIGN)) {
|
||||
else if ((curpeers->flags & PEERS_RESYNC_STATEMASK) == PEERS_RESYNC_FROMREMOTE &&
|
||||
!(curpeers->flags & PEERS_F_RESYNC_ASSIGN)) {
|
||||
/* assign peer for a lesson */
|
||||
curpeer->flags |= PEER_F_LEARN_ASSIGN;
|
||||
peers->flags |= PEERS_F_RESYNC_ASSIGN;
|
||||
curpeers->flags |= PEERS_F_RESYNC_ASSIGN;
|
||||
}
|
||||
|
||||
|
||||
@ -823,7 +823,7 @@ static void peer_io_handler(struct appctx *appctx)
|
||||
curpeer->statuscode = atoi(trash.str);
|
||||
|
||||
/* Awake main task */
|
||||
task_wakeup(peers->sync_task, TASK_WOKEN_MSG);
|
||||
task_wakeup(curpeers->sync_task, TASK_WOKEN_MSG);
|
||||
|
||||
/* If status code is success */
|
||||
if (curpeer->statuscode == PEER_SESS_SC_SUCCESSCODE) {
|
||||
@ -846,14 +846,14 @@ static void peer_io_handler(struct appctx *appctx)
|
||||
curpeer->flags |= PEER_F_TEACH_PROCESS;
|
||||
|
||||
}
|
||||
else if ((peers->flags & PEERS_RESYNC_STATEMASK) == PEERS_RESYNC_FROMREMOTE &&
|
||||
!(peers->flags & PEERS_F_RESYNC_ASSIGN)) {
|
||||
else if ((curpeers->flags & PEERS_RESYNC_STATEMASK) == PEERS_RESYNC_FROMREMOTE &&
|
||||
!(curpeers->flags & PEERS_F_RESYNC_ASSIGN)) {
|
||||
/* If peer is remote and resync from remote is needed,
|
||||
and no peer currently assigned */
|
||||
|
||||
/* assign peer for a lesson */
|
||||
curpeer->flags |= PEER_F_LEARN_ASSIGN;
|
||||
peers->flags |= PEERS_F_RESYNC_ASSIGN;
|
||||
curpeers->flags |= PEERS_F_RESYNC_ASSIGN;
|
||||
}
|
||||
|
||||
}
|
||||
@ -966,8 +966,8 @@ static void peer_io_handler(struct appctx *appctx)
|
||||
|
||||
if (curpeer->flags & PEER_F_LEARN_ASSIGN) {
|
||||
curpeer->flags &= ~PEER_F_LEARN_ASSIGN;
|
||||
peers->flags &= ~(PEERS_F_RESYNC_ASSIGN|PEERS_F_RESYNC_PROCESS);
|
||||
peers->flags |= (PEERS_F_RESYNC_LOCAL|PEERS_F_RESYNC_REMOTE);
|
||||
curpeers->flags &= ~(PEERS_F_RESYNC_ASSIGN|PEERS_F_RESYNC_PROCESS);
|
||||
curpeers->flags |= (PEERS_F_RESYNC_LOCAL|PEERS_F_RESYNC_REMOTE);
|
||||
}
|
||||
curpeer->confirm++;
|
||||
}
|
||||
@ -975,11 +975,11 @@ static void peer_io_handler(struct appctx *appctx)
|
||||
|
||||
if (curpeer->flags & PEER_F_LEARN_ASSIGN) {
|
||||
curpeer->flags &= ~PEER_F_LEARN_ASSIGN;
|
||||
peers->flags &= ~(PEERS_F_RESYNC_ASSIGN|PEERS_F_RESYNC_PROCESS);
|
||||
curpeers->flags &= ~(PEERS_F_RESYNC_ASSIGN|PEERS_F_RESYNC_PROCESS);
|
||||
|
||||
curpeer->flags |= PEER_F_LEARN_NOTUP2DATE;
|
||||
peers->resync_timeout = tick_add(now_ms, MS_TO_TICKS(5000));
|
||||
task_wakeup(peers->sync_task, TASK_WOKEN_MSG);
|
||||
curpeers->resync_timeout = tick_add(now_ms, MS_TO_TICKS(5000));
|
||||
task_wakeup(curpeers->sync_task, TASK_WOKEN_MSG);
|
||||
}
|
||||
curpeer->confirm++;
|
||||
}
|
||||
@ -1350,8 +1350,8 @@ static void peer_io_handler(struct appctx *appctx)
|
||||
|
||||
/* Need to request a resync */
|
||||
if ((curpeer->flags & PEER_F_LEARN_ASSIGN) &&
|
||||
(peers->flags & PEERS_F_RESYNC_ASSIGN) &&
|
||||
!(peers->flags & PEERS_F_RESYNC_PROCESS)) {
|
||||
(curpeers->flags & PEERS_F_RESYNC_ASSIGN) &&
|
||||
!(curpeers->flags & PEERS_F_RESYNC_PROCESS)) {
|
||||
unsigned char msg[2];
|
||||
|
||||
/* Current peer was elected to request a resync */
|
||||
@ -1367,7 +1367,7 @@ static void peer_io_handler(struct appctx *appctx)
|
||||
appctx->st0 = PEER_SESS_ST_END;
|
||||
goto switchstate;
|
||||
}
|
||||
peers->flags |= PEERS_F_RESYNC_PROCESS;
|
||||
curpeers->flags |= PEERS_F_RESYNC_PROCESS;
|
||||
}
|
||||
|
||||
/* Nothing to read, now we start to write */
|
||||
@ -1640,7 +1640,7 @@ static void peer_io_handler(struct appctx *appctx)
|
||||
|
||||
/* Current peer was elected to request a resync */
|
||||
msg[0] = PEER_MSG_CLASS_CONTROL;
|
||||
msg[1] = ((peers->flags & PEERS_RESYNC_STATEMASK) == PEERS_RESYNC_FINISHED) ? PEER_MSG_CTRL_RESYNCFINISHED : PEER_MSG_CTRL_RESYNCPARTIAL;
|
||||
msg[1] = ((curpeers->flags & PEERS_RESYNC_STATEMASK) == PEERS_RESYNC_FINISHED) ? PEER_MSG_CTRL_RESYNCFINISHED : PEER_MSG_CTRL_RESYNCPARTIAL;
|
||||
/* process final lesson message */
|
||||
repl = bi_putblk(si_ic(si), (char *)msg, sizeof(msg));
|
||||
if (repl <= 0) {
|
||||
|
@ -1021,7 +1021,7 @@ void soft_stop(void)
|
||||
p = p->next;
|
||||
}
|
||||
|
||||
prs = peers;
|
||||
prs = cfg_peers;
|
||||
while (prs) {
|
||||
if (prs->peers_fe)
|
||||
stop_proxy(prs->peers_fe);
|
||||
@ -1195,7 +1195,7 @@ void pause_proxies(void)
|
||||
p = p->next;
|
||||
}
|
||||
|
||||
prs = peers;
|
||||
prs = cfg_peers;
|
||||
while (prs) {
|
||||
if (prs->peers_fe)
|
||||
err |= !pause_proxy(prs->peers_fe);
|
||||
@ -1229,7 +1229,7 @@ void resume_proxies(void)
|
||||
p = p->next;
|
||||
}
|
||||
|
||||
prs = peers;
|
||||
prs = cfg_peers;
|
||||
while (prs) {
|
||||
if (prs->peers_fe)
|
||||
err |= !resume_proxy(prs->peers_fe);
|
||||
|
Loading…
Reference in New Issue
Block a user