Commit 78786ad8 authored by Julian Wiesener's avatar Julian Wiesener

named parameter for .backend and .hash_string

parent beb631a8
......@@ -8,7 +8,7 @@ Varnish Consistent Hashing Director Module
:Author: Julian Wiesener
:Date: 2014-07-16
:Version: 1.0
:Version: 1.1
:Manual section: 3
.. _synopsis:
......@@ -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
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
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 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 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 a backend based on the hash of its first argument using the hash
algorithm defined.
DEPRECATED: use .backend_by_int(hash_string()) instead
nte=0 will pick the first backend under respect of VSLP rules
altsrv_p=ture
healthy=true
hash=0 will use a CRC32 of the request URL
LIMITATIONS
......
......@@ -29,13 +29,13 @@ varnish v1 -vcl+backend {
sub vcl_recv {
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") {
set req.backend_hint = vd.backend_by_int(2147483647);
set req.backend_hint = vd.backend(hash=2147483647);
}
if(req.url == "/3") {
set req.backend_hint = vd.backend_by_int(4294967295);
set req.backend_hint = vd.backend(hash=4294967295);
}
return(pass);
}
......
......@@ -32,21 +32,21 @@ varnish v1 -vcl+backend {
}
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 {
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") {
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") {
set req.http.X-Hash = "/oob3dahS";
call recv_sub;
} 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") {
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);
}
......
......@@ -40,7 +40,7 @@ varnish v1 -vcl+backend {
}
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) {
unset req.http.vrstart;
}
......
......@@ -28,7 +28,7 @@ varnish v1 -vcl+backend {
}
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);
}
......
......@@ -31,7 +31,7 @@ varnish v1 -vcl+backend {
}
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);
}
......
......@@ -136,84 +136,27 @@ vmod_vslp_hash_string(const struct vrt_ctx *ctx, struct vmod_vslp_vslp *vslpd, V
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)
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;
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
CHECK_OBJ_NOTNULL(vslpd, VMOD_VSLP_VSLP_MAGIC);
be = vslpdir_pick_be(vslpd->vslpd, ctx, i, n, altsrv_p, healthy);
return (be);
}
VCL_BACKEND __match_proto__(td_vslp_vslp_backend_by_int)
vmod_vslp_backend_by_int(const struct vrt_ctx *ctx, struct vmod_vslp_vslp *vslpd, VCL_INT i)
{
VCL_BACKEND be;
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
CHECK_OBJ_NOTNULL(vslpd, VMOD_VSLP_VSLP_MAGIC);
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);
if(!hash) {
/* client or backend context ? */
struct http *http;
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, n, altsrv_p, healthy);
return (be);
}
......@@ -34,9 +34,5 @@ $Method VOID .set_rampup_ratio(REAL)
$Method VOID .set_rampup_time(DURATION)
$Method VOID .set_hash(ENUM { CRC32, SHA256, RS })
$Method VOID .init_hashcircle(INT)
$Method INT .hash_string(STRING, ENUM { CRC32, SHA256, RS })
$Method BACKEND .backend()
$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 })
$Method INT .hash_string(STRING string, ENUM { CRC32, SHA256, RS } alg="CRC32")
$Method BACKEND .backend(INT nte=0, BOOL altsrv_p=1, BOOL healthy=1, INT hash=0)
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