From 451ffafea4778807bb41b53264d63a0479ba487f Mon Sep 17 00:00:00 2001 From: Christopher Faulet Date: Thu, 9 Oct 2025 11:54:56 +0200 Subject: [PATCH] MINOR: stktable: Use an enum to type a sticky session in the updates tree Instead of using a boolean to know if an entry in the updates tree is local or not, an enum is used. This change will be mandatory when updates tree will be replaced by a list to be able to add markers owned by each peer. So now a sticky sessin has no type (STKSESS_UPDT_NONE) if it is not in the updates tree. STKSESS_UPDT_LOCAL is used for local entries and STKSESS_UPDT_REMOTE for remote ones. STKSESS_UPDT_MARKER is not used for now. --- include/haproxy/stick_table-t.h | 11 ++++++++++- src/stick_table.c | 7 ++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/include/haproxy/stick_table-t.h b/include/haproxy/stick_table-t.h index 143236c62..c4434e898 100644 --- a/include/haproxy/stick_table-t.h +++ b/include/haproxy/stick_table-t.h @@ -112,6 +112,15 @@ enum { #define STKCTR_TRACK_BACKEND 1 #define STKCTR_TRACK_CONTENT 2 +/* type of the sticky session in the updates tree */ +enum { + STKSESS_UPDT_NONE = 0, /* unset, only if table is not used by the peers */ + STKSESS_UPDT_LOCAL, /* the sticky session is locally updated */ + STKSESS_UPDT_REMOTE, /* the sticky session is remotely updated */ + STKSESS_UPDT_MARKER, /* not a true sticky session, only used a marker*/ +}; + + /* stick_table extra data. This is mainly used for casting or size computation */ union stktable_data { /* standard types for easy casting */ @@ -153,7 +162,7 @@ struct stksess { struct eb32_node exp; /* ebtree node used to hold the session in expiration tree */ struct eb32_node upd; /* ebtree node used to hold the update sequence tree */ struct mt_list pend_updts;/* list of entries to be inserted/moved in the update sequence tree */ - int updt_is_local; /* is the update a local one ? */ + unsigned int updt_type; /* One of STKSESS_UPDT_* value */ struct ebmb_node key; /* ebtree node used to hold the session in table */ /* WARNING! do not put anything after , it's used by the key */ }; diff --git a/src/stick_table.c b/src/stick_table.c index 0d50a9d63..5cd37a667 100644 --- a/src/stick_table.c +++ b/src/stick_table.c @@ -270,6 +270,7 @@ static struct stksess *__stksess_init(struct stktable *t, struct stksess * ts) ts->key.node.leaf_p = NULL; ts->exp.node.leaf_p = NULL; ts->upd.node.leaf_p = NULL; + ts->updt_type = STKSESS_UPDT_NONE; MT_LIST_INIT(&ts->pend_updts); ts->expire = tick_add(now_ms, MS_TO_TICKS(t->expire)); HA_RWLOCK_INIT(&ts->lock); @@ -639,13 +640,13 @@ void stktable_touch_with_exp(struct stktable *t, struct stksess *ts, int local, * scheduled for at least one peer. */ if (!ts->upd.node.leaf_p || _HA_ATOMIC_LOAD(&ts->seen)) { - _HA_ATOMIC_STORE(&ts->updt_is_local, 1); + _HA_ATOMIC_STORE(&ts->updt_type, STKSESS_UPDT_LOCAL); did_append = MT_LIST_TRY_APPEND(&t->pend_updts[tgid - 1], &ts->pend_updts); } } else { if (!ts->upd.node.leaf_p) { - _HA_ATOMIC_STORE(&ts->updt_is_local, 0); + _HA_ATOMIC_STORE(&ts->updt_type, STKSESS_UPDT_REMOTE); did_append = MT_LIST_TRY_APPEND(&t->pend_updts[tgid - 1], &ts->pend_updts); } } @@ -856,7 +857,7 @@ struct task *stktable_add_pend_updates(struct task *t, void *ctx, unsigned int s empty_tgid = 0; if (cur_tgid == global.nbtgroups) cur_tgid = 0; - is_local = stksess->updt_is_local; + is_local = (stksess->updt_type == STKSESS_UPDT_LOCAL); stksess->seen = 0; if (is_local) { stksess->upd.key = ++table->update;