Skip to content

feat(storage): clear_caches() for out-of-band snapshot restore in tests#70

Merged
jensens merged 1 commit into
mainfrom
fix/reset-shared-cache-after-restore
Jun 15, 2026
Merged

feat(storage): clear_caches() for out-of-band snapshot restore in tests#70
jensens merged 1 commit into
mainfrom
fix/reset-shared-cache-after-restore

Conversation

@jensens

@jensens jensens commented Jun 15, 2026

Copy link
Copy Markdown
Member

Problem

The process-wide SharedLoadCache (L2, added in 1.12.0 / #63) outlives a ZODB.DB connection 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() does DELETE + COPY of 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, unresolvable ConflictError.

This surfaced downstream in plone.pgcatalog: two clearFindAndRebuild integration tests fail with ConflictError on Products.ZCTextIndex...PLexicon whenever 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_tid to None, so the next poll_advance re-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.py gains TestClear (incl. a backwards-TID regression: after clear(), a lower TID is accepted again) and a storage-level clear_caches() test.

  • New tests: 3 passed (RED→GREEN verified).
  • Full suite: 533 passed, ruff clean.

🤖 Generated with Claude Code

…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>
@jensens jensens merged commit 9082af5 into main Jun 15, 2026
5 checks passed
@jensens jensens deleted the fix/reset-shared-cache-after-restore branch June 15, 2026 22:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant