Repository navigation
fix: publish grid cache cells atomically and preserve invalidations - #9
Draft
afonsobspinto wants to merge 1 commit into
Draft
afonsobspinto wants to merge 1 commit into
afonsobspinto wants to merge 1 commit into
Conversation
Coordinate cache workers and other cooperating refresh callers with one advisory lock and transaction per cell. Acknowledge only the dirty-row version observed before generation, preserve newer invalidations, and record generation time after acquiring the lock. Add nine PostgreSQL transaction and concurrency tests covering source-read serialization, independent cells, invalidation races, atomic payload visibility, rollback, and worker integration. Validated on PostgreSQL 16/PostGIS with Django 5.2.17 and psycopg 3.3.6; negative controls reproduce failures with the upstream worker and unsafe dirty-marker removal.
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.
Purpose
Draft for internal review before opening against upstream
catmaid/CATMAID:dev. The shared helper and cache-worker fixes are already included infeature/new-ingestion(PR #7). This PR isolates those runtime changes and adds PostgreSQL regression tests for review before submitting upstream.What changed and why
Adds
catmaid.control.grid_cache.locked_grid_cell()and uses it in the normalGridWorker:xmin) before generation. Clear only that version after successful publication, preserving newer invalidations.clock_timestamp()after acquiring the lock.The helper is shared with the ingestion rebuild in
feature/new-ingestion; this internal PR contains no importer or provenance code. It does not change worker node limits, grid settings, payload selection or query geometry.Before and after examples
1. An edit arrives during generation
A node moves from X=100 to X=200 while its cell is refreshing.
Existing notifications may trigger another refresh in either version; the fix prevents losing the database's evidence that another refresh is needed. Comparing
xminalso works when two invalidations have identical timestamps or a longer-running transaction records an older timestamp.2. A slower refresh overwrites a newer result
Before:
After:
This also coordinates a normal worker with an importer using the same helper. Making a Neuroglass layer inactive does not stop already queued cache jobs.
3. MessagePack serialization fails after JSON was written
For a grid storing only MessagePack, the multiple-format benefit is smaller; same-cell serialization and safe invalidation acknowledgement still apply.
4. Generation waits for a lock
If a transaction starts at 10:00 but acquires its cell lock at 10:02, PostgreSQL's
now()still reports 10:00. The helper records generation beginning at 10:02, after the wait. This supports accurate freshness checks with the locking protocol.Scope and limitations
Advisory locking coordinates callers using this helper; other cache-writing paths do not automatically participate. It does not lock skeleton editing or ordinary reads. An offline full rebuild can still leave missing or partial coverage, so the target ingestion layer must remain inactive through final verification.
The rectangular-cell bounds correction is reviewed separately in PR #8.
Validation
Adds nine PostgreSQL transaction/concurrency tests using independent database connections and explicit synchronization. They cover:
All nine pass on PostgreSQL 16/PostGIS with the internal
metacellruntime (Django 4.2.30/psycopg2) and were also validated on upstreamdev(Django 5.2.17/psycopg 3.3.6).Negative controls confirmed that the two worker regressions fail with the original upstream worker, and two invalidation regressions fail when dirty-row version checks are removed.
python manage.py test catmaid.tests.test_grid_cache_transactionsNo database migrations. This internal branch contains one fix commit directly on
metacell; cherry-pick it onto current upstreamdevafter internal review.