Issue Details (XML | Word | Printable)

Key: JDO-238
Type: Bug Bug
Status: Resolved Resolved
Resolution: Fixed
Priority: Minor Minor
Assignee: Martin Zaun
Reporter: Michael Bouschen
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
JDO

Timing bug in TCK test case ThreadSafe

Created: 09/Dec/05 07:33 PM   Updated: 10/Mar/06 04:15 AM
Return to search
Component/s: tck11, tck2
Affects Version/s: JDO 2 beta
Fix Version/s: JDO 2 final

Time Tracking:
Not Specified

File Attachments:
  Size
Java Source File Licensed for inclusion in ASF works ThreadSafe.java 2006-03-09 04:28 AM Martin Zaun 7 kB
File Licensed for inclusion in ASF works ThreadSafe.java.diff 2006-03-09 04:28 AM Martin Zaun 9 kB

Resolution Date: 10/Mar/06 04:05 AM


 Description  « Hide
The TCK test ThreadSafe runs multiple threads, where each thread tries to persist the same pc instance using its own PM. The expected behavior is that one thread succeeds persisting the pc instance and stores it at transaction commit. All other threads should result in a JDOException because the pc instance is already bound to a different PM. All threads close the PM at the end.

Now, it might happen that the succeeding thread closes the PM before a parallel thread tries to persist the pc instance. The behavior of pm.makePersistence for a pc instance bound to a closed pm is not specified, so it does not necessarily result in an exception.

The test case should be changed such that the succeeding thread waits for all the other threads before closing the PM. Please note, the solution must be robust enough to avoid a deadlock situation even if an erroneous JDO implementation would allow multiple threads to succeed persisting the pc instance.

 All   Comments   Work Log   Change History   Subversion Commits      Sort Order: Ascending order - Click to sort in descending order
Craig Russell made changes - 04/Feb/06 04:27 AM
Field Original Value New Value
Affects Version/s JDO 2 beta [ 12310683 ]
Fix Version/s JDO 2 rc1 [ 12310771 ]
Martin Zaun added a comment - 07/Feb/06 03:48 PM
The described issue is to be fixed by putting a 'barrier' synchronization before the pm.close(). There's a barrier utility that comes with JDK5 (in java.util.concurrent.CyclicBarrier), which cannot be used here to avoid introducing such a dependency. So, I've written a simple (and limited) barrier class that will do for the TCK tests.

That barrier utility class is to be used from both, tck11's and tck20's
  org.apache.jdo.tck.api.persistencemanager.ThreadSafe
tests. So, unless there's a common directory for shared utilities, I'm going to duplicate the barrier source into both, tck11's and tck20's, test classes.

Martin Zaun added a comment - 10/Feb/06 11:58 PM
The barrier class is likely to be used in other TCK tests, I'm therefore putting it into:
tck20/src/java/org/apache/jdo/tck/util and tck11/test/java/org/apache/jdo/tck/util.

Reviewing the ThreadSafe test class with Craig, we'd like it to be extended to test 2 thread-safety aspects by 4 tests:
1) Thread-Safety of PersistenceManagerFactory.getPersistenceManager():
        - pm=pmf.getPM(), barrier, pm.close()
        - pm=pmf.getPM(), pm.makePersistent(private PC instance), barrier, pm.close()
    No exceptions must occur.

2) Thread-Safety of PersistenceManager.makePersistent() on non-managed instances:
        - pm.makePersistent(shared transient PC instance), barrier, pm.close()
        - pm.makePersistent(shared detached PC instance), barrier, pm.close()
    Only one thread must succeed; all others must throw exactly a JDOUserException.

We don't intend to test concurrency within in a transaction (shared PM/Tx) at this time.

Craig Russell made changes - 25/Feb/06 07:41 AM
Fix Version/s JDO 2 final [ 12310830 ]
Fix Version/s JDO 2 rc1 [ 12310771 ]
Martin Zaun added a comment - 09/Mar/06 04:18 AM
Craig L Russell wrote:
>
> I think it's too late to add the requirement for thread-safety for
> makePersistent of the same detachable instance by multiple threads.
>
> So I'd write a separate low priority JIRA for the thread-safe
> makePersistent detachable and mark it for an unknown release. The rest
> of the thread-safe cases should be good to go.

OK. Created JDO-333 for testing thread-safety of operations on detached instances.
Dropping test pm.makePersistent(shared detached PC instance) from ThreadSafe.java.

Martin Zaun added a comment - 09/Mar/06 04:28 AM
Attached is the fixed ThreadSafe test (using a barrier), extended for 3 subtests (see comments).
By request, the entire source + diffs are attached.

Martin Zaun made changes - 09/Mar/06 04:28 AM
Attachment ThreadSafe.java [ 12323949 ]
Attachment ThreadSafe.java.diff [ 12323950 ]
Craig Russell added a comment - 09/Mar/06 06:41 AM
Looks good. A few comments.

1. The thread count of 2 doesn't seem to be much of a test. How about 14 or so?

2. The use of a local pmf should be restricted to where you need more than the single PMF that most tests use. Rather, the pmf defined in JDO_Test can be accessed directly without hiding it by the local pmf.

3. The use of testXXX should be avoided as testXXX methods are special cases for JUnit. Suggest calling the testConcurrent something like runConcurrentThreads.


Repository Revision Date User Message
ASF #384593 Thu Mar 09 20:03:10 UTC 2006 mzaun JDO-238 - fixed TCK test case ThreadSafe
Files Changed
MODIFY /db/jdo/trunk/tck20/src/java/org/apache/jdo/tck/api/persistencemanager/ThreadSafe.java

Martin Zaun added a comment - 10/Mar/06 03:59 AM
> 1. The thread count of 2 doesn't seem to be much of a test. How about 14 or so?

Having run my tests with a threadCount of 10, I was surprised to see that there's a reproducable deadlock happening with 20 threads (actually, with more than 16 threads, on my machine).

There seems to be an issue with jpox: From a certain number on of open PMs, even if they don't have an active transaction anymore, any attempt to begin a transaction on other PMs results in an infinite wait. Filing a jpox bug.

To have the TCK running, I'm checking in the ThreadSafe test with threadCount=10.

> 2. The use of a local pmf should be restricted to where you need more than the single PMF that most tests use. Rather, the pmf defined in JDO_Test can be accessed directly without hiding it by the local pmf.

Removed local pmf.

> 3. The use of testXXX should be avoided as testXXX methods are special cases for JUnit. Suggest calling the testConcurrent something like runConcurrentThreads.

Agreed. Renamed method to: runThreads().

Martin Zaun added a comment - 10/Mar/06 04:05 AM
Committed with revision 384593.

Martin Zaun made changes - 10/Mar/06 04:05 AM
Resolution Fixed [ 1 ]
Status Open [ 1 ] Resolved [ 5 ]
Erik Bengtson added a comment - 10/Mar/06 04:15 AM
The C3P0 has a default of maximum 15 connections in the pool. Try to increment this number

org.jpox.connectionPool.maxPoolSize=25

If this does not help, can you provide a thread dump?