r3120 - trunk/varnish-cache/bin/varnishd

phk at projects.linpro.no phk at projects.linpro.no
Thu Aug 21 11:04:24 CEST 2008


Author: phk
Date: 2008-08-21 11:04:24 +0200 (Thu, 21 Aug 2008)
New Revision: 3120

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_backend_cfg.c
Log:
Give the directors another method which returns not the backend to
connect to, but a connection to a backend, this makes it possible
for the directors to choose another backend, if connection to the
first backend fails.



Modified: trunk/varnish-cache/bin/varnishd/cache.h
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache.h	2008-08-21 08:48:29 UTC (rev 3119)
+++ trunk/varnish-cache/bin/varnishd/cache.h	2008-08-21 09:04:24 UTC (rev 3120)
@@ -408,7 +408,6 @@
 /* cache_backend_cfg.c */
 void VBE_Init(void);
 void VBE_DropRef(struct backend *);
-void VBE_SelectBackend(struct sess *sp);
 struct backend *VBE_AddBackend(struct cli *cli, const struct vrt_backend *vb);
 
 /* cache_backend_poll.c */

Modified: trunk/varnish-cache/bin/varnishd/cache_backend.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_backend.c	2008-08-21 08:48:29 UTC (rev 3119)
+++ trunk/varnish-cache/bin/varnishd/cache_backend.c	2008-08-21 09:04:24 UTC (rev 3120)
@@ -264,17 +264,37 @@
 	return (s);
 }
 
-/*--------------------------------------------------------------------*/
+/*--------------------------------------------------------------------
+ * Get a connection to whatever backend the director think this session
+ * should contact.
+ */
 
 struct vbe_conn *
 VBE_GetFd(struct sess *sp)
 {
+
+	CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
+
+	CHECK_OBJ_NOTNULL(sp->director, DIRECTOR_MAGIC);
+
+	if (sp->director->getfd != NULL)
+		return (sp->director->getfd(sp));
+
+	sp->backend = sp->director->choose(sp);
+	CHECK_OBJ_NOTNULL(sp->backend, BACKEND_MAGIC);
+	return (VBE_GetVbe(sp));
+}
+
+/*--------------------------------------------------------------------
+ * Get a connection to a particular backend.
+ */
+
+struct vbe_conn *
+VBE_GetVbe(const struct sess *sp)
+{
 	struct backend *bp;
 	struct vbe_conn *vc;
 
-	CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
-
-	VBE_SelectBackend(sp);
 	bp = sp->backend;
 	CHECK_OBJ_NOTNULL(bp, BACKEND_MAGIC);
 

Modified: trunk/varnish-cache/bin/varnishd/cache_backend.h
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_backend.h	2008-08-21 08:48:29 UTC (rev 3119)
+++ trunk/varnish-cache/bin/varnishd/cache_backend.h	2008-08-21 09:04:24 UTC (rev 3120)
@@ -69,13 +69,15 @@
  */
 
 struct vbp_target;
+struct vbe_conn;
 struct vrt_backend_probe;
 
-/* -------------------------------------------------------------------
+/*--------------------------------------------------------------------
  * A director is a piece of code which selects one of possibly multiple
  * backends to use.
  */
 
+typedef struct vbe_conn *vdi_getfd_f(struct sess *sp);
 typedef struct backend *vdi_choose_f(struct sess *sp);
 typedef void vdi_fini_f(struct director *d);
 
@@ -84,11 +86,15 @@
 #define DIRECTOR_MAGIC		0x3336351d
 	const char		*name;
 	vdi_choose_f		*choose;
+	vdi_getfd_f		*getfd;
 	vdi_fini_f		*fini;
 	void			*priv;
 };
 
-/* Backend indstance */
+/*--------------------------------------------------------------------
+ * An instance of a backend from a VCL program.
+ */
+
 struct backend {
 	unsigned		magic;
 #define BACKEND_MAGIC		0x64c4c7c6
@@ -117,6 +123,7 @@
 
 /* cache_backend.c */
 void VBE_ReleaseConn(struct vbe_conn *vc);
+struct vbe_conn *VBE_GetVbe(const struct sess *sp);
 
 /* cache_backend_cfg.c */
 extern MTX VBE_mtx;

Modified: trunk/varnish-cache/bin/varnishd/cache_backend_cfg.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_backend_cfg.c	2008-08-21 08:48:29 UTC (rev 3119)
+++ trunk/varnish-cache/bin/varnishd/cache_backend_cfg.c	2008-08-21 09:04:24 UTC (rev 3120)
@@ -56,20 +56,7 @@
  */
 static VTAILQ_HEAD(, backend) backends = VTAILQ_HEAD_INITIALIZER(backends);
 
-/*--------------------------------------------------------------------*/
 
-void
-VBE_SelectBackend(struct sess *sp)
-{
-	struct backend *bp;
-
-	CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
-	CHECK_OBJ_NOTNULL(sp->director, DIRECTOR_MAGIC);
-	bp = sp->director->choose(sp);
-	CHECK_OBJ_NOTNULL(bp, BACKEND_MAGIC);
-	sp->backend = bp;
-}
-
 /*--------------------------------------------------------------------
  */
 




More information about the varnish-commit mailing list