[3.0] e7d1ca8 Use the hash digest as identification instead of the neutered objhead pointer, in order to not have dependency between trouble entry and objhead lifetime.

Tollef Fog Heen tfheen at varnish-cache.org
Thu May 24 14:47:42 CEST 2012


commit e7d1ca8381c7451c10c79ac76d65588f08c011d4
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Mon Feb 27 12:41:33 2012 +0000

    Use the hash digest as identification instead of the neutered objhead
    pointer, in order to not have dependency between trouble entry and
    objhead lifetime.
    
    Fixes	#1091

diff --git a/bin/varnishd/cache_backend.c b/bin/varnishd/cache_backend.c
index 7e36bda..c4b9a16 100644
--- a/bin/varnishd/cache_backend.c
+++ b/bin/varnishd/cache_backend.c
@@ -251,7 +251,6 @@ vbe_Healthy(const struct vdi_simple *vs, const struct sess *sp)
 	unsigned i = 0, retval;
 	unsigned int threshold;
 	struct backend *backend;
-	uintptr_t target;
 	double now;
 
 	CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
@@ -283,7 +282,6 @@ vbe_Healthy(const struct vdi_simple *vs, const struct sess *sp)
 		return (1);
 
 	now = sp->t_req;
-	target = (uintptr_t)(sp->objcore->objhead);
 
 	old = NULL;
 	retval = 1;
@@ -298,7 +296,7 @@ vbe_Healthy(const struct vdi_simple *vs, const struct sess *sp)
 			break;
 		}
 
-		if (tr->target == target) {
+		if (!memcmp(tr->digest, sp->digest, sizeof tr->digest)) {
 			retval = 0;
 			break;
 		}
diff --git a/bin/varnishd/cache_backend.h b/bin/varnishd/cache_backend.h
index 059b4e7..b16d51e 100644
--- a/bin/varnishd/cache_backend.h
+++ b/bin/varnishd/cache_backend.h
@@ -97,7 +97,7 @@ struct director {
 struct trouble {
 	unsigned		magic;
 #define TROUBLE_MAGIC		0x4211ab21
-	uintptr_t		target;
+	unsigned char		digest[DIGEST_LEN];
 	double			timeout;
 	VTAILQ_ENTRY(trouble)	list;
 };
diff --git a/bin/varnishd/cache_vrt_var.c b/bin/varnishd/cache_vrt_var.c
index 2054953..9a2e500 100644
--- a/bin/varnishd/cache_vrt_var.c
+++ b/bin/varnishd/cache_vrt_var.c
@@ -149,7 +149,7 @@ VRT_l_beresp_saintmode(const struct sess *sp, double a)
 
 	ALLOC_OBJ(new, TROUBLE_MAGIC);
 	AN(new);
-	new->target = (uintptr_t)(sp->objcore->objhead);
+	memcpy(new->digest, sp->digest, sizeof new->digest);
 	new->timeout = sp->t_req + a;
 
 	/* Insert the new item on the list before the first item with a
diff --git a/bin/varnishtest/tests/r01091.vtc b/bin/varnishtest/tests/r01091.vtc
new file mode 100644
index 0000000..9234ffc
--- /dev/null
+++ b/bin/varnishtest/tests/r01091.vtc
@@ -0,0 +1,36 @@
+varnishtest "Test fallback director with saint mode"
+
+server s1 {
+        rxreq
+        txresp -hdr "Foo: 1"
+        accept
+        rxreq
+        txresp -hdr "Foo: 1"
+} -start
+
+server s2 {
+        rxreq
+        txresp -hdr "Foo: 2" -bodylen 1
+} -start
+
+varnish v1 -vcl+backend {
+        director f1 fallback {
+                { .backend = s1; }
+                { .backend = s2; }
+        }
+        sub vcl_recv {
+                set req.backend = f1;
+        }
+        sub vcl_fetch {
+                if(req.restarts < 1) {
+                        set beresp.saintmode = 1h;
+                        return(restart);
+                }
+        }
+} -start
+
+client c1 {
+        txreq
+        rxresp
+        expect resp.http.foo == "2"
+} -run



More information about the varnish-commit mailing list