[experimental-ims] 3df9ebf Moved sp->stale_obj to busyobj->stale_obj
Geoff Simmons
geoff at varnish-cache.org
Tue Jan 31 21:30:15 CET 2012
commit 3df9ebf5105a5da63c2a3085af772e5b3ab32f05
Author: Geoff Simmons <geoff at uplex.de>
Date: Tue Jan 31 21:29:08 2012 +0100
Moved sp->stale_obj to busyobj->stale_obj
diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h
index b257efc..6c3fb57 100644
--- a/bin/varnishd/cache/cache.h
+++ b/bin/varnishd/cache/cache.h
@@ -509,6 +509,7 @@ struct busyobj {
struct http *bereq;
struct http *beresp;
struct object *fetch_obj;
+ struct object *stale_obj;
struct exp exp;
struct http_conn htc;
@@ -649,8 +650,6 @@ struct sess {
int fd;
unsigned vsl_id;
- struct object *stale_obj;
-
/* Cross references ------------------------------------------*/
struct sesspool *sesspool;
diff --git a/bin/varnishd/cache/cache_center.c b/bin/varnishd/cache/cache_center.c
index 48d53a7..8897e83 100644
--- a/bin/varnishd/cache/cache_center.c
+++ b/bin/varnishd/cache/cache_center.c
@@ -628,7 +628,7 @@ cnt_fetch(struct sess *sp, struct worker *wrk, struct req *req)
* and merge headers from stale_obj into the busyobj if so.
* Any other response is handled as usual.
*/
- if (sp->stale_obj)
+ if (wrk->busyobj->stale_obj)
http_Check304(sp, wrk->busyobj);
req->err_code = http_GetStatus(wrk->busyobj->beresp);
@@ -650,10 +650,10 @@ cnt_fetch(struct sess *sp, struct worker *wrk, struct req *req)
VCL_fetch_method(sp);
- /* Cancel streaming if a stale object was validated */
- /* XXX: But not if original beresp.status != 304 */
- /* See also AZ(sp->stale_obj) in cnt_streambody() */
- if (sp->stale_obj)
+ /* Cancel streaming if a stale object was validated */
+ /* XXX: But not if original beresp.status != 304 */
+ /* See also AZ(busyobj->stale_obj) in cnt_streambody() */
+ if (wrk->busyobj->stale_obj)
wrk->busyobj->do_stream = 0;
if (req->objcore != NULL && wrk->busyobj->do_pass)
@@ -815,8 +815,8 @@ cnt_fetchbody(struct sess *sp, struct worker *wrk, struct req *req)
l = http_EstimateWS(bo->beresp,
pass ? HTTPH_R_PASS : HTTPH_A_INS, &nhttp);
- if (sp->stale_obj) {
- l += http_EstimateWS(sp->stale_obj->http, 0, &stale_nhttp);
+ if (bo->stale_obj) {
+ l += http_EstimateWS(bo->stale_obj->http, 0, &stale_nhttp);
nhttp += stale_nhttp;
}
@@ -923,18 +923,18 @@ cnt_fetchbody(struct sess *sp, struct worker *wrk, struct req *req)
* reset Content-Length from the size of the storage, and discard
* the stale_obj.
*/
- if (sp->stale_obj) {
- STV_dup(sp, sp->stale_obj, req->obj);
- assert(sp->stale_obj->len == req->obj->len);
+ if (bo->stale_obj) {
+ STV_dup(sp, bo->stale_obj, req->obj);
+ assert(bo->stale_obj->len == req->obj->len);
http_Unset(req->obj->http, H_Content_Length);
http_PrintfHeader(sp->wrk, sp->fd, req->obj->http,
"Content-Length: %u", req->obj->len);
- EXP_Clr(&sp->stale_obj->exp);
- EXP_Rearm(sp->stale_obj);
- HSH_Deref(sp->wrk, NULL, &sp->stale_obj);
- AZ(sp->stale_obj);
+ EXP_Clr(&bo->stale_obj->exp);
+ EXP_Rearm(bo->stale_obj);
+ HSH_Deref(sp->wrk, NULL, &bo->stale_obj);
+ AZ(bo->stale_obj);
}
http_Setup(bo->bereq, NULL);
@@ -987,9 +987,9 @@ cnt_streambody(struct sess *sp, struct worker *wrk, struct req *req)
CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
- AZ(sp->stale_obj);
CHECK_OBJ_NOTNULL(wrk->busyobj, BUSYOBJ_MAGIC);
+ AZ(wrk->busyobj->stale_obj);
memset(&sctx, 0, sizeof sctx);
sctx.magic = STREAM_CTX_MAGIC;
AZ(wrk->sctx);
@@ -1244,8 +1244,8 @@ cnt_lookup(struct sess *sp, struct worker *wrk, struct req *req)
wrk->stats.cache_hitpass++;
WSP(sp, SLT_HitPass, "%u", req->obj->xid);
(void)HSH_Deref(wrk, NULL, &req->obj);
- if (sp->stale_obj != NULL)
- (void)HSH_Deref(wrk, NULL, &sp->stale_obj);
+ if (wrk->busyobj != NULL && wrk->busyobj->stale_obj != NULL)
+ (void)HSH_Deref(wrk, NULL, &wrk->busyobj->stale_obj);
AZ(req->objcore);
sp->step = STP_PASS;
return (0);
@@ -1287,8 +1287,10 @@ cnt_miss(struct sess *sp, struct worker *wrk, struct req *req)
CHECK_OBJ_NOTNULL(wrk->busyobj, BUSYOBJ_MAGIC);
AZ(req->obj);
- WS_Reset(wrk->ws, NULL);
- wrk->busyobj = VBO_GetBusyObj(wrk);
+ if (!wrk->busyobj->stale_obj) {
+ WS_Reset(wrk->ws, NULL);
+ wrk->busyobj = VBO_GetBusyObj(wrk);
+ }
http_Setup(wrk->busyobj->bereq, wrk->ws);
http_FilterReq(sp, HTTPH_R_FETCH);
http_ForceGet(wrk->busyobj->bereq);
@@ -1306,7 +1308,7 @@ cnt_miss(struct sess *sp, struct worker *wrk, struct req *req)
/* If a candidate for a conditional backend request was found,
* add If-Modified-Since and/or If-None-Match to the bereq.
*/
- if (sp->stale_obj)
+ if (wrk->busyobj->stale_obj)
http_CheckRefresh(sp);
VCL_miss_method(sp);
diff --git a/bin/varnishd/cache/cache_hash.c b/bin/varnishd/cache/cache_hash.c
index 827d6af..9585e7a 100644
--- a/bin/varnishd/cache/cache_hash.c
+++ b/bin/varnishd/cache/cache_hash.c
@@ -307,7 +307,6 @@ HSH_Lookup(struct sess *sp, struct objhead **poh)
CHECK_OBJ_NOTNULL(sp->req->http, HTTP_MAGIC);
AN(sp->req->director);
AN(hash);
- AZ(sp->stale_obj);
wrk = sp->wrk;
HSH_Prealloc(sp);
@@ -470,27 +469,26 @@ HSH_Lookup(struct sess *sp, struct objhead **poh)
return (NULL);
}
+ /* Insert (precreated) objcore in objecthead */
+ oc = wrk->nobjcore;
+ wrk->nobjcore = NULL;
+ AN(oc->flags & OC_F_BUSY);
+ oc->refcnt = 1;
+
+ AZ(wrk->busyobj);
+ wrk->busyobj = VBO_GetBusyObj(wrk);
+
/* If we're not serving a valid or graced object and we saved stale_o,
* it is a candidate for the conditional backend request. */
- AZ(oc && !sp->req->hash_always_miss);
AZ(busy_oc);
if (stale_o != NULL) {
AZ(stale_o->objcore->flags & OC_F_BUSY);
CHECK_OBJ_NOTNULL(stale_o->objcore, OBJCORE_MAGIC);
Lck_AssertHeld(&oh->mtx);
stale_o->objcore->refcnt++;
- sp->stale_obj = stale_o;
+ wrk->busyobj->stale_obj = stale_o;
}
- /* Insert (precreated) objcore in objecthead */
- oc = wrk->nobjcore;
- wrk->nobjcore = NULL;
- AN(oc->flags & OC_F_BUSY);
- oc->refcnt = 1;
-
- AZ(wrk->busyobj);
- wrk->busyobj = VBO_GetBusyObj(wrk);
-
VRY_Validate(sp->req->vary_b);
if (sp->req->vary_l != NULL)
wrk->busyobj->vary = sp->req->vary_b;
diff --git a/bin/varnishd/cache/cache_http.c b/bin/varnishd/cache/cache_http.c
index ceef821..ac922b8 100644
--- a/bin/varnishd/cache/cache_http.c
+++ b/bin/varnishd/cache/cache_http.c
@@ -907,9 +907,8 @@ http_FilterReq(const struct sess *sp, unsigned how)
}
/*-------------------------------------------------------------------
- * This function checks for sp->freshen_obj. If present, HSH_Lookup()
- * found an expired object that qualifies for a refresh check,
- * so add the appropriate headers.
+ * This function checks if a stale_obj was found in HSH_Lookup().
+ * If so, add the appropriate headers for backend validation.
*/
void
@@ -919,7 +918,10 @@ http_CheckRefresh(struct sess *sp)
struct http *obj_hp, *bereq_hp;
char *p;
- freshen_obj = sp->stale_obj;
+ CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
+ CHECK_OBJ_NOTNULL(sp->wrk, WORKER_MAGIC);
+ CHECK_OBJ_NOTNULL(sp->wrk->busyobj, BUSYOBJ_MAGIC);
+ freshen_obj = sp->wrk->busyobj->stale_obj;
CHECK_OBJ_NOTNULL(freshen_obj, OBJECT_MAGIC);
bereq_hp = sp->wrk->busyobj->bereq;
CHECK_OBJ_NOTNULL(bereq_hp, HTTP_MAGIC);
@@ -936,7 +938,7 @@ http_CheckRefresh(struct sess *sp)
}
/*-------------------------------------------------------------------
- * Called after fetch and sp->freshen_obj present. Check
+ * Called after fetch for a backend conditional request. Check
* response and handle as needed.
*/
@@ -948,7 +950,7 @@ http_Check304(struct sess *sp, struct busyobj *busyobj)
CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
CHECK_OBJ_NOTNULL(busyobj, BUSYOBJ_MAGIC);
- o_stale = sp->stale_obj;
+ o_stale = busyobj->stale_obj;
CHECK_OBJ_NOTNULL(o_stale, OBJECT_MAGIC);
if (busyobj->beresp->status != 304) {
@@ -960,8 +962,10 @@ http_Check304(struct sess *sp, struct busyobj *busyobj)
|| http_GetHdr(busyobj->bereq, H_If_None_Match, &p))
sp->wrk->stats.fetch_not_validated++;
- HSH_Deref(sp->wrk, NULL, &sp->stale_obj);
- AZ(sp->stale_obj);
+ /* Discard the stale object */
+ /* XXX: just deref, or force expire? */
+ HSH_Deref(sp->wrk, NULL, &busyobj->stale_obj);
+ AZ(busyobj->stale_obj);
return;
}
diff --git a/bin/varnishd/cache/cache_vrt.c b/bin/varnishd/cache/cache_vrt.c
index 50a7b7f..9c7664c 100644
--- a/bin/varnishd/cache/cache_vrt.c
+++ b/bin/varnishd/cache/cache_vrt.c
@@ -114,8 +114,8 @@ vrt_selecthttp(const struct sess *sp, enum gethdr_e where)
hp = sp->req->obj->http;
break;
case HDR_STALE_OBJ:
- CHECK_OBJ_NOTNULL(sp->stale_obj, OBJECT_MAGIC);
- hp = sp->stale_obj->http;
+ CHECK_OBJ_NOTNULL(sp->wrk->busyobj->stale_obj, OBJECT_MAGIC);
+ hp = sp->wrk->busyobj->stale_obj->http;
break;
default:
INCOMPL();
@@ -131,7 +131,7 @@ VRT_GetHdr(const struct sess *sp, enum gethdr_e where, const char *n)
struct http *hp;
CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
- if (where == HDR_STALE_OBJ && sp->stale_obj == NULL) {
+ if (where == HDR_STALE_OBJ && sp->wrk->busyobj->stale_obj == NULL) {
WSP(sp, SLT_VCL_error,
"stale_obj does not exist (reading header %s)", n);
return NULL;
diff --git a/bin/varnishd/cache/cache_vrt_var.c b/bin/varnishd/cache/cache_vrt_var.c
index d376df1..f94dc83 100644
--- a/bin/varnishd/cache/cache_vrt_var.c
+++ b/bin/varnishd/cache/cache_vrt_var.c
@@ -94,20 +94,34 @@ VRT_r_##obj##_##hdr(const struct sess *sp) \
VRT_DO_HDR_l(obj, hdr, cont, http, fld) \
VRT_DO_HDR_r(obj, hdr, cont, http, fld, nullable) \
-VRT_DO_HDR(req, request, sp->req, http, HTTP_HDR_REQ, 0)
-VRT_DO_HDR(req, url, sp->req, http, HTTP_HDR_URL, 0)
-VRT_DO_HDR(req, proto, sp->req, http, HTTP_HDR_PROTO, 0)
-VRT_DO_HDR(bereq, request, sp->wrk->busyobj, bereq, HTTP_HDR_REQ, 0)
-VRT_DO_HDR(bereq, url, sp->wrk->busyobj, bereq, HTTP_HDR_URL, 0)
-VRT_DO_HDR(bereq, proto, sp->wrk->busyobj, bereq, HTTP_HDR_PROTO, 0)
-VRT_DO_HDR(obj, proto, sp->req->obj, http, HTTP_HDR_PROTO, 0)
-VRT_DO_HDR(obj, response, sp->req->obj, http, HTTP_HDR_RESPONSE, 0)
-VRT_DO_HDR(resp, proto, sp->req, resp, HTTP_HDR_PROTO, 0)
-VRT_DO_HDR(resp, response, sp->req, resp, HTTP_HDR_RESPONSE, 0)
-VRT_DO_HDR(beresp, proto, sp->wrk->busyobj, beresp, HTTP_HDR_PROTO, 0)
-VRT_DO_HDR(beresp, response, sp->wrk->busyobj, beresp, HTTP_HDR_RESPONSE, 0)
-VRT_DO_HDR_r(stale_obj, proto, sp->stale_obj, http, HTTP_HDR_PROTO, 1)
-VRT_DO_HDR_r(stale_obj, response, sp->stale_obj, http, HTTP_HDR_RESPONSE, 1)
+VRT_DO_HDR(req, request, sp->req,
+ http, HTTP_HDR_REQ, 0)
+VRT_DO_HDR(req, url, sp->req,
+ http, HTTP_HDR_URL, 0)
+VRT_DO_HDR(req, proto, sp->req,
+ http, HTTP_HDR_PROTO, 0)
+VRT_DO_HDR(bereq, request, sp->wrk->busyobj,
+ bereq, HTTP_HDR_REQ, 0)
+VRT_DO_HDR(bereq, url, sp->wrk->busyobj,
+ bereq, HTTP_HDR_URL, 0)
+VRT_DO_HDR(bereq, proto, sp->wrk->busyobj,
+ bereq, HTTP_HDR_PROTO, 0)
+VRT_DO_HDR(obj, proto, sp->req->obj,
+ http, HTTP_HDR_PROTO, 0)
+VRT_DO_HDR(obj, response, sp->req->obj,
+ http, HTTP_HDR_RESPONSE, 0)
+VRT_DO_HDR(resp, proto, sp->req,
+ resp, HTTP_HDR_PROTO, 0)
+VRT_DO_HDR(resp, response, sp->req,
+ resp, HTTP_HDR_RESPONSE, 0)
+VRT_DO_HDR(beresp, proto, sp->wrk->busyobj,
+ beresp, HTTP_HDR_PROTO, 0)
+VRT_DO_HDR(beresp, response, sp->wrk->busyobj,
+ beresp, HTTP_HDR_RESPONSE, 0)
+VRT_DO_HDR_r(stale_obj, proto, sp->wrk->busyobj->stale_obj,
+ http, HTTP_HDR_PROTO, 1)
+VRT_DO_HDR_r(stale_obj, response, sp->wrk->busyobj->stale_obj,
+ http, HTTP_HDR_RESPONSE, 1)
/*--------------------------------------------------------------------*/
@@ -137,10 +151,14 @@ VRT_r_##obj##_status(const struct sess *sp) \
VRT_DO_STATUS_l(obj, cont, http) \
VRT_DO_STATUS_r(obj, cont, http, nullable) \
-VRT_DO_STATUS(obj, sp->req->obj, http, 0)
-VRT_DO_STATUS(beresp, sp->wrk->busyobj, beresp, 0)
-VRT_DO_STATUS(resp, sp->req, resp, 0)
-VRT_DO_STATUS_r(stale_obj, sp->stale_obj, http, 1)
+VRT_DO_STATUS(obj, sp->req->obj,
+ http, 0)
+VRT_DO_STATUS(beresp, sp->wrk->busyobj,
+ beresp, 0)
+VRT_DO_STATUS(resp, sp->req,
+ resp, 0)
+VRT_DO_STATUS_r(stale_obj, sp->wrk->busyobj->stale_obj,
+ http, 1)
/*--------------------------------------------------------------------*/
@@ -455,9 +473,9 @@ VRT_DO_EXP(beresp, sp->wrk->busyobj, ttl, 0, 0,
VRT_DO_EXP(beresp, sp->wrk->busyobj, keep, 0, 0,
vrt_wsp_exp(sp, sp->req->xid, &sp->wrk->busyobj->exp);)
-VRT_DO_EXP_r(stale_obj, sp->stale_obj, grace, 0, 1)
-VRT_DO_EXP_r(stale_obj, sp->stale_obj, ttl, 0, 1)
-VRT_DO_EXP_r(stale_obj, sp->stale_obj, keep, 0, 1)
+VRT_DO_EXP_r(stale_obj, sp->wrk->busyobj->stale_obj, grace, 0, 1)
+VRT_DO_EXP_r(stale_obj, sp->wrk->busyobj->stale_obj, ttl, 0, 1)
+VRT_DO_EXP_r(stale_obj, sp->wrk->busyobj->stale_obj, keep, 0, 1)
/*--------------------------------------------------------------------
* req.xid
@@ -579,12 +597,12 @@ VRT_r_stale_obj_hits(const struct sess *sp)
{
CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
- if (sp->stale_obj == NULL) {
+ if (sp->wrk->busyobj->stale_obj == NULL) {
ILLEGAL_R(sp, "stale_obj", "hits");
return (0);
}
- CHECK_OBJ(sp->stale_obj, OBJECT_MAGIC); /* XXX */
- return (sp->stale_obj->hits);
+ CHECK_OBJ(sp->wrk->busyobj->stale_obj, OBJECT_MAGIC); /* XXX */
+ return (sp->wrk->busyobj->stale_obj->hits);
}
double
@@ -601,12 +619,12 @@ VRT_r_stale_obj_lastuse(const struct sess *sp)
{
CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
- if (sp->stale_obj == NULL) {
+ if (sp->wrk->busyobj->stale_obj == NULL) {
ILLEGAL_R(sp, "stale_obj", "lastuse");
return (0);
}
- CHECK_OBJ(sp->stale_obj, OBJECT_MAGIC); /* XXX */
- return (VTIM_real() - sp->stale_obj->last_use);
+ CHECK_OBJ(sp->wrk->busyobj->stale_obj, OBJECT_MAGIC); /* XXX */
+ return (VTIM_real() - sp->wrk->busyobj->stale_obj->last_use);
}
unsigned
@@ -621,5 +639,5 @@ unsigned
VRT_r_stale_obj(const struct sess *sp)
{
CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
- return (sp->stale_obj != NULL);
+ return (sp->wrk->busyobj->stale_obj != NULL);
}
More information about the varnish-commit
mailing list