Skip to content

Commit

Permalink
hash: Make HSH_Fail() rush the waiting list
Browse files Browse the repository at this point in the history
If the fetch task failed before reaching HSH_Unbusy() we make sure to
signal the waiting list immediately and not wait for the final objcore
reference to be dropped.

The OC_F_FAILED flag will prevent it from being looked up, so there is
no reason to delay the rush.
  • Loading branch information
dridi committed Jan 2, 2024
1 parent 3993923 commit 82c1d4d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
5 changes: 2 additions & 3 deletions bin/varnishd/cache/cache_fetch.c
Original file line number Diff line number Diff line change
Expand Up @@ -1043,9 +1043,8 @@ vbf_stp_fail(struct worker *wrk, struct busyobj *bo)
CHECK_OBJ_NOTNULL(oc, OBJCORE_MAGIC);

assert(oc->boc->state < BOS_FINISHED);
HSH_Fail(oc);
if (!(oc->flags & OC_F_BUSY))
HSH_Kill(oc);
HSH_Fail(wrk, oc);
HSH_Kill(oc);
ObjSetState(wrk, oc, BOS_FAILED);
return (F_STP_DONE);
}
Expand Down
10 changes: 9 additions & 1 deletion bin/varnishd/cache/cache_hash.c
Original file line number Diff line number Diff line change
Expand Up @@ -838,13 +838,16 @@ HSH_Purge(struct worker *wrk, struct objhead *oh, vtim_real ttl_now,
*/

void
HSH_Fail(struct objcore *oc)
HSH_Fail(struct worker *wrk, struct objcore *oc)
{
struct objhead *oh;
struct rush rush;

CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
CHECK_OBJ_NOTNULL(oc, OBJCORE_MAGIC);
oh = oc->objhead;
CHECK_OBJ(oh, OBJHEAD_MAGIC);
INIT_OBJ(&rush, RUSH_MAGIC);

/*
* We have to have either a busy bit, so that HSH_Lookup
Expand All @@ -854,8 +857,13 @@ HSH_Fail(struct objcore *oc)
assert((oc->flags & OC_F_BUSY) || (oc->stobj->stevedore != NULL));

Lck_Lock(&oh->mtx);
if (oc->flags & OC_F_BUSY) {
oc->flags &= ~OC_F_BUSY;
hsh_rush1(wrk, oc, &rush);
}
oc->flags |= OC_F_FAILED;
Lck_Unlock(&oh->mtx);
hsh_rush2(wrk, &rush);
}

/*---------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion bin/varnishd/cache/cache_objhead.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,11 @@ enum lookup_e {
HSH_BUSY,
};

void HSH_Fail(struct objcore *);
void HSH_Kill(struct objcore *);
void HSH_Insert(struct worker *, const void *hash, struct objcore *,
struct ban *);
void HSH_Unbusy(struct worker *, struct objcore *);
void HSH_Fail(struct worker *, struct objcore *);
int HSH_Snipe(const struct worker *, struct objcore *);
struct boc *HSH_RefBoc(const struct objcore *);
void HSH_DerefBoc(struct worker *wrk, struct objcore *);
Expand Down

0 comments on commit 82c1d4d

Please sign in to comment.