[master] 7264c91 Move grace and ttl variables into a common structure and rename HSH_Grace() to EXP_Grace()

Poul-Henning Kamp phk at varnish-cache.org
Wed Mar 2 17:30:59 CET 2011


commit 7264c919ecda6787489232fd15b9cc45c4adaf7f
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Wed Mar 2 16:30:05 2011 +0000

    Move grace and ttl variables into a common structure and rename
    HSH_Grace() to EXP_Grace()

diff --git a/bin/varnishd/cache.h b/bin/varnishd/cache.h
index 05cdcf9..ecad892 100644
--- a/bin/varnishd/cache.h
+++ b/bin/varnishd/cache.h
@@ -232,6 +232,13 @@ extern struct vfp vfp_esi;
 
 /*--------------------------------------------------------------------*/
 
+struct exp {
+	double			ttl;
+	double			grace;
+};
+
+/*--------------------------------------------------------------------*/
+
 struct worker {
 	unsigned		magic;
 #define WORKER_MAGIC		0x6391adcf
@@ -272,8 +279,7 @@ struct worker {
 
 	double			age;
 	double			entered;
-	double			ttl;
-	double			grace;
+	struct exp		exp;
 
 	/* This is only here so VRT can find it */
 	const char		*storage_hint;
@@ -449,10 +455,9 @@ struct object {
 
 	ssize_t			len;
 
-	double			ttl;
 	double			age;
 	double			entered;
-	double			grace;
+	struct exp		exp;
 
 	double			last_modified;
 	double			last_lru;
@@ -517,7 +522,7 @@ struct sess {
 	double			t_end;
 
 	/* Acceptable grace period */
-	double			grace;
+	struct exp		exp;
 
 	enum step		step;
 	unsigned		cur_method;
@@ -628,6 +633,7 @@ extern pthread_t cli_thread;
 #define ASSERT_CLI() do {assert(pthread_self() == cli_thread);} while (0)
 
 /* cache_expiry.c */
+double EXP_Grace(double g);
 void EXP_Insert(struct object *o);
 void EXP_Inject(struct objcore *oc, struct lru *lru, double when);
 void EXP_Init(void);
diff --git a/bin/varnishd/cache_ban.c b/bin/varnishd/cache_ban.c
index 2563f0c..a14c54e 100644
--- a/bin/varnishd/cache_ban.c
+++ b/bin/varnishd/cache_ban.c
@@ -475,8 +475,8 @@ ban_check_object(struct object *o, const struct sess *sp, int has_req)
 		oc_updatemeta(oc);
 		return (0);
 	} else {
-		o->ttl = 0;
-		o->grace = 0;
+		o->exp.ttl = 0;
+		o->exp.grace = 0;
 		oc->ban = NULL;
 		oc_updatemeta(oc);
 		/* BAN also changed, but that is not important any more */
@@ -543,7 +543,7 @@ ban_lurker(struct sess *sp, void *priv)
 		// AZ(oc->flags & OC_F_PERSISTENT);
 		o = oc_getobj(sp->wrk, oc);
 		i = ban_check_object(o, sp, 0);
-		WSP(sp, SLT_Debug, "lurker: %p %g %d", oc, o->ttl, i);
+		WSP(sp, SLT_Debug, "lurker: %p %g %d", oc, o->exp.ttl, i);
 		(void)HSH_Deref(sp->wrk, NULL, &o);
 		TIM_sleep(params->ban_lurker_sleep);
 	}
diff --git a/bin/varnishd/cache_center.c b/bin/varnishd/cache_center.c
index f6065f0..f5e7718 100644
--- a/bin/varnishd/cache_center.c
+++ b/bin/varnishd/cache_center.c
@@ -527,7 +527,7 @@ cnt_fetch(struct sess *sp)
 	 */
 	sp->wrk->entered = TIM_real();
 	sp->wrk->age = 0;
-	sp->wrk->ttl = RFC2616_Ttl(sp);
+	sp->wrk->exp.ttl = RFC2616_Ttl(sp);
 
 	/*
 	 * Initial cacheability determination per [RFC2616, 13.4]
@@ -543,16 +543,16 @@ cnt_fetch(struct sess *sp)
 	case 404: /* Not Found */
 		break;
 	default:
-		sp->wrk->ttl = sp->t_req - 1.;
+		sp->wrk->exp.ttl = sp->t_req - 1.;
 		break;
 	}
 
 	/* pass from vclrecv{} has negative TTL */
 	if (sp->objcore == NULL)
-		sp->wrk->ttl = sp->t_req - 1.;
+		sp->wrk->exp.ttl = sp->t_req - 1.;
 
 	sp->wrk->do_esi = 0;
-	sp->wrk->grace = NAN;
+	sp->wrk->exp.grace = NAN;
 
 	sp->wrk->body_status = RFC2616_Body(sp);
 
@@ -564,7 +564,7 @@ cnt_fetch(struct sess *sp)
 		/* This is a pass from vcl_recv */
 		pass = 1;
 		/* VCL may have fiddled this, but that doesn't help */
-		sp->wrk->ttl = sp->t_req - 1.;
+		sp->wrk->exp.ttl = sp->t_req - 1.;
 	} else if (sp->handling == VCL_RET_HIT_FOR_PASS) {
 		/* pass from vcl_fetch{} -> hit-for-pass */
 		/* XXX: the bereq was not filtered pass... */
@@ -653,12 +653,12 @@ cnt_fetch(struct sess *sp)
 	 */
 	l += strlen("Content-Length: XxxXxxXxxXxxXxxXxx") + sizeof(void *);
 
-	if (sp->wrk->ttl < sp->t_req + params->shortlived ||
+	if (sp->wrk->exp.ttl < sp->t_req + params->shortlived ||
 	    sp->objcore == NULL)
 		sp->wrk->storage_hint = TRANSIENT_STORAGE;
 
 	sp->obj = STV_NewObject(sp, sp->wrk->storage_hint, l,
-	    sp->wrk->ttl, nhttp);
+	    sp->wrk->exp.ttl, nhttp);
 	/* XXX: -> 513 */
 	CHECK_OBJ_NOTNULL(sp->obj, OBJECT_MAGIC);
 
@@ -678,7 +678,7 @@ cnt_fetch(struct sess *sp)
 
 	sp->obj->xid = sp->xid;
 	sp->obj->response = sp->err_code;
-	sp->obj->grace = sp->wrk->grace;
+	sp->obj->exp.grace = sp->wrk->exp.grace;
 	sp->obj->age = sp->wrk->age;
 	sp->obj->entered = sp->wrk->entered;
 	WS_Assert(sp->obj->ws_o);
diff --git a/bin/varnishd/cache_expire.c b/bin/varnishd/cache_expire.c
index 5d2e588..2393ca5 100644
--- a/bin/varnishd/cache_expire.c
+++ b/bin/varnishd/cache_expire.c
@@ -57,6 +57,14 @@ static pthread_t exp_thread;
 static struct binheap *exp_heap;
 static struct lock exp_mtx;
 
+double
+EXP_Grace(double g)
+{
+	if (isnan(g))
+		return (double)(params->default_grace);
+	return (g);
+}
+
 /*--------------------------------------------------------------------
  * When & why does the timer fire for this object ?
  */
@@ -72,7 +80,7 @@ update_object_when(const struct object *o)
 	CHECK_OBJ_NOTNULL(oc, OBJCORE_MAGIC);
 	Lck_AssertHeld(&exp_mtx);
 
-	when = o->ttl + HSH_Grace(o->grace);
+	when = o->exp.ttl + EXP_Grace(o->exp.grace);
 	assert(!isnan(when));
 	if (when == oc->timer_when)
 		return (0);
diff --git a/bin/varnishd/cache_hash.c b/bin/varnishd/cache_hash.c
index b3363cc..107c149 100644
--- a/bin/varnishd/cache_hash.c
+++ b/bin/varnishd/cache_hash.c
@@ -72,14 +72,6 @@ SVNID("$Id$")
 static const struct hash_slinger *hash;
 
 /*---------------------------------------------------------------------*/
-double
-HSH_Grace(double g)
-{
-	if (isnan(g))
-		return (double)(params->default_grace);
-	return (g);
-}
-
 /* Precreate an objhead and object for later use */
 void
 HSH_Prealloc(const struct sess *sp)
@@ -362,7 +354,7 @@ HSH_Lookup(struct sess *sp, struct objhead **poh)
 		o = oc_getobj(sp->wrk, oc);
 		CHECK_OBJ_NOTNULL(o, OBJECT_MAGIC);
 
-		if (o->ttl == 0)
+		if (o->exp.ttl == 0)
 			continue;
 		if (BAN_CheckObject(o, sp))
 			continue;
@@ -370,17 +362,17 @@ HSH_Lookup(struct sess *sp, struct objhead **poh)
 			continue;
 
 		/* If still valid, use it */
-		if (o->ttl >= sp->t_req)
+		if (o->exp.ttl >= sp->t_req)
 			break;
 
 		/*
 		 * Remember any matching objects inside their grace period
 		 * and if there are several, use the least expired one.
 		 */
-		if (o->ttl + HSH_Grace(o->grace) >= sp->t_req) {
-			if (grace_oc == NULL || grace_ttl < o->ttl) {
+		if (o->exp.ttl + EXP_Grace(o->exp.grace) >= sp->t_req) {
+			if (grace_oc == NULL || grace_ttl < o->exp.ttl) {
 				grace_oc = oc;
-				grace_ttl = o->ttl;
+				grace_ttl = o->exp.ttl;
 			}
 		}
 	}
@@ -404,7 +396,7 @@ HSH_Lookup(struct sess *sp, struct objhead **poh)
 					/* Or it is impossible to fetch */
 		o = oc_getobj(sp->wrk, grace_oc);
 		CHECK_OBJ_NOTNULL(o, OBJECT_MAGIC);
-		if (o->ttl + HSH_Grace(sp->grace) >= sp->t_req)
+		if (o->exp.ttl + EXP_Grace(sp->exp.grace) >= sp->t_req)
 			oc = grace_oc;
 	}
 	sp->objcore = NULL;
@@ -552,9 +544,9 @@ HSH_Purge(const struct sess *sp, struct objhead *oh, double ttl, double grace)
 		if (o == NULL)
 			continue;
 		CHECK_OBJ_NOTNULL(o, OBJECT_MAGIC);
-		o->ttl = sp->t_req + ttl;
+		o->exp.ttl = sp->t_req + ttl;
 		if (!isnan(grace))
-			o->grace = grace;
+			o->exp.grace = grace;
 		EXP_Rearm(o);
 		(void)HSH_Deref(sp->wrk, NULL, &o);
 	}
@@ -577,7 +569,7 @@ HSH_Drop(struct sess *sp)
 	o = sp->obj;
 	CHECK_OBJ_NOTNULL(o, OBJECT_MAGIC);
 	AssertObjPassOrBusy(o);
-	o->ttl = 0;
+	o->exp.ttl = 0;
 	if (o->objcore != NULL)		/* Pass has no objcore */
 		HSH_Unbusy(sp);
 	(void)HSH_Deref(sp->wrk, NULL, &sp->obj);
diff --git a/bin/varnishd/cache_session.c b/bin/varnishd/cache_session.c
index 8f26890..0fa662f 100644
--- a/bin/varnishd/cache_session.c
+++ b/bin/varnishd/cache_session.c
@@ -174,7 +174,7 @@ ses_setup(struct sessmem *sm)
 	sp->t_req = NAN;
 	sp->t_resp = NAN;
 	sp->t_end = NAN;
-	sp->grace = NAN;
+	sp->exp.grace = NAN;
 
 	WS_Init(sp->ws, "sess", sm->wsp, sm->workspace);
 	sp->http = sm->http[0];
diff --git a/bin/varnishd/cache_vrt_var.c b/bin/varnishd/cache_vrt_var.c
index 9fa56ba..b562d6d 100644
--- a/bin/varnishd/cache_vrt_var.c
+++ b/bin/varnishd/cache_vrt_var.c
@@ -247,17 +247,17 @@ VRT_l_beresp_ttl(const struct sess *sp, double a)
 	 * We special case and make sure that rounding does not surprise.
 	 */
 	if (a <= 0) {
-		sp->wrk->ttl = sp->t_req - 1;
-		sp->wrk->grace = 0.;
+		sp->wrk->exp.ttl = sp->t_req - 1;
+		sp->wrk->exp.grace = 0.;
 	} else
-		sp->wrk->ttl = sp->t_req + a;
+		sp->wrk->exp.ttl = sp->t_req + a;
 }
 
 double
 VRT_r_beresp_ttl(const struct sess *sp)
 {
 	CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
-	return (sp->wrk->ttl - sp->t_req);
+	return (sp->wrk->exp.ttl - sp->t_req);
 }
 
 /*--------------------------------------------------------------------*/
@@ -351,10 +351,10 @@ VRT_l_obj_ttl(const struct sess *sp, double a)
 	 * We special case and make sure that rounding does not surprise.
 	 */
 	if (a <= 0) {
-		sp->obj->ttl = sp->t_req - 1;
-		sp->obj->grace = 0;
+		sp->obj->exp.ttl = sp->t_req - 1;
+		sp->obj->exp.grace = 0;
 	} else
-		sp->obj->ttl = sp->t_req + a;
+		sp->obj->exp.ttl = sp->t_req + a;
 	EXP_Rearm(sp->obj);
 }
 
@@ -365,7 +365,7 @@ VRT_r_obj_ttl(const struct sess *sp)
 	CHECK_OBJ_NOTNULL(sp->obj, OBJECT_MAGIC);	/* XXX */
 	if (sp->obj->objcore == NULL)
 		return (0.0);
-	return (sp->obj->ttl - sp->t_req);
+	return (sp->obj->exp.ttl - sp->t_req);
 }
 
 /*--------------------------------------------------------------------*/
@@ -451,12 +451,12 @@ VRT_r_##which##_grace(struct sess *sp)				\
 {								\
 								\
 	CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);			\
-	return(HSH_Grace(fld));					\
+	return(EXP_Grace(fld));					\
 }
 
-VRT_DO_GRACE(req, sp->grace, )
-VRT_DO_GRACE(obj, sp->obj->grace, EXP_Rearm(sp->obj))
-VRT_DO_GRACE(beresp, sp->wrk->grace, )
+VRT_DO_GRACE(req, sp->exp.grace, )
+VRT_DO_GRACE(obj, sp->obj->exp.grace, EXP_Rearm(sp->obj))
+VRT_DO_GRACE(beresp, sp->wrk->exp.grace, )
 
 /*--------------------------------------------------------------------
  * req.xid
diff --git a/bin/varnishd/hash_slinger.h b/bin/varnishd/hash_slinger.h
index d4cd87d..d5e81e3 100644
--- a/bin/varnishd/hash_slinger.h
+++ b/bin/varnishd/hash_slinger.h
@@ -58,7 +58,6 @@ struct objcore *HSH_Lookup(struct sess *sp, struct objhead **poh);
 void HSH_Unbusy(const struct sess *sp);
 void HSH_Ref(struct objcore *o);
 void HSH_Drop(struct sess *sp);
-double HSH_Grace(double g);
 void HSH_Init(void);
 void HSH_AddString(const struct sess *sp, const char *str);
 void HSH_FindBan(const struct sess *sp, struct objcore **oc);
diff --git a/bin/varnishd/stevedore.c b/bin/varnishd/stevedore.c
index 9d16c6c..915eadc 100644
--- a/bin/varnishd/stevedore.c
+++ b/bin/varnishd/stevedore.c
@@ -198,9 +198,9 @@ STV_MkObject(struct sess *sp, void *ptr, unsigned ltot,
 
 	http_Setup(o->http, o->ws_o);
 	o->http->magic = HTTP_MAGIC;
-	o->grace = NAN;
+	o->exp.grace = NAN;
 	o->entered = NAN;
-	o->ttl = soc->ttl;
+	o->exp.ttl = soc->ttl;
 	VTAILQ_INIT(&o->store);
 	sp->wrk->stats.n_object++;
 
diff --git a/bin/varnishd/storage_persistent.c b/bin/varnishd/storage_persistent.c
index 0fd2ee4..789f86e 100644
--- a/bin/varnishd/storage_persistent.c
+++ b/bin/varnishd/storage_persistent.c
@@ -493,7 +493,7 @@ smp_allocobj(struct stevedore *stv, struct sess *sp, unsigned ltot,
 
 	CAST_OBJ_NOTNULL(sc, stv->priv, SMP_SC_MAGIC);
 	AN(sp->objcore);
-	AN(sp->wrk->ttl >= 0);
+	AN(sp->wrk->exp.ttl >= 0);
 
 	ltot = IRNUP(sc, ltot);
 
@@ -519,7 +519,7 @@ smp_allocobj(struct stevedore *stv, struct sess *sp, unsigned ltot,
 	/* We have to do this somewhere, might as well be here... */
 	assert(sizeof so->hash == DIGEST_LEN);
 	memcpy(so->hash, oc->objhead->digest, DIGEST_LEN);
-	so->ttl = o->ttl;	/* XXX: grace? */
+	so->ttl = o->exp.ttl;	/* XXX: grace? */
 	so->ptr = (uint8_t*)o - sc->base;
 	so->ban = o->ban_t;
 
diff --git a/bin/varnishd/storage_persistent_silo.c b/bin/varnishd/storage_persistent_silo.c
index 7a8bac2..86f487b 100644
--- a/bin/varnishd/storage_persistent_silo.c
+++ b/bin/varnishd/storage_persistent_silo.c
@@ -433,8 +433,8 @@ smp_oc_getobj(struct worker *wrk, struct objcore *oc)
 			bad |= 0x100;
 
 		if(bad) {
-			o->ttl = 0;
-			o->grace = 0;
+			o->exp.ttl = 0;
+			o->exp.grace = 0;
 			so->ttl = 0;
 		}
 
@@ -463,10 +463,10 @@ smp_oc_updatemeta(struct objcore *oc)
 	CHECK_OBJ_NOTNULL(sg->sc, SMP_SC_MAGIC);
 	so = smp_find_so(sg, oc);
 
-	if (isnan(o->grace))
-		mttl = o->ttl;
+	if (isnan(o->exp.grace))
+		mttl = o->exp.ttl;
 	else
-		mttl = - (o->ttl + o->grace);
+		mttl = - (o->exp.ttl + o->exp.grace);
 
 	if (sg == sg->sc->cur_seg) {
 		/* Lock necessary, we might race close_seg */



More information about the varnish-commit mailing list