[master] 62e111b Tighten up the object fetch code a little bit.

Poul-Henning Kamp phk at varnish-cache.org
Thu Jan 27 11:44:22 CET 2011


commit 62e111bef71dae24a25530e16dd7953a16781309
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Thu Jan 27 08:40:13 2011 +0000

    Tighten up the object fetch code a little bit.

diff --git a/bin/varnishd/cache.h b/bin/varnishd/cache.h
index 115ccf7..78c33e7 100644
--- a/bin/varnishd/cache.h
+++ b/bin/varnishd/cache.h
@@ -631,7 +631,7 @@ int EXP_NukeOne(const struct sess *sp, const struct lru *lru);
 /* cache_fetch.c */
 struct storage *FetchStorage(const struct sess *sp, ssize_t sz);
 int FetchHdr(struct sess *sp);
-int FetchBody(struct sess *sp);
+int FetchBody(struct sess *sp, struct http *hp);
 int FetchReqBody(struct sess *sp);
 void Fetch_Init(void);
 
diff --git a/bin/varnishd/cache_center.c b/bin/varnishd/cache_center.c
index 16d1a7e..82df85d 100644
--- a/bin/varnishd/cache_center.c
+++ b/bin/varnishd/cache_center.c
@@ -573,22 +573,11 @@ cnt_fetch(struct sess *sp)
 	 * had one.
 	 */
 
-	if (sp->wrk->cacheable) {
-		CHECK_OBJ_NOTNULL(sp->objcore, OBJCORE_MAGIC);
-		vary = VRY_Create(sp, sp->wrk->beresp);
-		if (vary != NULL) {
-			varyl = vsb_len(vary);
-			assert(varyl > 0);
-		}
-	} else {
-		AZ(sp->objcore);
-	}
-
 	AZ(sp->wrk->vfp);
 
 	/*
 	 * The VCL variables beresp.do_g[un]zip tells us how we want the
-	 * object stored.
+	 * object processed before it is stored.
 	 *
 	 * The backend Content-Encoding header tells us what we are going
 	 * to receive, which we classify in the following three classes:
@@ -645,8 +634,16 @@ cnt_fetch(struct sess *sp)
 	l = http_EstimateWS(sp->wrk->beresp,
 	    sp->pass ? HTTPH_R_PASS : HTTPH_A_INS, &nhttp);
 
-	if (vary != NULL)
-		l += varyl;
+	/* Create Vary instructions */
+	if (sp->wrk->cacheable) {
+		CHECK_OBJ_NOTNULL(sp->objcore, OBJCORE_MAGIC);
+		vary = VRY_Create(sp, sp->wrk->beresp);
+		if (vary != NULL) {
+			varyl = vsb_len(vary);
+			assert(varyl > 0);
+			l += varyl;
+		}
+	}
 
 	/*
 	 * Space for producing a Content-Length: header including padding
@@ -654,10 +651,6 @@ cnt_fetch(struct sess *sp)
 	 */
 	l += strlen("Content-Encoding: XxxXxxXxxXxxXxxXxx" + sizeof(void *));
 
-	/*
-	 * XXX: VFP's may affect estimate
-	 */
-
 	sp->obj = STV_NewObject(sp, sp->wrk->storage_hint, l,
 	    sp->wrk->ttl, nhttp);
 	CHECK_OBJ_NOTNULL(sp->obj, OBJECT_MAGIC);
@@ -700,7 +693,13 @@ cnt_fetch(struct sess *sp)
 	else
 		sp->obj->last_modified = sp->wrk->entered;
 
-	i = FetchBody(sp);
+
+	/* Use unmodified headers*/
+	i = FetchBody(sp, sp->wrk->beresp1);
+
+	sp->wrk->bereq = NULL;
+	sp->wrk->beresp = NULL;
+	sp->wrk->beresp1 = NULL;
 	sp->wrk->vfp = NULL;
 	AZ(sp->wrk->wfd);
 	AZ(sp->vbc);
@@ -709,9 +708,6 @@ cnt_fetch(struct sess *sp)
 	if (i) {
 		HSH_Drop(sp);
 		AZ(sp->obj);
-		sp->wrk->bereq = NULL;
-		sp->wrk->beresp = NULL;
-		sp->wrk->beresp1 = NULL;
 		sp->err_code = 503;
 		sp->step = STP_ERROR;
 		return (0);
@@ -722,9 +718,6 @@ cnt_fetch(struct sess *sp)
 		HSH_Drop(sp);
 		sp->director = NULL;
 		sp->restarts++;
-		sp->wrk->bereq = NULL;
-		sp->wrk->beresp = NULL;
-		sp->wrk->beresp1 = NULL;
 		sp->step = STP_RECV;
 		return (0);
 	case VCL_RET_PASS:
@@ -737,9 +730,6 @@ cnt_fetch(struct sess *sp)
 		break;
 	case VCL_RET_ERROR:
 		HSH_Drop(sp);
-		sp->wrk->bereq = NULL;
-		sp->wrk->beresp = NULL;
-		sp->wrk->beresp1 = NULL;
 		sp->step = STP_ERROR;
 		return (0);
 	default:
@@ -754,9 +744,6 @@ cnt_fetch(struct sess *sp)
 		HSH_Unbusy(sp);
 	}
 	sp->acct_tmp.fetch++;
-	sp->wrk->bereq = NULL;
-	sp->wrk->beresp = NULL;
-	sp->wrk->beresp1 = NULL;
 	sp->step = STP_DELIVER;
 	return (0);
 }
diff --git a/bin/varnishd/cache_fetch.c b/bin/varnishd/cache_fetch.c
index 22cce8c..a1db19f 100644
--- a/bin/varnishd/cache_fetch.c
+++ b/bin/varnishd/cache_fetch.c
@@ -481,11 +481,10 @@ FetchHdr(struct sess *sp)
 /*--------------------------------------------------------------------*/
 
 int
-FetchBody(struct sess *sp)
+FetchBody(struct sess *sp, struct http *hp)
 {
 	char *b;
 	int cls;
-	struct http *hp;
 	struct storage *st;
 	int mklen;
 
@@ -497,8 +496,6 @@ FetchBody(struct sess *sp)
 	if (sp->wrk->vfp == NULL)
 		sp->wrk->vfp = &vfp_nop;
 
-	/* We use the unmodified headers */
-	hp = sp->wrk->beresp1;
 	AN(sp->director);
 	AssertObjPassOrBusy(sp->obj);
 



More information about the varnish-commit mailing list