r4414 - trunk/varnish-cache/bin/varnishd

phk at projects.linpro.no phk at projects.linpro.no
Wed Dec 16 13:28:47 CET 2009


Author: phk
Date: 2009-12-16 13:28:47 +0100 (Wed, 16 Dec 2009)
New Revision: 4414

Modified:
   trunk/varnish-cache/bin/varnishd/cache.h
   trunk/varnish-cache/bin/varnishd/cache_backend.c
   trunk/varnish-cache/bin/varnishd/cache_backend.h
   trunk/varnish-cache/bin/varnishd/cache_dir_random.c
   trunk/varnish-cache/bin/varnishd/cache_dir_round_robin.c
   trunk/varnish-cache/bin/varnishd/cache_fetch.c
   trunk/varnish-cache/bin/varnishd/cache_hash.c
   trunk/varnish-cache/bin/varnishd/cache_pipe.c
   trunk/varnish-cache/bin/varnishd/cache_vrt.c
Log:
Polish pass:  Add wrapped methods for ->getfd and ->healthy.

Remove the backend deref code that is no longer needed by random/round-robin
directors, since they only reference other directors in the same VCL.

Stop messing with sp->vbe behind the back, make the assignment explicit
where it matters.



Modified: trunk/varnish-cache/bin/varnishd/cache.h
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache.h	2009-12-16 11:58:47 UTC (rev 4413)
+++ trunk/varnish-cache/bin/varnishd/cache.h	2009-12-16 12:28:47 UTC (rev 4414)
@@ -451,7 +451,8 @@
 
 /* cache_backend.c */
 
-void VBE_GetFd(struct sess *sp);
+struct vbe_conn *VBE_GetFd(struct director *, struct sess *sp);
+int VBE_Healthy(struct director *, const struct sess *sp);
 void VBE_ClosedFd(struct sess *sp);
 void VBE_RecycleFd(struct sess *sp);
 void VBE_AddHostHeader(const struct sess *sp);

Modified: trunk/varnish-cache/bin/varnishd/cache_backend.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_backend.c	2009-12-16 11:58:47 UTC (rev 4413)
+++ trunk/varnish-cache/bin/varnishd/cache_backend.c	2009-12-16 12:28:47 UTC (rev 4414)
@@ -353,21 +353,6 @@
 	return (vc);
 }
 
-/*--------------------------------------------------------------------
- * Get a connection to whatever backend the director think this session
- * should contact.
- */
-
-void
-VBE_GetFd(struct sess *sp)
-{
-
-	CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
-	CHECK_OBJ_NOTNULL(sp->director, DIRECTOR_MAGIC);
-
-	AN (sp->director->getfd);
-	sp->vbe = sp->director->getfd(sp->director, sp);
-}
 /* Close a connection ------------------------------------------------*/
 
 void
@@ -410,7 +395,32 @@
 	VBE_DropRefLocked(bp);
 }
 
+/* Get a connection --------------------------------------------------*/
 
+struct vbe_conn *
+VBE_GetFd(struct director *d, struct sess *sp)
+{
+
+	CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
+	if (d == NULL)
+		d = sp->director;
+	CHECK_OBJ_NOTNULL(d, DIRECTOR_MAGIC);
+	return (d->getfd(d, sp));
+}
+
+/* Cheack health -----------------------------------------------------*/
+
+int
+VBE_Healthy(struct director *d, const struct sess *sp)
+{
+
+	CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
+	if (d == NULL)
+		d = sp->director;
+	CHECK_OBJ_NOTNULL(d, DIRECTOR_MAGIC);
+	return (d->healthy(d, sp));
+}
+
 /*--------------------------------------------------------------------
  * The "simple" director really isn't, since thats where all the actual
  * connections happen.  Nontheless, pretend it is simple by sequestering

Modified: trunk/varnish-cache/bin/varnishd/cache_backend.h
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_backend.h	2009-12-16 11:58:47 UTC (rev 4413)
+++ trunk/varnish-cache/bin/varnishd/cache_backend.h	2009-12-16 12:28:47 UTC (rev 4414)
@@ -92,24 +92,6 @@
 	void			*priv;
 };
 
-static inline struct vbe_conn *
-dir_getfd(struct director *d, struct sess *sp)
-{
-
-	CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
-	CHECK_OBJ_NOTNULL(d, DIRECTOR_MAGIC);
-	return (d->getfd(d, sp));
-}
-
-static inline int
-dir_healthy(struct director *d, const struct sess *sp)
-{
-
-	CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
-	CHECK_OBJ_NOTNULL(d, DIRECTOR_MAGIC);
-	return (d->healthy(d, sp));
-}
-
 /*--------------------------------------------------------------------
  * List of objectheads that have recently been rejected by VCL.
  */

Modified: trunk/varnish-cache/bin/varnishd/cache_dir_random.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_dir_random.c	2009-12-16 11:58:47 UTC (rev 4413)
+++ trunk/varnish-cache/bin/varnishd/cache_dir_random.c	2009-12-16 12:28:47 UTC (rev 4414)
@@ -83,7 +83,8 @@
 		s1 = 0.0;
 		for (i = 0; i < vs->nhosts; i++) {
 			d2 = vs->hosts[i].backend;
-			if (d2->healthy(d2, sp))
+			/* XXX: cache result of healty to avoid double work */
+			if (VBE_Healthy(d2, sp))
 				s1 += vs->hosts[i].weight;
 		}
 
@@ -98,12 +99,12 @@
 		s1 = 0.0;
 		for (i = 0; i < vs->nhosts; i++)  {
 			d2 = vs->hosts[i].backend;
-			if (!d2->healthy(d2, sp))
+			if (!VBE_Healthy(d2, sp))
 				continue;
 			s1 += vs->hosts[i].weight;
 			if (r >= s1)
 				continue;
-			vbe = d2->getfd(d2, sp);
+			vbe = VBE_GetFd(d2, sp);
 			if (vbe != NULL)
 				return (vbe);
 			break;
@@ -126,7 +127,7 @@
 
 	for (i = 0; i < vs->nhosts; i++) {
 		d2 = vs->hosts[i].backend;
-		if (d2->healthy(d2, sp))
+		if (VBE_Healthy(d2, sp))
 			return 1;
 	}
 	return 0;
@@ -136,18 +137,11 @@
 static void
 vdi_random_fini(struct director *d)
 {
-	// int i;
 	struct vdi_random *vs;
-	struct vdi_random_host *vh;
 
 	CHECK_OBJ_NOTNULL(d, DIRECTOR_MAGIC);
 	CAST_OBJ_NOTNULL(vs, d->priv, VDI_RANDOM_MAGIC);
 
-	vh = vs->hosts;
-#if 0 /* XXX */
-	for (i = 0; i < vs->nhosts; i++, vh++)
-		VBE_DropRef(vh->backend);
-#endif
 	free(vs->hosts);
 	free(vs->dir.vcl_name);
 	vs->dir.magic = 0;

Modified: trunk/varnish-cache/bin/varnishd/cache_dir_round_robin.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_dir_round_robin.c	2009-12-16 11:58:47 UTC (rev 4413)
+++ trunk/varnish-cache/bin/varnishd/cache_dir_round_robin.c	2009-12-16 12:28:47 UTC (rev 4414)
@@ -75,9 +75,9 @@
 	for (i = 0; i < vs->nhosts; i++) {
 		backend = vs->hosts[vs->next_host].backend;
 		vs->next_host = (vs->next_host + 1) % vs->nhosts;
-		if (!backend->healthy(backend, sp))
+		if (!VBE_Healthy(backend, sp))
 			continue;
-		vbe = backend->getfd(backend, sp);
+		vbe = VBE_GetFd(backend, sp);
 		if (vbe != NULL)
 			return (vbe);
 	}
@@ -98,7 +98,7 @@
 
 	for (i = 0; i < vs->nhosts; i++) {
 		backend = vs->hosts[i].backend;
-		if (backend->healthy(backend, sp))
+		if (VBE_Healthy(backend, sp))
 			return 1;
 	}
 	return 0;
@@ -108,18 +108,11 @@
 static void
 vdi_round_robin_fini(struct director *d)
 {
-	// int i;
 	struct vdi_round_robin *vs;
-	struct vdi_round_robin_host *vh;
 
 	CHECK_OBJ_NOTNULL(d, DIRECTOR_MAGIC);
 	CAST_OBJ_NOTNULL(vs, d->priv, VDI_ROUND_ROBIN_MAGIC);
 
-	vh = vs->hosts;
-#if 0 /* XXX */
-	for (i = 0; i < vs->nhosts; i++, vh++)
-		VBE_DropRef(vh->backend);
-#endif
 	free(vs->hosts);
 	free(vs->dir.vcl_name);
 	vs->dir.magic = 0;

Modified: trunk/varnish-cache/bin/varnishd/cache_fetch.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_fetch.c	2009-12-16 11:58:47 UTC (rev 4413)
+++ trunk/varnish-cache/bin/varnishd/cache_fetch.c	2009-12-16 12:28:47 UTC (rev 4414)
@@ -351,7 +351,7 @@
 	w = sp->wrk;
 	hp = sp->wrk->bereq;
 
-	VBE_GetFd(sp);
+	sp->vbe = VBE_GetFd(NULL, sp);
 	if (sp->vbe == NULL) {
 		WSP(sp, SLT_FetchError, "no backend connection");
 		return (__LINE__);

Modified: trunk/varnish-cache/bin/varnishd/cache_hash.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_hash.c	2009-12-16 11:58:47 UTC (rev 4413)
+++ trunk/varnish-cache/bin/varnishd/cache_hash.c	2009-12-16 12:28:47 UTC (rev 4414)
@@ -408,7 +408,7 @@
 	 */
 	sp->objhead = oh;
 	if (oc == NULL && grace_oc != NULL &&
-	    (busy_oc != NULL || !sp->director->healthy(sp->director, sp))) {
+	    (busy_oc != NULL || !VBE_Healthy(NULL, sp))) {
 		o = grace_oc->obj;
 		CHECK_OBJ_NOTNULL(o, OBJECT_MAGIC);
 		if (o->ttl + HSH_Grace(sp->grace) >= sp->t_req)

Modified: trunk/varnish-cache/bin/varnishd/cache_pipe.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_pipe.c	2009-12-16 11:58:47 UTC (rev 4413)
+++ trunk/varnish-cache/bin/varnishd/cache_pipe.c	2009-12-16 12:28:47 UTC (rev 4414)
@@ -75,7 +75,7 @@
 	CHECK_OBJ_NOTNULL(sp->wrk, WORKER_MAGIC);
 	w = sp->wrk;
 
-	VBE_GetFd(sp);
+	sp->vbe = VBE_GetFd(NULL, sp);
 	if (sp->vbe == NULL)
 		return;
 	vc = sp->vbe;

Modified: trunk/varnish-cache/bin/varnishd/cache_vrt.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_vrt.c	2009-12-16 11:58:47 UTC (rev 4413)
+++ trunk/varnish-cache/bin/varnishd/cache_vrt.c	2009-12-16 12:28:47 UTC (rev 4414)
@@ -782,7 +782,7 @@
 {
 	CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
 	CHECK_OBJ_NOTNULL(sp->director, DIRECTOR_MAGIC);
-	return (sp->director->healthy(sp->director, sp));
+	return (VBE_Healthy(NULL, sp));
 }
 
 /*--------------------------------------------------------------------*/



More information about the varnish-commit mailing list