Bug 204890 - Implement detach
Summary: Implement detach
Status: CLOSED FIXED
Alias: None
Product: EMF
Classification: Modeling
Component: cdo.core (show other bugs)
Version: 2.0   Edit
Hardware: PC Windows XP
: P1 enhancement (vote)
Target Milestone: M3   Edit
Assignee: Eike Stepper CLA
QA Contact:
URL:
Whiteboard: Appealing to a Broader Community
Keywords: readme
: 244424 (view as bug list)
Depends on:
Blocks: 247518 247946
  Show dependency tree
 
Reported: 2007-09-28 04:05 EDT by Eike Stepper CLA
Modified: 2010-06-29 09:22 EDT (History)
5 users (show)

See Also:
stepper: galileo+


Attachments
New Design (38.63 KB, patch)
2008-08-20 06:51 EDT, Eike Stepper CLA
no flags Details | Diff
Use case "Attach" (9.59 KB, image/png)
2008-08-20 06:52 EDT, Eike Stepper CLA
no flags Details
Use case "Detach" (9.37 KB, image/png)
2008-08-20 06:52 EDT, Eike Stepper CLA
no flags Details
Use case "Move" (8.61 KB, image/png)
2008-08-20 06:53 EDT, Eike Stepper CLA
no flags Details
Use case "Switch" (9.17 KB, image/png)
2008-08-20 06:53 EDT, Eike Stepper CLA
no flags Details
Use case "Re-Attach" (10.21 KB, image/png)
2008-08-20 06:53 EDT, Eike Stepper CLA
no flags Details
Patch for BETA 1 (66.80 KB, patch)
2008-08-21 00:40 EDT, Simon Mc Duff CLA
no flags Details | Diff
Better patch (75.36 KB, patch)
2008-08-21 22:04 EDT, Simon Mc Duff CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Eike Stepper CLA 2007-09-28 04:05:35 EDT
Detaching objects from a view is needed, for example, when objects are moved from one transaction to another.
Possibly it's also needed when transitioning objects to TRANSIENT.
Comment 1 Eike Stepper CLA 2008-01-29 11:23:44 EST
I'm struggling a bit. This is more complex than I originally thought ;-(

There are several use-cases (triggers) for detach:
1) Object is simply removed (or unset or cleared or overwritten by set) from a containment reference. This can also happen as an inverse operation.
2) CDOResource is removed from the resources list of the ResourceSet. This can also happen as an inverse operation.
3) An object is moved within one CDOTransaction. This leads to a remove plus an add. Should the CDOID/version of the object stay the same when "readding"???
4) An object is moved to another CDOTransaction. It should get a new CDOID/version=1.
5) ???

Detaching means to transition an object from non-transient to transient. But this reminds me that transient is not just transient. It always means "transient with respect to a given view"!! Clearly this is not reflected in the code (other than in the test case asserts). I fear I can't implement detach without finally implementing a view-aware isTransient() method in FSMUtil. This will have major impact on the state machine and I don't know so far how to design this additional condition...
Comment 2 Simon Mc Duff CLA 2008-01-29 11:45:47 EST
I don't see the problem.

Detach mechanism and rollback are two different things.. right ?

To be sure I understand correctly, Does your problem is more related to rollback or to detach ?

Detach mechanism doesn't need to remember where the object come from... right ?

To implement detach... it is only removing objects(CDOResource or CDOObject) from another objects change it state to transient.

When you implement detach you don't need to worry about :
Number 3 in your list, since this is the work of the rollback mechanism. 

Now, the rollback mechanism need to be more aware of the inverse operation you mentionned. 

When you play with two CDOTransactions, you would need to rollback both CDOTransaction... right ? In this case, both of them will react correctly.(One will add the other will remove)

If you are doing only a rollback from one side ..it will only detach.. or add the objects.. the other will be in a strange state.





(In reply to comment #1)
> I'm struggling a bit. This is more complex than I originally thought ;-(
> There are several use-cases (triggers) for detach:
> 1) Object is simply removed (or unset or cleared or overwritten by set) from a
> containment reference. This can also happen as an inverse operation.
> 2) CDOResource is removed from the resources list of the ResourceSet. This can
> also happen as an inverse operation.
> 3) An object is moved within one CDOTransaction. This leads to a remove plus an
> add. Should the CDOID/version of the object stay the same when "readding"???
> 4) An object is moved to another CDOTransaction. It should get a new
> CDOID/version=1.
> 5) ???
> Detaching means to transition an object from non-transient to transient. But
> this reminds me that transient is not just transient. It always means
> "transient with respect to a given view"!! Clearly this is not reflected in the
> code (other than in the test case asserts). I fear I can't implement detach
> without finally implementing a view-aware isTransient() method in FSMUtil. This
> will have major impact on the state machine and I don't know so far how to
> design this additional condition...

Comment 3 Eike Stepper CLA 2008-01-29 11:56:26 EST
No, I did neither talk nor think about rollback. This seems a completely different story to me.

Agreed that we have no public API for detach? It is only derived from certain other triggers in the store just like attach.

But if we simply detach an object e.g. in CDOStore.remove() then we detach it also for moves from on list to another list. Detaching is a comparingly expensive operation since, if we want to do it correctly, all the data must be copied from the revision to the transient settings in the object. This can even lead to load requests in the course of dereferencing CDOIDs!

Got a clue what I mean? ;-)
Comment 4 Eike Stepper CLA 2008-01-29 12:04:53 EST
May be we can do the "depopulation" of the revision (copying the revision values to the transient settings of the object) lazily. Detach would then mean to set the object state to transient and leave all other fields intact (particularly view and revision). Of course the object would have to be removed from CDOViewImpl.objects as well.

Then, when attaching this same object to an arbitrary view we'd have to check if it is "lazy"-transient and the new view is identical with the old view. In this case just the state is changed to DIRTY. Otherwise the revision would have to be migrated which potentially includes a different CDORevisionManager. But the second case should be rare comapred to the first one.
Comment 5 Eike Stepper CLA 2008-01-29 12:07:26 EST
Hmm, but then the object would not work correctly until it gets attached to a CDOView again ;-( And there could be issues with garbage collection...

I fear there is no alternative to eagerly copy the revision state into the transient area exactly at the time detach is necessary. And that can also be during view-internal moves.
Comment 6 Simon Mc Duff CLA 2008-01-29 12:17:37 EST
(In reply to comment #5)
> Hmm, but then the object would not work correctly until it gets attached to a
> CDOView again ;-( And there could be issues with garbage collection...
> I fear there is no alternative to eagerly copy the revision state into the
> transient area exactly at the time detach is necessary. And that can also be
> during view-internal moves.

I agree, we do exactly the inverse of the attach.
Comment 7 Eike Stepper CLA 2008-01-29 12:19:07 EST
I'm just about to write TCs for the new depopulation code ;-)
Comment 8 Simon Mc Duff CLA 2008-05-23 07:10:09 EDT
Do you still work on that bugs ? Did you start to write something?

Comment 9 Eike Stepper CLA 2008-05-23 08:30:11 EDT
Not at the moment. I struggled several times due to conceptual issues (see my other comments).
Everything that got written is in HEAD.
Comment 10 Eike Stepper CLA 2008-06-10 02:28:52 EDT
Reversioned due to graduation
Comment 11 Eike Stepper CLA 2008-08-19 06:38:40 EDT
*** Bug 244424 has been marked as a duplicate of this bug. ***
Comment 12 Eike Stepper CLA 2008-08-20 06:51:30 EDT
Created attachment 110428 [details]
New Design

Patch created from "detach" branch against HEAD.

Simon, ready to be merged into "NewContainment" when you're ready...
Comment 13 Eike Stepper CLA 2008-08-20 06:52:32 EDT
Created attachment 110429 [details]
Use case "Attach"
Comment 14 Eike Stepper CLA 2008-08-20 06:52:52 EDT
Created attachment 110430 [details]
Use case "Detach"
Comment 15 Eike Stepper CLA 2008-08-20 06:53:10 EDT
Created attachment 110431 [details]
Use case "Move"
Comment 16 Eike Stepper CLA 2008-08-20 06:53:28 EDT
Created attachment 110432 [details]
Use case "Switch"
Comment 17 Eike Stepper CLA 2008-08-20 06:53:48 EDT
Created attachment 110433 [details]
Use case "Re-Attach"
Comment 18 Victor Roldan Betancort CLA 2008-08-20 07:25:14 EDT
Hi Eike,

is it possible that you could change the "assigned-to" field of this bugzilla to emf.cdo-inbox@eclipse.org? I'm interested on it and realized I wasn't receiving any mailing :P

I'll take a look at the branch code, I'm getting NPE while deleting an element from the object tree, I assume it's related with this bug.

Best Regards,
ViK.
Comment 19 Simon Mc Duff CLA 2008-08-20 09:55:07 EDT
I will start with the following:
- DetachTransaction will call view.unregisterObject 
- CDOSavePoint will have a list of detachObjects (In the cases where a newObject is detach, it will only be removed from the newList)
- When we commit, Detach object will be send to the server.

- Add the following to CommitContext : 
  public CDORevision[] getNewObjects();

THis will solve Stefan problem.
Should I do that with all my others changes.. or Could I just use HEAD and provide a patch?
Comment 20 Stefan Winkler CLA 2008-08-20 10:30:19 EDT
Please note that my problem is in fact two cases:
Both ADD - REMOVE - COMMIT [object in newObject list] and ADD - COMMIT - REMOVE - COMMIT don't work. I suggest to add testcases according to Bug 244424 to test these cases.
Comment 21 Eike Stepper CLA 2008-08-20 10:47:25 EDT
(In reply to comment #18)
> is it possible that you could change the "assigned-to" field of this bugzilla
> to emf.cdo-inbox@eclipse.org? I'm interested on it and realized I wasn't
> receiving any mailing :P

i can't hold all bugs in the inbox. the inbox is only there so that you get notified on *new* bugs. then you can decide to cc yourself if you're further interested. for most of the existing bugs (pre-inbox "era") you'd have to go through a query and selectively cc yourself or do a mass update.

 
> I'll take a look at the branch code, I'm getting NPE while deleting an element
> from the object tree, I assume it's related with this bug.

the code in the branch is far from being complete at the moment. i'll keep you informed here about the progress.
Comment 22 Eike Stepper CLA 2008-08-20 10:49:56 EDT
(In reply to comment #19)
> I will start with the following:
> - DetachTransaction will call view.unregisterObject 
ok.

> - CDOSavePoint will have a list of detachObjects (In the cases where a
> newObject is detach, it will only be removed from the newList)
good.

> - When we commit, Detach object will be send to the server.
only the id i guess?

 
> - Add the following to CommitContext : 
>   public CDORevision[] getNewObjects();
what about getRemovedObjects() ?

 
> THis will solve Stefan problem.
> Should I do that with all my others changes.. or Could I just use HEAD and
> provide a patch?
please see the other email i sent to you ;-)

Comment 23 Simon Mc Duff CLA 2008-08-21 00:40:44 EDT
Created attachment 110520 [details]
Patch for BETA 1
Comment 24 Simon Mc Duff CLA 2008-08-21 00:43:47 EDT
I'm not finish yet but all testcases are working.

I added DetachTest. 
It test case 1, 2 and 3. Not 4 and 5 yet.

I don't like the way we handle add/remove/load Resource. I think we will have the time to review it when support external will be there. It is why I didn't spend time on that problem yet. (In the current patch) 

I don't handle detach Resource yet.
The code will slightly change.. when it comes to add & remove resources. I just changed it to make it work.

I refactored CDOSavePoint to have getAllNewObjects, getAllRevisions, etc...
I updated CDOSavePoint to handle removedObjects.
I kept CDOStore.setContainer since I need to generate Delta.
I added removedObjects to be send to the server
I added FSMUtil.checkLegacySystemAvailability in CDOStore.
I throw an exception when we detach an object from the View and try to access it with the id.
In CDOResourceFactoryImpl, the state of CDOresource is at PROXY when isExisting == true. I don't know if it is good... But I know it will not stay like this since the way to create Resource changed in my other feature (Support external feature).

What else...it is late.. I will go to bed!






Comment 25 Eike Stepper CLA 2008-08-21 03:21:36 EDT
Hey, as always you're the geatest!!
I think cases 1-3 are the most important ones. The others are more like sugar.

What you describe looks very good (but I haven't had the time to look at the patch).

Regarding CDOResourceImpl being created in state PROXY I already tried hard to remember why exactly this was needed (and it was!). I think it was related to the way the Load(Resource)Transition was programmed. Maybe combined with the fact that often resource instances are locally needed (each revision has a resourceID field) but not necessarily in a loaded state. If we feel that it's no longer needed (i.e. they can start in TRANSIENT) and proof that through tests, I'd be glad to get rid of the hack.
Comment 26 Simon Mc Duff CLA 2008-08-21 09:59:49 EDT
I need to define meaningful exception and add javadoc. I'm doing that right now. 
I submitted the patch only to give you an idea where I was going. It is not complete yet. I hop it will be for tonight!! (for case 1,2,3).maybe 4 and 5

The patch you submitted was really helpful. Thank you!
PROXY State is exactly what you thought. (for  Load(Resource)Transition) 
If I remember correctly we will be able to remove it in the future.(Not sure at 100%)


Comment 27 Eike Stepper CLA 2008-08-21 14:45:39 EDT
(In reply to comment #26)
> I need to define meaningful exception and add javadoc. I'm doing that right
> now. 
> I submitted the patch only to give you an idea where I was going. It is not
> complete yet. I hop it will be for tonight!! (for case 1,2,3).maybe 4 and 5

I hope that I can take the time to look at your patch tomorrow. I'm currently quite busy with the NASA slides.


> The patch you submitted was really helpful. Thank you!
> PROXY State is exactly what you thought. (for  Load(Resource)Transition) 
> If I remember correctly we will be able to remove it in the future.(Not sure at
> 100%)

Good to see that I still have some degree of overview ;-)
But more comments wil be necessary in the future!

Comment 28 Simon Mc Duff CLA 2008-08-21 22:04:40 EDT
Created attachment 110638 [details]
Better patch
Comment 29 Simon Mc Duff CLA 2008-09-11 18:12:05 EDT

In HEAD, we can detach objects/resources. Did we miss some requirements ?
If no I think we can close this bug. Right ?
Comment 30 Eike Stepper CLA 2008-09-12 01:55:50 EDT
Yes, it was committed to HEAD with bug #213402.
Comment 31 Eike Stepper CLA 2008-09-16 14:07:40 EDT
Fix available in HEAD: 2.0.0.I200809110653.
Comment 32 Eike Stepper CLA 2009-06-27 11:46:44 EDT
Generally available.