Bug 546872 - [DB] MySQL Error: "Table definition has changed" on initializing new CDO repository
Summary: [DB] MySQL Error: "Table definition has changed" on initializing new CDO repo...
Status: CLOSED FIXED
Alias: None
Product: EMF
Classification: Modeling
Component: cdo.db (show other bugs)
Version: 4.10   Edit
Hardware: Macintosh Mac OS X
: P3 normal with 1 vote (vote)
Target Milestone: ---   Edit
Assignee: Eike Stepper CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 560986 (view as bug list)
Depends on:
Blocks:
 
Reported: 2019-04-30 13:20 EDT by Simon Kuzin CLA
Modified: 2020-12-11 10:41 EST (History)
3 users (show)

See Also:


Attachments
Trace log (32.10 KB, application/octet-stream)
2019-04-30 13:20 EDT, Simon Kuzin CLA
no flags Details
Proposed patch (986 bytes, patch)
2019-04-30 13:23 EDT, Simon Kuzin CLA
no flags Details | Diff
this patch works for mysql5.7 (6.45 KB, application/octet-stream)
2020-03-19 12:24 EDT, Robert Schulk CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Simon Kuzin CLA 2019-04-30 13:20:16 EDT
Created attachment 278450 [details]
Trace log

MySQL 8.0.15. InnoDB
Horizontal Mapping Strategy

Scenario:
1. Start CDO server on empty DB schema.

Expected result:
1. CDO server started successfully
2. DB schema intialized

Actual result:
1. CDO server startup interrupted with exception : "org.eclipse.net4j.db.DBException: java.sql.SQLException: Table definition has changed, please retry transaction" in HorizontalBranchingClassMapping.writeRevision
(log attached)

Similar issue discussed in CDO Bug_482886:https://bugs.eclipse.org/bugs/show_bug.cgi?id=482886.

"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)."

In current version org.eclipse.emf.cdo.server.db (4.6), AbstractHorizontalClassMapping.initTable opens SchemaTransaction using separate dedicated db connection , separate from main one , used for DML.
As a consequence, active transaction open on main DML connection gets invalidated and next DML statement fails.

This code might also fail on Oracle/Postgres due to strict transaction isolation, though i did not tested it with Oracle/Postgres.

Immediate solution is to run SchemaTransaction over main DML connection.

Is there any specific reason to run SchemaTransaction over separate connection ?
Comment 1 Simon Kuzin CLA 2019-04-30 13:21:00 EDT
Proposed patch attached.
Comment 2 Simon Kuzin CLA 2019-04-30 13:23:04 EDT
Created attachment 278451 [details]
Proposed patch
Comment 3 Simon Kuzin CLA 2019-04-30 13:43:55 EDT
For patch, necessary to run CDO server with MySQL 8 , refer to Bug 546671 : https://bugs.eclipse.org/bugs/show_bug.cgi?id=546671
Comment 4 Eike Stepper CLA 2019-11-08 02:06:59 EST
Moving all unresolved issues to version 4.8-
Comment 5 Eike Stepper CLA 2019-12-13 12:53:22 EST
Moving all unresolved issues to version 4.9
Comment 6 Robert Schulk CLA 2020-03-19 12:17:51 EDT
*** Bug 560986 has been marked as a duplicate of this bug. ***
Comment 7 Robert Schulk CLA 2020-03-19 12:23:20 EDT
Also Mysql 5.7 is affected.
For me, the proposed patch needs some more changes. I will attach a patch which worked for me with Mysql 5.7.
Comment 8 Robert Schulk CLA 2020-03-19 12:24:12 EDT
Created attachment 282152 [details]
this patch works for mysql5.7
Comment 9 Eike Stepper CLA 2020-03-29 12:58:27 EDT
For bug 561563 I've committed changes that may change this symptom. I'm not sure it addresses the possibly Mysql-specific underlying root cause, but it should at least change the error handling in the rollback case.

Is it possible that you try your scenario again with this new code?
Comment 10 Eike Stepper CLA 2020-03-29 12:59:27 EDT
I've kicked build I20200329-1258...
Comment 11 Robert Schulk CLA 2020-03-30 04:49:11 EDT
For me: neither mysql 5 or 8 are working. Although: the rollback seems to be successful, so this is good I guess. But the repository cannot be started anyways.

The original exception like before is still being thrown. For me, only the proposed patch seems to fix it.
Comment 12 Eike Stepper CLA 2020-03-30 09:03:57 EDT
(In reply to Robert Schulk from comment #11)
> For me: neither mysql 5 or 8 are working. Although: the rollback seems to be
> successful, so this is good I guess. 

Thanks, Robert, for testing it. Making the automatic rollback work was the goal of my commit so far.

> But the repository cannot be started anyways.
> 
> The original exception like before is still being thrown. For me, only the
> proposed patch seems to fix it.

I'll test the patch when I have time to update all my DBMS versions. I vaguely recall that the proposed patch might cause regressions with other DBMS types. Which could mean that we need to refactor the decision about whether to use the same or a separate Connection into the DBAdapter...
Comment 13 Simon Kuzin CLA 2020-04-01 10:39:13 EDT
Hi Robert, Eike,

nice to see this issue finally grabbed some attention.

For the time passed from the creation of the ticket, I've got CDO server with proposed patch running with Postgres 11 and Oracle 11.

I can run some sanity check on these DBMSs if you guide me on tests, we need to execute.
Comment 14 Eike Stepper CLA 2020-04-03 03:54:57 EDT
So, I've spent the better part of this entire week on modernizing our Mysql support. That includes the following activities:

- Upgrade the MYSQLAdapter to version 5.7.28
  * Notice the new, smaller list of reserved words (which are actually just the "keywords"). This can lead to problems when using the new adapter with an older db. Manual schema modifications may be required!
  
- Refactor the decision about whether to use the same or a separate Connection into the DBAdapter
  * that fixes the problem of this bugzilla 
  * and also works with H2

- Introduce two new DBStore-level properties:
  <property name="externalRefsURIColumnType" value="VARCHAR"/>
  <property name="externalRefsURIColumnLength" value="1024"/>

- Introduce DBAdapter.convertToSQL(Object)
  * Called from SQLQueryHandler to support customizable parameter value conversion
  
- Introduce IDBField.isIndexed()
  * Called from MYSQLAdapter.getTypeName(IDBField) to implement smarter VARCHAR conversion
  
- Fixed all (!) test failures in AllTestsDBMysql
  * Create /org.eclipse.emf.cdo.tests.db/install-db/install-mysql.ant to download, install, initialize, and start a Mysql db.
  * See comment on MYSQLConfig.java


TODOs:

- Provide a p2 repo with latest JDBC drivers
- Test with Postgres, Oracle, DB2, Derby, Hsqldb
- Fix a few timeouts in auditing that are related to testing CDOUnit support, see Bugzilla_486458b_Test.testLongCommitWithParallelCreateUnit()
- Cope with MySQL 8.x
Comment 15 Eike Stepper CLA 2020-04-03 04:00:01 EDT
(In reply to comment #13)
> For the time passed from the creation of the ticket, I've got CDO server with
> proposed patch running with Postgres 11 and Oracle 11.
> 
> I can run some sanity check on these DBMSs if you guide me on tests, we need to
> execute.

Simon, that would be absolutely great. We have the following launch configs:
	CDO AllTests (PostgreSQL ALL)
	CDO AllTests (Oracle)
	
But I have currently no clue what subtleties are in org.eclipse.emf.cdo.tests.db.PostgresqlConfig and org.eclipse.emf.cdo.tests.db.OracleConfig. If you give it a try and hit problems, let me know...
Comment 16 Eike Stepper CLA 2020-04-03 04:02:14 EDT
(In reply to comment #14)
> - Upgrade the MYSQLAdapter to version 5.7.28
> * Notice the new, smaller list of reserved words (which are actually just the
> "keywords"). This can lead to problems when using the new adapter with an older
> db. Manual schema modifications may be required!

A solution to bug 282789 would help at least for similar cases in the future...
Comment 17 Eike Stepper CLA 2020-04-03 04:19:09 EDT
The changes are committed:
https://git.eclipse.org/c/cdo/cdo.git/commit/?id=cc6e929b042369cb56a2a30436f150b337ddd664
Comment 18 Robert Schulk CLA 2020-04-15 04:42:19 EDT
Thanks so much! The last integration build works for me (mysql 5.7).

I observed an issue with the method CDODBUtil#createStore: the properties must not be set to null anymore. I am using an empty map, and everything works fine.
Comment 19 Eike Stepper CLA 2020-12-11 10:27:46 EST
Closing.
Comment 20 Eike Stepper CLA 2020-12-11 10:41:27 EST
Closing.