[master] 928dd02 Pass the digest to the backend->healthy() check, rather than the req*

Poul-Henning Kamp phk at varnish-cache.org
Mon Apr 29 15:36:03 CEST 2013


commit 928dd021e709f00f97ae8601510f99c8f515a19e
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Mon Apr 29 13:35:40 2013 +0000

    Pass the digest to the backend->healthy() check, rather than the req*

diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h
index 50128ce..e24fe84 100644
--- a/bin/varnishd/cache/cache.h
+++ b/bin/varnishd/cache/cache.h
@@ -516,7 +516,7 @@ struct busyobj {
 	struct http		*bereq;
 	struct http		*beresp;
 	struct object		*fetch_obj;
-	unsigned char		digest[DIGEST_LEN];
+	uint8_t			digest[DIGEST_LEN];
 	struct exp		exp;
 	struct http_conn	htc;
 
@@ -615,7 +615,7 @@ struct req {
 	uint8_t			*vary_l;
 	uint8_t			*vary_e;
 
-	unsigned char		digest[DIGEST_LEN];
+	uint8_t			digest[DIGEST_LEN];
 
 	enum sess_close		doclose;
 	struct exp		exp;
diff --git a/bin/varnishd/cache/cache_backend.c b/bin/varnishd/cache/cache_backend.c
index 3b1636b..45d9943 100644
--- a/bin/varnishd/cache/cache_backend.c
+++ b/bin/varnishd/cache/cache_backend.c
@@ -42,6 +42,7 @@
 #include "cache_backend.h"
 #include "vrt.h"
 #include "vtcp.h"
+#include "vtim.h"
 
 static struct mempool	*vbcpool;
 
@@ -264,7 +265,7 @@ VBE_AddTrouble(const struct busyobj *bo, double expires)
  */
 
 static unsigned int
-vbe_Healthy(const struct vdi_simple *vs, const struct req *req)
+vbe_Healthy(const struct vdi_simple *vs, const uint8_t *digest)
 {
 	struct trouble *tr;
 	struct trouble *tr2;
@@ -274,7 +275,7 @@ vbe_Healthy(const struct vdi_simple *vs, const struct req *req)
 	VTAILQ_HEAD(, trouble)  troublelist;
 	double now;
 
-	CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
+	AN(digest);
 	CHECK_OBJ_NOTNULL(vs, VDI_SIMPLE_MAGIC);
 	backend = vs->backend;
 	CHECK_OBJ_NOTNULL(backend, BACKEND_MAGIC);
@@ -299,7 +300,7 @@ vbe_Healthy(const struct vdi_simple *vs, const struct req *req)
 	if (threshold == 0 || backend->n_trouble == 0)
 		return (1);
 
-	now = req->t_req;
+	now = VTIM_real();
 
 	retval = 1;
 	VTAILQ_INIT(&troublelist);
@@ -314,7 +315,7 @@ vbe_Healthy(const struct vdi_simple *vs, const struct req *req)
 			continue;
 		}
 
-		if (!memcmp(tr->digest, req->digest, sizeof tr->digest)) {
+		if (!memcmp(tr->digest, digest, sizeof tr->digest)) {
 			retval = 0;
 			break;
 		}
@@ -382,7 +383,7 @@ vbe_GetVbe(struct req *req, struct vdi_simple *vs)
 		VBE_ReleaseConn(vc);
 	}
 
-	if (!vbe_Healthy(vs, req)) {
+	if (!vbe_Healthy(vs, req->digest)) {
 		VSC_C_main->backend_unhealthy++;
 		return (NULL);
 	}
@@ -472,13 +473,13 @@ vdi_simple_getfd(const struct director *d, struct req *req)
 }
 
 static unsigned
-vdi_simple_healthy(const struct director *d, const struct req *req)
+vdi_simple_healthy(const struct director *d, const uint8_t *digest)
 {
 	struct vdi_simple *vs;
 
 	CHECK_OBJ_NOTNULL(d, DIRECTOR_MAGIC);
 	CAST_OBJ_NOTNULL(vs, d->priv, VDI_SIMPLE_MAGIC);
-	return (vbe_Healthy(vs, req));
+	return (vbe_Healthy(vs, digest));
 }
 
 static void
diff --git a/bin/varnishd/cache/cache_backend.h b/bin/varnishd/cache/cache_backend.h
index a291604..13d452e 100644
--- a/bin/varnishd/cache/cache_backend.h
+++ b/bin/varnishd/cache/cache_backend.h
@@ -77,7 +77,7 @@ struct vrt_backend_probe;
 
 typedef struct vbc *vdi_getfd_f(const struct director *, struct req *);
 typedef void vdi_fini_f(const struct director *);
-typedef unsigned vdi_healthy(const struct director *, const struct req *);
+typedef unsigned vdi_healthy(const struct director *, const uint8_t *digest);
 
 struct director {
 	unsigned		magic;
@@ -97,7 +97,7 @@ struct director {
 struct trouble {
 	unsigned		magic;
 #define TROUBLE_MAGIC		0x4211ab21
-	unsigned char		digest[DIGEST_LEN];
+	uint8_t			digest[DIGEST_LEN];
 	double			timeout;
 	VTAILQ_ENTRY(trouble)	list;
 };
diff --git a/bin/varnishd/cache/cache_dir.c b/bin/varnishd/cache/cache_dir.c
index ab43cf1..68e6e99 100644
--- a/bin/varnishd/cache/cache_dir.c
+++ b/bin/varnishd/cache/cache_dir.c
@@ -128,5 +128,5 @@ VDI_Healthy(const struct director *d, const struct req *req)
 
 	CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
 	CHECK_OBJ_NOTNULL(d, DIRECTOR_MAGIC);
-	return (d->healthy(d, req));
+	return (d->healthy(d, req->digest));
 }
diff --git a/bin/varnishd/hash/hash_slinger.h b/bin/varnishd/hash/hash_slinger.h
index ec6a4f2..8a3d08b 100644
--- a/bin/varnishd/hash/hash_slinger.h
+++ b/bin/varnishd/hash/hash_slinger.h
@@ -90,7 +90,7 @@ struct objhead {
 	int			refcnt;
 	struct lock		mtx;
 	VTAILQ_HEAD(,objcore)	objcs;
-	unsigned char		digest[DIGEST_LEN];
+	uint8_t			digest[DIGEST_LEN];
 	struct waitinglist	*waitinglist;
 
 	/*----------------------------------------------------
diff --git a/lib/libvmod_directors/fall_back.c b/lib/libvmod_directors/fall_back.c
index 76cfb4e..af25ac3 100644
--- a/lib/libvmod_directors/fall_back.c
+++ b/lib/libvmod_directors/fall_back.c
@@ -45,12 +45,12 @@ struct vmod_directors_fallback {
 };
 
 static unsigned __match_proto__(vdi_healthy)
-vmod_rr_healthy(const struct director *dir, const struct req *req)
+vmod_rr_healthy(const struct director *dir, const uint8_t *digest)
 {
 	struct vmod_directors_fallback *rr;
 
 	CAST_OBJ_NOTNULL(rr, dir->priv, VMOD_DIRECTORS_FALLBACK_MAGIC);
-	return (vdir_any_healthy(rr->vd, req));
+	return (vdir_any_healthy(rr->vd, digest));
 }
 
 static struct vbc * __match_proto__(vdi_getfd_f)
@@ -65,7 +65,7 @@ vmod_rr_getfd(const struct director *dir, struct req *req)
 	for (u = 0; u < rr->vd->n_backend; u++) {
 		be = rr->vd->backend[u];
 		CHECK_OBJ_NOTNULL(be, DIRECTOR_MAGIC);
-		if (be->healthy(be, req))
+		if (be->healthy(be, req->digest))
 			break;
 	}
 	vdir_unlock(rr->vd);
diff --git a/lib/libvmod_directors/random.c b/lib/libvmod_directors/random.c
index 61eb677..d12b5b2 100644
--- a/lib/libvmod_directors/random.c
+++ b/lib/libvmod_directors/random.c
@@ -50,12 +50,12 @@ struct vmod_directors_random {
 };
 
 static unsigned __match_proto__(vdi_healthy)
-vmod_rr_healthy(const struct director *dir, const struct req *req)
+vmod_rr_healthy(const struct director *dir, const uint8_t *digest)
 {
 	struct vmod_directors_random *rr;
 
 	CAST_OBJ_NOTNULL(rr, dir->priv, VMOD_DIRECTORS_RANDOM_MAGIC);
-	return (vdir_any_healthy(rr->vd, req));
+	return (vdir_any_healthy(rr->vd, digest));
 }
 
 static struct vbc * __match_proto__(vdi_getfd_f)
diff --git a/lib/libvmod_directors/round_robin.c b/lib/libvmod_directors/round_robin.c
index 98df225..35e2454 100644
--- a/lib/libvmod_directors/round_robin.c
+++ b/lib/libvmod_directors/round_robin.c
@@ -46,12 +46,12 @@ struct vmod_directors_round_robin {
 };
 
 static unsigned __match_proto__(vdi_healthy)
-vmod_rr_healthy(const struct director *dir, const struct req *req)
+vmod_rr_healthy(const struct director *dir, const uint8_t *digest)
 {
 	struct vmod_directors_round_robin *rr;
 
 	CAST_OBJ_NOTNULL(rr, dir->priv, VMOD_DIRECTORS_ROUND_ROBIN_MAGIC);
-	return (vdir_any_healthy(rr->vd, req));
+	return (vdir_any_healthy(rr->vd, digest));
 }
 
 static struct vbc * __match_proto__(vdi_getfd_f)
@@ -68,7 +68,7 @@ vmod_rr_getfd(const struct director *dir, struct req *req)
 		be = rr->vd->backend[rr->nxt];
 		rr->nxt++;
 		CHECK_OBJ_NOTNULL(be, DIRECTOR_MAGIC);
-		if (be->healthy(be, req))
+		if (be->healthy(be, req->digest))
 			break;
 	}
 	vdir_unlock(rr->vd);
diff --git a/lib/libvmod_directors/vdir.c b/lib/libvmod_directors/vdir.c
index 0a8e954..c921cf0 100644
--- a/lib/libvmod_directors/vdir.c
+++ b/lib/libvmod_directors/vdir.c
@@ -128,7 +128,7 @@ vdir_add_backend(struct vdir *vd, VCL_BACKEND be, double weight)
 }
 
 unsigned
-vdir_any_healthy(struct vdir *vd, const struct req *req)
+vdir_any_healthy(struct vdir *vd, const uint8_t *digest)
 {
 	unsigned retval = 0;
 	VCL_BACKEND be;
@@ -139,7 +139,7 @@ vdir_any_healthy(struct vdir *vd, const struct req *req)
 	for (u = 0; u < vd->n_backend; u++) {
 		be = vd->backend[u];
 		CHECK_OBJ_NOTNULL(be, DIRECTOR_MAGIC);
-		if (be->healthy(be, req)) {
+		if (be->healthy(be, digest)) {
 			retval = 1;
 			break;
 		}
@@ -185,7 +185,7 @@ vdir_pick_be(struct vdir *vd, const struct req *req, double w, unsigned nloops)
 		u = vdir_pick_by_weight(vd, w * tw, vbm);
 		be = vd->backend[u];
 		CHECK_OBJ_NOTNULL(be, DIRECTOR_MAGIC);
-		if (be->healthy(be, req))
+		if (be->healthy(be, req->digest))
 			break;
 		if (l == 0) {
 			vbm = vd->vbm;
diff --git a/lib/libvmod_directors/vdir.h b/lib/libvmod_directors/vdir.h
index 76795d7..1bd8648 100644
--- a/lib/libvmod_directors/vdir.h
+++ b/lib/libvmod_directors/vdir.h
@@ -47,6 +47,6 @@ void vdir_delete(struct vdir **vdp);
 void vdir_lock(struct vdir *vd);
 void vdir_unlock(struct vdir *vd);
 unsigned vdir_add_backend(struct vdir *vd, VCL_BACKEND be, double weight);
-unsigned vdir_any_healthy(struct vdir *vd, const struct req *);
+unsigned vdir_any_healthy(struct vdir *vd, const uint8_t *digest);
 VCL_BACKEND vdir_pick_be(struct vdir *vd, const struct req *req, double w,
     unsigned nloops);



More information about the varnish-commit mailing list