[3.0] 1369592 Ensure ban lurker sleeps 1.0s on failure
Tollef Fog Heen
tfheen at varnish-cache.org
Wed Oct 26 14:58:57 CEST 2011
commit 1369592ded40e4a0982fe6ba9c50a0bb10992a39
Author: Kristian Lyngstol <kristian at bohemians.org>
Date: Mon Oct 17 14:09:11 2011 +0200
Ensure ban lurker sleeps 1.0s on failure
As per documentation, the ban lurker sleeps ban_lurker_sleep when it is
successful, but on failure it should only sleep 1.0s. No point hammering
the ban list every 0.01s if bans aren't even used.
Fixes #1030
Conflicts:
bin/varnishd/cache_ban.c
diff --git a/bin/varnishd/cache_ban.c b/bin/varnishd/cache_ban.c
index 4c95592..7fbeffd 100644
--- a/bin/varnishd/cache_ban.c
+++ b/bin/varnishd/cache_ban.c
@@ -738,7 +738,7 @@ BAN_CheckObject(struct object *o, const struct sess *sp)
* Ban tail lurker thread
*/
-static void
+static int
ban_lurker_work(const struct sess *sp)
{
struct ban *b, *bf;
@@ -757,21 +757,21 @@ ban_lurker_work(const struct sess *sp)
if (bf != NULL) {
Lck_Unlock(&ban_mtx);
BAN_Free(bf);
- return;
+ return (0);
}
/* Find the last ban give up, if we have only one */
b = VTAILQ_LAST(&ban_head, banhead_s);
if (b == ban_start) {
Lck_Unlock(&ban_mtx);
- return;
+ return (0);
}
/* Find the first object on it, if any */
oc = VTAILQ_FIRST(&b->objcore);
if (oc == NULL) {
Lck_Unlock(&ban_mtx);
- return;
+ return (0);
}
/* Try to lock the objhead */
@@ -779,7 +779,7 @@ ban_lurker_work(const struct sess *sp)
CHECK_OBJ_NOTNULL(oh, OBJHEAD_MAGIC);
if (Lck_Trylock(&oh->mtx)) {
Lck_Unlock(&ban_mtx);
- return;
+ return (0);
}
/*
@@ -792,7 +792,7 @@ ban_lurker_work(const struct sess *sp)
if (oc2 == NULL) {
Lck_Unlock(&oh->mtx);
Lck_Unlock(&ban_mtx);
- return;
+ return (0);
}
/*
* Grab a reference to the OC and we can let go of the BAN mutex
@@ -809,12 +809,13 @@ ban_lurker_work(const struct sess *sp)
Lck_Unlock(&oh->mtx);
WSP(sp, SLT_Debug, "lurker: %p %g %d", oc, o->exp.ttl, i);
(void)HSH_Deref(sp->wrk, NULL, &o);
+ return (i);
}
static void * __match_proto__(bgthread_t)
ban_lurker(struct sess *sp, void *priv)
{
-
+ int i = 0;
(void)priv;
while (1) {
if (params->ban_lurker_sleep == 0.0) {
@@ -822,8 +823,11 @@ ban_lurker(struct sess *sp, void *priv)
TIM_sleep(1.0);
continue;
}
- TIM_sleep(params->ban_lurker_sleep);
- ban_lurker_work(sp);
+ if (i != 0)
+ TIM_sleep(params->ban_lurker_sleep);
+ else
+ TIM_sleep(1.0);
+ i = ban_lurker_work(sp);
WSL_Flush(sp->wrk, 0);
WRK_SumStat(sp->wrk);
}
diff --git a/bin/varnishtest/tests/r01030.vtc b/bin/varnishtest/tests/r01030.vtc
new file mode 100644
index 0000000..97ef3d7
--- /dev/null
+++ b/bin/varnishtest/tests/r01030.vtc
@@ -0,0 +1,64 @@
+varnishtest "Test ban_lurker_sleep vs failed ban lurker"
+
+# The idea here is that the ban lurker should always wait 1 second when it
+# can't proceed, as per documentation and original intent. The
+# ban_lurker_sleep should not affect sleep-times when the lurker fails.
+
+server s1 {
+ rxreq
+ txresp -status 200
+
+ rxreq
+ txresp -status 200
+} -start
+
+varnish v1 -vcl+backend {
+ sub vcl_recv {
+ if (req.request == "BAN") {
+ ban("obj.http.url ~ /");
+ error 201 "banned";
+ }
+ return (lookup);
+ }
+ sub vcl_fetch {
+ set beresp.http.url = req.url;
+ }
+} -start
+
+varnish v1 -cliok "param.set ban_lurker_sleep 0.01"
+varnish v1 -expect n_ban_obj_test == 0
+
+delay 0.01
+client c1 {
+ txreq -req GET
+ rxresp
+ expect resp.status == 200
+
+ txreq -req BAN
+ rxresp
+ expect resp.status == 201
+} -run
+
+delay 0.1
+varnish v1 -expect n_ban_obj_test == 0
+
+delay 1.0
+varnish v1 -expect n_ban_obj_test == 1
+
+varnish v1 -cliok "param.set ban_lurker_sleep 5.01"
+
+client c2 {
+ txreq -req GET
+ rxresp
+ expect resp.status == 200
+
+ txreq -req BAN
+ rxresp
+ expect resp.status == 201
+} -run
+
+delay 0.1
+varnish v1 -expect n_ban_obj_test == 1
+
+delay 1.1
+varnish v1 -expect n_ban_obj_test == 2
More information about the varnish-commit
mailing list