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

Synchronize backend probe tear-down with a mutex.

parent a49d6239
...@@ -68,6 +68,7 @@ VBE_DeleteBackend(struct backend *b) ...@@ -68,6 +68,7 @@ VBE_DeleteBackend(struct backend *b)
free(b->display_name); free(b->display_name);
VSM_Free(b->vsc); VSM_Free(b->vsc);
VBT_Rel(&b->tcp_pool); VBT_Rel(&b->tcp_pool);
Lck_Delete(&b->mtx);
FREE_OBJ(b); FREE_OBJ(b);
VSC_C_main->n_backend--; VSC_C_main->n_backend--;
} }
......
...@@ -57,12 +57,14 @@ struct vbp_target { ...@@ -57,12 +57,14 @@ struct vbp_target {
unsigned magic; unsigned magic;
#define VBP_TARGET_MAGIC 0x6b7cb656 #define VBP_TARGET_MAGIC 0x6b7cb656
struct lock mtx;
int stop;
struct backend *backend; struct backend *backend;
struct tcp_pool *tcp_pool; struct tcp_pool *tcp_pool;
struct vrt_backend_probe probe; struct vrt_backend_probe probe;
int stop;
char *req; char *req;
int req_len; int req_len;
...@@ -235,27 +237,31 @@ vbp_has_poked(struct vbp_target *vt) ...@@ -235,27 +237,31 @@ vbp_has_poked(struct vbp_target *vt)
} }
vt->good = j; vt->good = j;
if (vt->good >= vt->probe.threshold) { Lck_Lock(&vt->mtx);
if (vt->backend->healthy) if (vt->backend != NULL) {
logmsg = "Still healthy"; if (vt->good >= vt->probe.threshold) {
else { if (vt->backend->healthy)
logmsg = "Back healthy"; logmsg = "Still healthy";
vt->backend->health_changed = VTIM_real(); else {
logmsg = "Back healthy";
vt->backend->health_changed = VTIM_real();
}
vt->backend->healthy = 1;
} else {
if (vt->backend->healthy) {
logmsg = "Went sick";
vt->backend->health_changed = VTIM_real();
} else
logmsg = "Still sick";
vt->backend->healthy = 0;
} }
vt->backend->healthy = 1; VSL(SLT_Backend_health, 0, "%s %s %s %u %u %u %.6f %.6f %s",
} else { vt->backend->vcl_name, logmsg, bits,
if (vt->backend->healthy) { vt->good, vt->probe.threshold, vt->probe.window,
logmsg = "Went sick"; vt->last, vt->avg, vt->resp_buf);
vt->backend->health_changed = VTIM_real(); vt->backend->vsc->happy = vt->happy;
} else
logmsg = "Still sick";
vt->backend->healthy = 0;
} }
VSL(SLT_Backend_health, 0, "%s %s %s %u %u %u %.6f %.6f %s", Lck_Unlock(&vt->mtx);
vt->backend->vcl_name, logmsg, bits,
vt->good, vt->probe.threshold, vt->probe.window,
vt->last, vt->avg, vt->resp_buf);
vt->backend->vsc->happy = vt->happy;
} }
/*-------------------------------------------------------------------- /*--------------------------------------------------------------------
...@@ -282,6 +288,11 @@ vbp_wrk_poll_backend(void *priv) ...@@ -282,6 +288,11 @@ vbp_wrk_poll_backend(void *priv)
if (!vt->stop) if (!vt->stop)
VTIM_sleep(vt->probe.interval); VTIM_sleep(vt->probe.interval);
} }
Lck_Delete(&vt->mtx);
VTAILQ_REMOVE(&vbp_list, vt, list);
VBT_Rel(&vt->tcp_pool);
free(vt->req);
FREE_OBJ(vt);
return (NULL); return (NULL);
} }
...@@ -423,6 +434,7 @@ VBP_Insert(struct backend *b, const struct vrt_backend_probe *p, ...@@ -423,6 +434,7 @@ VBP_Insert(struct backend *b, const struct vrt_backend_probe *p,
vt->backend = b; vt->backend = b;
b->probe = vt; b->probe = vt;
VTAILQ_INSERT_TAIL(&vbp_list, vt, list); VTAILQ_INSERT_TAIL(&vbp_list, vt, list);
Lck_New(&vt->mtx, lck_backend);
vt->tcp_pool = VBT_Ref(b->ipv4, b->ipv6); vt->tcp_pool = VBT_Ref(b->ipv4, b->ipv6);
AN(vt->tcp_pool); AN(vt->tcp_pool);
...@@ -440,28 +452,24 @@ VBP_Insert(struct backend *b, const struct vrt_backend_probe *p, ...@@ -440,28 +452,24 @@ VBP_Insert(struct backend *b, const struct vrt_backend_probe *p,
if (!vt->probe.initial) if (!vt->probe.initial)
vbp_has_poked(vt); vbp_has_poked(vt);
AZ(pthread_create(&vt->thread, NULL, vbp_wrk_poll_backend, vt)); AZ(pthread_create(&vt->thread, NULL, vbp_wrk_poll_backend, vt));
AZ(pthread_detach(vt->thread));
} }
void void
VBP_Remove(struct backend *b) VBP_Remove(struct backend *be)
{ {
struct vbp_target *vt; struct vbp_target *vt;
void *ret;
ASSERT_CLI(); ASSERT_CLI();
CHECK_OBJ_NOTNULL(b, BACKEND_MAGIC); CHECK_OBJ_NOTNULL(be, BACKEND_MAGIC);
vt = b->probe; vt = be->probe;
CHECK_OBJ_NOTNULL(vt, VBP_TARGET_MAGIC); CHECK_OBJ_NOTNULL(vt, VBP_TARGET_MAGIC);
Lck_Lock(&vt->mtx);
vt->stop = 1; vt->stop = 1;
vt->backend = NULL;
Lck_Unlock(&vt->mtx);
AZ(pthread_cancel(vt->thread)); be->healthy = 1;
AZ(pthread_join(vt->thread, &ret)); be->probe = NULL;
VTAILQ_REMOVE(&vbp_list, vt, list);
b->healthy = 1;
b->probe = NULL;
VBT_Rel(&vt->tcp_pool);
free(vt->req);
FREE_OBJ(vt);
} }
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