Doctrine 2 - rowlocking does not seem to work

Showing 1-5 of 5 messages
Doctrine 2 - rowlocking does not seem to work Bram 5/29/12 1:50 PM
Im using Doctrine 2 in my Symfony 2 application. The application uses a messagequeue to process a few tasks asynchronous. The task involve a few operations on external services. Most of the tasks involve creating/updating existing local entities on the remote services. For each service a different task is put in the message queue and tasks are processed parralel to eachother, so multiple tasks involving the same entity can run at the same time. To keep track of the progress, each entity has a jobcounter that is decreased by one when a task is finished. I tried to use doctrine's build-in locking support to lock and retreive the entity, update the counter and put it back. Somehow the entity is not locked and when tasks finish in the same time, the counter is updated wrong (only decreased once instead of twice). Here is the code im using:

// $em instanceof EntityManager
$em->getConnection()->beginTransaction();

try {
$entity = $em->find('Entity', $id, LockMode::PESSIMISTIC_WRITE);
printf("Updating jobcount from %d to %d\n", $entity->getPendingJobs(), $entity->getPendingJobs() - 1);
$entity->setPendingJobs($entity->getPendingJobs() - 1);
$em->persist($entity);
$em->flush();
$em->getConnection()->commit();
} catch ( \Exception $ex ) {
$em->getConnection()->rollback();
}

For debugging purposes I placed the output, and when jobs are finished on the same time, both job processors output the same thing:
Updating jobcount from 2 to 1

Im using mysql 5.5.22-0ubuntu1. What is going wrong or what am I doing wrong? I tried it with LockMode::PESSIMISTIC_WRITE and LockMode::PESSIMISTIC_READ, both giving me the same problems.
Re: [doctrine-user] Doctrine 2 - rowlocking does not seem to work Benjamin Eberlei 5/29/12 2:25 PM
did you check the sql log if the locking is present in the SELECT?

--
You received this message because you are subscribed to the Google Groups "doctrine-user" group.
To view this discussion on the web visit https://groups.google.com/d/msg/doctrine-user/-/YEryTxzUwCAJ.
To post to this group, send email to doctri...@googlegroups.com.
To unsubscribe from this group, send email to doctrine-use...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/doctrine-user?hl=en.

Re: [doctrine-user] Doctrine 2 - rowlocking does not seem to work Bram 5/29/12 10:32 PM
Apperantly I needed to do a $em->clear(); before starting the transaction. By not doing that the entity was retreived from the doctrine cache. In some way this makes sense but it would probebly be handy if this was noted somewhere on the doctrine docs. Anyways, it works now.

Op dinsdag 29 mei 2012 23:25:02 UTC+2 schreef Benjamin Eberlei het volgende:
Re: [doctrine-user] Doctrine 2 - rowlocking does not seem to work Benjamin Eberlei 5/29/12 11:34 PM
Can you open a bug report? There is a way to fix this without the clear() by using EntityManager#lock() internally.

To view this discussion on the web visit https://groups.google.com/d/msg/doctrine-user/-/SCPE9oJ1H40J.

To post to this group, send email to doctri...@googlegroups.com.
To unsubscribe from this group, send email to doctrine-use...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/doctrine-user?hl=en.

Re: [doctrine-user] Doctrine 2 - rowlocking does not seem to work Bram 5/30/12 12:28 AM
As requested:  http://www.doctrine-project.org/jira/browse/DDC-1846