CLEANUP: stktable: replace nopurge attribute with flag

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.
This commit is contained in:
Aurelien DARRAGON 2024-12-05 12:02:38 +01:00
parent 1f73d3524d
commit 9f44c5f9be
3 changed files with 7 additions and 6 deletions

View 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 {

View 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");

View 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) {