r3164 - in trunk/varnish-cache: bin/varnishd include lib/libvcl

tfheen at projects.linpro.no tfheen at projects.linpro.no
Sun Sep 7 09:47:39 CEST 2008


Author: tfheen
Date: 2008-09-07 09:47:39 +0200 (Sun, 07 Sep 2008)
New Revision: 3164

Modified:
   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_dir_simple.c
   trunk/varnish-cache/bin/varnishd/cache_vrt.c
   trunk/varnish-cache/include/vrt_obj.h
   trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c
   trunk/varnish-cache/lib/libvcl/vcc_gen_obj.tcl
   trunk/varnish-cache/lib/libvcl/vcc_obj.c
Log:
Make backend.healthy available to VCL (Fixes: #312)

It'll typically be used in a manner similar to:

    if (! backend.healthy) {
        error 500 "Backend sick!";
    }


Modified: trunk/varnish-cache/bin/varnishd/cache_backend.h
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_backend.h	2008-09-07 07:47:26 UTC (rev 3163)
+++ trunk/varnish-cache/bin/varnishd/cache_backend.h	2008-09-07 07:47:39 UTC (rev 3164)
@@ -79,6 +79,7 @@
 
 typedef struct vbe_conn *vdi_getfd_f(struct sess *sp);
 typedef void vdi_fini_f(struct director *d);
+typedef unsigned vdi_healthy(const struct sess *sp);
 
 struct director {
 	unsigned		magic;
@@ -86,6 +87,7 @@
 	const char		*name;
 	vdi_getfd_f		*getfd;
 	vdi_fini_f		*fini;
+	vdi_healthy		*healthy;
 	void			*priv;
 };
 

Modified: trunk/varnish-cache/bin/varnishd/cache_dir_random.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_dir_random.c	2008-09-07 07:47:26 UTC (rev 3163)
+++ trunk/varnish-cache/bin/varnishd/cache_dir_random.c	2008-09-07 07:47:39 UTC (rev 3164)
@@ -120,6 +120,23 @@
 	return (NULL);
 }
 
+static unsigned *
+vdi_random_healthy(const struct sess *sp)
+{
+	struct vdi_random *vs;
+	int i;
+
+	CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
+	CHECK_OBJ_NOTNULL(sp->director, DIRECTOR_MAGIC);
+	CAST_OBJ_NOTNULL(vs, sp->director->priv, VDI_RANDOM_MAGIC);
+
+	for (i = 0; i < vs->nhosts; i++) {
+		if (vs->hosts[i].backend->healthy)
+			return 1;
+	}
+	return 0;
+}
+
 /*lint -e{818} not const-able */
 static void
 vdi_random_fini(struct director *d)
@@ -159,6 +176,7 @@
 	vs->dir.name = "random";
 	vs->dir.getfd = vdi_random_getfd;
 	vs->dir.fini = vdi_random_fini;
+	vs->dir.healthy = vdi_random_healthy;
 
 	vs->retries = t->retries;
 	if (vs->retries == 0)

Modified: trunk/varnish-cache/bin/varnishd/cache_dir_round_robin.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_dir_round_robin.c	2008-09-07 07:47:26 UTC (rev 3163)
+++ trunk/varnish-cache/bin/varnishd/cache_dir_round_robin.c	2008-09-07 07:47:39 UTC (rev 3164)
@@ -84,6 +84,23 @@
 	return (NULL);
 }
 
+static unsigned *
+vdi_round_robin_healthy(const struct sess *sp)
+{
+	struct vdi_round_robin *vs;
+	int i;
+
+	CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
+	CHECK_OBJ_NOTNULL(sp->director, DIRECTOR_MAGIC);
+	CAST_OBJ_NOTNULL(vs, sp->director->priv, VDI_ROUND_ROBIN_MAGIC);
+
+	for (i = 0; i < vs->nhosts; i++) {
+		if (vs->hosts[i].backend->healthy)
+			return 1;
+	}
+	return 0;
+}
+
 /*lint -e{818} not const-able */
 static void
 vdi_round_robin_fini(struct director *d)
@@ -124,6 +141,7 @@
 	vs->dir.name = "round_robin";
 	vs->dir.getfd = vdi_round_robin_getfd;
 	vs->dir.fini = vdi_round_robin_fini;
+	vs->dir.healthy = vdi_round_robin_healthy;
 
 	vh = vs->hosts;
 	te = t->members;

Modified: trunk/varnish-cache/bin/varnishd/cache_dir_simple.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_dir_simple.c	2008-09-07 07:47:26 UTC (rev 3163)
+++ trunk/varnish-cache/bin/varnishd/cache_dir_simple.c	2008-09-07 07:47:39 UTC (rev 3164)
@@ -66,6 +66,17 @@
 	return (VBE_GetVbe(sp, vs->backend));
 }
 
+static unsigned *
+vdi_simple_healthy(const struct sess *sp)
+{
+	struct vdi_simple *vs;
+
+	CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
+	CHECK_OBJ_NOTNULL(sp->director, DIRECTOR_MAGIC);
+	CAST_OBJ_NOTNULL(vs, sp->director->priv, VDI_SIMPLE_MAGIC);
+	return vs->backend->healthy;
+}
+
 /*lint -e{818} not const-able */
 static void
 vdi_simple_fini(struct director *d)
@@ -94,6 +105,7 @@
 	vs->dir.name = "simple";
 	vs->dir.getfd = vdi_simple_getfd;
 	vs->dir.fini = vdi_simple_fini;
+	vs->dir.healthy = vdi_simple_healthy;
 
 	vs->backend = VBE_AddBackend(cli, t->host);
 

Modified: trunk/varnish-cache/bin/varnishd/cache_vrt.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_vrt.c	2008-09-07 07:47:26 UTC (rev 3163)
+++ trunk/varnish-cache/bin/varnishd/cache_vrt.c	2008-09-07 07:47:39 UTC (rev 3164)
@@ -50,8 +50,8 @@
 #include "vrt_obj.h"
 #include "vcl.h"
 #include "cache.h"
+#include "cache_backend.h"
 
-
 void *vrt_magic_string_end = &vrt_magic_string_end;
 
 /*--------------------------------------------------------------------*/
@@ -575,17 +575,12 @@
 	return (sp->obj->objhead->hash);
 }
 
-int
-VRT_r_backend_health(const struct sess *sp)
+unsigned
+VRT_r_backend_healthy(const struct sess *sp)
 {
 	CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
-#if 0	
-	CHECK_OBJ_NOTNULL(sp->backend, BACKEND_MAGIC);
-	return (sp->backend->health);
-#else
-	INCOMPL();
-	return (0);
-#endif
+	CHECK_OBJ_NOTNULL(sp->director, DIRECTOR_MAGIC);
+	return (sp->director->healthy(sp));
 }
 
 /*--------------------------------------------------------------------*/

Modified: trunk/varnish-cache/include/vrt_obj.h
===================================================================
--- trunk/varnish-cache/include/vrt_obj.h	2008-09-07 07:47:26 UTC (rev 3163)
+++ trunk/varnish-cache/include/vrt_obj.h	2008-09-07 07:47:39 UTC (rev 3164)
@@ -51,4 +51,4 @@
 const char * VRT_r_resp_response(const struct sess *);
 void VRT_l_resp_response(const struct sess *, const char *, ...);
 double VRT_r_now(const struct sess *);
-int VRT_r_backend_health(const struct sess *);
+unsigned VRT_r_backend_healthy(const struct sess *);

Modified: trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c
===================================================================
--- trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c	2008-09-07 07:47:26 UTC (rev 3163)
+++ trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c	2008-09-07 07:47:39 UTC (rev 3164)
@@ -509,5 +509,5 @@
 	vsb_cat(sb, "const char * VRT_r_resp_response(const struct sess *);\n");
 	vsb_cat(sb, "void VRT_l_resp_response(const struct sess *, const char *, ...);\n");
 	vsb_cat(sb, "double VRT_r_now(const struct sess *);\n");
-	vsb_cat(sb, "int VRT_r_backend_health(const struct sess *);\n");
+	vsb_cat(sb, "unsigned VRT_r_backend_healthy(const struct sess *);\n");
 }

Modified: trunk/varnish-cache/lib/libvcl/vcc_gen_obj.tcl
===================================================================
--- trunk/varnish-cache/lib/libvcl/vcc_gen_obj.tcl	2008-09-07 07:47:26 UTC (rev 3163)
+++ trunk/varnish-cache/lib/libvcl/vcc_gen_obj.tcl	2008-09-07 07:47:39 UTC (rev 3164)
@@ -211,7 +211,7 @@
 	    {recv pipe pass hash miss hit fetch deliver discard timeout}
 	    "const struct sess *"
     }
-    { backend.health	RO INT
+    { backend.healthy	RO BOOL
 	    {recv pipe pass hash miss hit fetch deliver discard timeout}
 	    "const struct sess *"
     }

Modified: trunk/varnish-cache/lib/libvcl/vcc_obj.c
===================================================================
--- trunk/varnish-cache/lib/libvcl/vcc_obj.c	2008-09-07 07:47:26 UTC (rev 3163)
+++ trunk/varnish-cache/lib/libvcl/vcc_obj.c	2008-09-07 07:47:39 UTC (rev 3164)
@@ -8,7 +8,6 @@
 
 #include "config.h"
 #include <stdio.h>
-#include "config.h"
 #include "vcc_compile.h"
 
 struct var vcc_vars[] = {
@@ -229,8 +228,8 @@
 	    0,
 	    VCL_MET_RECV | VCL_MET_PIPE | VCL_MET_PASS | VCL_MET_HASH | VCL_MET_MISS | VCL_MET_HIT | VCL_MET_FETCH | VCL_MET_DELIVER | VCL_MET_DISCARD | VCL_MET_TIMEOUT
 	},
-	{ "backend.health", INT, 14,
-	    "VRT_r_backend_health(sp)",
+	{ "backend.healthy", BOOL, 15,
+	    "VRT_r_backend_healthy(sp)",
 	    NULL,
 	    V_RO,
 	    0,




More information about the varnish-commit mailing list