r3941 - in trunk/varnish-cache/bin: varnishd varnishtest/tests

phk at projects.linpro.no phk at projects.linpro.no
Mon Mar 16 15:54:25 CET 2009


Author: phk
Date: 2009-03-16 15:54:24 +0100 (Mon, 16 Mar 2009)
New Revision: 3941

Added:
   trunk/varnish-cache/bin/varnishtest/tests/p00003.vtc
Modified:
   trunk/varnish-cache/bin/varnishd/cache.h
   trunk/varnish-cache/bin/varnishd/cache_ban.c
   trunk/varnish-cache/bin/varnishd/storage_persistent.c
   trunk/varnish-cache/bin/varnishtest/tests/p00002.vtc
Log:
Kick a hole all the way through persistent bans.

Some cleanup is necessary, but now at least it works...



Modified: trunk/varnish-cache/bin/varnishd/cache.h
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache.h	2009-03-16 13:44:36 UTC (rev 3940)
+++ trunk/varnish-cache/bin/varnishd/cache.h	2009-03-16 14:54:24 UTC (rev 3941)
@@ -290,6 +290,7 @@
 	VTAILQ_ENTRY(objcore)	list;
 	VTAILQ_ENTRY(objcore)	lru_list;
 	struct smp_seg		*smp_seg;
+	struct ban		*ban;
 };
 
 /* Object structure --------------------------------------------------*/
@@ -308,8 +309,8 @@
 	struct ws		ws_o[1];
 	unsigned char		*vary;
 
-	struct ban		*ban;
-
+	double			ban_t;
+	struct ban		*ban;	/* XXX --> objcore */
 	unsigned		response;
 
 	unsigned		cacheable;
@@ -462,6 +463,8 @@
 void BAN_Reload(double t0, unsigned flags, const char *ban);
 struct ban *BAN_TailRef(void);
 void BAN_Compile(void);
+struct ban *BAN_RefBan(double t0, struct ban *tail);
+void BAN_Deref(struct ban **ban);
 
 /* cache_center.c [CNT] */
 void CNT_Session(struct sess *sp);

Modified: trunk/varnish-cache/bin/varnishd/cache_ban.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_ban.c	2009-03-16 13:44:36 UTC (rev 3940)
+++ trunk/varnish-cache/bin/varnishd/cache_ban.c	2009-03-16 14:54:24 UTC (rev 3941)
@@ -61,6 +61,7 @@
 
 struct banhead ban_head = VTAILQ_HEAD_INITIALIZER(ban_head);
 struct lock ban_mtx;
+static struct ban *ban_magic;
 
 /*--------------------------------------------------------------------
  * Manipulation of bans
@@ -327,10 +328,10 @@
 	VSL_stats->n_purge++;
 	VSL_stats->n_purge_add++;
 
-	if (params->purge_dups) {
-		be = VTAILQ_LAST(&ban_head, banhead);
+	be = VTAILQ_LAST(&ban_head, banhead);
+	if (params->purge_dups && be != b)
 		be->refcount++;
-	} else
+	else
 		be = NULL;
 
 	SMP_NewBan(b->t0, b->test);
@@ -367,6 +368,7 @@
 	o->ban = ban_start;
 	ban_start->refcount++;
 	Lck_Unlock(&ban_mtx);
+	o->ban_t = o->ban->t0;
 }
 
 static struct ban *
@@ -453,6 +455,7 @@
 
 	if (b == o->ban) {	/* not banned */
 		o->ban = b0;
+		o->ban_t = o->ban->t0;
 		if (o->smp_object != NULL)
 			SMP_BANchanged(o, b0->t0);
 		return (0);
@@ -469,9 +472,26 @@
 }
 
 /*--------------------------------------------------------------------
- * Bans read in from persistent storage on startup
+ * Release a reference
  */
 
+void
+BAN_Deref(struct ban **bb)
+{
+	struct ban *b;
+
+	b = *bb;
+	*bb = NULL;
+	Lck_Lock(&ban_mtx);
+	b->refcount--;
+fprintf(stderr, "DEREF %p %u\n", b, b->refcount);
+	Lck_Unlock(&ban_mtx);
+}
+
+/*--------------------------------------------------------------------
+ * Get a reference to the oldest ban in the list
+ */
+
 struct ban *
 BAN_TailRef(void)
 {
@@ -481,10 +501,36 @@
 	b = VTAILQ_LAST(&ban_head, banhead);
 	AN(b);
 	b->refcount++;
+fprintf(stderr, "TAILREF %p %u\n", b, b->refcount);
 	return (b);
 }
 
 /*--------------------------------------------------------------------
+ * Find and/or Grab a reference to an objects ban based on timestamp
+ */
+
+struct ban *
+BAN_RefBan(double t0, struct ban *tail)
+{
+	struct ban *b;
+
+	VTAILQ_FOREACH(b, &ban_head, list) {
+fprintf(stderr, "REF...: %g %g %g (%s)\n", b->t0, t0, b->t0 - t0, b->test);
+		if (b == tail)
+			break;
+		if (b->t0 <= t0)
+			break;
+	}
+	AN(b);
+fprintf(stderr, "REF: %p %g %g %g\n", b, b->t0, t0, b->t0 - t0);
+	assert(b->t0 >= t0);
+	Lck_Lock(&ban_mtx);
+	b->refcount++;
+	Lck_Unlock(&ban_mtx);
+	return (b);
+}
+
+/*--------------------------------------------------------------------
  * Put a skeleton ban in the list, unless there is an indentical one
  * already.
  */
@@ -533,6 +579,9 @@
 
 	ASSERT_CLI();
 
+	fprintf(stderr, "BAN_MAGIC %u\n", ban_magic->refcount);
+	SMP_NewBan(ban_magic->t0, ban_magic->test);
+	fprintf(stderr, "BAN_MAGIC %u\n", ban_magic->refcount);
 	VTAILQ_FOREACH(b, &ban_head, list) {
 		if (!(b->flags & BAN_F_PENDING))
 			continue;
@@ -634,8 +683,7 @@
 static void
 ccf_purge_list(struct cli *cli, const char * const *av, void *priv)
 {
-	struct ban *b;
-	char t[64];
+	struct ban *b, *bl = NULL;
 
 	(void)av;
 	(void)priv;
@@ -644,23 +692,25 @@
 		/* Attempt to purge last ban entry */
 		Lck_Lock(&ban_mtx);
 		b = BAN_CheckLast();
+		bl = VTAILQ_LAST(&ban_head, banhead);
 		if (b == NULL)
-			VTAILQ_LAST(&ban_head, banhead)->refcount++;
+			bl->refcount++;
 		Lck_Unlock(&ban_mtx);
 		if (b != NULL)
 			BAN_Free(b);
 	} while (b != NULL);
+	AN(bl);
 
 	VTAILQ_FOREACH(b, &ban_head, list) {
-		if (b->refcount == 0 && (b->flags & BAN_F_GONE))
-			continue;
-		TIM_format(b->t0, t);
-		cli_out(cli, "%s %10.6f %5u%s\t%s\n", t, b->t0, b->refcount,
+		// if (b->refcount == 0 && (b->flags & BAN_F_GONE))
+		//	continue;
+		cli_out(cli, "%p %10.6f %5u%s\t%s\n", b, b->t0,
+		    bl == b ? b->refcount - 1 : b->refcount,
 		    b->flags & BAN_F_GONE ? "G" : " ", b->test);
 	}
 
 	Lck_Lock(&ban_mtx);
-	VTAILQ_LAST(&ban_head, banhead)->refcount--;
+	bl->refcount--;
 	Lck_Unlock(&ban_mtx);
 }
 
@@ -682,12 +732,12 @@
 void
 BAN_Init(void)
 {
-	struct ban *b;
 
 	Lck_New(&ban_mtx);
 	CLI_AddFuncs(PUBLIC_CLI, ban_cmds);
 
-	b = BAN_New();
-	b->flags |= BAN_F_GONE;
-	BAN_Insert(b);
+	ban_magic = BAN_New();
+	ban_magic->flags |= BAN_F_GONE;
+	BAN_Insert(ban_magic);
+	fprintf(stderr, "BAN_MAGIC %u\n", ban_magic->refcount);
 }

Modified: trunk/varnish-cache/bin/varnishd/storage_persistent.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/storage_persistent.c	2009-03-16 13:44:36 UTC (rev 3940)
+++ trunk/varnish-cache/bin/varnishd/storage_persistent.c	2009-03-16 14:54:24 UTC (rev 3941)
@@ -525,11 +525,9 @@
 	oc->obj->refcnt = 0;
 	oc->obj->objcore = oc;
 	oc->obj->objhead = oh;
+	oc->obj->ban = oc->ban;
+fprintf(stderr, "OBJ FIX: %p ban %p\n", oc->obj, oc->obj->ban);
 
-	/* XXX: Placeholder for persistent bans */
-	oc->obj->ban = NULL;
-	BAN_NewObj(oc->obj);
-
 	sg->nfixed++;
 }
 
@@ -542,7 +540,7 @@
 {
 	uint8_t *ptr, *ptr2;
 	
-fprintf(stderr, "silo %p BAN %g %s\n", sc, t0, ban);
+	(void)sc;
 	ptr = ptr2 = SIGN_END(ctx);
 
 	memcpy(ptr, "BAN", 4);
@@ -668,6 +666,7 @@
 	CHECK_OBJ_NOTNULL(sg, SMP_SEG_MAGIC);
 	CHECK_OBJ_NOTNULL(sg->sc, SMP_SC_MAGIC);
 
+fprintf(stderr, "OBJ CHG %p ban %10.9f\n", o, t);
 	o->smp_object->ban = t;
 }
 
@@ -733,6 +732,8 @@
 		sp->wrk->nobjcore->flags &= ~OC_F_BUSY;
 		sp->wrk->nobjcore->obj = (void*)so;
 		sp->wrk->nobjcore->smp_seg = sg;
+		sp->wrk->nobjcore->ban = BAN_RefBan(so->ban, sc->tailban);
+fprintf(stderr, "OBJ LOAD: %p ban %10.9f %p\n", so->ptr, so->ban, sp->wrk->nobjcore->ban);
 		memcpy(sp->wrk->nobjhead->digest, so->hash, SHA256_LEN);
 		(void)HSH_Insert(sp);
 		sg->nalloc++;
@@ -879,6 +880,7 @@
 		smp_load_seg(sp, sc, sg);
 
 	sc->flags |= SMP_F_LOADED;
+	BAN_Deref(&sc->tailban);
 	while (1)	
 		sleep (1);
 	return (NULL);
@@ -957,6 +959,7 @@
 	memcpy(so->hash, sp->obj->objhead->digest, DIGEST_LEN);
 	so->ttl = sp->obj->ttl;
 	so->ptr = sp->obj;
+	so->ban = sp->obj->ban_t;
 
 fprintf(stderr, "Object(%p %p)\n", sp, sp->obj);
 }

Modified: trunk/varnish-cache/bin/varnishtest/tests/p00002.vtc
===================================================================
--- trunk/varnish-cache/bin/varnishtest/tests/p00002.vtc	2009-03-16 13:44:36 UTC (rev 3940)
+++ trunk/varnish-cache/bin/varnishtest/tests/p00002.vtc	2009-03-16 14:54:24 UTC (rev 3941)
@@ -36,15 +36,5 @@
 
 varnish v1 -cliok purge.list
 
-varnish v1 -expect n_purge == 1
-
-# client c1 {
-#	txreq -url "/"
-#	rxresp
-#	expect resp.status == 200
-#	expect resp.http.X-Varnish == "1001"
-#	expect resp.http.foo == "bar"
-#} -run
-#
-#varnish v1 -stop
-
+# Count of 3 here, because two "magic" bans are also there"
+varnish v1 -expect n_purge == 3

Added: trunk/varnish-cache/bin/varnishtest/tests/p00003.vtc
===================================================================
--- trunk/varnish-cache/bin/varnishtest/tests/p00003.vtc	                        (rev 0)
+++ trunk/varnish-cache/bin/varnishtest/tests/p00003.vtc	2009-03-16 14:54:24 UTC (rev 3941)
@@ -0,0 +1,57 @@
+# $Id$
+
+test "Ban a persistent object"
+
+shell "rm -f /tmp/__v1/_.per"
+
+server s1 {
+	rxreq 
+	txresp -hdr "Foo: foo"
+} -start
+
+varnish v1 \
+	-arg "-pdiag_bitmap=0x20000" \
+	-arg "-spersistent,/tmp/__v1/_.per,10m" \
+	-vcl+backend { } -start 
+
+varnish v1 -cliok purge.list
+
+client c1 {
+	txreq -url "/"
+	rxresp
+	expect resp.status == 200
+	expect resp.http.X-Varnish == "1001"
+	expect resp.http.foo == "foo"
+} -run
+
+varnish v1 -cliok "purge req.url == /"
+varnish v1 -cliok purge.list
+varnish v1 -stop
+server s1 -wait
+
+server s1 {
+	rxreq 
+	txresp -hdr "Foo: bar"
+} -start
+
+varnish v1 -start
+
+varnish v1 -cliok purge.list
+
+# Count of 2 here, because the "magic" ban is also there"
+# varnish v1 -expect n_purge == 2
+
+
+client c1 {
+	txreq -url "/"
+	rxresp
+	expect resp.status == 200
+	expect resp.http.X-Varnish == "1001"
+	expect resp.http.foo == "bar"
+} -run
+
+
+varnish v1 -cliok purge.list
+
+varnish v1 -stop
+



More information about the varnish-commit mailing list