Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 258831 - Check for Concurrency in CDOStateMachine
Summary: Check for Concurrency in CDOStateMachine
Status: CLOSED FIXED
Alias: None
Product: EMF
Classification: Modeling
Component: cdo.core (show other bugs)
Version: 2.0   Edit
Hardware: PC Windows XP
: P2 normal (vote)
Target Milestone: M6   Edit
Assignee: Simon Mc Duff CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 266982
  Show dependency tree
 
Reported: 2008-12-15 10:45 EST by Simon Mc Duff CLA
Modified: 2010-06-29 09:23 EDT (History)
1 user (show)

See Also:
stepper: galileo+
stepper: review+


Attachments
To be more complete (2.73 KB, patch)
2009-03-15 16:03 EDT, Simon Mc Duff CLA
no flags Details | Diff
Patch v2 (2.58 KB, patch)
2009-03-16 01:55 EDT, Eike Stepper CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Simon Mc Duff CLA 2008-12-15 10:45:33 EST
The state of an object could be changed at the same time by two different processes...

We should verify that!


Simon
Comment 1 Eike Stepper CLA 2008-12-15 11:49:37 EST
The discussion from ancient times ;-(

I still pretend that it's not good to operate with multiple threads on the same CDOView (including the objects of the view).

Or do you mean concurrent access between exactly one client thread and exactly one framework thread?
Comment 2 Simon Mc Duff CLA 2008-12-15 12:11:15 EST
(In reply to comment #1)
> The discussion from ancient times ;-(
> 
> I still pretend that it's not good to operate with multiple threads on the same
> CDOView (including the objects of the view).
> 
I know we do not agree on this one. I would say that our framework doesn't use always the same threads to do such things. (invalidation etc..) so it becomes really hard for the end-users to achieve that. I don't want to prevent concurrency into modifications of data... only that threads should be able to load objects at the same time and modify different objects at the same time..

> Or do you mean concurrent access between exactly one client thread and exactly
> one framework thread?
> 

At the moment, we could start to make sure the state is correct between
- 1 end - user
- Invalidation process
- Conflicts
- Rollback mechanisms.

I expect that after we fix it... it will work for many threads at the same time.. (at one point.. CDO will have the same limit as EMF... I understand that a list cannot be modified at the same time by 2 processes)

Simon
Comment 3 Simon Mc Duff CLA 2009-03-15 15:29:15 EDT
Can we close this bugs since the concurrency of the state machine was fixed in 
https://bugs.eclipse.org/bugs/show_bug.cgi?id=266982

Simon
Comment 4 Simon Mc Duff CLA 2009-03-15 15:30:30 EDT
I think we should check concurrency in SAVEpoint when we rollback ?
Others places ?
Comment 5 Simon Mc Duff CLA 2009-03-15 16:03:42 EDT
Created attachment 128851 [details]
To be more complete
Comment 6 Simon Mc Duff CLA 2009-03-15 16:16:58 EDT
Here what I committed. I committed since it could freeze CDO.

Basically the synchronized(objects) has been reduced! 
We cannot call the state machine inside a syncrhonized(objects)... Since the state machine could call back CDOVIew and block again....

The patch I submitted in this bugs still need to review. 

### Eclipse Workspace Patch 1.0
#P org.eclipse.emf.cdo
Index: src/org/eclipse/emf/internal/cdo/view/CDOViewImpl.java
===================================================================
RCS file: /cvsroot/modeling/org.eclipse.emf/org.eclipse.emf.cdo/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/view/CDOViewImpl.java,v
retrieving revision 1.9
diff -u -r1.9 CDOViewImpl.java
--- src/org/eclipse/emf/internal/cdo/view/CDOViewImpl.java	15 Mar 2009 19:28:13 -0000	1.9
+++ src/org/eclipse/emf/internal/cdo/view/CDOViewImpl.java	15 Mar 2009 20:13:56 -0000
@@ -1072,23 +1072,24 @@
     {
       for (CDOIDAndVersion dirtyOID : dirtyOIDs)
       {
-        InternalCDOObject dirtyObject;
+        InternalCDOObject dirtyObject = null;
+        // 258831 - Causes deadlock when introduce thread safe mechanisms in State machine.
         synchronized (objects)
         {
           dirtyObject = objects.get(dirtyOID.getID());
-          if (dirtyObject != null)
+        }
+        if (dirtyObject != null)
+        {
+          CDOStateMachine.INSTANCE.invalidate(dirtyObject, dirtyOID.getVersion());
+          dirtyObjects.add(dirtyObject);
+          if (dirtyObject.cdoConflict())
           {
-            CDOStateMachine.INSTANCE.invalidate(dirtyObject, dirtyOID.getVersion());
-            dirtyObjects.add(dirtyObject);
-            if (dirtyObject.cdoConflict())
+            if (conflicts == null)
             {
-              if (conflicts == null)
-              {
-                conflicts = new HashSet<CDOObject>();
-              }
-
-              conflicts.add(dirtyObject);
+              conflicts = new HashSet<CDOObject>();
             }
+
+            conflicts.add(dirtyObject);
           }
         }
       }
Comment 7 Eike Stepper CLA 2009-03-16 01:55:55 EDT
Created attachment 128878 [details]
Patch v2

Ready to be committed.

Simon, Can you please add some JavaDoc to InternalCDOView.getStateLock() and explain how it differs from CDOView.getLock() ?
Comment 8 Simon Mc Duff CLA 2009-03-18 09:15:11 EDT
I will create a testcase for every cases that the state machine could be called.
(read, write, reload, detach, etc..)

That way we will be sure that we do not forget something.. like I did with reload!

Simon
Comment 9 Simon Mc Duff CLA 2009-03-18 17:13:37 EDT
I added some comments. 

What left on this bug ?

Add testcases!

I will do so!
Comment 10 Eike Stepper CLA 2009-04-04 03:25:11 EDT
I'd like to see this bug RESOLVED ;-)
Comment 11 Simon Mc Duff CLA 2009-04-04 08:18:00 EDT
I will do my best!
Comment 12 Simon Mc Duff CLA 2009-04-29 07:12:28 EDT
Since I'm working in Concurrency in another bugs.. I will close the following.
Comment 13 Eike Stepper CLA 2009-05-06 06:39:33 EDT
Fix available in EMF CDO 2.0.0M7
Comment 14 Eike Stepper CLA 2009-06-27 11:47:11 EDT
Generally available.