From: phk Date: Mon, 28 Jan 2008 09:28:47 +0000 (+0000) Subject: Introduce obj.grace variable: X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=40a2703a36b1c5f0536a5b6152aa38995c76218f;p=varnish Introduce obj.grace variable: The amount of time after obj.ttl this object can be served, provided we are already trying to fetch a new copy. Nothing inspects this variable yet. git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@2391 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- diff --git a/varnish-cache/bin/varnishd/cache.h b/varnish-cache/bin/varnishd/cache.h index 594b3e7b..9e0c854e 100644 --- a/varnish-cache/bin/varnishd/cache.h +++ b/varnish-cache/bin/varnishd/cache.h @@ -256,6 +256,7 @@ struct object { double age; double entered; double ttl; + double grace; double prefetch; double last_modified; diff --git a/varnish-cache/bin/varnishd/cache_vrt.c b/varnish-cache/bin/varnishd/cache_vrt.c index 9e042fcd..d2e873f7 100644 --- a/varnish-cache/bin/varnishd/cache_vrt.c +++ b/varnish-cache/bin/varnishd/cache_vrt.c @@ -304,6 +304,29 @@ VRT_r_obj_ttl(const struct sess *sp) return (sp->obj->ttl - sp->t_req); } +/*-------------------------------------------------------------------- + * obj.grace is relative to obj.ttl, so no special magic is necessary. + */ + +void +VRT_l_obj_grace(const struct sess *sp, double a) +{ + + CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); + CHECK_OBJ_NOTNULL(sp->obj, OBJECT_MAGIC); /* XXX */ + if (a < 0) + a = 0; + sp->obj->grace = a; +} + +double +VRT_r_obj_grace(const struct sess *sp) +{ + CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); + CHECK_OBJ_NOTNULL(sp->obj, OBJECT_MAGIC); /* XXX */ + return (sp->obj->grace); +} + /*--------------------------------------------------------------------*/ /* XXX: the VCL_info messages has unexpected fractions on the ttl */ diff --git a/varnish-cache/include/vrt_obj.h b/varnish-cache/include/vrt_obj.h index ca2d8737..8594d775 100644 --- a/varnish-cache/include/vrt_obj.h +++ b/varnish-cache/include/vrt_obj.h @@ -40,6 +40,8 @@ unsigned VRT_r_obj_cacheable(const struct sess *); void VRT_l_obj_cacheable(const struct sess *, unsigned); double VRT_r_obj_ttl(const struct sess *); void VRT_l_obj_ttl(const struct sess *, double); +double VRT_r_obj_grace(const struct sess *); +void VRT_l_obj_grace(const struct sess *, double); double VRT_r_obj_prefetch(const struct sess *); void VRT_l_obj_prefetch(const struct sess *, double); double VRT_r_obj_lastuse(const struct sess *); diff --git a/varnish-cache/lib/libvcl/vcc_fixed_token.c b/varnish-cache/lib/libvcl/vcc_fixed_token.c index 70244946..62ae6638 100644 --- a/varnish-cache/lib/libvcl/vcc_fixed_token.c +++ b/varnish-cache/lib/libvcl/vcc_fixed_token.c @@ -539,6 +539,8 @@ vcl_output_lang_h(struct vsb *sb) vsb_cat(sb, "void VRT_l_obj_cacheable(const struct sess *, unsigned);\n"); vsb_cat(sb, "double VRT_r_obj_ttl(const struct sess *);\n"); vsb_cat(sb, "void VRT_l_obj_ttl(const struct sess *, double);\n"); + vsb_cat(sb, "double VRT_r_obj_grace(const struct sess *);\n"); + vsb_cat(sb, "void VRT_l_obj_grace(const struct sess *, double);\n"); vsb_cat(sb, "double VRT_r_obj_prefetch(const struct sess *);\n"); vsb_cat(sb, "void VRT_l_obj_prefetch(const struct sess *, double);\n"); vsb_cat(sb, "double VRT_r_obj_lastuse(const struct sess *);\n"); diff --git a/varnish-cache/lib/libvcl/vcc_gen_obj.tcl b/varnish-cache/lib/libvcl/vcc_gen_obj.tcl index 1e88b93f..ebc8b1d2 100755 --- a/varnish-cache/lib/libvcl/vcc_gen_obj.tcl +++ b/varnish-cache/lib/libvcl/vcc_gen_obj.tcl @@ -157,6 +157,11 @@ set spobj { { hit fetch discard timeout} "const struct sess *" } + { obj.grace + RW TIME + { hit fetch discard timeout} + "const struct sess *" + } { obj.prefetch RW RTIME { fetch prefetch } diff --git a/varnish-cache/lib/libvcl/vcc_obj.c b/varnish-cache/lib/libvcl/vcc_obj.c index a89e6853..4f006797 100644 --- a/varnish-cache/lib/libvcl/vcc_obj.c +++ b/varnish-cache/lib/libvcl/vcc_obj.c @@ -182,6 +182,13 @@ struct var vcc_vars[] = { 0, VCL_MET_HIT | VCL_MET_FETCH | VCL_MET_DISCARD | VCL_MET_TIMEOUT }, + { "obj.grace", TIME, 9, + "VRT_r_obj_grace(sp)", + "VRT_l_obj_grace(sp, ", + V_RW, + 0, + VCL_MET_HIT | VCL_MET_FETCH | VCL_MET_DISCARD | VCL_MET_TIMEOUT + }, { "obj.prefetch", RTIME, 12, "VRT_r_obj_prefetch(sp)", "VRT_l_obj_prefetch(sp, ",