Fix race condition in bulk upsert verification - #926
Conversation
|
Warning Review limit reached
Next review available in: 54 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthrough
ChangesBulk upsert concurrency validation
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Greptile SummaryFixes one race in bulk upsert processing:
Confidence Score: 3/5The PR is not yet safe to merge because unsupported update locks and timestamp collisions still allow concurrent changes to be silently overwritten. The deletion check now rejects a missing locking read result, but Redis and non-replica-set Mongo still lack the required exclusion between verification and upsert, while the sole update comparison uses a millisecond-precision timestamp that concurrent writes can share. Files Needing Attention: src/Database/Database.php; src/Database/Adapter/Mongo.php; src/Database/Adapter/Redis.php Important Files Changed
Reviews (4): Last reviewed commit: "Merge branch 'main' into main" | Re-trigger Greptile |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/Database/Database.php`:
- Around line 7499-7501: Update the locking re-fetch in the document upsert flow
around getDocument to execute within withTenant($old->getTenant(), ...) when
tenant-per-document mode is enabled, matching the initial read’s tenant scoping;
preserve the existing authorization and silent wrappers and use the ambient
context only when tenant-per-document mode is disabled.
- Around line 7502-7504: The conflict check in upsertDocuments() must also
reject an originally existing row that is missing from the locked re-read.
Update the condition around $fresh and $old so it throws ConflictException when
$fresh is empty or its updated timestamp differs, preventing stale Change data
from recreating a concurrently deleted document.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: caa2ecea-6126-4f7b-b786-ec1463379fd8
📒 Files selected for processing (1)
src/Database/Database.php
Summary
FOR UPDATEinside the transaction.Fixes appwrite/appwrite#12960
Summary by CodeRabbit