Repository navigation
fix(databases): return the committed row from get after a transaction - #14201
Conversation
A staged commit runs each write inside an outer transaction, so updateDocument() purges the document cache when its savepoint releases, before COMMIT. A get in that window caches the pre-commit row and serves it until the next write or the cache TTL. Purge every row the commit wrote once that outer transaction returns. Fixes #14173
Security rulesNo new WARNING or ERROR findings from security rules. 32 existing findings tracked in
|
✨ Benchmark resultsComparing
Per-scenario breakdown & investigation detailsMetrics below reflect the current branch (after). Δ P95 compares against the base.
Top API waits (after)
|
PHPStan does not resolve Utopia\Console\Console. Log a failed purge through Utopia\Console, matching the other database actions, so a cache error still cannot fail a commit that already landed.
…t state applyBulkDeleteToState() matches the delete's queries in memory and ignores limit, cursor and filters it cannot evaluate, so it can unset rows from $state that the database kept. Those rows then missed the post-commit purge, and a read in the savepoint-to-COMMIT window left a stale entry (a 404 for a row that exists). Record every row still in $state for the collection before that call. Also trim the purge bookkeeping: $state keys are always either an operation's row id, which is already recorded, or the row's own id, so collect only the row ids. Drop the no-op casts and empty-id guards, and name the Database parameter $dbForDatabases like the other handlers.
A single sequential client never reads between the in-savepoint purge and COMMIT, so the test passes with or without the post-commit purge. testUpdateDocument already covers a get after commit with a warmed cache.
|
Review complete. No issues found — approved ✅. This change updates the transactions
Reviewed commit: ff08776 |
|
@hansi-codes review |
🔵 Tier A · Mergeable after minor fixes
Database transaction commits now record cache purges made during their writes and replay them after the outer transaction commits. An E2E regression test polls a row while a staged update and filler creates are committed. Latest changes: The latest commits replace explicit row and relationship ID collection with recording all cache purges during the transaction and replaying them after COMMIT, and simplify the concurrency regression to one update-plus-filler test.
Fix with agent prompt### Issue 1
tests/e2e/Services/Databases/Transactions/TransactionsBase.php:2135-2141
**Keep coverage for implicit relationship and cascade purges**
This revision removes the nested-update and cascade-delete concurrency tests, leaving only a direct-row update case. Since the new approach relies on the database layer issuing purge calls for implicit relationship and cascade writes, a missed purge in either path would now pass this suite; retaining coverage for those cases would protect the broader behavior.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.📂 Walkthrough · 3
✅ Fixed since the last review · 1
Merged |
A nested child written with its parent is purged inside the savepoint, so a concurrent get can cache the pre-commit child. Record those related rows with the parent, and overlap readers with the commit so the following get must return the committed value. Fixes #14173
|
Nested related rows are now included in the post-commit purge. A staged create, update, or upsert records those child ids from the operation payload and from the row written when the nested document had no id yet, then purges them after the outer transaction returns.
|
|
@hansi-codes review |
| if (!\in_array($action, ['create', 'update', 'upsert'], true)) { | ||
| return; |
There was a problem hiding this comment.
Include related rows affected by staged deletes
A staged delete with onDelete: cascade also deletes related rows, but this early return excludes them, and neither $written nor $state records those child IDs. A concurrent child read can therefore re-cache the pre-delete row before COMMIT and keep returning it afterwards; please capture and purge the affected related IDs for delete operations too.
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/Appwrite/Platform/Modules/Databases/Http/Databases/Transactions/Update.php
Line: 654-655
Comment:
**Include related rows affected by staged deletes**
A staged delete with `onDelete: cascade` also deletes related rows, but this early return excludes them, and neither `$written` nor `$state` records those child IDs. A concurrent child read can therefore re-cache the pre-delete row before COMMIT and keep returning it afterwards; please capture and purge the affected related IDs for delete operations too.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.🟡 Minor · bug · Reply if this doesn't apply.
A staged delete with onDelete cascade removes related rows inside the savepoint, so a concurrent get can cache the pre-delete child. Record those ids before the delete and purge them after the outer commit. Fixes #14173.
|
Staged deletes with
|
|
@hansi-codes review |
|
Already reviewed 28e637f. No new commits since then, so I didn't post another review. |
Record the cache keys purged while the commit's outer transaction runs and purge them again once it returns, instead of rebuilding the written row set from operations, state and relationship metadata. This covers every write path the database layer purges, including relationship writes it runs silently. Rows in collections with relationship attributes are never cached, so the nested and cascade discovery is dropped along with its tests. The remaining test polls getRow for the whole commit and fails without the fix.
| $operations = [[ | ||
| 'action' => 'update', | ||
| 'databaseId' => $databaseId, | ||
| $this->getContainerIdParam() => $collectionId, | ||
| $this->getRecordIdParam() => $documentId, | ||
| 'data' => ['name' => 'done'], | ||
| ]]; |
There was a problem hiding this comment.
Keep coverage for implicit relationship and cascade purges
This revision removes the nested-update and cascade-delete concurrency tests, leaving only a direct-row update case. Since the new approach relies on the database layer issuing purge calls for implicit relationship and cascade writes, a missed purge in either path would now pass this suite; retaining coverage for those cases would protect the broader behavior.
Prompt To Fix With AI
This is a comment left during a code review.
Path: tests/e2e/Services/Databases/Transactions/TransactionsBase.php
Line: 2135-2141
Comment:
**Keep coverage for implicit relationship and cascade purges**
This revision removes the nested-update and cascade-delete concurrency tests, leaving only a direct-row update case. Since the new approach relies on the database layer issuing purge calls for implicit relationship and cascade writes, a missed purge in either path would now pass this suite; retaining coverage for those cases would protect the broader behavior.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.🟡 Minor · testing · Reply if this doesn't apply.
Brings in main's post-commit cache purges for transactions (#14201). It merges cleanly onto the database 8.0 API. Co-Authored-By: Claude Opus 5.5 <[email protected]>
What does this PR do?
After a transaction commit,
getRowcould keep serving the pre-commit row (or a 404 for a row the commit created) until the next write to that row or the 24h document-cache TTL.The commit endpoint runs every staged write inside one outer
withTransaction(), so each write's cache purge runs inside a savepoint, before the realCOMMIT. A read in that window misses the cache, reads the still-committed old row, and caches it.The commit now runs under
Cache::recordPurges(), which records every key purged while it runs, and purges those keys again once the outer transaction returns. This covers every write path the database purges, including relationship writes it runs silently. A cache error is logged and does not fail a commit that already landed.utopia-php/database 8.x purges after the outermost commit itself, so this can go when Appwrite moves to it.
Test Plan
testGetAfterCommitWithConcurrentReadsstages an update plus 90 filler creates and keeps 8 readers pollinggetRowfor the whole commit. It fails onmainand passes with this change.Local repro (PostgreSQL, Redis), 10 rounds per write type:
mainLegacy transactions server, client and ACID e2e suites pass.
Related PRs and Issues
Checklist
🤖 Generated with Claude Code