mirror of
https://github.com/doctrine/orm.git
synced 2026-03-24 06:52:09 +01:00
Should locking a result for PESSIMISTIC_WRITE refresh the entity cache? #5658
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @shauno on GitHub (Aug 26, 2017).
Originally assigned to: @lcobucci on GitHub.
I'm new to Doctrine and recently ran into an issue in a high(ish) concurrency environment.
In short, when fetching an entity with
$query->setLockMode(LockMode::PESSIMISTIC_WRITE);, the result will be overwritten with a cached result if that entity has been fetched earlier in the script (even though the actual query will correctly wait on getting a proper lock, and return the latest correct data).In researching the issue, I found I can add a
->setHint(Query::HINT_REFRESH, true)to the query which will make sure the entity is not loaded from cache, but should that not be the default behavior when using aLockMode::PESSIMISTIC_WRITEon the query?I've put together a simple repo illustrating the issue here: https://github.com/shauno/doctrine-stale-demo
@Ocramius commented on GitHub (Aug 28, 2017):
@shauno I'd say that a pessimistic write should not use the L2 cache at all. @lcobucci thoughts?
We can't do much with demos if they aren't in our test suite, sorry :-(
@Ocramius commented on GitHub (Aug 28, 2017):
Ah yes, in order to ensure that other clients are blocked, then a pessimistic write lock is also required to clear the cache. I'd say this only applies to a
READ_WRITEcache, not to other caching mechanisms. If another client wants to read the data without actually modifying it,NONSTRICT_READ_WRITEshould just keep going, without being affected by the lock.The "why" of this needs to be pictured in a series of test scenarios.