[4.0] 0672a5e Use n + hist_buckets as hit flag in varnishhist bucket history
Lasse Karstensen
lkarsten at varnish-software.com
Thu Jan 15 16:35:41 CET 2015
commit 0672a5e56bffc2b22fc5e4c1e4bdc1f14a249718
Author: Martin Blix Grydeland <martin at varnish-software.com>
Date: Mon Nov 10 15:22:06 2014 +0100
Use n + hist_buckets as hit flag in varnishhist bucket history
Because -0 == +0, the use of negative numbers as a distinction between
hits and misses in the recorded bucket history fails when there are
entries of index 0.
Fixes: #1623
diff --git a/bin/varnishhist/varnishhist.c b/bin/varnishhist/varnishhist.c
index d01595c..c364ad3 100644
--- a/bin/varnishhist/varnishhist.c
+++ b/bin/varnishhist/varnishhist.c
@@ -193,7 +193,8 @@ static int /*__match_proto__ (VSLQ_dispatch_f)*/
accumulate(struct VSL_data *vsl, struct VSL_transaction * const pt[],
void *priv)
{
- int i, j, tag, skip, match, hit;
+ int i, tag, skip, match, hit;
+ unsigned u;
double value;
struct VSL_transaction *tr;
@@ -259,13 +260,15 @@ accumulate(struct VSL_data *vsl, struct VSL_transaction * const pt[],
/* phase out old data */
if (nhist == HIST_N) {
- j = rr_hist[next_hist];
- if (j < 0) {
- assert(bucket_miss[-j] > 0);
- bucket_miss[-j]--;
+ u = rr_hist[next_hist];
+ if (u >= hist_buckets) {
+ u -= hist_buckets;
+ assert(u < hist_buckets);
+ assert(bucket_hit[u] > 0);
+ bucket_hit[u]--;
} else {
- assert(bucket_hit[j] > 0);
- bucket_hit[j]--;
+ assert(bucket_miss[u] > 0);
+ bucket_miss[u]--;
}
} else {
++nhist;
@@ -274,10 +277,10 @@ accumulate(struct VSL_data *vsl, struct VSL_transaction * const pt[],
/* phase in new data */
if (hit) {
bucket_hit[i]++;
- rr_hist[next_hist] = i;
+ rr_hist[next_hist] = i + hist_buckets;
} else {
bucket_miss[i]++;
- rr_hist[next_hist] = -i;
+ rr_hist[next_hist] = i;
}
if (++next_hist == HIST_N) {
next_hist = 0;
More information about the varnish-commit
mailing list