]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
[MEDIUM] stick_table: move the server ID to a generic data type
authorWilly Tarreau <w@1wt.eu>
Sun, 6 Jun 2010 14:40:39 +0000 (16:40 +0200)
committerWilly Tarreau <w@1wt.eu>
Mon, 14 Jun 2010 13:10:25 +0000 (15:10 +0200)
The server ID is now stored just as any other data type. It is only
allocated if needed and is manipulated just like the other ones.

doc/configuration.txt
include/types/stick_table.h
src/cfgparse.c
src/session.c
src/stick_table.c

index fb2f48d82f2b72c80c96bff165adae79597ddb77..f2275f79a9d55c87c35718b5e5eb1d90f470d08b 100644 (file)
@@ -5055,7 +5055,9 @@ stick-table type {ip | integer | string [len <length>] } size <size>
                item specified here, the size of each entry will be inflated so
                that the additional data can fit. At the moment, only "conn_cum"
                is supported, which can be used to store and retrieve the total
-               number of connections matching the entry since it was created.
+               number of connections matching the entry since it was created. A
+               "server_id" type is also supported but it's only for internal
+               use for stick and store directives.
 
   The is only one stick-table per backend. At the moment of writing this doc,
   it does not seem useful to have multiple tables per backend. If this happens
index 3e27b8f2716c738daf6e75ab6c7ca0edc71cba40..843f5d73ed8df58160ce1cce4c416f3023330aa0 100644 (file)
@@ -41,6 +41,7 @@ enum {
 
 /* The types of extra data we can store in a stick table */
 enum {
+       STKTABLE_DT_SERVER_ID,    /* the server ID to use with this session if > 0 */
        STKTABLE_DT_CONN_CUM,     /* cumulated number of connections */
        STKTABLE_DATA_TYPES       /* Number of data types, must always be last */
 };
@@ -48,6 +49,7 @@ enum {
 /* stick_table extra data. This is mainly used for casting or size computation */
 union stktable_data {
        unsigned int conn_cum;
+       int server_id;
 };
 
 /* known data types */
@@ -72,7 +74,6 @@ struct stktable_type {
  * keys and variable-sized data without making use of intermediate pointers.
  */
 struct stksess {
-       int sid;                  /* id of server to use for this session */
        unsigned int expire;      /* session expiration date */
        struct eb32_node exp;     /* ebtree node used to hold the session in expiration tree */
        struct ebmb_node key;     /* ebtree node used to hold the session in table */
index 26c8ba744a143ab4203077d48320933e2323a959..d472f9963b6a73fabf7c89e324fb7419fb5e3dcb 100644 (file)
@@ -4899,6 +4899,7 @@ int check_config_validity()
                        else {
                                free((void *)mrule->table.name);
                                mrule->table.t = &(target->table);
+                               stktable_alloc_data_type(&target->table, STKTABLE_DT_SERVER_ID);
                        }
                }
 
@@ -4931,6 +4932,7 @@ int check_config_validity()
                        else {
                                free((void *)mrule->table.name);
                                mrule->table.t = &(target->table);
+                               stktable_alloc_data_type(&target->table, STKTABLE_DT_SERVER_ID);
                        }
                }
 
index 873201c68ddfedae8d88a657003b7b41b230d310..2ae6f906cfde217bb14c32e76ba2c7fb6120531b 100644 (file)
@@ -945,9 +945,11 @@ int process_sticking_rules(struct session *s, struct buffer *req, int an_bit)
                                if ((ts = stktable_lookup_key(rule->table.t, key)) != NULL) {
                                        if (!(s->flags & SN_ASSIGNED)) {
                                                struct eb32_node *node;
+                                               void *ptr;
 
                                                /* srv found in table */
-                                               node = eb32_lookup(&px->conf.used_server_id, ts->sid);
+                                               ptr = stktable_data_ptr(rule->table.t, ts, STKTABLE_DT_SERVER_ID);
+                                               node = eb32_lookup(&px->conf.used_server_id, stktable_data_cast(ptr, server_id));
                                                if (node) {
                                                        struct server *srv;
 
@@ -1050,6 +1052,7 @@ int process_store_rules(struct session *s, struct buffer *rep, int an_bit)
        /* process store request and store response */
        for (i = 0; i < s->store_count; i++) {
                struct stksess *ts;
+               void *ptr;
 
                ts = stktable_lookup(s->store[i].table, s->store[i].ts);
                if (ts) {
@@ -1060,7 +1063,8 @@ int process_store_rules(struct session *s, struct buffer *rep, int an_bit)
                        ts = stktable_store(s->store[i].table, s->store[i].ts);
 
                s->store[i].ts = NULL;
-               ts->sid = s->srv->puid;
+               ptr = stktable_data_ptr(s->store[i].table, ts, STKTABLE_DT_SERVER_ID);
+               stktable_data_cast(ptr, server_id) = s->srv->puid;
        }
 
        rep->analysers &= ~an_bit;
index 994fbebef83d1db247195b7201a25ad56cdd7bc2..017362f700a7645e33ed288213070ec443ee1850 100644 (file)
@@ -64,7 +64,6 @@ void stksess_setkey(struct stktable *t, struct stksess *ts, struct stktable_key
 static struct stksess *stksess_init(struct stktable *t, struct stksess * ts)
 {
        memset((void *)ts - t->data_size, 0, t->data_size);
-       ts->sid = 0;
        ts->key.node.leaf_p = NULL;
        ts->exp.node.leaf_p = NULL;
        return ts;
@@ -476,6 +475,7 @@ int stktable_compatible_pattern(struct pattern_expr *expr, unsigned long table_t
 /* Extra data types processing */
 struct stktable_data_type stktable_data_types[STKTABLE_DATA_TYPES] = {
        [STKTABLE_DT_CONN_CUM] = { .name = "conn_cum", .data_length = stktable_data_size(conn_cum) },
+       [STKTABLE_DT_SERVER_ID] = { .name = "server_id", .data_length = stktable_data_size(server_id) },
 };
 
 /*