[master] 241be56b9 expire: New MAIN.n_superseded counter

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


commit 241be56b946e5aab532994d542ac82757e319a25
Author: Dridi Boukelmoune <dridi.boukelmoune at gmail.com>
Date:   Wed Jan 10 14:00:06 2024 +0100

    expire: New MAIN.n_superseded counter

diff --git a/bin/varnishd/cache/cache_expire.c b/bin/varnishd/cache/cache_expire.c
index 60aafb098..fb823e3cc 100644
--- a/bin/varnishd/cache/cache_expire.c
+++ b/bin/varnishd/cache/cache_expire.c
@@ -149,12 +149,16 @@ EXP_RefNewObjcore(struct objcore *oc)
  */
 
 void
-EXP_Remove(struct objcore *oc)
+EXP_Remove(struct objcore *oc, const struct objcore *new_oc)
 {
 
 	CHECK_OBJ_NOTNULL(oc, OBJCORE_MAGIC);
+	CHECK_OBJ_ORNULL(new_oc, OBJCORE_MAGIC);
+
 	if (oc->exp_flags & OC_EF_REFD) {
 		Lck_Lock(&exphdl->mtx);
+		if (new_oc != NULL)
+			VSC_C_main->n_superseded++;
 		if (oc->exp_flags & OC_EF_NEW) {
 			/* EXP_Insert has not been called for this object
 			 * yet. Mark it for removal, and EXP_Insert will
diff --git a/bin/varnishd/cache/cache_hash.c b/bin/varnishd/cache/cache_hash.c
index 6d982ddec..2cde33868 100644
--- a/bin/varnishd/cache/cache_hash.c
+++ b/bin/varnishd/cache/cache_hash.c
@@ -453,7 +453,7 @@ HSH_Lookup(struct req *req, struct objcore **ocp, struct objcore **bocp)
 
 		if (BAN_CheckObject(wrk, oc, req)) {
 			oc->flags |= OC_F_DYING;
-			EXP_Remove(oc);
+			EXP_Remove(oc, NULL);
 			continue;
 		}
 
@@ -743,7 +743,7 @@ 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);
 			if (is_purge)
-				EXP_Remove(ocp[i]);
+				EXP_Remove(ocp[i], NULL);
 			else
 				EXP_Rearm(ocp[i], ttl_now, ttl, grace, keep);
 			(void)HSH_DerefObjCore(wrk, &ocp[i], 0);
@@ -919,7 +919,7 @@ HSH_Kill(struct objcore *oc)
 	Lck_Lock(&oc->objhead->mtx);
 	oc->flags |= OC_F_DYING;
 	Lck_Unlock(&oc->objhead->mtx);
-	EXP_Remove(oc);
+	EXP_Remove(oc, NULL);
 }
 
 /*====================================================================
@@ -946,7 +946,7 @@ HSH_Snipe(const struct worker *wrk, struct objcore *oc)
 		Lck_Unlock(&oc->objhead->mtx);
 	}
 	if (retval)
-		EXP_Remove(oc);
+		EXP_Remove(oc, NULL);
 	return (retval);
 }
 
diff --git a/bin/varnishd/cache/cache_varnishd.h b/bin/varnishd/cache/cache_varnishd.h
index 019b426dc..a73ff7170 100644
--- a/bin/varnishd/cache/cache_varnishd.h
+++ b/bin/varnishd/cache/cache_varnishd.h
@@ -207,7 +207,7 @@ vtim_real EXP_Ttl(const struct req *, const struct objcore *);
 vtim_real EXP_Ttl_grace(const struct req *, const struct objcore *oc);
 void EXP_RefNewObjcore(struct objcore *);
 void EXP_Insert(struct worker *wrk, struct objcore *oc);
-void EXP_Remove(struct objcore *);
+void EXP_Remove(struct objcore *, const struct objcore *);
 
 #define EXP_Dttl(req, oc) (oc->ttl - (req->t_req - oc->t_origin))
 
diff --git a/lib/libvsc/VSC_main.vsc b/lib/libvsc/VSC_main.vsc
index 14f3e266f..82542a4c5 100644
--- a/lib/libvsc/VSC_main.vsc
+++ b/lib/libvsc/VSC_main.vsc
@@ -397,6 +397,12 @@
 
 	Number of objects that expired from cache because of old age.
 
+.. varnish_vsc:: n_superseded
+	:level:	diag
+	:oneliner:	Number of superseded objects
+
+	Number of times an object was superseded by a new one.
+
 .. varnish_vsc:: n_lru_nuked
 	:oneliner:	Number of LRU nuked objects
 


More information about the varnish-commit mailing list