[4.0] 01b4e4a Move obj.hits to struct objcore. This gives us a separate hits counter per object, in line with the functionality as it was in Varnish 3.0.

Lasse Karstensen lkarsten at varnish-software.com
Thu Jan 15 16:35:41 CET 2015


commit 01b4e4a4d3a674f76fc0c38c1dd8e7485999cff6
Author: Dag Haavi Finstad <daghf at varnish-software.com>
Date:   Mon Oct 27 14:31:08 2014 +0100

    Move obj.hits to struct objcore. This gives us a separate hits counter
    per object, in line with the functionality as it was in Varnish 3.0.
    
    Conflicts:
    	bin/varnishd/cache/cache_vrt_var.c

diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h
index 04debc8..6aca502 100644
--- a/bin/varnishd/cache/cache.h
+++ b/bin/varnishd/cache/cache.h
@@ -425,6 +425,7 @@ struct objcore {
 	struct objhead		*objhead;
 	struct busyobj		*busyobj;
 	double			timer_when;
+	long			hits;
 
 	uint16_t		flags;
 #define OC_F_BUSY		(1<<1)
diff --git a/bin/varnishd/cache/cache_hash.c b/bin/varnishd/cache/cache_hash.c
index 47f346f..59e6d94 100644
--- a/bin/varnishd/cache/cache_hash.c
+++ b/bin/varnishd/cache/cache_hash.c
@@ -435,8 +435,8 @@ HSH_Lookup(struct req *req, struct objcore **ocp, struct objcore **bocp,
 			assert(oh->refcnt > 1);
 			assert(oc->objhead == oh);
 			oc->refcnt++;
-			if (oh->hits < LONG_MAX)
-				oh->hits++;
+			if (oc->hits < LONG_MAX)
+				oc->hits++;
 			Lck_Unlock(&oh->mtx);
 			assert(HSH_DerefObjHead(&wrk->stats, &oh));
 			*ocp = oc;
@@ -464,8 +464,8 @@ HSH_Lookup(struct req *req, struct objcore **ocp, struct objcore **bocp,
 			AZ(req->hash_ignore_busy);
 			retval = HSH_EXP;
 		}
-		if (oh->hits < LONG_MAX)
-			oh->hits++;
+		if (exp_oc->hits < LONG_MAX)
+			exp_oc->hits++;
 		Lck_Unlock(&oh->mtx);
 		if (retval == HSH_EXP)
 			assert(HSH_DerefObjHead(&wrk->stats, &oh));
diff --git a/bin/varnishd/cache/cache_vrt_var.c b/bin/varnishd/cache/cache_vrt_var.c
index 7cfe163..a5f0bde 100644
--- a/bin/varnishd/cache/cache_vrt_var.c
+++ b/bin/varnishd/cache/cache_vrt_var.c
@@ -581,8 +581,7 @@ VRT_r_obj_hits(const struct vrt_ctx *ctx)
 	CHECK_OBJ_NOTNULL(ctx->req, REQ_MAGIC);
 	CHECK_OBJ_NOTNULL(ctx->req->obj, OBJECT_MAGIC);
 	CHECK_OBJ_NOTNULL(ctx->req->obj->objcore, OBJCORE_MAGIC);
-	CHECK_OBJ_NOTNULL(ctx->req->obj->objcore->objhead, OBJHEAD_MAGIC);
-	return (ctx->req->obj->objcore->objhead->hits);
+	return (ctx->req->obj->objcore->hits);
 }
 
 unsigned
diff --git a/bin/varnishd/hash/hash_slinger.h b/bin/varnishd/hash/hash_slinger.h
index 3c6f815..0afdb93 100644
--- a/bin/varnishd/hash/hash_slinger.h
+++ b/bin/varnishd/hash/hash_slinger.h
@@ -95,8 +95,6 @@ struct objhead {
 	uint8_t			digest[DIGEST_LEN];
 	struct waitinglist	*waitinglist;
 
-	long			hits;
-
 	/*----------------------------------------------------
 	 * The fields below are for the sole private use of
 	 * the hash implementation(s).
diff --git a/bin/varnishtest/tests/v00039.vtc b/bin/varnishtest/tests/v00039.vtc
index 90bc865..029e114 100644
--- a/bin/varnishtest/tests/v00039.vtc
+++ b/bin/varnishtest/tests/v00039.vtc
@@ -31,19 +31,19 @@ client c1 {
 	expect resp.bodylen == 6
 	expect resp.http.hits == 1
 
-	# This is a miss on different vary -> hits still == 1
+	# This is a miss on different vary -> hits == 0
 	txreq -url "/" -hdr "Bar: 2"
 	rxresp
 	expect resp.status == 200
 	expect resp.bodylen == 4
-	expect resp.http.hits == 1
+	expect resp.http.hits == 0
 
-	# This is a hit -> hits == 2
+	# This is a hit -> hits == 1
 	txreq -url "/" -hdr "Bar: 2"
 	rxresp
 	expect resp.status == 200
 	expect resp.bodylen == 4
-	expect resp.http.hits == 2
+	expect resp.http.hits == 1
 
 } -run
 
diff --git a/lib/libvcc/generate.py b/lib/libvcc/generate.py
index f9e1836..372ef1c 100755
--- a/lib/libvcc/generate.py
+++ b/lib/libvcc/generate.py
@@ -548,13 +548,9 @@ sp_variables = [
 		'INT',
 		( 'hit', 'deliver',),
 		( ), """
-		The count of cache-hits on this hash-key since it was
-		last instantiated.  This counts cache-hits across all
-		Vary:-ants on this hash-key.
-		The counter will only be reset to zero if/when all objects
-		with this hash-key have disappeared from cache.
-		NB: obj.hits == 0 does *not* indicate a cache miss.
-		"""
+                The count of cache-hits on this object. A value of 0 indicates a
+		cache miss.
+                """
 	),
 	('obj.http.',
 		'HEADER',



More information about the varnish-commit mailing list