Permalink
Browse files

Have VCL track backends at the director level.

  • Loading branch information...
bsdphk committed Nov 14, 2017
1 parent bce70b9 commit 1d26aa4c6d0fcaeef2675bd2a1d7b6a3b70cc6a2
@@ -54,12 +54,10 @@ struct backend {
unsigned n_conn;
VTAILQ_ENTRY(backend) list;
VTAILQ_ENTRY(backend) vcl_list;
struct lock mtx;
VRT_BACKEND_FIELDS()
struct vcl *vcl;
char *display_name;
@@ -87,9 +85,8 @@ 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(struct backend *be);
const char *
VBE_AdminHealth(const struct vbe_ahealth *);
void VBE_Delete(const struct director *);
const char *VBE_AdminHealth(const struct vbe_ahealth *);
/* cache_backend_probe.c */
void VBP_Insert(struct backend *b, struct vrt_backend_probe const *p,
@@ -99,5 +96,5 @@ void VBP_Control(const struct backend *b, int stop);
void VBP_Status(struct cli *cli, const struct backend *, int details);
/* cache_vcl.c */
int VCL_AddBackend(struct vcl *, struct backend *);
void VCL_DelBackend(struct backend *);
int VCL_AddBackend(struct vcl *, struct director *);
void VCL_DelBackend(const struct director *);
@@ -141,8 +141,6 @@ VRT_new_backend(VRT_CTX, const struct vrt_backend *vrt)
AN(b->display_name);
VSB_destroy(&vsb);
b->vcl = vcl;
b->healthy = 1;
b->health_changed = VTIM_real();
b->admin_health = vbe_ah_probe;
@@ -165,7 +163,7 @@ VRT_new_backend(VRT_CTX, const struct vrt_backend *vrt)
VBP_Insert(b, vbp, b->tcp_pool);
}
retval = VCL_AddBackend(ctx->vcl, b);
retval = VCL_AddBackend(ctx->vcl, b->director);
if (retval == 0)
return (b->director);
@@ -219,10 +217,12 @@ VBE_SetHappy(const struct backend *be, uint64_t happy)
*/
void
VBE_Delete(struct backend *be)
VBE_Delete(const struct director *d)
{
struct backend *be;
ASSERT_CLI();
CHECK_OBJ_NOTNULL(be, BACKEND_MAGIC);
CAST_OBJ_NOTNULL(be, d->priv, BACKEND_MAGIC);
if (be->probe != NULL)
VBP_Remove(be);
@@ -457,8 +457,8 @@ VBE_Poll(void)
if (be->n_conn > 0)
continue;
Lck_Unlock(&backends_mtx);
VCL_DelBackend(be);
VBE_Delete(be);
VCL_DelBackend(be->director);
VBE_Delete(be->director);
Lck_Lock(&backends_mtx);
}
Lck_Unlock(&backends_mtx);
@@ -73,4 +73,8 @@ struct director {
vdi_panic_f *panic;
void *priv;
const void *priv2;
/* Internal Housekeeping fields */
VTAILQ_ENTRY(director) list;
struct vcl *vcl;
};
@@ -70,7 +70,7 @@ struct vcl {
unsigned discard;
const char *temp;
pthread_rwlock_t temp_rwl;
VTAILQ_HEAD(,backend) backend_list;
VTAILQ_HEAD(,director) director_list;
VTAILQ_HEAD(,vclref) ref_list;
int nrefs;
struct vcl *label;
@@ -327,11 +327,11 @@ VCL_Rel(struct vcl **vcc)
/*--------------------------------------------------------------------*/
int
VCL_AddBackend(struct vcl *vcl, struct backend *be)
VCL_AddBackend(struct vcl *vcl, struct director *d)
{
CHECK_OBJ_NOTNULL(vcl, VCL_MAGIC);
CHECK_OBJ_NOTNULL(be, BACKEND_MAGIC);
CHECK_OBJ_NOTNULL(d, DIRECTOR_MAGIC);
AZ(errno=pthread_rwlock_rdlock(&vcl->temp_rwl));
if (vcl->temp == VCL_TEMP_COOLING) {
@@ -340,12 +340,13 @@ VCL_AddBackend(struct vcl *vcl, struct backend *be)
}
Lck_Lock(&vcl_mtx);
VTAILQ_INSERT_TAIL(&vcl->backend_list, be, vcl_list);
VTAILQ_INSERT_TAIL(&vcl->director_list, d, list);
d->vcl = vcl;
Lck_Unlock(&vcl_mtx);
if (VCL_WARM(vcl))
/* Only when adding backend to already warm VCL */
VDI_Event(be->director, VCL_EVENT_WARM);
VDI_Event(d, VCL_EVENT_WARM);
else if (vcl->temp != VCL_TEMP_INIT)
WRONG("Dynamic Backends can only be added to warm VCLs");
AZ(errno=pthread_rwlock_unlock(&vcl->temp_rwl));
@@ -354,50 +355,50 @@ VCL_AddBackend(struct vcl *vcl, struct backend *be)
}
void
VCL_DelBackend(struct backend *be)
VCL_DelBackend(const struct director *d)
{
struct vcl *vcl;
CHECK_OBJ_NOTNULL(be, BACKEND_MAGIC);
vcl = be->vcl;
CHECK_OBJ_NOTNULL(d, DIRECTOR_MAGIC);
vcl = d->vcl;
CHECK_OBJ_NOTNULL(vcl, VCL_MAGIC);
Lck_Lock(&vcl_mtx);
VTAILQ_REMOVE(&vcl->backend_list, be, vcl_list);
VTAILQ_REMOVE(&vcl->director_list, d, list);
Lck_Unlock(&vcl_mtx);
AZ(errno=pthread_rwlock_rdlock(&vcl->temp_rwl));
if (VCL_WARM(vcl))
VDI_Event(be->director, VCL_EVENT_COLD);
VDI_Event(d, VCL_EVENT_COLD);
AZ(errno=pthread_rwlock_unlock(&vcl->temp_rwl));
}
static void
vcl_BackendEvent(const struct vcl *vcl, enum vcl_event_e e)
{
struct backend *be;
struct director *d;
ASSERT_CLI();
CHECK_OBJ_NOTNULL(vcl, VCL_MAGIC);
AZ(vcl->busy);
VTAILQ_FOREACH(be, &vcl->backend_list, vcl_list)
VDI_Event(be->director, e);
VTAILQ_FOREACH(d, &vcl->director_list, list)
VDI_Event(d, e);
}
static void
vcl_KillBackends(struct vcl *vcl)
{
struct backend *be;
struct director *d;
CHECK_OBJ_NOTNULL(vcl, VCL_MAGIC);
AZ(vcl->busy);
assert(VTAILQ_EMPTY(&vcl->ref_list));
while (1) {
be = VTAILQ_FIRST(&vcl->backend_list);
if (be == NULL)
d = VTAILQ_FIRST(&vcl->director_list);
if (d == NULL)
break;
VTAILQ_REMOVE(&vcl->backend_list, be, vcl_list);
VBE_Delete(be);
VTAILQ_REMOVE(&vcl->director_list, d, list);
VBE_Delete(d);
}
}
@@ -752,7 +753,7 @@ vcl_load(struct cli *cli, struct vrt_ctx *ctx,
vcl->loaded_name = strdup(name);
XXXAN(vcl->loaded_name);
VTAILQ_INIT(&vcl->backend_list);
VTAILQ_INIT(&vcl->director_list);
VTAILQ_INIT(&vcl->ref_list);
vcl->temp = VCL_TEMP_INIT;

0 comments on commit 1d26aa4

Please sign in to comment.