Varnish and failed upstream

Nikolay Bogdanov nikolay.bogdanov at flant.com
Tue Jul 9 08:10:21 UTC 2019


Hello. I have one case and I can not find good solution for it.
In varnish3 req.backend was saved during restarts, so I can compare old
backend property and set other backend after first restart.
But in varnish 5 and newer req.backend_hint in vcl_recv is default always.
I can not use retry in vcl_backend_response, because this function did not
called.
How can I fix it?

My bad solution:

sub vcl_init {
    new upstream_rr = directors.round_robin();
    key_rr.add_backend(srv1);
    key_rr.add_backend(srv2);
}

sub vcl_recv {
    if (req.restarts == 0) {
      set req.backend_hint = upstream_rr.backend();
    } else {
      if (req.restarts == 1) {
        std.syslog(180, "RECV IN PROG: set backend srv1");
        set req.backend_hint = srv1;
      } elseif (req.restarts == 2) {
        std.syslog(180, "RECV IN PROG: set backend srv2");
        set req.backend_hint = srv2;
      } elseif (req.restarts > 2) {
        std.syslog(180, "RECV IN PROG: use other DC backend default");
        set req.backend_hint = default;
      }
    }
    return (hash);
}

-- 
-- 
Николай Богданов
Инженер АО «Флант»
http://flant.ru/
+7 (495) 721-10-27, доб. 422
+7 (926) 125-39-69
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.varnish-cache.org/lists/pipermail/varnish-misc/attachments/20190709/5911c58b/attachment.html>


More information about the varnish-misc mailing list