[master] 0ad1299 Now that we can retry fetches, we have to keep things straight:

Poul-Henning Kamp phk at varnish-cache.org
Wed Jul 3 14:23:50 CEST 2013


commit 0ad12998f4af74509f04a0901918d3f224ea4007
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Wed Jul 3 12:22:23 2013 +0000

    Now that we can retry fetches, we have to keep things straight:
    
    bereq.uncacheable is our *intention* to pass
    
    beresp.uncacheable is the *consequence* if we pass.
    
    This way it is possible to fetch as miss first time, and try for
    a pass on retry.

diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h
index f08feeb..afef220 100644
--- a/bin/varnishd/cache/cache.h
+++ b/bin/varnishd/cache/cache.h
@@ -543,7 +543,10 @@ struct busyobj {
 	unsigned		do_gzip;
 	unsigned		do_gunzip;
 	unsigned		do_stream;
+
+	/* do_pass is our intent, uncacheable is the result */
 	unsigned		do_pass;
+	unsigned		uncacheable;
 
 	/* Timeouts */
 	double			connect_timeout;
diff --git a/bin/varnishd/cache/cache_fetch.c b/bin/varnishd/cache/cache_fetch.c
index fe12452..3488954 100644
--- a/bin/varnishd/cache/cache_fetch.c
+++ b/bin/varnishd/cache/cache_fetch.c
@@ -54,7 +54,7 @@ vbf_release_req(struct req ***reqpp)
 }
 
 /*--------------------------------------------------------------------
- * Copy req->bereq and run it by VCL::vcl_backend_fetch{}
+ * Copy req->bereq
  */
 
 static enum fetch_step
@@ -92,13 +92,12 @@ vbf_stp_mkbereq(const struct worker *wrk, struct busyobj *bo,
 }
 
 /*--------------------------------------------------------------------
- * Copy req->bereq and run it by VCL::vcl_backend_fetch{}
+ * Copy run bereq by VCL::vcl_backend_fetch{}
  */
 
 static enum fetch_step
 vbf_stp_startfetch(struct worker *wrk, struct busyobj *bo)
 {
-	int i;
 
 	CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
 	CHECK_OBJ_NOTNULL(bo, BUSYOBJ_MAGIC);
@@ -111,10 +110,9 @@ vbf_stp_startfetch(struct worker *wrk, struct busyobj *bo)
 	HTTP_Setup(bo->bereq, bo->ws, bo->vsl, HTTP_Bereq);
 	HTTP_Copy(bo->bereq, bo->bereq0);
 
-	// Don't let VCL reset do_pass
-	i = bo->do_pass;
 	VCL_backend_fetch_method(bo->vcl, wrk, NULL, bo, bo->bereq->ws);
-	bo->do_pass |= i;
+
+	bo->uncacheable = bo->do_pass;
 
 	http_PrintfHeader(bo->bereq,
 	    "X-Varnish: %u", bo->vsl->wid & VSL_IDENTMASK);
@@ -199,10 +197,7 @@ vbf_stp_fetchhdr(struct worker *wrk, struct busyobj *bo, struct req ***reqpp)
 
 	AZ(bo->do_esi);
 
-	// Don't let VCL reset do_pass
-	i = bo->do_pass;
 	VCL_backend_response_method(bo->vcl, wrk, NULL, bo, bo->beresp->ws);
-	bo->do_pass |= i;
 
 	if (wrk->handling == VCL_RET_DELIVER)
 		return (F_STP_FETCH);
@@ -237,7 +232,7 @@ vbf_stp_fetch(struct worker *wrk, struct busyobj *bo)
 	CHECK_OBJ_NOTNULL(bo, BUSYOBJ_MAGIC);
 
 	assert(wrk->handling == VCL_RET_DELIVER);
-	if (bo->do_pass)
+	if (bo->uncacheable)
 		bo->fetch_objcore->flags |= OC_F_PASS;
 
 	/*
@@ -294,48 +289,15 @@ vbf_stp_fetch(struct worker *wrk, struct busyobj *bo)
 	else if (bo->is_gzip)
 		bo->vfp = &vfp_testgzip;
 
-
-#if 0
-	if (wrk->handling != VCL_RET_DELIVER)
-		VDI_CloseFd(&bo->vbc);
-
-	if (wrk->handling != VCL_RET_DELIVER) {
-		/* Clean up partial fetch */
-		AZ(bo->vbc);
-
-		if (bo->fetch_objcore->objhead != NULL ||
-		    wrk->handling == VCL_RET_RESTART ||
-		    wrk->handling == VCL_RET_ERROR) {
-			CHECK_OBJ_NOTNULL(bo->fetch_objcore, OBJCORE_MAGIC);
-			AZ(HSH_Deref(&wrk->stats, bo->fetch_objcore, NULL));
-			bo->fetch_objcore = NULL;
-		}
-		assert(bo->refcount == 2);
-		bo->storage_hint = NULL;
-		bo->director = NULL;
-
-		switch (wrk->handling) {
-		case VCL_RET_ERROR:
-			bo->state = BOS_FAILED;
-			VBO_DerefBusyObj(wrk, &bo);	// XXX ?
-			return (F_STP_DONE);
-		case VCL_RET_RESTART:
-			INCOMPL();
-		default:
-			WRONG("Illegal action in vcl_fetch{}");
-		}
-	}
-#endif
-
 	if (bo->fetch_objcore->objhead == NULL)
-		AN(bo->do_pass);
+		AN(bo->uncacheable);
 
 	/* No reason to try streaming a non-existing body */
 	if (bo->htc.body_status == BS_NONE)
 		bo->do_stream = 0;
 
 	l = http_EstimateWS(bo->beresp,
-	    bo->do_pass ? HTTPH_R_PASS : HTTPH_A_INS, &nhttp);
+	    bo->uncacheable ? HTTPH_R_PASS : HTTPH_A_INS, &nhttp);
 
 	/* Create Vary instructions */
 	if (bo->fetch_objcore->objhead != NULL) {
@@ -356,7 +318,7 @@ vbf_stp_fetch(struct worker *wrk, struct busyobj *bo)
 			AZ(vary);
 	}
 
-	if (bo->exp.ttl < cache_param->shortlived || bo->do_pass == 1)
+	if (bo->exp.ttl < cache_param->shortlived || bo->uncacheable == 1)
 		bo->storage_hint = TRANSIENT_STORAGE;
 
 	/*
@@ -413,7 +375,7 @@ vbf_stp_fetch(struct worker *wrk, struct busyobj *bo)
 	hp2 = obj->http;
 
 	hp2->logtag = HTTP_Obj;
-	http_FilterResp(hp, hp2, bo->do_pass ? HTTPH_R_PASS : HTTPH_A_INS);
+	http_FilterResp(hp, hp2, bo->uncacheable ? HTTPH_R_PASS : HTTPH_A_INS);
 	http_CopyHome(hp2);
 
 	if (http_GetHdr(hp, H_Last_Modified, &b))
diff --git a/bin/varnishd/cache/cache_vrt_var.c b/bin/varnishd/cache/cache_vrt_var.c
index 0491b30..1429602 100644
--- a/bin/varnishd/cache/cache_vrt_var.c
+++ b/bin/varnishd/cache/cache_vrt_var.c
@@ -144,8 +144,52 @@ VBERESP(beresp, unsigned, do_esi,	do_esi)
 VBERESP(beresp, unsigned, do_gzip,	do_gzip)
 VBERESP(beresp, unsigned, do_gunzip,	do_gunzip)
 VBERESP(beresp, unsigned, do_stream,	do_stream)
-VBERESP(beresp, unsigned, do_pass,	do_pass)
-VBERESP(beresp, unsigned, uncacheable,	do_pass)
+
+/*--------------------------------------------------------------------*/
+
+void
+VRT_l_bereq_uncacheable(const struct vrt_ctx *ctx, unsigned a)
+{
+	CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
+	CHECK_OBJ_NOTNULL(ctx->bo, BUSYOBJ_MAGIC);
+
+	if (ctx->bo->do_pass && !a) {
+		VSLb(ctx->vsl, SLT_VCL_Error,
+		    "Ignoring attempt to reset bereq.uncacheable");
+	} else if (a) {
+		ctx->bo->do_pass = a;
+	}
+}
+
+unsigned
+VRT_r_bereq_uncacheable(const struct vrt_ctx *ctx)
+{
+	CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
+	CHECK_OBJ_NOTNULL(ctx->bo, BUSYOBJ_MAGIC);
+	return (ctx->bo->do_pass);
+}
+
+void
+VRT_l_beresp_uncacheable(const struct vrt_ctx *ctx, unsigned a)
+{
+	CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
+	CHECK_OBJ_NOTNULL(ctx->bo, BUSYOBJ_MAGIC);
+
+	if (ctx->bo->uncacheable && !a) {
+		VSLb(ctx->vsl, SLT_VCL_Error,
+		    "Ignoring attempt to reset beresp.uncacheable");
+	} else if (a) {
+		ctx->bo->uncacheable = a;
+	}
+}
+
+unsigned
+VRT_r_beresp_uncacheable(const struct vrt_ctx *ctx)
+{
+	CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
+	CHECK_OBJ_NOTNULL(ctx->bo, BUSYOBJ_MAGIC);
+	return (ctx->bo->uncacheable);
+}
 
 /*--------------------------------------------------------------------*/
 
diff --git a/bin/varnishd/default.vcl b/bin/varnishd/default.vcl
index 520bc06..267b3c8 100644
--- a/bin/varnishd/default.vcl
+++ b/bin/varnishd/default.vcl
@@ -135,7 +135,7 @@ sub vcl_backend_response {
 		 * Mark as "Hit-For-Pass" for the next 2 minutes
 		 */
 		set beresp.ttl = 120 s;
-		set beresp.do_pass = true;
+		set beresp.uncacheable = true;
     }
     return (deliver);
 }
diff --git a/lib/libvcl/generate.py b/lib/libvcl/generate.py
index ef3f109..1226b1e 100755
--- a/lib/libvcl/generate.py
+++ b/lib/libvcl/generate.py
@@ -257,6 +257,11 @@ sp_variables = (
 		( 'pipe', 'backend_fetch', 'pass', 'miss', 'backend_response',),
 		( 'pipe', 'backend_fetch', 'pass', 'miss', 'backend_response',),
 	),
+	('bereq.uncacheable',
+		'BOOL',
+		( 'backend_fetch', 'backend_response',),
+		( 'backend_fetch', 'backend_response',),
+	),
 	('bereq.connect_timeout',
 		'DURATION',
 		( 'pipe', 'backend_fetch', 'pass', 'miss',),
@@ -317,11 +322,6 @@ sp_variables = (
 		( 'backend_response',),
 		( 'backend_response',),
 	),
-	('beresp.do_pass',
-		'BOOL',
-		( 'backend_response',),
-		( 'backend_response',),
-	),
 	('beresp.uncacheable',
 		'BOOL',
 		( 'backend_response',),



More information about the varnish-commit mailing list