From 6eb58c3e8959c36a6413727bbfe666950dd32967 Mon Sep 17 00:00:00 2001 From: Nils Goroll Date: Mon, 28 Oct 2024 16:27:41 +0100 Subject: [PATCH] vdire: Wait for directors to retire before staring a new iteration This is to prevent a potential pileup of resigned directors with a constant stream of iterators coming on --- bin/varnishd/cache/cache_vcl.c | 5 +++++ bin/varnishd/cache/cache_vcl.h | 2 ++ 2 files changed, 7 insertions(+) diff --git a/bin/varnishd/cache/cache_vcl.c b/bin/varnishd/cache/cache_vcl.c index f9641192b9d..de7b031a239 100644 --- a/bin/varnishd/cache/cache_vcl.c +++ b/bin/varnishd/cache/cache_vcl.c @@ -387,6 +387,7 @@ vdire_new(struct lock *mtx, const struct vcltemp **tempp) VTAILQ_INIT(&vdire->directors); VTAILQ_INIT(&vdire->resigning); vdire->mtx = mtx; + PTOK(pthread_cond_init(&vdire->cond, NULL)); vdire->tempp = tempp; return (vdire); } @@ -399,6 +400,8 @@ vdire_start_iter(struct vdire *vdire) CHECK_OBJ_NOTNULL(vdire, VDIRE_MAGIC); Lck_Lock(vdire->mtx); + while (! VTAILQ_EMPTY(&vdire->resigning)) + (void)Lck_CondWait(&vdire->cond, vdire->mtx); vdire->iterating++; Lck_Unlock(vdire->mtx); } @@ -422,6 +425,7 @@ vdire_end_iter(struct vdire *vdire) VTAILQ_FOREACH(vdir, &resigning, resigning_list) VTAILQ_REMOVE(&vdire->directors, vdir, directors_list); temp = *vdire->tempp; + PTOK(pthread_cond_broadcast(&vdire->cond)); } Lck_Unlock(vdire->mtx); @@ -653,6 +657,7 @@ VCL_Close(struct vcl **vclp) TAKE_OBJ_NOTNULL(vcl, vclp, VCL_MAGIC); assert(VTAILQ_EMPTY(&vcl->filters)); AZ(dlclose(vcl->dlh)); + PTOK(pthread_cond_destroy(&vcl->vdire->cond)); FREE_OBJ(vcl->vdire); FREE_OBJ(vcl); } diff --git a/bin/varnishd/cache/cache_vcl.h b/bin/varnishd/cache/cache_vcl.h index 7b7b28ce11a..f7fc31b6009 100644 --- a/bin/varnishd/cache/cache_vcl.h +++ b/bin/varnishd/cache/cache_vcl.h @@ -47,6 +47,8 @@ struct vdire { struct vcldir_head resigning; // vcl_mtx for now - to be refactored into separate mtx? struct lock *mtx; + // to signal when iterators can enter again + pthread_cond_t cond; const struct vcltemp **tempp; };