[master] 15cc069 bring back beresp.storage_hint for vcl 4.0
Nils Goroll
nils.goroll at uplex.de
Mon Mar 5 19:03:10 UTC 2018
commit 15cc069bdc4ec7ff1925848b8cd8bfb2e9edeece
Author: Nils Goroll <nils.goroll at uplex.de>
Date: Mon Mar 5 20:00:04 2018 +0100
bring back beresp.storage_hint for vcl 4.0
see doc/changes.rst for details
Closes #2509
diff --git a/bin/varnishd/cache/cache_vrt_var.c b/bin/varnishd/cache/cache_vrt_var.c
index 1b071c9..d781ce7 100644
--- a/bin/varnishd/cache/cache_vrt_var.c
+++ b/bin/varnishd/cache/cache_vrt_var.c
@@ -365,6 +365,53 @@ VRT_l_beresp_storage(VRT_CTX, VCL_STEVEDORE stv)
ctx->bo->storage = stv;
}
+/*--------------------------------------------------------------------
+ * VCL <= 4.0 ONLY
+ */
+
+#include "storage/storage.h"
+
+const char *
+VRT_r_beresp_storage_hint(VRT_CTX)
+{
+ CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
+ CHECK_OBJ_NOTNULL(ctx->bo, BUSYOBJ_MAGIC);
+ if (ctx->bo->storage == NULL)
+ return (NULL);
+ CHECK_OBJ_NOTNULL(ctx->bo->storage, STEVEDORE_MAGIC);
+ return (ctx->bo->storage->vclname);
+}
+
+void
+VRT_l_beresp_storage_hint(VRT_CTX, const char *str, ...)
+{
+ const char *p;
+ va_list ap;
+ uintptr_t sn;
+ VCL_STEVEDORE stv;
+
+ CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
+ CHECK_OBJ_NOTNULL(ctx->bo, BUSYOBJ_MAGIC);
+
+ sn = WS_Snapshot(ctx->ws);
+ va_start(ap, str);
+ p = VRT_String(ctx->ws, NULL, str, ap);
+ va_end(ap);
+
+ if (p == NULL) {
+ VSLb(ctx->vsl, SLT_LostHeader, "storage_hint");
+ WS_MarkOverflow(ctx->ws);
+ WS_Reset(ctx->ws, sn);
+ return;
+ }
+
+ stv = VRT_stevedore(p);
+ if (stv != NULL)
+ ctx->bo->storage = stv;
+
+ WS_Reset(ctx->ws, sn);
+}
+
/*--------------------------------------------------------------------*/
VCL_STEVEDORE
diff --git a/bin/varnishtest/tests/c00078.vtc b/bin/varnishtest/tests/c00078.vtc
index f8d234a..9f14a77 100644
--- a/bin/varnishtest/tests/c00078.vtc
+++ b/bin/varnishtest/tests/c00078.vtc
@@ -1,6 +1,6 @@
varnishtest "Stevedores RR, beresp.storage"
-server s1 -repeat 6 {
+server s1 -repeat 7 {
rxreq
txresp
} -start
@@ -17,8 +17,11 @@ varnish v1 \
set beresp.storage = storage.s1;
} else if (bereq.url == "/6") {
set beresp.storage = vtc.no_stevedore();
+ } else if (bereq.url == "/deprecated") {
+ set beresp.storage_hint = "s1";
}
set beresp.http.storage = beresp.storage;
+ set beresp.http.storage-hint = beresp.storage_hint;
}
} -start
@@ -26,19 +29,38 @@ client c1 {
txreq -url /1
rxresp
expect resp.http.storage == "storage.s1"
+ expect resp.http.storage == resp.http.storage-hint
txreq -url /2
rxresp
expect resp.http.storage == "storage.s1"
+ expect resp.http.storage == resp.http.storage-hint
txreq -url /3
rxresp
expect resp.http.storage == "storage.s0"
+ expect resp.http.storage == resp.http.storage-hint
txreq -url /4
rxresp
expect resp.http.storage == "storage.s1"
+ expect resp.http.storage == resp.http.storage-hint
txreq -url /5
rxresp
expect resp.http.storage == "storage.s2"
+ expect resp.http.storage == resp.http.storage-hint
txreq -url /6
rxresp
expect resp.http.storage == <undef>
+ expect resp.http.storage == resp.http.storage-hint
+ txreq -url /deprecated
+ rxresp
+ expect resp.http.storage == "storage.s1"
+ expect resp.http.storage == resp.http.storage-hint
} -run
+
+varnish v1 \
+ -syntax 4.1 \
+ -errvcl "Only available when VCL syntax <= 4.0" {
+ import vtc;
+ sub vcl_backend_response {
+ set beresp.storage_hint = "foo";
+ }
+}
diff --git a/doc/changes.rst b/doc/changes.rst
index 7468107..6648e52 100644
--- a/doc/changes.rst
+++ b/doc/changes.rst
@@ -41,7 +41,17 @@ VCL and bundled VMODs
``req.hash_always_miss`` are now accessible from all of the client
side subs, not just ``vcl_recv{}``
-* Removed ``beresp.storage_hint`` (was deprecated since Varnish 5.1)
+* Removed ``beresp.storage_hint`` for VCL 4.1 (was deprecated since
+ Varnish 5.1)
+
+ For VCL 4.0, compatibility is preserved, but the implementation is
+ changed slightly: ``beresp.storage_hint`` is now referring to the
+ same internal data structure as ``beresp.storage``.
+
+ In particular, it was previously possible to set
+ ``beresp.storage_hint`` to an invalid storage name and later
+ retrieve it back. Doing so will now yield the last successfully set
+ stevedore or the undefined (``NULL``) string.
* workspace overflows in ``std.log()`` now trigger a VCL failure
diff --git a/doc/sphinx/reference/vcl_var.rst b/doc/sphinx/reference/vcl_var.rst
index 3d17078..37e88c9 100644
--- a/doc/sphinx/reference/vcl_var.rst
+++ b/doc/sphinx/reference/vcl_var.rst
@@ -868,6 +868,21 @@ beresp.storage
The storage backend to use to save this object.
+beresp.storage_hint ``VCL <= 4.0``
+
+ Type: STRING
+
+ Readable from: vcl_backend_response, vcl_backend_error
+
+ Writable from: vcl_backend_response, vcl_backend_error
+
+
+ Deprecated since varnish 5.1 and discontinued since VCL
+ 4.1 (varnish 6.0). Use beresp.storage instead.
+
+ Hint to Varnish that you want to save this object to a
+ particular storage backend.
+
obj
~~~
diff --git a/include/vrt.h b/include/vrt.h
index 9d67405..603d24f 100644
--- a/include/vrt.h
+++ b/include/vrt.h
@@ -61,8 +61,8 @@
* VRT_VSC_Overhead() added
* struct director.event added
* struct director.destroy added
- * VRT_r_beresp_storage_hint() removed - under discussion #2509
- * VRT_l_beresp_storage_hint() removed - under discussion #2509
+ * VRT_r_beresp_storage_hint() VCL <= 4.0 #2509
+ * VRT_l_beresp_storage_hint() VCL <= 4.0 #2509
* VRT_blob() added
* VCL_STRANDS added
* 6.1 (2017-09-15 aka 5.2)
More information about the varnish-commit
mailing list