[master] 43da3e4a0 Add VRT_VCL_Busy() and VRT_VCL_Unbusy() so VMODs can prevent their VCL from going cold.
Poul-Henning Kamp
phk at FreeBSD.org
Tue Apr 23 10:28:07 UTC 2019
commit 43da3e4a015410558da851f7ae47a6c17d9d38b3
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Tue Apr 23 10:26:24 2019 +0000
Add VRT_VCL_Busy() and VRT_VCL_Unbusy() so VMODs can prevent
their VCL from going cold.
One half of #2471
diff --git a/bin/varnishd/cache/cache_vrt_vcl.c b/bin/varnishd/cache/cache_vrt_vcl.c
index 0137655f3..12f7843cf 100644
--- a/bin/varnishd/cache/cache_vrt_vcl.c
+++ b/bin/varnishd/cache/cache_vrt_vcl.c
@@ -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, ...)
diff --git a/bin/varnishtest/tests/r02471.vtc b/bin/varnishtest/tests/r02471.vtc
new file mode 100644
index 000000000..24c84ee1c
--- /dev/null
+++ b/bin/varnishtest/tests/r02471.vtc
@@ -0,0 +1,63 @@
+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"
diff --git a/include/vrt.h b/include/vrt.h
index e4e3b8841..cdf7bd12f 100644
--- a/include/vrt.h
+++ b/include/vrt.h
@@ -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);
diff --git a/lib/libvmod_debug/vmod.vcc b/lib/libvmod_debug/vmod.vcc
index 8c6ffad05..0cd1963c7 100644
--- a/lib/libvmod_debug/vmod.vcc
+++ b/lib/libvmod_debug/vmod.vcc
@@ -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
diff --git a/lib/libvmod_debug/vmod_debug.c b/lib/libvmod_debug/vmod_debug.c
index 51ba7dd03..fc9720a74 100644
--- a/lib/libvmod_debug/vmod_debug.c
+++ b/lib/libvmod_debug/vmod_debug.c
@@ -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);
+}
More information about the varnish-commit
mailing list