[6.0] 5ee0e2573 Simplify HSH_Lookup 2/N
Dridi Boukelmoune
dridi.boukelmoune at gmail.com
Fri Feb 8 13:13:10 UTC 2019
commit 5ee0e2573a77c1508faf0dccf2d6432c7d3aa561
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Tue Dec 4 22:02:05 2018 +0000
Simplify HSH_Lookup 2/N
Refactor the hit-cases
Inspired by: #2856
diff --git a/bin/varnishd/cache/cache_hash.c b/bin/varnishd/cache/cache_hash.c
index 15c8fe8bb..c5f5d3c7d 100644
--- a/bin/varnishd/cache/cache_hash.c
+++ b/bin/varnishd/cache/cache_hash.c
@@ -452,46 +452,31 @@ 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) {
@@ -499,6 +484,7 @@ HSH_Lookup(struct req *req, struct objcore **ocp, struct objcore **bocp,
* 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);
More information about the varnish-commit
mailing list