]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
CLEANUP: stktable: replace nopurge attribute with flag
authorAurelien DARRAGON <adarragon@haproxy.com>
Thu, 5 Dec 2024 11:02:38 +0000 (12:02 +0100)
committerAurelien DARRAGON <adarragon@haproxy.com>
Thu, 5 Dec 2024 11:15:31 +0000 (12:15 +0100)
Thanks to previous commit stktable struct now have a "flags" struct member

Let's take this opportunity to remove the isolated "nopurge" attribute in
stktable struct and rely on a flag named STK_FL_NOPURGE instead.

This helps to better organize stktable struct members.

include/haproxy/stick_table-t.h
src/hlua_fcn.c
src/stick_table.c

index fcc79ceb63089c4dc1a4159794917add9ae53007..43b6e5e8f797f5ad7605ce512eafbe735da83de4 100644 (file)
@@ -159,6 +159,7 @@ struct stksess {
 #define STK_FL_RECV_ONLY 0x01      /* table is assumed to be remotely updated only
                                     * (never updated locally)
                                     */
+#define STK_FL_NOPURGE   0x02      /* if non-zero, don't purge sticky sessions when full */
 
 /* stick table */
 struct stktable {
@@ -183,12 +184,13 @@ struct stktable {
        size_t key_size;          /* size of a key, maximum size in case of string */
        unsigned int server_key_type; /* What type of key is used to identify servers */
        unsigned int size;        /* maximum number of sticky sessions in table */
-       int nopurge;              /* if non-zero, don't purge sticky sessions when full */
        int expire;               /* time to live for sticky sessions (milliseconds) */
        int data_size;            /* the size of the data that is prepended *before* stksess */
        int data_ofs[STKTABLE_DATA_TYPES]; /* negative offsets of present data types, or 0 if absent */
        unsigned int data_nbelem[STKTABLE_DATA_TYPES]; /* to store nb_elem in case of array types */
        unsigned int brates_factor; /* Factor used for IN/OUT bytes rates */
+       uint16_t flags;
+       /* 2-bytes hole */
        union {
                int i;
                unsigned int u;
@@ -201,8 +203,6 @@ struct stktable {
                void *ptr;          /* generic ptr to check if set or not */
        } write_to; /* updates received on the source table will also update write_to */
 
-       uint16_t flags;
-
        THREAD_ALIGN(64);
 
        struct {
index b6252fbf1c770e36b5cf544bbfbb796a46b91aea..e14004b65dd140b25e41fadc6e6d263ff612e27d 100644 (file)
@@ -823,7 +823,7 @@ int hlua_stktable_info(lua_State *L)
        lua_settable(L, -3);
 
        lua_pushstring(L, "nopurge");
-       lua_pushboolean(L, tbl->nopurge > 0);
+       lua_pushboolean(L, (tbl->flags & STK_FL_NOPURGE));
        lua_settable(L, -3);
 
        lua_pushstring(L, "expire");
index a18d89309c6205f7c4276e21476a3e7eaf6593ae..1da4296b85db42646d5e09a87e60b79093e70906 100644 (file)
@@ -396,7 +396,8 @@ struct stksess *stksess_new(struct stktable *t, struct stktable_key *key)
 
        if (unlikely(current >= t->size)) {
                /* the table was already full, we may have to purge entries */
-               if (t->nopurge || !stktable_trash_oldest(t, (t->size >> 8) + 1)) {
+               if ((t->flags & STK_FL_NOPURGE) ||
+                   !stktable_trash_oldest(t, (t->size >> 8) + 1)) {
                        HA_ATOMIC_DEC(&t->current);
                        return NULL;
                }
@@ -1248,7 +1249,7 @@ int parse_stick_table(const char *file, int linenum, char **args,
                        idx++;
                }
                else if (strcmp(args[idx], "nopurge") == 0) {
-                       t->nopurge = 1;
+                       t->flags |= STK_FL_NOPURGE;
                        idx++;
                }
                else if (strcmp(args[idx], "type") == 0) {