Commit ed40aa55 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

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: http://www.varnish-cache.org/svn/trunk@3120 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent 02fe13d4
......@@ -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 */
......
......@@ -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);
......
......@@ -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;
......
......@@ -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;
}
/*--------------------------------------------------------------------
*/
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment