Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 336532 - [DB] MySQL exception when merging branches
Summary: [DB] MySQL exception when merging branches
Status: CLOSED FIXED
Alias: None
Product: EMF
Classification: Modeling
Component: cdo.db (show other bugs)
Version: 4.10   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Stefan Winkler CLA
QA Contact: Eike Stepper CLA
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-02-07 11:37 EST by Lothar Werzinger CLA
Modified: 2020-12-11 10:39 EST (History)
3 users (show)

See Also:
stepper: review+


Attachments
console log showing the error (51.98 KB, text/plain)
2011-02-07 11:37 EST, Lothar Werzinger CLA
no flags Details
patch-v1 We ignore the exception by checking for the respective SQL state. Unfortunately, this code is returned differently by MySQL. To handle this, I moved the decision whether we have a duplicate key constraint violation into the DBAdapter. The patch (9.18 KB, patch)
2011-02-12 14:00 EST, Stefan Winkler CLA
no flags Details | Diff
Patch v2 - ready to be committed (10.02 KB, patch)
2011-02-22 05:57 EST, Eike Stepper CLA
no flags Details | Diff
Example fix in the MySQL case (637 bytes, patch)
2011-03-08 21:17 EST, Cameron Bateman CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Lothar Werzinger CLA 2011-02-07 11:37:03 EST
Build Identifier: 

I get a strange MySQL error when merging branches (see attached log).

MySQLIntegrityConstraintViolationException: Duplicate entry '2' for key 'cdo_objects_idx0'


Reproducible: Always

Steps to Reproduce:
1. Create multiple branches that are branched of the MAIN branch at create time:

    CDOBranch mainBranch = ...;
    long timestamp = mainBranch.getBase().getTimeStamp();
    CDOBranch result = mainBranch.createBranch(branchName, timestamp);

2. Create some object tree on one branch and commit.
3. Try to merge this branch to another (which at that time should be empty).

    CDOTransaction transaction = session.openTransaction(targetBranch);

    CDOMerger merger = new DefaultCDOMerger.PerFeature.ManyValued();
    transaction.merge(sourceBranch.getHead(), merger);
    transaction.commit();
Comment 1 Lothar Werzinger CLA 2011-02-07 11:37:45 EST
Created attachment 188453 [details]
console log showing the error
Comment 2 Lothar Werzinger CLA 2011-02-07 11:39:19 EST
As discussed with Stefan Winkler I refer to Bug 336382.

> Hi Lothar,
> 
> please open a Bug and refer to the test case attached to Bug 336382. 
> This test case fails w/ range-based branching on a MySQL database.
Comment 3 Stefan Winkler CLA 2011-02-12 14:00:36 EST
Created attachment 188838 [details]
patch-v1
We ignore the exception by checking for the respective SQL state. Unfortunately, this code is returned differently by MySQL. To handle this, I moved the decision whether we have a duplicate key constraint violation into the DBAdapter. 

The patch

Found it. The duplicate key exception is a known error which occurs when new objects from another branch are added to a target branch.

For H2, we ignore the exception by checking for the respective SQL status code. Unfortunately, this code is returned differently by MySQL. To handle this, I moved the decision whether we have a duplicate key constraint violation into the DBAdapter. 

The patch also contains the testcase mentioned above.
Tested with mysql and H2.
Comment 4 Eike Stepper CLA 2011-02-22 05:57:57 EST
Created attachment 189468 [details]
Patch v2 - ready to be committed
Comment 5 Eike Stepper CLA 2011-02-26 00:03:03 EST
Stefan, please go ahead...
Comment 6 Stefan Winkler CLA 2011-02-28 09:26:16 EST
Committed to trunk, rev. 7308
Comment 7 Cameron Bateman CLA 2011-03-08 18:16:09 EST
When I successfully branch a model using this change, I still see a similar constraint violation in HorizontalBranchClassMapping when I subsequently try to commit certain changes in the source branch (the one I branched from).  An example stack trace is below.  I believe a similar change is required in HorizontalBranchClassMapping to what was done in ObjectTypeTable.


org.eclipse.emf.cdo.util.CommitException: Rollback in DBStore: org.eclipse.net4j.db.DBException: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Duplicate entry '18581-3-1' for key 'PrimaryContract_idx0'
	at org.eclipse.emf.cdo.server.internal.db.mapping.horizontal.HorizontalBranchingClassMapping.writeValues(HorizontalBranchingClassMapping.java:653)
	at org.eclipse.emf.cdo.server.internal.db.mapping.horizontal.HorizontalBranchingClassMapping$FeatureDeltaWriter.process(HorizontalBranchingClassMapping.java:129)
	at org.eclipse.emf.cdo.server.internal.db.mapping.horizontal.HorizontalBranchingClassMapping.writeRevisionDelta(HorizontalBranchingClassMapping.java:1074)
	at org.eclipse.emf.cdo.server.internal.db.DBStoreAccessor.writeRevisionDelta(DBStoreAccessor.java:542)
	at org.eclipse.emf.cdo.server.internal.db.DBStoreAccessor.writeRevisionDeltas(DBStoreAccessor.java:527)
	at org.eclipse.emf.cdo.spi.server.StoreAccessor.doWrite(StoreAccessor.java:95)
	at org.eclipse.emf.cdo.spi.server.StoreAccessorBase.write(StoreAccessorBase.java:135)
	at org.eclipse.emf.cdo.internal.server.TransactionCommitContext.write(TransactionCommitContext.java:409)
	at org.eclipse.emf.cdo.spi.server.InternalCommitContext$1.runLoop(InternalCommitContext.java:40)
	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)
	at org.eclipse.net4j.signal.Signal.doInput(Signal.java:326)
	at org.eclipse.net4j.signal.IndicationWithResponse.execute(IndicationWithResponse.java:63)
	at org.eclipse.net4j.signal.IndicationWithMonitoring.execute(IndicationWithMonitoring.java:63)
	at org.eclipse.net4j.signal.Signal.runSync(Signal.java:251)
	at org.eclipse.net4j.signal.Signal.run(Signal.java:147)
	at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
	at java.lang.Thread.run(Unknown Source)
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Duplicate entry '18581-3-1' for key 'PrimaryContract_idx0'
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
	at java.lang.reflect.Constructor.newInstance(Unknown Source)
	at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)
	at com.mysql.jdbc.Util.getInstance(Util.java:381)
	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1015)
	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956)
	at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3515)
	at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3447)
	at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1951)
	at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2101)
	at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2554)
	at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1761)
	at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2046)
	at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1964)
	at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1949)
	at org.eclipse.net4j.db.DBUtil.update(DBUtil.java:558)
	at org.eclipse.emf.cdo.server.internal.db.mapping.horizontal.HorizontalBranchingClassMapping.writeValues(HorizontalBranchingClassMapping.java:647)
	... 23 more

	at org.eclipse.emf.internal.cdo.transaction.CDOSingleTransactionStrategyImpl.commit(CDOSingleTransactionStrategyImpl.java:94)
	at org.eclipse.emf.internal.cdo.transaction.CDOTransactionImpl.commit(CDOTransactionImpl.java:1056)
	at org.eclipse.emf.cdo.transaction.CDOPushTransaction.push(CDOPushTransaction.java:239)
	at biz.tradescape.mmt.ui.editor.AbstractCDOEditor$6.run(AbstractCDOEditor.java:693)
	at biz.tradescape.compatibility.JobFactoryImpl$2$1.run(JobFactoryImpl.java:41)
	at org.apache.shiro.subject.support.SubjectRunnable.doRun(SubjectRunnable.java:120)
	at org.apache.shiro.subject.support.SubjectRunnable.run(SubjectRunnable.java:108)
	at biz.tradescape.compatibility.JobFactoryImpl$2.run(JobFactoryImpl.java:45)
	at org.eclipse.core.internal.jobs.Worker.run(Worker.java:54)
Comment 8 Lothar Werzinger CLA 2011-03-08 18:19:01 EST
Reopening for Cameron.
Comment 9 Cameron Bateman CLA 2011-03-08 21:17:27 EST
Created attachment 190721 [details]
Example fix in the MySQL case

This appear so to fix the issue in a MySQL specific. I'm not sure about the more generalized solution.
Comment 10 Eike Stepper CLA 2012-06-05 07:29:23 EDT
Moving all open bug reports to 4.1 because the release is very near and it's hghly unlikely that there will be spare time to address 4.0 problems.

Please make sure that your patches can be applied against the master branch and that your problem is not already fixed there!!!
Comment 11 Eike Stepper CLA 2012-08-14 22:57:32 EDT
Moving all open issues to 4.2. Open bugs can be ported to 4.1 maintenance after they've been fixed in master.
Comment 12 Eike Stepper CLA 2013-06-29 12:18:46 EDT
We'll try to address open problems in 4.3 (master) first and then port fixes back to 4.2.
Comment 13 Eike Stepper CLA 2015-07-14 02:21:12 EDT
Moving all open bugzillas to 4.5.
Comment 14 Eike Stepper CLA 2016-07-31 01:03:58 EDT
Moving all unaddressed bugzillas to 4.6.
Comment 15 Eike Stepper CLA 2017-12-28 01:13:53 EST
Moving all open bugs to 4.7
Comment 16 Eike Stepper CLA 2019-11-08 02:12:32 EST
Moving all unresolved issues to version 4.8-
Comment 17 Eike Stepper CLA 2019-12-13 12:48:55 EST
Moving all unresolved issues to version 4.9
Comment 18 Eike Stepper CLA 2020-04-03 04:08:03 EDT
I assume that this is fixed now with the changes of bug 546872.
Comment 19 Eike Stepper CLA 2020-12-11 10:30:07 EST
Closing.
Comment 20 Eike Stepper CLA 2020-12-11 10:39:10 EST
Closing.