mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-09-21 22:01:31 +02:00
CLEANUP: server: Use a local eb-tree to store lines of the global server-state file
There is no reason to use a global variable to store the lines of the global server-state file. This tree is only used during the file parsing, as a line cache. Now the eb-tree is declared as a local variable in the apply_server_state() function.
This commit is contained in:
parent
6d87c58fb4
commit
8b4b6a0d63
11
src/server.c
11
src/server.c
@ -74,9 +74,6 @@ struct dict server_key_dict = {
|
|||||||
.values = EB_ROOT_UNIQUE,
|
.values = EB_ROOT_UNIQUE,
|
||||||
};
|
};
|
||||||
|
|
||||||
/* tree where global state_file is loaded */
|
|
||||||
struct eb_root state_file = EB_ROOT_UNIQUE;
|
|
||||||
|
|
||||||
int srv_downtime(const struct server *s)
|
int srv_downtime(const struct server *s)
|
||||||
{
|
{
|
||||||
if ((s->cur_state != SRV_ST_STOPPED) || s->last_change >= now.tv_sec) // ignore negative time
|
if ((s->cur_state != SRV_ST_STOPPED) || s->last_change >= now.tv_sec) // ignore negative time
|
||||||
@ -3218,6 +3215,8 @@ static inline int srv_state_get_filepath(char *dst_path, int maxpathlen, const c
|
|||||||
*/
|
*/
|
||||||
void apply_server_state(void)
|
void apply_server_state(void)
|
||||||
{
|
{
|
||||||
|
/* tree where global state_file is loaded */
|
||||||
|
struct eb_root global_state_tree = EB_ROOT_UNIQUE;
|
||||||
struct proxy *curproxy;
|
struct proxy *curproxy;
|
||||||
struct server *srv;
|
struct server *srv;
|
||||||
struct server_state_line *st_line;
|
struct server_state_line *st_line;
|
||||||
@ -3274,7 +3273,7 @@ void apply_server_state(void)
|
|||||||
goto nextline;
|
goto nextline;
|
||||||
}
|
}
|
||||||
memcpy(st_line->node.key, trash.area, trash.data + 1);
|
memcpy(st_line->node.key, trash.area, trash.data + 1);
|
||||||
if (ebst_insert(&state_file, &st_line->node) != &st_line->node) {
|
if (ebst_insert(&global_state_tree, &st_line->node) != &st_line->node) {
|
||||||
/* this is a duplicate key, probably a hand-crafted file,
|
/* this is a duplicate key, probably a hand-crafted file,
|
||||||
* drop it!
|
* drop it!
|
||||||
*/
|
*/
|
||||||
@ -3318,7 +3317,7 @@ void apply_server_state(void)
|
|||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
chunk_printf(&trash, "%s %s", curproxy->id, srv->id);
|
chunk_printf(&trash, "%s %s", curproxy->id, srv->id);
|
||||||
node = ebst_lookup(&state_file, trash.area);
|
node = ebst_lookup(&global_state_tree, trash.area);
|
||||||
if (!node)
|
if (!node)
|
||||||
continue; /* next server */
|
continue; /* next server */
|
||||||
st_line = ebmb_entry(node, typeof(*st_line), node);
|
st_line = ebmb_entry(node, typeof(*st_line), node);
|
||||||
@ -3413,7 +3412,7 @@ void apply_server_state(void)
|
|||||||
fclose(f);
|
fclose(f);
|
||||||
}
|
}
|
||||||
|
|
||||||
node = ebmb_first(&state_file);
|
node = ebmb_first(&global_state_tree);
|
||||||
while (node) {
|
while (node) {
|
||||||
st_line = ebmb_entry(node, typeof(*st_line), node);
|
st_line = ebmb_entry(node, typeof(*st_line), node);
|
||||||
next_node = ebmb_next(node);
|
next_node = ebmb_next(node);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user