Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
V
varnish-cache
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
varnishcache
varnish-cache
Commits
50aeefcc
Commit
50aeefcc
authored
Dec 04, 2015
by
Dridi Boukelmoune
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow VMODs to hold a reference on a warm VCL
parent
16b83752
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
52 additions
and
4 deletions
+52
-4
cache_vcl.c
bin/varnishd/cache/cache_vcl.c
+41
-3
vmod.rst
doc/sphinx/reference/vmod.rst
+8
-1
vrt.h
include/vrt.h
+3
-0
No files found.
bin/varnishd/cache/cache_vcl.c
View file @
50aeefcc
...
@@ -61,6 +61,7 @@ struct vcl {
...
@@ -61,6 +61,7 @@ struct vcl {
char
state
[
8
];
char
state
[
8
];
char
*
loaded_name
;
char
*
loaded_name
;
unsigned
busy
;
unsigned
busy
;
unsigned
refcount
;
unsigned
discard
;
unsigned
discard
;
const
char
*
temp
;
const
char
*
temp
;
VTAILQ_HEAD
(,
backend
)
backend_list
;
VTAILQ_HEAD
(,
backend
)
backend_list
;
...
@@ -244,6 +245,7 @@ vcl_KillBackends(struct vcl *vcl)
...
@@ -244,6 +245,7 @@ vcl_KillBackends(struct vcl *vcl)
CHECK_OBJ_NOTNULL
(
vcl
,
VCL_MAGIC
);
CHECK_OBJ_NOTNULL
(
vcl
,
VCL_MAGIC
);
AZ
(
vcl
->
busy
);
AZ
(
vcl
->
busy
);
AZ
(
vcl
->
refcount
);
while
(
1
)
{
while
(
1
)
{
be
=
VTAILQ_FIRST
(
&
vcl
->
backend_list
);
be
=
VTAILQ_FIRST
(
&
vcl
->
backend_list
);
if
(
be
==
NULL
)
if
(
be
==
NULL
)
...
@@ -366,6 +368,41 @@ VRT_count(VRT_CTX, unsigned u)
...
@@ -366,6 +368,41 @@ VRT_count(VRT_CTX, unsigned u)
ctx
->
vcl
->
conf
->
ref
[
u
].
line
,
ctx
->
vcl
->
conf
->
ref
[
u
].
pos
);
ctx
->
vcl
->
conf
->
ref
[
u
].
line
,
ctx
->
vcl
->
conf
->
ref
[
u
].
pos
);
}
}
void
VRT_ref_vcl
(
VRT_CTX
)
{
struct
vcl
*
vcl
;
ASSERT_CLI
();
CHECK_OBJ_NOTNULL
(
ctx
,
VRT_CTX_MAGIC
);
vcl
=
ctx
->
vcl
;
CHECK_OBJ_NOTNULL
(
vcl
,
VCL_MAGIC
);
xxxassert
(
vcl
->
temp
==
vcl_temp_warm
);
Lck_Lock
(
&
vcl_mtx
);
vcl
->
refcount
++
;
Lck_Unlock
(
&
vcl_mtx
);
}
void
VRT_rel_vcl
(
VRT_CTX
)
{
struct
vcl
*
vcl
;
CHECK_OBJ_NOTNULL
(
ctx
,
VRT_CTX_MAGIC
);
vcl
=
ctx
->
vcl
;
CHECK_OBJ_NOTNULL
(
vcl
,
VCL_MAGIC
);
assert
(
vcl
->
temp
==
vcl_temp_warm
||
vcl
->
temp
==
vcl_temp_cooling
);
Lck_Lock
(
&
vcl_mtx
);
assert
(
vcl
->
refcount
>
0
);
vcl
->
refcount
--
;
/* No garbage collection here, for the same reasons as in VCL_Rel. */
Lck_Unlock
(
&
vcl_mtx
);
}
/*--------------------------------------------------------------------*/
/*--------------------------------------------------------------------*/
static
struct
vcl
*
static
struct
vcl
*
...
@@ -402,7 +439,7 @@ vcl_set_state(struct vcl *vcl, const char *state)
...
@@ -402,7 +439,7 @@ vcl_set_state(struct vcl *vcl, const char *state)
vcl
->
temp
=
vcl_temp_cold
;
vcl
->
temp
=
vcl_temp_cold
;
if
(
vcl
->
temp
==
vcl_temp_cold
)
if
(
vcl
->
temp
==
vcl_temp_cold
)
break
;
break
;
if
(
vcl
->
busy
==
0
)
{
if
(
vcl
->
busy
==
0
&&
vcl
->
refcount
==
0
)
{
vcl
->
temp
=
vcl_temp_cold
;
vcl
->
temp
=
vcl_temp_cold
;
AZ
(
vcl
->
conf
->
event_vcl
(
&
ctx
,
VCL_EVENT_COLD
));
AZ
(
vcl
->
conf
->
event_vcl
(
&
ctx
,
VCL_EVENT_COLD
));
vcl_BackendEvent
(
vcl
,
VCL_EVENT_COLD
);
vcl_BackendEvent
(
vcl
,
VCL_EVENT_COLD
);
...
@@ -508,6 +545,7 @@ VCL_Nuke(struct vcl *vcl)
...
@@ -508,6 +545,7 @@ VCL_Nuke(struct vcl *vcl)
assert
(
vcl
!=
vcl_active
);
assert
(
vcl
!=
vcl_active
);
assert
(
vcl
->
discard
);
assert
(
vcl
->
discard
);
AZ
(
vcl
->
busy
);
AZ
(
vcl
->
busy
);
AZ
(
vcl
->
refcount
);
VTAILQ_REMOVE
(
&
vcl_head
,
vcl
,
list
);
VTAILQ_REMOVE
(
&
vcl_head
,
vcl
,
list
);
ctx
.
method
=
VCL_MET_FINI
;
ctx
.
method
=
VCL_MET_FINI
;
ctx
.
handling
=
&
hand
;
ctx
.
handling
=
&
hand
;
...
@@ -531,7 +569,7 @@ VCL_Poll(void)
...
@@ -531,7 +569,7 @@ VCL_Poll(void)
VTAILQ_FOREACH_SAFE
(
vcl
,
&
vcl_head
,
list
,
vcl2
)
{
VTAILQ_FOREACH_SAFE
(
vcl
,
&
vcl_head
,
list
,
vcl2
)
{
if
(
vcl
->
temp
==
vcl_temp_cooling
)
if
(
vcl
->
temp
==
vcl_temp_cooling
)
vcl_set_state
(
vcl
,
"0"
);
vcl_set_state
(
vcl
,
"0"
);
if
(
vcl
->
discard
&&
vcl
->
busy
==
0
)
if
(
vcl
->
discard
&&
vcl
->
busy
==
0
&&
vcl
->
refcount
==
0
)
VCL_Nuke
(
vcl
);
VCL_Nuke
(
vcl
);
}
}
}
}
...
@@ -602,7 +640,7 @@ ccf_config_discard(struct cli *cli, const char * const *av, void *priv)
...
@@ -602,7 +640,7 @@ ccf_config_discard(struct cli *cli, const char * const *av, void *priv)
vcl
->
discard
=
1
;
vcl
->
discard
=
1
;
Lck_Unlock
(
&
vcl_mtx
);
Lck_Unlock
(
&
vcl_mtx
);
if
(
vcl
->
busy
==
0
)
if
(
vcl
->
busy
==
0
&&
vcl
->
refcount
==
0
)
VCL_Nuke
(
vcl
);
VCL_Nuke
(
vcl
);
}
}
...
...
doc/sphinx/reference/vmod.rst
View file @
50aeefcc
...
@@ -383,6 +383,13 @@ first with a ``VCL_EVENT_WARM`` event. Unless a user decides that a given VCL
...
@@ -383,6 +383,13 @@ first with a ``VCL_EVENT_WARM`` event. Unless a user decides that a given VCL
should always be warm, an inactive VMOD will eventually become cold and should
should always be warm, an inactive VMOD will eventually become cold and should
manage resources accordingly.
manage resources accordingly.
If your VMOD is running an asynchronous background job you can hold a reference
to the VCL to prevent it from going cold too soon and get the same guarantees
as backends with ongoing requests for instance. For that, you must acquire the
reference by calling ``VRT_ref_vcl`` when you receive a ``VCL_EVENT_WARM`` and
later calling ``VRT_rel_vcl`` once the background job is over. Receiving a
``VCL_EVENT_COLD`` is your cue to terminate any background job bound to a VCL.
There is also a ``VCL_EVENT_USE`` event. Please note that this event is now
There is also a ``VCL_EVENT_USE`` event. Please note that this event is now
deprecated and may be removed in a future release. A warm VCL should be ready
deprecated and may be removed in a future release. A warm VCL should be ready
to use so no additional task should be postponed at use time.
to use so no additional task should be postponed at use time.
...
...
include/vrt.h
View file @
50aeefcc
...
@@ -295,6 +295,9 @@ struct vmod_priv {
...
@@ -295,6 +295,9 @@ struct vmod_priv {
typedef
int
vmod_event_f
(
VRT_CTX
,
struct
vmod_priv
*
,
enum
vcl_event_e
);
typedef
int
vmod_event_f
(
VRT_CTX
,
struct
vmod_priv
*
,
enum
vcl_event_e
);
#endif
#endif
void
VRT_ref_vcl
(
VRT_CTX
);
void
VRT_rel_vcl
(
VRT_CTX
);
void
VRT_priv_fini
(
const
struct
vmod_priv
*
p
);
void
VRT_priv_fini
(
const
struct
vmod_priv
*
p
);
struct
vmod_priv
*
VRT_priv_task
(
VRT_CTX
,
void
*
vmod_id
);
struct
vmod_priv
*
VRT_priv_task
(
VRT_CTX
,
void
*
vmod_id
);
struct
vmod_priv
*
VRT_priv_top
(
VRT_CTX
,
void
*
vmod_id
);
struct
vmod_priv
*
VRT_priv_top
(
VRT_CTX
,
void
*
vmod_id
);
...
...
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