Commit 8c113ff6 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Make sure that the ban-lurker cleans the tail at least once every

10 loops.  Simplify the structure of the code some more.

Prodded by:	martin
parent 952e1ce5
...@@ -818,25 +818,30 @@ BAN_CheckObject(struct object *o, struct req *req) ...@@ -818,25 +818,30 @@ BAN_CheckObject(struct object *o, struct req *req)
return (ban_check_object(o, req->vsl, req->http) > 0); return (ban_check_object(o, req->vsl, req->http) > 0);
} }
static struct ban * static void
ban_CheckLast(void) ban_cleantail(void)
{ {
struct ban *b; struct ban *b;
Lck_AssertHeld(&ban_mtx); do {
b = VTAILQ_LAST(&ban_head, banhead_s); Lck_Lock(&ban_mtx);
if (b != VTAILQ_FIRST(&ban_head) && b->refcount == 0) { b = VTAILQ_LAST(&ban_head, banhead_s);
if (b->flags & BAN_F_GONE) if (b != VTAILQ_FIRST(&ban_head) && b->refcount == 0) {
VSC_C_main->bans_gone--; if (b->flags & BAN_F_GONE)
if (b->flags & BAN_F_REQ) VSC_C_main->bans_gone--;
VSC_C_main->bans_req--; if (b->flags & BAN_F_REQ)
VSC_C_main->bans--; VSC_C_main->bans_req--;
VSC_C_main->bans_deleted++; VSC_C_main->bans--;
VTAILQ_REMOVE(&ban_head, b, list); VSC_C_main->bans_deleted++;
} else { VTAILQ_REMOVE(&ban_head, b, list);
b = NULL; STV_BanInfo(BI_DROP, b->spec, ban_len(b->spec));
} } else {
return (b); b = NULL;
}
Lck_Unlock(&ban_mtx);
if (b != NULL)
BAN_Free(b);
} while (b != NULL);
} }
/*-------------------------------------------------------------------- /*--------------------------------------------------------------------
...@@ -983,41 +988,29 @@ ban_lurker_work(struct worker *wrk, struct vsl_log *vsl) ...@@ -983,41 +988,29 @@ ban_lurker_work(struct worker *wrk, struct vsl_log *vsl)
static void * __match_proto__(bgthread_t) static void * __match_proto__(bgthread_t)
ban_lurker(struct worker *wrk, void *priv) ban_lurker(struct worker *wrk, void *priv)
{ {
struct ban *bf;
struct vsl_log vsl; struct vsl_log vsl;
volatile double d;
int i = 0, n = 0;
int i = 0;
VSL_Setup(&vsl, NULL, 0); VSL_Setup(&vsl, NULL, 0);
(void)priv; (void)priv;
while (1) { while (1) {
d = cache_param->ban_lurker_sleep;
do { if (d > 0.0) {
/* i = ban_lurker_work(wrk, &vsl);
* Ban-lurker is disabled: VSL_Flush(&vsl, 0);
* Clean the last ban, if possible, and sleep WRK_SumStat(wrk);
*/ if (i) {
Lck_Lock(&ban_mtx); VTIM_sleep(d);
bf = ban_CheckLast(); if (++n > 10) {
if (bf != NULL) ban_cleantail();
/* Notify stevedores */ n = 0;
STV_BanInfo(BI_DROP, bf->spec, }
ban_len(bf->spec)); continue;
Lck_Unlock(&ban_mtx); }
if (bf != NULL)
BAN_Free(bf);
} while (bf != NULL);
if (cache_param->ban_lurker_sleep != 0.0) {
do {
i = ban_lurker_work(wrk, &vsl);
VSL_Flush(&vsl, 0);
WRK_SumStat(wrk);
if (i)
VTIM_sleep(
cache_param->ban_lurker_sleep);
} while (i);
} }
ban_cleantail();
VTIM_sleep(0.609); // Random, non-magic VTIM_sleep(0.609); // Random, non-magic
} }
NEEDLESS_RETURN(NULL); NEEDLESS_RETURN(NULL);
......
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