Skip to content

Commit

Permalink
vdire: Wait for directors to retire before staring a new iteration
Browse files Browse the repository at this point in the history
This is to prevent a potential pileup of resigned directors with a constant
stream of iterators coming on
  • Loading branch information
nigoroll committed Oct 28, 2024
1 parent 375895a commit 41c42a0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
5 changes: 5 additions & 0 deletions bin/varnishd/cache/cache_vcl.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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);
}
Expand All @@ -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);

Expand Down Expand Up @@ -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);
}
Expand Down
2 changes: 2 additions & 0 deletions bin/varnishd/cache/cache_vcl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

Expand Down

0 comments on commit 41c42a0

Please sign in to comment.