[master] 709f71ab7 hash: A purged object didn't get a chance to expire

Dridi Boukelmoune dridi.boukelmoune at gmail.com
Fri Jan 26 16:55:08 UTC 2024


commit 709f71ab731298fa4d30d4c8b2b61dae04002ea6
Author: Dridi Boukelmoune <dridi.boukelmoune at gmail.com>
Date:   Thu Jan 11 17:40:52 2024 +0100

    hash: A purged object didn't get a chance to expire
    
    So the n_expired, n_purges and n_obj_purged counters should reflect
    that. Likewise, it shouldn't be logged as "EXP_Expired".

diff --git a/bin/varnishd/cache/cache_hash.c b/bin/varnishd/cache/cache_hash.c
index 4b3799888..6d982ddec 100644
--- a/bin/varnishd/cache/cache_hash.c
+++ b/bin/varnishd/cache/cache_hash.c
@@ -674,10 +674,12 @@ HSH_Purge(struct worker *wrk, struct objhead *oh, vtim_real ttl_now,
 {
 	struct objcore *oc, *oc_nows[2], **ocp;
 	unsigned i, j, n, n_max, total = 0;
+	int is_purge;
 
 	CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
 	CHECK_OBJ_NOTNULL(oh, OBJHEAD_MAGIC);
 
+	is_purge = (ttl == 0 && grace == 0 && keep == 0);
 	n_max = WS_ReserveLumps(wrk->aws, sizeof *ocp);
 	if (n_max < 2) {
 		/* No space on the workspace. Give it a stack buffer of 2
@@ -740,7 +742,10 @@ HSH_Purge(struct worker *wrk, struct objhead *oh, vtim_real ttl_now,
 		}
 		for (i = 0; i < j; i++) {
 			CHECK_OBJ_NOTNULL(ocp[i], OBJCORE_MAGIC);
-			EXP_Rearm(ocp[i], ttl_now, ttl, grace, keep);
+			if (is_purge)
+				EXP_Remove(ocp[i]);
+			else
+				EXP_Rearm(ocp[i], ttl_now, ttl, grace, keep);
 			(void)HSH_DerefObjCore(wrk, &ocp[i], 0);
 			AZ(ocp[i]);
 			total++;
@@ -765,7 +770,8 @@ HSH_Purge(struct worker *wrk, struct objhead *oh, vtim_real ttl_now,
 	}
 
 	WS_Release(wrk->aws, 0);
-	Pool_PurgeStat(total);
+	if (is_purge)
+		Pool_PurgeStat(total);
 	return (total);
 }
 
diff --git a/bin/varnishtest/tests/b00036.vtc b/bin/varnishtest/tests/b00036.vtc
index 97902ecb2..fc1ad0519 100644
--- a/bin/varnishtest/tests/b00036.vtc
+++ b/bin/varnishtest/tests/b00036.vtc
@@ -33,3 +33,11 @@ client c1 {
 	expect resp.http.foo == 2
 
 } -run
+
+varnish v1 -vsl_catchup
+
+varnish v1 -expect MAIN.n_purges == 1
+varnish v1 -expect MAIN.n_obj_purged == 1
+
+# NB: a purge used to increase n_expired
+varnish v1 -expect MAIN.n_expired == 0
diff --git a/bin/varnishtest/tests/r02339.vtc b/bin/varnishtest/tests/r02339.vtc
index a19c22ce7..9ff18632d 100644
--- a/bin/varnishtest/tests/r02339.vtc
+++ b/bin/varnishtest/tests/r02339.vtc
@@ -21,7 +21,7 @@ varnish v1 -vcl+backend {
 varnish v1 -cliok "param.set timeout_idle 2"
 
 logexpect l0 -v v1 -g raw {
-	expect * 0 ExpKill	"EXP_Expired x=1002"
+	expect * 0 ExpKill	"EXP_Removed x=1002"
 } -start
 
 logexpect l2 -v v1 -g raw {


More information about the varnish-commit mailing list