Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
U
unique-xids
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
uplex-varnish
unique-xids
Commits
a21746d2
Commit
a21746d2
authored
Mar 02, 2011
by
Poul-Henning Kamp
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Unify .grace and .ttl VCL variable handling
parent
3101d97c
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
53 additions
and
82 deletions
+53
-82
cache.h
bin/varnishd/cache.h
+5
-0
cache_expire.c
bin/varnishd/cache_expire.c
+39
-0
cache_vrt_var.c
bin/varnishd/cache_vrt_var.c
+8
-81
b00030.vtc
bin/varnishtest/tests/b00030.vtc
+1
-1
No files found.
bin/varnishd/cache.h
View file @
a21746d2
...
...
@@ -633,6 +633,11 @@ extern pthread_t cli_thread;
#define ASSERT_CLI() do {assert(pthread_self() == cli_thread);} while (0)
/* cache_expiry.c */
double
EXP_Get_grace
(
const
struct
exp
*
e
);
double
EXP_Get_ttl
(
const
struct
exp
*
e
);
void
EXP_Set_grace
(
struct
exp
*
e
,
double
v
);
void
EXP_Set_ttl
(
struct
exp
*
e
,
double
v
);
double
EXP_Grace
(
double
g
);
void
EXP_Insert
(
struct
object
*
o
);
void
EXP_Inject
(
struct
objcore
*
oc
,
struct
lru
*
lru
,
double
when
);
...
...
bin/varnishd/cache_expire.c
View file @
a21746d2
...
...
@@ -59,8 +59,47 @@ static struct lock exp_mtx;
/*--------------------------------------------------------------------
* struct exp manipulations
*
* The Get/Set functions encapsulate the mutual magic between the
* fields in one single place.
*/
void
EXP_Set_grace
(
struct
exp
*
e
,
double
v
)
{
if
(
v
>
0
.)
e
->
grace
=
v
;
else
e
->
grace
=
NAN
;
}
double
EXP_Get_grace
(
const
struct
exp
*
e
)
{
return
(
e
->
grace
>
0
.
?
e
->
grace
:
-
1
.);
}
void
EXP_Set_ttl
(
struct
exp
*
e
,
double
v
)
{
if
(
v
>
0
.)
e
->
ttl
=
v
;
else
{
e
->
ttl
=
-
1
.;
e
->
grace
=
NAN
;
}
}
double
EXP_Get_ttl
(
const
struct
exp
*
e
)
{
return
(
e
->
ttl
>
0
.
?
e
->
ttl
:
-
1
.);
}
double
EXP_Grace
(
double
g
)
{
...
...
bin/varnishd/cache_vrt_var.c
View file @
a21746d2
...
...
@@ -363,105 +363,32 @@ VRT_r_req_restarts(const struct sess *sp)
return
(
sp
->
restarts
);
}
/*--------------------------------------------------------------------
* ttl and grace have special magical relationships, encapsulated in
* cache_expire.c
*/
void
VRT_l_obj_ttl
(
const
struct
sess
*
sp
,
double
a
)
{
CHECK_OBJ_NOTNULL
(
sp
,
SESS_MAGIC
);
CHECK_OBJ_NOTNULL
(
sp
->
obj
,
OBJECT_MAGIC
);
/* XXX */
if
(
sp
->
obj
->
objcore
==
NULL
)
return
;
WSP
(
sp
,
SLT_TTL
,
"%u VCL %.0f %.0f"
,
sp
->
obj
->
xid
,
a
,
sp
->
t_req
);
/*
* If people set obj.ttl = 0s, they don't expect it to be cacheable
* any longer, but it will still be for up to 1s - epsilon because
* of the rounding to seconds.
* We special case and make sure that rounding does not surprise.
*/
if
(
a
<=
0
)
{
sp
->
obj
->
exp
.
ttl
=
-
1
.;
sp
->
obj
->
exp
.
grace
=
0
.;
}
else
sp
->
obj
->
exp
.
ttl
=
a
;
EXP_Rearm
(
sp
->
obj
);
}
double
VRT_r_obj_ttl
(
const
struct
sess
*
sp
)
{
CHECK_OBJ_NOTNULL
(
sp
,
SESS_MAGIC
);
CHECK_OBJ_NOTNULL
(
sp
->
obj
,
OBJECT_MAGIC
);
/* XXX */
if
(
sp
->
obj
->
objcore
==
NULL
)
return
(
0
.
0
);
return
(
sp
->
obj
->
exp
.
ttl
);
}
/*--------------------------------------------------------------------
* XXX: Working relative to t_req is maybe not the right thing, we could
* XXX: have spent a long time talking to the backend since then.
* XXX: It might make sense to cache a timestamp as "current time"
* XXX: before vcl_recv (== t_req) and vcl_fetch.
* XXX: On the other hand, that might lead to inconsistent behaviour
* XXX: where an object expires while we are running VCL code, and
* XXX: and that may not be a good idea either.
* XXX: See also related t_req use in cache_hash.c
*/
void
VRT_l_beresp_ttl
(
const
struct
sess
*
sp
,
double
a
)
{
CHECK_OBJ_NOTNULL
(
sp
,
SESS_MAGIC
);
WSP
(
sp
,
SLT_TTL
,
"%u VCL %.0f %.0f"
,
sp
->
xid
,
a
,
sp
->
t_req
);
/*
* If people set obj.ttl = 0s, they don't expect it to be cacheable
* any longer, but it will still be for up to 1s - epsilon because
* of the rounding to seconds.
* We special case and make sure that rounding does not surprise.
*/
if
(
a
<=
0
)
{
sp
->
wrk
->
exp
.
ttl
=
-
1
.;
sp
->
wrk
->
exp
.
grace
=
0
.;
}
else
sp
->
wrk
->
exp
.
ttl
=
a
;
}
double
VRT_r_beresp_ttl
(
const
struct
sess
*
sp
)
{
CHECK_OBJ_NOTNULL
(
sp
,
SESS_MAGIC
);
return
(
sp
->
wrk
->
exp
.
ttl
);
}
/*--------------------------------------------------------------------*/
#define VRT_DO_EXP(which, exp, fld, extra) \
\
void __match_proto__() \
VRT_l_##which##_
grace
(struct sess *sp, double a) \
VRT_l_##which##_
##fld
(struct sess *sp, double a) \
{ \
\
CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); \
exp.fld = a >= 0.0 ? a : NAN;
\
EXP_Set_##fld(&exp, a);
\
extra; \
} \
\
double __match_proto__() \
VRT_r_##which##_
grace
(struct sess *sp) \
VRT_r_##which##_
##fld
(struct sess *sp) \
{ \
\
CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); \
return(EXP_G
race(exp.fld
)); \
return(EXP_G
et_##fld(&exp
)); \
}
VRT_DO_EXP
(
req
,
sp
->
exp
,
grace
,
)
VRT_DO_EXP
(
obj
,
sp
->
obj
->
exp
,
grace
,
EXP_Rearm
(
sp
->
obj
))
VRT_DO_EXP
(
obj
,
sp
->
obj
->
exp
,
ttl
,
EXP_Rearm
(
sp
->
obj
))
VRT_DO_EXP
(
beresp
,
sp
->
wrk
->
exp
,
grace
,
)
VRT_DO_EXP
(
beresp
,
sp
->
wrk
->
exp
,
ttl
,
)
/*--------------------------------------------------------------------
* req.xid
...
...
bin/varnishtest/tests/b00030.vtc
View file @
a21746d2
...
...
@@ -21,5 +21,5 @@ varnish v1 -vcl+backend {
client c1 {
txreq
rxresp
expect resp.msg == "
10
.000"
expect resp.msg == "
-1
.000"
} -run
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment