You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@openjpa.apache.org by mrgiba <mr...@ig.com.br> on 2013/10/08 22:18:20 UTC

Supposed concurrent access issue to PCPath instance

Hi,

Has anyone ever experienced any issue with concurrent access to PCPath
resources ?

I got the error below once:



The error happened in a multi user scenario when processing the following
query:



Looking at the OpenJPA 2.2.1 source code, I noticed that not all methods
that read/write the _actions collection from CandidatePath class (super
class of PCPath) have a synchronized block or any other concurrency control.
If the same PCPath instance can really be accessed by more than one thread,
then there are really chances to trouble



--
View this message in context: http://openjpa.208410.n2.nabble.com/Supposed-concurrent-access-issue-to-PCPath-instance-tp7585102.html
Sent from the OpenJPA Developers mailing list archive at Nabble.com.

Re: Supposed concurrent access issue to PCPath instance

Posted by Rick Curtis <cu...@gmail.com>.
Also, can we see the entire stack trace?


On Wed, Oct 9, 2013 at 11:12 AM, Kevin Sutter <kw...@gmail.com> wrote:

> In general, I would say it's not possible for PCPath to be shared by
> multiple threads.  There could be a bug here, but we're not aware of one.
>
> Just for giggles, can you run with openjpa.Mulithreaded set to true and let
> us know the results.
>
> Thanks, Kevin
>
>
> On Wed, Oct 9, 2013 at 8:53 AM, givanildo.alves <mr...@ig.com.br> wrote:
>
> > As a complement to my previous post, one question: in a scenario where
> each
> > thread has its own EntityManager instance, is it possible for a PCPath
> > instance be shared by multiple threads ?
> >
> > Thanks
> >
> >
> >
> > --
> > View this message in context:
> >
> http://openjpa.208410.n2.nabble.com/Supposed-concurrent-access-issue-to-PCPath-instance-tp7585102p7585114.html
> > Sent from the OpenJPA Developers mailing list archive at Nabble.com.
> >
>



-- 
*Rick Curtis*

Re: Supposed concurrent access issue to PCPath instance

Posted by "givanildo.alves" <mr...@ig.com.br>.
Sure. I just simplified the full stack trace, for the reader's sake:

Failed to execute query "SELECT rec FROM com.testapp.model.TestRecord... ".
Check the query syntax for correctness. See nested exception for details.
	at org.apache.openjpa.kernel.QueryImpl.execute(QueryImpl.java:872)
	at org.apache.openjpa.kernel.QueryImpl.execute(QueryImpl.java:794)
	at
org.apache.openjpa.kernel.DelegatingQuery.execute(DelegatingQuery.java:542)
	at org.apache.openjpa.persistence.QueryImpl.execute(QueryImpl.java:286)
	at
org.apache.openjpa.persistence.QueryImpl.getResultList(QueryImpl.java:302)
...
Caused by: java.util.ConcurrentModificationException
	at java.util.LinkedList$LinkIterator.next(LinkedList.java:119)
	at
org.apache.openjpa.jdbc.kernel.exps.PCPath.getPCPathString(PCPath.java:260)
	at
org.apache.openjpa.jdbc.kernel.exps.ContainsExpression.initialize(ContainsExpression.java:44)
	at
org.apache.openjpa.jdbc.kernel.exps.AndExpression.initialize(AndExpression.java:47)
	at
org.apache.openjpa.jdbc.kernel.exps.AndExpression.initialize(AndExpression.java:48)
	at
org.apache.openjpa.jdbc.kernel.exps.SelectConstructor.initialize(SelectConstructor.java:232)
	at
org.apache.openjpa.jdbc.kernel.exps.SelectConstructor.newSelect(SelectConstructor.java:173)
	at
org.apache.openjpa.jdbc.kernel.exps.SelectConstructor.evaluate(SelectConstructor.java:87)	
	at
org.apache.openjpa.jdbc.kernel.JDBCStoreQuery.createWhereSelects(JDBCStoreQuery.java:360)
	at
org.apache.openjpa.jdbc.kernel.JDBCStoreQuery.executeQuery(JDBCStoreQuery.java:193)
	at
org.apache.openjpa.kernel.ExpressionStoreQuery$DataStoreExecutor.executeQuery(ExpressionStoreQuery.java:783)
	at org.apache.openjpa.kernel.QueryImpl.execute(QueryImpl.java:1005)
	at org.apache.openjpa.kernel.QueryImpl.execute(QueryImpl.java:863)
	... 96 more

In terms of syntax, the JPQL query is correct. 
We run our regression every day in a list of machines and we stumbled upon
that concurrent modification error once, in one machine, so the error seems
to be related to some seldom timing of threads. Therefore, only enabling the
openjpa.Mulithreaded property is not enough for me to tell whether the
problem is gone. I'll have look at our code and look for holes in our
control to ensure EntityManagers are not shared accross threads

Thanks



--
View this message in context: http://openjpa.208410.n2.nabble.com/Supposed-concurrent-access-issue-to-PCPath-instance-tp7585102p7585117.html
Sent from the OpenJPA Developers mailing list archive at Nabble.com.

Re: Supposed concurrent access issue to PCPath instance

Posted by Kevin Sutter <kw...@gmail.com>.
In general, I would say it's not possible for PCPath to be shared by
multiple threads.  There could be a bug here, but we're not aware of one.

Just for giggles, can you run with openjpa.Mulithreaded set to true and let
us know the results.

Thanks, Kevin


On Wed, Oct 9, 2013 at 8:53 AM, givanildo.alves <mr...@ig.com.br> wrote:

> As a complement to my previous post, one question: in a scenario where each
> thread has its own EntityManager instance, is it possible for a PCPath
> instance be shared by multiple threads ?
>
> Thanks
>
>
>
> --
> View this message in context:
> http://openjpa.208410.n2.nabble.com/Supposed-concurrent-access-issue-to-PCPath-instance-tp7585102p7585114.html
> Sent from the OpenJPA Developers mailing list archive at Nabble.com.
>

Re: Supposed concurrent access issue to PCPath instance

Posted by "givanildo.alves" <mr...@ig.com.br>.
As a complement to my previous post, one question: in a scenario where each
thread has its own EntityManager instance, is it possible for a PCPath
instance be shared by multiple threads ?

Thanks



--
View this message in context: http://openjpa.208410.n2.nabble.com/Supposed-concurrent-access-issue-to-PCPath-instance-tp7585102p7585114.html
Sent from the OpenJPA Developers mailing list archive at Nabble.com.

Re: Supposed concurrent access issue to PCPath instance

Posted by "givanildo.alves" <mr...@ig.com.br>.
Oh yes, my application ensures an EntityManager instance is not shared by
multiple threads.

The intermittent error is:

Caused by: java.util.ConcurrentModificationException
	at java.util.LinkedList$LinkIterator.next(LinkedList.java:119)
	at
org.apache.openjpa.jdbc.kernel.exps.PCPath.getPCPathString(PCPath.java:260)
	at
org.apache.openjpa.jdbc.kernel.exps.ContainsExpression.initialize(ContainsExpression.java:44)
	at
org.apache.openjpa.jdbc.kernel.exps.AndExpression.initialize(AndExpression.java:47)
	at
org.apache.openjpa.jdbc.kernel.exps.AndExpression.initialize(AndExpression.java:48)
	at
org.apache.openjpa.jdbc.kernel.exps.SelectConstructor.initialize(SelectConstructor.java:232)
	at
org.apache.openjpa.jdbc.kernel.exps.SelectConstructor.newSelect(SelectConstructor.java:173)
	at
org.apache.openjpa.jdbc.kernel.exps.SelectConstructor.evaluate(SelectConstructor.java:87)
	at
org.apache.openjpa.jdbc.kernel.JDBCStoreQuery.createWhereSelects(JDBCStoreQuery.java:360)
	at
org.apache.openjpa.jdbc.kernel.JDBCStoreQuery.executeQuery(JDBCStoreQuery.java:193)
	at
org.apache.openjpa.kernel.ExpressionStoreQuery$DataStoreExecutor.executeQuery(ExpressionStoreQuery.java:783)
	at org.apache.openjpa.kernel.QueryImpl.execute(QueryImpl.java:1005)
	at org.apache.openjpa.kernel.QueryImpl.execute(QueryImpl.java:863)
	... 96 more


The query is:

SELECT rec FROM com.testapp.model.TestRecord rec
WHERE
    EXISTS (
SELECT attr
FROM com.testapp.model.TestAttribute attr
WHERE attr.record = rec AND attr.namespace.namespaceURI = ?1 AND attr.name =
?2 AND ( ( attr.valueTypeId = ?3 AND attr.stringValue = ?4 )))
     AND ?5 MEMBER OF rec.recordTypes
     AND rec.isVirtual = ?6
     AND rec.recordId NOT IN (?7)


Thanks




--
View this message in context: http://openjpa.208410.n2.nabble.com/Supposed-concurrent-access-issue-to-PCPath-instance-tp7585102p7585113.html
Sent from the OpenJPA Developers mailing list archive at Nabble.com.

Re: Supposed concurrent access issue to PCPath instance

Posted by Kevin Sutter <kw...@gmail.com>.
Something's missing from your post.  There is no error message or query
posted...

As far as mulit-user access...  EntityManagers are not meant to be shared
by multiple threads.  That's defined by the spec.  So, under normal
circumstances, not protecting the data structures down these paths is fine.

As a quick test, you can set the property openjpa.Multithreaded to true
[1].  If you use this property and you no longer experience this
concurrency issue, then this shows that you have a problem with your
application.  You are either accidentally or on purpose sharing an instance
of an EM.  You should not be doing that.  Find out how to modify your
application to avoid the use of this property and then remove it.

Good luck,
Kevin


[1]
http://ci.apache.org/projects/openjpa/trunk/docbook/manual.html#openjpa.Multithreaded


On Tue, Oct 8, 2013 at 3:18 PM, mrgiba <mr...@ig.com.br> wrote:

> Hi,
>
> Has anyone ever experienced any issue with concurrent access to PCPath
> resources ?
>
> I got the error below once:
>
>
>
> The error happened in a multi user scenario when processing the following
> query:
>
>
>
> Looking at the OpenJPA 2.2.1 source code, I noticed that not all methods
> that read/write the _actions collection from CandidatePath class (super
> class of PCPath) have a synchronized block or any other concurrency
> control.
> If the same PCPath instance can really be accessed by more than one thread,
> then there are really chances to trouble
>
>
>
> --
> View this message in context:
> http://openjpa.208410.n2.nabble.com/Supposed-concurrent-access-issue-to-PCPath-instance-tp7585102.html
> Sent from the OpenJPA Developers mailing list archive at Nabble.com.
>