Commit 43da3e4a authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Add VRT_VCL_Busy() and VRT_VCL_Unbusy() so VMODs can prevent

their VCL from going cold.

One half of #2471
parent f58469a7
......@@ -144,6 +144,28 @@ VCL_Rel(struct vcl **vcc)
/*--------------------------------------------------------------------*/
void
VRT_VCL_Busy(VRT_CTX)
{
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
CHECK_OBJ_NOTNULL(ctx->vcl, VCL_MAGIC);
VCL_Ref(ctx->vcl);
}
void
VRT_VCL_Unbusy(VRT_CTX)
{
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
struct vcl *vcl;
CHECK_OBJ_NOTNULL(ctx->vcl, VCL_MAGIC);
vcl = ctx->vcl;
VCL_Rel(&vcl);
}
/*--------------------------------------------------------------------*/
VCL_BACKEND
VRT_AddDirector(VRT_CTX, const struct vdi_methods *m, void *priv,
const char *fmt, ...)
......
varnishtest "test VRT_VCL_(Un)Busy()"
server s1 {
rxreq
txresp
} -start
varnish v1 -vcl+backend {
import debug;
sub vcl_recv {
if (req.url == "/hold") {
debug.hold_vcl_busy();
} else if (req.url == "/release") {
debug.release_vcl_busy();
}
return (synth(200));
}
} -start
varnish v1 -vcl+backend {}
varnish v1 -cliok "vcl.state vcl1 cold"
# Nothing holds vcl1, so it should go gold.
varnish v1 -cliexpect "cold cold 0 vcl1" "vcl.list"
# Grab hold of vcl1
varnish v1 -cliok "vcl.use vcl1"
client c1 {
txreq -url "/hold"
rxresp
} -run
# Flush worker threads hold
varnish v1 -cliok "vcl.use vcl2"
client c1 {
txreq
rxresp
} -run
# There should still be a single busy hold on vcl1
varnish v1 -cliok "vcl.state vcl1 cold"
varnish v1 -cliexpect "cold busy 1 vcl1" "vcl.list"
# Release hold on vcl1
varnish v1 -cliok "vcl.use vcl1"
client c1 {
txreq -url "/release"
rxresp
} -run
# Flush worker threads hold
varnish v1 -cliok "vcl.use vcl2"
client c1 {
txreq
rxresp
} -run
# Nothing holds vcl1, so it should go gold.
varnish v1 -cliok "vcl.state vcl1 cold"
varnish v1 -cliexpect "cold cold 0 vcl1" "vcl.list"
......@@ -52,6 +52,7 @@
* binary/load-time compatible, increment MAJOR version
*
* unreleased (planned for 2019-09-15)
* VRT_VCL_Busy() and VRT_VCL_Unbusy() added.
* VRT_vcl_get moved to vcc_interface.h
* VRT_vcl_rel emoved to vcc_interface.h
* VRT_vcl_select emoved to vcc_interface.h
......@@ -575,3 +576,10 @@ void VRT_VSC_Destroy(const char *, struct vsc_seg *);
void VRT_VSC_Hide(const struct vsc_seg *);
void VRT_VSC_Reveal(const struct vsc_seg *);
size_t VRT_VSC_Overhead(size_t);
/*
* API to prevent VCL from going cold
*/
void VRT_VCL_Busy(VRT_CTX);
void VRT_VCL_Unbusy(VRT_CTX);
......@@ -243,3 +243,11 @@ This function is by no means guaranteed to work cross platform and
should now only be used for diagnostic purposes.
0B is returned if no sensible value can be determined.
$Function VOID hold_vcl_busy()
Prevent VCL from going cold
$Function VOID release_vcl_busy()
Allow VCL to go cold
......@@ -793,3 +793,17 @@ xyzzy_stk(VRT_CTX)
return (0);
}
VCL_VOID
xyzzy_hold_vcl_busy(VRT_CTX)
{
VRT_VCL_Busy(ctx);
}
VCL_VOID
xyzzy_release_vcl_busy(VRT_CTX)
{
VRT_VCL_Unbusy(ctx);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment