From: phk Date: Thu, 21 Aug 2008 09:04:24 +0000 (+0000) Subject: Give the directors another method which returns not the backend to X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=cf35c879a0fdaef7c6a83188111379a136ef6de8;p=varnish 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. git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@3120 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- diff --git a/varnish-cache/bin/varnishd/cache.h b/varnish-cache/bin/varnishd/cache.h index e7385e9b..6dbc24a8 100644 --- a/varnish-cache/bin/varnishd/cache.h +++ b/varnish-cache/bin/varnishd/cache.h @@ -408,7 +408,6 @@ void VBE_Poll(void); /* 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 */ diff --git a/varnish-cache/bin/varnishd/cache_backend.c b/varnish-cache/bin/varnishd/cache_backend.c index 23532ea4..4ab195c7 100644 --- a/varnish-cache/bin/varnishd/cache_backend.c +++ b/varnish-cache/bin/varnishd/cache_backend.c @@ -264,17 +264,37 @@ bes_conn_try(const struct sess *sp, struct backend *bp) return (s); } -/*--------------------------------------------------------------------*/ +/*-------------------------------------------------------------------- + * Get a connection to whatever backend the director think this session + * should contact. + */ struct vbe_conn * VBE_GetFd(struct sess *sp) { - struct backend *bp; - struct vbe_conn *vc; CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); - VBE_SelectBackend(sp); + 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; + bp = sp->backend; CHECK_OBJ_NOTNULL(bp, BACKEND_MAGIC); diff --git a/varnish-cache/bin/varnishd/cache_backend.h b/varnish-cache/bin/varnishd/cache_backend.h index 21641cfa..314f3a4f 100644 --- a/varnish-cache/bin/varnishd/cache_backend.h +++ b/varnish-cache/bin/varnishd/cache_backend.h @@ -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 @@ struct director { #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 @@ struct backend { /* 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; diff --git a/varnish-cache/bin/varnishd/cache_backend_cfg.c b/varnish-cache/bin/varnishd/cache_backend_cfg.c index ec787ae1..27aba581 100644 --- a/varnish-cache/bin/varnishd/cache_backend_cfg.c +++ b/varnish-cache/bin/varnishd/cache_backend_cfg.c @@ -56,19 +56,6 @@ MTX VBE_mtx; */ 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; -} /*-------------------------------------------------------------------- */