Commit 6496bf75 authored by Nils Goroll's avatar Nils Goroll

rename NOW->DEEP, add resolve=SHALLOW

parent 107a46cb
...@@ -9,7 +9,8 @@ libvmod_cluster_la_LDFLAGS = $(VMOD_LDFLAGS) ...@@ -9,7 +9,8 @@ libvmod_cluster_la_LDFLAGS = $(VMOD_LDFLAGS)
libvmod_cluster_la_SOURCES = vmod_cluster.c libvmod_cluster_la_SOURCES = vmod_cluster.c
nodist_libvmod_cluster_la_SOURCES = \ nodist_libvmod_cluster_la_SOURCES = \
vcc_cluster_if.c \ vcc_cluster_if.c \
vcc_cluster_if.h vcc_cluster_if.h \
tbl_resolve.h
@BUILD_VMOD_CLUSTER@ @BUILD_VMOD_CLUSTER@
...@@ -26,7 +27,9 @@ AM_VTC_LOG_FLAGS = \ ...@@ -26,7 +27,9 @@ AM_VTC_LOG_FLAGS = \
TESTS = \ TESTS = \
vtc/cfg.vtc \ vtc/cfg.vtc \
vtc/now.vtc \ vtc/deep.vtc \
vtc/deep_stk.vtc \
vtc/shallow.vtc \
vtc/lazy.vtc vtc/lazy.vtc
# Documentation # Documentation
......
VMODENUM(LAZY)
VMODENUM(SHALLOW)
VMODENUM(DEEP)
VMODENUM(NOW)
#undef VMODENUM
...@@ -37,6 +37,21 @@ ...@@ -37,6 +37,21 @@
#include "vcc_cluster_if.h" #include "vcc_cluster_if.h"
enum resolve_e {
_RESOLVE_E_INVALID = 0,
#define VMODENUM(x) x,
#include "tbl_resolve.h"
_RESOLVE_E_MAX
};
static enum resolve_e
parse_resolve_e(VCL_ENUM e)
{
#define VMODENUM(n) if (e == vmod_enum_ ## n) return(n);
#include "tbl_resolve.h"
WRONG("illegal resolve enum");
}
struct vmod_cluster_cluster_param { struct vmod_cluster_cluster_param {
unsigned magic; unsigned magic;
#define VMOD_CLUSTER_CLUSTER_PARAM_MAGIC 0x3ba2a0d5 #define VMOD_CLUSTER_CLUSTER_PARAM_MAGIC 0x3ba2a0d5
...@@ -393,30 +408,50 @@ vmod_cluster_get_uncacheable_direct(VRT_CTX, ...@@ -393,30 +408,50 @@ vmod_cluster_get_uncacheable_direct(VRT_CTX,
return (pr->uncacheable_direct); return (pr->uncacheable_direct);
} }
static inline VCL_BACKEND
by_resolve(VRT_CTX, VCL_BACKEND r, enum resolve_e resolve)
{
switch (resolve) {
case SHALLOW:
return (r);
case DEEP:
return (VRT_DirectorResolve(ctx, r));
default:
WRONG("illegal resolve argument");
}
}
static VCL_BACKEND static VCL_BACKEND
cluster_resolve(VRT_CTX, cluster_resolve(VRT_CTX,
const struct vmod_cluster_cluster_param *pr) const struct vmod_cluster_cluster_param *pr, enum resolve_e resolve)
{ {
VCL_BACKEND r; VCL_BACKEND r;
if (pr->uncacheable_direct && ctx->bo && if (pr->uncacheable_direct && ctx->bo &&
(ctx->bo->do_pass || ctx->bo->uncacheable)) (ctx->bo->do_pass || ctx->bo->uncacheable))
return (pr->real); return (by_resolve(ctx, pr->real, resolve));
AN(pr->cluster); AN(pr->cluster);
r = VRT_DirectorResolve(ctx, pr->cluster); r = VRT_DirectorResolve(ctx, pr->cluster);
if (cluster_blacklisted(pr, r)) if (cluster_blacklisted(pr, r))
r = pr->real; return (by_resolve(ctx, pr->real, resolve));
switch (resolve) {
case SHALLOW:
return (pr->cluster);
case DEEP:
return (r); return (r);
default:
WRONG("illegal resolve argument");
}
} }
static VCL_BACKEND v_matchproto_(vdi_resolve_f) static VCL_BACKEND v_matchproto_(vdi_resolve_f)
vmod_cluster_resolve(VRT_CTX, VCL_BACKEND dir) vmod_cluster_resolve(VRT_CTX, VCL_BACKEND dir)
{ {
return (cluster_resolve(ctx, return (cluster_resolve(ctx,
cluster_task_param_r(ctx, dir->priv))); cluster_task_param_r(ctx, dir->priv), DEEP));
} }
VCL_BACKEND VCL_BACKEND
...@@ -430,16 +465,22 @@ vmod_cluster_backend(VRT_CTX, ...@@ -430,16 +465,22 @@ vmod_cluster_backend(VRT_CTX,
struct vmod_cluster_cluster_param *pl = NULL; struct vmod_cluster_cluster_param *pl = NULL;
void *spc = NULL; void *spc = NULL;
int nblack; int nblack;
enum resolve_e resolve = parse_resolve_e(arg->resolve);
// transitional only
if (resolve == NOW)
resolve = DEEP;
if (! modify) { if (! modify) {
if (arg->resolve == vmod_enum_LAZY) if (resolve == LAZY)
return (vc->dir); return (vc->dir);
return (vmod_cluster_resolve(ctx, vc->dir)); pr = cluster_task_param_r(ctx, vc);
return (cluster_resolve(ctx, pr, resolve));
} }
AN(modify); AN(modify);
if (arg->resolve == vmod_enum_LAZY && if (resolve == LAZY &&
(ctx->method & cluster_methods) == 0) { (ctx->method & cluster_methods) == 0) {
VRT_fail(ctx, "cluster.backend(resolve=LAZY)" VRT_fail(ctx, "cluster.backend(resolve=LAZY)"
" can not be called here"); " can not be called here");
...@@ -452,7 +493,7 @@ vmod_cluster_backend(VRT_CTX, ...@@ -452,7 +493,7 @@ vmod_cluster_backend(VRT_CTX,
char pstk[param_sz(pr, pr->nblack + 1)]; char pstk[param_sz(pr, pr->nblack + 1)];
nblack = pr->nblack; nblack = pr->nblack;
if (arg->resolve == vmod_enum_NOW) if (resolve == SHALLOW || resolve == DEEP)
spc = pstk; spc = pstk;
if (arg->valid_deny && arg->deny != NULL && if (arg->valid_deny && arg->deny != NULL &&
...@@ -475,10 +516,10 @@ vmod_cluster_backend(VRT_CTX, ...@@ -475,10 +516,10 @@ vmod_cluster_backend(VRT_CTX,
pr = pl = cluster_task_param_l(ctx, vc, nblack, spc); pr = pl = cluster_task_param_l(ctx, vc, nblack, spc);
pl->uncacheable_direct = arg->valid_uncacheable_direct; pl->uncacheable_direct = arg->valid_uncacheable_direct;
} }
if (arg->resolve == vmod_enum_LAZY) if (resolve == LAZY)
return (vc->dir); return (vc->dir);
return (cluster_resolve(ctx, pr)); return (cluster_resolve(ctx, pr, resolve));
} }
static VCL_BOOL static VCL_BOOL
......
...@@ -25,7 +25,7 @@ object from its cache or issue a request against a `real` backend. ...@@ -25,7 +25,7 @@ object from its cache or issue a request against a `real` backend.
For a shard director argument ``shard``, the following examples are For a shard director argument ``shard``, the following examples are
roughly equivalent if ``myself`` resolves to the local node roughly equivalent if ``myself`` resolves to the local node
* explicit VCL code with shard director ``resolve=now``:: * explicit VCL code with shard director ``resolve=NOW``::
sub vcl_init { sub vcl_init {
new shard = directors.shard(); new shard = directors.shard();
...@@ -168,25 +168,37 @@ Return the currently configured behaviour. ...@@ -168,25 +168,37 @@ Return the currently configured behaviour.
See :ref:`meth_ctx` for limitations. See :ref:`meth_ctx` for limitations.
$Method BACKEND .backend(ENUM {NOW, LAZY} resolve=LAZY, $Method BACKEND .backend(ENUM {LAZY, SHALLOW, DEEP, NOW} resolve=LAZY,
[ BACKEND deny ], [ BACKEND real ], [ BACKEND deny ], [ BACKEND real ],
[ BOOL uncacheable_direct ]) [ BOOL uncacheable_direct ])
Return a backend by the method described in the rest of this Return a backend by the method described in the rest of this
documentation, either as a reference to cluster director for documentation:
``resolve=LAZY`` or immediately for ``resolve=NOW``.
* for ``resolve=LAZY`` a reference to the cluster director, which can
still be reconfigured using the `set_*` method after the
`.backend()` call.
* for ``resolve=SHALLOW`` a reference to the `cluster` or `real`
backend
* for ``resolve=DEEP`` the actual backend which the `cluster` or
`real`backend resolve to. Only differs from ``resolve=SHALLOW`` for
director backends.
``resolve=NOW`` is identical to ``resolve=DEEP`` as a transitional
interface and will be removed in a future version.
The optional `deny`, `real` and `uncacheable_direct` arguments have The optional `deny`, `real` and `uncacheable_direct` arguments have
the same effect as calling the methods :ref:`func_cluster.deny`, the same effect as calling the methods :ref:`func_cluster.deny`,
:ref:`func_cluster.set_real` and :ref:`func_cluster.set_real` and
:ref:`func_cluster.set_uncacheable_direct` before the `.backend()` :ref:`func_cluster.set_uncacheable_direct` before the `.backend()`
method with ``resolve=LAZY``, but can also be used with method with ``resolve=LAZY``.
``resolve=NOW``.
Use of these arguments with ``resolve=LAZY`` is only allowed in Use of these arguments with ``resolve=LAZY`` is only allowed in
``vcl_backend_fetch {}`` and ``vcl_init {}``. ``vcl_backend_fetch {}`` and ``vcl_init {}``.
Calling with ``resolve=NOW`` is valid anywhere. Calling with ``resolve=DEEP`` and ``resolve=SHALLOW`` is valid anywhere.
SEE ALSO SEE ALSO
======== ========
......
varnishtest "vmod_cluster toy example with round-robin"
varnish v1 -vcl {
import cluster;
import directors;
backend s1 { .host = "${bad_backend}";}
backend s2 { .host = "${bad_backend}";}
backend s3 { .host = "${bad_backend}";}
sub vcl_init {
new rr = directors.round_robin();
rr.add_backend(s1);
rr.add_backend(s2);
new cl = cluster.cluster(rr.backend(), deny=s2, real=s3);
}
sub vcl_recv {
return (synth(200));
}
sub vcl_synth {
set resp.http.b1 = cl.backend(resolve=DEEP);
set resp.http.b2 = cl.backend(resolve=DEEP);
}
} -start
client c1 {
txreq
rxresp
expect resp.status == 200
expect resp.http.b1 == s1
expect resp.http.b2 == s3
} -run
varnishtest "vmod_cluster toy example with round-robin"
varnish v1 -vcl {
import cluster;
import directors;
backend s1 { .host = "${bad_backend}";}
backend s2 { .host = "${bad_backend}";}
sub vcl_init {
new rr = directors.round_robin();
rr.add_backend(s1);
rr.add_backend(s2);
new real = directors.round_robin();
new cl = cluster.cluster(rr.backend(), real=real.backend(), deny=s2);
}
sub vcl_recv {
return (synth(200));
}
sub vcl_synth {
set resp.http.b1 = cl.backend(resolve=SHALLOW);
set resp.http.b2 = cl.backend(resolve=SHALLOW);
}
} -start
client c1 {
txreq
rxresp
expect resp.status == 200
expect resp.http.b1 == rr
expect resp.http.b2 == real
} -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