[master] 7de8e83 Lift the health fields from backend to director

Poul-Henning Kamp phk at FreeBSD.org
Tue Nov 14 09:31:11 UTC 2017


commit 7de8e8369b514aeb52edd22cb5388ea4749afe71
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Tue Nov 14 09:08:50 2017 +0000

    Lift the health fields from backend to director

diff --git a/bin/varnishd/cache/cache_backend.c b/bin/varnishd/cache/cache_backend.c
index fc2f9db..94739eb 100644
--- a/bin/varnishd/cache/cache_backend.c
+++ b/bin/varnishd/cache/cache_backend.c
@@ -75,7 +75,7 @@ vbe_dir_getfd(struct worker *wrk, struct backend *bp, struct busyobj *bo)
 	CHECK_OBJ_NOTNULL(bp, BACKEND_MAGIC);
 	AN(bp->vsc);
 
-	if (!VBE_Healthy(bp, NULL)) {
+	if (!VDI_Healthy(bp->director, NULL)) {
 		VSLb(bo->vsl, SLT_FetchError,
 		     "backend %s: unhealthy", bp->display_name);
 		// XXX: per backend stats ?
@@ -147,7 +147,7 @@ vbe_dir_healthy(const struct director *d, const struct busyobj *bo,
 	CHECK_OBJ_NOTNULL(d, DIRECTOR_MAGIC);
 	CHECK_OBJ_ORNULL(bo, BUSYOBJ_MAGIC);
 	CAST_OBJ_NOTNULL(be, d->priv, BACKEND_MAGIC);
-	return (VBE_Healthy(be, changed));
+	return (VDI_Healthy(be->director, changed));
 }
 
 static void __match_proto__(vdi_finish_f)
@@ -353,9 +353,10 @@ vbe_panic(const struct director *d, struct vsb *vsb)
 	VSB_printf(vsb, "port = %s,\n", bp->port);
 	VSB_printf(vsb, "hosthdr = %s,\n", bp->hosthdr);
 	VSB_printf(vsb, "health = %s,\n",
-	    bp->healthy ? "healthy" : "sick");
+	    bp->director->health ? "healthy" : "sick");
 	VSB_printf(vsb, "admin_health = %s, changed = %f,\n",
-	    VBE_AdminHealth(bp->admin_health), bp->health_changed);
+	    VBE_AdminHealth(bp->director->admin_health),
+	    bp->director->health_changed);
 	VSB_printf(vsb, "n_conn = %u,\n", bp->n_conn);
 }
 
diff --git a/bin/varnishd/cache/cache_backend.h b/bin/varnishd/cache/cache_backend.h
index 993aa4c..02e9bb0 100644
--- a/bin/varnishd/cache/cache_backend.h
+++ b/bin/varnishd/cache/cache_backend.h
@@ -62,9 +62,6 @@ struct backend {
 
 
 	struct vbp_target	*probe;
-	unsigned		healthy;
-	const struct vbe_ahealth *admin_health;
-	double			health_changed;
 
 	struct VSC_vbe		*vsc;
 
@@ -84,7 +81,6 @@ void VBE_fill_director(struct backend *be);
 
 /* cache_backend_cfg.c */
 void VBE_SetHappy(const struct backend *, uint64_t);
-unsigned VBE_Healthy(const struct backend *b, double *changed);
 void VBE_Delete(const struct director *);
 const char *VBE_AdminHealth(const struct vbe_ahealth *);
 
diff --git a/bin/varnishd/cache/cache_backend_cfg.c b/bin/varnishd/cache/cache_backend_cfg.c
index 5098810..18e5221 100644
--- a/bin/varnishd/cache/cache_backend_cfg.c
+++ b/bin/varnishd/cache/cache_backend_cfg.c
@@ -141,9 +141,11 @@ VRT_new_backend(VRT_CTX, const struct vrt_backend *vrt)
 	AN(b->display_name);
 	VSB_destroy(&vsb);
 
-	b->healthy = 1;
-	b->health_changed = VTIM_real();
-	b->admin_health = vbe_ah_probe;
+	VBE_fill_director(b);
+
+	b->director->health = 1;
+	b->director->health_changed = VTIM_real();
+	b->director->admin_health = vbe_ah_probe;
 
 	vbp = vrt->probe;
 	if (vbp == NULL)
@@ -156,8 +158,6 @@ VRT_new_backend(VRT_CTX, const struct vrt_backend *vrt)
 	    vbe_proto_ident);
 	Lck_Unlock(&backends_mtx);
 
-	VBE_fill_director(b);
-
 	if (vbp != NULL) {
 		VTP_AddRef(b->tcp_pool);
 		VBP_Insert(b, vbp, b->tcp_pool);
@@ -189,8 +189,8 @@ VRT_delete_backend(VRT_CTX, struct director **dp)
 	TAKE_OBJ_NOTNULL(d, dp, DIRECTOR_MAGIC);
 	CAST_OBJ_NOTNULL(be, d->priv, BACKEND_MAGIC);
 	Lck_Lock(&be->mtx);
-	be->admin_health = vbe_ah_deleted;
-	be->health_changed = VTIM_real();
+	be->director->admin_health = vbe_ah_deleted;
+	be->director->health_changed = VTIM_real();
 	be->cooled = VTIM_real() + 60.;
 	Lck_Unlock(&be->mtx);
 	Lck_Lock(&backends_mtx);
@@ -253,23 +253,23 @@ VBE_Delete(const struct director *d)
  */
 
 unsigned
-VBE_Healthy(const struct backend *backend, double *changed)
+VDI_Healthy(const struct director *d, double *changed)
 {
-	CHECK_OBJ_NOTNULL(backend, BACKEND_MAGIC);
+	CHECK_OBJ_NOTNULL(d, DIRECTOR_MAGIC);
 
 	if (changed != NULL)
-		*changed = backend->health_changed;
+		*changed = d->health_changed;
 
-	if (backend->admin_health == vbe_ah_probe)
-		return (backend->healthy);
+	if (d->admin_health == vbe_ah_probe)
+		return (d->health);
 
-	if (backend->admin_health == vbe_ah_sick)
+	if (d->admin_health == vbe_ah_sick)
 		return (0);
 
-	if (backend->admin_health == vbe_ah_deleted)
+	if (d->admin_health == vbe_ah_deleted)
 		return (0);
 
-	if (backend->admin_health == vbe_ah_healthy)
+	if (d->admin_health == vbe_ah_healthy)
 		return (1);
 
 	WRONG("Wrong admin health");
@@ -313,7 +313,7 @@ backend_find(struct cli *cli, const char *matcher, bf_func *func, void *priv)
 	AZ(VSB_finish(vsb));
 	Lck_Lock(&backends_mtx);
 	VTAILQ_FOREACH(b, &backends, list) {
-		if (b->admin_health == vbe_ah_deleted)
+		if (b->director->admin_health == vbe_ah_deleted)
 			continue;
 		if (fnmatch(VSB_data(vsb), b->display_name, 0))
 			continue;
@@ -344,19 +344,19 @@ do_list(struct cli *cli, struct backend *b, void *priv)
 
 	VCLI_Out(cli, "\n%-30s", b->display_name);
 
-	VCLI_Out(cli, " %-10s", VBE_AdminHealth(b->admin_health));
+	VCLI_Out(cli, " %-10s", VBE_AdminHealth(b->director->admin_health));
 
 	if (b->probe == NULL)
 		VCLI_Out(cli, " %-20s", "Healthy (no probe)");
 	else {
-		if (b->healthy)
+		if (b->director->health)
 			VCLI_Out(cli, " %-20s", "Healthy ");
 		else
 			VCLI_Out(cli, " %-20s", "Sick ");
 		VBP_Status(cli, b, *probes);
 	}
 
-	VTIM_format(b->health_changed, time_str);
+	VTIM_format(b->director->health_changed, time_str);
 	VCLI_Out(cli, " %s", time_str);
 
 	return (0);
@@ -399,11 +399,11 @@ do_set_health(struct cli *cli, struct backend *b, void *priv)
 	ah = *(const struct vbe_ahealth **)priv;
 	AN(ah);
 	CHECK_OBJ_NOTNULL(b, BACKEND_MAGIC);
-	prev = VBE_Healthy(b, NULL);
-	if (b->admin_health != vbe_ah_deleted)
-		b->admin_health = ah;
-	if (prev != VBE_Healthy(b, NULL))
-		b->health_changed = VTIM_real();
+	prev = VDI_Healthy(b->director, NULL);
+	if (b->director->admin_health != vbe_ah_deleted)
+		b->director->admin_health = ah;
+	if (prev != VDI_Healthy(b->director, NULL))
+		b->director->health_changed = VTIM_real();
 
 	return (0);
 }
diff --git a/bin/varnishd/cache/cache_backend_probe.c b/bin/varnishd/cache/cache_backend_probe.c
index aa176c0..66b0546 100644
--- a/bin/varnishd/cache/cache_backend_probe.c
+++ b/bin/varnishd/cache/cache_backend_probe.c
@@ -169,20 +169,22 @@ vbp_update_backend(struct vbp_target *vt)
 		assert(i < sizeof bits);
 
 		if (vt->good >= vt->threshold) {
-			if (vt->backend->healthy)
+			if (vt->backend->director->health)
 				logmsg = "Still healthy";
 			else {
 				logmsg = "Back healthy";
-				vt->backend->health_changed = VTIM_real();
+				vt->backend->director->health_changed =
+				     VTIM_real();
 			}
-			vt->backend->healthy = 1;
+			vt->backend->director->health = 1;
 		} else {
-			if (vt->backend->healthy) {
+			if (vt->backend->director->health) {
 				logmsg = "Went sick";
-				vt->backend->health_changed = VTIM_real();
+				vt->backend->director->health_changed =
+				     VTIM_real();
 			} else
 				logmsg = "Still sick";
-			vt->backend->healthy = 0;
+			vt->backend->director->health = 0;
 		}
 		VSL(SLT_Backend_health, 0, "%s %s %s %u %u %u %.6f %.6f %s",
 		    vt->backend->display_name, logmsg, bits,
@@ -635,7 +637,7 @@ VBP_Remove(struct backend *be)
 	CHECK_OBJ_NOTNULL(vt, VBP_TARGET_MAGIC);
 
 	Lck_Lock(&vbp_mtx);
-	be->healthy = 1;
+	be->director->health = 1;
 	be->probe = NULL;
 	vt->backend = NULL;
 	if (vt->running) {
diff --git a/bin/varnishd/cache/cache_director.h b/bin/varnishd/cache/cache_director.h
index 9d7a6b9..2b283e0 100644
--- a/bin/varnishd/cache/cache_director.h
+++ b/bin/varnishd/cache/cache_director.h
@@ -78,6 +78,13 @@ struct director {
 	const void		*priv2;
 
 	/* Internal Housekeeping fields */
+
 	VTAILQ_ENTRY(director)	list;
 	struct vcl		*vcl;
+
+	unsigned		health;
+	const struct vbe_ahealth *admin_health;
+	double			health_changed;
 };
+
+unsigned VDI_Healthy(const struct director *, double *);


More information about the varnish-commit mailing list