From 3f1284560fce0012cc0d3eadbd458262f7fc1f82 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Wed, 20 Sep 2023 20:09:58 +0200 Subject: [PATCH] MINOR: log: remove the unused curr_idx in struct smp_log_range 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 | 3 --- src/log.c | 4 +--- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/include/haproxy/log-t.h b/include/haproxy/log-t.h index 039621a34e..2445051844 100644 --- a/include/haproxy/log-t.h +++ b/include/haproxy/log-t.h @@ -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. */ diff --git a/src/log.c b/src/log.c index 3d9e390410..b28b67e605 100644 --- 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; } -- 2.39.5