Long cursored query and concurrent updates leads to out-of-date reads from long query [message #1636300] |
Thu, 26 February 2015 05:59 |
Vjacheslav Borisov Messages: 6 Registered: March 2014 |
Junior Member |
|
|
Long cursored query and concurrent updates leads to out-of-date reads from long query
I have Client:Segment many-to-many entity relation
I have long running cursored query
Query query = em.createQuery("SELECT c FROM Client c WHERE c.clientUUID between :clientUUIDFrom and :clientUUIDTill ORDER BY c.clientUUID");
query.setParameter("clientUUIDFrom", clientUUIDFrom);
query.setParameter("clientUUIDTill", clientUUIDTo);
query.setHint(QueryHints.CURSOR, HintValues.TRUE);
query.setHint(QueryHints.QUERY_RESULTS_CACHE, HintValues.FALSE);
query.setHint(QueryHints.LEFT_FETCH,"c.segments");
One thread reads all records and updates many-to-many relation.
This is working when there is no concurrent work on same entity
But when there is short concurrent update in other thread, which alters many-to-many relation of entity, and later same entity being read from long query, it reads it in old state.
And update of this entity leads to mysql exception
Duplicate entry '693502093-10' for key 'PRIMARY'
Becouse relation 693502093-10 aready persisted in parallel thread before.
How to correctly lock / invalidate results of long cursored query in case of concurrent updates?
[Updated on: Fri, 27 February 2015 04:58] Report message to a moderator
|
|
|
Powered by
FUDForum. Page generated in 0.02659 seconds