Commit 0672a5e5 authored by Martin Blix Grydeland's avatar Martin Blix Grydeland Committed by Lasse Karstensen

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
parent 39349f4f
...@@ -193,7 +193,8 @@ static int /*__match_proto__ (VSLQ_dispatch_f)*/ ...@@ -193,7 +193,8 @@ static int /*__match_proto__ (VSLQ_dispatch_f)*/
accumulate(struct VSL_data *vsl, struct VSL_transaction * const pt[], accumulate(struct VSL_data *vsl, struct VSL_transaction * const pt[],
void *priv) void *priv)
{ {
int i, j, tag, skip, match, hit; int i, tag, skip, match, hit;
unsigned u;
double value; double value;
struct VSL_transaction *tr; struct VSL_transaction *tr;
...@@ -259,13 +260,15 @@ accumulate(struct VSL_data *vsl, struct VSL_transaction * const pt[], ...@@ -259,13 +260,15 @@ accumulate(struct VSL_data *vsl, struct VSL_transaction * const pt[],
/* phase out old data */ /* phase out old data */
if (nhist == HIST_N) { if (nhist == HIST_N) {
j = rr_hist[next_hist]; u = rr_hist[next_hist];
if (j < 0) { if (u >= hist_buckets) {
assert(bucket_miss[-j] > 0); u -= hist_buckets;
bucket_miss[-j]--; assert(u < hist_buckets);
assert(bucket_hit[u] > 0);
bucket_hit[u]--;
} else { } else {
assert(bucket_hit[j] > 0); assert(bucket_miss[u] > 0);
bucket_hit[j]--; bucket_miss[u]--;
} }
} else { } else {
++nhist; ++nhist;
...@@ -274,10 +277,10 @@ accumulate(struct VSL_data *vsl, struct VSL_transaction * const pt[], ...@@ -274,10 +277,10 @@ accumulate(struct VSL_data *vsl, struct VSL_transaction * const pt[],
/* phase in new data */ /* phase in new data */
if (hit) { if (hit) {
bucket_hit[i]++; bucket_hit[i]++;
rr_hist[next_hist] = i; rr_hist[next_hist] = i + hist_buckets;
} else { } else {
bucket_miss[i]++; bucket_miss[i]++;
rr_hist[next_hist] = -i; rr_hist[next_hist] = i;
} }
if (++next_hist == HIST_N) { if (++next_hist == HIST_N) {
next_hist = 0; next_hist = 0;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment