Permalink
Browse files

Simplify HSH_Lookup 2/N

Refactor the hit-cases

Inspired by:	#2856
  • Loading branch information...
bsdphk committed Dec 4, 2018
1 parent f29d204 commit 6567393d1396738e32fc93a5fa2905d1ed2fef55
Showing with 19 additions and 33 deletions.
  1. +19 −33 bin/varnishd/cache/cache_hash.c
@@ -452,53 +452,39 @@ HSH_Lookup(struct req *req, struct objcore **ocp, struct objcore **bocp,
}
}
if (oc != NULL && oc->flags & OC_F_HFP) {
xid = ObjGetXID(wrk, oc);
dttl = EXP_Dttl(req, oc);
AN(hsh_deref_objhead_unlock(wrk, &oh));
wrk->stats->cache_hitpass++;
VSLb(req->vsl, SLT_HitPass, "%u %.6f", xid, dttl);
return (HSH_HITPASS);
}
if (oc != NULL) {
if (oc->flags & OC_F_HFP) {
xid = ObjGetXID(wrk, oc);
dttl = EXP_Dttl(req, oc);
oc = NULL;
retval = HSH_HITPASS;
} else if (oc->flags & OC_F_HFM) {
*ocp = oc;
oc->refcnt++;
if (oc->flags & OC_F_HFM) {
xid = ObjGetXID(wrk, oc);
dttl = EXP_Dttl(req, oc);
*bocp = hsh_insert_busyobj(wrk, oh);
oc->refcnt++;
retval = HSH_HITMISS;
} else {
oc->refcnt++;
if (oc->hits < LONG_MAX)
oc->hits++;
retval = HSH_HIT;
}
*ocp = oc;
if (*bocp == NULL)
AN(hsh_deref_objhead_unlock(wrk, &oh));
else
Lck_Unlock(&oh->mtx);
switch (retval) {
case HSH_HITPASS:
wrk->stats->cache_hitpass++;
VSLb(req->vsl, SLT_HitPass, "%u %.6f", xid, dttl);
break;
case HSH_HITMISS:
wrk->stats->cache_hitmiss++;
VSLb(req->vsl, SLT_HitMiss, "%u %.6f", xid, dttl);
break;
case HSH_HIT:
break;
default:
INCOMPL();
}
return (retval);
return (HSH_HITMISS);
}
if (oc->hits < LONG_MAX)
oc->hits++;
AN(hsh_deref_objhead_unlock(wrk, &oh));
return (HSH_HIT);
}
if (exp_oc != NULL && exp_oc->flags & OC_F_HFM) {
/*
* expired HFM ("grace/keep HFM")
*
* XXX should HFM objects actually have grace/keep ?
* XXX also: why isn't *ocp = exp_oc ?
*/
xid = ObjGetXID(wrk, exp_oc);
dttl = EXP_Dttl(req, exp_oc);

0 comments on commit 6567393

Please sign in to comment.