r5586 - in trunk/varnish-cache: bin/varnishd include

phk at varnish-cache.org phk at varnish-cache.org
Mon Nov 22 12:02:45 CET 2010


Author: phk
Date: 2010-11-22 12:02:45 +0100 (Mon, 22 Nov 2010)
New Revision: 5586

Modified:
   trunk/varnish-cache/bin/varnishd/storage_persistent.c
   trunk/varnish-cache/include/persistent.h
Log:
Wnen we inject a persistent object, the timer we arm it with must
reflect the sum of obj.ttl and obj.grace.

Obj.grace if not set, default to $default_grace, which might have
a different value when we open the silo in a new run.

Solve this, by saving the ttl as the negative sum of (obj.ttl + obj.grace)
if obj.grace is set, or the positive obj.ttl if it is not, and by
adding $default_grace to obj.ttl in the latter case.



Modified: trunk/varnish-cache/bin/varnishd/storage_persistent.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/storage_persistent.c	2010-11-22 10:43:28 UTC (rev 5585)
+++ trunk/varnish-cache/bin/varnishd/storage_persistent.c	2010-11-22 11:02:45 UTC (rev 5586)
@@ -700,6 +700,7 @@
 	struct object *o;
 	struct smp_seg *sg;
 	unsigned smp_index;
+	double mttl;
 
 	CHECK_OBJ_NOTNULL(oc, OBJCORE_MAGIC);
 	o = smp_oc_getobj(NULL, oc);
@@ -710,15 +711,20 @@
 	smp_index = oc->priv2;
 	assert(smp_index < sg->nalloc2);
 
+	if (isnan(o->grace))
+		mttl = o->ttl;
+	else
+		mttl = - (o->ttl + o->grace);
+
 	if (sg == sg->sc->cur_seg) {
 		/* Lock necessary, we might race close_seg */
 		Lck_Lock(&sg->sc->mtx);
 		sg->objs[smp_index].ban = o->ban_t;
-		sg->objs[smp_index].ttl = o->ttl;
+		sg->objs[smp_index].ttl = mttl;
 		Lck_Unlock(&sg->sc->mtx);
 	} else {
 		sg->objs[smp_index].ban = o->ban_t;
-		sg->objs[smp_index].ttl = o->ttl;
+		sg->objs[smp_index].ttl = mttl;
 	}
 }
 
@@ -916,8 +922,10 @@
 	sg->nobj = 0;
 	n = 0;
 	for (;no > 0; so++,no--,n++) {
-		if (so->ttl < t_now)
+		if (so->ttl > 0 && so->ttl < t_now)
 			continue;
+		if (so->ttl < 0 && -so->ttl < t_now)
+			continue;
 		HSH_Prealloc(sp);
 		oc = sp->wrk->nobjcore;
 		oc->flags |= OC_F_NEEDFIXUP | OC_F_LRUDONTMOVE;
@@ -929,7 +937,7 @@
 		memcpy(sp->wrk->nobjhead->digest, so->hash, SHA256_LEN);
 		(void)HSH_Insert(sp);
 		AZ(sp->wrk->nobjcore);
-		EXP_Inject(oc, sg->lru, so->ttl);
+		EXP_Inject(oc, sg->lru, fabs(so->ttl));
 		sg->nobj++;
 	}
 	WRK_SumStat(sp->wrk);

Modified: trunk/varnish-cache/include/persistent.h
===================================================================
--- trunk/varnish-cache/include/persistent.h	2010-11-22 10:43:28 UTC (rev 5585)
+++ trunk/varnish-cache/include/persistent.h	2010-11-22 11:02:45 UTC (rev 5586)
@@ -130,6 +130,9 @@
 
 /*
  * An object descriptor
+ *
+ * A positive ttl is obj.ttl with obj.grace being NAN
+ * A negative ttl is - (obj.ttl + obj.grace)
  */
 
 struct smp_object {




More information about the varnish-commit mailing list