[3.0] 8f451fa Move request vary string from wrk to sess

Tollef Fog Heen tfheen at varnish-cache.org
Wed Aug 17 11:25:28 CEST 2011


commit 8f451fa73c3fee45f4c20531541cefc31571756f
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Wed Jun 22 10:39:47 2011 +0000

    Move request vary string from wrk to sess

diff --git a/bin/varnishd/cache.h b/bin/varnishd/cache.h
index 22fa5ff..1d3db55 100644
--- a/bin/varnishd/cache.h
+++ b/bin/varnishd/cache.h
@@ -300,9 +300,6 @@ struct worker {
 
 	/* Lookup stuff */
 	struct SHA256Context	*sha256ctx;
-	uint8_t			*vary_b;
-	uint8_t			*vary_l;
-	uint8_t			*vary_e;
 
 	struct http_conn	htc[1];
 	struct ws		ws[1];
@@ -554,6 +551,11 @@ struct sess {
 
 	unsigned char		digest[DIGEST_LEN];
 
+	/* Built Vary string */
+	uint8_t			*vary_b;
+	uint8_t			*vary_l;
+	uint8_t			*vary_e;
+
 	struct http_conn	htc[1];
 
 	/* Timestamps, all on TIM_real() timescale */
@@ -884,7 +886,7 @@ void RES_StreamPoll(const struct sess *sp);
 
 /* cache_vary.c */
 struct vsb *VRY_Create(const struct sess *sp, const struct http *hp);
-int VRY_Match(const struct sess *sp, const uint8_t *vary);
+int VRY_Match(struct sess *sp, const uint8_t *vary);
 
 /* cache_vcl.c */
 void VCL_Init(void);
diff --git a/bin/varnishd/cache_center.c b/bin/varnishd/cache_center.c
index 5b55d58..23ad92f 100644
--- a/bin/varnishd/cache_center.c
+++ b/bin/varnishd/cache_center.c
@@ -1028,28 +1028,23 @@ cnt_lookup(struct sess *sp)
 	struct objcore *oc;
 	struct object *o;
 	struct objhead *oh;
-	struct worker *wrk;
 
 	CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
 	CHECK_OBJ_NOTNULL(sp->vcl, VCL_CONF_MAGIC);
 
-
-	wrk = sp->wrk;
-	AZ(wrk->vary_b);
-	AZ(wrk->vary_l);
-	AZ(wrk->vary_e);
-	(void)WS_Reserve(wrk->ws, 0);
-	wrk->vary_b = (void*)wrk->ws->f;
-	wrk->vary_e = (void*)wrk->ws->r;
-	wrk->vary_b[2] = '\0';
+	if (sp->hash_objhead == NULL) {
+		/* Not a waiting list return */
+		AZ(sp->vary_b);
+		AZ(sp->vary_l);
+		AZ(sp->vary_e);
+		(void)WS_Reserve(sp->ws, 0);
+		sp->vary_b = (void*)sp->ws->f;
+		sp->vary_e = (void*)sp->ws->r;
+		sp->vary_b[2] = '\0';
+	}
 
 	oc = HSH_Lookup(sp, &oh);
 
-	WS_Release(wrk->ws, 0);
-	wrk->vary_b = NULL;
-	wrk->vary_l = NULL;
-	wrk->vary_e = NULL;
-
 	if (oc == NULL) {
 		/*
 		 * We lost the session to a busy object, disembark the
@@ -1060,6 +1055,7 @@ cnt_lookup(struct sess *sp)
 		return (1);
 	}
 
+
 	CHECK_OBJ_NOTNULL(oc, OBJCORE_MAGIC);
 	CHECK_OBJ_NOTNULL(oh, OBJHEAD_MAGIC);
 
@@ -1067,6 +1063,14 @@ cnt_lookup(struct sess *sp)
 	if (oc->flags & OC_F_BUSY) {
 		sp->wrk->stats.cache_miss++;
 
+		if (sp->vary_l != NULL)
+			WS_ReleaseP(sp->ws, (void*)sp->vary_l);
+		else
+			WS_Release(sp->ws, 0);
+		sp->vary_b = NULL;
+		sp->vary_l = NULL;
+		sp->vary_e = NULL;
+
 		sp->objcore = oc;
 		sp->step = STP_MISS;
 		return (0);
@@ -1076,6 +1080,11 @@ cnt_lookup(struct sess *sp)
 	CHECK_OBJ_NOTNULL(o, OBJECT_MAGIC);
 	sp->obj = o;
 
+	WS_Release(sp->ws, 0);
+	sp->vary_b = NULL;
+	sp->vary_l = NULL;
+	sp->vary_e = NULL;
+
 	if (oc->flags & OC_F_PASS) {
 		sp->wrk->stats.cache_hitpass++;
 		WSP(sp, SLT_HitPass, "%u", sp->obj->xid);
diff --git a/bin/varnishd/cache_vary.c b/bin/varnishd/cache_vary.c
index 01816f6..89e1675 100644
--- a/bin/varnishd/cache_vary.c
+++ b/bin/varnishd/cache_vary.c
@@ -176,9 +176,9 @@ vry_cmp(const uint8_t * const *v1, uint8_t * const *v2)
 }
 
 int
-VRY_Match(const struct sess *sp, const uint8_t *vary)
+VRY_Match(struct sess *sp, const uint8_t *vary)
 {
-	uint8_t *vsp = sp->wrk->vary_b;
+	uint8_t *vsp = sp->vary_b;
 	char *h, *e;
 	unsigned lh, ln;
 	int i, retval = 1, oflo = 0;
@@ -204,8 +204,8 @@ VRY_Match(const struct sess *sp, const uint8_t *vary)
 
 			/* Length of the entire new vary entry */
 			ln = 2 + vary[2] + 2 + (lh == 0xffff ? 0 : lh);
-			if (vsp + ln >= sp->wrk->vary_e) {
-				vsp = sp->wrk->vary_b;
+			if (vsp + ln >= sp->vary_e) {
+				vsp = sp->vary_b;
 				oflo = 1;
 			}
 
@@ -213,7 +213,7 @@ VRY_Match(const struct sess *sp, const uint8_t *vary)
 			 * We MUST have space for one entry and the end marker
 			 * after it, which prevents old junk from confusing us
 			 */
-			assert(vsp + ln + 2 < sp->wrk->vary_e);
+			assert(vsp + ln + 2 < sp->vary_e);
 
 			vbe16enc(vsp, (uint16_t)lh);
 			memcpy(vsp + 2, vary + 2, vary[2] + 2);
@@ -231,19 +231,19 @@ VRY_Match(const struct sess *sp, const uint8_t *vary)
 		vsp += vry_len(vsp);
 		vary += vry_len(vary);
 	}
-	if (vsp + 3 > sp->wrk->vary_e)
+	if (vsp + 3 > sp->vary_e)
 		oflo = 1;
 
 	if (oflo) {
 		/* XXX: Should log this */
-		vsp = sp->wrk->vary_b;
+		vsp = sp->vary_b;
 	}
 	vsp[0] = 0xff;
 	vsp[1] = 0xff;
 	vsp[2] = 0;
 	if (oflo) 
-		sp->wrk->vary_l = NULL;
+		sp->vary_l = NULL;
 	else
-		sp->wrk->vary_l = vsp + 3;
+		sp->vary_l = vsp + 3;
 	return (retval);
 }



More information about the varnish-commit mailing list