r3779 - trunk/varnish-cache/bin/varnishd

phk at projects.linpro.no phk at projects.linpro.no
Tue Feb 17 11:06:19 CET 2009


Author: phk
Date: 2009-02-17 11:06:19 +0100 (Tue, 17 Feb 2009)
New Revision: 3779

Modified:
   trunk/varnish-cache/bin/varnishd/cache.h
   trunk/varnish-cache/bin/varnishd/cache_ban.c
   trunk/varnish-cache/bin/varnishd/cache_center.c
   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/rfc2616.c
Log:
Move the ttl from object up to the objcore



Modified: trunk/varnish-cache/bin/varnishd/cache.h
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache.h	2009-02-17 09:50:05 UTC (rev 3778)
+++ trunk/varnish-cache/bin/varnishd/cache.h	2009-02-17 10:06:19 UTC (rev 3779)
@@ -262,6 +262,7 @@
 #define OBJCORE_MAGIC		0x4d301302
 	struct object		*obj;
 	double			timer_when;
+	double			ttl;
 	unsigned char		timer_what;
 #define OC_T_TTL		1
 #define OC_T_PREFETCH		2
@@ -298,7 +299,6 @@
 
 	double			age;
 	double			entered;
-	double			ttl;
 	double			grace;
 	double			prefetch;
 

Modified: trunk/varnish-cache/bin/varnishd/cache_ban.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_ban.c	2009-02-17 09:50:05 UTC (rev 3778)
+++ trunk/varnish-cache/bin/varnishd/cache_ban.c	2009-02-17 10:06:19 UTC (rev 3779)
@@ -1,6 +1,6 @@
 /*-
  * Copyright (c) 2006 Verdens Gang AS
- * Copyright (c) 2006-2008 Linpro AS
+ * Copyright (c) 2006-2009 Linpro AS
  * All rights reserved.
  *
  * Author: Poul-Henning Kamp <phk at phk.freebsd.dk>
@@ -528,7 +528,7 @@
 		o->ban = b0;
 		return (0);
 	} else {
-		o->ttl = 0;
+		o->objcore->ttl = 0;
 		WSP(sp, SLT_ExpBan, "%u was banned", o->xid);
 		EXP_Rearm(o);
 		o->ban = NULL;

Modified: trunk/varnish-cache/bin/varnishd/cache_center.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_center.c	2009-02-17 09:50:05 UTC (rev 3778)
+++ trunk/varnish-cache/bin/varnishd/cache_center.c	2009-02-17 10:06:19 UTC (rev 3779)
@@ -378,6 +378,7 @@
 cnt_fetch(struct sess *sp)
 {
 	int i;
+	struct objcore *oc;
 
 	CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
 	CHECK_OBJ_NOTNULL(sp->vcl, VCL_CONF_MAGIC);
@@ -414,10 +415,12 @@
 		sp->step = STP_RECV;
 		return (0);
 	case VCL_RET_PASS:
-		if (sp->obj->objcore != NULL)
-			sp->obj->objcore->flags |= OC_F_PASS;
-		if (sp->obj->ttl - sp->t_req < params->default_ttl)
-			sp->obj->ttl = sp->t_req + params->default_ttl;
+		if (sp->obj->objcore != NULL) {
+			oc = sp->obj->objcore;
+			oc->flags |= OC_F_PASS;
+			if (oc->ttl - sp->t_req < params->default_ttl)
+				oc->ttl = sp->t_req + params->default_ttl;
+		}
 		break;
 	case VCL_RET_DELIVER:
 		break;

Modified: trunk/varnish-cache/bin/varnishd/cache_expire.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_expire.c	2009-02-17 09:50:05 UTC (rev 3778)
+++ trunk/varnish-cache/bin/varnishd/cache_expire.c	2009-02-17 10:06:19 UTC (rev 3779)
@@ -97,14 +97,14 @@
 	Lck_AssertHeld(&exp_mtx);
 
 	if (o->prefetch < 0.0) {
-		when = o->ttl + o->prefetch;
+		when = oc->ttl + o->prefetch;
 		what = OC_T_PREFETCH;
 	} else if (o->prefetch > 0.0) {
-		assert(o->prefetch <= o->ttl);
+		assert(o->prefetch <= oc->ttl);
 		when = o->prefetch;
 		what = OC_T_PREFETCH;
 	} else {
-		when = o->ttl + HSH_Grace(o->grace);
+		when = oc->ttl + HSH_Grace(o->grace);
 		what = OC_T_TTL;
 	}
 	assert(!isnan(when));
@@ -304,7 +304,7 @@
 
 			assert(sp->handling == VCL_RET_DISCARD);
 			WSL(&ww, SLT_ExpKill, 0,
-			    "%u %d", o->xid, (int)(o->ttl - t));
+			    "%u %d", o->xid, (int)(o->objcore->ttl - t));
 			Lck_Lock(&exp_mtx);
 			assert(oc->timer_idx == BINHEAP_NOIDX);
 			VTAILQ_REMOVE(&lru, o->objcore, lru_list);

Modified: trunk/varnish-cache/bin/varnishd/cache_hash.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_hash.c	2009-02-17 09:50:05 UTC (rev 3778)
+++ trunk/varnish-cache/bin/varnishd/cache_hash.c	2009-02-17 10:06:19 UTC (rev 3779)
@@ -1,6 +1,6 @@
 /*-
  * Copyright (c) 2006 Verdens Gang AS
- * Copyright (c) 2006-2008 Linpro AS
+ * Copyright (c) 2006-2009 Linpro AS
  * All rights reserved.
  *
  * Author: Poul-Henning Kamp <phk at phk.freebsd.dk>
@@ -275,7 +275,7 @@
 		}
 		if (!o->cacheable)
 			continue;
-		if (o->ttl == 0)
+		if (oc->ttl == 0)
 			continue;
 		if (BAN_CheckObject(o, sp)) 
 			continue;
@@ -283,11 +283,11 @@
 			continue;
 
 		/* If still valid, use it */
-		if (o->ttl >= sp->t_req)
+		if (oc->ttl >= sp->t_req)
 			break;
 
 		/* Remember any matching objects inside their grace period */
-		if (o->ttl + HSH_Grace(o->grace) >= sp->t_req)
+		if (oc->ttl + HSH_Grace(o->grace) >= sp->t_req)
 			grace_o = o;
 	}
 	if (oc == NULL)
@@ -301,7 +301,7 @@
 	 */
 	if (o == NULL && grace_o != NULL &&
 	    grace_o->child != NULL &&
-	    grace_o->ttl + HSH_Grace(sp->grace) >= sp->t_req)
+	    grace_o->objcore->ttl + HSH_Grace(sp->grace) >= sp->t_req)
 		o = grace_o;
 
 	if (o != NULL) {
@@ -377,10 +377,11 @@
 	CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
 	o = sp->obj;
 	CHECK_OBJ_NOTNULL(o, OBJECT_MAGIC);
-	if (o->objcore != NULL)		/* Pass has no objcore */
+	assert(o->refcnt > 0);
+	if (o->objcore != NULL) {	/* Pass has no objcore */
 		AN(ObjIsBusy(o));
-	assert(o->refcnt > 0);
-	o->ttl = 0;
+		o->objcore->ttl = 0;
+	}
 	o->cacheable = 0;
 	if (o->objcore != NULL)		/* Pass has no objcore */
 		HSH_Unbusy(sp);

Modified: trunk/varnish-cache/bin/varnishd/cache_vrt.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_vrt.c	2009-02-17 09:50:05 UTC (rev 3778)
+++ trunk/varnish-cache/bin/varnishd/cache_vrt.c	2009-02-17 10:06:19 UTC (rev 3779)
@@ -1,6 +1,6 @@
 /*-
  * Copyright (c) 2006 Verdens Gang AS
- * Copyright (c) 2006-2008 Linpro AS
+ * Copyright (c) 2006-2009 Linpro AS
  * All rights reserved.
  *
  * Author: Poul-Henning Kamp <phk at phk.freebsd.dk>
@@ -369,6 +369,8 @@
 
 	CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
 	CHECK_OBJ_NOTNULL(sp->obj, OBJECT_MAGIC);	/* XXX */
+	if (sp->obj->objcore == NULL)
+		return;
 	WSP(sp, SLT_TTL, "%u VCL %.0f %.0f",
 	    sp->obj->xid, a, sp->t_req);
 	/*
@@ -378,9 +380,9 @@
 	 * We special case and make sure that rounding does not surprise.
 	 */
 	if (a <= 0)
-		sp->obj->ttl = sp->t_req - 1;
+		sp->obj->objcore->ttl = sp->t_req - 1;
 	else
-		sp->obj->ttl = sp->t_req + a;
+		sp->obj->objcore->ttl = sp->t_req + a;
 	EXP_Rearm(sp->obj);
 }
 
@@ -389,7 +391,9 @@
 {
 	CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
 	CHECK_OBJ_NOTNULL(sp->obj, OBJECT_MAGIC);	/* XXX */
-	return (sp->obj->ttl - sp->t_req);
+	if (sp->obj->objcore == NULL)
+		return (0.0);
+	return (sp->obj->objcore->ttl - sp->t_req);
 }
 
 /*--------------------------------------------------------------------
@@ -428,21 +432,23 @@
 
 	CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
 	CHECK_OBJ_NOTNULL(sp->obj, OBJECT_MAGIC);	/* XXX */
+	if (sp->obj->objcore == NULL)
+		return;
 	sp->obj->prefetch = 0.0;
 	if (a == 0.0)
 		sp->obj->prefetch = a;
-	else if (a > 0.0 && a + sp->t_req <= sp->obj->ttl)
+	else if (a > 0.0 && a + sp->t_req <= sp->obj->objcore->ttl)
 		sp->obj->prefetch = a + sp->t_req;
-	else if (a < 0.0 && a + sp->obj->ttl > sp->t_req)
+	else if (a < 0.0 && a + sp->obj->objcore->ttl > sp->t_req)
 		sp->obj->prefetch = a;
 	else if (a > 0.0)
 		WSL(sp->wrk, SLT_VCL_info, sp->id,
 		    "XID %u: obj.prefetch (%g) after TTL (%g), ignored.",
-		    sp->obj->xid, a, sp->obj->ttl - sp->t_req);
+		    sp->obj->xid, a, sp->obj->objcore->ttl - sp->t_req);
 	else /* if (a < 0.0) */
 		WSL(sp->wrk, SLT_VCL_info, sp->id,
 		    "XID %u: obj.prefetch (%g) less than ttl (%g), ignored.",
-		    sp->obj->xid, a, sp->obj->ttl - sp->t_req);
+		    sp->obj->xid, a, sp->obj->objcore->ttl - sp->t_req);
 	EXP_Rearm(sp->obj);
 }
 

Modified: trunk/varnish-cache/bin/varnishd/rfc2616.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/rfc2616.c	2009-02-17 09:50:05 UTC (rev 3778)
+++ trunk/varnish-cache/bin/varnishd/rfc2616.c	2009-02-17 10:06:19 UTC (rev 3779)
@@ -1,6 +1,6 @@
 /*-
  * Copyright (c) 2006 Verdens Gang AS
- * Copyright (c) 2006-2008 Linpro AS
+ * Copyright (c) 2006-2009 Linpro AS
  * All rights reserved.
  *
  * Author: Poul-Henning Kamp <phk at phk.freebsd.dk>
@@ -173,6 +173,7 @@
 RFC2616_cache_policy(const struct sess *sp, const struct http *hp)
 {
 	int body = 0;
+	double ttl;
 
 	/*
 	 * Initial cacheability determination per [RFC2616, 13.4]
@@ -196,8 +197,10 @@
 		break;
 	}
 
-	sp->obj->ttl = RFC2616_Ttl(sp, hp, sp->obj);
-	if (sp->obj->ttl == 0)
+	ttl = RFC2616_Ttl(sp, hp, sp->obj);
+	if (sp->obj->objcore != NULL)
+		sp->obj->objcore->ttl = ttl;
+	if (ttl == 0)
 		sp->obj->cacheable = 0;
 
 	return (body);



More information about the varnish-commit mailing list