Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
L
libvmod-cluster
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
uplex-varnish
libvmod-cluster
Commits
6496bf75
Commit
6496bf75
authored
Jun 21, 2018
by
Nils Goroll
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
rename NOW->DEEP, add resolve=SHALLOW
parent
107a46cb
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
146 additions
and
21 deletions
+146
-21
Makefile.am
src/Makefile.am
+5
-2
tbl_resolve.h
src/tbl_resolve.h
+5
-0
vmod_cluster.c
src/vmod_cluster.c
+53
-12
vmod_cluster.vcc
src/vmod_cluster.vcc
+19
-7
deep.vtc
src/vtc/deep.vtc
+0
-0
deep_stk.vtc
src/vtc/deep_stk.vtc
+32
-0
shallow.vtc
src/vtc/shallow.vtc
+32
-0
No files found.
src/Makefile.am
View file @
6496bf75
...
...
@@ -9,7 +9,8 @@ libvmod_cluster_la_LDFLAGS = $(VMOD_LDFLAGS)
libvmod_cluster_la_SOURCES
=
vmod_cluster.c
nodist_libvmod_cluster_la_SOURCES
=
\
vcc_cluster_if.c
\
vcc_cluster_if.h
vcc_cluster_if.h
\
tbl_resolve.h
@BUILD_VMOD_CLUSTER@
...
...
@@ -26,7 +27,9 @@ AM_VTC_LOG_FLAGS = \
TESTS
=
\
vtc/cfg.vtc
\
vtc/now.vtc
\
vtc/deep.vtc
\
vtc/deep_stk.vtc
\
vtc/shallow.vtc
\
vtc/lazy.vtc
# Documentation
...
...
src/tbl_resolve.h
0 → 100644
View file @
6496bf75
VMODENUM
(
LAZY
)
VMODENUM
(
SHALLOW
)
VMODENUM
(
DEEP
)
VMODENUM
(
NOW
)
#undef VMODENUM
src/vmod_cluster.c
View file @
6496bf75
...
...
@@ -37,6 +37,21 @@
#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
{
unsigned
magic
;
#define VMOD_CLUSTER_CLUSTER_PARAM_MAGIC 0x3ba2a0d5
...
...
@@ -393,30 +408,50 @@ vmod_cluster_get_uncacheable_direct(VRT_CTX,
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
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
;
if
(
pr
->
uncacheable_direct
&&
ctx
->
bo
&&
(
ctx
->
bo
->
do_pass
||
ctx
->
bo
->
uncacheable
))
return
(
pr
->
real
);
return
(
by_resolve
(
ctx
,
pr
->
real
,
resolve
)
);
AN
(
pr
->
cluster
);
r
=
VRT_DirectorResolve
(
ctx
,
pr
->
cluster
);
if
(
cluster_blacklisted
(
pr
,
r
))
r
=
pr
->
real
;
return
(
r
);
return
(
by_resolve
(
ctx
,
pr
->
real
,
resolve
));
switch
(
resolve
)
{
case
SHALLOW
:
return
(
pr
->
cluster
);
case
DEEP
:
return
(
r
);
default:
WRONG
(
"illegal resolve argument"
);
}
}
static
VCL_BACKEND
v_matchproto_
(
vdi_resolve_f
)
vmod_cluster_resolve
(
VRT_CTX
,
VCL_BACKEND
dir
)
{
return
(
cluster_resolve
(
ctx
,
cluster_task_param_r
(
ctx
,
dir
->
priv
)));
cluster_task_param_r
(
ctx
,
dir
->
priv
)
,
DEEP
));
}
VCL_BACKEND
...
...
@@ -430,16 +465,22 @@ vmod_cluster_backend(VRT_CTX,
struct
vmod_cluster_cluster_param
*
pl
=
NULL
;
void
*
spc
=
NULL
;
int
nblack
;
enum
resolve_e
resolve
=
parse_resolve_e
(
arg
->
resolve
);
// transitional only
if
(
resolve
==
NOW
)
resolve
=
DEEP
;
if
(
!
modify
)
{
if
(
arg
->
resolve
==
vmod_enum_
LAZY
)
if
(
resolve
==
LAZY
)
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
);
if
(
arg
->
resolve
==
vmod_enum_
LAZY
&&
if
(
resolve
==
LAZY
&&
(
ctx
->
method
&
cluster_methods
)
==
0
)
{
VRT_fail
(
ctx
,
"cluster.backend(resolve=LAZY)"
" can not be called here"
);
...
...
@@ -452,7 +493,7 @@ vmod_cluster_backend(VRT_CTX,
char
pstk
[
param_sz
(
pr
,
pr
->
nblack
+
1
)];
nblack
=
pr
->
nblack
;
if
(
arg
->
resolve
==
vmod_enum_NOW
)
if
(
resolve
==
SHALLOW
||
resolve
==
DEEP
)
spc
=
pstk
;
if
(
arg
->
valid_deny
&&
arg
->
deny
!=
NULL
&&
...
...
@@ -475,10 +516,10 @@ vmod_cluster_backend(VRT_CTX,
pr
=
pl
=
cluster_task_param_l
(
ctx
,
vc
,
nblack
,
spc
);
pl
->
uncacheable_direct
=
arg
->
valid_uncacheable_direct
;
}
if
(
arg
->
resolve
==
vmod_enum_
LAZY
)
if
(
resolve
==
LAZY
)
return
(
vc
->
dir
);
return
(
cluster_resolve
(
ctx
,
pr
));
return
(
cluster_resolve
(
ctx
,
pr
,
resolve
));
}
static
VCL_BOOL
...
...
src/vmod_cluster.vcc
View file @
6496bf75
...
...
@@ -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
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 {
new shard = directors.shard();
...
...
@@ -168,25 +168,37 @@ Return the currently configured behaviour.
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 ],
[ BOOL uncacheable_direct ])
Return a backend by the method described in the rest of this
documentation, either as a reference to cluster director for
``resolve=LAZY`` or immediately for ``resolve=NOW``.
documentation:
* 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 same effect as calling the methods :ref:`func_cluster.deny`,
:ref:`func_cluster.set_real` and
:ref:`func_cluster.set_uncacheable_direct` before the `.backend()`
method with ``resolve=LAZY``, but can also be used with
``resolve=NOW``.
method with ``resolve=LAZY``.
Use of these arguments with ``resolve=LAZY`` is only allowed in
``vcl_backend_fetch {}`` and ``vcl_init {}``.
Calling with ``resolve=
N
OW`` is valid anywhere.
Calling with ``resolve=
DEEP`` and ``resolve=SHALL
OW`` is valid anywhere.
SEE ALSO
========
...
...
src/vtc/
now
.vtc
→
src/vtc/
deep
.vtc
View file @
6496bf75
File moved
src/vtc/deep_stk.vtc
0 → 100644
View file @
6496bf75
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
src/vtc/shallow.vtc
0 → 100644
View file @
6496bf75
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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment