Repository: ambari Updated Branches: refs/heads/branch-2.6 9e3030517 -> 8187ecdda refs/heads/trunk 54d4d5e62 -> 0c45d48f5
AMBARI-21883. Upgrade to Ambari 2.6.0 fails with DB constraint violation on fk_sc_history_upgrade_id (dlysnichenko) Project: http://git-wip-us.apache.org/repos/asf/ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/8187ecdd Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/8187ecdd Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/8187ecdd Branch: refs/heads/branch-2.6 Commit: 8187ecddaedeaf0621f14f2fcca0c492d9372380 Parents: 9e30305 Author: Lisnichenko Dmitro <dlysniche...@hortonworks.com> Authored: Wed Sep 6 20:05:32 2017 +0300 Committer: Lisnichenko Dmitro <dlysniche...@hortonworks.com> Committed: Wed Sep 6 20:05:32 2017 +0300 ---------------------------------------------------------------------- .../ambari/server/checks/DatabaseConsistencyCheckHelper.java | 5 ++++- .../org/apache/ambari/server/upgrade/UpgradeCatalog260.java | 6 +++++- 2 files changed, 9 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/8187ecdd/ambari-server/src/main/java/org/apache/ambari/server/checks/DatabaseConsistencyCheckHelper.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/checks/DatabaseConsistencyCheckHelper.java b/ambari-server/src/main/java/org/apache/ambari/server/checks/DatabaseConsistencyCheckHelper.java index 97da8b1..575485b 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/checks/DatabaseConsistencyCheckHelper.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/checks/DatabaseConsistencyCheckHelper.java @@ -654,7 +654,7 @@ public class DatabaseConsistencyCheckHelper { Set<String> nonMappedConfigs = new HashSet<>(); for (ClusterConfigEntity clusterConfigEntity : notMappedClasterConfigs) { - if (!clusterConfigEntity.isUnmapped()){ + if (!clusterConfigEntity.isUnmapped()){ //this check does not report warning for configs from deleted services nonMappedConfigs.add(clusterConfigEntity.getType() + '-' + clusterConfigEntity.getTag()); } } @@ -668,6 +668,7 @@ public class DatabaseConsistencyCheckHelper { * of desired host component states. According to ambari logic these * two tables should have the same count of rows. If not then we are * adding missed host components. + * hard to predict root couse of inconsistency, so it can be dangerous */ @Transactional static void fixHostComponentStatesCountEqualsHostComponentsDesiredStates() { @@ -740,6 +741,7 @@ public class DatabaseConsistencyCheckHelper { * The purpose of these checks is to avoid that tables and constraints in ambari's schema get confused with tables * and constraints in other schemas on the DB user's search path. This can happen after an improperly made DB restore * operation and can cause issues during upgrade. + * we may have no permissions (e.g. external DB) to auto fix this problem **/ static void checkSchemaName () { Configuration conf = injector.getInstance(Configuration.class); @@ -795,6 +797,7 @@ public class DatabaseConsistencyCheckHelper { /** * This method checks tables engine type to be innodb for MySQL. + * it's too risky to autofix by migrating DB to innodb * */ static void checkMySQLEngine () { Configuration conf = injector.getInstance(Configuration.class); http://git-wip-us.apache.org/repos/asf/ambari/blob/8187ecdd/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 f2eac97..7fb978b 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 @@ -85,6 +85,8 @@ public class UpgradeCatalog260 extends AbstractUpgradeCatalog { public static final String FK_REPO_VERSION_ID = "FK_repo_version_id"; public static final String UPGRADE_TABLE = "upgrade"; + public static final String UPGRADE_GROUP_TABLE = "upgrade_group"; + public static final String UPGRADE_ITEM_TABLE = "upgrade_item"; public static final String FROM_REPO_VERSION_ID_COLUMN = "from_repo_version_id"; public static final String TO_REPO_VERSION_ID_COLUMN = "to_repo_version_id"; public static final String ORCHESTRATION_COLUMN = "orchestration"; @@ -157,9 +159,9 @@ public class UpgradeCatalog260 extends AbstractUpgradeCatalog { addSelectedCollumsToClusterconfigTable(); updateHostComponentDesiredStateTable(); updateHostComponentStateTable(); + dropStaleTables(); updateUpgradeTable(); createUpgradeHistoryTable(); - dropStaleTables(); updateRepositoryVersionTable(); renameServiceDeletedColumn(); } @@ -229,6 +231,8 @@ public class UpgradeCatalog260 extends AbstractUpgradeCatalog { * @throws java.sql.SQLException */ private void updateUpgradeTable() throws SQLException { + dbAccessor.clearTable(UPGRADE_ITEM_TABLE); + dbAccessor.clearTable(UPGRADE_GROUP_TABLE); dbAccessor.clearTable(UPGRADE_TABLE); dbAccessor.dropFKConstraint(UPGRADE_TABLE, FK_UPGRADE_FROM_REPO_ID); dbAccessor.dropFKConstraint(UPGRADE_TABLE, FK_UPGRADE_TO_REPO_ID);