Commit 705e38b6 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Move backend trouble maintenance to cache_backend.c

Move VRT interface to cache_vrt.c rather than cache_vrt_var.c,
the latter is reserved for VCL variables.
parent 2e1dcdfd
......@@ -223,6 +223,38 @@ vbe_NewConn(void)
return (vc);
}
/*--------------------------------------------------------------------
* Add backend trouble item
*/
void
VBE_AddTrouble(const struct req *req, double dt)
{
struct trouble *tp;
struct vbc *vbc;
struct backend *be;
CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
CHECK_OBJ_NOTNULL(req->busyobj, BUSYOBJ_MAGIC);
vbc = req->busyobj->vbc;
if (vbc == NULL)
return;
CHECK_OBJ_NOTNULL(vbc, VBC_MAGIC);
be = vbc->backend;
CHECK_OBJ_NOTNULL(be, BACKEND_MAGIC);
if (dt <= 0.)
return;
ALLOC_OBJ(tp, TROUBLE_MAGIC);
if (tp == NULL)
return;
memcpy(tp->digest, req->digest, sizeof tp->digest);
tp->timeout = req->t_req + dt;
Lck_Lock(&vbc->backend->mtx);
VTAILQ_INSERT_HEAD(&be->troublelist, tp, list);
be->n_trouble++;
Lck_Unlock(&vbc->backend->mtx);
}
/*--------------------------------------------------------------------
* It evaluates if a backend is healthy _for_a_specific_object_.
* That means that it relies on req->objcore->objhead. This is mainly for
......
......@@ -138,6 +138,8 @@ struct backend {
struct vbp_target *probe;
unsigned healthy;
enum admin_health admin_health;
unsigned n_trouble;
VTAILQ_HEAD(, trouble) troublelist;
struct VSC_C_vbe *vsc;
......@@ -167,6 +169,7 @@ struct vbc {
/* cache_backend.c */
void VBE_ReleaseConn(struct vbc *vc);
void VBE_AddTrouble(const struct req *req, double dt);
/* cache_backend_cfg.c */
void VBE_DropRefConn(struct backend *);
......
......@@ -385,6 +385,19 @@ VRT_BOOL_string(unsigned val)
return (val ? "true" : "false");
}
/*--------------------------------------------------------------------
* Add an objecthead to the saintmode list for the (hopefully) relevant
* backend.
*/
void
VRT_l_beresp_saintmode(const struct req *req, double a)
{
VBE_AddTrouble(req, a);
}
/*--------------------------------------------------------------------*/
void
......
......@@ -128,66 +128,6 @@ VRT_DO_STATUS(beresp, px->beresp)
/*--------------------------------------------------------------------*/
/* XXX: review this */
/* Add an objecthead to the saintmode list for the (hopefully) relevant
* backend. Some double-up asserting here to avoid assert-errors when there
* is no object.
*/
void
VRT_l_beresp_saintmode(const struct req *req, double a)
{
struct trouble *new;
struct trouble *tr;
struct trouble *tr2;
struct vbc *vbc;
CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
CHECK_OBJ_NOTNULL(req->busyobj, BUSYOBJ_MAGIC);
vbc = req->busyobj->vbc;
if (!vbc)
return;
CHECK_OBJ_NOTNULL(vbc, VBC_MAGIC);
if (!vbc->backend)
return;
CHECK_OBJ_NOTNULL(vbc->backend, BACKEND_MAGIC);
if (!req->objcore->objhead)
return;
CHECK_OBJ_NOTNULL(req->objcore, OBJCORE_MAGIC);
/* Setting a negative holdoff period is a mistake. Detecting this
* when compiling the VCL would be better.
*/
assert(a > 0);
ALLOC_OBJ(new, TROUBLE_MAGIC);
AN(new);
memcpy(new->digest, req->digest, sizeof new->digest);
new->timeout = req->t_req + a;
/* Insert the new item on the list before the first item with a
* timeout at a later date (ie: sort by which entry will time out
* from the list
*/
Lck_Lock(&vbc->backend->mtx);
VTAILQ_FOREACH_SAFE(tr, &vbc->backend->troublelist, list, tr2) {
if (tr->timeout < new->timeout) {
VTAILQ_INSERT_BEFORE(tr, new, list);
new = NULL;
break;
}
}
/* Insert the item at the end if the list is empty or all other
* items have a longer timeout.
*/
if (new)
VTAILQ_INSERT_TAIL(&vbc->backend->troublelist, new, list);
Lck_Unlock(&vbc->backend->mtx);
}
/*--------------------------------------------------------------------*/
#define VBERESP(dir, type, onm, field) \
void \
VRT_l_##dir##_##onm(struct busyobj *bo, type a) \
......
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