Skip to content

Commit 41c42a0

Browse files
committed
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
1 parent 375895a commit 41c42a0

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

bin/varnishd/cache/cache_vcl.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,7 @@ vdire_new(struct lock *mtx, const struct vcltemp **tempp)
387387
VTAILQ_INIT(&vdire->directors);
388388
VTAILQ_INIT(&vdire->resigning);
389389
vdire->mtx = mtx;
390+
PTOK(pthread_cond_init(&vdire->cond, NULL));
390391
vdire->tempp = tempp;
391392
return (vdire);
392393
}
@@ -399,6 +400,8 @@ vdire_start_iter(struct vdire *vdire)
399400
CHECK_OBJ_NOTNULL(vdire, VDIRE_MAGIC);
400401

401402
Lck_Lock(vdire->mtx);
403+
while (! VTAILQ_EMPTY(&vdire->resigning))
404+
(void)Lck_CondWait(&vdire->cond, vdire->mtx);
402405
vdire->iterating++;
403406
Lck_Unlock(vdire->mtx);
404407
}
@@ -422,6 +425,7 @@ vdire_end_iter(struct vdire *vdire)
422425
VTAILQ_FOREACH(vdir, &resigning, resigning_list)
423426
VTAILQ_REMOVE(&vdire->directors, vdir, directors_list);
424427
temp = *vdire->tempp;
428+
PTOK(pthread_cond_broadcast(&vdire->cond));
425429
}
426430
Lck_Unlock(vdire->mtx);
427431

@@ -653,6 +657,7 @@ VCL_Close(struct vcl **vclp)
653657
TAKE_OBJ_NOTNULL(vcl, vclp, VCL_MAGIC);
654658
assert(VTAILQ_EMPTY(&vcl->filters));
655659
AZ(dlclose(vcl->dlh));
660+
PTOK(pthread_cond_destroy(&vcl->vdire->cond));
656661
FREE_OBJ(vcl->vdire);
657662
FREE_OBJ(vcl);
658663
}

bin/varnishd/cache/cache_vcl.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ struct vdire {
4747
struct vcldir_head resigning;
4848
// vcl_mtx for now - to be refactored into separate mtx?
4949
struct lock *mtx;
50+
// to signal when iterators can enter again
51+
pthread_cond_t cond;
5052
const struct vcltemp **tempp;
5153
};
5254

0 commit comments

Comments
 (0)