Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 374418 - Issue on control/uncontrol of model element with Savepoint
Summary: Issue on control/uncontrol of model element with Savepoint
Status: CLOSED FIXED
Alias: None
Product: EMF
Classification: Modeling
Component: cdo.core (show other bugs)
Version: 4.0   Edit
Hardware: PC Linux
: P3 major (vote)
Target Milestone: ---   Edit
Assignee: Eike Stepper CLA
QA Contact: Eike Stepper CLA
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-03-15 12:47 EDT by Esteban DUGUEPEROUX CLA
Modified: 2012-09-21 06:51 EDT (History)
2 users (show)

See Also:


Attachments
JUnit test (2.39 KB, text/x-java)
2012-03-15 12:49 EDT, Esteban DUGUEPEROUX CLA
stepper: iplog+
Details
The metamodel (21.54 KB, application/zip)
2012-03-15 12:50 EDT, Esteban DUGUEPEROUX CLA
no flags Details
Patch (346.29 KB, patch)
2012-03-21 07:23 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 Esteban DUGUEPEROUX CLA 2012-03-15 12:47:44 EDT
Build Identifier: 

With a metamodel generated in native with containment proxy to true :
1. Control a model element to a new resource
2. Set a savepoint
3. Commit
4. Uncontrol this model element to its original resource
2. Set a savepoint
3. Commit
1. Control again this model element to the new resource
2. Set a savepoint
3. Commit

I get the following exception on commit :

org.eclipse.emf.cdo.util.CommitException: Rollback in MEMStore: java.lang.IllegalStateException: Origin revision not found for CDORevisionDelta[Root@OID5:0v3 --> [CDOFeatureDelta[null, CONTAINER, resource=OID6, container=OID4, feature=-1]]]
	at org.eclipse.emf.cdo.internal.server.TransactionCommitContext.computeDirtyObject(TransactionCommitContext.java:959)
	at org.eclipse.emf.cdo.internal.server.TransactionCommitContext.computeDirtyObjects(TransactionCommitContext.java:937)
	at org.eclipse.emf.cdo.internal.server.TransactionCommitContext.write(TransactionCommitContext.java:455)
	at org.eclipse.emf.cdo.spi.server.InternalCommitContext$1.runLoop(InternalCommitContext.java:42)
	at org.eclipse.emf.cdo.spi.server.InternalCommitContext$1.runLoop(InternalCommitContext.java:1)
	at org.eclipse.net4j.util.om.monitor.ProgressDistributor.run(ProgressDistributor.java:96)
	at org.eclipse.emf.cdo.server.internal.net4j.protocol.CommitTransactionIndication.indicatingCommit(CommitTransactionIndication.java:244)
	at org.eclipse.emf.cdo.server.internal.net4j.protocol.CommitTransactionIndication.indicating(CommitTransactionIndication.java:92)
	at org.eclipse.emf.cdo.server.internal.net4j.protocol.CDOServerIndicationWithMonitoring.indicating(CDOServerIndicationWithMonitoring.java:109)
	at org.eclipse.net4j.signal.IndicationWithMonitoring.indicating(IndicationWithMonitoring.java:84)
	at org.eclipse.net4j.signal.IndicationWithResponse.doExtendedInput(IndicationWithResponse.java:90)

Reproducible: Always
Comment 1 Esteban DUGUEPEROUX CLA 2012-03-15 12:49:59 EDT
Created attachment 212736 [details]
JUnit test

Attached a JUnit test to show the issue using a metamodel also in attachment.
Comment 2 Esteban DUGUEPEROUX CLA 2012-03-15 12:50:48 EDT
Created attachment 212737 [details]
The metamodel
Comment 3 Esteban DUGUEPEROUX CLA 2012-03-15 13:00:46 EDT
Reproduced with CDO 4.0 SR2 but also with master.
Comment 4 Esteban DUGUEPEROUX CLA 2012-03-15 13:04:55 EDT
If we doesn't set CDOSavePoint we doesn't have the exception, this seems related to https://bugs.eclipse.org/bugs/show_bug.cgi?id=352977 .
Comment 5 Esteban DUGUEPEROUX CLA 2012-03-21 06:01:03 EDT
Removing the "childRoot" model element from its resource before adding to the new resource doesn't throws exception.
Comment 6 Eike Stepper CLA 2012-03-21 06:09:17 EDT
I regenerated model6 with containmentProxies=true and stripped down the test to the minimum to reproduce the problem:

    Root root = getModel6Factory().createRoot();
    BaseObject childRoot = getModel6Factory().createBaseObject();
    root.getListA().add(childRoot);

    CDOSession session = openSession();
    CDOTransaction transaction = session.openTransaction();
    CDOResource mainResource = transaction.createResource(getResourcePath("/mainResource.model1"));
    mainResource.getContents().add(root);
    transaction.commit();

    // Control childRoot to a new resource
    CDOResource fragmentResource = transaction.createResource(getResourcePath("/fragmentResource.model1"));
    fragmentResource.getContents().add(childRoot);
    transaction.commit();

    // Uncontrol category1 to its original resource
    fragmentResource.getContents().remove(childRoot);
    transaction.setSavepoint(); // <---- Problem here!!!
    transaction.commit();

    // Control again childRoot to the new resource
    fragmentResource.getContents().add(childRoot);
    transaction.commit();

It turns out that a single setSavepoint() call causes the problem. Removing it makes the test pass.
Comment 7 Eike Stepper CLA 2012-03-21 06:38:00 EDT
The problem is, again, this pathological combination of reattachment with multiple savepoints.
It seems I can fix it with this code in CDOSavepointImpl.getAllRevisionDeltas():

        Set<CDOID> reattachedObjects = savepoint.getReattachedObjects().keySet();
        for (CDOID detachedID : savepoint.getDetachedObjects().keySet())
        {
          if (!reattachedObjects.contains(detachedID))
          {
            allRevisionDeltas.remove(detachedID);
          }
        }

As you've suggested in comment 4 this is really related to bug 352977 which requires a larger redesign to give us more confidence.
Comment 8 Eike Stepper CLA 2012-03-21 06:41:21 EDT
Comment on attachment 212736 [details]
JUnit test

Esteban, please confirm that:

1) The number of lines that you changed is smaller than 250.
2) You are the only author of these changed lines.
3) You apply the EPL to these changed lines.
Comment 9 Eike Stepper CLA 2012-03-21 06:55:26 EDT
All suites pass.

commit b255e7b5c36e07a796b294447d0caee8460a79e0
Comment 10 Eike Stepper CLA 2012-03-21 06:56:12 EDT
Port to 4.1 via bug 374882.
Comment 11 Eike Stepper CLA 2012-03-21 07:23:02 EDT
Created attachment 212989 [details]
Patch
Comment 12 Esteban DUGUEPEROUX CLA 2012-03-21 08:05:03 EDT
I confirm that:

1) The number of lines that I changed is smaller than 250.
2) I am the only author of these changed lines.
3) I apply the EPL to these changed lines.

Thanks.
Comment 13 Eike Stepper CLA 2012-09-21 06:51:26 EDT
Closing.