[master] 00b606f Eliminate beresp.cachable VCL variable. Cacheability is now controlled solely through the .ttl and .grace variables.
Poul-Henning Kamp
phk at varnish-cache.org
Fri Jan 28 23:44:19 CET 2011
commit 00b606f3f9704eaeb4fcd408a547864b41c753b1
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Fri Jan 28 22:42:07 2011 +0000
Eliminate beresp.cachable VCL variable. Cacheability is now controlled
solely through the .ttl and .grace variables.
Add a parameter "shortlived", objects with ttl shorter than this
always go into transient (malloc) storage, just like pass objects do.
Enforce a minimum 1sec TTL for hit-for-pass.
diff --git a/bin/varnishd/cache.h b/bin/varnishd/cache.h
index c2051b3..f997341 100644
--- a/bin/varnishd/cache.h
+++ b/bin/varnishd/cache.h
@@ -104,6 +104,8 @@ struct lock { void *priv; }; // Opaque
#define DIGEST_LEN 32
+/* Name of transient storage */
+#define TRANSIENT_STORAGE "Transient"
/*--------------------------------------------------------------------
* Pointer aligment magic
@@ -268,14 +270,13 @@ struct worker {
struct http *beresp;
struct http *resp;
- unsigned cacheable;
double age;
double entered;
double ttl;
double grace;
/* This is only here so VRT can find it */
- char *storage_hint;
+ const char *storage_hint;
/* Fetch stuff */
enum body_status body_status;
diff --git a/bin/varnishd/cache_center.c b/bin/varnishd/cache_center.c
index fc8de44..6595a98 100644
--- a/bin/varnishd/cache_center.c
+++ b/bin/varnishd/cache_center.c
@@ -379,7 +379,6 @@ cnt_error(struct sess *sp)
w = sp->wrk;
if (sp->obj == NULL) {
HSH_Prealloc(sp);
- sp->wrk->cacheable = 0;
/* XXX: 1024 is a pure guess */
sp->obj = STV_NewObject(sp, NULL, 1024, 0,
params->http_headers);
@@ -525,6 +524,13 @@ cnt_fetch(struct sess *sp)
sp->err_code = http_GetStatus(sp->wrk->beresp);
/*
+ * What does RFC2616 think about TTL ?
+ */
+ sp->wrk->entered = TIM_real();
+ sp->wrk->age = 0;
+ sp->wrk->ttl = RFC2616_Ttl(sp);
+
+ /*
* Initial cacheability determination per [RFC2616, 13.4]
* We do not support ranges yet, so 206 is out.
*/
@@ -536,19 +542,15 @@ cnt_fetch(struct sess *sp)
case 302: /* Moved Temporarily */
case 410: /* Gone */
case 404: /* Not Found */
- sp->wrk->cacheable = 1;
break;
default:
- sp->wrk->cacheable = 0;
+ sp->wrk->ttl = sp->t_req - 1.;
break;
}
- sp->wrk->entered = TIM_real();
- sp->wrk->age = 0;
- sp->wrk->ttl = RFC2616_Ttl(sp);
-
+ /* pass from vclrecv{} has negative TTL */
if (sp->objcore == NULL)
- sp->wrk->cacheable = 0;
+ sp->wrk->ttl = sp->t_req - 1.;
sp->wrk->do_esi = 0;
sp->wrk->grace = NAN;
@@ -561,11 +563,17 @@ cnt_fetch(struct sess *sp)
if (sp->objcore == NULL) {
/* This is a pass from vcl_recv */
- sp->wrk->cacheable = 0;
pass = 1;
- } else if (sp->handling == VCL_RET_PASS || !sp->wrk->cacheable) {
+ /* VCL may have fiddled this, but that doesn't help */
+ sp->wrk->ttl = sp->t_req - 1.;
+ } else if (sp->handling == VCL_RET_PASS) {
/* pass from vcl_fetch{} -> hit-for-pass */
+ /* XXX: the bereq was not filtered pass... */
pass = 1;
+ sp->objcore->flags |= OC_F_PASS;
+ /* Enforce a minimum TTL of 1 sec (if set from VCL) */
+ if (sp->wrk->ttl <= sp->t_req)
+ sp->wrk->ttl = sp->wrk->entered + params->default_ttl;
} else {
/* regular object */
pass = 0;
@@ -633,7 +641,7 @@ cnt_fetch(struct sess *sp)
pass ? HTTPH_R_PASS : HTTPH_A_INS, &nhttp);
/* Create Vary instructions */
- if (sp->wrk->cacheable) {
+ if (sp->objcore != NULL) {
CHECK_OBJ_NOTNULL(sp->objcore, OBJCORE_MAGIC);
vary = VRY_Create(sp, sp->wrk->beresp);
if (vary != NULL) {
@@ -649,11 +657,18 @@ cnt_fetch(struct sess *sp)
*/
l += strlen("Content-Encoding: XxxXxxXxxXxxXxxXxx" + sizeof(void *));
+ if (sp->wrk->ttl < sp->t_req + params->shortlived ||
+ sp->objcore == NULL)
+ sp->wrk->storage_hint = TRANSIENT_STORAGE;
+
sp->obj = STV_NewObject(sp, sp->wrk->storage_hint, l,
sp->wrk->ttl, nhttp);
+ /* XXX: -> 513 */
CHECK_OBJ_NOTNULL(sp->obj, OBJECT_MAGIC);
sp->wrk->storage_hint = NULL;
+
+ /* VFP will update as needed */
sp->obj->gziped = sp->wrk->is_gzip;
if (vary != NULL) {
@@ -687,7 +702,6 @@ cnt_fetch(struct sess *sp)
else
sp->obj->last_modified = sp->wrk->entered;
-
/* Use unmodified headers*/
i = FetchBody(sp, sp->wrk->beresp1);
@@ -715,11 +729,6 @@ cnt_fetch(struct sess *sp)
sp->step = STP_RECV;
return (0);
case VCL_RET_PASS:
- if (sp->obj->objcore != NULL)
- sp->obj->objcore->flags |= OC_F_PASS;
- if (sp->obj->ttl - sp->t_req < params->default_ttl)
- sp->obj->ttl = sp->t_req + params->default_ttl;
- break;
case VCL_RET_DELIVER:
break;
case VCL_RET_ERROR:
@@ -730,7 +739,7 @@ cnt_fetch(struct sess *sp)
WRONG("Illegal action in vcl_fetch{}");
}
- if (sp->wrk->cacheable) {
+ if (sp->obj->objcore != NULL) {
EXP_Insert(sp->obj);
AN(sp->obj->objcore);
AN(sp->obj->objcore->ban);
diff --git a/bin/varnishd/cache_vrt_var.c b/bin/varnishd/cache_vrt_var.c
index a111e0b..cc0d11e 100644
--- a/bin/varnishd/cache_vrt_var.c
+++ b/bin/varnishd/cache_vrt_var.c
@@ -195,7 +195,6 @@ VRT_r_##dir##_##onm(const struct sess *sp) \
return (sp->wrk->field); \
}
-VBERESP(beresp, unsigned, cacheable, cacheable)
VBERESP(beresp, unsigned, do_esi, do_esi)
VBERESP(beresp, unsigned, do_gzip, do_gzip)
VBERESP(beresp, unsigned, do_gunzip, do_gunzip)
diff --git a/bin/varnishd/default.vcl b/bin/varnishd/default.vcl
index 350e0a7..6093780 100644
--- a/bin/varnishd/default.vcl
+++ b/bin/varnishd/default.vcl
@@ -102,7 +102,7 @@ sub vcl_miss {
}
sub vcl_fetch {
- if (!beresp.cacheable) {
+ if (beresp.ttl <= 0s) {
return (pass);
}
if (beresp.http.Set-Cookie) {
diff --git a/bin/varnishd/heritage.h b/bin/varnishd/heritage.h
index 9c5a328..4b902a5 100644
--- a/bin/varnishd/heritage.h
+++ b/bin/varnishd/heritage.h
@@ -205,6 +205,8 @@ struct params {
unsigned gzip_level;
double critbit_cooloff;
+
+ double shortlived;
};
/*
diff --git a/bin/varnishd/mgt_param.c b/bin/varnishd/mgt_param.c
index f46d3ca..4ba6554 100644
--- a/bin/varnishd/mgt_param.c
+++ b/bin/varnishd/mgt_param.c
@@ -842,6 +842,12 @@ static const struct parspec input_parspec[] = {
" just a waste of memory.",
EXPERIMENTAL,
"32768", "Bytes" },
+ { "shortlived", tweak_timeout_double,
+ &master.shortlived, 0, UINT_MAX,
+ "Objects created with TTL shorter than this are always "
+ "put in transient storage.\n",
+ 0,
+ "10.0", "s" },
{ "critbit_cooloff", tweak_timeout_double,
&master.critbit_cooloff, 60, 254,
"How long time the critbit hasher keeps deleted objheads "
diff --git a/bin/varnishd/stevedore.c b/bin/varnishd/stevedore.c
index 81ce7a4..8e4d0c5 100644
--- a/bin/varnishd/stevedore.c
+++ b/bin/varnishd/stevedore.c
@@ -47,8 +47,6 @@ SVNID("$Id$")
#include "cli_priv.h"
#include "vrt_obj.h"
-#define TRANSIENT_NAME "Transient"
-
static VTAILQ_HEAD(, stevedore) stevedores =
VTAILQ_HEAD_INITIALIZER(stevedores);
@@ -91,7 +89,7 @@ stv_pick_stevedore(const char *hint)
if (!strcmp(stv->ident, hint))
return (stv);
}
- if (!strcmp(TRANSIENT_NAME, hint))
+ if (!strcmp(TRANSIENT_STORAGE, hint))
return (stv_transient);
}
/* pick a stevedore and bump the head along */
@@ -268,10 +266,7 @@ STV_NewObject(struct sess *sp, const char *hint, unsigned wsl, double ttl,
ltot = sizeof *o + wsl + lhttp;
- if (!sp->wrk->cacheable)
- stv = stv_transient;
- else
- stv = stv_pick_stevedore(hint);
+ stv = stv_pick_stevedore(hint);
AN(stv->allocobj);
o = stv->allocobj(stv, sp, ltot, &soc);
CHECK_OBJ_NOTNULL(o, OBJECT_MAGIC);
@@ -477,7 +472,7 @@ STV_Config(const char *spec)
else if (ac != 0)
ARGV_ERR("(-s%s) too many arguments\n", stv->name);
- if (!strcmp(stv->ident, TRANSIENT_NAME)) {
+ if (!strcmp(stv->ident, TRANSIENT_STORAGE)) {
stv->transient = 1;
AZ(stv_transient);
stv_transient = stv;
@@ -497,9 +492,9 @@ STV_Config_Transient(void)
ASSERT_MGT();
VTAILQ_FOREACH(stv, &stevedores, list)
- if (!strcmp(stv->ident, TRANSIENT_NAME))
+ if (!strcmp(stv->ident, TRANSIENT_STORAGE))
return;
- STV_Config(TRANSIENT_NAME "=malloc");
+ STV_Config(TRANSIENT_STORAGE "=malloc");
}
/*--------------------------------------------------------------------*/
@@ -539,7 +534,7 @@ stv_find(const char *nm)
VTAILQ_FOREACH(stv, &stevedores, list)
if (!strcmp(stv->ident, nm))
return (stv);
- if (!strcmp(TRANSIENT_NAME, nm))
+ if (!strcmp(TRANSIENT_STORAGE, nm))
return (stv_transient);
return (NULL);
}
diff --git a/bin/varnishd/storage_persistent.c b/bin/varnishd/storage_persistent.c
index f9739bb..a4ba7a3 100644
--- a/bin/varnishd/storage_persistent.c
+++ b/bin/varnishd/storage_persistent.c
@@ -1436,7 +1436,7 @@ smp_allocobj(struct stevedore *stv, struct sess *sp, unsigned ltot,
/* XXX: temporary sanity */
AN(sp->objcore);
- AN(sp->wrk->cacheable);
+ AN(sp->wrk->ttl >= 0);
sg = NULL;
st = smp_allocx(stv, ltot, &sg);
diff --git a/bin/varnishtest/tests/b00015.vtc b/bin/varnishtest/tests/b00015.vtc
index 4cc8360..d5c9aeb 100644
--- a/bin/varnishtest/tests/b00015.vtc
+++ b/bin/varnishtest/tests/b00015.vtc
@@ -57,7 +57,6 @@ server s1 {
varnish v1 -vcl+backend {
sub vcl_fetch {
if (beresp.status == 502) {
- set beresp.cacheable = true;
set beresp.ttl = 10m;
}
}
diff --git a/bin/varnishtest/tests/r00411.vtc b/bin/varnishtest/tests/r00411.vtc
index edef375..a61e5a9 100644
--- a/bin/varnishtest/tests/r00411.vtc
+++ b/bin/varnishtest/tests/r00411.vtc
@@ -21,7 +21,7 @@ varnish v1 -vcl+backend {
}
sub vcl_fetch {
if (beresp.status == 303) {
- set beresp.cacheable = true;
+ set beresp.ttl = 3m;
set beresp.http.X-Magic-Redirect = "1";
}
}
diff --git a/bin/varnishtest/tests/r00412.vtc b/bin/varnishtest/tests/r00412.vtc
index cb2983e..5fcd43a 100644
--- a/bin/varnishtest/tests/r00412.vtc
+++ b/bin/varnishtest/tests/r00412.vtc
@@ -14,7 +14,6 @@ server s1 {
varnish v1 -vcl+backend {
sub vcl_fetch {
if (beresp.status == 303) {
- set beresp.cacheable = true;
set beresp.ttl = 60 s;
set beresp.http.X-Magic-Redirect = "1";
set req.url = beresp.http.Location;
diff --git a/bin/varnishtest/tests/r00667.vtc b/bin/varnishtest/tests/r00667.vtc
index 926c5bb..19d5cb9 100644
--- a/bin/varnishtest/tests/r00667.vtc
+++ b/bin/varnishtest/tests/r00667.vtc
@@ -19,7 +19,7 @@ server s1 {
varnish v1 -vcl+backend {
sub vcl_fetch {
- set beresp.cacheable = false;
+ set beresp.ttl = 0s;
}
} -start
diff --git a/bin/varnishtest/tests/s00002.vtc b/bin/varnishtest/tests/s00002.vtc
index c0ef1f8..b0bc60a 100644
--- a/bin/varnishtest/tests/s00002.vtc
+++ b/bin/varnishtest/tests/s00002.vtc
@@ -52,7 +52,6 @@ varnish v1 -vcl {
sub vcl_fetch {
set beresp.ttl = 1s;
set beresp.grace = 1m;
- set beresp.cacheable = true;
}
} -start
diff --git a/bin/varnishtest/tests/s00003.vtc b/bin/varnishtest/tests/s00003.vtc
index 0d97a42..162f1b6 100644
--- a/bin/varnishtest/tests/s00003.vtc
+++ b/bin/varnishtest/tests/s00003.vtc
@@ -20,7 +20,6 @@ varnish v1 -vcl+backend {
sub vcl_fetch {
set beresp.ttl = 1s;
set beresp.grace = 10m;
- set beresp.cacheable = true;
if (beresp.http.foo == "2")
{
set beresp.saintmode = 2s;
diff --git a/lib/libvcl/generate.py b/lib/libvcl/generate.py
index 922ca94..d6f75e4 100755
--- a/lib/libvcl/generate.py
+++ b/lib/libvcl/generate.py
@@ -292,12 +292,6 @@ sp_variables = (
( 'fetch',),
'const struct sess *'
),
- ('beresp.cacheable',
- 'BOOL',
- ( 'fetch',),
- ( 'fetch',),
- 'const struct sess *'
- ),
('beresp.do_esi',
'BOOL',
( 'fetch',),
More information about the varnish-commit
mailing list