Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 344072 - Reattachment registers object as DIRTY even when it's not
Summary: Reattachment registers object as DIRTY even when it's not
Status: CLOSED FIXED
Alias: None
Product: EMF
Classification: Modeling
Component: cdo.core (show other bugs)
Version: 4.0   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Martin Fluegge CLA
QA Contact: Eike Stepper CLA
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-04-28 01:20 EDT by Caspar D. CLA
Modified: 2011-06-23 03:41 EDT (History)
2 users (show)

See Also:
stepper: review+


Attachments
Patch (3.26 KB, patch)
2011-04-28 01:53 EDT, Caspar D. CLA
no flags Details | Diff
Patch v2 (3.28 KB, patch)
2011-04-28 03:33 EDT, Eike Stepper CLA
no flags Details | Diff
Testcase (1.83 KB, text/x-java)
2011-05-02 23:39 EDT, Caspar D. CLA
no flags Details
Legacy Patch v1 (5.01 KB, patch)
2011-05-04 14:09 EDT, Martin Fluegge CLA
no flags Details | Diff
Patch v3 (3.34 KB, patch)
2011-05-05 04:28 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 Caspar D. CLA 2011-04-28 01:20:50 EDT
The existing re-attachment logic assumes that the state after
reattachment must always be dirty. This isn't necessarily the
case; the object could be perfectly CLEAN after re-attachment.

Trivial patch in a minute.
Comment 1 Caspar D. CLA 2011-04-28 01:21:21 EDT
[NoMagicNote: SVR-2889]
Comment 2 Caspar D. CLA 2011-04-28 01:53:31 EDT
Created attachment 194230 [details]
Patch
Comment 3 Eike Stepper CLA 2011-04-28 03:33:19 EDT
Created attachment 194234 [details]
Patch v2

I just simplified the if condition (a little bit).
Comment 4 Caspar D. CLA 2011-04-28 04:17:05 EDT
Committed revision 7642.
Comment 5 Caspar D. CLA 2011-04-28 04:38:15 EDT
Committed revision 7643. (Didn't realize you modified the patch, so
the previous commit was my own original patch.)
Comment 6 Martin Fluegge CLA 2011-05-02 03:43:54 EDT
Seems as if this patch breaks Legacy:

https://hudson.eclipse.org/hudson/job/emf-cdo-integration/1314/

Is this intentional? Or is this something which does not occur while running the legacy tests locally?

Is investigation required? ;)
Comment 7 Eike Stepper CLA 2011-05-02 04:17:56 EDT
(In reply to comment #6)
> Is investigation required? ;)

Yes! Please clarify with Caspar who feels responsibility first ;-)
Comment 8 Martin Fluegge CLA 2011-05-02 11:29:25 EDT
> Please clarify with Caspar who feels responsibility first ;-)

Due to my limited time at the momment (there are some significant Dawn issues) it would be nice if Caspar could clarify whether this behavior is EMF compliant or not.

1.) If it is, I would jump in because this means an implementation problem in Legacy

2.) If not, we should discuss whether it is o.k. to differ from EMF in this case

o.k.?
Comment 9 Caspar D. CLA 2011-05-02 23:36:58 EDT
The problem (in Legacy) is this: if you call getContainerID on a clean
object's revision you get the real ID object, e.g. a CDOIDObjectLongImpl. Then,
if you detach the object from its container, and reattach it to the same
container, and call getContainerID again, you don't get the real ID object
anymore, but a CDOLegacyAdapter instead.

And since calling cdoRevision().data().getContainerID() is exactly what
BaseCDORevision.compare(...) does, the comparison yields a spurious 
CDOFeatureDelta that is interpreted by the reattachment logic as an indication
that the object is DIRTY, while in fact the comparison should have yielded
no feature deltas and the object should have been put in state CLEAN.

I'm not sure which logic is "most at fault" here. I don't understand why
an ID object is sometimes wrapped in a CDOLegacyAdapter, and even if we
do have good reasons for that, I don't know why our compare logic isn't
prepared to deal with that possibility.
Comment 10 Caspar D. CLA 2011-05-02 23:39:11 EDT
Created attachment 194548 [details]
Testcase

Testcase demonstrating the legacy problem
(It's a straight Java source file, not a patch.)
Comment 11 Martin Fluegge CLA 2011-05-04 14:09:58 EDT
Created attachment 194750 [details]
Legacy Patch v1

Hi Caspar,

thanks for your investigation.

The problem you’ve showed in the test case seems indeed not to be correct. The fix for it was actually quite trivial. I had to adjust Bugzilla_24662_Test, but I think the previous test logic was not 100% correct. Eike, could you please verify this?

But I do not really understand what this has to do with the failing tests, because they are still failing.
Comment 12 Eike Stepper CLA 2011-05-05 03:09:44 EDT
Marked Patch v2 obsolete as it looks as if it has been applied already.
Comment 13 Eike Stepper CLA 2011-05-05 03:22:53 EDT
(In reply to comment #11)
> The problem you’ve showed in the test case seems indeed not to be correct. The
> fix for it was actually quite trivial. I had to adjust Bugzilla_24662_Test, but
> I think the previous test logic was not 100% correct.

Now I'm confused. I was concerned that Bugzilla_283985_1_Test started failing in LEGACY but you changed Bugzilla_246622_Test and that in a way that it now fails too for NATIVE. Can you explain why you did that?
Comment 14 Eike Stepper CLA 2011-05-05 03:52:30 EDT
Committed revision 7650:
- trunk/plugins/org.eclipse.emf.cdo.tests
Comment 15 Eike Stepper CLA 2011-05-05 04:28:48 EDT
Created attachment 194803 [details]
Patch v3

The root cause seems to be in the compare() method of CDORevisionDeltaImpl as Caspar pointed out. Revision.containerID can in fact be an EObject under certain circumstances in a dirty client transaction. I've added an interface to cdo.common so that the common mechansims can detect this situation and use the CDOID of the EObject instead. Now the correct if branch in the Reattach transition is used and CDOState.CLEAN ends up in the EObject (legacy adapter).

Unfortunately the test still fails because some time later and up in the stack cdoInternalSetState() is called again, making the object DIRTY again. It's my impression that this is a pure LEGACY issue now. Martin, can you have a look again? It will help to set a breakpoint in CDOLegacyWrapper.cdoInternalSetState().

I'm currently running all tests. If no other regressions pop up I'll commit this patch...
Comment 16 Eike Stepper CLA 2011-05-05 04:39:43 EDT
Committed revision 7651:
- trunk/plugins/org.eclipse.emf.cdo
- trunk/plugins/org.eclipse.emf.cdo.common
Comment 17 Martin Fluegge CLA 2011-05-05 12:17:01 EDT
> Martin, can you have a look again? 

O.k. Assign this one to me. But I've no glue when there is time for it.
Comment 18 Eike Stepper CLA 2011-05-06 00:45:07 EDT
Committed revision 7653:
- trunk/plugins/org.eclipse.emf.cdo.tests
Comment 19 Eike Stepper CLA 2011-05-06 00:45:35 EDT
Ok, I've added this to the 4 offending tests:

    skipConfig(LEGACY); // TODO Fix bug 344072
Comment 20 Eike Stepper CLA 2011-05-18 04:59:13 EDT
Committed revision 7807
Comment 21 Eike Stepper CLA 2011-05-25 06:58:27 EDT
Should we resolve this one and open a new one for LEGACY?
Comment 22 Martin Fluegge CLA 2011-05-25 07:06:25 EDT
Good idea.
Comment 23 Eike Stepper CLA 2011-05-25 07:23:22 EDT
The LEGACY apsect of this problem will be tracked in bug 347135.
Comment 24 Eike Stepper CLA 2011-06-23 03:41:35 EDT
Available in R20110608-1407