Repository navigation
fix(databases): purge cached collection before announcing schema changes - #14104
Merged
Merged
Conversation
The databases worker marked an attribute or index available (or failed, or deleted) and then fired the realtime event before purging the cached collection document in its finally block. The collection document embeds its attributes and indexes, so for the duration of the event dispatch the API still served the old schema from cache while the attribute document itself already read as available. A client that polled the attribute and created an index on it as soon as it was available could hit that gap and get a 400 "not yet available" (seen as a flake in TablesDB testPatchAttribute). Purge the collection caches first and announce afterwards in every worker path (create/delete attribute, create/delete index), so no work sits between the metadata write and the purge. The purge stays in finally so the failure paths still clear the cache. Attribute deletion now announces after the dependent index metadata is adjusted, for the same reason. The new e2e creates several attributes and indexes each one the moment its attribute reports available, polling tightly so the window is exercised on every run. Co-Authored-By: Claude Opus 5.5 <[email protected]>
🟢 Tier S · Ready to merge
The worker now purges collection caches before dispatching attribute and index realtime events, including related collections. Attribute deletion dispatch is also moved after dependent index metadata updates. A shared E2E test creates indexes immediately after attributes become available and waits for those indexes to complete.
📂 Walkthrough · 2
Reviewed |
✨ Benchmark resultsComparing
Per-scenario breakdown & investigation detailsMetrics below reflect the current branch (after). Δ P95 compares against the base.
Top API waits (after)
|
abnegate
added a commit
that referenced
this pull request
Oct 5, 2026
Bring in main e182a59: #14103 resets the presence created flag on every transaction attempt, #14104 purges the cached collection before a schema change is announced (the race behind the intermittent TablesDB testPatchAttribute 400 column_not_available), and #14105 deletes attributes through the databases handle. Conflicts: - src/Appwrite/Presences/State.php: kept the branch's lookup (userId query with authorization skipped) and took main's per-attempt reset of $presenceCreated, so a retried attempt that updates a concurrent presence no longer reports a creation. - tests/unit/Presences/StateTest.php (added on both sides): union of the branch's permission tests and main's retry tests. main's setUp() is ported to database 8.0 (Collection + Attribute::string instead of the array createCollection/createAttribute with Database::VAR_STRING). The retry test fails when the per-attempt reset is removed. Adaptations: - tests/e2e/Services/Databases/DatabasesBase.php: main's new testCreateIndexOnAttributeAsSoonAsAvailable sent Database::INDEX_KEY, which 8.0 removed; it now sends IndexType::Key->value like the rest of the file. Co-Authored-By: Claude Opus 5.5 <[email protected]>
2 tasks done
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.
What does this PR do?
Problem. The databases worker marked an attribute
available, fired the realtime event, and only then purged the cached collection document infinally. The collection document embeds its attributes and indexes. So while the event was being dispatched,GET .../attributes/:keyalready returnedavailable(it reads the attribute document, whichupdateDocumentpurges), but index create still validated against the cached collection, where the column was stillprocessing. A client that created an index as soon as the attribute was available could get400 column_not_available. This showed up as a flake inE2E / MariaDB (shared) / TablesDB testPatchAttribute.Fix. In every worker path (create/delete attribute, including relationship attributes and their related collection, and create/delete index), purge the collection caches first and fire the event afterwards. No other work then runs between the metadata write and the purge. The purge stays in
finally, so the failure paths (failed/stuck) still clear the cache. Attribute deletion now fires its event after the dependent index metadata is adjusted and purged, instead of before.Test Plan
The new e2e
testCreateIndexOnAttributeAsSoonAsAvailableis inDatabasesBase, so it runs on Legacy, TablesDB and VectorsDB for every adapter. It creates five attributes and indexes each one the moment its attribute reportsavailable. It polls every 5 ms instead of the default 500 ms, so every run exercises the gap.A deterministic fail-first e2e is not possible here. The race is between two writes inside the worker, and an e2e can only make it likely, not force it (worker tests are out of scope per AGENTS.md). With the fix, the gap shrinks to the time between the metadata commit and the next cache call. Before the fix, it included the realtime dispatch. A truly zero gap would need index create to re-check the attribute document when the cached collection disagrees. That is left out to keep this change to the worker ordering.
Related PRs and Issues
Seen as a flake on #11649 (run 37267066799, attempt 1).
Checklist
🤖 Generated with Claude Code