Commit 365848c6 authored by Martin Blix Grydeland's avatar Martin Blix Grydeland

Introduce req.hash_always_miss (force cache miss) and req.hash_ignore_busy...

Introduce req.hash_always_miss (force cache miss) and req.hash_ignore_busy (ignore busy objects) variables available in vcl_fetch.



git-svn-id: http://www.varnish-cache.org/svn/trunk/varnish-cache@5170 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent a6a528a9
......@@ -379,6 +379,9 @@ struct sess {
int esis;
int disable_esi;
uint8_t hash_ignore_busy;
uint8_t hash_always_miss;
struct worker *wrk;
socklen_t sockaddrlen;
......
......@@ -268,6 +268,8 @@ cnt_done(struct sess *sp)
memset(&sp->acct_req, 0, sizeof sp->acct_req);
sp->t_req = NAN;
sp->hash_always_miss = 0;
sp->hash_ignore_busy = 0;
if (sp->fd >= 0 && sp->doclose != NULL) {
/*
......
......@@ -402,8 +402,9 @@ HSH_Lookup(struct sess *sp, struct objhead **poh)
if (oc == NULL /* We found no live object */
&& grace_oc != NULL /* There is a grace candidate */
&& (busy_oc != NULL /* Somebody else is already busy */
|| !VDI_Healthy(sp->t_req, sp->director, (uintptr_t)oh))) {
/* Or it is impossible to fetch: */
|| !VDI_Healthy(sp->t_req, sp->director, (uintptr_t)oh))
/* Or it is impossible to fetch */
&& !sp->hash_ignore_busy) { /* And we've not been told to ignore busy */
o = grace_oc->obj;
CHECK_OBJ_NOTNULL(o, OBJECT_MAGIC);
if (o->ttl + HSH_Grace(sp->grace) >= sp->t_req)
......@@ -415,18 +416,27 @@ HSH_Lookup(struct sess *sp, struct objhead **poh)
CHECK_OBJ_NOTNULL(o, OBJECT_MAGIC);
assert(oc->objhead == oh);
/* We found an object we like */
oc->refcnt++;
if (o->hits < INT_MAX)
o->hits++;
assert(oh->refcnt > 1);
Lck_Unlock(&oh->mtx);
assert(hash->deref(oh));
*poh = oh;
return (oc);
if(sp->hash_always_miss) {
if (o->ttl >= sp->t_req) {
o->ttl = sp->t_req - 1;
o->grace = HSH_Grace(sp->grace);
EXP_Rearm(o);
}
o = NULL;
} else {
/* We found an object we like */
oc->refcnt++;
if (o->hits < INT_MAX)
o->hits++;
assert(oh->refcnt > 1);
Lck_Unlock(&oh->mtx);
assert(hash->deref(oh));
*poh = oh;
return (oc);
}
}
if (busy_oc != NULL) {
if (busy_oc != NULL && !sp->hash_ignore_busy) {
/* There are one or more busy objects, wait for them */
if (sp->esis == 0)
VTAILQ_INSERT_TAIL(&oh->waitinglist, sp, list);
......
......@@ -736,6 +736,42 @@ VRT_r_req_xid(struct sess *sp)
return (p);
}
/*--------------------------------------------------------------------
* req.hash_ignore_busy
*/
void
VRT_l_req_hash_ignore_busy(struct sess *sp, unsigned ignore_busy)
{
CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
sp->hash_ignore_busy = !!ignore_busy;
}
unsigned
VRT_r_req_hash_ignore_busy(struct sess *sp)
{
CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
return sp->hash_ignore_busy;
}
/*--------------------------------------------------------------------
* req.hash_always_miss
*/
void
VRT_l_req_hash_always_miss(struct sess *sp, unsigned always_miss)
{
CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
sp->hash_always_miss = !!always_miss;
}
unsigned
VRT_r_req_hash_always_miss(struct sess *sp)
{
CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
return sp->hash_always_miss;
}
/*--------------------------------------------------------------------*/
struct sockaddr *
......
# $Id$
test "Test req.hash_always_miss in vcl_recv"
server s1 {
rxreq
txresp -hdr "Inc: 1"
rxreq
txresp -hdr "Inc: 2"
} -start
varnish v1 -vcl+backend {
sub vcl_recv {
if (req.http.x-missit == "1") {
set req.hash_always_miss = true;
}
}
sub vcl_deliver {
if(obj.hits > 0) {
set resp.http.X-Cache = "HIT";
} else {
set resp.http.X-Cache = "MISS";
}
}
} -start
client c1 {
txreq -url "/"
rxresp
expect resp.status == 200
expect resp.http.Inc == "1"
txreq -url "/"
rxresp
expect resp.status == 200
expect resp.http.Inc == "1"
txreq -url "/" -hdr "x-missit: 1"
rxresp
expect resp.status == 200
expect resp.http.Inc == "2"
txreq -url "/"
rxresp
expect resp.status == 200
expect resp.http.Inc == "2"
} -run
# $Id$
test "Test req.hash_ignore_busy in vcl_recv"
server s1 {
rxreq
sema r1 sync 2
delay 1
txresp -hdr "Server: 1"
} -start
server s2 {
rxreq
txresp -hdr "Server: 2"
} -start
varnish v1 -vcl+backend {
sub vcl_recv {
if (req.http.x-ignorebusy == "1") {
set req.hash_ignore_busy = true;
}
if (req.http.x-client == "1") {
set req.backend = s1;
}
if (req.http.x-client == "2") {
set req.backend = s2;
}
}
sub vcl_deliver {
if(obj.hits > 0) {
set resp.http.X-Cache = "HIT";
} else {
set resp.http.X-Cache = "MISS";
}
}
} -start
client c1 {
txreq -url "/" -hdr "x-client: 1"
rxresp
expect resp.status == 200
expect resp.http.Server == "1"
} -start
client c2 {
sema r1 sync 2
txreq -url "/" -hdr "x-client: 2" -hdr "x-ignorebusy: 1"
txreq -url "/" -hdr "x-client: 2"
rxresp
expect resp.status == 200
expect resp.http.Server == "2"
} -start
client c1 -wait
client c2 -wait
......@@ -514,6 +514,12 @@ req.backend.healthy
req.http.header
The corresponding HTTP header.
req.hash_always_miss
Force a cache miss for this request.
req.hash_ignore_busy
Ignore any busy object during cache lookup.
The following variables are available while preparing a backend
request (either for a cache miss or for pass or pipe mode):
......
......@@ -196,6 +196,18 @@ sp_variables = (
( ),
'const struct sess *'
),
('req.hash_ignore_busy',
'BOOL',
( 'recv',),
( 'recv',),
'struct sess *'
),
('req.hash_always_miss',
'BOOL',
( 'recv',),
( 'recv',),
'struct sess *'
),
('bereq.request',
'STRING',
( 'pipe', 'pass', 'miss', 'fetch',),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment