r4100 - in trunk/varnish-cache: bin/varnishd include lib/libvcl man

phk at projects.linpro.no phk at projects.linpro.no
Tue Jun 9 12:41:39 CEST 2009


Author: phk
Date: 2009-06-09 12:41:38 +0200 (Tue, 09 Jun 2009)
New Revision: 4100

Modified:
   trunk/varnish-cache/bin/varnishd/cache_expire.c
   trunk/varnish-cache/bin/varnishd/default.vcl
   trunk/varnish-cache/include/vcl.h
   trunk/varnish-cache/include/vcl_returns.h
   trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c
   trunk/varnish-cache/lib/libvcl/vcc_gen_fixed_token.tcl
   trunk/varnish-cache/lib/libvcl/vcc_gen_obj.tcl
   trunk/varnish-cache/lib/libvcl/vcc_obj.c
   trunk/varnish-cache/man/vcl.7so
Log:
Remove the vcl_timeout{} VCL callback.

We had big plans for this originally, but none of them have materialized
because there are better ways to do those things.

For instance: why invent a lot of code to do prefetch, when wget(1) can
do the job already ?

Getting rid of vcl_timeout{} (and vcl_discard{}, see yesterdays commit)
simplifies the expiry codes locking and statekeeping significantly.



Modified: trunk/varnish-cache/bin/varnishd/cache_expire.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_expire.c	2009-06-08 21:40:48 UTC (rev 4099)
+++ trunk/varnish-cache/bin/varnishd/cache_expire.c	2009-06-09 10:41:38 UTC (rev 4100)
@@ -31,20 +31,10 @@
  * We have two data structures, a LRU-list and a binary heap for the timers
  * and two ways to kill objects: TTL-timeouts and LRU cleanups.
  *
- * To avoid holding the mutex while we ponder the fate of objects, we
- * have the following prototol:
+ * Any object on the LRU is also on the binheap and vice versa.
  *
- * Any object on the LRU is also on the binheap (normal case)
+ * We hold one object reference for both data structures.
  *
- * An object is taken off only the binheap but left on the LRU during timer
- * processing because we have no easy way to put it back the right place
- * in the LRU list.
- *
- * An object is taken off both LRU and binheap for LRU processing, (which
- * implies that it must be on both, from where it follows that the timer
- * is not chewing on it) because we expect the majority of objects to be
- * discarded by LRU and save a lock cycle that way, and because we can
- * properly replace it's position in the binheap.
  */
 
 #include "config.h"
@@ -112,6 +102,7 @@
 	struct objcore *oc;
 
 	CHECK_OBJ_NOTNULL(o, OBJECT_MAGIC);
+	AN(o->objhead);
 	AN(ObjIsBusy(o));
 	assert(o->cacheable);
 	HSH_Ref(o);
@@ -151,6 +142,7 @@
 	oc = o->objcore;
 	if (oc == NULL)
 		return (retval);
+	AN(o->objhead);
 	CHECK_OBJ_NOTNULL(oc, OBJCORE_MAGIC);
 	if (Lck_Trylock(&exp_mtx))
 		return (retval);
@@ -241,9 +233,12 @@
 		o = oc->obj;
 		CHECK_OBJ_NOTNULL(o, OBJECT_MAGIC);
 		CHECK_OBJ_NOTNULL(o->objhead, OBJHEAD_MAGIC);
+		assert(oc->flags & OC_F_ONLRU);
 		assert(oc->timer_idx != BINHEAP_NOIDX);
 		binheap_delete(exp_heap, oc->timer_idx);
 		assert(oc->timer_idx == BINHEAP_NOIDX);
+		VTAILQ_REMOVE(&lru, o->objcore, lru_list);
+		oc->flags &= ~OC_F_ONLRU;
 
 		{	/* Sanity checking */
 			struct objcore *oc2 = binheap_root(exp_heap);
@@ -253,32 +248,17 @@
 			}
 		}
 
-		assert(oc->flags & OC_F_ONLRU);
-		Lck_Unlock(&exp_mtx);
-
-		WSL(sp->wrk, SLT_ExpPick, 0, "%u TTL", o->xid);
-
-		sp->obj = o;
-		VCL_timeout_method(sp);
-		sp->obj = NULL;
-
-		assert(sp->handling == VCL_RET_DISCARD);
-		WSL(sp->wrk, SLT_ExpKill, 0,
-		    "%u %d", o->xid, (int)(o->ttl - t));
-		Lck_Lock(&exp_mtx);
-		assert(oc->timer_idx == BINHEAP_NOIDX);
-		assert(oc->flags & OC_F_ONLRU);
-		VTAILQ_REMOVE(&lru, o->objcore, lru_list);
-		oc->flags &= ~OC_F_ONLRU;
 		VSL_stats->n_expired++;
 		Lck_Unlock(&exp_mtx);
+		WSL(sp->wrk, SLT_ExpKill, 0, "%u %d",
+		    o->xid, (int)(o->ttl - t));
 		HSH_Deref(sp->wrk, &o);
 	}
 }
 
 /*--------------------------------------------------------------------
- * Attempt to make space by nuking, with VCLs permission, the oldest
- * object on the LRU list which isn't in use.
+ * Attempt to make space by nuking, the oldest object on the LRU list
+ * which isn't in use.
  * Returns: 1: did, 0: didn't, -1: can't
  */
 
@@ -291,14 +271,12 @@
 	/*
 	 * Find the first currently unused object on the LRU.
 	 *
-	 * Ideally we would have the refcnt in the objcore so we the object does
+	 * Ideally we would have the refcnt in the objcore so we object does
 	 * not need to get paged in for this check, but it does not pay off
 	 * the complexity:  The chances of an object being in front of the LRU,
 	 * with active references, likely means that it is already in core. An
 	 * object with no active references will be prodded further anyway.
 	 *
-	 * NB: Checking refcount here is no guarantee that it does not gain
-	 * another ref while we ponder its destiny without the lock held.
 	 */
 	Lck_Lock(&exp_mtx);
 	VTAILQ_FOREACH(oc, &lru, lru_list) {

Modified: trunk/varnish-cache/bin/varnishd/default.vcl
===================================================================
--- trunk/varnish-cache/bin/varnishd/default.vcl	2009-06-08 21:40:48 UTC (rev 4099)
+++ trunk/varnish-cache/bin/varnishd/default.vcl	2009-06-09 10:41:38 UTC (rev 4100)
@@ -110,11 +110,6 @@
     return (deliver);
 }
 
-sub vcl_timeout {
-    /* XXX: Do not redefine vcl_timeout{}, it is not yet supported */
-    return (discard);
-}
-
 sub vcl_error {
     set obj.http.Content-Type = "text/html; charset=utf-8";
     synthetic {"

Modified: trunk/varnish-cache/include/vcl.h
===================================================================
--- trunk/varnish-cache/include/vcl.h	2009-06-08 21:40:48 UTC (rev 4099)
+++ trunk/varnish-cache/include/vcl.h	2009-06-09 10:41:38 UTC (rev 4100)
@@ -22,10 +22,9 @@
 #define VCL_MET_HIT		(1 << 5)
 #define VCL_MET_FETCH		(1 << 6)
 #define VCL_MET_DELIVER		(1 << 7)
-#define VCL_MET_TIMEOUT		(1 << 8)
-#define VCL_MET_ERROR		(1 << 9)
+#define VCL_MET_ERROR		(1 << 8)
 
-#define VCL_MET_MAX		10
+#define VCL_MET_MAX		9
 
 /* VCL Returns */
 #define VCL_RET_ERROR		0
@@ -69,6 +68,5 @@
 	vcl_func_f	*hit_func;
 	vcl_func_f	*fetch_func;
 	vcl_func_f	*deliver_func;
-	vcl_func_f	*timeout_func;
 	vcl_func_f	*error_func;
 };

Modified: trunk/varnish-cache/include/vcl_returns.h
===================================================================
--- trunk/varnish-cache/include/vcl_returns.h	2009-06-08 21:40:48 UTC (rev 4099)
+++ trunk/varnish-cache/include/vcl_returns.h	2009-06-09 10:41:38 UTC (rev 4100)
@@ -60,10 +60,6 @@
      ((1 << VCL_RET_RESTART)
     | (1 << VCL_RET_DELIVER)
 ))
-VCL_MET_MAC(timeout,TIMEOUT,
-     ((1 << VCL_RET_FETCH)
-    | (1 << VCL_RET_DISCARD)
-))
 VCL_MET_MAC(error,ERROR,
      ((1 << VCL_RET_RESTART)
     | (1 << VCL_RET_DELIVER)

Modified: trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c
===================================================================
--- trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c	2009-06-08 21:40:48 UTC (rev 4099)
+++ trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c	2009-06-09 10:41:38 UTC (rev 4100)
@@ -1,5 +1,5 @@
 /*
- * $Id: vcc_gen_fixed_token.tcl 3948 2009-03-18 11:25:43Z kristian $
+ * $Id: vcc_gen_fixed_token.tcl 4099 2009-06-08 21:40:48Z phk $
  *
  * NB:  This file is machine generated, DO NOT EDIT!
  *
@@ -159,10 +159,10 @@
 
 	/* ../../include/vcl.h */
 
-	vsb_cat(sb, "/*\n * $Id: vcc_gen_fixed_token.tcl 3948 2009-03-18 11");
-	vsb_cat(sb, ":25:43Z kristian $\n *\n * NB:  This file is machine g");
-	vsb_cat(sb, "enerated, DO NOT EDIT!\n *\n * Edit and run vcc_gen_fi");
-	vsb_cat(sb, "xed_token.tcl instead\n */\n\nstruct sess;\n");
+	vsb_cat(sb, "/*\n * $Id: vcc_gen_fixed_token.tcl 4099 2009-06-08 21");
+	vsb_cat(sb, ":40:48Z phk $\n *\n * NB:  This file is machine genera");
+	vsb_cat(sb, "ted, DO NOT EDIT!\n *\n * Edit and run vcc_gen_fixed_t");
+	vsb_cat(sb, "oken.tcl instead\n */\n\nstruct sess;\n");
 	vsb_cat(sb, "struct cli;\n\ntypedef void vcl_init_f(struct cli *);\n");
 	vsb_cat(sb, "typedef void vcl_fini_f(struct cli *);\n");
 	vsb_cat(sb, "typedef int vcl_func_f(struct sess *sp);\n");
@@ -174,17 +174,16 @@
 	vsb_cat(sb, "#define VCL_MET_HIT\t\t(1 << 5)\n");
 	vsb_cat(sb, "#define VCL_MET_FETCH\t\t(1 << 6)\n");
 	vsb_cat(sb, "#define VCL_MET_DELIVER\t\t(1 << 7)\n");
-	vsb_cat(sb, "#define VCL_MET_TIMEOUT\t\t(1 << 8)\n");
-	vsb_cat(sb, "#define VCL_MET_ERROR\t\t(1 << 9)\n");
-	vsb_cat(sb, "\n#define VCL_MET_MAX\t\t10\n\n");
-	vsb_cat(sb, "/* VCL Returns */\n#define VCL_RET_ERROR\t\t0\n");
-	vsb_cat(sb, "#define VCL_RET_LOOKUP\t\t1\n#define VCL_RET_HASH\t\t2");
-	vsb_cat(sb, "\n#define VCL_RET_PIPE\t\t3\n#define VCL_RET_PASS\t\t4");
-	vsb_cat(sb, "\n#define VCL_RET_FETCH\t\t5\n#define VCL_RET_DELIVER\t");
-	vsb_cat(sb, "\t6\n#define VCL_RET_DISCARD\t\t7\n");
-	vsb_cat(sb, "#define VCL_RET_KEEP\t\t8\n#define VCL_RET_RESTART\t\t");
-	vsb_cat(sb, "9\n\n#define VCL_RET_MAX\t\t10\n");
-	vsb_cat(sb, "\nstruct VCL_conf {\n\tunsigned\tmagic;\n");
+	vsb_cat(sb, "#define VCL_MET_ERROR\t\t(1 << 8)\n");
+	vsb_cat(sb, "\n#define VCL_MET_MAX\t\t9\n\n/* VCL Returns */\n");
+	vsb_cat(sb, "#define VCL_RET_ERROR\t\t0\n#define VCL_RET_LOOKUP\t\t");
+	vsb_cat(sb, "1\n#define VCL_RET_HASH\t\t2\n#define VCL_RET_PIPE\t\t");
+	vsb_cat(sb, "3\n#define VCL_RET_PASS\t\t4\n#define VCL_RET_FETCH\t\t");
+	vsb_cat(sb, "5\n#define VCL_RET_DELIVER\t\t6\n");
+	vsb_cat(sb, "#define VCL_RET_DISCARD\t\t7\n#define VCL_RET_KEEP\t\t");
+	vsb_cat(sb, "8\n#define VCL_RET_RESTART\t\t9\n");
+	vsb_cat(sb, "\n#define VCL_RET_MAX\t\t10\n\n");
+	vsb_cat(sb, "struct VCL_conf {\n\tunsigned\tmagic;\n");
 	vsb_cat(sb, "#define VCL_CONF_MAGIC\t0x7406c509\t/* from /dev/rando");
 	vsb_cat(sb, "m */\n\n\tstruct director\t**director;\n");
 	vsb_cat(sb, "\tunsigned\tndirector;\n\tstruct vrt_ref\t*ref;\n");
@@ -197,8 +196,8 @@
 	vsb_cat(sb, "\tvcl_func_f\t*pass_func;\n\tvcl_func_f\t*hash_func;\n");
 	vsb_cat(sb, "\tvcl_func_f\t*miss_func;\n\tvcl_func_f\t*hit_func;\n");
 	vsb_cat(sb, "\tvcl_func_f\t*fetch_func;\n\tvcl_func_f\t*deliver_fun");
-	vsb_cat(sb, "c;\n\tvcl_func_f\t*timeout_func;\n");
-	vsb_cat(sb, "\tvcl_func_f\t*error_func;\n};\n");
+	vsb_cat(sb, "c;\n\tvcl_func_f\t*error_func;\n");
+	vsb_cat(sb, "};\n");
 
 	/* ../../include/vrt.h */
 

Modified: trunk/varnish-cache/lib/libvcl/vcc_gen_fixed_token.tcl
===================================================================
--- trunk/varnish-cache/lib/libvcl/vcc_gen_fixed_token.tcl	2009-06-08 21:40:48 UTC (rev 4099)
+++ trunk/varnish-cache/lib/libvcl/vcc_gen_fixed_token.tcl	2009-06-09 10:41:38 UTC (rev 4100)
@@ -42,7 +42,6 @@
 	{hit		{error restart pass deliver}}
 	{fetch		{error restart pass deliver}}
 	{deliver	{restart deliver}}
-	{timeout	{fetch discard}}
 	{error		{restart deliver}}
 }
 

Modified: trunk/varnish-cache/lib/libvcl/vcc_gen_obj.tcl
===================================================================
--- trunk/varnish-cache/lib/libvcl/vcc_gen_obj.tcl	2009-06-08 21:40:48 UTC (rev 4099)
+++ trunk/varnish-cache/lib/libvcl/vcc_gen_obj.tcl	2009-06-09 10:41:38 UTC (rev 4100)
@@ -233,17 +233,17 @@
     }
     { obj.ttl
 	RW TIME
-	{                         hit               timeout error}
+	{                         hit               error}
 	"const struct sess *"
     }
     { obj.grace
 	RW TIME
-	{                         hit               timeout error}
+	{                         hit               error}
 	"const struct sess *"
     }
     { obj.lastuse
 	RO TIME
-	{                         hit       deliver timeout error}
+	{                         hit       deliver error}
 	"const struct sess *"
     }
     { obj.hash
@@ -280,11 +280,11 @@
     # XXX: or delta times in VCL programs, so this shouldn't be needed /phk
     { now
 	    RO TIME
-	    {recv pipe pass hash miss hit fetch deliver timeout}
+	    {recv pipe pass hash miss hit fetch deliver }
 	    "const struct sess *"
     }
     { req.backend.healthy	RO BOOL
-	    {recv pipe pass hash miss hit fetch deliver timeout}
+	    {recv pipe pass hash miss hit fetch deliver }
 	    "const struct sess *"
     }
 

Modified: trunk/varnish-cache/lib/libvcl/vcc_obj.c
===================================================================
--- trunk/varnish-cache/lib/libvcl/vcc_obj.c	2009-06-08 21:40:48 UTC (rev 4099)
+++ trunk/varnish-cache/lib/libvcl/vcc_obj.c	2009-06-09 10:41:38 UTC (rev 4100)
@@ -1,5 +1,5 @@
 /*
- * $Id: vcc_gen_obj.tcl 4066 2009-05-10 21:21:36Z sky $
+ * $Id: vcc_gen_obj.tcl 4099 2009-06-08 21:40:48Z phk $
  *
  * NB:  This file is machine generated, DO NOT EDIT!
  *
@@ -215,17 +215,17 @@
 	{ "obj.ttl", TIME, 7,
 	    "VRT_r_obj_ttl(sp)",	    "VRT_l_obj_ttl(sp, ",
 	    V_RW,	    0,
-	    VCL_MET_HIT | VCL_MET_TIMEOUT | VCL_MET_ERROR
+	    VCL_MET_HIT | VCL_MET_ERROR
 	},
 	{ "obj.grace", TIME, 9,
 	    "VRT_r_obj_grace(sp)",	    "VRT_l_obj_grace(sp, ",
 	    V_RW,	    0,
-	    VCL_MET_HIT | VCL_MET_TIMEOUT | VCL_MET_ERROR
+	    VCL_MET_HIT | VCL_MET_ERROR
 	},
 	{ "obj.lastuse", TIME, 11,
 	    "VRT_r_obj_lastuse(sp)",	    NULL,
 	    V_RO,	    0,
-	    VCL_MET_HIT | VCL_MET_DELIVER | VCL_MET_TIMEOUT | VCL_MET_ERROR
+	    VCL_MET_HIT | VCL_MET_DELIVER | VCL_MET_ERROR
 	},
 	{ "obj.hash", STRING, 8,
 	    "VRT_r_obj_hash(sp)",	    NULL,
@@ -257,14 +257,12 @@
 	    V_RO,	    0,
 	    VCL_MET_RECV | VCL_MET_PIPE | VCL_MET_PASS | VCL_MET_HASH
 	     | VCL_MET_MISS | VCL_MET_HIT | VCL_MET_FETCH | VCL_MET_DELIVER
-	     | VCL_MET_TIMEOUT
 	},
 	{ "req.backend.healthy", BOOL, 19,
 	    "VRT_r_req_backend_healthy(sp)",	    NULL,
 	    V_RO,	    0,
 	    VCL_MET_RECV | VCL_MET_PIPE | VCL_MET_PASS | VCL_MET_HASH
 	     | VCL_MET_MISS | VCL_MET_HIT | VCL_MET_FETCH | VCL_MET_DELIVER
-	     | VCL_MET_TIMEOUT
 	},
 	{ NULL }
 };

Modified: trunk/varnish-cache/man/vcl.7so
===================================================================
--- trunk/varnish-cache/man/vcl.7so	2009-06-08 21:40:48 UTC (rev 4099)
+++ trunk/varnish-cache/man/vcl.7so	2009-06-09 10:41:38 UTC (rev 4100)
@@ -444,37 +444,8 @@
 .It Cm deliver
 Deliver the object to the client.
 .El
-.\" vcl_timeout
-.It Cm vcl_timeout
-Called by the reaper thread shortly before a cached document reaches
-its expiry time.
-.Pp
-The
-.Cm vcl_timeout
-subroutine may terminate with one of the following keywords:
-.Bl -tag -width indent
-.It Cm fetch
-Request a fresh copy of the object from the backend.
-.It Cm discard
-Discard the object.
 .El
-.\" vcl_discard
-.It Cm vcl_discard
-Called by the reaper thread when a cached document is about to be
-discarded, either because it has expired or because space is running
-low.
 .Pp
-The
-.Cm vcl_discard
-subroutine may terminate with one of the following keywords:
-.Bl -tag -width indent
-.It Cm discard
-Discard the object.
-.It Cm keep
-Keep the object in cache.
-.El
-.El
-.Pp
 If one of these subroutines is left undefined or terminates without
 reaching a handling decision, control will be handed over to the
 builtin default.



More information about the varnish-commit mailing list