[master] b7507f942 hash: New HSH_Replace() function

Dridi Boukelmoune dridi.boukelmoune at gmail.com
Fri Mar 1 18:56:06 UTC 2024


commit b7507f9421333cb51eaa0b8445116b282f186852
Author: Dridi Boukelmoune <dridi.boukelmoune at gmail.com>
Date:   Wed Jan 10 14:11:19 2024 +0100

    hash: New HSH_Replace() function

diff --git a/bin/varnishd/cache/cache_fetch.c b/bin/varnishd/cache/cache_fetch.c
index c6c26ada0..f49de59cf 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 2cde33868..ce31aecf0 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 58b536502..2edfb5a88 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 3a316c3a8..49afa4550 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


More information about the varnish-commit mailing list