Mailing List Archive

#1625: if(req.backend_hint == b1) compiles, but does nothing
#1625: if(req.backend_hint == b1) compiles, but does nothing
-------------------------+--------------------
Reporter: huguesalary | Type: defect
Status: new | Priority: normal
Milestone: | Component: build
Version: 4.0.2 | Severity: normal
Keywords: |
-------------------------+--------------------
In vcl_deliver, I'm currently trying to detect which backend a request was
sent to.

I originally tried to detect which **director** a request was assigned to,
but I found this bug report: https://www.varnish-
cache.org/trac/ticket/1502 and realized that doing {{{ if (
req.backend_hint == name-of-director ) { } }}} is not possible, and **will
never be**.

However, the following code snippet compiles correctly, but does not
actually work:

{{{

backend b0 {
.host = "127.0.0.1";
.port = "80";
}
backend b1 {
.host = "127.0.0.1";
.port = "80";
}

sub vcl_init {
new a = directors.round_robin();
a.add_backend(b0);

new b = directors.round_robin();
b.add_backend(b1);
}

sub vcl_recv {
if(std.random(1,100) <= 50) {
set req.backend_hint = a.backend();
} else {
set req.backend_hint = b.backend();
}
}

sub vcl_deliver {
if(req.backend_hint == b1)
{
set resp.http.Test = "something;
} else {
set resp.http.Test = "something else";
}
}
}}}

The {{{ if }}} condition in //vcl_deliver// always fails and executes the
{{{ else }}}. My guess is that my code is not valid (and will never be),
however, if that is the case, I'd expect it to not compile.

--
Ticket URL: <https://www.varnish-cache.org/trac/ticket/1625>
Varnish <https://varnish-cache.org/>
The Varnish HTTP Accelerator

_______________________________________________
varnish-bugs mailing list
varnish-bugs@varnish-cache.org
https://www.varnish-cache.org/lists/mailman/listinfo/varnish-bugs
Re: #1625: if(req.backend_hint == b1) compiles, but does nothing [ In reply to ]
#1625: if(req.backend_hint == b1) compiles, but does nothing
-------------------------+--------------------
Reporter: huguesalary | Owner:
Type: defect | Status: new
Priority: normal | Milestone:
Component: build | Version: 4.0.2
Severity: normal | Resolution:
Keywords: |
-------------------------+--------------------

Comment (by lkarsten):

Comparing with req.backend_hint isn't the way to go.

You should tag your object with beresp.backend.name in
vcl_backend_response, and compare with that instead.

--
Ticket URL: <https://www.varnish-cache.org/trac/ticket/1625#comment:1>
Varnish <https://varnish-cache.org/>
The Varnish HTTP Accelerator

_______________________________________________
varnish-bugs mailing list
varnish-bugs@varnish-cache.org
https://www.varnish-cache.org/lists/mailman/listinfo/varnish-bugs
Re: #1625: if(req.backend_hint == b1) compiles, but does nothing [ In reply to ]
#1625: if(req.backend_hint == b1) compiles, but does nothing
-------------------------+--------------------
Reporter: huguesalary | Owner:
Type: defect | Status: new
Priority: normal | Milestone:
Component: build | Version: 4.0.2
Severity: normal | Resolution:
Keywords: |
-------------------------+--------------------

Comment (by fgsch):

I think the issue here is more about semantics than anything else.
req.backend_hints is type BACKEND.

You assign a backend and read the backend name back.

If you assign a backend via a director, however, you get the director's
name back. This might not be a problem except that you cannot compare it
against a director or specific backend within that director.
The former will fail while the latter will never match.

I think we need define how req.backend_hint should behave and make it
consistent across all cases.
Right now it seems to be consistent when assigning backends directly but
not via directors.

--
Ticket URL: <https://www.varnish-cache.org/trac/ticket/1625#comment:2>
Varnish <https://varnish-cache.org/>
The Varnish HTTP Accelerator

_______________________________________________
varnish-bugs mailing list
varnish-bugs@varnish-cache.org
https://www.varnish-cache.org/lists/mailman/listinfo/varnish-bugs
Re: #1625: if(req.backend_hint == b1) compiles, but does nothing [ In reply to ]
#1625: if(req.backend_hint == b1) compiles, but does nothing
-------------------------+--------------------
Reporter: huguesalary | Owner: phk
Type: defect | Status: new
Priority: normal | Milestone:
Component: build | Version: 4.0.2
Severity: normal | Resolution:
Keywords: |
-------------------------+--------------------
Changes (by fgsch):

* owner: => phk


--
Ticket URL: <https://www.varnish-cache.org/trac/ticket/1625#comment:3>
Varnish <https://varnish-cache.org/>
The Varnish HTTP Accelerator

_______________________________________________
varnish-bugs mailing list
varnish-bugs@varnish-cache.org
https://www.varnish-cache.org/lists/mailman/listinfo/varnish-bugs
Re: #1625: if(req.backend_hint == b1) compiles, but does nothing [ In reply to ]
#1625: if(req.backend_hint == b1) compiles, but does nothing
-------------------------+-------------------------
Reporter: huguesalary | Owner: phk
Type: defect | Status: closed
Priority: normal | Milestone:
Component: build | Version: 4.0.2
Severity: normal | Resolution: worksforme
Keywords: |
-------------------------+-------------------------
Changes (by phk):

* status: new => closed
* resolution: => worksforme


Comment:

Apologies for taking so long to reply to this.

The variable you want is beresp.backend, that gives you the actual backend
the fetch was made from. This variable is available in
vcl_backend_response{}.

The trouble here is the way directors came into Varnish wasn't entirely
thought out, and that caused directors like round-robin to have a "hidden"
backend, which does the actual selection only at fetch-time.

The real trouble is that people like to assign backends in vcl_recv{}, but
doing too much work there is a waste of time for all cache-hits, so we
want to keep it light-weight and not actually do the selection there.

Varnish 5 will be a good time to revisit this.

--
Ticket URL: <https://www.varnish-cache.org/trac/ticket/1625#comment:4>
Varnish <https://varnish-cache.org/>
The Varnish HTTP Accelerator

_______________________________________________
varnish-bugs mailing list
varnish-bugs@varnish-cache.org
https://www.varnish-cache.org/lists/mailman/listinfo/varnish-bugs