Commit 016531bb authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Shuffling the backend code around a bit in preparation for multi-protocol

backends.
parent 97014d35
......@@ -695,6 +695,7 @@ void VBE_UseHealth(const struct director *vdi);
void VBE_DiscardHealth(const struct director *vdi);
int VDI_GetHdr(struct worker *wrk, struct busyobj *bo);
struct vbc *VDI_GetFd(struct busyobj *);
int VDI_Healthy(const struct director *);
void VDI_CloseFd(struct vbc **vbp, const struct acct_bereq *);
......
......@@ -42,6 +42,7 @@
#include "cache_backend.h"
#include "vrt.h"
#include "vtcp.h"
#include "vtim.h"
static struct mempool *vbcpool;
......@@ -355,6 +356,35 @@ VBE_DiscardHealth(const struct director *vdi)
VBP_Remove(vs->backend, vs->vrt->probe);
}
/*--------------------------------------------------------------------
*/
int
VDI_GetHdr(struct worker *wrk, struct busyobj *bo)
{
int i;
CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
CHECK_OBJ_NOTNULL(bo, BUSYOBJ_MAGIC);
if (bo->director == NULL) {
VSLb(bo->vsl, SLT_FetchError, "No backend");
return (-1);
}
i = V1F_fetch_hdr(wrk, bo);
/*
* If we recycle a backend connection, there is a finite chance
* that the backend closed it before we get a request to it.
* Do a single retry in that case.
*/
if (i == 1) {
VSC_C_main->backend_retry++;
i = VDI_GetHdr(wrk, bo);
}
return (i);
}
/*--------------------------------------------------------------------
*
*/
......@@ -378,7 +408,7 @@ vdi_simple_getfd(const struct director *d, struct busyobj *bo)
return (vc);
}
static unsigned
static unsigned __match_proto__(vdi_healthy_f)
vdi_simple_healthy(const struct director *d, double *changed)
{
struct vdi_simple *vs;
......@@ -391,6 +421,17 @@ vdi_simple_healthy(const struct director *d, double *changed)
return (VBE_Healthy(be, changed));
}
static int __match_proto__(vdi_gethdrs_f)
vdi_simple_gethdrs(const struct director *d, struct worker *wrk,
struct busyobj *bo)
{
CHECK_OBJ_NOTNULL(d, DIRECTOR_MAGIC);
CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
CHECK_OBJ_NOTNULL(bo, BUSYOBJ_MAGIC);
return (-1);
}
/*--------------------------------------------------------------------*/
void
......@@ -428,6 +469,7 @@ VRT_init_dir(struct cli *cli, struct director **bp, int idx, const void *priv)
REPLACE(vs->dir.vcl_name, t->vcl_name);
vs->dir.getfd = vdi_simple_getfd;
vs->dir.healthy = vdi_simple_healthy;
vs->dir.gethdrs = vdi_simple_gethdrs;
vs->vrt = t;
......
......@@ -76,7 +76,9 @@ struct vrt_backend_probe;
*/
typedef struct vbc *vdi_getfd_f(const struct director *, struct busyobj *);
typedef unsigned vdi_healthy(const struct director *, double *changed);
typedef unsigned vdi_healthy_f(const struct director *, double *changed);
typedef int vdi_gethdrs_f(const struct director *, struct worker *,
struct busyobj *);
struct director {
unsigned magic;
......@@ -84,7 +86,8 @@ struct director {
const char *name;
char *vcl_name;
vdi_getfd_f *getfd;
vdi_healthy *healthy;
vdi_healthy_f *healthy;
vdi_gethdrs_f *gethdrs;
void *priv;
};
......
......@@ -265,17 +265,8 @@ vbf_stp_startfetch(struct worker *wrk, struct busyobj *bo)
assert(bo->state <= BOS_REQ_DONE);
i = V1F_fetch_hdr(wrk, bo);
/*
* If we recycle a backend connection, there is a finite chance
* that the backend closed it before we get a request to it.
* Do a single retry in that case.
*/
if (i == 1) {
VSLb_ts_busyobj(bo, "Beresp", W_TIM_real(wrk));
VSC_C_main->backend_retry++;
i = V1F_fetch_hdr(wrk, bo);
}
i = VDI_GetHdr(wrk, bo);
now = W_TIM_real(wrk);
VSLb_ts_busyobj(bo, "Beresp", now);
......
......@@ -86,15 +86,10 @@ V1F_fetch_hdr(struct worker *wrk, struct busyobj *bo)
CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
CHECK_OBJ_NOTNULL(bo, BUSYOBJ_MAGIC);
CHECK_OBJ_NOTNULL(bo->director, DIRECTOR_MAGIC);
CHECK_OBJ_ORNULL(bo->req, REQ_MAGIC);
htc = bo->htc;
if (bo->director == NULL) {
VSLb(bo->vsl, SLT_FetchError, "No backend");
return (-1);
}
AN(bo->director);
hp = bo->bereq;
bo->vbc = VDI_GetFd(bo);
......
......@@ -51,7 +51,7 @@ vdir_expand(struct vdir *vd, unsigned n)
}
void
vdir_new(struct vdir **vdp, const char *vcl_name, vdi_healthy *healthy,
vdir_new(struct vdir **vdp, const char *vcl_name, vdi_healthy_f *healthy,
vdi_getfd_f *getfd, void *priv)
{
struct vdir *vd;
......
......@@ -41,7 +41,7 @@ struct vdir {
struct vbitmap *vbm;
};
void vdir_new(struct vdir **vdp, const char *vcl_name, vdi_healthy *healthy,
void vdir_new(struct vdir **vdp, const char *vcl_name, vdi_healthy_f *healthy,
vdi_getfd_f *getfd, void *priv);
void vdir_delete(struct vdir **vdp);
void vdir_lock(struct vdir *vd);
......
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