Commit 691c4937 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Polish pass: Add wrapped methods for ->getfd and ->healthy.

Remove the backend deref code that is no longer needed by random/round-robin
directors, since they only reference other directors in the same VCL.

Stop messing with sp->vbe behind the back, make the assignment explicit
where it matters.



git-svn-id: http://www.varnish-cache.org/svn/trunk@4414 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent 8ce92cec
......@@ -451,7 +451,8 @@ extern pthread_t VCA_thread;
/* cache_backend.c */
void VBE_GetFd(struct sess *sp);
struct vbe_conn *VBE_GetFd(struct director *, struct sess *sp);
int VBE_Healthy(struct director *, const struct sess *sp);
void VBE_ClosedFd(struct sess *sp);
void VBE_RecycleFd(struct sess *sp);
void VBE_AddHostHeader(const struct sess *sp);
......
......@@ -353,21 +353,6 @@ vbe_GetVbe(struct sess *sp, struct backend *bp)
return (vc);
}
/*--------------------------------------------------------------------
* Get a connection to whatever backend the director think this session
* should contact.
*/
void
VBE_GetFd(struct sess *sp)
{
CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
CHECK_OBJ_NOTNULL(sp->director, DIRECTOR_MAGIC);
AN (sp->director->getfd);
sp->vbe = sp->director->getfd(sp->director, sp);
}
/* Close a connection ------------------------------------------------*/
void
......@@ -410,6 +395,31 @@ VBE_RecycleFd(struct sess *sp)
VBE_DropRefLocked(bp);
}
/* Get a connection --------------------------------------------------*/
struct vbe_conn *
VBE_GetFd(struct director *d, struct sess *sp)
{
CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
if (d == NULL)
d = sp->director;
CHECK_OBJ_NOTNULL(d, DIRECTOR_MAGIC);
return (d->getfd(d, sp));
}
/* Cheack health -----------------------------------------------------*/
int
VBE_Healthy(struct director *d, const struct sess *sp)
{
CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
if (d == NULL)
d = sp->director;
CHECK_OBJ_NOTNULL(d, DIRECTOR_MAGIC);
return (d->healthy(d, sp));
}
/*--------------------------------------------------------------------
* The "simple" director really isn't, since thats where all the actual
......
......@@ -92,24 +92,6 @@ struct director {
void *priv;
};
static inline struct vbe_conn *
dir_getfd(struct director *d, struct sess *sp)
{
CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
CHECK_OBJ_NOTNULL(d, DIRECTOR_MAGIC);
return (d->getfd(d, sp));
}
static inline int
dir_healthy(struct director *d, const struct sess *sp)
{
CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
CHECK_OBJ_NOTNULL(d, DIRECTOR_MAGIC);
return (d->healthy(d, sp));
}
/*--------------------------------------------------------------------
* List of objectheads that have recently been rejected by VCL.
*/
......
......@@ -83,7 +83,8 @@ vdi_random_getfd(struct director *d, struct sess *sp)
s1 = 0.0;
for (i = 0; i < vs->nhosts; i++) {
d2 = vs->hosts[i].backend;
if (d2->healthy(d2, sp))
/* XXX: cache result of healty to avoid double work */
if (VBE_Healthy(d2, sp))
s1 += vs->hosts[i].weight;
}
......@@ -98,12 +99,12 @@ vdi_random_getfd(struct director *d, struct sess *sp)
s1 = 0.0;
for (i = 0; i < vs->nhosts; i++) {
d2 = vs->hosts[i].backend;
if (!d2->healthy(d2, sp))
if (!VBE_Healthy(d2, sp))
continue;
s1 += vs->hosts[i].weight;
if (r >= s1)
continue;
vbe = d2->getfd(d2, sp);
vbe = VBE_GetFd(d2, sp);
if (vbe != NULL)
return (vbe);
break;
......@@ -126,7 +127,7 @@ vdi_random_healthy(struct director *d, const struct sess *sp)
for (i = 0; i < vs->nhosts; i++) {
d2 = vs->hosts[i].backend;
if (d2->healthy(d2, sp))
if (VBE_Healthy(d2, sp))
return 1;
}
return 0;
......@@ -136,18 +137,11 @@ vdi_random_healthy(struct director *d, const struct sess *sp)
static void
vdi_random_fini(struct director *d)
{
// int i;
struct vdi_random *vs;
struct vdi_random_host *vh;
CHECK_OBJ_NOTNULL(d, DIRECTOR_MAGIC);
CAST_OBJ_NOTNULL(vs, d->priv, VDI_RANDOM_MAGIC);
vh = vs->hosts;
#if 0 /* XXX */
for (i = 0; i < vs->nhosts; i++, vh++)
VBE_DropRef(vh->backend);
#endif
free(vs->hosts);
free(vs->dir.vcl_name);
vs->dir.magic = 0;
......
......@@ -75,9 +75,9 @@ vdi_round_robin_getfd(struct director *d, struct sess *sp)
for (i = 0; i < vs->nhosts; i++) {
backend = vs->hosts[vs->next_host].backend;
vs->next_host = (vs->next_host + 1) % vs->nhosts;
if (!backend->healthy(backend, sp))
if (!VBE_Healthy(backend, sp))
continue;
vbe = backend->getfd(backend, sp);
vbe = VBE_GetFd(backend, sp);
if (vbe != NULL)
return (vbe);
}
......@@ -98,7 +98,7 @@ vdi_round_robin_healthy(struct director *d, const struct sess *sp)
for (i = 0; i < vs->nhosts; i++) {
backend = vs->hosts[i].backend;
if (backend->healthy(backend, sp))
if (VBE_Healthy(backend, sp))
return 1;
}
return 0;
......@@ -108,18 +108,11 @@ vdi_round_robin_healthy(struct director *d, const struct sess *sp)
static void
vdi_round_robin_fini(struct director *d)
{
// int i;
struct vdi_round_robin *vs;
struct vdi_round_robin_host *vh;
CHECK_OBJ_NOTNULL(d, DIRECTOR_MAGIC);
CAST_OBJ_NOTNULL(vs, d->priv, VDI_ROUND_ROBIN_MAGIC);
vh = vs->hosts;
#if 0 /* XXX */
for (i = 0; i < vs->nhosts; i++, vh++)
VBE_DropRef(vh->backend);
#endif
free(vs->hosts);
free(vs->dir.vcl_name);
vs->dir.magic = 0;
......
......@@ -351,7 +351,7 @@ FetchHdr(struct sess *sp)
w = sp->wrk;
hp = sp->wrk->bereq;
VBE_GetFd(sp);
sp->vbe = VBE_GetFd(NULL, sp);
if (sp->vbe == NULL) {
WSP(sp, SLT_FetchError, "no backend connection");
return (__LINE__);
......
......@@ -408,7 +408,7 @@ HSH_Lookup(struct sess *sp, struct objhead **poh)
*/
sp->objhead = oh;
if (oc == NULL && grace_oc != NULL &&
(busy_oc != NULL || !sp->director->healthy(sp->director, sp))) {
(busy_oc != NULL || !VBE_Healthy(NULL, sp))) {
o = grace_oc->obj;
CHECK_OBJ_NOTNULL(o, OBJECT_MAGIC);
if (o->ttl + HSH_Grace(sp->grace) >= sp->t_req)
......
......@@ -75,7 +75,7 @@ PipeSession(struct sess *sp)
CHECK_OBJ_NOTNULL(sp->wrk, WORKER_MAGIC);
w = sp->wrk;
VBE_GetFd(sp);
sp->vbe = VBE_GetFd(NULL, sp);
if (sp->vbe == NULL)
return;
vc = sp->vbe;
......
......@@ -782,7 +782,7 @@ VRT_r_req_backend_healthy(const struct sess *sp)
{
CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
CHECK_OBJ_NOTNULL(sp->director, DIRECTOR_MAGIC);
return (sp->director->healthy(sp->director, sp));
return (VBE_Healthy(NULL, sp));
}
/*--------------------------------------------------------------------*/
......
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