r5661 - in trunk/varnish-cache: bin/varnishd bin/varnishtest/tests lib/libvcl

phk at varnish-cache.org phk at varnish-cache.org
Mon Dec 20 13:59:30 CET 2010


Author: phk
Date: 2010-12-20 13:59:30 +0100 (Mon, 20 Dec 2010)
New Revision: 5661

Modified:
   trunk/varnish-cache/bin/varnishd/cache_center.c
   trunk/varnish-cache/bin/varnishd/stevedore.c
   trunk/varnish-cache/bin/varnishd/stevedore.h
   trunk/varnish-cache/bin/varnishtest/tests/v00033.vtc
   trunk/varnish-cache/lib/libvcl/vcc_storage.c
Log:
Pass beresp.storage into stevedore selection as a hint, and pick any
stevedore which matches the name exactly.



Modified: trunk/varnish-cache/bin/varnishd/cache_center.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_center.c	2010-12-20 12:39:51 UTC (rev 5660)
+++ trunk/varnish-cache/bin/varnishd/cache_center.c	2010-12-20 12:59:30 UTC (rev 5661)
@@ -351,7 +351,8 @@
 		HSH_Prealloc(sp);
 		sp->wrk->cacheable = 0;
 		/* XXX: 1024 is a pure guess */
-		sp->obj = STV_NewObject(sp, 1024, 0, params->http_headers);
+		sp->obj = STV_NewObject(sp, NULL, 1024, 0,
+		     params->http_headers);
 		sp->obj->xid = sp->xid;
 		sp->obj->entered = sp->t_req;
 	} else {
@@ -567,7 +568,7 @@
 	 * XXX: also.
 	 */
 
-	sp->obj = STV_NewObject(sp, l, sp->wrk->ttl, nhttp);
+	sp->obj = STV_NewObject(sp, sp->wrk->storage, l, sp->wrk->ttl, nhttp);
 	CHECK_OBJ_NOTNULL(sp->obj, OBJECT_MAGIC);
 
 	sp->wrk->storage = NULL;

Modified: trunk/varnish-cache/bin/varnishd/stevedore.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/stevedore.c	2010-12-20 12:39:51 UTC (rev 5660)
+++ trunk/varnish-cache/bin/varnishd/stevedore.c	2010-12-20 12:59:30 UTC (rev 5661)
@@ -82,10 +82,18 @@
  */
 
 static struct stevedore *
-stv_pick_stevedore(void)
+stv_pick_stevedore(const char *hint)
 {
 	struct stevedore *stv;
 
+	if (hint != NULL && *hint != '\0') {
+		VTAILQ_FOREACH(stv, &stevedores, list) {
+			if (!strcmp(stv->ident, hint))
+				return (stv);
+		}
+		if (!strcmp(TRANSIENT_NAME, hint))
+			return (stv_transient);
+	}
 	/* pick a stevedore and bump the head along */
 	stv = VTAILQ_NEXT(stv_next, list);
 	if (stv == NULL)
@@ -93,8 +101,6 @@
 	AN(stv);
 	AN(stv->name);
 	stv_next = stv;
-	if (stv->transient)
-		stv = stv_pick_stevedore();
 	return (stv);
 }
 
@@ -239,7 +245,8 @@
  */
 
 struct object *
-STV_NewObject(struct sess *sp, unsigned wsl, double ttl, unsigned nhttp)
+STV_NewObject(struct sess *sp, const char *hint, unsigned wsl, double ttl,
+    unsigned nhttp)
 {
 	struct object *o;
 	struct stevedore *stv;
@@ -264,7 +271,7 @@
 	if (!sp->wrk->cacheable)
 		stv = stv_transient;
 	else
-		stv = stv_pick_stevedore();
+		stv = stv_pick_stevedore(hint);
 	AN(stv->allocobj);
 	o = stv->allocobj(stv, sp, ltot, &soc);
 	CHECK_OBJ_NOTNULL(o, OBJECT_MAGIC);

Modified: trunk/varnish-cache/bin/varnishd/stevedore.h
===================================================================
--- trunk/varnish-cache/bin/varnishd/stevedore.h	2010-12-20 12:39:51 UTC (rev 5660)
+++ trunk/varnish-cache/bin/varnishd/stevedore.h	2010-12-20 12:59:30 UTC (rev 5661)
@@ -79,8 +79,8 @@
 struct object *STV_MkObject(struct sess *sp, void *ptr, unsigned ltot,
     const struct stv_objsecrets *soc);
 
-struct object *STV_NewObject(struct sess *sp, unsigned len, double ttl,
-    unsigned nhttp);
+struct object *STV_NewObject(struct sess *sp, const char *hint, unsigned len,
+    double ttl, unsigned nhttp);
 struct storage *STV_alloc(const struct sess *sp, size_t size);
 void STV_trim(struct storage *st, size_t size);
 void STV_free(struct storage *st);

Modified: trunk/varnish-cache/bin/varnishtest/tests/v00033.vtc
===================================================================
--- trunk/varnish-cache/bin/varnishtest/tests/v00033.vtc	2010-12-20 12:39:51 UTC (rev 5660)
+++ trunk/varnish-cache/bin/varnishtest/tests/v00033.vtc	2010-12-20 12:59:30 UTC (rev 5661)
@@ -5,7 +5,9 @@
 
 server s1 {
 	rxreq
-	txresp
+	txresp -bodylen 4
+	rxreq
+	txresp -bodylen 5
 } -start
 
 varnish v1 -vcl+backend {
@@ -14,7 +16,13 @@
 		set beresp.http.foo =
 		    storage.nowhere.free_space +
 		    1 B + 1 KB + 1 MB + 1GB + 1TB;
+		if (req.url == "/foo") {
+			set beresp.storage = "Transient";
+		}
 	}
+	sub vcl_deliver {
+		set resp.http.bar = storage.Transient.used_space > 0B;
+	}
 } -start
 
 client c1 {
@@ -22,4 +30,11 @@
 	rxresp
 	expect resp.status == 200
 	expect resp.http.foo == 1100586419201.000
+	expect resp.http.bar == false
+
+	txreq -url /foo
+	rxresp
+	expect resp.status == 200
+	expect resp.http.foo == 1100586419201.000
+	expect resp.http.bar == true
 } -run

Modified: trunk/varnish-cache/lib/libvcl/vcc_storage.c
===================================================================
--- trunk/varnish-cache/lib/libvcl/vcc_storage.c	2010-12-20 12:39:51 UTC (rev 5660)
+++ trunk/varnish-cache/lib/libvcl/vcc_storage.c	2010-12-20 12:59:30 UTC (rev 5661)
@@ -83,7 +83,11 @@
 	AN(v);
 
 	v->name = TlDupTok(tl, t);
-	v->r_methods = VCL_MET_FETCH;		/* XXX ? */
+	v->r_methods = 0
+#define VCL_MET_MAC(l,u,b)	| VCL_MET_##u
+#include "vcl_returns.h"
+#undef VCL_MET_MAC
+		;
 	v->fmt = fmt;
 
 	return (v);




More information about the varnish-commit mailing list