[squid-dev] [PATCH] Purge cache entries in SMP-aware caches
Eduard Bagdasaryan
eduard.bagdasaryan at measurement-factory.com
Thu Jun 1 16:27:08 UTC 2017
Hello,
This patch fixes Squid bug 4505.
Before this change, SMP Squid with SMP-aware caches sometimes
does not purge cache entries.
When Squid finds a requested entry in the memory cache, it does not
check whether the same entry is also stored in a cache_dir. The
StoreEntry object may become associated with its store entry in the
memory cache but not with its store entry on disk. This inconsistency
causes two known problems:
1. Squid may needlessly swap out the memory hit to disk, either
overwriting an existing (and identical) disk entry or, worse,
creating a duplicate entry on another disk. In the second case, the
two disk entries are not synchronized and may eventually start to
differ if one of them is removed or updated.
2. Squid may not delete a stale disk entry when needed, violating
various HTTP MUSTs, and eventually serving stale [disk] cache entries
to clients.
Another purging problem is not caused by the above inconsistency:
3. A DELETE request or equivalent may come for the entry which is still
locked for writing. Squid fails to get a lock for such an entry (in
order to purge it) and the entry remains in disk and/or memory cache.
To solve the first two problems:
* StoreEntry::mayStartSwapout() now avoids needless swapouts by checking
whether StoreEntry was fully loaded, is being loaded, or could have
been loaded from disk.
To fix problem #3:
* A new Store::Controller::unlinkByKey() method purges (or marks for
deletion if purging is impossible) all the matching store entries,
without loading the StoreEntry information from stores. The lack of
StoreEntry creation reduces waste of resources (the StoreEntry object
would have to be deleted anyway) _and_ allows us to mark being-created
entries (that are locked for writing and, hence, cannot be loaded into
a StoreEntry object).
Note that even if Squid properly avoids storing duplicate disk entries,
some cache_dir manipulations by humans and Squid crashes may lead to
such duplicates being present. This patch leaves dealing with potential
duplicates out of scope except it guarantees that if an entry is
deleted, then all [possible] duplicates are deleted as well.
Also added StoreEntry helper methods to prevent direct manipulation of
individual disk-related data members (swap_dirn, swap_filen, and
swap_status). These methods help keep these related data members in a
coherent state and minimize code duplication.
Also tightened rules around several Storage methods: A storage method
must not be given a StoreEntry object unless that object belongs to that
storage.
Also do not mark Transients entry as "waitingToBeFreed" when the entry
is simply closed for writing. This flag is used to mark locked entries
for deletion and should not be used for "completed" transient entries to
avoid confusion.
XXX: SMP cache purges may continue to malfunction when the Transients
table is missing. Currently, Transients are created only when the
collapsed_forwarding is on. After Squid bug 4579 is fixed, every public
StoreEntry will have the corresponding Transients entry and vice versa,
extending these fixes to all SMP environments.
Since this work started long ago and is v4-based, I am attaching the
existing v4 patch for review now and start converting it to v5 version.
I plan to post final v5 version after the review is over.
Thanks,
Eduard.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: SQUID-175-methods-do-not-invalidate-v4-t13.patch
Type: text/x-patch
Size: 161575 bytes
Desc: not available
URL: <http://lists.squid-cache.org/pipermail/squid-dev/attachments/20170601/3c613356/attachment-0001.bin>
More information about the squid-dev
mailing list