Commit 9c0abf0c authored by AlveElde's avatar AlveElde Committed by Nils Goroll

expire: Introduce EXP_Reduce()

This commit introduces EXP_Reduce(), a function to reduce object timers.
The goal is to provide a function better suited to soft-purging objects,
as EXP_Rearm() has some non-obvious disadvantages when used or this
purpose.

When EXP_Rearm() is used to soft-purge an object by setting its TTL to
0, the expiry is effectively reset to the start of the objects grace
period. This happens because the object TTL includes a time delta
between object insertion time (oc->t_origin) and now. The result is that
a soft-purge extends the lifetime of an already stale object, and
repeated soft-purges can keep the object away from expiry indefinitely.

The EXP_Reduce() function is better suited for soft-purging, as it only
updates an objects TTL if it would reduce the objects lifetime. The
function also has facilities for reducing grace and keep.
parent 8f2c3648
......@@ -219,6 +219,28 @@ EXP_Insert(struct worker *wrk, struct objcore *oc)
}
}
/*--------------------------------------------------------------------
* Reduce object timers
*/
void
EXP_Reduce(struct objcore *oc, vtim_real now,
vtim_dur ttl, vtim_dur grace, vtim_dur keep)
{
CHECK_OBJ_NOTNULL(oc, OBJCORE_MAGIC);
assert(oc->refcnt > 0);
if (!isnan(ttl) && now + ttl - oc->t_origin >= oc->ttl)
ttl = NAN;
if (!isnan(grace) && grace >= oc->grace)
grace = NAN;
if (!isnan(keep) && keep >= oc->keep)
keep = NAN;
EXP_Rearm(oc, now, ttl, grace, keep);
}
/*--------------------------------------------------------------------
* We have changed one or more of the object timers, tell the exp_thread
*
......
......@@ -240,6 +240,8 @@ void EXP_Remove(struct objcore *, const struct objcore *);
/* cache_exp.c */
void EXP_Rearm(struct objcore *oc, vtim_real now,
vtim_dur ttl, vtim_dur grace, vtim_dur keep);
void EXP_Reduce(struct objcore *oc, vtim_real now,
vtim_dur ttl, vtim_dur grace, vtim_dur keep);
/* From cache_main.c */
void BAN_Init(void);
......
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