[master] 452852f Fix implicit cache hit reporting in X-Varnish
Nils Goroll
nils.goroll at uplex.de
Tue Jan 6 19:50:27 CET 2015
commit 452852f6fbaaf9db23cd7c0a8884a129ef993ec2
Author: Nils Goroll <nils.goroll at uplex.de>
Date: Tue Jan 6 19:41:51 2015 +0100
Fix implicit cache hit reporting in X-Varnish
req->wrk->stats->cache_hit only gets reset when workers go to idle
and sum up stats.
This additional space-wasting byte-flag will get collapsed with the
other space-wasting flags soon, it is just added temporarly to separate
commits.
diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h
index 1db9644..20b6022 100644
--- a/bin/varnishd/cache/cache.h
+++ b/bin/varnishd/cache/cache.h
@@ -542,6 +542,7 @@ struct req {
int disable_esi;
uint8_t hash_ignore_busy;
uint8_t hash_always_miss;
+ uint8_t hit;
struct sess *sp;
struct worker *wrk;
diff --git a/bin/varnishd/cache/cache_req_fsm.c b/bin/varnishd/cache/cache_req_fsm.c
index b2e5aef..9255bbd 100644
--- a/bin/varnishd/cache/cache_req_fsm.c
+++ b/bin/varnishd/cache/cache_req_fsm.c
@@ -74,7 +74,7 @@ cnt_deliver(struct worker *wrk, struct req *req)
ObjGetattr(req->wrk, req->objcore, OA_HEADERS, NULL)));
http_ForceField(req->resp, HTTP_HDR_PROTO, "HTTP/1.1");
- if (req->wrk->stats->cache_hit)
+ if (req->hit)
http_PrintfHeader(req->resp,
"X-Varnish: %u %u", VXID(req->vsl->wid),
ObjGetXID(wrk, req->objcore));
@@ -364,6 +364,7 @@ cnt_lookup(struct worker *wrk, struct req *req)
(void)VRB_Ignore(req);// XXX: handle err
}
wrk->stats->cache_hit++;
+ req->hit = 1;
req->req_step = R_STP_DELIVER;
return (REQ_FSM_MORE);
case VCL_RET_FETCH:
@@ -391,6 +392,7 @@ cnt_lookup(struct worker *wrk, struct req *req)
break;
case VCL_RET_PASS:
wrk->stats->cache_hit++;
+ req->hit = 1;
req->req_step = R_STP_PASS;
break;
default:
@@ -546,6 +548,7 @@ cnt_restart(struct worker *wrk, struct req *req)
req->err_code = 0;
req->req_step = R_STP_RECV;
}
+ req->hit = 0;
return (REQ_FSM_MORE);
}
diff --git a/bin/varnishd/http1/cache_http1_fsm.c b/bin/varnishd/http1/cache_http1_fsm.c
index 910dfac..f8814a1 100644
--- a/bin/varnishd/http1/cache_http1_fsm.c
+++ b/bin/varnishd/http1/cache_http1_fsm.c
@@ -186,6 +186,7 @@ http1_cleanup(struct sess *sp, struct worker *wrk, struct req *req)
req->hash_always_miss = 0;
req->hash_ignore_busy = 0;
+ req->hit = 0;
if (sp->fd >= 0 && req->doclose != SC_NULL)
SES_Close(sp, req->doclose);
diff --git a/bin/varnishtest/tests/c00010.vtc b/bin/varnishtest/tests/c00010.vtc
index 18e364b..5e8b087 100644
--- a/bin/varnishtest/tests/c00010.vtc
+++ b/bin/varnishtest/tests/c00010.vtc
@@ -7,9 +7,19 @@ server s1 {
rxreq
expect req.url == "/foo"
txresp -body foobar1
+ rxreq
+ expect req.url == "/pass"
+ txresp -body foobar12
} -start
varnish v1 -vcl+backend {
+ sub vcl_recv {
+ if (req.url == "/foo") {
+ return(hash);
+ } else {
+ return(pass);
+ }
+ }
sub vcl_hit {
return(pass);
}
@@ -22,10 +32,19 @@ client c1 {
expect resp.bodylen == 6
expect resp.http.x-varnish == "1001"
txreq -url "/foo"
+
rxresp
expect resp.status == 200
expect resp.bodylen == 7
expect resp.http.x-varnish == "1003 1004"
+
+ # a pass following a hit on the same wrk should not be
+ # reported as a hit
+ txreq -url "/pass"
+ rxresp
+ expect resp.status == 200
+ expect resp.bodylen == 8
+ expect resp.http.x-varnish == "1005"
}
client c1 -run
More information about the varnish-commit
mailing list