Dmitry Lysnichenko created AMBARI-12073: -------------------------------------------
Summary: ambari-server upgrade to 2.1 fails when config groups exist Key: AMBARI-12073 URL: https://issues.apache.org/jira/browse/AMBARI-12073 Project: Ambari Issue Type: Bug Components: ambari-server Reporter: Dmitry Lysnichenko Assignee: Dmitry Lysnichenko Fix For: 2.1.0 While executing {{ambari-server upgrade}} to Ambari 2.1 when configuration groups exist, the upgrade fails with the following in the ambari-server log, specifically related to the {{serviceconfighosts}} table: {code} 21 Jun 2015 17:55:10,368 INFO [main] DBAccessorImpl:676 - Executing query: ALTER TABLE serviceconfighosts ALTER COLUMN host_id SET NOT NULL 21 Jun 2015 17:55:10,369 ERROR [main] DBAccessorImpl:682 - Error executing query: ALTER TABLE serviceconfighosts ALTER COLUMN host_id SET NOT NULL org.postgresql.util.PSQLException: ERROR: column "host_id" contains null values at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2161) at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1890) at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:255) at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:559) at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:403) at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:395) at org.apache.ambari.server.orm.DBAccessorImpl.executeQuery(DBAccessorImpl.java:679) at org.apache.ambari.server.orm.DBAccessorImpl.executeQuery(DBAccessorImpl.java:659) at org.apache.ambari.server.orm.DBAccessorImpl.setColumnNullable(DBAccessorImpl.java:896) at org.apache.ambari.server.upgrade.UpgradeCatalog210.executeHostsDDLUpdates(UpgradeCatalog210.java:451) at org.apache.ambari.server.upgrade.UpgradeCatalog210.executeDDLUpdates(UpgradeCatalog210.java:176) at org.apache.ambari.server.upgrade.AbstractUpgradeCatalog.upgradeSchema(AbstractUpgradeCatalog.java:512) at org.apache.ambari.server.upgrade.SchemaUpgradeHelper.executeUpgrade(SchemaUpgradeHelper.java:176) at org.apache.ambari.server.upgrade.SchemaUpgradeHelper.main(SchemaUpgradeHelper.java:277) 21 Jun 2015 17:55:10,371 ERROR [main] SchemaUpgradeHelper:178 - Upgrade failed. org.postgresql.util.PSQLException: ERROR: column "host_id" contains null values at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2161) at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1890) at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:255) at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:559) at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:403) at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:395) at org.apache.ambari.server.orm.DBAccessorImpl.executeQuery(DBAccessorImpl.java:679) at org.apache.ambari.server.orm.DBAccessorImpl.executeQuery(DBAccessorImpl.java:659) at org.apache.ambari.server.orm.DBAccessorImpl.setColumnNullable(DBAccessorImpl.java:896) at org.apache.ambari.server.upgrade.UpgradeCatalog210.executeHostsDDLUpdates(UpgradeCatalog210.java:451) at org.apache.ambari.server.upgrade.UpgradeCatalog210.executeDDLUpdates(UpgradeCatalog210.java:176) at org.apache.ambari.server.upgrade.AbstractUpgradeCatalog.upgradeSchema(AbstractUpgradeCatalog.java:512) at org.apache.ambari.server.upgrade.SchemaUpgradeHelper.executeUpgrade(SchemaUpgradeHelper.java:176) at org.apache.ambari.server.upgrade.SchemaUpgradeHelper.main(SchemaUpgradeHelper.java:277) 21 Jun 2015 17:55:10,371 ERROR [main] SchemaUpgradeHelper:294 - Exception occurred during upgrade, failed org.apache.ambari.server.AmbariException: ERROR: column "host_id" contains null values at org.apache.ambari.server.upgrade.SchemaUpgradeHelper.executeUpgrade(SchemaUpgradeHelper.java:179) at org.apache.ambari.server.upgrade.SchemaUpgradeHelper.main(SchemaUpgradeHelper.java:277) Caused by: org.postgresql.util.PSQLException: ERROR: column "host_id" contains null values at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2161) at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1890) at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:255) at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:559) at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:403) at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:395) at org.apache.ambari.server.orm.DBAccessorImpl.executeQuery(DBAccessorImpl.java:679) at org.apache.ambari.server.orm.DBAccessorImpl.executeQuery(DBAccessorImpl.java:659) at org.apache.ambari.server.orm.DBAccessorImpl.setColumnNullable(DBAccessorImpl.java:896) at org.apache.ambari.server.upgrade.UpgradeCatalog210.executeHostsDDLUpdates(UpgradeCatalog210.java:451) at org.apache.ambari.server.upgrade.UpgradeCatalog210.executeDDLUpdates(UpgradeCatalog210.java:176) at org.apache.ambari.server.upgrade.AbstractUpgradeCatalog.upgradeSchema(AbstractUpgradeCatalog.java:512) at org.apache.ambari.server.upgrade.SchemaUpgradeHelper.executeUpgrade(SchemaUpgradeHelper.java:176) ... 1 more {code} This seems to be because of this code in UpgradeCatalog210.executeHostsDDLUpdates: {code} ... // The column name is different for one table String hostNameColumnName = tableName.equals(SERVICE_CONFIG_HOSTS_TABLE) ? "hostname" : "host_name"; if (dbAccessor.tableHasData(tableName) && dbAccessor.tableHasColumn(tableName,HOST_NAME_COL)) { dbAccessor.executeQuery("UPDATE " + tableName + " t SET host_id = (SELECT host_id FROM hosts h WHERE h.host_name = t." + hostNameColumnName + ") WHERE t.host_id IS NULL AND t." + hostNameColumnName + " IS NOT NULL"); ... {code} The code figures out that it needs to switch table names for the {{serviceconfighosts}} table but then when it does the test to see if the table has a host name column it tests for HOST_NAME_COLUMN and not the generated variable. This causes the population of the host_id column to be skipped in this table only, and the resulting addition of the NOT NULL constraint to fail. -- This message was sent by Atlassian JIRA (v6.3.4#6332)