[master] b1f0b29 Don't abuse OA_LEN to assemble the object, but set it once, and only once, once we know it.
Poul-Henning Kamp
phk at FreeBSD.org
Tue Feb 23 16:59:58 CET 2016
commit b1f0b29e660f9d45e4309b21c663708087109776
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Tue Feb 23 15:59:19 2016 +0000
Don't abuse OA_LEN to assemble the object, but set it once, and
only once, once we know it.
diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h
index 54e7ead..42bd867 100644
--- a/bin/varnishd/cache/cache.h
+++ b/bin/varnishd/cache/cache.h
@@ -379,6 +379,7 @@ struct boc {
void *stevedore_priv;
enum boc_state_e state;
uint8_t *vary;
+ uint64_t len_so_far;
};
/* Object core structure ---------------------------------------------
@@ -856,7 +857,8 @@ int ObjIterate(struct worker *, struct objcore *,
void *priv, objiterate_f *func);
int ObjGetSpace(struct worker *, struct objcore *, ssize_t *sz, uint8_t **ptr);
void ObjExtend(struct worker *, struct objcore *, ssize_t l);
-uint64_t ObjWaitExtend(struct worker *, struct objcore *, uint64_t l);
+uint64_t ObjWaitExtend(const struct worker *, const struct objcore *,
+ uint64_t l);
void ObjSetState(struct worker *, const struct objcore *,
enum boc_state_e next);
void ObjWaitState(const struct objcore *, enum boc_state_e want);
diff --git a/bin/varnishd/cache/cache_fetch.c b/bin/varnishd/cache/cache_fetch.c
index ae6621c..83945b3 100644
--- a/bin/varnishd/cache/cache_fetch.c
+++ b/bin/varnishd/cache/cache_fetch.c
@@ -627,6 +627,8 @@ vbf_stp_fetch(struct worker *wrk, struct busyobj *bo)
if (bo->htc->body_status == BS_NONE)
bo->do_stream = 0;
+ bo->fetch_objcore->boc->len_so_far = 0;
+
if (VFP_Open(bo->vfc)) {
(void)VFP_Error(bo->vfc, "Fetch pipeline failed to open");
bo->htc->doclose = SC_RX_BODY;
@@ -693,6 +695,9 @@ vbf_stp_fetch(struct worker *wrk, struct busyobj *bo)
}
}
+ AZ(ObjSetU64(wrk, bo->fetch_objcore, OA_LEN,
+ bo->fetch_objcore->boc->len_so_far));
+
if (bo->do_stream)
assert(bo->fetch_objcore->boc->state == BOS_STREAM);
else {
@@ -726,8 +731,7 @@ vbf_objiterator(void *priv, int flush, const void *ptr, ssize_t len)
CAST_OBJ_NOTNULL(bo, priv, BUSYOBJ_MAGIC);
while (len > 0) {
- l = ObjGetLen(bo->wrk, bo->stale_oc);
- assert(l > 0);
+ l = len;
if (VFP_GetStorage(bo->vfc, &l, &pd) != VFP_OK)
return (1);
if (len < l)
@@ -771,6 +775,9 @@ vbf_stp_condfetch(struct worker *wrk, struct busyobj *bo)
return (F_STP_FAIL);
}
+ AZ(ObjSetU64(wrk, bo->fetch_objcore, OA_LEN,
+ bo->fetch_objcore->boc->len_so_far));
+
if (!bo->do_stream)
HSH_Unbusy(wrk, bo->fetch_objcore);
@@ -878,8 +885,8 @@ vbf_stp_error(struct worker *wrk, struct busyobj *bo)
ll -= l;
o += l;
}
+ AZ(ObjSetU64(wrk, bo->fetch_objcore, OA_LEN, VSB_len(synth_body) - ll));
VSB_delete(synth_body);
-
HSH_Unbusy(wrk, bo->fetch_objcore);
ObjSetState(wrk, bo->fetch_objcore, BOS_FINISHED);
return (F_STP_DONE);
diff --git a/bin/varnishd/cache/cache_obj.c b/bin/varnishd/cache/cache_obj.c
index a0d82b9..a930fc9 100644
--- a/bin/varnishd/cache/cache_obj.c
+++ b/bin/varnishd/cache/cache_obj.c
@@ -175,19 +175,15 @@ void
ObjExtend(struct worker *wrk, struct objcore *oc, ssize_t l)
{
const struct obj_methods *om = obj_getmethods(oc);
- uint64_t len;
CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
CHECK_OBJ_NOTNULL(oc->boc, BOC_MAGIC);
assert(l > 0);
- AZ(ObjGetU64(wrk, oc, OA_LEN, &len));
- len += l;
-
Lck_Lock(&oc->boc->mtx);
AN(om->objextend);
om->objextend(wrk, oc, l);
- AZ(ObjSetU64(wrk, oc, OA_LEN, len));
+ oc->boc->len_so_far += l;
Lck_Unlock(&oc->boc->mtx);
AZ(pthread_cond_broadcast(&oc->boc->cond));
}
@@ -196,7 +192,7 @@ ObjExtend(struct worker *wrk, struct objcore *oc, ssize_t l)
*/
uint64_t
-ObjWaitExtend(struct worker *wrk, struct objcore *oc, uint64_t l)
+ObjWaitExtend(const struct worker *wrk, const struct objcore *oc, uint64_t l)
{
uint64_t rv;
@@ -204,14 +200,14 @@ ObjWaitExtend(struct worker *wrk, struct objcore *oc, uint64_t l)
CHECK_OBJ_NOTNULL(oc, OBJCORE_MAGIC);
CHECK_OBJ_NOTNULL(oc->boc, BOC_MAGIC);
Lck_Lock(&oc->boc->mtx);
- AZ(ObjGetU64(wrk, oc, OA_LEN, &rv));
while (1) {
+ rv = oc->boc->len_so_far;
assert(l <= rv || oc->boc->state == BOS_FAILED);
if (rv > l || oc->boc->state >= BOS_FINISHED)
break;
(void)Lck_CondWait(&oc->boc->cond, &oc->boc->mtx, 0);
- AZ(ObjGetU64(wrk, oc, OA_LEN, &rv));
}
+ rv = oc->boc->len_so_far;
Lck_Unlock(&oc->boc->mtx);
return (rv);
}
@@ -220,7 +216,8 @@ ObjWaitExtend(struct worker *wrk, struct objcore *oc, uint64_t l)
*/
void
-ObjSetState(struct worker *wrk, const struct objcore *oc, enum boc_state_e next)
+ObjSetState(struct worker *wrk, const struct objcore *oc,
+ enum boc_state_e next)
{
const struct obj_methods *om;
@@ -229,6 +226,8 @@ ObjSetState(struct worker *wrk, const struct objcore *oc, enum boc_state_e next)
assert(next > oc->boc->state);
CHECK_OBJ_ORNULL(oc->stobj->stevedore, STEVEDORE_MAGIC);
+ AN(next != BOS_FINISHED || (oc->oa_present & (1 << OA_LEN)));
+
if (oc->stobj->stevedore != NULL) {
om = oc->stobj->stevedore->methods;
if (om->objsetstate != NULL)
diff --git a/bin/varnishd/cache/cache_req_fsm.c b/bin/varnishd/cache/cache_req_fsm.c
index 733b21d..991883f 100644
--- a/bin/varnishd/cache/cache_req_fsm.c
+++ b/bin/varnishd/cache/cache_req_fsm.c
@@ -162,7 +162,6 @@ cnt_synth(struct worker *wrk, struct req *req)
if (req->err_code < 100 || req->err_code > 999)
req->err_code = 501;
-
HTTP_Setup(req->resp, req->ws, req->vsl, SLT_RespMethod);
h = req->resp;
http_TimeHeader(h, "Date: ", now);
@@ -208,6 +207,8 @@ cnt_synth(struct worker *wrk, struct req *req)
}
}
+ if (szl >= 0)
+ AZ(ObjSetU64(wrk, req->objcore, OA_LEN, szl));
HSH_DerefBoc(wrk, req->objcore);
VSB_delete(synth_body);
More information about the varnish-commit
mailing list