[master] 705e38b Move backend trouble maintenance to cache_backend.c
Poul-Henning Kamp
phk at varnish-cache.org
Wed Apr 24 09:36:19 CEST 2013
commit 705e38b6a545452407c19386596cbe5b8a884fa0
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Wed Apr 24 07:29:35 2013 +0000
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.
diff --git a/bin/varnishd/cache/cache_backend.c b/bin/varnishd/cache/cache_backend.c
index c6f0b9b..9d743c3 100644
--- a/bin/varnishd/cache/cache_backend.c
+++ b/bin/varnishd/cache/cache_backend.c
@@ -224,6 +224,38 @@ vbe_NewConn(void)
}
/*--------------------------------------------------------------------
+ * 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
* saint-mode, but also takes backend->healthy into account. If
diff --git a/bin/varnishd/cache/cache_backend.h b/bin/varnishd/cache/cache_backend.h
index b87b8d4..670fcf8 100644
--- a/bin/varnishd/cache/cache_backend.h
+++ b/bin/varnishd/cache/cache_backend.h
@@ -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 *);
diff --git a/bin/varnishd/cache/cache_vrt.c b/bin/varnishd/cache/cache_vrt.c
index f6ad925..b2d5da6 100644
--- a/bin/varnishd/cache/cache_vrt.c
+++ b/bin/varnishd/cache/cache_vrt.c
@@ -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
diff --git a/bin/varnishd/cache/cache_vrt_var.c b/bin/varnishd/cache/cache_vrt_var.c
index 474fe95..8060a50 100644
--- a/bin/varnishd/cache/cache_vrt_var.c
+++ b/bin/varnishd/cache/cache_vrt_var.c
@@ -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) \
More information about the varnish-commit
mailing list