Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
L
libvmod-vslp
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-vslp
Commits
78786ad8
Commit
78786ad8
authored
Dec 20, 2014
by
Julian Wiesener
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
named parameter for .backend and .hash_string
parent
beb631a8
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
39 additions
and
119 deletions
+39
-119
README.rst
README.rst
+12
-31
v01001.vtc
src/tests/v01001.vtc
+3
-3
v01004.vtc
src/tests/v01004.vtc
+5
-5
v01005.vtc
src/tests/v01005.vtc
+1
-1
v01006.vtc
src/tests/v01006.vtc
+1
-1
v01007.vtc
src/tests/v01007.vtc
+1
-1
vmod_vslp.c
src/vmod_vslp.c
+14
-71
vmod_vslp.vcc
src/vmod_vslp.vcc
+2
-6
No files found.
README.rst
View file @
78786ad8
...
@@ -8,7 +8,7 @@ Varnish Consistent Hashing Director Module
...
@@ -8,7 +8,7 @@ Varnish Consistent Hashing Director Module
:Author: Julian Wiesener
:Author: Julian Wiesener
:Date: 2014-07-16
:Date: 2014-07-16
:Version: 1.
0
:Version: 1.
1
:Manual section: 3
:Manual section: 3
.. _synopsis:
.. _synopsis:
...
@@ -147,42 +147,23 @@ Initializes the hash ring. This function must be called after all backends are
...
@@ -147,42 +147,23 @@ Initializes the hash ring. This function must be called after all backends are
added. The argument is the numbers of replicas the hash ring contains for each
added. The argument is the numbers of replicas the hash ring contains for each
backend.
backend.
INT .hash_string(STRING
, ENUM { CRC32, SHA256, RS }
)
INT .hash_string(STRING
string, ENUM { CRC32, SHA256, RS } alg
)
----------------------------------------------------
----------------------------------------------------
-----------
Returns the hash of its first argument using the hash
Returns the hash of its first argument using the hash
algorithm defined.
algorithm defined
, defaults to CRC32
.
BACKEND .backend()
------------------
Returns a backend based on the default hash of the request URL.
BACKEND .backend(INT nte, BOOL altsrv_p, BOOL healthy, INT hash)
----------------------------------------------------------------
BACKEND .backend_n(INT, BOOL, BOOL, INT)
Returns the nth backend with respect of altsrv_p and respect of its healthy
----------------------------
state for the given hash. All parameters are optional, the defaults are:
Returns the n-th backend (first parameter) with respect of altsrv_p (second
parameter) and respect of its healthy state (third parameter) for the given
hash (last parameter).
BACKEND .backend_by_int(INT)
----------------------------
Returns a backend based on the value of its parameter. The value should be
evenly distributet between 0 and MAX_INT to get a good distribution of requests.
BACKEND .backend_by_string(STRING)
----------------------------------
Returns a backend based on the default hash of its argument.
DEPRECATED: use .backend_by_int(hash_string()) instead
BACKEND .backend_by_string_hash(STRING, ENUM { CRC32, SHA256, RS })
-------------------------------------------------------------------
Returns a backend based on the hash of its first argument using the hash
nte=0 will pick the first backend under respect of VSLP rules
algorithm defined.
altsrv_p=ture
DEPRECATED: use .backend_by_int(hash_string()) instead
healthy=true
hash=0 will use a CRC32 of the request URL
LIMITATIONS
LIMITATIONS
...
...
src/tests/v01001.vtc
View file @
78786ad8
...
@@ -29,13 +29,13 @@ varnish v1 -vcl+backend {
...
@@ -29,13 +29,13 @@ varnish v1 -vcl+backend {
sub vcl_recv {
sub vcl_recv {
if(req.url == "/1") {
if(req.url == "/1") {
set req.backend_hint = vd.backend
_by_int(
1);
set req.backend_hint = vd.backend
(hash=
1);
}
}
if(req.url == "/2") {
if(req.url == "/2") {
set req.backend_hint = vd.backend
_by_int(
2147483647);
set req.backend_hint = vd.backend
(hash=
2147483647);
}
}
if(req.url == "/3") {
if(req.url == "/3") {
set req.backend_hint = vd.backend
_by_int(
4294967295);
set req.backend_hint = vd.backend
(hash=
4294967295);
}
}
return(pass);
return(pass);
}
}
...
...
src/tests/v01004.vtc
View file @
78786ad8
...
@@ -32,21 +32,21 @@ varnish v1 -vcl+backend {
...
@@ -32,21 +32,21 @@ varnish v1 -vcl+backend {
}
}
sub recv_sub {
sub recv_sub {
set req.backend_hint = vd.backend
_by_string_hash(req.http.X-Hash, RS
);
set req.backend_hint = vd.backend
(hash=vd.hash_string(req.http.X-Hash, RS)
);
}
}
sub vcl_recv {
sub vcl_recv {
if(req.url == "/1") {
if(req.url == "/1") {
set req.backend_hint = vd.backend
_by_string("/eishoSu2"
);
set req.backend_hint = vd.backend
(hash=vd.hash_string("/eishoSu2")
);
} else if (req.url == "/2") {
} else if (req.url == "/2") {
set req.backend_hint = vd.backend
_by_string_hash("/eishoSu2", SHA256
);
set req.backend_hint = vd.backend
(hash=vd.hash_string(alg=SHA256, string="/eishoSu2")
);
} else if (req.url == "/3") {
} else if (req.url == "/3") {
set req.http.X-Hash = "/oob3dahS";
set req.http.X-Hash = "/oob3dahS";
call recv_sub;
call recv_sub;
} else if (req.url == "/null_by_string") {
} else if (req.url == "/null_by_string") {
set req.backend_hint = vd.backend
_by_string(req.http.NonExistent
);
set req.backend_hint = vd.backend
(hash=vd.hash_string(req.http.NonExistent)
);
} else if (req.url == "/null_by_string_hash") {
} else if (req.url == "/null_by_string_hash") {
set req.backend_hint = vd.backend
_by_string_hash(req.http.NonExistent, SHA256
);
set req.backend_hint = vd.backend
(hash=vd.hash_string(req.http.NonExistent, SHA256)
);
}
}
return(pass);
return(pass);
}
}
...
...
src/tests/v01005.vtc
View file @
78786ad8
...
@@ -40,7 +40,7 @@ varnish v1 -vcl+backend {
...
@@ -40,7 +40,7 @@ varnish v1 -vcl+backend {
}
}
sub vcl_recv {
sub vcl_recv {
set req.backend_hint = vd.backend
_by_string("/eishoSu2"
);
set req.backend_hint = vd.backend
(hash=vd.hash_string("/eishoSu2")
);
if(req.url == "/2" && req.restarts > 0) {
if(req.url == "/2" && req.restarts > 0) {
unset req.http.vrstart;
unset req.http.vrstart;
}
}
...
...
src/tests/v01006.vtc
View file @
78786ad8
...
@@ -28,7 +28,7 @@ varnish v1 -vcl+backend {
...
@@ -28,7 +28,7 @@ varnish v1 -vcl+backend {
}
}
sub vcl_recv {
sub vcl_recv {
set req.backend_hint = vd.backend
_by_string("/eishoSu2"
);
set req.backend_hint = vd.backend
(hash=vd.hash_string("/eishoSu2")
);
return(pass);
return(pass);
}
}
...
...
src/tests/v01007.vtc
View file @
78786ad8
...
@@ -31,7 +31,7 @@ varnish v1 -vcl+backend {
...
@@ -31,7 +31,7 @@ varnish v1 -vcl+backend {
}
}
sub vcl_recv {
sub vcl_recv {
set req.backend_hint = vd.backend
_by_string("/eishoSu2"
);
set req.backend_hint = vd.backend
(hash=vd.hash_string("/eishoSu2")
);
return(pass);
return(pass);
}
}
...
...
src/vmod_vslp.c
View file @
78786ad8
...
@@ -136,84 +136,27 @@ vmod_vslp_hash_string(const struct vrt_ctx *ctx, struct vmod_vslp_vslp *vslpd, V
...
@@ -136,84 +136,27 @@ vmod_vslp_hash_string(const struct vrt_ctx *ctx, struct vmod_vslp_vslp *vslpd, V
return
(
hash
);
return
(
hash
);
}
}
VCL_BACKEND
__match_proto__
(
td_vslp_vslp_backend
)
vmod_vslp_backend
(
const
struct
vrt_ctx
*
ctx
,
struct
vmod_vslp_vslp
*
vslpd
)
{
uint32_t
hash
;
VCL_BACKEND
be
;
struct
http
*
http
;
CHECK_OBJ_NOTNULL
(
ctx
,
VRT_CTX_MAGIC
);
CHECK_OBJ_NOTNULL
(
vslpd
,
VMOD_VSLP_VSLP_MAGIC
);
/* client or backend context ? */
if
(
ctx
->
http_req
)
{
AN
(
http
=
ctx
->
http_req
);
}
else
{
AN
(
ctx
->
http_bereq
);
AN
(
http
=
ctx
->
http_bereq
);
}
hash
=
vslpd
->
vslpd
->
hash_fp
(
http
->
hd
[
HTTP_HDR_URL
].
b
);
be
=
vslpdir_pick_be
(
vslpd
->
vslpd
,
ctx
,
hash
,
0
,
true
,
true
);
return
(
be
);
}
VCL_BACKEND
__match_proto__
(
td_vslp_vslp_backend_n
)
VCL_BACKEND
__match_proto__
(
td_vslp_vslp_backend_n
)
vmod_vslp_backend
_n
(
const
struct
vrt_ctx
*
ctx
,
struct
vmod_vslp_vslp
*
vslpd
,
VCL_INT
n
,
VCL_BOOL
altsrv_p
,
VCL_BOOL
healthy
,
VCL_INT
i
)
vmod_vslp_backend
(
const
struct
vrt_ctx
*
ctx
,
struct
vmod_vslp_vslp
*
vslpd
,
VCL_INT
n
,
VCL_BOOL
altsrv_p
,
VCL_BOOL
healthy
,
VCL_INT
i
)
{
{
uint32_t
hash
=
(
uint32_t
)
i
;
VCL_BACKEND
be
;
VCL_BACKEND
be
;
CHECK_OBJ_NOTNULL
(
ctx
,
VRT_CTX_MAGIC
);
CHECK_OBJ_NOTNULL
(
ctx
,
VRT_CTX_MAGIC
);
CHECK_OBJ_NOTNULL
(
vslpd
,
VMOD_VSLP_VSLP_MAGIC
);
CHECK_OBJ_NOTNULL
(
vslpd
,
VMOD_VSLP_VSLP_MAGIC
);
be
=
vslpdir_pick_be
(
vslpd
->
vslpd
,
ctx
,
i
,
n
,
altsrv_p
,
healthy
);
if
(
!
hash
)
{
/* client or backend context ? */
return
(
be
);
struct
http
*
http
;
}
if
(
ctx
->
http_req
)
{
AN
(
http
=
ctx
->
http_req
);
VCL_BACKEND
__match_proto__
(
td_vslp_vslp_backend_by_int
)
}
else
{
vmod_vslp_backend_by_int
(
const
struct
vrt_ctx
*
ctx
,
struct
vmod_vslp_vslp
*
vslpd
,
VCL_INT
i
)
AN
(
ctx
->
http_bereq
);
{
AN
(
http
=
ctx
->
http_bereq
);
VCL_BACKEND
be
;
}
hash
=
vslpd
->
vslpd
->
hash_fp
(
http
->
hd
[
HTTP_HDR_URL
].
b
);
CHECK_OBJ_NOTNULL
(
ctx
,
VRT_CTX_MAGIC
);
}
CHECK_OBJ_NOTNULL
(
vslpd
,
VMOD_VSLP_VSLP_MAGIC
);
be
=
vslpdir_pick_be
(
vslpd
->
vslpd
,
ctx
,
hash
,
n
,
altsrv_p
,
healthy
);
be
=
vslpdir_pick_be
(
vslpd
->
vslpd
,
ctx
,
i
,
0
,
true
,
true
);
return
(
be
);
}
VCL_BACKEND
__match_proto__
(
td_vslp_vslp_backend_by_string
)
vmod_vslp_backend_by_string
(
const
struct
vrt_ctx
*
ctx
,
struct
vmod_vslp_vslp
*
vslpd
,
VCL_STRING
s
)
{
uint32_t
hash
;
VCL_BACKEND
be
;
CHECK_OBJ_NOTNULL
(
ctx
,
VRT_CTX_MAGIC
);
CHECK_OBJ_NOTNULL
(
vslpd
,
VMOD_VSLP_VSLP_MAGIC
);
hash
=
vslpd
->
vslpd
->
hash_fp
(
s
?
s
:
""
);
be
=
vslpdir_pick_be
(
vslpd
->
vslpd
,
ctx
,
hash
,
0
,
true
,
true
);
return
(
be
);
}
VCL_BACKEND
__match_proto__
(
td_vslp_vslp_backend_by_string_hash
)
vmod_vslp_backend_by_string_hash
(
const
struct
vrt_ctx
*
ctx
,
struct
vmod_vslp_vslp
*
vslpd
,
VCL_STRING
s
,
VCL_ENUM
hash_m
)
{
uint32_t
hash
;
hash_func
hash_fp
;
VCL_BACKEND
be
;
CHECK_OBJ_NOTNULL
(
ctx
,
VRT_CTX_MAGIC
);
CHECK_OBJ_NOTNULL
(
vslpd
,
VMOD_VSLP_VSLP_MAGIC
);
hash_fp
=
vslp_get_hash_fp
(
hash_m
);
hash
=
hash_fp
(
s
?
s
:
""
);
be
=
vslpdir_pick_be
(
vslpd
->
vslpd
,
ctx
,
hash
,
0
,
true
,
true
);
return
(
be
);
return
(
be
);
}
}
src/vmod_vslp.vcc
View file @
78786ad8
...
@@ -34,9 +34,5 @@ $Method VOID .set_rampup_ratio(REAL)
...
@@ -34,9 +34,5 @@ $Method VOID .set_rampup_ratio(REAL)
$Method VOID .set_rampup_time(DURATION)
$Method VOID .set_rampup_time(DURATION)
$Method VOID .set_hash(ENUM { CRC32, SHA256, RS })
$Method VOID .set_hash(ENUM { CRC32, SHA256, RS })
$Method VOID .init_hashcircle(INT)
$Method VOID .init_hashcircle(INT)
$Method INT .hash_string(STRING, ENUM { CRC32, SHA256, RS })
$Method INT .hash_string(STRING string, ENUM { CRC32, SHA256, RS } alg="CRC32")
$Method BACKEND .backend()
$Method BACKEND .backend(INT nte=0, BOOL altsrv_p=1, BOOL healthy=1, INT hash=0)
$Method BACKEND .backend_n(INT, BOOL, BOOL, INT)
$Method BACKEND .backend_by_int(INT)
$Method BACKEND .backend_by_string(STRING)
$Method BACKEND .backend_by_string_hash(STRING, ENUM { CRC32, SHA256, RS })
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