feat(storage): clear_caches() for out-of-band snapshot restore in tests#70
Merged
Merged
Conversation
…restore The process-wide SharedLoadCache (L2) outlives a ZODB.DB connection pool and uses a strictly monotonic consensus TID. Test harnesses that roll the database backwards out of band (snapshot restore between tests) leave it serving object state at TIDs newer than the rolled-back DB, causing a spurious ConflictError on the next commit. Add public PGJsonbStorage.clear_caches() and SharedLoadCache.clear() to drop all in-memory caches and reset the consensus TID. Not needed in production, where TIDs never decrease. Co-Authored-By: Claude Opus 4.8 (1M context) <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.
Problem
The process-wide
SharedLoadCache(L2, added in 1.12.0 / #63) outlives aZODB.DBconnection pool and uses a strictly monotonic consensus TID. Test harnesses that roll the database backwards out of band — e.g. restoring a snapshot between tests (PGTestDB.restore()doesDELETE+COPYof baseline rows at their original, lower TIDs) — leave the shared cache serving object state at TIDs newer than the rolled-back DB. The next commit then conflict-checks the in-memory_serial(newer) against the DB row (older) and raises a spurious, unresolvableConflictError.This surfaced downstream in
plone.pgcatalog: twoclearFindAndRebuildintegration tests fail withConflictErroronProducts.ZCTextIndex...PLexiconwhenever a rebuild test runs after another rebuild test. Green before 1.12.0 (no shared cache), red after.Fix
Add two public methods:
SharedLoadCache.clear()— drop all entries and reset_consensus_tidtoNone, so the nextpoll_advancere-establishes consensus from the (lower) current TID.PGJsonbStorage.clear_caches()— reset the shared L2 cache, the main L1 load cache, and the serial cache.In production TIDs never decrease (pack never lowers a live object's TID), so this is not part of the normal code path — it is a hook for test harnesses doing out-of-band rollbacks.
Tests
TDD:
tests/test_shared_load_cache.pygainsTestClear(incl. a backwards-TID regression: afterclear(), a lower TID is accepted again) and a storage-levelclear_caches()test.🤖 Generated with Claude Code