]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MEDIUM: stick-table: return inserted entry in __stktable_store()
authorWilly Tarreau <w@1wt.eu>
Tue, 11 Oct 2022 13:09:46 +0000 (15:09 +0200)
committerWilly Tarreau <w@1wt.eu>
Wed, 12 Oct 2022 12:19:05 +0000 (14:19 +0200)
This function is used to create an entry in the table. But it doesn't
consider the possibility that the entry already exists, because right
now it's only called in situations where it was verified under a lock
that it doesn't exist. Since we'll soon need to break that assumption
we need it to verify that the requested entry was added and to return
a pointer to the one in the tree so that the caller can detect any
possible conflict. At the moment this is not used.

src/stick_table.c

index 92f662dfb6325b05fc2f20337df1c77cad7b10a0..6f5e6c8999850efea2dd718069081ea52e998cf0 100644 (file)
@@ -498,18 +498,23 @@ static void stktable_release(struct stktable *t, struct stksess *ts)
 
 /* Insert new sticky session <ts> in the table. It is assumed that it does not
  * yet exist (the caller must check this). The table's timeout is updated if it
- * is set. <ts> is returned.
+ * is set. <ts> is returned if properly inserted, otherwise the one already
+ * present if any.
  */
-void __stktable_store(struct stktable *t, struct stksess *ts)
+struct stksess *__stktable_store(struct stktable *t, struct stksess *ts)
 {
+       struct ebmb_node *eb;
 
-       ebmb_insert(&t->keys, &ts->key, t->key_size);
-       ts->exp.key = ts->expire;
-       eb32_insert(&t->exps, &ts->exp);
+       eb = ebmb_insert(&t->keys, &ts->key, t->key_size);
+       if (likely(eb == &ts->key)) {
+               ts->exp.key = ts->expire;
+               eb32_insert(&t->exps, &ts->exp);
+       }
        if (t->expire) {
                t->exp_task->expire = t->exp_next = tick_first(ts->expire, t->exp_next);
                task_queue(t->exp_task);
        }
+       return ebmb_entry(eb, struct stksess, key); // most commonly this is <ts>
 }
 
 /* Returns a valid or initialized stksess for the specified stktable_key in the