[ 
https://issues.apache.org/jira/browse/AMBARI-23204?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

ASF GitHub Bot updated AMBARI-23204:
------------------------------------
    Labels: pull-request-available upgrade  (was: upgrade)

> Ambari Upgrade : Schema Upgrade Fails with error "Foreign key constraint is 
> incorrectly formed"
> -----------------------------------------------------------------------------------------------
>
>                 Key: AMBARI-23204
>                 URL: https://issues.apache.org/jira/browse/AMBARI-23204
>             Project: Ambari
>          Issue Type: Bug
>          Components: ambari-server
>    Affects Versions: 2.7.0
>            Reporter: Jasmeen Kaur
>            Assignee: Attila Magyar
>            Priority: Blocker
>              Labels: pull-request-available, upgrade
>             Fix For: 2.7.0
>
>
> Ambari Schema Upgrade from 2.6.X to 2.7.0.0 fails with below exception . 
> A blocker for Ambari Upgrades testing.
> {code:java}
> 12 Mar 2018 00:51:37,879  INFO [main] SchemaUpgradeHelper:424 - Upgrading 
> schema to target version = 2.7.0.0
> 12 Mar 2018 00:51:37,883  INFO [main] SchemaUpgradeHelper:433 - Upgrading 
> schema from source version = 2.6.1
> 12 Mar 2018 00:51:37,888  INFO [main] SchemaUpgradeHelper:163 - Upgrade path: 
> [{ upgradeCatalog: sourceVersion = 2.6.1, targetVersion = 2.6.2 }, { 
> upgradeCatalog: sourceVersion = 2.6.2, targetVersion = 2.7.0 }, { 
> upgradeCatalog: sourceVersion = null, targetVersion = 2.7.0 }, { 
> upgradeCatalog: sourceVersion = null, targetVersion = 2.7.0 }]
> 12 Mar 2018 00:51:37,889  INFO [main] SchemaUpgradeHelper:200 - Executing DDL 
> upgrade...
> 12 Mar 2018 00:51:37,911  INFO [main] DBAccessorImpl:876 - Executing query: 
> ALTER TABLE topology_host_request ADD status VARCHAR(255)
> 12 Mar 2018 00:51:37,948  INFO [main] DBAccessorImpl:876 - Executing query: 
> ALTER TABLE topology_host_request ADD status_message VARCHAR(1024)
> 12 Mar 2018 00:51:37,982  INFO [main] DBAccessorImpl:876 - Executing query: 
> ALTER TABLE stage ADD status VARCHAR(255) NOT NULL DEFAULT 'PENDING'
> 12 Mar 2018 00:51:38,017  INFO [main] DBAccessorImpl:876 - Executing query: 
> ALTER TABLE stage ADD display_status VARCHAR(255) NOT NULL DEFAULT 'PENDING'
> 12 Mar 2018 00:51:38,055  INFO [main] DBAccessorImpl:876 - Executing query: 
> ALTER TABLE request ADD display_status VARCHAR(255) NOT NULL DEFAULT 'PENDING'
> 12 Mar 2018 00:51:38,091  INFO [main] DBAccessorImpl:876 - Executing query: 
> ALTER TABLE request ADD user_name VARCHAR(255)
> 12 Mar 2018 00:51:38,127  INFO [main] DBAccessorImpl:876 - Executing query: 
> ALTER TABLE host_role_command ADD ops_display_name VARCHAR(255)
> 12 Mar 2018 00:51:38,314  INFO [main] DBAccessorImpl:876 - Executing query: 
> ALTER TABLE hostcomponentdesiredstate DROP COLUMN security_state
> 12 Mar 2018 00:51:38,351  INFO [main] DBAccessorImpl:876 - Executing query: 
> ALTER TABLE hostcomponentstate DROP COLUMN security_state
> 12 Mar 2018 00:51:38,387  INFO [main] DBAccessorImpl:876 - Executing query: 
> ALTER TABLE servicedesiredstate DROP COLUMN security_state
> 12 Mar 2018 00:51:38,426  INFO [main] DBAccessorImpl:876 - Executing query: 
> CREATE TABLE ambari_configuration (category_name VARCHAR(100) NOT NULL, 
> property_name VARCHAR(100) NOT NULL, property_value VARCHAR(255)) 
> ENGINE=INNODB
> 12 Mar 2018 00:51:38,435  INFO [main] DBAccessorImpl:876 - Executing query: 
> ALTER TABLE ambari_configuration ADD CONSTRAINT PK_ambari_configuration 
> PRIMARY KEY (category_name,property_name)
> 12 Mar 2018 00:51:38,443  INFO [main] DBAccessorImpl:876 - Executing query: 
> ALTER TABLE hostcomponentstate ADD last_live_state VARCHAR(255) DEFAULT 
> 'UNKNOWN'
> 12 Mar 2018 00:51:38,476  WARN [main] DBAccessorImpl:965 - 
> user_authentication_tmp table doesn't exists, skipping
> 12 Mar 2018 00:51:38,477  INFO [main] DBAccessorImpl:876 - Executing query: 
> CREATE TABLE user_authentication_tmp (user_authentication_id BIGINT NOT NULL, 
> user_id BIGINT NOT NULL, authentication_type VARCHAR(50) NOT NULL, 
> authentication_key LONGTEXT, create_time DATETIME, update_time DATETIME) 
> ENGINE=INNODB
> 12 Mar 2018 00:51:38,483  INFO [main] DBAccessorImpl:876 - Executing query: 
> CREATE TABLE user_authentication (user_authentication_id BIGINT NOT NULL, 
> user_id BIGINT NOT NULL, authentication_type VARCHAR(50) NOT NULL, 
> authentication_key LONGTEXT, create_time DATETIME, update_time DATETIME) 
> ENGINE=INNODB
> 12 Mar 2018 00:51:38,490  INFO [main] DBAccessorImpl:876 - Executing query: 
> ALTER TABLE user_authentication ADD CONSTRAINT PK_user_authentication PRIMARY 
> KEY (user_authentication_id)
> 12 Mar 2018 00:51:38,555  INFO [main] DBAccessorImpl:876 - Executing query: 
> ALTER TABLE user_authentication ADD CONSTRAINT FK_user_authentication_users 
> FOREIGN KEY (user_id) REFERENCES users (user_id)
> 12 Mar 2018 00:51:38,572 ERROR [main] DBAccessorImpl:882 - Error executing 
> query: ALTER TABLE user_authentication ADD CONSTRAINT 
> FK_user_authentication_users FOREIGN KEY (user_id) REFERENCES users (user_id)
> 12 Mar 2018 00:51:38,572 ERROR [main] DBAccessorImpl:882 - Error executing 
> query: ALTER TABLE user_authentication ADD CONSTRAINT 
> FK_user_authentication_users FOREIGN KEY (user_id) REFERENCES users (user_id)
> java.sql.SQLException: Can't create table `ambaricustom`.`#sql-642_c9` 
> (errno: 150 "Foreign key constraint is incorrectly formed")
>         at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:996)
>         at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3887)
>         at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3823)
>         at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2435)
>         at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2582)
>         at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2526)
>         at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2484)
>         at com.mysql.jdbc.StatementImpl.execute(StatementImpl.java:848)
>         at com.mysql.jdbc.StatementImpl.execute(StatementImpl.java:742)
>         at 
> org.apache.ambari.server.orm.DBAccessorImpl.executeQuery(DBAccessorImpl.java:879)
>         at 
> org.apache.ambari.server.orm.DBAccessorImpl.addFKConstraint(DBAccessorImpl.java:519)
>         at 
> org.apache.ambari.server.orm.DBAccessorImpl.addFKConstraint(DBAccessorImpl.java:484)
>         at 
> org.apache.ambari.server.upgrade.UpgradeCatalog270.createUserAuthenticationTable(UpgradeCatalog270.java:560)
>         at 
> org.apache.ambari.server.upgrade.UpgradeCatalog270.upgradeUserTables(UpgradeCatalog270.java:303)
>         at 
> org.apache.ambari.server.upgrade.UpgradeCatalog270.executeDDLUpdates(UpgradeCatalog270.java:280)
>         at 
> org.apache.ambari.server.upgrade.AbstractUpgradeCatalog.upgradeSchema(AbstractUpgradeCatalog.java:973)
>         at 
> org.apache.ambari.server.upgrade.SchemaUpgradeHelper.executeUpgrade(SchemaUpgradeHelper.java:205)
>         at 
> org.apache.ambari.server.upgrade.SchemaUpgradeHelper.main(SchemaUpgradeHelper.java:448)
> 12 Mar 2018 00:51:38,572  WARN [main] DBAccessorImpl:521 - Add FK constraint 
> failed, constraintName = FK_user_authentication_users, tableName = 
> user_authentication
> 12 Mar 2018 00:51:38,572 ERROR [main] SchemaUpgradeHelper:207 - Upgrade 
> failed.
> java.sql.SQLException: Can't create table `ambaricustom`.`#sql-642_c9` 
> (errno: 150 "Foreign key constraint is incorrectly formed")
>         at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:996)
>         at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3887)
>         at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3823)
>         at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2435)
>         at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2582)
>         at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2526)
>         at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2484)
>         at com.mysql.jdbc.StatementImpl.execute(StatementImpl.java:848)
>         at com.mysql.jdbc.StatementImpl.execute(StatementImpl.java:742)
>         at 
> org.apache.ambari.server.orm.DBAccessorImpl.executeQuery(DBAccessorImpl.java:879)
>         at 
> org.apache.ambari.server.orm.DBAccessorImpl.addFKConstraint(DBAccessorImpl.java:519)
>         at 
> org.apache.ambari.server.orm.DBAccessorImpl.addFKConstraint(DBAccessorImpl.java:484)
>         at 
> org.apache.ambari.server.upgrade.UpgradeCatalog270.createUserAuthenticationTable(UpgradeCatalog270.java:560)
> at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3823)
>         at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2435)
>         at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2582)
>         at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2526)
>         at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2484)
>         at com.mysql.jdbc.StatementImpl.execute(StatementImpl.java:848)
>         at com.mysql.jdbc.StatementImpl.execute(StatementImpl.java:742)
>         at 
> org.apache.ambari.server.orm.DBAccessorImpl.executeQuery(DBAccessorImpl.java:879)
>         at 
> org.apache.ambari.server.orm.DBAccessorImpl.addFKConstraint(DBAccessorImpl.java:519)
>         at 
> org.apache.ambari.server.orm.DBAccessorImpl.addFKConstraint(DBAccessorImpl.java:484)
>         at 
> org.apache.ambari.server.upgrade.UpgradeCatalog270.createUserAuthenticationTable(UpgradeCatalog270.java:560)
>         at 
> org.apache.ambari.server.upgrade.UpgradeCatalog270.upgradeUserTables(UpgradeCatalog270.java:303)
>         at 
> org.apache.ambari.server.upgrade.UpgradeCatalog270.executeDDLUpdates(UpgradeCatalog270.java:280)
>         at 
> org.apache.ambari.server.upgrade.AbstractUpgradeCatalog.upgradeSchema(AbstractUpgradeCatalog.java:973)
>         at 
> org.apache.ambari.server.upgrade.SchemaUpgradeHelper.executeUpgrade(SchemaUpgradeHelper.java:205)
>         at 
> org.apache.ambari.server.upgrade.SchemaUpgradeHelper.main(SchemaUpgradeHelper.java:448)
> 12 Mar 2018 00:51:38,573 ERROR [main] SchemaUpgradeHelper:473 - Exception 
> occurred during upgrade, failed
> org.apache.ambari.server.AmbariException: Can't create table 
> `ambaricustom`.`#sql-642_c9` (errno: 150 "Foreign key constraint is 
> incorrectly formed")
>         at 
> org.apache.ambari.server.upgrade.SchemaUpgradeHelper.executeUpgrade(SchemaUpgradeHelper.java:208)
>         at 
> org.apache.ambari.server.upgrade.SchemaUpgradeHelper.main(SchemaUpgradeHelper.java:448)
> Caused by: java.sql.SQLException: Can't create table 
> `ambaricustom`.`#sql-642_c9` (errno: 150 "Foreign key constraint is 
> incorrectly formed")
>         at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:996)
>         at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3887)
>         at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3823)
>         at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2435)
>         at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2582)
>         at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2526)
>         at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2484)
>         at com.mysql.jdbc.StatementImpl.execute(StatementImpl.java:848)
>         at com.mysql.jdbc.StatementImpl.execute(StatementImpl.java:742)
>         at 
> org.apache.ambari.server.orm.DBAccessorImpl.executeQuery(DBAccessorImpl.java:879)
>         at 
> org.apache.ambari.server.orm.DBAccessorImpl.addFKConstraint(DBAccessorImpl.java:519)
>         at 
> org.apache.ambari.server.orm.DBAccessorImpl.addFKConstraint(DBAccessorImpl.java:484)
>         at 
> org.apache.ambari.server.upgrade.UpgradeCatalog270.createUserAuthenticationTable(UpgradeCatalog270.java:560)
>         at 
> org.apache.ambari.server.upgrade.UpgradeCatalog270.upgradeUserTables(UpgradeCatalog270.java:303)
>         at 
> org.apache.ambari.server.upgrade.UpgradeCatalog270.executeDDLUpdates(UpgradeCatalog270.java:280)
>         at 
> org.apache.ambari.server.upgrade.AbstractUpgradeCatalog.upgradeSchema(AbstractUpgradeCatalog.java:973)
>         at 
> org.apache.ambari.server.upgrade.SchemaUpgradeHelper.executeUpgrade(SchemaUpgradeHelper.java:205)
>         ... 1 more
> {code}
> Possibly the issue is in different datatypes of user_id(int(11)) column in 
> users and user_id(bigint(20)) in user_authentication table : See below:
> {code:java}
> MariaDB [ambaricustom]> desc user_authentication;
> +------------------------+-------------+------+-----+---------+-------+
> | Field                  | Type        | Null | Key | Default | Extra |
> +------------------------+-------------+------+-----+---------+-------+
> | user_authentication_id | bigint(20)  | NO   | PRI | NULL    |       |
> | user_id                | bigint(20)  | NO   |     | NULL    |       |
> | authentication_type    | varchar(50) | NO   |     | NULL    |       |
> | authentication_key     | longtext    | YES  |     | NULL    |       |
> | create_time            | datetime    | YES  |     | NULL    |       |
> | update_time            | datetime    | YES  |     | NULL    |       |
> +------------------------+-------------+------+-----+---------+-------+
> 6 rows in set (0.01 sec)
> MariaDB [ambaricustom]> desc users;
> +-----------------------+---------------+------+-----+---------------------+-------+
> | Field                 | Type          | Null | Key | Default             | 
> Extra |
> +-----------------------+---------------+------+-----+---------------------+-------+
> | user_id               | int(11)       | NO   | PRI | NULL                |  
>      |
> | principal_id          | bigint(20)    | NO   | MUL | NULL                |  
>      |
> | create_time           | timestamp     | NO   |     | current_timestamp() |  
>      |
> | ldap_user             | int(11)       | NO   |     | 0                   |  
>      |
> | user_type             | varchar(100)  | NO   |     | LOCAL               |  
>      |
> | user_name             | varchar(100)  | NO   | MUL | NULL                |  
>      |
> | user_password         | varchar(255)  | YES  |     | NULL                |  
>      |
> | active                | int(11)       | NO   |     | 1                   |  
>      |
> | active_widget_layouts | varchar(1024) | YES  |     | NULL                |  
>      |
> +-----------------------+---------------+------+-----+---------------------+-------+
> 9 rows in set (0.00 sec)
> {code}



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to