Commit 401d1dd9 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Make everybody use VRT_Healthy() and simplify backends as result.

parent c25ed7e1
...@@ -88,7 +88,7 @@ vbe_dir_getfd(struct worker *wrk, struct backend *bp, struct busyobj *bo, ...@@ -88,7 +88,7 @@ vbe_dir_getfd(struct worker *wrk, struct backend *bp, struct busyobj *bo,
CHECK_OBJ_NOTNULL(bp, BACKEND_MAGIC); CHECK_OBJ_NOTNULL(bp, BACKEND_MAGIC);
AN(bp->vsc); AN(bp->vsc);
if (!VDI_Healthy(bp->director, NULL)) { if (!bp->director->health) {
VSLb(bo->vsl, SLT_FetchError, VSLb(bo->vsl, SLT_FetchError,
"backend %s: unhealthy", bp->director->cli_name); "backend %s: unhealthy", bp->director->cli_name);
// XXX: per backend stats ? // XXX: per backend stats ?
...@@ -153,17 +153,6 @@ vbe_dir_getfd(struct worker *wrk, struct backend *bp, struct busyobj *bo, ...@@ -153,17 +153,6 @@ vbe_dir_getfd(struct worker *wrk, struct backend *bp, struct busyobj *bo,
return (pfd); return (pfd);
} }
static VCL_BOOL v_matchproto_(vdi_healthy_f)
vbe_dir_healthy(VRT_CTX, VCL_BACKEND d, VCL_TIME *changed)
{
struct backend *be;
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
CHECK_OBJ_NOTNULL(d, DIRECTOR_MAGIC);
CAST_OBJ_NOTNULL(be, d->priv, BACKEND_MAGIC);
return (VDI_Healthy(be->director, changed));
}
static void v_matchproto_(vdi_finish_f) static void v_matchproto_(vdi_finish_f)
vbe_dir_finish(const struct director *d, struct worker *wrk, vbe_dir_finish(const struct director *d, struct worker *wrk,
struct busyobj *bo) struct busyobj *bo)
...@@ -439,7 +428,6 @@ static const struct director_methods vbe_methods[1] = {{ ...@@ -439,7 +428,6 @@ static const struct director_methods vbe_methods[1] = {{
.magic = DIRECTOR_METHODS_MAGIC, .magic = DIRECTOR_METHODS_MAGIC,
.type = "backend", .type = "backend",
.http1pipe = vbe_dir_http1pipe, .http1pipe = vbe_dir_http1pipe,
.healthy = vbe_dir_healthy,
.gethdrs = vbe_dir_gethdrs, .gethdrs = vbe_dir_gethdrs,
.getip = vbe_dir_getip, .getip = vbe_dir_getip,
.finish = vbe_dir_finish, .finish = vbe_dir_finish,
......
...@@ -219,19 +219,32 @@ VDI_Http1Pipe(struct req *req, struct busyobj *bo) ...@@ -219,19 +219,32 @@ VDI_Http1Pipe(struct req *req, struct busyobj *bo)
* If director has no healthy method, we just assume it is healthy. * If director has no healthy method, we just assume it is healthy.
*/ */
int /*--------------------------------------------------------------------
VRT_Healthy(VRT_CTX, VCL_BACKEND d) * Test if backend is healthy and report when that last changed
*/
VCL_BOOL
VRT_Healthy(VRT_CTX, VCL_BACKEND d, VCL_TIME *changed)
{ {
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC); CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
if (d == NULL) if (d == NULL)
return (0); return (0);
CHECK_OBJ_NOTNULL(d, DIRECTOR_MAGIC); CHECK_OBJ_NOTNULL(d, DIRECTOR_MAGIC);
if (!VDI_Healthy(d, NULL))
return (0); if (d->admin_health->health >= 0) {
if (d->methods->healthy == NULL) if (changed != NULL)
return (1); *changed = d->health_changed;
return (d->methods->healthy(ctx, d, NULL)); return (d->admin_health->health);
}
if (d->methods->healthy == NULL) {
if (changed != NULL)
*changed = d->health_changed;
return (d->health);
}
return (d->methods->healthy(ctx, d, changed));
} }
/* Send Event ---------------------------------------------------------- /* Send Event ----------------------------------------------------------
...@@ -270,24 +283,6 @@ VDI_Panic(const struct director *d, struct vsb *vsb, const char *nm) ...@@ -270,24 +283,6 @@ VDI_Panic(const struct director *d, struct vsb *vsb, const char *nm)
VSB_printf(vsb, "},\n"); VSB_printf(vsb, "},\n");
} }
/*--------------------------------------------------------------------
* Test if backend is healthy and report when it last changed
*/
unsigned
VDI_Healthy(const struct director *d, double *changed)
{
CHECK_OBJ_NOTNULL(d, DIRECTOR_MAGIC);
AN(d->admin_health);
if (changed != NULL)
*changed = d->health_changed;
if (d->admin_health->health < 0)
return (d->health);
return (d->admin_health->health);
}
/*---------------------------------------------------------------------*/ /*---------------------------------------------------------------------*/
...@@ -358,43 +353,49 @@ cli_backend_list(struct cli *cli, const char * const *av, void *priv) ...@@ -358,43 +353,49 @@ cli_backend_list(struct cli *cli, const char * const *av, void *priv)
/*---------------------------------------------------------------------*/ /*---------------------------------------------------------------------*/
struct set_health {
unsigned magic;
#define SET_HEALTH_MAGIC 0x0c46b9fb
const struct vdi_ahealth *ah;
};
static int v_matchproto_(vcl_be_func) static int v_matchproto_(vcl_be_func)
do_set_health(struct cli *cli, struct director *d, void *priv) do_set_health(struct cli *cli, struct director *d, void *priv)
{ {
unsigned prev; struct set_health *sh;
(void)cli; (void)cli;
AN(priv);
CHECK_OBJ_NOTNULL(d, DIRECTOR_MAGIC); CHECK_OBJ_NOTNULL(d, DIRECTOR_MAGIC);
CAST_OBJ_NOTNULL(sh, priv, SET_HEALTH_MAGIC);
if (d->admin_health == VDI_AH_DELETED) if (d->admin_health == VDI_AH_DELETED)
return (0); return (0);
prev = VDI_Healthy(d, NULL); if (d->admin_health != sh->ah) {
d->admin_health = *(const struct vdi_ahealth **)priv;
(void)VDI_Ahealth(d); // Acts like type-check
if (prev != VDI_Healthy(d, NULL))
d->health_changed = VTIM_real(); d->health_changed = VTIM_real();
d->admin_health = sh->ah;
d->health = sh->ah->health ? 1 : 0;
}
return (0); return (0);
} }
static void v_matchproto_() static void v_matchproto_()
cli_backend_set_health(struct cli *cli, const char * const *av, void *priv) cli_backend_set_health(struct cli *cli, const char * const *av, void *priv)
{ {
const struct vdi_ahealth *ah;
int n; int n;
struct set_health sh[1];
(void)av; (void)av;
(void)priv; (void)priv;
ASSERT_CLI(); ASSERT_CLI();
AN(av[2]); AN(av[2]);
AN(av[3]); AN(av[3]);
ah = vdi_str2ahealth(av[3]); INIT_OBJ(sh, SET_HEALTH_MAGIC);
if (ah == NULL || ah == VDI_AH_DELETED) { sh->ah = vdi_str2ahealth(av[3]);
if (sh->ah == NULL || sh->ah == VDI_AH_DELETED) {
VCLI_Out(cli, "Invalid state %s", av[3]); VCLI_Out(cli, "Invalid state %s", av[3]);
VCLI_SetResult(cli, CLIS_PARAM); VCLI_SetResult(cli, CLIS_PARAM);
return; return;
} }
n = VCL_IterDirector(cli, av[2], do_set_health, &ah); n = VCL_IterDirector(cli, av[2], do_set_health, sh);
if (n == 0) { if (n == 0) {
VCLI_Out(cli, "No Backends matches"); VCLI_Out(cli, "No Backends matches");
VCLI_SetResult(cli, CLIS_PARAM); VCLI_SetResult(cli, CLIS_PARAM);
......
...@@ -99,7 +99,6 @@ struct director { ...@@ -99,7 +99,6 @@ struct director {
double health_changed; double health_changed;
}; };
unsigned VDI_Healthy(const struct director *, double *);
/* cache_vcl.c */ /* cache_vcl.c */
int VRT_AddDirector(VRT_CTX, struct director *, const char *); int VRT_AddDirector(VRT_CTX, struct director *, const char *);
......
...@@ -23,7 +23,7 @@ varnish v1 -vcl { ...@@ -23,7 +23,7 @@ varnish v1 -vcl {
} -start } -start
delay 1 varnish v1 -vsl_catchup
varnish v1 -cliok "vcl.list" varnish v1 -cliok "vcl.list"
varnish v1 -cliok "backend.list -p" varnish v1 -cliok "backend.list -p"
...@@ -36,6 +36,8 @@ client c1 { ...@@ -36,6 +36,8 @@ client c1 {
expect resp.status == 200 expect resp.status == 200
} -run } -run
varnish v1 -vsl_catchup
varnish v1 -cliok "backend.list" varnish v1 -cliok "backend.list"
varnish v1 -cliok "backend.set_health s1 sick" varnish v1 -cliok "backend.set_health s1 sick"
varnish v1 -cliok "backend.list" varnish v1 -cliok "backend.list"
...@@ -46,6 +48,8 @@ client c1 { ...@@ -46,6 +48,8 @@ client c1 {
expect resp.status == 503 expect resp.status == 503
} -run } -run
varnish v1 -vsl_catchup
varnish v1 -cliok "backend.list" varnish v1 -cliok "backend.list"
varnish v1 -cliok "backend.set_health s1 healthy" varnish v1 -cliok "backend.set_health s1 healthy"
varnish v1 -cliok "backend.list" varnish v1 -cliok "backend.list"
...@@ -56,6 +60,8 @@ client c1 { ...@@ -56,6 +60,8 @@ client c1 {
expect resp.status == 200 expect resp.status == 200
} -run } -run
varnish v1 -vsl_catchup
varnish v1 -clierr 106 "backend.set_health s1 foo" varnish v1 -clierr 106 "backend.set_health s1 foo"
varnish v1 -clierr 106 "backend.set_health s2 foo" varnish v1 -clierr 106 "backend.set_health s2 foo"
varnish v1 -clierr 106 "backend.set_health s2 auto" varnish v1 -clierr 106 "backend.set_health s2 auto"
......
...@@ -61,7 +61,10 @@ client c1 { ...@@ -61,7 +61,10 @@ client c1 {
expect resp.body == "22" expect resp.body == "22"
} -run } -run
varnish v1 -vsl_catchup
varnish v1 -cliok "backend.set_health s1 sick" varnish v1 -cliok "backend.set_health s1 sick"
varnish v1 -cliok "backend.list"
client c1 { client c1 {
txreq txreq
...@@ -72,7 +75,10 @@ client c1 { ...@@ -72,7 +75,10 @@ client c1 {
expect resp.body == "22" expect resp.body == "22"
} -run } -run
varnish v1 -vsl_catchup
varnish v1 -cliok "backend.set_health s2 sick" varnish v1 -cliok "backend.set_health s2 sick"
varnish v1 -cliok "backend.list"
client c1 { client c1 {
txreq txreq
......
...@@ -52,6 +52,8 @@ ...@@ -52,6 +52,8 @@
* binary/load-time compatible, increment MAJOR version * binary/load-time compatible, increment MAJOR version
* *
* *
* TRUNK (2018-09-15)
* VRT_Healthy() changed prototype
* 7.0 (2018-03-15) * 7.0 (2018-03-15)
* lots of stuff moved from cache.h to cache_varnishd.h * lots of stuff moved from cache.h to cache_varnishd.h
* (ie: from "$Abi vrt" to "$Abi strict") * (ie: from "$Abi vrt" to "$Abi strict")
...@@ -416,7 +418,7 @@ struct vsmw_cluster *VRT_VSM_Cluster_New(VRT_CTX, size_t); ...@@ -416,7 +418,7 @@ struct vsmw_cluster *VRT_VSM_Cluster_New(VRT_CTX, size_t);
void VRT_VSM_Cluster_Destroy(VRT_CTX, struct vsmw_cluster **); void VRT_VSM_Cluster_Destroy(VRT_CTX, struct vsmw_cluster **);
/* cache_director.c */ /* cache_director.c */
int VRT_Healthy(VRT_CTX, VCL_BACKEND); VCL_BOOL VRT_Healthy(VRT_CTX, VCL_BACKEND, VCL_TIME *);
/* Suckaddr related */ /* Suckaddr related */
int VRT_VSA_GetPtr(const struct suckaddr *sua, const unsigned char ** dst); int VRT_VSA_GetPtr(const struct suckaddr *sua, const unsigned char ** dst);
......
...@@ -74,7 +74,7 @@ vmod_fallback_resolve(VRT_CTX, VCL_BACKEND dir) ...@@ -74,7 +74,7 @@ vmod_fallback_resolve(VRT_CTX, VCL_BACKEND dir)
for (u = 0; u < fb->vd->n_backend; u++) { for (u = 0; u < fb->vd->n_backend; u++) {
be = fb->vd->backend[fb->cur]; be = fb->vd->backend[fb->cur];
CHECK_OBJ_NOTNULL(be, DIRECTOR_MAGIC); CHECK_OBJ_NOTNULL(be, DIRECTOR_MAGIC);
if (be->methods->healthy(ctx, be, NULL)) if (VRT_Healthy(ctx, be, NULL))
break; break;
if (++fb->cur == fb->vd->n_backend) if (++fb->cur == fb->vd->n_backend)
fb->cur = 0; fb->cur = 0;
......
...@@ -73,7 +73,7 @@ vmod_rr_resolve(VRT_CTX, VCL_BACKEND dir) ...@@ -73,7 +73,7 @@ vmod_rr_resolve(VRT_CTX, VCL_BACKEND dir)
rr->nxt = nxt + 1; rr->nxt = nxt + 1;
be = rr->vd->backend[nxt]; be = rr->vd->backend[nxt];
CHECK_OBJ_NOTNULL(be, DIRECTOR_MAGIC); CHECK_OBJ_NOTNULL(be, DIRECTOR_MAGIC);
if (be->methods->healthy(ctx, be, NULL)) if (VRT_Healthy(ctx, be, NULL))
break; break;
} }
vdir_unlock(rr->vd); vdir_unlock(rr->vd);
......
...@@ -189,7 +189,7 @@ shard_next(struct shard_state *state, VCL_INT skip, VCL_BOOL healthy) ...@@ -189,7 +189,7 @@ shard_next(struct shard_state *state, VCL_INT skip, VCL_BOOL healthy)
sbe = NULL; sbe = NULL;
be = state->shardd->backend[c].backend; be = state->shardd->backend[c].backend;
AN(be); AN(be);
if (be->methods->healthy(state->ctx, be, &changed)) { if (VRT_Healthy(state->ctx, be, &changed)) {
if (skip-- == 0) { if (skip-- == 0) {
chosen = c; chosen = c;
sbe = &state->last; sbe = &state->last;
...@@ -324,7 +324,7 @@ sharddir_any_healthy(VRT_CTX, struct sharddir *shardd, VCL_TIME *changed) ...@@ -324,7 +324,7 @@ sharddir_any_healthy(VRT_CTX, struct sharddir *shardd, VCL_TIME *changed)
for (u = 0; u < shardd->n_backend; u++) { for (u = 0; u < shardd->n_backend; u++) {
be = shardd->backend[u].backend; be = shardd->backend[u].backend;
CHECK_OBJ_NOTNULL(be, DIRECTOR_MAGIC); CHECK_OBJ_NOTNULL(be, DIRECTOR_MAGIC);
retval = be->methods->healthy(ctx, be, &c); retval = VRT_Healthy(ctx, be, &c);
if (changed != NULL && c > *changed) if (changed != NULL && c > *changed)
*changed = c; *changed = c;
if (retval) if (retval)
......
...@@ -70,7 +70,7 @@ vdir_new(VRT_CTX, struct vdir **vdp, const char *vcl_name, ...@@ -70,7 +70,7 @@ vdir_new(VRT_CTX, struct vdir **vdp, const char *vcl_name,
vd->dir->methods = m; vd->dir->methods = m;
REPLACE(vd->dir->vcl_name, vcl_name); REPLACE(vd->dir->vcl_name, vcl_name);
vd->dir->priv = priv; vd->dir->priv = priv;
vd->dir->admin_health = VDI_AH_HEALTHY; vd->dir->admin_health = VDI_AH_PROBE;
vd->vbm = vbit_new(8); vd->vbm = vbit_new(8);
AN(vd->vbm); AN(vd->vbm);
} }
...@@ -188,7 +188,7 @@ vdir_any_healthy(VRT_CTX, struct vdir *vd, VCL_TIME *changed) ...@@ -188,7 +188,7 @@ vdir_any_healthy(VRT_CTX, struct vdir *vd, VCL_TIME *changed)
for (u = 0; u < vd->n_backend; u++) { for (u = 0; u < vd->n_backend; u++) {
be = vd->backend[u]; be = vd->backend[u];
CHECK_OBJ_NOTNULL(be, DIRECTOR_MAGIC); CHECK_OBJ_NOTNULL(be, DIRECTOR_MAGIC);
retval = be->methods->healthy(ctx, be, &c); retval = VRT_Healthy(ctx, be, &c);
if (changed != NULL && c > *changed) if (changed != NULL && c > *changed)
*changed = c; *changed = c;
if (retval) if (retval)
...@@ -230,7 +230,7 @@ vdir_pick_be(VRT_CTX, struct vdir *vd, double w) ...@@ -230,7 +230,7 @@ vdir_pick_be(VRT_CTX, struct vdir *vd, double w)
CHECK_OBJ_NOTNULL(vd, VDIR_MAGIC); CHECK_OBJ_NOTNULL(vd, VDIR_MAGIC);
vdir_wrlock(vd); vdir_wrlock(vd);
for (u = 0; u < vd->n_backend; u++) { for (u = 0; u < vd->n_backend; u++) {
if (vd->backend[u]->methods->healthy(ctx, vd->backend[u], NULL)) { if (VRT_Healthy(ctx, vd->backend[u], NULL)) {
vbit_clr(vd->vbm, u); vbit_clr(vd->vbm, u);
tw += vd->weight[u]; tw += vd->weight[u];
} else } else
......
...@@ -209,7 +209,7 @@ vmod_healthy(VRT_CTX, VCL_BACKEND be) ...@@ -209,7 +209,7 @@ vmod_healthy(VRT_CTX, VCL_BACKEND be)
{ {
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC); CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
CHECK_OBJ_ORNULL(be, DIRECTOR_MAGIC); CHECK_OBJ_ORNULL(be, DIRECTOR_MAGIC);
return (VRT_Healthy(ctx, be)); return (VRT_Healthy(ctx, be, NULL));
} }
VCL_INT v_matchproto_(td_std_port) VCL_INT v_matchproto_(td_std_port)
......
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