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

phk at projects.linpro.no phk at projects.linpro.no
Mon Jan 28 11:28:24 CET 2008


Author: phk
Date: 2008-01-28 11:28:24 +0100 (Mon, 28 Jan 2008)
New Revision: 2392

Modified:
   trunk/varnish-cache/bin/varnishd/cache.h
   trunk/varnish-cache/bin/varnishd/cache_expire.c
   trunk/varnish-cache/bin/varnishd/cache_hash.c
   trunk/varnish-cache/bin/varnishd/cache_vrt.c
   trunk/varnish-cache/bin/varnishd/cache_ws.c
   trunk/varnish-cache/include/vrt_obj.h
   trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c
   trunk/varnish-cache/lib/libvcl/vcc_gen_obj.tcl
   trunk/varnish-cache/lib/libvcl/vcc_obj.c
Log:
Finish (the "easy") part of degraded mode:

Add req.grace timer:  We only serve degraded mode objects if both the
request and the object's grace timers are satisfied.

Sort expiry list on obj.ttl + obj.grace and fiddle list if either changes.

In the hash lookup: record if any objects still in grace by obj.grace which
match our Vary: criteria (if any).

If no in-ttl object was found AND we have a graced object AND it is also
graced by req.grace AND it is being fetched: serve the graced object.

Otherwise, mark us as successor to the graced object while we fetch to
give others the chance.

When we unbusy the object, clean the magic pointers between the two
objects again.


To play with this you need at least:

	sub vcl_recv {
		set req.grace = 2m;
	}
	sub vcl_fetch {
		set obj.grace = 2m;
	}


Modified: trunk/varnish-cache/bin/varnishd/cache.h
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache.h	2008-01-28 09:28:47 UTC (rev 2391)
+++ trunk/varnish-cache/bin/varnishd/cache.h	2008-01-28 10:28:24 UTC (rev 2392)
@@ -220,7 +220,6 @@
 };
 
 /* -------------------------------------------------------------------*/
-
 enum e_objtimer {
 	TIMER_TTL,
 	TIMER_PREFETCH
@@ -271,6 +270,10 @@
 	VTAILQ_HEAD(, esi_bit)	esibits;
 
 	double			lru_stamp;
+
+	/* Prefetch */
+	struct object		*parent;
+	struct object		*child;
 };
 
 struct objhead {
@@ -326,6 +329,9 @@
 	double			t_resp;
 	double			t_end;
 
+	/* Acceptable grace period */
+	double			grace;
+
 	enum step		step;
 	unsigned		cur_method;
 	unsigned 		handling;

Modified: trunk/varnish-cache/bin/varnishd/cache_expire.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_expire.c	2008-01-28 09:28:47 UTC (rev 2391)
+++ trunk/varnish-cache/bin/varnishd/cache_expire.c	2008-01-28 10:28:24 UTC (rev 2392)
@@ -79,7 +79,7 @@
 		o->timer_when = o->prefetch;
 		o->timer_what = TIMER_PREFETCH;
 	} else {
-		o->timer_when = o->ttl;
+		o->timer_when = o->ttl + o->grace;
 		o->timer_what = TIMER_TTL;
 	}
 }

Modified: trunk/varnish-cache/bin/varnishd/cache_hash.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_hash.c	2008-01-28 09:28:47 UTC (rev 2391)
+++ trunk/varnish-cache/bin/varnishd/cache_hash.c	2008-01-28 10:28:24 UTC (rev 2392)
@@ -173,7 +173,7 @@
 	struct worker *w;
 	struct http *h;
 	struct objhead *oh;
-	struct object *o, *busy_o;
+	struct object *o, *busy_o, *grace_o;
 
 	CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
 	CHECK_OBJ_NOTNULL(sp->wrk, WORKER_MAGIC);
@@ -198,6 +198,7 @@
 	}
 
 	busy_o = NULL;
+	grace_o = NULL;
 	VTAILQ_FOREACH(o, &oh->objects, list) {
 		if (o->busy) {
 			busy_o = o;
@@ -207,8 +208,6 @@
 			continue;
 		if (o->ttl == 0) 
 			continue;
-		if (o->ttl <= sp->t_req) 
-			continue;
 		if (BAN_CheckObject(o, h->hd[HTTP_HDR_URL].b, oh->hash)) {
 			o->ttl = 0;
 			WSP(sp, SLT_ExpBan, "%u was banned", o->xid);
@@ -216,9 +215,27 @@
 				EXP_TTLchange(o);
 			continue;
 		}
-		if (o->vary == NULL || VRY_Match(sp, o->vary))
+		if (o->vary != NULL && !VRY_Match(sp, o->vary))
+			continue;
+
+		/* If still valid, use it */
+		if (o->ttl >= sp->t_req)
 			break;
+
+		/* Remember any matching objects inside their grace period */
+		if (o->ttl + o->grace >= sp->t_req)
+			grace_o = o;
 	}
+
+	/*
+	 * If we have a object in grace and being fetched,
+	 * use it, if req.grace is also satisified.
+	 */
+	if (o == NULL && grace_o != NULL &&
+	    grace_o->child != NULL &&
+	    grace_o->ttl + sp->grace >= sp->t_req)
+		o = grace_o;
+
 	if (o != NULL) {
 		/* We found an object we like */
 		o->refcnt++;
@@ -239,8 +256,14 @@
 	o = w->nobj;
 	w->nobj = NULL;
 	o->objhead = oh;
+	/* XXX: Should this not be ..._HEAD now ? */
 	VTAILQ_INSERT_TAIL(&oh->objects, o, list);
 	/* NB: do not deref objhead the new object inherits our reference */
+	if (grace_o != NULL) {
+		grace_o->child = o;
+		o->parent = grace_o;
+		grace_o->refcnt++;
+	}
 	UNLOCK(&oh->mtx);
 	BAN_NewObj(o);
 	/*
@@ -271,6 +294,7 @@
 HSH_Unbusy(struct object *o)
 {
 	struct objhead *oh;
+	struct object *parent;
 
 	CHECK_OBJ_NOTNULL(o, OBJECT_MAGIC);
 	assert(o->busy);
@@ -284,8 +308,14 @@
 	}
 	o->busy = 0;
 	hsh_rush(oh);
+	parent = o->parent;
+	o->parent = NULL;
+	if (parent != NULL)
+		parent->child = NULL;
 	if (oh != NULL)
 		UNLOCK(&oh->mtx);
+	if (parent != NULL)
+		HSH_Deref(parent);
 }
 
 void

Modified: trunk/varnish-cache/bin/varnishd/cache_vrt.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_vrt.c	2008-01-28 09:28:47 UTC (rev 2391)
+++ trunk/varnish-cache/bin/varnishd/cache_vrt.c	2008-01-28 10:28:24 UTC (rev 2392)
@@ -317,6 +317,8 @@
 	if (a < 0)
 		a = 0;
 	sp->obj->grace = a;
+	if (sp->obj->timer_idx != 0)
+		EXP_TTLchange(sp->obj);
 }
 
 double
@@ -427,6 +429,27 @@
 	return (sp->restarts);
 }
 
+/*--------------------------------------------------------------------
+ * req.grace
+ */
+
+void
+VRT_l_req_grace(struct sess *sp, double a)
+{
+
+	CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
+	if (a < 0)
+		a = 0;
+	sp->grace = a;
+}
+
+double
+VRT_r_req_grace(struct sess *sp)
+{
+	CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
+	return (sp->grace);
+}
+
 /*--------------------------------------------------------------------*/
 
 const char *

Modified: trunk/varnish-cache/bin/varnishd/cache_ws.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_ws.c	2008-01-28 09:28:47 UTC (rev 2391)
+++ trunk/varnish-cache/bin/varnishd/cache_ws.c	2008-01-28 10:28:24 UTC (rev 2392)
@@ -46,7 +46,7 @@
 #include "cache.h"
 
 /* Enable this to get detailed logging of WS usage */
-#ifdef DIAGNOSTICS
+#ifdef DIAGNOSTICS0
 #  define WS_DEBUG(fmt, ...)	VSL(SLT_Debug, 0, fmt, __VA_ARGS__)
 #else
 #  define WS_DEBUG(fmt, ...)	/* nothing */

Modified: trunk/varnish-cache/include/vrt_obj.h
===================================================================
--- trunk/varnish-cache/include/vrt_obj.h	2008-01-28 09:28:47 UTC (rev 2391)
+++ trunk/varnish-cache/include/vrt_obj.h	2008-01-28 10:28:24 UTC (rev 2392)
@@ -22,6 +22,8 @@
 struct backend * VRT_r_req_backend(struct sess *);
 void VRT_l_req_backend(struct sess *, struct backend *);
 int VRT_r_req_restarts(const struct sess *);
+double VRT_r_req_grace(struct sess *);
+void VRT_l_req_grace(struct sess *, double);
 const char * VRT_r_bereq_request(const struct sess *);
 void VRT_l_bereq_request(const struct sess *, const char *, ...);
 const char * VRT_r_bereq_url(const struct sess *);

Modified: trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c
===================================================================
--- trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c	2008-01-28 09:28:47 UTC (rev 2391)
+++ trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c	2008-01-28 10:28:24 UTC (rev 2392)
@@ -521,6 +521,8 @@
 	vsb_cat(sb, "struct backend * VRT_r_req_backend(struct sess *);\n");
 	vsb_cat(sb, "void VRT_l_req_backend(struct sess *, struct backend *);\n");
 	vsb_cat(sb, "int VRT_r_req_restarts(const struct sess *);\n");
+	vsb_cat(sb, "double VRT_r_req_grace(const struct sess *);\n");
+	vsb_cat(sb, "void VRT_l_req_grace(const struct sess *, double);\n");
 	vsb_cat(sb, "const char * VRT_r_bereq_request(const struct sess *);\n");
 	vsb_cat(sb, "void VRT_l_bereq_request(const struct sess *, const char *, ...);\n");
 	vsb_cat(sb, "const char * VRT_r_bereq_url(const struct sess *);\n");

Modified: trunk/varnish-cache/lib/libvcl/vcc_gen_obj.tcl
===================================================================
--- trunk/varnish-cache/lib/libvcl/vcc_gen_obj.tcl	2008-01-28 09:28:47 UTC (rev 2391)
+++ trunk/varnish-cache/lib/libvcl/vcc_gen_obj.tcl	2008-01-28 10:28:24 UTC (rev 2392)
@@ -97,6 +97,11 @@
 		{recv pipe pass hash miss hit fetch deliver                }
 		"const struct sess *"
 	}
+	{ req.grace
+		RW TIME
+		{recv pipe pass hash miss hit fetch deliver		   }
+		"struct sess *"
+	}
 
 	# Request sent to backend
 	{ bereq.request

Modified: trunk/varnish-cache/lib/libvcl/vcc_obj.c
===================================================================
--- trunk/varnish-cache/lib/libvcl/vcc_obj.c	2008-01-28 09:28:47 UTC (rev 2391)
+++ trunk/varnish-cache/lib/libvcl/vcc_obj.c	2008-01-28 10:28:24 UTC (rev 2392)
@@ -105,6 +105,13 @@
 	    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
 	},
+	{ "req.grace", TIME, 9,
+	    "VRT_r_req_grace(sp)",
+	    "VRT_l_req_grace(sp, ",
+	    V_RW,
+	    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
+	},
 	{ "bereq.request", STRING, 13,
 	    "VRT_r_bereq_request(sp)",
 	    "VRT_l_bereq_request(sp, ",




More information about the varnish-commit mailing list