]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MINOR: counters: make the sc-inc-gpc0 and sc-set-gpt0 touch the table
authorWilly Tarreau <w@1wt.eu>
Mon, 25 Jan 2016 13:54:45 +0000 (14:54 +0100)
committerWilly Tarreau <w@1wt.eu>
Mon, 25 Jan 2016 13:56:33 +0000 (14:56 +0100)
These two actions don't touch the table so the entry will expire and
the values will not be pushed to other peers. Also in the case of gpc0,
the gpc0_rate counter must be updated. The issue was reported by
Ruoshan Huang.

This fix needs to be backported to 1.6.

src/stick_table.c

index 93fb10c0a3ef7b734df2c76fab52c002402c3c82..e5bb168d7bd1ef4507055ee682c630c7ebb6a6dd 100644 (file)
@@ -1316,7 +1316,6 @@ static int sample_conv_table_trackers(const struct arg *arg_p, struct sample *sm
 static enum act_return action_inc_gpc0(struct act_rule *rule, struct proxy *px,
                                        struct session *sess, struct stream *s, int flags)
 {
-       void *ptr;
        struct stksess *ts;
        struct stkctr *stkctr;
 
@@ -1325,16 +1324,25 @@ static enum act_return action_inc_gpc0(struct act_rule *rule, struct proxy *px,
                stkctr = &s->stkctr[rule->arg.gpc.sc];
        else
                stkctr = &sess->stkctr[rule->arg.gpc.sc];
+
        ts = stkctr_entry(stkctr);
-       if (!ts)
-               return ACT_RET_CONT;
+       if (ts) {
+               void *ptr1, *ptr2;
 
-       /* Store the sample in the required sc, and ignore errors. */
-       ptr = stktable_data_ptr(stkctr->table, ts, STKTABLE_DT_GPC0);
-       if (!ptr)
-               return ACT_RET_CONT;
+               /* First, update gpc0_rate if it's tracked. Second, update its gpc0 if tracked. */
+               ptr1 = stktable_data_ptr(stkctr->table, ts, STKTABLE_DT_GPC0_RATE);
+               if (ptr1)
+                       update_freq_ctr_period(&stktable_data_cast(ptr1, gpc0_rate),
+                                              stkctr->table->data_arg[STKTABLE_DT_GPC0_RATE].u, 1);
+
+               ptr2 = stktable_data_ptr(stkctr->table, ts, STKTABLE_DT_GPC0);
+               if (ptr2)
+                       stktable_data_cast(ptr2, gpc0)++;
 
-       stktable_data_cast(ptr, gpc0)++;
+               /* If data was modified, we need to touch to re-schedule sync */
+               if (ptr1 || ptr2)
+                       stktable_touch(stkctr->table, ts, 1);
+       }
        return ACT_RET_CONT;
 }
 
@@ -1394,14 +1402,18 @@ static enum act_return action_set_gpt0(struct act_rule *rule, struct proxy *px,
                stkctr = &s->stkctr[rule->arg.gpt.sc];
        else
                stkctr = &sess->stkctr[rule->arg.gpt.sc];
+
        ts = stkctr_entry(stkctr);
        if (!ts)
                return ACT_RET_CONT;
 
        /* Store the sample in the required sc, and ignore errors. */
        ptr = stktable_data_ptr(stkctr->table, ts, STKTABLE_DT_GPT0);
-       if (ptr)
+       if (ptr) {
                stktable_data_cast(ptr, gpt0) = rule->arg.gpt.value;
+               stktable_touch(stkctr->table, ts, 1);
+       }
+
        return ACT_RET_CONT;
 }