[master] f2caddc Fix a bug in setting *.ttl variables from VCL and go over testcases at the same time.
Poul-Henning Kamp
phk at FreeBSD.org
Thu Aug 28 10:24:18 CEST 2014
commit f2caddcff6d2018604b2ab83ec9bf0e12ec4d51a
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Thu Aug 28 08:23:38 2014 +0000
Fix a bug in setting *.ttl variables from VCL and go over
testcases at the same time.
Spotted by: UPLEX
diff --git a/bin/varnishd/cache/cache_vrt_var.c b/bin/varnishd/cache/cache_vrt_var.c
index 0d639a7..93bbf04 100644
--- a/bin/varnishd/cache/cache_vrt_var.c
+++ b/bin/varnishd/cache/cache_vrt_var.c
@@ -483,17 +483,23 @@ VRT_r_bereq_retries(const struct vrt_ctx *ctx)
}
/*--------------------------------------------------------------------
- * NB: TTL is relative to when object was created, whereas grace and
- * keep are relative to ttl.
+ * In exp.*:
+ * t_origin is absolute
+ * ttl is relative to t_origin
+ * grace&keep are relative to ttl
+ * In VCL:
+ * ttl is relative to now
+ * grace&keep are relative to ttl
*/
-#define VRT_DO_EXP_L(which, sexp, fld) \
+#define VRT_DO_EXP_L(which, sexp, fld, offset) \
\
void \
VRT_l_##which##_##fld(const struct vrt_ctx *ctx, double a) \
{ \
\
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC); \
+ a += (offset); \
if (a < 0.0) \
a = 0.0; \
sexp.fld = a; \
@@ -506,23 +512,28 @@ VRT_l_##which##_##fld(const struct vrt_ctx *ctx, double a) \
double \
VRT_r_##which##_##fld(const struct vrt_ctx *ctx) \
{ \
+ double d; \
\
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC); \
- if (sexp.fld > 0.0) \
- return(sexp.fld - offset); \
- return(0.0); \
+ d = sexp.fld; \
+ if (d <= 0.0) \
+ d = 0.0; \
+ d -= (offset); \
+ return(d); \
}
VRT_DO_EXP_R(obj, ctx->req->objcore->exp, ttl,
- (ctx->req->t_req - ctx->req->objcore->exp.t_origin))
+ ctx->now - ctx->req->objcore->exp.t_origin)
VRT_DO_EXP_R(obj, ctx->req->objcore->exp, grace, 0)
VRT_DO_EXP_R(obj, ctx->req->objcore->exp, keep, 0)
-VRT_DO_EXP_L(beresp, ctx->bo->fetch_objcore->exp, ttl)
-VRT_DO_EXP_R(beresp, ctx->bo->fetch_objcore->exp, ttl, 0)
-VRT_DO_EXP_L(beresp, ctx->bo->fetch_objcore->exp, grace)
+VRT_DO_EXP_L(beresp, ctx->bo->fetch_objcore->exp, ttl,
+ ctx->now - ctx->bo->fetch_objcore->exp.t_origin)
+VRT_DO_EXP_R(beresp, ctx->bo->fetch_objcore->exp, ttl,
+ ctx->now - ctx->bo->fetch_objcore->exp.t_origin)
+VRT_DO_EXP_L(beresp, ctx->bo->fetch_objcore->exp, grace, 0)
VRT_DO_EXP_R(beresp, ctx->bo->fetch_objcore->exp, grace, 0)
-VRT_DO_EXP_L(beresp, ctx->bo->fetch_objcore->exp, keep)
+VRT_DO_EXP_L(beresp, ctx->bo->fetch_objcore->exp, keep, 0)
VRT_DO_EXP_R(beresp, ctx->bo->fetch_objcore->exp, keep, 0)
/*--------------------------------------------------------------------
diff --git a/bin/varnishtest/tests/c00060.vtc b/bin/varnishtest/tests/c00060.vtc
index ece157e..1e6e734 100644
--- a/bin/varnishtest/tests/c00060.vtc
+++ b/bin/varnishtest/tests/c00060.vtc
@@ -11,6 +11,7 @@ server s1 {
txresp -status "304" \
-hdr "Last-Modified: Thu, 26 Jun 2008 12:00:01 GMT" \
-hdr "Snafu: 2" \
+ -hdr "Grifle: 3" \
-nolen
} -start
@@ -40,6 +41,7 @@ client c1 {
rxresp
expect resp.bodylen == 13
expect resp.http.foobar == foo0
+ expect resp.http.grifle == 3
expect resp.http.snafu == 2a
} -run
diff --git a/bin/varnishtest/tests/r00956.vtc b/bin/varnishtest/tests/r00956.vtc
index 85cca43..71dc617 100644
--- a/bin/varnishtest/tests/r00956.vtc
+++ b/bin/varnishtest/tests/r00956.vtc
@@ -7,6 +7,7 @@ server s1 {
varnish v1 -vcl+backend {
sub vcl_backend_response {
+ set beresp.http.fooA = beresp.ttl;
set beresp.ttl = 10s;
set beresp.http.fooB = beresp.ttl;
}
@@ -22,21 +23,22 @@ client c1 {
txreq
rxresp
expect resp.bodylen == 40
+ expect resp.http.fooA == 19.000
expect resp.http.fooB == 10.000
delay 2
txreq
rxresp
expect resp.bodylen == 40
- # XXX: should be: < 8
+ expect resp.http.fooA == 19.000
expect resp.http.fooB == 10.000
- expect resp.http.foo != 10.000
- expect resp.http.foo != 9.000
+ expect resp.http.foo <= 8.000
delay 2
txreq
rxresp
expect resp.bodylen == 40
+ expect resp.http.fooA == 19.000
expect resp.http.fooB == 10.000
- expect resp.http.foo <= 5.000
+ expect resp.http.foo <= 6.000
} -run
diff --git a/bin/varnishtest/tests/r01578.vtc b/bin/varnishtest/tests/r01578.vtc
index a72a3c9..4cf4904 100644
--- a/bin/varnishtest/tests/r01578.vtc
+++ b/bin/varnishtest/tests/r01578.vtc
@@ -21,7 +21,7 @@ client c1 {
txreq
rxresp
expect resp.bodylen == 40
- expect resp.http.x-ttl == 23.000
+ expect resp.http.x-ttl == 19.000
expect resp.http.Age == 4
@@ -29,13 +29,13 @@ client c1 {
txreq
rxresp
expect resp.bodylen == 40
- expect resp.http.x-ttl == 23.000
- expect resp.http.x-remaining-ttl ~ ^17\.0|^16\.[89]
+ expect resp.http.x-ttl == 19.000
+ expect resp.http.x-remaining-ttl <= 17.000
delay 2
txreq
rxresp
expect resp.bodylen == 40
- expect resp.http.x-ttl == 23.000
- expect resp.http.x-remaining-ttl ~ ^15\.0|^14\.[89]
+ expect resp.http.x-ttl == 19.000
+ expect resp.http.x-remaining-ttl <= 15.000
} -run
More information about the varnish-commit
mailing list