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
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. */
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++;
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;
}