AMBARI-22216. Ambari Schema Upgrade Failed during Ambari Upgrade - workaround (dlysnichenko)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/e219186e Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/e219186e Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/e219186e Branch: refs/heads/feature-branch-AMBARI-21307 Commit: e219186ea68a869ee0b7929dfd6c5322cf8c1e7b Parents: df10813 Author: Lisnichenko Dmitro <dlysniche...@hortonworks.com> Authored: Mon Oct 16 12:13:01 2017 +0300 Committer: Lisnichenko Dmitro <dlysniche...@hortonworks.com> Committed: Mon Oct 16 12:13:47 2017 +0300 ---------------------------------------------------------------------- .../ambari/server/upgrade/UpgradeCatalog260.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/e219186e/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog260.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog260.java b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog260.java index 866a501..71a0ff3 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog260.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog260.java @@ -81,6 +81,7 @@ public class UpgradeCatalog260 extends AbstractUpgradeCatalog { public static final String DESIRED_REPO_VERSION_ID_COLUMN = "desired_repo_version_id"; public static final String REPO_STATE_COLUMN = "repo_state"; public static final String FK_SCDS_DESIRED_STACK_ID = "FK_scds_desired_stack_id"; + public static final String FK_SERVICECOMPONENTDESIREDSTATE_DESIRED_STACK_ID = "FK_servicecomponentdesiredstate_desired_stack_id"; public static final String FK_SCDS_DESIRED_REPO_ID = "FK_scds_desired_repo_id"; public static final String REPO_VERSION_TABLE = "repo_version"; @@ -152,6 +153,9 @@ public class UpgradeCatalog260 extends AbstractUpgradeCatalog { public static final String STALE_POSTGRESS_USERS_LDAP_USER_KEY = "users_ldap_user_key"; public static final String SHORT_URL_COLUMN = "short_url"; public static final String FK_INSTANCE_URL_ID = "FK_instance_url_id"; + public static final String FK_SERVICEDESIREDSTATE_DESIRED_STACK_ID = "FK_servicedesiredstate_desired_stack_id"; + public static final String FK_HOSTCOMPONENTDESIREDSTATE_DESIRED_STACK_ID = "FK_hostcomponentdesiredstate_desired_stack_id"; + public static final String FK_HOSTCOMPONENTSTATE_CURRENT_STACK_ID = "FK_hostcomponentstate_current_stack_id"; /** @@ -187,6 +191,7 @@ public class UpgradeCatalog260 extends AbstractUpgradeCatalog { @Override protected void executeDDLUpdates() throws AmbariException, SQLException { int currentVersionID = getCurrentVersionID(); + dropBrokenFK(); updateServiceComponentDesiredStateTable(currentVersionID); updateServiceDesiredStateTable(currentVersionID); addSelectedCollumsToClusterconfigTable(); @@ -202,6 +207,20 @@ public class UpgradeCatalog260 extends AbstractUpgradeCatalog { removeStaleConstraints(); } + /** + * Drop broken FK + * {@value #FK_SERVICECOMPONENTDESIREDSTATE_DESIRED_STACK_ID} + * {@value #FK_SERVICEDESIREDSTATE_DESIRED_STACK_ID} + * {@value #FK_HOSTCOMPONENTDESIREDSTATE_DESIRED_STACK_ID} + * {@value #FK_HOSTCOMPONENTSTATE_CURRENT_STACK_ID} + */ + private void dropBrokenFK() throws SQLException { + dbAccessor.dropFKConstraint(SERVICE_COMPONENT_DESIRED_STATE_TABLE, FK_SERVICECOMPONENTDESIREDSTATE_DESIRED_STACK_ID); + dbAccessor.dropFKConstraint(SERVICE_DESIRED_STATE_TABLE, FK_SERVICEDESIREDSTATE_DESIRED_STACK_ID); + dbAccessor.dropFKConstraint(HOST_COMPONENT_DESIRED_STATE_TABLE, FK_HOSTCOMPONENTDESIREDSTATE_DESIRED_STACK_ID); + dbAccessor.dropFKConstraint(HOST_COMPONENT_STATE_TABLE, FK_HOSTCOMPONENTSTATE_CURRENT_STACK_ID); + } + /** * Updates {@value #VIEWURL_TABLE} table.