You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by jo...@apache.org on 2015/08/05 20:44:25 UTC
ambari git commit: AMBARI-12570 - Cluster creates stuck at 9x%
(deadlock sql exception) (part2) (jonathanhurley)
Repository: ambari
Updated Branches:
refs/heads/trunk d592ba9b0 -> 0862422cd
AMBARI-12570 - Cluster creates stuck at 9x% (deadlock sql exception) (part2) (jonathanhurley)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/0862422c
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/0862422c
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/0862422c
Branch: refs/heads/trunk
Commit: 0862422cd08c80787a272aec08207146e527819e
Parents: d592ba9
Author: Jonathan Hurley <jh...@hortonworks.com>
Authored: Wed Aug 5 14:44:06 2015 -0400
Committer: Jonathan Hurley <jh...@hortonworks.com>
Committed: Wed Aug 5 14:44:06 2015 -0400
----------------------------------------------------------------------
.../server/upgrade/UpgradeCatalog211.java | 150 +++++++++++++++++--
.../server/upgrade/UpgradeCatalog220.java | 112 +-------------
2 files changed, 138 insertions(+), 124 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/0862422c/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog211.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog211.java b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog211.java
index 616d4c4..af2c349 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog211.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog211.java
@@ -18,25 +18,45 @@
package org.apache.ambari.server.upgrade;
-import com.google.inject.Inject;
-import com.google.inject.Injector;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.text.MessageFormat;
+import java.util.Collections;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.atomic.AtomicLong;
+
import org.apache.ambari.server.AmbariException;
+import org.apache.ambari.server.configuration.Configuration;
+import org.apache.ambari.server.configuration.Configuration.DatabaseType;
import org.apache.ambari.server.controller.AmbariManagementController;
+import org.apache.ambari.server.orm.DBAccessor.DBColumnInfo;
import org.apache.ambari.server.orm.dao.DaoUtils;
import org.apache.ambari.server.state.Cluster;
import org.apache.ambari.server.state.Clusters;
import org.apache.ambari.server.state.Config;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.jdbc.support.JdbcUtils;
-import java.sql.SQLException;
-import java.util.Collections;
-import java.util.Map;
-import java.util.Set;
+import com.google.inject.Inject;
+import com.google.inject.Injector;
/**
* Upgrade catalog for version 2.1.1.
*/
public class UpgradeCatalog211 extends AbstractUpgradeCatalog {
+ private static final String HOST_COMPONENT_STATE_TABLE = "hostcomponentstate";
+ private static final String HOST_COMPONENT_STATE_ID_COLUMN = "id";
+ private static final String HOST_COMPONENT_STATE_INDEX = "idx_host_component_state";
+
+ /**
+ * Logger.
+ */
+ private static final Logger LOG = LoggerFactory.getLogger(UpgradeCatalog211.class);
+
@Inject
DaoUtils daoUtils;
@@ -79,6 +99,8 @@ public class UpgradeCatalog211 extends AbstractUpgradeCatalog {
*/
@Override
protected void executeDDLUpdates() throws AmbariException, SQLException {
+ // change out the PK on hostcomponentstate
+ executeHostComponentStateDDLUpdates();
}
/**
@@ -97,14 +119,14 @@ public class UpgradeCatalog211 extends AbstractUpgradeCatalog {
updateExistingConfigurations();
}
-
// ----- UpgradeCatalog211 --------------------------------------------
-
/**
- * Iterates over the set of clusters to call service-specific configuration update routines.
+ * Iterates over the set of clusters to call service-specific configuration
+ * update routines.
*
- * @throws AmbariException if an error occurs while updating the configurations
+ * @throws AmbariException
+ * if an error occurs while updating the configurations
*/
protected void updateExistingConfigurations() throws AmbariException {
AmbariManagementController ambariManagementController = injector.getInstance(AmbariManagementController.class);
@@ -131,11 +153,14 @@ public class UpgradeCatalog211 extends AbstractUpgradeCatalog {
* <p/>
* Performs the following updates:
* <ul>
- * <li>Rename <code>create_attributes_template</code> to <code>ad_create_attributes_template</code></li>
+ * <li>Rename <code>create_attributes_template</code> to
+ * <code>ad_create_attributes_template</code></li>
* </ul>
*
- * @param cluster the cluster
- * @throws AmbariException if an error occurs while updating the configurations
+ * @param cluster
+ * the cluster
+ * @throws AmbariException
+ * if an error occurs while updating the configurations
*/
protected void updateKerberosConfigurations(Cluster cluster) throws AmbariException {
Config config = cluster.getDesiredConfigByType("kerberos-env");
@@ -149,4 +174,103 @@ public class UpgradeCatalog211 extends AbstractUpgradeCatalog {
updateConfigurationPropertiesForCluster(cluster, "kerberos-env", updates, removes, true, false);
}
}
+
+ /**
+ * Perform the DDL updates required to add a new Primary Key ID column to the
+ * {@code hostcomponentstate} table. This will perform the following actions:
+ * <ul>
+ * <li>Add a new column to hostcomponentstate named id</li>
+ * <li>Populated id with an incrementing long, then make it non-NULL</li>
+ * <li>Drop the existing PK on hostcomponentstate</li>
+ * <li>Add a new surrogate PK on hostcomponentstate on the id column</li>
+ * <li>Add an index on hostcomponentstate for host_id, component_name,
+ * service_name, cluster_id</li>
+ * </ul>
+ *
+ * @throws AmbariException
+ * @throws SQLException
+ */
+ private void executeHostComponentStateDDLUpdates() throws AmbariException, SQLException {
+ // add the new column, nullable for now until we insert unique IDs
+ dbAccessor.addColumn(HOST_COMPONENT_STATE_TABLE,
+ new DBColumnInfo(HOST_COMPONENT_STATE_ID_COLUMN, Long.class, null, null, true));
+
+ // insert sequence values
+ AtomicLong id = new AtomicLong(1);
+ Statement statement = null;
+ ResultSet resultSet = null;
+ try {
+ statement = dbAccessor.getConnection().createStatement();
+ if (statement != null) {
+ String selectSQL = MessageFormat.format(
+ "SELECT cluster_id, service_name, component_name, host_id FROM {0}",
+ HOST_COMPONENT_STATE_TABLE);
+
+ resultSet = statement.executeQuery(selectSQL);
+ while (resultSet.next()) {
+ final Long clusterId = resultSet.getLong("cluster_id");
+ final String serviceName = resultSet.getString("service_name");
+ final String componentName = resultSet.getString("component_name");
+ final Long hostId = resultSet.getLong("host_id");
+
+ String updateSQL = MessageFormat.format(
+ "UPDATE {0} SET {1} = {2} WHERE cluster_id = {3} AND service_name = ''{4}'' AND component_name = ''{5}'' and host_id = {6}",
+ HOST_COMPONENT_STATE_TABLE, HOST_COMPONENT_STATE_ID_COLUMN, id.getAndIncrement(),
+ clusterId, serviceName, componentName, hostId);
+
+ dbAccessor.executeQuery(updateSQL);
+ }
+ }
+ } finally {
+ JdbcUtils.closeResultSet(resultSet);
+ JdbcUtils.closeStatement(statement);
+ }
+
+ // make the column NON NULL now
+ dbAccessor.alterColumn(HOST_COMPONENT_STATE_TABLE,
+ new DBColumnInfo(HOST_COMPONENT_STATE_ID_COLUMN, Long.class, null, null, false));
+
+ // drop the current PK
+ String primaryKeyConstraintName = null;
+ Configuration.DatabaseType databaseType = configuration.getDatabaseType();
+ switch (databaseType) {
+ case POSTGRES: {
+ primaryKeyConstraintName = "hostcomponentstate_pkey";
+ break;
+ }
+ case ORACLE:
+ case SQL_SERVER: {
+ // Oracle and SQL Server require us to lookup the PK name
+ primaryKeyConstraintName = dbAccessor.getPrimaryKeyConstraintName(
+ HOST_COMPONENT_STATE_TABLE);
+
+ break;
+ }
+ default:
+ break;
+ }
+
+ if (databaseType == DatabaseType.MYSQL) {
+ String mysqlDropQuery = MessageFormat.format("ALTER TABLE {0} DROP PRIMARY KEY",
+ HOST_COMPONENT_STATE_TABLE);
+
+ dbAccessor.executeQuery(mysqlDropQuery, true);
+ } else {
+ // warn if we can't find it
+ if (null == primaryKeyConstraintName) {
+ LOG.warn("Unable to determine the primary key constraint name for {}",
+ HOST_COMPONENT_STATE_TABLE);
+ } else {
+ dbAccessor.dropPKConstraint(HOST_COMPONENT_STATE_TABLE, primaryKeyConstraintName, true);
+ }
+ }
+
+ // create a new PK, matching the name of the constraint found in the SQL
+ // files
+ dbAccessor.addPKConstraint(HOST_COMPONENT_STATE_TABLE, "pk_hostcomponentstate", "id");
+
+ // create index, ensuring column order matches that of the SQL files
+ dbAccessor.createIndex(HOST_COMPONENT_STATE_INDEX, HOST_COMPONENT_STATE_TABLE, "host_id",
+ "component_name", "service_name", "cluster_id");
+ }
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/0862422c/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog220.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog220.java b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog220.java
index 8951e3c..4eb7a80 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog220.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog220.java
@@ -18,20 +18,13 @@
package org.apache.ambari.server.upgrade;
-import java.sql.ResultSet;
import java.sql.SQLException;
-import java.sql.Statement;
-import java.text.MessageFormat;
-import java.util.concurrent.atomic.AtomicLong;
import org.apache.ambari.server.AmbariException;
-import org.apache.ambari.server.configuration.Configuration;
-import org.apache.ambari.server.configuration.Configuration.DatabaseType;
import org.apache.ambari.server.orm.DBAccessor.DBColumnInfo;
import org.apache.ambari.server.orm.dao.DaoUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.springframework.jdbc.support.JdbcUtils;
import com.google.inject.Inject;
import com.google.inject.Injector;
@@ -43,9 +36,6 @@ import com.google.inject.Injector;
public class UpgradeCatalog220 extends AbstractUpgradeCatalog {
private static final String HOST_ROLE_COMMAND_TABLE = "host_role_command";
private static final String HOST_ID_COL = "host_id";
- private static final String HOST_COMPONENT_STATE_TABLE = "hostcomponentstate";
- private static final String HOST_COMPONENT_STATE_ID_COLUMN = "id";
- private static final String HOST_COMPONENT_STATE_INDEX = "idx_host_component_state";
@Inject
DaoUtils daoUtils;
@@ -93,11 +83,8 @@ public class UpgradeCatalog220 extends AbstractUpgradeCatalog {
*/
@Override
protected void executeDDLUpdates() throws AmbariException, SQLException {
- dbAccessor.alterColumn(HOST_ROLE_COMMAND_TABLE,
- new DBColumnInfo(HOST_ID_COL, Long.class, null, null, true));
- // change out the PK on hostcomponentstate
- executeHostComponentStateDDLUpdates();
+ dbAccessor.alterColumn(HOST_ROLE_COMMAND_TABLE, new DBColumnInfo(HOST_ID_COL, Long.class, null, null, true));
}
@Override
@@ -108,103 +95,6 @@ public class UpgradeCatalog220 extends AbstractUpgradeCatalog {
protected void executeDMLUpdates() throws AmbariException, SQLException {
}
- /**
- * Perform the DDL updates required to add a new Primary Key ID column to the
- * {@code hostcomponentstate} table. This will perform the following actions:
- * <ul>
- * <li>Add a new column to hostcomponentstate named id</li>
- * <li>Populated id with an incrementing long, then make it non-NULL</li>
- * <li>Drop the existing PK on hostcomponentstate</li>
- * <li>Add a new surrogate PK on hostcomponentstate on the id column</li>
- * <li>Add an index on hostcomponentstate for host_id, component_name, service_name, cluster_id</li>
- * </ul>
- *
- * @throws AmbariException
- * @throws SQLException
- */
- private void executeHostComponentStateDDLUpdates() throws AmbariException, SQLException {
- // add the new column, nullable for now until we insert unique IDs
- dbAccessor.addColumn(HOST_COMPONENT_STATE_TABLE,
- new DBColumnInfo(HOST_COMPONENT_STATE_ID_COLUMN, Long.class, null, null, true));
-
- // insert sequence values
- AtomicLong id = new AtomicLong(1);
- Statement statement = null;
- ResultSet resultSet = null;
- try {
- statement = dbAccessor.getConnection().createStatement();
- if (statement != null) {
- String selectSQL = MessageFormat.format(
- "SELECT cluster_id, service_name, component_name, host_id FROM {0}",
- HOST_COMPONENT_STATE_TABLE);
-
- resultSet = statement.executeQuery(selectSQL);
- while (resultSet.next()) {
- final Long clusterId = resultSet.getLong("cluster_id");
- final String serviceName = resultSet.getString("service_name");
- final String componentName = resultSet.getString("component_name");
- final Long hostId = resultSet.getLong("host_id");
-
- String updateSQL = MessageFormat.format(
- "UPDATE {0} SET {1} = {2} WHERE cluster_id = {3} AND service_name = ''{4}'' AND component_name = ''{5}'' and host_id = {6}",
- HOST_COMPONENT_STATE_TABLE, HOST_COMPONENT_STATE_ID_COLUMN, id.getAndIncrement(),
- clusterId, serviceName,
- componentName, hostId);
-
- dbAccessor.executeQuery(updateSQL);
- }
- }
- } finally {
- JdbcUtils.closeResultSet(resultSet);
- JdbcUtils.closeStatement(statement);
- }
-
- // make the column NON NULL now
- dbAccessor.alterColumn(HOST_COMPONENT_STATE_TABLE,
- new DBColumnInfo(HOST_COMPONENT_STATE_ID_COLUMN, Long.class, null, null, false));
-
- // drop the current PK
- String primaryKeyConstraintName = null;
- Configuration.DatabaseType databaseType = configuration.getDatabaseType();
- switch (databaseType) {
- case POSTGRES: {
- primaryKeyConstraintName = "hostcomponentstate_pkey";
- break;
- }
- case ORACLE:
- case SQL_SERVER: {
- // Oracle and SQL Server require us to lookup the PK name
- primaryKeyConstraintName = dbAccessor.getPrimaryKeyConstraintName(
- HOST_COMPONENT_STATE_TABLE);
-
- break;
- }
- default:
- break;
- }
-
- if (databaseType == DatabaseType.MYSQL) {
- String mysqlDropQuery = MessageFormat.format("ALTER TABLE {0} DROP PRIMARY KEY",
- HOST_COMPONENT_STATE_TABLE);
-
- dbAccessor.executeQuery(mysqlDropQuery, true);
- } else {
- // warn if we can't find it
- if (null == primaryKeyConstraintName) {
- LOG.warn("Unable to determine the primary key constraint name for {}",
- HOST_COMPONENT_STATE_TABLE);
- } else {
- dbAccessor.dropPKConstraint(HOST_COMPONENT_STATE_TABLE, primaryKeyConstraintName, true);
- }
- }
-
- // create a new PK, matching the name of the constraint found in the SQL files
- dbAccessor.addPKConstraint(HOST_COMPONENT_STATE_TABLE, "pk_hostcomponentstate", "id");
-
- // create index, ensuring column order matches that of the SQL files
- dbAccessor.createIndex(HOST_COMPONENT_STATE_INDEX, HOST_COMPONENT_STATE_TABLE, "host_id",
- "component_name", "service_name", "cluster_id");
- }
// ----- UpgradeCatalog ----------------------------------------------------