Determine if grace object is available

Mattias Geniar mattias at nucleus.be
Wed Jul 30 09:38:12 CEST 2014


>> I¹d like to get fancy with grace stored objects, but I¹m not sure how
>>to do this. Can I determine if there¹s a grace object I could deliver?
>>Basically I want my logic to be:

As a follow-up to this thread, I'm wondering if the following is possible,
given that there is a director present with 2 servers, having health
probes configured.

If the director has no healthy backends;
1. See if a grace object is available, if so, deliver it
2. If no grace object is available, change the backend to a "maintenance"
one to serve a static HTML page for maintenance purposes

The struggle is in vcl_recv {}, how would this be able to work? If I use
req.backend.healthy to determine the backend health to set a new backend,
I lose the grace ability (as it'll be passed to the new, available,
backend?). Or I'm missing something here.

# Use grace, when available and when needed
if (! req.backend.healthy) {
  # Backends are sick, so fall back to a stale object, if possible
  set req.grace = 5m;

  # If no stale object is available, how should we switch to a new backend
here?
  set req.backend = maintenance_backend;  # This could serve static pages
with maintenance info
}


I'm thing something like this, but it's not possible?
if (req.grace.available) {
  set req.grace = 5m;
} else {
  # No grace object available, set new backend
  set req.backend = maintenance_backend;
}

Thanks,

Mattias




More information about the varnish-misc mailing list