Commit 55b6e90d authored by Nils Goroll's avatar Nils Goroll

allow setting bereq.backend in vcl_backend_fetch

parent 43155054
varnishtest "VSLP director - same as v01000.vtc but setting backend in fetch"
server s1 {
rxreq
txresp -body "ech3Ooj"
} -start
server s2 {
rxreq
txresp -body "ieQu2qua"
} -start
server s3 {
rxreq
txresp -body "xiuFi3Pe"
} -start
varnish v1 -vcl+backend {
import vslp from "${vmod_topbuild}/src/.libs/libvmod_vslp.so" ;
sub vcl_init {
new vd = vslp.vslp();
vd.add_backend(s1);
vd.add_backend(s2);
vd.add_backend(s3);
vd.set_rampup_ratio(0);
vd.init_hashcircle(25);
}
sub vcl_backend_fetch {
set bereq.backend = vd.backend();
return(fetch);
}
} -start
client c1 {
txreq -url /eishoSu2
rxresp
expect resp.body == "ech3Ooj"
txreq -url /Zainao9d
rxresp
expect resp.body == "ieQu2qua"
txreq -url /Aunah3uo
rxresp
expect resp.body == "xiuFi3Pe"
} -run
......@@ -125,14 +125,20 @@ 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);
AN(ctx->http_req);
AN(ctx->http_req->hd);
/* 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(ctx->http_req->hd[HTTP_HDR_URL].b);
hash = vslpd->vslpd->hash_fp(http->hd[HTTP_HDR_URL].b);
be = vslpdir_pick_be(vslpd->vslpd, ctx, hash);
return (be);
......
......@@ -393,18 +393,19 @@ vslpdir_any_healthy(struct vslpdir *vslpd)
VCL_BACKEND vslpdir_pick_be(struct vslpdir *vslpd, const struct vrt_ctx *ctx, uint32_t hash)
{
VCL_BACKEND be;
int chosen, be_choice, restarts, n_retry = 0;
int chosen, be_choice, restarts_o, restarts, n_retry = 0;
struct vslp_state state;
CHECK_OBJ_NOTNULL(vslpd, VSLPDIR_MAGIC);
AN(ctx->req);
be_choice = (scalbn(random(), -31) > vslpd->altsrv_p);
if (ctx->bo)
restarts = ctx->bo->retries;
else
restarts = ctx->req->restarts;
if (ctx->bo) {
restarts = restarts_o = ctx->bo->retries;
} else {
AN(ctx->req);
restarts = restarts_o = ctx->req->restarts;
}
state.picklist = 0;
state.vslpd = vslpd;
......@@ -428,7 +429,7 @@ VCL_BACKEND vslpdir_pick_be(struct vslpdir *vslpd, const struct vrt_ctx *ctx, ui
if(restarts <= 0)
{
char msg[56];
sprintf(msg, "VSLP picked backend %2i for key %8x in restarts: %2i", chosen, hash, ctx->req->restarts);
sprintf(msg, "VSLP picked backend %2i for key %8x in restarts: %2i", chosen, hash, restarts_o);
vlog_debug(ctx, msg);
be = vslpd->backend[chosen];
AN(be);
......
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