DDC-3858: Doctrine SLC and @version, failure to get optimistic lock #4725

Open
opened 2026-01-22 14:48:23 +01:00 by admin · 1 comment
Owner

Originally created by @doctrinebot on GitHub (Jul 31, 2015).

Jira issue originally created by user dorrogeray:

Greetings everyone,

UPDATE: As a temporary workaround, I switched to the less performant READ_WRITE with the basic filelock implementation, and the problem went away.

I am using Doctrine 2.5 with SLC enabled (memcached) and I have encountered some strange behaviour. When doctrine fetches entities from cache, the @version column is actually set to NULL instead of whatever value is correctly in the database - looks like the @version doesn't get updated as far as cache is concerned.

Note that afected entity uses @ORM\Cache(usage="NONSTRICT_READ_WRITE", region="Entity\Contact")

If I restart memcached, correct @version is loaded (because of the force reload).

This also leads to failure to get optimistic lock (due to incorrectly evaluated version mismatch).

I have no idea, but could this be somehow related to http://www.doctrine-project.org/jira/browse/DDC-3781 ?

For now, Ill try to prevent this issue from occurring by clearing updated entities from cache, and thus forcing their reload by whoever will request them next.

Thanks for any response/advice!

Here is part of call stack, this time failing on different entity, but for the same reason:
#0 /var/www/TravelSupport/vendor/doctrine/orm/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php(483): Doctrine\ORM\OptimisticLockException::lockFailed(Object(DoctrineORMModule\Proxy*CG\CsnTour\Entity\Customer))
#1 /var/www/TravelSupport/vendor/doctrine/orm/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php(366): Doctrine\ORM\Persisters\Entity\BasicEntityPersister->updateTable(Object(DoctrineORMModule\Proxy
CG\CsnTour\Entity\Customer), 'customer', Array, true)
#2 /var/www/TravelSupport/vendor/doctrine/orm/lib/Doctrine/ORM/Cache/Persister/Entity/NonStrictReadWriteCachedEntityPersister.php(95): Doctrine\ORM\Persisters\Entity\BasicEntityPersister->update(Object(DoctrineORMModule\Proxy
CG\CsnTour\Entity\Customer))
#3 /var/www/TravelSupport/vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php(1069): Doctrine\ORM\Cache\Persister\Entity\NonStrictReadWriteCachedEntityPersister->update(Object(DoctrineORMModule\Proxy
CG*\CsnTour\Entity\Customer))
#4 /var/www/TravelSupport/vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php(384): Doctrine\ORM\UnitOfWork->executeUpdates(Object(Doctrine\ORM\Mapping\ClassMetadata))
#5 /var/www/TravelSupport/vendor/doctrine/orm/lib/Doctrine/ORM/EntityManager.php(356): Doctrine\ORM\UnitOfWork->commit(NULL)
#6 /var/www/TravelSupport/module/CsnTour/src/CsnTour/Controller/TicketController.php(2014): Doctrine\ORM\EntityManager->flush()

Originally created by @doctrinebot on GitHub (Jul 31, 2015). Jira issue originally created by user dorrogeray: Greetings everyone, UPDATE: As a temporary workaround, I switched to the less performant READ_WRITE with the basic filelock implementation, and the problem went away. I am using Doctrine 2.5 with SLC enabled (memcached) and I have encountered some strange behaviour. When doctrine fetches entities from cache, the @version column is actually set to NULL instead of whatever value is correctly in the database - looks like the @version doesn't get updated as far as cache is concerned. Note that afected entity uses @ORM\Cache(usage="NONSTRICT_READ_WRITE", region="Entity\Contact") If I restart memcached, correct @version is loaded (because of the force reload). This also leads to failure to get optimistic lock (due to incorrectly evaluated version mismatch). I have no idea, but could this be somehow related to http://www.doctrine-project.org/jira/browse/[DDC-3781](http://www.doctrine-project.org/jira/browse/DDC-3781) ? For now, Ill try to prevent this issue from occurring by clearing updated entities from cache, and thus forcing their reload by whoever will request them next. Thanks for any response/advice! Here is part of call stack, this time failing on different entity, but for the same reason: #0 /var/www/TravelSupport/vendor/doctrine/orm/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php(483): Doctrine\ORM\OptimisticLockException::lockFailed(Object(DoctrineORMModule\Proxy*_CG_*\CsnTour\Entity\Customer)) #1 /var/www/TravelSupport/vendor/doctrine/orm/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php(366): Doctrine\ORM\Persisters\Entity\BasicEntityPersister->updateTable(Object(DoctrineORMModule\Proxy*_CG_*\CsnTour\Entity\Customer), '`customer`', Array, true) #2 /var/www/TravelSupport/vendor/doctrine/orm/lib/Doctrine/ORM/Cache/Persister/Entity/NonStrictReadWriteCachedEntityPersister.php(95): Doctrine\ORM\Persisters\Entity\BasicEntityPersister->update(Object(DoctrineORMModule\Proxy*_CG_*\CsnTour\Entity\Customer)) #3 /var/www/TravelSupport/vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php(1069): Doctrine\ORM\Cache\Persister\Entity\NonStrictReadWriteCachedEntityPersister->update(Object(DoctrineORMModule\Proxy*_CG_*\CsnTour\Entity\Customer)) #4 /var/www/TravelSupport/vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php(384): Doctrine\ORM\UnitOfWork->executeUpdates(Object(Doctrine\ORM\Mapping\ClassMetadata)) #5 /var/www/TravelSupport/vendor/doctrine/orm/lib/Doctrine/ORM/EntityManager.php(356): Doctrine\ORM\UnitOfWork->commit(NULL) #6 /var/www/TravelSupport/module/CsnTour/src/CsnTour/Controller/TicketController.php(2014): Doctrine\ORM\EntityManager->flush()
admin added the Bug label 2026-01-22 14:48:23 +01:00
Author
Owner

@doctrinebot commented on GitHub (Aug 4, 2015):

Comment created by @FabioBatSilva:

[~dorrogeray],
Can you please add a failing test case ?

If you need help to write the test you can use this ticket as a reference.

@doctrinebot commented on GitHub (Aug 4, 2015): Comment created by @FabioBatSilva: [~dorrogeray], Can you please add a failing test case ? If you need help to write the test you can use this [ticket](https://github.com/doctrine/doctrine2/blob/master/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2862Test.php) as a reference.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#4725