[experimental-ims] 3f56d4e Fix ttl when backend fetches are salvaged into transient storage.

Poul-Henning Kamp phk at FreeBSD.org
Thu Dec 18 10:27:47 CET 2014


commit 3f56d4ebb4297f383cba2d05c2eca179eb171fe6
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Mon May 21 07:23:27 2012 +0000

    Fix ttl when backend fetches are salvaged into transient storage.
    
    Submitted by:	Martin
    Fixes		#1140

diff --git a/bin/varnishd/cache/cache_center.c b/bin/varnishd/cache/cache_center.c
index 9b7a968..b350438 100644
--- a/bin/varnishd/cache/cache_center.c
+++ b/bin/varnishd/cache/cache_center.c
@@ -812,12 +812,12 @@ cnt_fetchbody(struct sess *sp, struct worker *wrk, struct req *req)
 		 * Try to salvage the transaction by allocating a
 		 * shortlived object on Transient storage.
 		 */
-		req->obj = STV_NewObject(bo, &req->objcore, TRANSIENT_STORAGE,
-		    l, nhttp);
 		if (bo->exp.ttl > cache_param->shortlived)
 			bo->exp.ttl = cache_param->shortlived;
 		bo->exp.grace = 0.0;
 		bo->exp.keep = 0.0;
+		req->obj = STV_NewObject(bo, &req->objcore, TRANSIENT_STORAGE,
+		    l, nhttp);
 	}
 	bo->stats = NULL;
 	if (req->obj == NULL) {
diff --git a/bin/varnishtest/tests/r01140.vtc b/bin/varnishtest/tests/r01140.vtc
new file mode 100644
index 0000000..4bd0b3b
--- /dev/null
+++ b/bin/varnishtest/tests/r01140.vtc
@@ -0,0 +1,39 @@
+varnishtest "Transient-salvaged objects ttl should be shortened - #1140"
+
+server s1 {
+	# This response should almost completely fill the storage
+	rxreq
+	expect req.url == /url1
+	txresp -bodylen 1048050
+
+	# The next one should not fit in the storage, ending up in transient
+	# with zero ttl (=shortlived)
+	rxreq
+	expect req.url == /url2
+	txresp -bodylen 1024
+
+	# And therefore this one should be fetched next
+	rxreq
+	expect req.url == /url2
+	txresp -bodylen 1025
+} -start
+
+varnish v1 -arg "-p expiry_sleep=0.01 -p nuke_limit=0 -p shortlived=0" \
+	-storage "-smalloc,1m" -vcl+backend { } -start
+
+client c1 {
+	txreq -url /url1
+	rxresp
+	expect resp.status == 200
+	expect resp.bodylen == 1048050
+
+	txreq -url /url2
+	rxresp
+	expect resp.status == 200
+	expect resp.bodylen == 1024
+
+	txreq -url /url2
+	rxresp
+	expect resp.status == 200
+	expect resp.bodylen == 1025
+} -run



More information about the varnish-commit mailing list