Skip to content

Commit

Permalink
expire: Introduce EXP_Reduce()
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
AlveElde authored and nigoroll committed Mar 25, 2024
1 parent 8f2c364 commit 9c0abf0
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
22 changes: 22 additions & 0 deletions bin/varnishd/cache/cache_expire.c
Expand Up @@ -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
*
Expand Down
2 changes: 2 additions & 0 deletions bin/varnishd/cache/cache_varnishd.h
Expand Up @@ -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);
Expand Down

0 comments on commit 9c0abf0

Please sign in to comment.