Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 482886 - MySQL InnoDB needs commit after package creation
Summary: MySQL InnoDB needs commit after package creation
Status: CLOSED FIXED
Alias: None
Product: EMF
Classification: Modeling
Component: cdo.db (show other bugs)
Version: 4.5   Edit
Hardware: PC Windows NT
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Eike Stepper CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-11-24 04:40 EST by Thorsten Schlathölter CLA
Modified: 2020-12-11 10:32 EST (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Thorsten Schlathölter CLA 2015-11-24 04:40:58 EST
As discussed in this thread 

https://www.eclipse.org/forums/index.php/t/1072386/

it seems to be necessary to commit the creation of new tables and indices - which result from registration of new packages - in case of using MySQL InnoDB (standard since MySQL 5.5).

This is due to a InnoDB limitation described here:

http://dev.mysql.com/doc/refman/5.5/en/innodb-create-index-limitations.html

If changes to the table definition are not committed, a select on that table results in the following exception:

[ERROR] Rollback in DBStore: org.eclipse.net4j.db.DBException: java.sql.SQLException: Table definition has changed, please retry transaction
	at org.eclipse.emf.cdo.server.internal.db.mapping.horizontal.AbstractHorizontalMappingStrategy.queryResources(AbstractHorizontalMappingStrategy.java:474)
	at org.eclipse.emf.cdo.server.internal.db.mapping.horizontal.AbstractHorizontalMappingStrategy.queryResources(AbstractHorizontalMappingStrategy.java:126)
	at org.eclipse.emf.cdo.server.internal.db.mapping.horizontal.HorizontalMappingStrategy.queryResources(HorizontalMappingStrategy.java:184)
	at org.eclipse.emf.cdo.server.internal.db.DBStoreAccessor.queryResources(DBStoreAccessor.java:331)
	at org.eclipse.emf.cdo.spi.server.StoreAccessorBase.readResourceID(StoreAccessorBase.java:215)
	at org.eclipse.emf.cdo.server.internal.db.mapping.horizontal.AbstractHorizontalClassMapping.checkDuplicateResources(AbstractHorizontalClassMapping.java:469)
	at org.eclipse.emf.cdo.server.internal.db.mapping.horizontal.HorizontalBranchingClassMapping.writeRevision(HorizontalBranchingClassMapping.java:747)
	at org.eclipse.emf.cdo.server.internal.db.DBStoreAccessor.writeRevision(DBStoreAccessor.java:591)
	at org.eclipse.emf.cdo.server.internal.db.DBStoreAccessor.writeRevisions(DBStoreAccessor.java:571)
	at org.eclipse.emf.cdo.spi.server.StoreAccessor.doWrite(StoreAccessor.java:98)
	at org.eclipse.emf.cdo.server.internal.db.DBStoreAccessor.doWrite(DBStoreAccessor.java:831)
	at org.eclipse.emf.cdo.spi.server.StoreAccessorBase.write(StoreAccessorBase.java:152)
	at org.eclipse.emf.cdo.internal.server.TransactionCommitContext.write(TransactionCommitContext.java:651)
	at org.eclipse.emf.cdo.internal.server.Repository.initRootResource(Repository.java:2060)
	at org.eclipse.emf.cdo.internal.server.Repository.doActivate(Repository.java:2213)
	at org.eclipse.net4j.util.lifecycle.Lifecycle.internalActivate(Lifecycle.java:76)
	at org.eclipse.net4j.util.lifecycle.ShareableLifecycle.internalActivate(ShareableLifecycle.java:43)
	at org.eclipse.net4j.util.lifecycle.Lifecycle.activate(Lifecycle.java:162)
	at org.eclipse.net4j.util.lifecycle.LifecycleUtil.activate(LifecycleUtil.java:127)
	at org.eclipse.net4j.util.lifecycle.LifecycleUtil.activate(LifecycleUtil.java:117)
	at org.eclipse.emf.cdo.server.CDOServerUtil.addRepository(CDOServerUtil.java:292)
	at org.eclipse.emf.cdo.spi.server.RepositoryConfigurator.configure(RepositoryConfigurator.java:141)
	at org.eclipse.emf.cdo.spi.server.RepositoryConfigurator.configure(RepositoryConfigurator.java:108)
	at enco.sox2.workspace.cdo.server.CDOApplication.doStart(CDOApplication.java:62)
	at org.eclipse.net4j.util.om.OSGiApplication.start(OSGiApplication.java:63)
	at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
	at org.eclipse.equinox.internal.app.AnyThreadAppLauncher.run(AnyThreadAppLauncher.java:26)
	at java.lang.Thread.run(Unknown Source)
Comment 1 Thorsten Schlathölter CLA 2015-11-24 04:45:13 EST
A solution to this problem is depicted in 

https://www.eclipse.org/forums/index.php/t/1072386/

Add a new method to the IDBAdapter interface:

needsCommitAfterSchemaModification()

Add a conditional commit in DBStoreAccessor.writePackageUnits

public void writePackageUnits(InternalCDOPackageUnit[] packageUnits, OMMonitor monitor) {
   super.writePackageUnits(packageUnits, monitor);

   IDBAdapter dbAdapter = getStore().getDBAdapter();
   if (dbAdapter.needsCommitAfterSchemaModification()) {
      try {
         getConnection().commit();
      } catch (SQLException e) {
         OM.LOG.error(e);
      }
   }
}
Comment 2 Eike Stepper CLA 2016-02-04 12:34:38 EST
I've played with this some ore and found an interesting fix. It appears that the problem only comes up during the initial commit that creates the root resource. And it comes up during the checkDuplicateResources() call. But at this time this call isn't needed at all because the root resource is only created once, never moved, and can't be a duplicate. The fix is simply to skip this call during the very first commit and it seems to work well (your testing is appreciated).

The fix is committed to master:
http://git.eclipse.org/c/cdo/cdo.git/commit/?id=f11f14a3b2711978ad96d835dd69b2384721bb37
Comment 3 Eike Stepper CLA 2016-02-04 12:42:56 EST
For future reference: I've committed a more aggressive fix that involves an extra commit to my branch "committers/estepper/commit-after-ddl".
Comment 4 Eike Stepper CLA 2020-12-11 10:26:41 EST
Closing.
Comment 5 Eike Stepper CLA 2020-12-11 10:32:33 EST
Closing.