[master] 71a357a Make objects read-only, once they have been stored.

Poul-Henning Kamp phk at FreeBSD.org
Mon Mar 24 09:01:05 CET 2014


commit 71a357ab29bb4ec4f8e671665395e101ad885d2e
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Mon Mar 24 07:59:58 2014 +0000

    Make objects read-only, once they have been stored.
    
    Now that we have a proper purge-mechanism, all the magic to
    set obj.{ttl,grace,keep} in vcl_hit{} can go away.

diff --git a/bin/varnishd/cache/cache_vrt_var.c b/bin/varnishd/cache/cache_vrt_var.c
index b51d2de..c48dc37 100644
--- a/bin/varnishd/cache/cache_vrt_var.c
+++ b/bin/varnishd/cache/cache_vrt_var.c
@@ -436,23 +436,21 @@ VRT_r_bereq_retries(const struct vrt_ctx *ctx)
  * keep are relative to ttl.
  */
 
-#define VRT_DO_EXP(which, sexp, fld, offset, now, extra)	\
+#define VRT_DO_EXP_L(which, sexp, fld)				\
 								\
 void								\
 VRT_l_##which##_##fld(const struct vrt_ctx *ctx, double a)	\
 {								\
-	double dt;						\
 								\
 	CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);			\
-	if (a > 0.0)						\
-		sexp.fld = a + offset;				\
-	else							\
-		sexp.fld = 0;					\
-	extra;							\
-	dt = now - sexp.t_origin;				\
-	VSLb(ctx->vsl, SLT_TTL, "VCL %.0f %.0f %.0f %.0f %.0f",	\
-	    sexp.ttl - dt, sexp.grace, sexp.keep, now, dt);	\
-}								\
+	if (a < 0.0)						\
+		a = 0.0;					\
+	sexp.fld = a;						\
+	VSLb(ctx->vsl, SLT_TTL, "VCL %.0f %.0f %.0f %.0f",	\
+	    sexp.ttl, sexp.grace, sexp.keep, sexp.t_origin);	\
+}
+
+#define VRT_DO_EXP_R(which, sexp, fld, offset)			\
 								\
 double								\
 VRT_r_##which##_##fld(const struct vrt_ctx *ctx)		\
@@ -464,17 +462,17 @@ VRT_r_##which##_##fld(const struct vrt_ctx *ctx)		\
 	return(0.0);						\
 }
 
-VRT_DO_EXP(obj, ctx->req->obj->exp, grace, 0, ctx->req->t_req,
-   EXP_Rearm(ctx->req->obj, ctx->req->t_req, NAN, NAN, NAN);)
-VRT_DO_EXP(obj, ctx->req->obj->exp, ttl,
-   (ctx->req->t_req - ctx->req->obj->exp.t_origin), ctx->req->t_req,
-   EXP_Rearm(ctx->req->obj, ctx->req->t_req, NAN, NAN, NAN);)
-VRT_DO_EXP(obj, ctx->req->obj->exp, keep, 0, ctx->req->t_req,
-   EXP_Rearm(ctx->req->obj, ctx->req->t_req, NAN, NAN, NAN);)
+VRT_DO_EXP_R(obj, ctx->req->obj->exp, ttl,
+   (ctx->req->t_req - ctx->req->obj->exp.t_origin))
+VRT_DO_EXP_R(obj, ctx->req->obj->exp, grace, 0)
+VRT_DO_EXP_R(obj, ctx->req->obj->exp, keep, 0)
 
-VRT_DO_EXP(beresp, ctx->bo->exp, grace, 0, ctx->bo->exp.t_origin,)
-VRT_DO_EXP(beresp, ctx->bo->exp, ttl, 0, ctx->bo->exp.t_origin,)
-VRT_DO_EXP(beresp, ctx->bo->exp, keep, 0, ctx->bo->exp.t_origin,)
+VRT_DO_EXP_L(beresp, ctx->bo->exp, ttl)
+VRT_DO_EXP_R(beresp, ctx->bo->exp, ttl, 0)
+VRT_DO_EXP_L(beresp, ctx->bo->exp, grace)
+VRT_DO_EXP_R(beresp, ctx->bo->exp, grace, 0)
+VRT_DO_EXP_L(beresp, ctx->bo->exp, keep)
+VRT_DO_EXP_R(beresp, ctx->bo->exp, keep, 0)
 
 /*--------------------------------------------------------------------
  * [be]req.xid
diff --git a/bin/varnishtest/tests/p00001.vtc b/bin/varnishtest/tests/p00001.vtc
deleted file mode 100644
index 8c38715..0000000
--- a/bin/varnishtest/tests/p00001.vtc
+++ /dev/null
@@ -1,70 +0,0 @@
-varnishtest "Change TTL on persistent object"
-
-shell "rm -f ${tmpdir}/_.per"
-
-server s1 {
-	rxreq
-	txresp -hdr "Foo: foo"
-} -start
-
-varnish v1 \
-	-arg "-pfeature=+wait_silo" \
-	-arg "-pban_lurker_sleep=0" \
-	-arg "-spersistent,${tmpdir}/_.per,10m" \
-	-vcl+backend { } -start
-
-varnish v1 -cliok "param.set default_grace 0"
-varnish v1 -cliok "param.set default_keep 0"
-
-client c1 {
-	txreq -url "/"
-	rxresp
-	expect resp.status == 200
-	expect resp.http.X-Varnish == "1001"
-	expect resp.http.foo == "foo"
-} -run
-
-varnish v1 -stop
-
-varnish v1 -vcl+backend {
-	sub vcl_hit {
-		set obj.ttl = 1 s;
-	}
-}
-
-server s1 -wait
-
-varnish v1 -start
-varnish v1 -cliok "debug.xid 1999"
-
-client c1 {
-	txreq -url "/"
-	rxresp
-	expect resp.status == 200
-	expect resp.http.X-Varnish == "2001 1002"
-	expect resp.http.foo == "foo"
-} -run
-
-varnish v1 -stop
-
-server s1 {
-	rxreq
-	txresp -hdr "Foo: bar"
-} -start
-
-varnish v1 -vcl+backend { }
-
-delay 2
-
-varnish v1 -start
-varnish v1 -cliok "debug.xid 2999"
-
-client c1 {
-	txreq -url "/"
-	rxresp
-	expect resp.status == 200
-	expect resp.http.X-Varnish == "3001"
-	expect resp.http.foo == "bar"
-} -run
-
-# shell "rm -f /tmp/__v1/_.per"
diff --git a/bin/varnishtest/tests/r00365.vtc b/bin/varnishtest/tests/r00365.vtc
deleted file mode 100644
index 43c76b3..0000000
--- a/bin/varnishtest/tests/r00365.vtc
+++ /dev/null
@@ -1,29 +0,0 @@
-varnishtest "Test restarts in vcl_hit"
-
-server s1 {
-	rxreq
-	expect req.url == "/foo"
-	txresp -status 200 -body "1"
-	rxreq
-	expect req.url == "/foo"
-	txresp -status 200 -body "22"
-} -start
-
-varnish v1 -vcl+backend {
-	sub vcl_hit {
-		set obj.ttl = 0s;
-		return (restart);
-	}
-} -start
-
-client c1 {
-	txreq -url "/foo"
-	rxresp
-	expect resp.status == 200
-	expect resp.bodylen == 1
-
-	txreq -url "/foo"
-	rxresp
-	expect resp.status == 200
-	expect resp.bodylen == 2
-} -run
diff --git a/bin/varnishtest/tests/r00444.vtc b/bin/varnishtest/tests/r00444.vtc
deleted file mode 100644
index 899ab57..0000000
--- a/bin/varnishtest/tests/r00444.vtc
+++ /dev/null
@@ -1,59 +0,0 @@
-varnishtest "purging on POST"
-
-server s1 {
-	rxreq
-	expect req.method == "GET"
-	txresp -body "1"
-
-	rxreq
-	expect req.method == "POST"
-	txresp -body "22"
-
-	rxreq
-	expect req.method == "POST"
-	txresp -body "333"
-
-	rxreq
-	expect req.method == "GET"
-	txresp -body "4444"
-} -start
-
-varnish v1 -vcl+backend {
-	sub vcl_recv {
-		if (req.method == "POST") {
-			/* Lookup so we find any cached object */
-			return (hash);
-		}
-	}
-	sub vcl_hit {
-		if (req.method == "POST") {
-			/* Get rid of this object */
-			set obj.ttl = 0s;
-			return (pass);
-		}
-	}
-	sub vcl_miss {
-		if (req.method == "POST") {
-			/* Make sure we don't cache the POST result */
-			return (pass);
-		}
-	}
-} -start
-
-client c1 {
-	txreq
-	rxresp
-	expect resp.bodylen == 1
-
-	txreq -req POST
-	rxresp
-	expect resp.bodylen == 2
-
-	txreq -req POST
-	rxresp
-	expect resp.bodylen == 3
-
-	txreq
-	rxresp
-	expect resp.bodylen == 4
-} -run
diff --git a/bin/varnishtest/tests/r00956.vtc b/bin/varnishtest/tests/r00956.vtc
index 2744a44..85cca43 100644
--- a/bin/varnishtest/tests/r00956.vtc
+++ b/bin/varnishtest/tests/r00956.vtc
@@ -9,18 +9,12 @@ varnish v1 -vcl+backend {
 	sub vcl_backend_response {
 		set beresp.ttl = 10s;
 		set beresp.http.fooB = beresp.ttl;
-		set beresp.http.barB = "xxx";
 	}
 	sub vcl_hit {
 		set req.http.foo = obj.ttl;
-		set obj.ttl = 7s;
-		set obj.grace = 120s;
-		set obj.keep = 1h;
-		set req.http.bar = obj.ttl;
 	}
 	sub vcl_deliver {
 		set resp.http.foo = req.http.foo;
-		set resp.http.bar = req.http.bar;
 	}
 } -start
 
@@ -29,7 +23,6 @@ client c1 {
 	rxresp
 	expect resp.bodylen == 40
 	expect resp.http.fooB == 10.000
-	expect resp.http.barB == "xxx"
 
 	delay 2
 	txreq
@@ -37,19 +30,13 @@ client c1 {
 	expect resp.bodylen == 40
 	# XXX: should be: < 8
 	expect resp.http.fooB == 10.000
-	expect resp.http.barB == "xxx"
 	expect resp.http.foo != 10.000
 	expect resp.http.foo != 9.000
-	expect resp.http.bar == 7.000
 
 	delay 2
 	txreq
 	rxresp
 	expect resp.bodylen == 40
-	# XXX: should be: < 5
 	expect resp.http.fooB == 10.000
-	expect resp.http.barB == "xxx"
-	expect resp.http.foo != 7.000
-	expect resp.http.foo != 6.000
-	expect resp.http.bar == 7.000
+	expect resp.http.foo <= 5.000
 } -run
diff --git a/bin/varnishtest/tests/v00016.vtc b/bin/varnishtest/tests/v00016.vtc
index b42106d..1107f86 100644
--- a/bin/varnishtest/tests/v00016.vtc
+++ b/bin/varnishtest/tests/v00016.vtc
@@ -75,12 +75,12 @@ varnish v1 -vcl {
 
 varnish v1 -errvcl {Unknown time unit 'k'.  Legal are 'ms', 's', 'm', 'h', 'd' and 'w'} {
 	backend b { .host = "127.0.0.1"; }
-	sub vcl_backend_response { set obj.ttl = 1. k; }
+	sub vcl_backend_response { set beresp.ttl = 1. k; }
 }
 
 varnish v1 -errvcl {Expression has type DURATION, expected BOOL} {
 	backend b { .host = "127.0.0.1"; }
-	sub vcl_backend_response { if (obj.ttl *= 2) { } }
+	sub vcl_backend_response { if (beresp.ttl *= 2) { } }
 }
 
 varnish v1 -errvcl {Operator > not possible on BACKEND} {
diff --git a/bin/varnishtest/tests/v00021.vtc b/bin/varnishtest/tests/v00021.vtc
index 636207e..301384b 100644
--- a/bin/varnishtest/tests/v00021.vtc
+++ b/bin/varnishtest/tests/v00021.vtc
@@ -1,11 +1,11 @@
 varnishtest "VCL compiler coverage test: vcc_xref.c"
 
-varnish v1 -errvcl {'obj.ttl': cannot be set in method 'vcl_recv'.} {
+varnish v1 -errvcl {Variable 'obj.ttl' is read only.} {
 	backend b { .host = "127.0.0.1"; }
 	sub vcl_recv { set obj.ttl = 1 w; }
 }
 
-varnish v1 -errvcl {'obj.ttl': cannot be set from method 'foo'.} {
+varnish v1 -errvcl {Variable 'obj.ttl' is read only.} {
 	backend b { .host = "127.0.0.1"; }
 
 	sub foo { set obj.ttl = 1 w; }
diff --git a/bin/varnishtest/tests/v00023.vtc b/bin/varnishtest/tests/v00023.vtc
deleted file mode 100644
index e96585a..0000000
--- a/bin/varnishtest/tests/v00023.vtc
+++ /dev/null
@@ -1,29 +0,0 @@
-varnishtest "Test that obj.ttl = 0s prevents subsequent hits"
-
-server s1 {
-	rxreq
-	expect req.url == "/foo"
-	txresp -status 200 -body "1"
-	rxreq
-	expect req.url == "/foo"
-	txresp -status 200 -body "22"
-} -start
-
-varnish v1 -vcl+backend {
-	sub vcl_hit {
-		set obj.ttl = 0s;
-		return (restart);
-	}
-} -start
-
-client c1 {
-	txreq -url "/foo"
-	rxresp
-	expect resp.status == 200
-	expect resp.bodylen == 1
-
-	txreq -url "/foo"
-	rxresp
-	expect resp.status == 200
-	expect resp.bodylen == 2
-} -run
diff --git a/bin/varnishtest/tests/v00025.vtc b/bin/varnishtest/tests/v00025.vtc
index b090502..1be49af 100644
--- a/bin/varnishtest/tests/v00025.vtc
+++ b/bin/varnishtest/tests/v00025.vtc
@@ -24,14 +24,10 @@ varnish v1 -vcl+backend {
 
 	sub vcl_hit {
 		if (obj.grace < 3m) {
-			set obj.grace = 1m;
-		} else {
-			set obj.grace = 2m;
+			return (deliver);
 		}
 		if (obj.ttl < 3m) {
-			set obj.ttl = 2m;
-		} else {
-			set obj.ttl = 3m;
+			return (deliver);
 		}
 	}
 
diff --git a/include/tbl/vsl_tags.h b/include/tbl/vsl_tags.h
index 9217582..5f768ec 100644
--- a/include/tbl/vsl_tags.h
+++ b/include/tbl/vsl_tags.h
@@ -230,27 +230,26 @@ SLTM(TTL, 0, "TTL set on object",
 	"A TTL record is emitted whenever the ttl, grace or keep"
 	" values for an object is set.\n\n"
 	"The format is::\n\n"
-	"\t%u %s %d %d %d %d %d [ %d %u %u ]\n"
-	"\t|  |  |  |  |  |  |    |  |  |\n"
-	"\t|  |  |  |  |  |  |    |  |  +- Max-Age from Cache-Control header\n"
-	"\t|  |  |  |  |  |  |    |  +---- Expires header\n"
-	"\t|  |  |  |  |  |  |    +------- Date header\n"
-	"\t|  |  |  |  |  |  +------------ Age (incl Age: header value)\n"
-	"\t|  |  |  |  |  +--------------- Reference time for TTL\n"
-	"\t|  |  |  |  +------------------ Keep\n"
-	"\t|  |  |  +--------------------- Grace\n"
-	"\t|  |  +------------------------ TTL\n"
-	"\t|  +--------------------------- \"RFC\" or \"VCL\"\n"
-	"\t+------------------------------ object XID\n"
+	"\t%s %d %d %d %d %d [ %d %u %u ]\n"
+	"\t|  |  |  |  |  |    |  |  |\n"
+	"\t|  |  |  |  |  |    |  |  +- Max-Age from Cache-Control header\n"
+	"\t|  |  |  |  |  |    |  +---- Expires header\n"
+	"\t|  |  |  |  |  |    +------- Date header\n"
+	"\t|  |  |  |  |  +------------ Age (incl Age: header value)\n"
+	"\t|  |  |  |  +--------------- Reference time for TTL\n"
+	"\t|  |  |  +------------------ Keep\n"
+	"\t|  |  +--------------------- Grace\n"
+	"\t|  +------------------------ TTL\n"
+	"\t+--------------------------- \"RFC\" or \"VCL\"\n"
 	"\n"
-	"The last three fields are only present in \"RFC\" headers.\n\n"
+	"The last four fields are only present in \"RFC\" headers.\n\n"
 	"Examples::\n\n"
-	"\t1001 RFC 19 -1 -1 1312966109 4 0 0 23\n"
-	"\t1001 VCL 10 -1 -1 1312966109 4\n"
-	"\t1001 VCL 7 -1 -1 1312966111 6\n"
-	"\t1001 VCL 7 120 -1 1312966111 6\n"
-	"\t1001 VCL 7 120 3600 1312966111 6\n"
-	"\t1001 VCL 12 120 3600 1312966113 8\n"
+	"\tRFC 19 -1 -1 1312966109 4 0 0 23\n"
+	"\tVCL 10 -1 -1 1312966109 4\n"
+	"\tVCL 7 -1 -1 1312966111 6\n"
+	"\tVCL 7 120 -1 1312966111 6\n"
+	"\tVCL 7 120 3600 1312966111 6\n"
+	"\tVCL 12 120 3600 1312966113 8\n"
 	"\n"
 )
 
diff --git a/lib/libvcc/generate.py b/lib/libvcc/generate.py
index 95c32eb..b6ccfe2 100755
--- a/lib/libvcc/generate.py
+++ b/lib/libvcc/generate.py
@@ -528,7 +528,7 @@ sp_variables = [
 	('obj.ttl',
 		'DURATION',
 		( 'hit', ),
-		( 'hit', ), """
+		( ), """
 		The object's remaining time to live, in seconds.
 		obj.ttl is writable.
 		"""
@@ -536,14 +536,14 @@ sp_variables = [
 	('obj.grace',
 		'DURATION',
 		( 'hit', ),
-		( 'hit', ), """
+		( ), """
 		The object's grace period in seconds. obj.grace is writable.
 		"""
 	),
 	('obj.keep',
 		'DURATION',
 		( 'hit', ),
-		( 'hit', ), """
+		( ), """
 		"""
 	),
 	('obj.uncacheable',



More information about the varnish-commit mailing list