r5170 - in trunk/varnish-cache: bin/varnishd bin/varnishtest/tests doc/sphinx/reference lib/libvcl
martin at varnish-cache.org
martin at varnish-cache.org
Mon Sep 6 15:21:26 CEST 2010
Author: martin
Date: 2010-09-06 15:21:26 +0200 (Mon, 06 Sep 2010)
New Revision: 5170
Added:
trunk/varnish-cache/bin/varnishtest/tests/c00037.vtc
trunk/varnish-cache/bin/varnishtest/tests/c00038.vtc
Modified:
trunk/varnish-cache/bin/varnishd/cache.h
trunk/varnish-cache/bin/varnishd/cache_center.c
trunk/varnish-cache/bin/varnishd/cache_hash.c
trunk/varnish-cache/bin/varnishd/cache_vrt.c
trunk/varnish-cache/doc/sphinx/reference/vcl.rst
trunk/varnish-cache/lib/libvcl/generate.py
Log:
Introduce req.hash_always_miss (force cache miss) and req.hash_ignore_busy (ignore busy objects) variables available in vcl_fetch.
Modified: trunk/varnish-cache/bin/varnishd/cache.h
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache.h 2010-09-06 12:40:48 UTC (rev 5169)
+++ trunk/varnish-cache/bin/varnishd/cache.h 2010-09-06 13:21:26 UTC (rev 5170)
@@ -379,6 +379,9 @@
int esis;
int disable_esi;
+ uint8_t hash_ignore_busy;
+ uint8_t hash_always_miss;
+
struct worker *wrk;
socklen_t sockaddrlen;
Modified: trunk/varnish-cache/bin/varnishd/cache_center.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_center.c 2010-09-06 12:40:48 UTC (rev 5169)
+++ trunk/varnish-cache/bin/varnishd/cache_center.c 2010-09-06 13:21:26 UTC (rev 5170)
@@ -268,6 +268,8 @@
memset(&sp->acct_req, 0, sizeof sp->acct_req);
sp->t_req = NAN;
+ sp->hash_always_miss = 0;
+ sp->hash_ignore_busy = 0;
if (sp->fd >= 0 && sp->doclose != NULL) {
/*
Modified: trunk/varnish-cache/bin/varnishd/cache_hash.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_hash.c 2010-09-06 12:40:48 UTC (rev 5169)
+++ trunk/varnish-cache/bin/varnishd/cache_hash.c 2010-09-06 13:21:26 UTC (rev 5170)
@@ -402,8 +402,9 @@
if (oc == NULL /* We found no live object */
&& grace_oc != NULL /* There is a grace candidate */
&& (busy_oc != NULL /* Somebody else is already busy */
- || !VDI_Healthy(sp->t_req, sp->director, (uintptr_t)oh))) {
- /* Or it is impossible to fetch: */
+ || !VDI_Healthy(sp->t_req, sp->director, (uintptr_t)oh))
+ /* Or it is impossible to fetch */
+ && !sp->hash_ignore_busy) { /* And we've not been told to ignore busy */
o = grace_oc->obj;
CHECK_OBJ_NOTNULL(o, OBJECT_MAGIC);
if (o->ttl + HSH_Grace(sp->grace) >= sp->t_req)
@@ -415,18 +416,27 @@
CHECK_OBJ_NOTNULL(o, OBJECT_MAGIC);
assert(oc->objhead == oh);
- /* We found an object we like */
- oc->refcnt++;
- if (o->hits < INT_MAX)
- o->hits++;
- assert(oh->refcnt > 1);
- Lck_Unlock(&oh->mtx);
- assert(hash->deref(oh));
- *poh = oh;
- return (oc);
+ if(sp->hash_always_miss) {
+ if (o->ttl >= sp->t_req) {
+ o->ttl = sp->t_req - 1;
+ o->grace = HSH_Grace(sp->grace);
+ EXP_Rearm(o);
+ }
+ o = NULL;
+ } else {
+ /* We found an object we like */
+ oc->refcnt++;
+ if (o->hits < INT_MAX)
+ o->hits++;
+ assert(oh->refcnt > 1);
+ Lck_Unlock(&oh->mtx);
+ assert(hash->deref(oh));
+ *poh = oh;
+ return (oc);
+ }
}
- if (busy_oc != NULL) {
+ if (busy_oc != NULL && !sp->hash_ignore_busy) {
/* There are one or more busy objects, wait for them */
if (sp->esis == 0)
VTAILQ_INSERT_TAIL(&oh->waitinglist, sp, list);
Modified: trunk/varnish-cache/bin/varnishd/cache_vrt.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_vrt.c 2010-09-06 12:40:48 UTC (rev 5169)
+++ trunk/varnish-cache/bin/varnishd/cache_vrt.c 2010-09-06 13:21:26 UTC (rev 5170)
@@ -736,6 +736,42 @@
return (p);
}
+/*--------------------------------------------------------------------
+ * req.hash_ignore_busy
+ */
+
+void
+VRT_l_req_hash_ignore_busy(struct sess *sp, unsigned ignore_busy)
+{
+ CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
+ sp->hash_ignore_busy = !!ignore_busy;
+}
+
+unsigned
+VRT_r_req_hash_ignore_busy(struct sess *sp)
+{
+ CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
+ return sp->hash_ignore_busy;
+}
+
+/*--------------------------------------------------------------------
+ * req.hash_always_miss
+ */
+
+void
+VRT_l_req_hash_always_miss(struct sess *sp, unsigned always_miss)
+{
+ CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
+ sp->hash_always_miss = !!always_miss;
+}
+
+unsigned
+VRT_r_req_hash_always_miss(struct sess *sp)
+{
+ CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
+ return sp->hash_always_miss;
+}
+
/*--------------------------------------------------------------------*/
struct sockaddr *
Added: trunk/varnish-cache/bin/varnishtest/tests/c00037.vtc
===================================================================
--- trunk/varnish-cache/bin/varnishtest/tests/c00037.vtc (rev 0)
+++ trunk/varnish-cache/bin/varnishtest/tests/c00037.vtc 2010-09-06 13:21:26 UTC (rev 5170)
@@ -0,0 +1,44 @@
+# $Id$
+
+test "Test req.hash_always_miss in vcl_recv"
+
+server s1 {
+ rxreq
+ txresp -hdr "Inc: 1"
+ rxreq
+ txresp -hdr "Inc: 2"
+} -start
+
+varnish v1 -vcl+backend {
+ sub vcl_recv {
+ if (req.http.x-missit == "1") {
+ set req.hash_always_miss = true;
+ }
+ }
+ sub vcl_deliver {
+ if(obj.hits > 0) {
+ set resp.http.X-Cache = "HIT";
+ } else {
+ set resp.http.X-Cache = "MISS";
+ }
+ }
+ } -start
+
+client c1 {
+ txreq -url "/"
+ rxresp
+ expect resp.status == 200
+ expect resp.http.Inc == "1"
+ txreq -url "/"
+ rxresp
+ expect resp.status == 200
+ expect resp.http.Inc == "1"
+ txreq -url "/" -hdr "x-missit: 1"
+ rxresp
+ expect resp.status == 200
+ expect resp.http.Inc == "2"
+ txreq -url "/"
+ rxresp
+ expect resp.status == 200
+ expect resp.http.Inc == "2"
+} -run
Added: trunk/varnish-cache/bin/varnishtest/tests/c00038.vtc
===================================================================
--- trunk/varnish-cache/bin/varnishtest/tests/c00038.vtc (rev 0)
+++ trunk/varnish-cache/bin/varnishtest/tests/c00038.vtc 2010-09-06 13:21:26 UTC (rev 5170)
@@ -0,0 +1,55 @@
+# $Id$
+
+test "Test req.hash_ignore_busy in vcl_recv"
+
+server s1 {
+ rxreq
+ sema r1 sync 2
+ delay 1
+ txresp -hdr "Server: 1"
+} -start
+
+server s2 {
+ rxreq
+ txresp -hdr "Server: 2"
+} -start
+
+varnish v1 -vcl+backend {
+ sub vcl_recv {
+ if (req.http.x-ignorebusy == "1") {
+ set req.hash_ignore_busy = true;
+ }
+ if (req.http.x-client == "1") {
+ set req.backend = s1;
+ }
+ if (req.http.x-client == "2") {
+ set req.backend = s2;
+ }
+ }
+ sub vcl_deliver {
+ if(obj.hits > 0) {
+ set resp.http.X-Cache = "HIT";
+ } else {
+ set resp.http.X-Cache = "MISS";
+ }
+ }
+} -start
+
+client c1 {
+ txreq -url "/" -hdr "x-client: 1"
+ rxresp
+ expect resp.status == 200
+ expect resp.http.Server == "1"
+} -start
+
+client c2 {
+ sema r1 sync 2
+ txreq -url "/" -hdr "x-client: 2" -hdr "x-ignorebusy: 1"
+ txreq -url "/" -hdr "x-client: 2"
+ rxresp
+ expect resp.status == 200
+ expect resp.http.Server == "2"
+} -start
+
+client c1 -wait
+client c2 -wait
Modified: trunk/varnish-cache/doc/sphinx/reference/vcl.rst
===================================================================
--- trunk/varnish-cache/doc/sphinx/reference/vcl.rst 2010-09-06 12:40:48 UTC (rev 5169)
+++ trunk/varnish-cache/doc/sphinx/reference/vcl.rst 2010-09-06 13:21:26 UTC (rev 5170)
@@ -514,6 +514,12 @@
req.http.header
The corresponding HTTP header.
+req.hash_always_miss
+ Force a cache miss for this request.
+
+req.hash_ignore_busy
+ Ignore any busy object during cache lookup.
+
The following variables are available while preparing a backend
request (either for a cache miss or for pass or pipe mode):
Modified: trunk/varnish-cache/lib/libvcl/generate.py
===================================================================
--- trunk/varnish-cache/lib/libvcl/generate.py 2010-09-06 12:40:48 UTC (rev 5169)
+++ trunk/varnish-cache/lib/libvcl/generate.py 2010-09-06 13:21:26 UTC (rev 5170)
@@ -196,6 +196,18 @@
( ),
'const struct sess *'
),
+ ('req.hash_ignore_busy',
+ 'BOOL',
+ ( 'recv',),
+ ( 'recv',),
+ 'struct sess *'
+ ),
+ ('req.hash_always_miss',
+ 'BOOL',
+ ( 'recv',),
+ ( 'recv',),
+ 'struct sess *'
+ ),
('bereq.request',
'STRING',
( 'pipe', 'pass', 'miss', 'fetch',),
More information about the varnish-commit
mailing list