Repository: ambari Updated Branches: refs/heads/branch-1.7.0 b6076d3e0 -> d2c515945
AMBARI-8096. 1.4.1 -> 1.7.0 upgrade throws exception. (mpapirkovskyy) Project: http://git-wip-us.apache.org/repos/asf/ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/d2c51594 Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/d2c51594 Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/d2c51594 Branch: refs/heads/branch-1.7.0 Commit: d2c5159454018fde6207888d9274a02093c28c08 Parents: b6076d3 Author: Myroslav Papirkovskyy <mpapyrkovs...@hortonworks.com> Authored: Sat Nov 1 20:59:23 2014 +0200 Committer: Myroslav Papirkovskyy <mpapyrkovs...@hortonworks.com> Committed: Sat Nov 1 21:49:21 2014 +0200 ---------------------------------------------------------------------- .../ambari/server/orm/DBAccessorImpl.java | 2 +- .../server/upgrade/UpgradeCatalog150.java | 25 +++++++++++--------- 2 files changed, 15 insertions(+), 12 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/d2c51594/ambari-server/src/main/java/org/apache/ambari/server/orm/DBAccessorImpl.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/DBAccessorImpl.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/DBAccessorImpl.java index 543e707..05db3f7 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/orm/DBAccessorImpl.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/DBAccessorImpl.java @@ -567,7 +567,7 @@ public class DBAccessorImpl implements DBAccessor { @Override public void dropSequence(String sequenceName) throws SQLException { - executeQuery(dbmsHelper.getDropSequenceStatement(sequenceName)); + executeQuery(dbmsHelper.getDropSequenceStatement(sequenceName), true); } @Override http://git-wip-us.apache.org/repos/asf/ambari/blob/d2c51594/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog150.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog150.java b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog150.java index 703987b..2ccf16b 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog150.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog150.java @@ -64,6 +64,7 @@ import javax.persistence.criteria.*; import java.io.File; import java.io.IOException; +import java.sql.ResultSet; import java.sql.SQLException; import java.util.ArrayList; import java.util.List; @@ -433,26 +434,28 @@ public class UpgradeCatalog150 extends AbstractUpgradeCatalog { } } - - // TODO: Convert all possible native queries using Criteria builder - // Sequences if (dbAccessor.tableExists("ambari_sequences")) { if (dbType.equals(Configuration.POSTGRES_DB_NAME)) { + + ResultSet resultSet = dbAccessor.executeSelect("select * from ambari_sequences where sequence_name in " + + "('cluster_id_seq','user_id_seq','host_role_command_id_seq')"); + try { - dbAccessor.executeQuery(getPostgresSequenceUpgradeQuery()); - // Deletes - dbAccessor.dropSequence("host_role_command_task_id_seq"); - dbAccessor.dropSequence("users_user_id_seq"); - dbAccessor.dropSequence("clusters_cluster_id_seq"); - } catch (SQLException sql) { - LOG.warn("Sequence update threw exception. ", sql); + if (!resultSet.next()) { + dbAccessor.executeQuery(getPostgresSequenceUpgradeQuery(), true); + // Deletes + dbAccessor.dropSequence("host_role_command_task_id_seq"); + dbAccessor.dropSequence("users_user_id_seq"); + dbAccessor.dropSequence("clusters_cluster_id_seq"); + } + } finally { + resultSet.close(); } } } //add new sequences for config groups - //TODO evalate possibility to automatically wrap object names in DBAcessor String valueColumnName = "sequence_value"; dbAccessor.executeQuery("INSERT INTO ambari_sequences(sequence_name, " + valueColumnName + ") " +