title: Change backend during retry in Varnish 4
body: <p>I'd like to be able to change the backend on a retry in Varnish 4. We've got this working on a different (older) application using Varnish 3, but I haven't been able to figure it out for v4, nor find much documentation. The setup we want is to have 2 sets of directors - one for the initial request trying a local server in the same datacenter as varnish because this is way faster, and then only if that fails, pick randomly from a different director for servers in other datacenters.</p>
  
  <p>In v3, this was easy:</p>
  
  <pre><code>sub vcl_recv {
      if (req.restarts == 0) {
          set req.backend = defaultdirector;
      } else {
          set req.backend = backupdirector;
      }
  }
  
  #Then in vcl_fetch and/or vcl_error something like:
  if (beresp.status &gt;= 500 &amp;&amp; req.restarts &lt; some_max) {
      return(restart);
  }
  </code></pre>
  
  <p>But now in v4, restart has supposedly been replaced with retry, with the entire documentation being:</p>
  
  <blockquote>
    <p>In 3.0 it was possible to do return(restart) after noticing that the backend response was wrong, to change to a different backend.</p>
    
    <p>This is now called return(retry), and jumps back up to vcl_backend_fetch.</p>
    
    <p>This only influences the backend fetch thread, client-side handling is not affected.</p>
  </blockquote>
  
  <p>Yet I still see a few people's example code containing return(restart) rather than return(retry), and not a single example of it working with the retry command.</p>
  
  <p>I understand that varnish should not have to do all of the work in vcl_recv again (such as stripping cookies), since it was only the communication with the backend that failed, so it does make sense to bounce back to the backend fetch rather than redo all the frontend processing, but I get a compile error if I try to change the backend in vcl_backend_fetch. How do I make this work?</p>