Permalink
Browse files

Lift events up to director level

  • Loading branch information...
bsdphk committed Nov 14, 2017
1 parent c34b28f commit bce70b95385dcdf1e6c8da61ee56b6decc77ab99
@@ -308,6 +308,35 @@ vbe_dir_http1pipe(const struct director *d, struct req *req, struct busyobj *bo)
/*--------------------------------------------------------------------*/
static void
vbe_dir_event(const struct director *d, enum vcl_event_e ev)
{
struct backend *bp;
CHECK_OBJ_NOTNULL(d, DIRECTOR_MAGIC);
CAST_OBJ_NOTNULL(bp, d->priv, BACKEND_MAGIC);
if (ev == VCL_EVENT_WARM) {
AZ(bp->vsc);
bp->vsc = VSC_vbe_New(bp->display_name);
AN(bp->vsc);
}
if (bp->probe != NULL && ev == VCL_EVENT_WARM)
VBP_Control(bp, 1);
if (bp->probe != NULL && ev == VCL_EVENT_COLD)
VBP_Control(bp, 0);
if (ev == VCL_EVENT_COLD) {
AN(bp->vsc);
VSC_vbe_Destroy(&bp->vsc);
AZ(bp->vsc);
}
}
/*--------------------------------------------------------------------*/
static void
vbe_panic(const struct director *d, struct vsb *vsb)
{
@@ -349,5 +378,6 @@ VBE_fill_director(struct backend *be)
d->gethdrs = vbe_dir_gethdrs;
d->getip = vbe_dir_getip;
d->finish = vbe_dir_finish;
d->event = vbe_dir_event;
d->panic = vbe_panic;
}
@@ -87,9 +87,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);
#ifdef VCL_MET_MAX
void VBE_Event(struct backend *, enum vcl_event_e);
#endif
void VBE_Delete(struct backend *be);
const char *
VBE_AdminHealth(const struct vbe_ahealth *);
@@ -39,7 +39,6 @@
#include "cache_varnishd.h"
#include "vcli_serve.h"
#include "vcl.h"
#include "vtim.h"
#include "waiter/waiter.h"
@@ -219,32 +218,6 @@ VBE_SetHappy(const struct backend *be, uint64_t happy)
* These are for cross-calls with cache_vcl.c only.
*/
void
VBE_Event(struct backend *be, enum vcl_event_e ev)
{
CHECK_OBJ_NOTNULL(be, BACKEND_MAGIC);
if (ev == VCL_EVENT_WARM) {
Lck_Lock(&backends_mtx);
be->vsc = VSC_vbe_New(be->display_name);
AN(be->vsc);
Lck_Unlock(&backends_mtx);
}
if (be->probe != NULL && ev == VCL_EVENT_WARM)
VBP_Control(be, 1);
if (be->probe != NULL && ev == VCL_EVENT_COLD)
VBP_Control(be, 0);
if (ev == VCL_EVENT_COLD) {
Lck_Lock(&backends_mtx);
VSC_vbe_Destroy(&be->vsc);
Lck_Unlock(&backends_mtx);
}
}
void
VBE_Delete(struct backend *be)
{
@@ -184,6 +184,18 @@ VRT_Healthy(VRT_CTX, VCL_BACKEND be)
return (be->healthy(be, ctx->bo, NULL));
}
/* Send Event ----------------------------------------------------------
*/
void
VDI_Event(const struct director *d, enum vcl_event_e ev)
{
CHECK_OBJ_NOTNULL(d, DIRECTOR_MAGIC);
if (d->event != NULL)
d->event(d, ev);
}
/* Dump panic info -----------------------------------------------------
*/
@@ -53,6 +53,8 @@ typedef void vdi_finish_f(const struct director *, struct worker *,
typedef enum sess_close vdi_http1pipe_f(const struct director *, struct req *,
struct busyobj *);
typedef void vdi_event_f(const struct director *, enum vcl_event_e);
typedef void vdi_panic_f(const struct director *, struct vsb *);
struct director {
@@ -67,6 +69,7 @@ struct director {
vdi_getbody_f *getbody;
vdi_getip_f *getip;
vdi_finish_f *finish;
vdi_event_f *event;
vdi_panic_f *panic;
void *priv;
const void *priv2;
@@ -70,6 +70,7 @@ const struct suckaddr *VDI_GetIP(struct worker *, struct busyobj *);
void VDI_Finish(struct worker *wrk, struct busyobj *bo);
enum sess_close VDI_Http1Pipe(struct req *, struct busyobj *);
void VDI_Panic(const struct director *, struct vsb *, const char *nm);
void VDI_Event(const struct director *d, enum vcl_event_e ev);
/* cache_exp.c */
double EXP_Ttl(const struct req *, const struct objcore *);
@@ -345,7 +345,7 @@ VCL_AddBackend(struct vcl *vcl, struct backend *be)
if (VCL_WARM(vcl))
/* Only when adding backend to already warm VCL */
VBE_Event(be, VCL_EVENT_WARM);
VDI_Event(be->director, 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));
@@ -367,7 +367,7 @@ VCL_DelBackend(struct backend *be)
AZ(errno=pthread_rwlock_rdlock(&vcl->temp_rwl));
if (VCL_WARM(vcl))
VBE_Event(be, VCL_EVENT_COLD);
VDI_Event(be->director, VCL_EVENT_COLD);
AZ(errno=pthread_rwlock_unlock(&vcl->temp_rwl));
}
@@ -381,7 +381,7 @@ vcl_BackendEvent(const struct vcl *vcl, enum vcl_event_e e)
AZ(vcl->busy);
VTAILQ_FOREACH(be, &vcl->backend_list, vcl_list)
VBE_Event(be, e);
VDI_Event(be->director, e);
}
static void

0 comments on commit bce70b9

Please sign in to comment.