9

I have a fresh install of Slackware 64 14bit, and looking through Varnish installation documentation I have all the dependencies installed and compiled varnish with no error (make check passes all tests)

Yet, when I try to run varnish using

varnishd -f /etc/varnish/user.vcl -s malloc,4G -T 127.0.0.1:2000

I get

Message from VCC-compiler:
Unknown variable 'req.grace'
At: ('input' Line 17 Pos 9)
    set req.grace = 15s;
--------#########-------

Running VCC-compiler failed, exit 1

VCL compilation failed

My very simple /etc/varnish/ucer.vcl file looks like this:

vcl 4.0;

# set default backend if no server cluster specified
backend default {
    .host = "127.0.0.1";
    .port = "8080";
    .probe = {
        .url = "/";
        .timeout = 34ms;
        .interval = 1s;
        .window = 10;
        .threshold = 8;
    }
}

sub vcl_recv {
    set req.grace = 15s;
}

sub vcl_fetch {
    set beresp.grace = 30m;
}

The variable names are identical to this example.

varnishd -V returns

varnishd (varnish-4.0.0 revision 2acedeb)

By removing both sub vcl_recv and sub vcl_fetch (using only backend default) varnish works fine and I can see it's headers, but I need to edit the VCL file.

Any ideas?

Renato Massaro
  • 544
  • 1
  • 8
  • 18

2 Answers2

11

You are using Varnish 4.0.0, which needs updating from the 3.0 format your VCL code is based on.

req.grace is gone (you usually don't need it) and vcl_fetch is now called vcl_backend_response.

See the upgrade documentation: https://www.varnish-cache.org/docs/trunk/whats-new/upgrading.html

lkarsten
  • 2,971
  • 1
  • 15
  • 11
  • Thanks, I can't believe I missed that. I read the doc about upgrading from 3 to 4 a few times, but didn't noticed the vlc_fetch change (and it does not quote grace, even though the example I provided uses both terms and it belongs to 4.0 documentation). – Renato Massaro Apr 25 '14 at 08:00
1

For reference, it is possible to handle properly the grace feature, following what is said in this blog post:

(copy/paste of the code, for more details refer to the blog)

sub vcl_hit {
    if (obj.ttl >= 0s) {
        # normal hit
        return (deliver);
    }
    # We have no fresh fish. Lets look at the stale ones.
    if (std.healthy(req.backend_hint)) {
        # Backend is healthy. Limit age to 10s.
        if (obj.ttl + 10s > 0s) {
            set req.http.grace = "normal(limited)";
            return (deliver);
        } else {
            # No candidate for grace. Fetch a fresh object.
            return(fetch);
        }
    } else {
        # backend is sick - use full grace
        if (obj.ttl + obj.grace > 0s) {
            set req.http.grace = "full";
            return (deliver);
        } else {
            # no graced object.
            return (fetch);
        }
    }
}

HTH

Ronnie
  • 852
  • 12
  • 25
zmo
  • 24,463
  • 4
  • 54
  • 90