-----------------------------------------------------------
This is an automatically generated e-mail. To reply, visit:
https://reviews.apache.org/r/57478/
-----------------------------------------------------------
Review request for Ambari, Sumit Mohanty and Sid Wagle.
Bugs: AMBARI-20387
https://issues.apache.org/jira/browse/AMBARI-20387
Repository: ambari
Description
-------
There are some MySQL installations of Ambari which are correctly setup to use
{{InnoDB}}, but still are missing foreign key relationships on certain tables.
When the upgrade catalogs try to drop foreign keys by name, they are not found.
However, when re-creating them, the existing {{INDEX}} constraints are named
the same and prevent the new FKs from being created.
```
Error output from schema upgrade command:
Exception in thread "main" org.apache.ambari.server.AmbariException: Duplicate
key name 'hstcmpnntdesiredstatecmpnntnme'
at
org.apache.ambari.server.upgrade.SchemaUpgradeHelper.executeUpgrade(SchemaUpgradeHelper.java:210)
at
org.apache.ambari.server.upgrade.SchemaUpgradeHelper.main(SchemaUpgradeHelper.java:350)
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Duplicate
key name 'hstcmpnntdesiredstatecmpnntnme'
...
... 1 more
ERROR: Error executing schema upgrade, please check the server logs.
```
```
mysql> show create table hostcomponentdesiredstate;
----------------------------------------------------------------------------------+
| hostcomponentdesiredstate | CREATE TABLE `hostcomponentdesiredstate` (
`cluster_id` bigint(20) NOT NULL,
`component_name` varchar(255) NOT NULL,
`desired_state` varchar(255) NOT NULL,
`service_name` varchar(255) NOT NULL,
`admin_state` varchar(32) DEFAULT NULL,
`maintenance_state` varchar(32) NOT NULL DEFAULT 'ACTIVE',
`security_state` varchar(32) NOT NULL DEFAULT 'UNSECURED',
`restart_required` tinyint(1) NOT NULL DEFAULT '0',
`host_id` bigint(20) NOT NULL,
`desired_stack_id` bigint(20) NOT NULL,
PRIMARY KEY (`cluster_id`,`component_name`,`host_id`,`service_name`),
KEY `hstcmpnntdesiredstatecmpnntnme`
(`component_name`,`cluster_id`,`service_name`),
KEY `FK_hostcomponentdesiredstate_desired_stack_id` (`desired_stack_id`),
KEY `FK_hostcomponentdesiredstate_host_id` (`host_id`),
CONSTRAINT `FK_hcdesiredstate_host_id` FOREIGN KEY (`host_id`) REFERENCES
`hosts` (`host_id`),
CONSTRAINT `fk_hcds_desired_stack_id` FOREIGN KEY (`desired_stack_id`)
REFERENCES `stack` (`stack_id`),
CONSTRAINT `FK_hostcomponentdesiredstate_desired_stack_id` FOREIGN KEY
(`desired_stack_id`) REFERENCES `stack` (`stack_id`),
CONSTRAINT `FK_hostcomponentdesiredstate_host_id` FOREIGN KEY (`host_id`)
REFERENCES `hosts` (`host_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 |
```
In this case, the {{INDEX}} {{hstcmpnntdesiredstatecmpnntnme}} prevents the new
FK creation.
Diffs
-----
ambari-server/src/main/java/org/apache/ambari/server/orm/DBAccessor.java
5d9eb6c
ambari-server/src/main/java/org/apache/ambari/server/orm/DBAccessorImpl.java
1c0ab30
Diff: https://reviews.apache.org/r/57478/diff/1/
Testing
-------
Tests run: 4939, Failures: 0, Errors: 0, Skipped: 39
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 19:04 min
[INFO] Finished at: 2017-03-09T16:49:32-05:00
[INFO] Final Memory: 59M/728M
[INFO] ------------------------------------------------------------------------
Thanks,
Jonathan Hurley