]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: stick-table: split stktable_store() between key and requeue
authorWilly Tarreau <w@1wt.eu>
Wed, 12 Oct 2022 09:56:08 +0000 (09:56 +0000)
committerWilly Tarreau <w@1wt.eu>
Wed, 12 Oct 2022 12:19:05 +0000 (14:19 +0200)
__staktable_store() performs two distinct things, one is to insert a key
and the other one is to requeue the task's expiration date. Since the
latter might be done without a lock, let's first split the function in
two halves. For now this has no impact.

src/stick_table.c

index b1144661e938929318c5a767f5ccf808e812c72d..facd5fa786a31905e00597a284d1b02d57f7843c 100644 (file)
@@ -510,13 +510,20 @@ struct stksess *__stktable_store(struct stktable *t, struct stksess *ts)
                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>
 }
 
+/* requeues the table's expiration task to take the recently added <ts> into
+ * account. This is performed atomically and doesn't require any lock.
+ */
+static void stktable_requeue_exp(struct stktable *t, const struct stksess *ts)
+{
+       if (!t->expire)
+               return;
+       t->exp_task->expire = t->exp_next = tick_first(ts->expire, t->exp_next);
+       task_queue(t->exp_task);
+}
+
 /* Returns a valid or initialized stksess for the specified stktable_key in the
  * specified table, or NULL if the key was NULL, or if no entry was found nor
  * could be created. The entry's expiration is updated. This function locks the
@@ -560,6 +567,7 @@ struct stksess *stktable_get_entry(struct stktable *table, struct stktable_key *
                ts = ts2;
        }
 
+       stktable_requeue_exp(table, ts);
        HA_ATOMIC_INC(&ts->ref_cnt);
        HA_RWLOCK_WRUNLOCK(STK_TABLE_LOCK, &table->lock);
 
@@ -597,6 +605,7 @@ struct stksess *stktable_set_entry(struct stktable *table, struct stksess *nts)
        /* now we're write-locked */
 
        __stktable_store(table, ts);
+       stktable_requeue_exp(table, ts);
        HA_RWLOCK_WRUNLOCK(STK_TABLE_LOCK, &table->lock);
        return ts;
 }