Fence document cache fills#903
Conversation
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ 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 |
a94c08d to
a8ca092
Compare
|
Closing this draft because the fix now lives in utopia-php/cache as hidden cache fencing; this database branch only updates the dev dependency and no longer carries a meaningful library change. |
What
Uses the fenced cache lease API from
utopia-php/cacheto guard document cache fills inDatabase::getDocument().Depends on: utopia-php/cache#74
Why
A cache-miss read can race with a concurrent writer purge: the reader fetches an older DB row, the writer commits and purges, then the reader saves the older document back into cache. The database layer then serves that poisoned document to whole-document read-modify-write callers, which can permanently overwrite fields with stale values.
Changes
getDocument()calls.saveLease()so a purge between read and save makes the fill a no-op.utopia-php/cacheatdev-cache-lease-fencefrom the cache PR branch and update the lockfile.Validation
php -l src/Database/Database.phpcomposer validate --strict --no-check-publishphp -d memory_limit=2G vendor/bin/pint --test composer.json src/Database/Database.php tests/unit/ForUpdateCacheTest.phpvendor/bin/phpunit --configuration phpunit.xml tests/unit/ForUpdateCacheTest.phpvendor/bin/phpstan analyse --level 7 src/Database/Database.php --memory-limit 2GNote: Composer update required
--ignore-platform-req=ext-pcovlocally becauseext-pcovis not installed in this environment.