Commit c2b0f149 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Final (?) Part of ttl/grace clean up: Add an EXP_Clr() function to

initialize struct exp, and use it.

Pass an 'exp' instead of just the ttl to STV_NewObject()

Have -spersistent always use the graced timeout for object index,
rearm when we resurrect the zombie object.
parent fc836dd2
......@@ -633,6 +633,7 @@ extern pthread_t cli_thread;
#define ASSERT_CLI() do {assert(pthread_self() == cli_thread);} while (0)
/* cache_expiry.c */
void EXP_Clr(struct exp *e);
double EXP_Get_grace(const struct exp *e);
double EXP_Get_ttl(const struct exp *e);
void EXP_Set_grace(struct exp *e, double v);
......
......@@ -475,8 +475,7 @@ ban_check_object(struct object *o, const struct sess *sp, int has_req)
oc_updatemeta(oc);
return (0);
} else {
o->exp.ttl = -1.;
o->exp.grace = -1.;
EXP_Clr(&o->exp);
oc->ban = NULL;
oc_updatemeta(oc);
/* BAN also changed, but that is not important any more */
......
......@@ -381,7 +381,8 @@ cnt_error(struct sess *sp)
if (sp->obj == NULL) {
HSH_Prealloc(sp);
/* XXX: 1024 is a pure guess */
sp->obj = STV_NewObject(sp, NULL, 1024, 0,
EXP_Clr(&w->exp);
sp->obj = STV_NewObject(sp, NULL, 1024, &w->exp,
params->http_max_hdr);
sp->obj->xid = sp->xid;
sp->obj->entered = sp->t_req;
......@@ -527,8 +528,8 @@ cnt_fetch(struct sess *sp)
*/
sp->wrk->entered = TIM_real();
sp->wrk->age = 0;
EXP_Clr(&sp->wrk->exp);
sp->wrk->exp.ttl = RFC2616_Ttl(sp);
sp->wrk->exp.grace = NAN;
/*
* Initial cacheability determination per [RFC2616, 13.4]
......@@ -657,7 +658,7 @@ cnt_fetch(struct sess *sp)
sp->wrk->storage_hint = TRANSIENT_STORAGE;
sp->obj = STV_NewObject(sp, sp->wrk->storage_hint, l,
sp->wrk->exp.ttl, nhttp);
&sp->wrk->exp, nhttp);
/* XXX: -> 513 */
CHECK_OBJ_NOTNULL(sp->obj, OBJECT_MAGIC);
......@@ -677,7 +678,6 @@ cnt_fetch(struct sess *sp)
sp->obj->xid = sp->xid;
sp->obj->response = sp->err_code;
sp->obj->exp.grace = sp->wrk->exp.grace;
sp->obj->age = sp->wrk->age;
sp->obj->entered = sp->wrk->entered;
WS_Assert(sp->obj->ws_o);
......
......@@ -64,6 +64,14 @@ static struct lock exp_mtx;
* fields in one single place.
*/
void
EXP_Clr(struct exp *e)
{
e->grace = -1;
e->ttl = -1;
}
void
EXP_Set_grace(struct exp *e, double v)
{
......@@ -113,7 +121,7 @@ EXP_Grace(const struct sess *sp, const struct object *o)
r = (double)params->default_grace;
if (o->exp.grace > 0.)
r = o->exp.grace;
if (sp != NULL && sp->exp.grace > 0. && sp->exp.grace > r)
if (sp != NULL && sp->exp.grace > 0. && sp->exp.grace < r)
r = sp->exp.grace;
return (EXP_Ttl(sp, o) + r);
}
......@@ -124,7 +132,7 @@ EXP_Ttl(const struct sess *sp, const struct object *o)
double r;
r = o->exp.ttl;
if (sp != NULL && sp->exp.ttl > 0. && sp->exp.ttl > r)
if (sp != NULL && sp->exp.ttl > 0. && sp->exp.ttl < r)
r = sp->exp.ttl;
return (o->entered + r);
}
......
......@@ -370,7 +370,8 @@ HSH_Lookup(struct sess *sp, struct objhead **poh)
* and if there are several, use the least expired one.
*/
if (EXP_Grace(sp, o) >= sp->t_req) {
if (grace_oc == NULL || grace_ttl < o->entered + o->exp.ttl) {
if (grace_oc == NULL ||
grace_ttl < o->entered + o->exp.ttl) {
grace_oc = oc;
grace_ttl = o->entered + o->exp.ttl;
}
......@@ -534,8 +535,11 @@ HSH_Purge(const struct sess *sp, struct objhead *oh, double ttl, double grace)
}
Lck_Unlock(&oh->mtx);
if (ttl <= 0)
/* NB: inverse test to catch NAN also */
if (!(ttl > 0.))
ttl = -1.;
if (!(grace > 0.))
grace = -1.;
for (n = 0; n < nobj; n++) {
oc = ocp[n];
CHECK_OBJ_NOTNULL(oc, OBJCORE_MAGIC);
......@@ -544,8 +548,7 @@ HSH_Purge(const struct sess *sp, struct objhead *oh, double ttl, double grace)
continue;
CHECK_OBJ_NOTNULL(o, OBJECT_MAGIC);
o->exp.ttl = ttl;
if (!isnan(grace))
o->exp.grace = grace;
o->exp.grace = grace;
EXP_Rearm(o);
(void)HSH_Deref(sp->wrk, NULL, &o);
}
......
......@@ -174,7 +174,7 @@ ses_setup(struct sessmem *sm)
sp->t_req = NAN;
sp->t_resp = NAN;
sp->t_end = NAN;
sp->exp.grace = NAN;
EXP_Clr(&sp->exp);
WS_Init(sp->ws, "sess", sm->wsp, sm->workspace);
sp->http = sm->http[0];
......
......@@ -158,7 +158,7 @@ struct stv_objsecrets {
unsigned nhttp;
unsigned lhttp;
unsigned wsl;
double ttl;
struct exp *exp;
};
/*--------------------------------------------------------------------
......@@ -198,9 +198,8 @@ STV_MkObject(struct sess *sp, void *ptr, unsigned ltot,
http_Setup(o->http, o->ws_o);
o->http->magic = HTTP_MAGIC;
o->exp.grace = NAN;
o->entered = NAN;
o->exp.ttl = soc->ttl;
o->exp = *soc->exp;
VTAILQ_INIT(&o->store);
sp->wrk->stats.n_object++;
......@@ -251,7 +250,7 @@ stv_default_allocobj(struct stevedore *stv, struct sess *sp, unsigned ltot,
*/
struct object *
STV_NewObject(struct sess *sp, const char *hint, unsigned wsl, double ttl,
STV_NewObject(struct sess *sp, const char *hint, unsigned wsl, struct exp *ep,
unsigned nhttp)
{
struct object *o;
......@@ -270,7 +269,7 @@ STV_NewObject(struct sess *sp, const char *hint, unsigned wsl, double ttl,
soc.nhttp = nhttp;
soc.lhttp = lhttp;
soc.wsl = wsl;
soc.ttl = ttl;
soc.exp = ep;
ltot = sizeof *o + wsl + lhttp;
......
......@@ -30,6 +30,7 @@
*/
struct stevedore;
struct exp;
struct sess;
struct iovec;
struct object;
......@@ -91,7 +92,7 @@ struct object *STV_MkObject(struct sess *sp, void *ptr, unsigned ltot,
const struct stv_objsecrets *soc);
struct object *STV_NewObject(struct sess *sp, const char *hint, unsigned len,
double ttl, unsigned nhttp);
struct exp *, unsigned nhttp);
struct storage *STV_alloc(const struct sess *sp, size_t size);
void STV_trim(struct storage *st, size_t size);
void STV_free(struct storage *st);
......
......@@ -519,7 +519,7 @@ smp_allocobj(struct stevedore *stv, struct sess *sp, unsigned ltot,
/* We have to do this somewhere, might as well be here... */
assert(sizeof so->hash == DIGEST_LEN);
memcpy(so->hash, oc->objhead->digest, DIGEST_LEN);
so->ttl = o->entered + o->exp.ttl; /* XXX: grace? */
so->ttl = EXP_Grace(NULL, o);
so->ptr = (uint8_t*)o - sc->base;
so->ban = o->ban_t;
......
......@@ -152,9 +152,7 @@ smp_load_seg(const struct sess *sp, const struct smp_sc *sc,
/* Clear the bogus "hold" count */
sg->nobj = 0;
for (;no > 0; so++,no--) {
if (so->ttl > 0 && so->ttl < t_now)
continue;
if (so->ttl < 0 && -so->ttl < t_now)
if (so->ttl == 0 || so->ttl < t_now)
continue;
HSH_Prealloc(sp);
oc = sp->wrk->nobjcore;
......@@ -165,7 +163,7 @@ smp_load_seg(const struct sess *sp, const struct smp_sc *sc,
memcpy(sp->wrk->nobjhead->digest, so->hash, SHA256_LEN);
(void)HSH_Insert(sp);
AZ(sp->wrk->nobjcore);
EXP_Inject(oc, sg->lru, fabs(so->ttl));
EXP_Inject(oc, sg->lru, so->ttl);
sg->nobj++;
}
WRK_SumStat(sp->wrk);
......@@ -433,10 +431,9 @@ smp_oc_getobj(struct worker *wrk, struct objcore *oc)
bad |= 0x100;
if(bad) {
o->exp.ttl = -1.;
o->exp.grace = 0.;
EXP_Set_ttl(&o->exp, -1);
so->ttl = 0;
}
}
sg->nfixed++;
wrk->stats.n_object++;
......@@ -444,6 +441,7 @@ smp_oc_getobj(struct worker *wrk, struct objcore *oc)
oc->flags &= ~OC_F_NEEDFIXUP;
}
Lck_Unlock(&sg->sc->mtx);
EXP_Rearm(o);
return (o);
}
......@@ -463,10 +461,7 @@ smp_oc_updatemeta(struct objcore *oc)
CHECK_OBJ_NOTNULL(sg->sc, SMP_SC_MAGIC);
so = smp_find_so(sg, oc);
if (isnan(o->exp.grace))
mttl = o->entered + o->exp.ttl;
else
mttl = - (o->entered + o->exp.ttl + o->exp.grace);
mttl = EXP_Grace(NULL, o);
if (sg == sg->sc->cur_seg) {
/* Lock necessary, we might race close_seg */
......
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