From b7507f9421333cb51eaa0b8445116b282f186852 Mon Sep 17 00:00:00 2001 From: Dridi Boukelmoune Date: Wed, 10 Jan 2024 14:11:19 +0100 Subject: [PATCH] hash: New HSH_Replace() function --- bin/varnishd/cache/cache_fetch.c | 2 +- bin/varnishd/cache/cache_hash.c | 13 ++++++++++++- bin/varnishd/cache/cache_objhead.h | 1 + bin/varnishtest/tests/b00039.vtc | 2 ++ 4 files changed, 16 insertions(+), 2 deletions(-) diff --git a/bin/varnishd/cache/cache_fetch.c b/bin/varnishd/cache/cache_fetch.c index c6c26ada0f7..f49de59cf71 100644 --- a/bin/varnishd/cache/cache_fetch.c +++ b/bin/varnishd/cache/cache_fetch.c @@ -756,7 +756,7 @@ vbf_stp_fetchend(struct worker *wrk, struct busyobj *bo) VSL(SLT_ExpKill, NO_VXID, "VBF_Superseded x=%ju n=%ju", VXID(ObjGetXID(wrk, bo->stale_oc)), VXID(ObjGetXID(wrk, bo->fetch_objcore))); - HSH_Kill(bo->stale_oc); + HSH_Replace(bo->stale_oc, bo->fetch_objcore); } return (F_STP_DONE); } diff --git a/bin/varnishd/cache/cache_hash.c b/bin/varnishd/cache/cache_hash.c index 2cde338687f..ce31aecf09f 100644 --- a/bin/varnishd/cache/cache_hash.c +++ b/bin/varnishd/cache/cache_hash.c @@ -911,15 +911,26 @@ HSH_Unbusy(struct worker *wrk, struct objcore *oc) void HSH_Kill(struct objcore *oc) +{ + + HSH_Replace(oc, NULL); +} + +void +HSH_Replace(struct objcore *oc, const struct objcore *new_oc) { CHECK_OBJ_NOTNULL(oc, OBJCORE_MAGIC); CHECK_OBJ_NOTNULL(oc->objhead, OBJHEAD_MAGIC); + if (new_oc != NULL) { + CHECK_OBJ(new_oc, OBJCORE_MAGIC); + assert(oc->objhead == new_oc->objhead); + } Lck_Lock(&oc->objhead->mtx); oc->flags |= OC_F_DYING; Lck_Unlock(&oc->objhead->mtx); - EXP_Remove(oc, NULL); + EXP_Remove(oc, new_oc); } /*==================================================================== diff --git a/bin/varnishd/cache/cache_objhead.h b/bin/varnishd/cache/cache_objhead.h index 58b53650294..2edfb5a883b 100644 --- a/bin/varnishd/cache/cache_objhead.h +++ b/bin/varnishd/cache/cache_objhead.h @@ -67,6 +67,7 @@ enum lookup_e { void HSH_Fail(struct objcore *); void HSH_Kill(struct objcore *); +void HSH_Replace(struct objcore *, const struct objcore *); void HSH_Insert(struct worker *, const void *hash, struct objcore *, struct ban *); void HSH_Unbusy(struct worker *, struct objcore *); diff --git a/bin/varnishtest/tests/b00039.vtc b/bin/varnishtest/tests/b00039.vtc index 3a316c3a8a5..49afa455061 100644 --- a/bin/varnishtest/tests/b00039.vtc +++ b/bin/varnishtest/tests/b00039.vtc @@ -67,3 +67,5 @@ client c1 { } -run logexpect l1 -wait + +varnish v1 -expect MAIN.n_superseded == 2