Commit 31cecd8a authored by Nils Goroll's avatar Nils Goroll

add a switch to always go to the real backend

This is useful for VCL simplification
parent eb36c34f
......@@ -30,6 +30,7 @@ TESTS = \
vtc/cfg.vtc \
vtc/deep.vtc \
vtc/deep_stk.vtc \
vtc/direct.vtc \
vtc/shallow.vtc \
vtc/lazy.vtc \
vtc/lazy_shard.vtc
......
......@@ -83,6 +83,7 @@ struct vmod_cluster_cluster_param {
unsigned magic;
#define VMOD_CLUSTER_CLUSTER_PARAM_MAGIC 0x3ba2a0d5
VCL_BOOL uncacheable_direct;
VCL_BOOL direct;
VCL_BACKEND cluster;
VCL_BACKEND real;
int nblack;
......@@ -439,6 +440,19 @@ vmod_cluster_get_uncacheable_direct(VRT_CTX, struct vmod_cluster_cluster *vc)
CLUSTER_R(ctx, vc, uncacheable_direct, 0);
}
VCL_VOID
vmod_cluster_set_direct(VRT_CTX,
struct vmod_cluster_cluster *vc, VCL_BOOL bool)
{
CLUSTER_L(ctx, vc, direct, bool);
}
VCL_BOOL
vmod_cluster_get_direct(VRT_CTX, struct vmod_cluster_cluster *vc)
{
CLUSTER_R(ctx, vc, direct, 0);
}
static inline VCL_BACKEND
by_resolve(VRT_CTX, VCL_BACKEND r, enum resolve_e resolve)
{
......@@ -458,7 +472,8 @@ cluster_resolve(VRT_CTX,
{
VCL_BACKEND r;
if (pr->uncacheable_direct && ctx->bo &&
if (pr->direct ||
pr->uncacheable_direct && ctx->bo &&
(ctx->bo->do_pass || ctx->bo->uncacheable))
return (by_resolve(ctx, pr->real, resolve));
......
......@@ -172,6 +172,21 @@ Return the currently configured behaviour.
See :ref:`meth_ctx` for limitations.
$Method VOID .set_direct(BOOL)
A ``true`` argument instructs the director to select a `real` backend
always.
A ``false`` argument restores the original behavior.
See :ref:`meth_ctx` for limitations.
$Method BOOL .get_direct()
Return the current `direct` value as set with :ref:`func_cluster.get_direct`.
See :ref:`meth_ctx` for limitations.
$Method BACKEND .backend(ENUM {LAZY, SHALLOW, DEEP, NOW} resolve=LAZY,
[ BACKEND deny ], [ BACKEND real ],
[ BOOL uncacheable_direct ])
......
varnishtest "vmod_cluster test shard director layering and backend.list"
server s1 {
} -start
server s2 {
}
server s3 -repeat 2 -keepalive {
rxreq
txresp
} -start
varnish v1 -vcl+backend {
import cluster;
import directors;
sub vcl_init {
new shard = directors.shard();
shard.add_backend(s1);
shard.add_backend(s2);
shard.reconfigure();
new cl = cluster.cluster(shard.backend(), deny=s2, real=s3);
cl.set_uncacheable_direct(false);
}
sub vcl_recv {
return (pass);
}
sub vcl_backend_fetch {
set bereq.http.shard = shard.backend();
set bereq.http.unc = cl.get_uncacheable_direct();
set bereq.http.dir1 = cl.get_direct();
cl.set_direct(bereq.http.shard != "s2");
set bereq.backend = cl.backend();
set bereq.http.dir2 = cl.get_direct();
}
sub vcl_backend_response {
set beresp.http.shard = bereq.http.shard;
set beresp.http.unc = bereq.http.unc;
set beresp.http.backend = beresp.backend;
set beresp.http.dir1 = bereq.http.dir1;
set beresp.http.dir2 = bereq.http.dir2;
}
} -start
varnish v1 -cliexpect "shard.*healthy" "backend.list"
varnish v1 -cliexpect "cl.*healthy" "backend.list"
client c1 {
txreq
rxresp
expect resp.status == 200
expect resp.http.unc == "false"
expect resp.http.shard == "s2"
expect resp.http.backend == "s3"
expect resp.http.dir1 == "false"
expect resp.http.dir2 == "false"
txreq -url "/foo"
rxresp
expect resp.status == 200
expect resp.http.unc == "false"
expect resp.http.shard == "s1"
expect resp.http.backend == "s3"
expect resp.http.dir1 == "false"
expect resp.http.dir2 == "true"
} -run
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