core icon indicating copy to clipboard operation
core copied to clipboard

Upgrade to 3.2.x fails for clients with SQL Server Databases

Open joseorsini opened this issue 11 years ago • 2 comments

Reproduced in client and locally running 3.2.2 with a DB from version 2.3.

Despite READCOMMITTEDSNAPSHOT and ALLOWSNAPSHOTISOLATION are set to true in the SQL Server 2012 DB (RE: http://dotcms.com/docs/latest/database-configuration ), we are having issues with this upgrade task

https://github.com/dotCMS/core/blob/master-3.2/src/com/dotmarketing/startup/runonce/Task03000CreateContainertStructures.java

We're forcing READ COMMITTED inside a Hibernate Transaction in order to move container-structures relationship to the newly created container_structures table, however, SQL Server does not support DDL operations under a Transaction running under Snapshot Isolation

https://msdn.microsoft.com/en-us/library/ms189122.aspx

This means that all ALTER TABLE queries within that transaction will fail:

https://gist.github.com/joseorsini/ac11794ca3df3a5c4527

We're also hitting this exception https://github.com/dotCMS/core/blob/master-3.2/src/com/dotmarketing/startup/runonce/Task03000CreateContainertStructures.java#L101 however, that constraint exists in SQL Server. After adding an e.getMessage() to the Logger.error, we're able to see why it fails, and the exception is the same than the Gist from above.

2015-07-10 11:04:45,122 INFO  com.dotmarketing.common.db.DotConnect - Executing alter table containers drop constraint structure_fk
2015-07-10 11:04:45,124 INFO  com.dotmarketing.startup.runonce.Task03000CreateContainertStructures - foreign key for structure_inode on containers table didn't exist, not dropping anything here: Transaction failed because this DDL statement is not allowed inside a snapshot isolation transaction. Since metadata is not versioned, a metadata change can lead to inconsistency if mixed within snapshot isolation.
2015-07-10 11:04:45,124 INFO  com.dotmarketing.common.db.DotConnect - Executing alter table containers drop column structure_inode
2015-07-10 11:04:45,128 ERROR com.dotmarketing.startup.runonce.Task03000CreateContainertStructures - Transaction failed because this DDL statement is not allowed inside a snapshot isolation transaction. Since metadata is not versioned, a metadata change can lead to inconsistency if mixed within snapshot isolation.
com.microsoft.sqlserver.jdbc.SQLServerException: Transaction failed because this DDL statement is not allowed inside a snapshot isolation transaction. Since metadata is not versioned, a metadata change can lead to inconsistency if mixed within snapshot isolation.

joseorsini avatar Jul 10 '15 15:07 joseorsini

PR: https://github.com/dotCMS/core/pull/7933

joseorsini avatar Jul 15 '15 14:07 joseorsini

Fix is working. Tested upgrading manually from 2.5.7 to 3.2.4 using 3.2.4 Nightly build 2015-07-17 21:08 // Win7 Pro SP1 // SQLServer 2012 // Firefox & Chrome

shaydotcms avatar Jul 22 '15 14:07 shaydotcms