Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 318729 - Containment Cycle Detection should also work for non branching configurations
Summary: Containment Cycle Detection should also work for non branching configurations
Status: CLOSED FIXED
Alias: None
Product: EMF
Classification: Modeling
Component: cdo.core (show other bugs)
Version: 4.0   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Martin Fluegge CLA
QA Contact: Eike Stepper CLA
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-07-02 10:25 EDT by Martin Fluegge CLA
Modified: 2011-06-23 03:42 EDT (History)
0 users

See Also:
stepper: review+


Attachments
Patch v1 (5.66 KB, patch)
2010-07-02 13:40 EDT, Martin Fluegge CLA
no flags Details | Diff
Pacth v2_1 (17.04 KB, patch)
2010-07-07 13:39 EDT, Martin Fluegge CLA
no flags Details | Diff
Patch v2_2 (4.03 KB, patch)
2010-07-07 13:39 EDT, Martin Fluegge CLA
no flags Details | Diff
Patch V3 (5.78 KB, patch)
2010-07-28 14:29 EDT, Martin Fluegge CLA
no flags Details | Diff
Patch v4 - ready to be committed (5.78 KB, patch)
2010-08-07 04:31 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 Martin Fluegge CLA 2010-07-02 10:25:20 EDT
Containment cycle detection is troublesome on non branching configuration which uses CDOID instead of CDOIDAndBranch. This happens because the equality between the CDOIDRevisionDeltaLockWrapper and the CDOID cannot be guaranteed. This one is related to bug 316444.
Comment 1 Martin Fluegge CLA 2010-07-02 13:40:50 EDT
Created attachment 173322 [details]
Patch v1

I found a solution which works also with non-branching config. But this is rather a poor hack. Or in other words, this is anything but a clean solution. So please, do not commit it ;)
It also performs poor on legacy but it shows the idea behind it.

The problem is, as I and you guessed, that the equals method fails because the CDOID does not match the CDOIDRevisionDeltaLockWrapper. As a result the lockedObjects HashMap in the TransactionCommitContext will contain a Wrapper and a CDOID for the same ID (OID7 in our test). When the key is retrieved from the lockManager the CDOID will be found first and thus it is no CDOIDRevisionDeltaLockWrapper the delta will not be compared and no check will be performed for locked parents.

The patch is not the final solution. I think we should discuss this if there is some time.
Comment 2 Martin Fluegge CLA 2010-07-07 13:39:16 EDT
Created attachment 173685 [details]
Pacth v2_1

After looking at this topic again my first patch does not seem to be that bad. I played a bit with a special LockContainer object (Patch v2_1). But I am not sure whether this is worth the effort. Patch v2_2 is simpler and does not need to break API. We should discuss both patches.
Comment 3 Martin Fluegge CLA 2010-07-07 13:39:44 EDT
Created attachment 173686 [details]
Patch v2_2
Comment 4 Martin Fluegge CLA 2010-07-28 14:29:32 EDT
Created attachment 175433 [details]
Patch V3

O.k. I had a look at the Set.add() method again because I couldn?t believe that the java doc is so complete wrong. And than I found it...The java doc is correct and add() does *not* overwrite the value. 
The trick will be visible if you look at the implementation a map.put(). There the *value* will be replaced, but nut the *key*. Because Set.add() simple delegates to map.put() to store the value for the key of the map, the key remains unchanged - the value is not overwritten.

With the test we wrote we managed to fool ourselves because we overwrote equals() to return true in any cause. When we checked that our second object is in the set (our proof that the value was overwritten) we also should have checked whether the list contains the other object, too...what it did due to our equals() method ;)

O.k. back to the topic. That?s why I locked the references not before but after the containment check. 

I also changed the test for the initial bugzilla (Bug 316444) slightly because it was not 100% reliable.
Comment 5 Eike Stepper CLA 2010-07-29 02:36:34 EDT
(In reply to comment #4)
> With the test we wrote we managed to fool ourselves because we overwrote
> equals() to return true in any cause. 

True. I wanted to (but did not) use assertSame() rather than assertEquals() ;-(
Comment 6 Eike Stepper CLA 2010-08-07 04:31:26 EDT
Created attachment 176083 [details]
Patch v4 - ready to be committed

Just a minor reformat...
Comment 7 Martin Fluegge CLA 2010-08-07 13:23:31 EDT
Patch v4 - Committed to HEAD.
Comment 8 Eike Stepper CLA 2011-06-23 03:42:14 EDT
Available in R20110608-1407