]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: stktable: Use an enum to type a sticky session in the updates tree
authorChristopher Faulet <cfaulet@haproxy.com>
Thu, 9 Oct 2025 09:54:56 +0000 (11:54 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Thu, 30 Oct 2025 13:17:49 +0000 (14:17 +0100)
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
src/stick_table.c

index 143236c62fe5dce0f3d1e73cd58efe738667e41f..c4434e89847cf86d396cbc7690ffe0a0f81ef725 100644 (file)
@@ -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 <keys>, it's used by the key */
 };
index 9d4a75c1935a475e47c3d7d400289d1943c116a4..a55d0bb0c6ebaadab788f6f404ca69c3b50242cf 100644 (file)
@@ -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);
                        }
                }
@@ -859,7 +860,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;