]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: log: remove the unused curr_idx in struct smp_log_range
authorWilly Tarreau <w@1wt.eu>
Wed, 20 Sep 2023 18:09:58 +0000 (20:09 +0200)
committerWilly Tarreau <w@1wt.eu>
Wed, 20 Sep 2023 19:38:33 +0000 (21:38 +0200)
This index is useless because it only serves to know when the global
index reached the end, while the global one already knows it. Let's
just drop it and perform the test on the global range.

It was verified with the following config that the first server continues
to take 1/10 of the traffic, the 2nd one 2/10, the 3rd one 3/10 and the
4th one 4/10:

    log 127.0.0.1:10001 sample 1:10 local0
    log 127.0.0.1:10002 sample 2,5:10 local0
    log 127.0.0.1:10003 sample 3,7,9:10 local0
    log 127.0.0.1:10004 sample 4,6,8,10:10 local0

include/haproxy/log-t.h
src/log.c

index 039621a34e4ae346566aa373f8ea59eb65d23e41..24450518442904b06f27864d6dc86c01a2036088 100644 (file)
@@ -208,9 +208,6 @@ struct smp_log_range {
        size_t sz;               /* The size of this range, or number of indexes in
                                  * this range.
                                  */
-       unsigned int curr_idx;   /* The current index used to sample this range of
-                                 *indexes.
-                                 */
 };
 
 /* Log sampling information. */
index 3d9e390410c5e06cec7022eb0a0ee156fadd0578..b28b67e605739dd8687fb6e2cccbd5f7cb5af599 100644 (file)
--- a/src/log.c
+++ b/src/log.c
@@ -970,7 +970,6 @@ int parse_logsrv(char **args, struct list *logsrvs, int do_del, const char *file
                        smp_rgs[smp_rgs_sz].low = low;
                        smp_rgs[smp_rgs_sz].high = high;
                        smp_rgs[smp_rgs_sz].sz = high - low + 1;
-                       smp_rgs[smp_rgs_sz].curr_idx = 0;
                        if (smp_rgs[smp_rgs_sz].high > smp_sz)
                                smp_sz = smp_rgs[smp_rgs_sz].high;
                        smp_rgs_sz++;
@@ -1841,8 +1840,7 @@ void process_send_log(struct list *logsrvs, int level, int facility,
                        in_range = curr_rg->low <= next_idx && next_idx <= curr_rg->high;
                        if (in_range) {
                                /* Let's consume this range. */
-                               curr_rg->curr_idx = (curr_rg->curr_idx + 1) % curr_rg->sz;
-                               if (!curr_rg->curr_idx) {
+                               if (next_idx == curr_rg->high) {
                                        /* If consumed, let's select the next range. */
                                        logsrv->lb.curr_rg = (logsrv->lb.curr_rg + 1) % logsrv->lb.smp_rgs_sz;
                                }