Migrate cache backend from diskcache to pysciqlop-cache#289
Open
jeandet wants to merge 1 commit into
Open
Conversation
Swap the cache and index backends to pysciqlop-cache (>=0.1.0). It has identical semantics for everything Speasy uses, plus crash-safe atomic add(expire=, tag=), per-shard FanoutCache transactions, and a built-in diskcache-compatible migrator. Migration is automatic on first launch: if a legacy diskcache layout is detected, the cache is staged in a sibling directory and only swapped in once the new sciqlop-cache is fully written; the old data is preserved at <path>.diskcache.backup so users can verify before deleting. While here, fix three issues in the request deduplication code that the new backend makes easy: - Stale PendingRequest entries on worker crash now auto-expire via add(expire=timeout) instead of leaking until the next attempt. - Peers waiting on an in-flight request wake up promptly when the producer finishes (poll `key in cache`) instead of always sleeping the full timeout. Reproducer test added. - Pending markers are tagged so a proxy/server can drop them all on startup with evict_pending_requests(). The latent FanoutCache.transact() no-op is also fixed: Cache.transact() now takes an optional shard key and forwards it correctly. Callers in _providers_caches.py pass the product as shard key. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.




Summary
diskcache→pysciqlop-cacheincache.pyandspeasy_index.py. APIs are near-identical; the few differences (kwarg renames,stats()returning a dict, noclose()/RAII,FanoutCache.transact()taking a shard key) are handled in the wrapper.pysciqlop_cache.migrate. The new cache is staged in a sibling directory and only swapped in on success; the legacy data is preserved at<path>.diskcache.backupfor the user to verify and delete._request_locker.pywhile we're here, leveraging the newadd(expire=, tag=)primitive:PendingRequestentries from crashed workers now auto-expire instead of leaking until the next attempt picks them up.key in cache) instead of always sleeping the full timeout. Regression test added (RequestLockerWakeup).pending_requesttag so a proxy/server can drop them all on startup viaevict_pending_requests().FanoutCache.transact()no-op:Cache.transact()now accepts an optional shard key and forwards it;_providers_caches.pycallers passproductas the key.Why pysciqlop-cache
add(key, value, expire=, tag=)— no separate lock + check + set dance.FanoutCache.transact(key)— the SciQLop proxy plans to use FanoutCache for ~4 TB-scale storage where SQLite write contention spreading and per-shard recovery are valuable.incr,evict_tag, reentrant transactions, fixed counter races. Seepysciqlop-cachev0.1.0 release notes.Migration path for users
On first launch with the new code, Speasy detects the legacy layout (
cache.dbin the cache directory) and migrates automatically. Mechanics:<path>.diskcache.backup, then staging → original.The migration tool requires
diskcacheto be importable. We keep it inrequirements_dev.txtfor development; users upgrading from a previous Speasy install already have it installed in their environment, so the auto-migration just works. Fresh installs that never had a Speasy cache need nothing.For very large caches the migration takes minutes; it's logged at WARNING so users know what's happening.
Test plan
tests/test_cache.py— 232 passed (9:32 wall clock)closes #275