ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vbrodets...@apache.org
Subject ambari git commit: AMBARI-21843. Database consistency check fails after upgrade to ambari 2.6.0.(vbrodetskyi)
Date Tue, 29 Aug 2017 22:25:42 GMT
Repository: ambari
Updated Branches:
  refs/heads/branch-2.6 63989a2d6 -> 43432ae30


AMBARI-21843. Database consistency check fails after upgrade to ambari 2.6.0.(vbrodetskyi)


Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/43432ae3
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/43432ae3
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/43432ae3

Branch: refs/heads/branch-2.6
Commit: 43432ae30355765fbf982553d7360aa00d7534e1
Parents: 63989a2
Author: Vitaly Brodetskyi <vbrodetskyi@hortonworks.com>
Authored: Wed Aug 30 01:23:31 2017 +0300
Committer: Vitaly Brodetskyi <vbrodetskyi@hortonworks.com>
Committed: Wed Aug 30 01:23:31 2017 +0300

----------------------------------------------------------------------
 .../checks/DatabaseConsistencyCheckHelper.java  | 87 +++++---------------
 .../DatabaseConsistencyCheckHelperTest.java     | 56 ++-----------
 2 files changed, 29 insertions(+), 114 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/43432ae3/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 aa96875..f5a7203 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
@@ -187,7 +187,6 @@ public class DatabaseConsistencyCheckHelper {
       checkSchemaName();
       checkMySQLEngine();
       checkForConfigsNotMappedToService();
-      checkForNotMappedConfigsToCluster();
       checkForConfigsSelectedMoreThanOnce();
       checkForHostsWithoutState();
       checkHostComponentStatesCountEqualsHostComponentsDesiredStates();
@@ -244,49 +243,6 @@ public class DatabaseConsistencyCheckHelper {
     LOG.info("DB store version is compatible");
   }
 
-  static void checkForNotMappedConfigsToCluster() {
-    LOG.info("Checking for configs not mapped to any cluster");
-
-    String GET_NOT_MAPPED_CONFIGS_QUERY = "select type_name from clusterconfig where type_name
not in (select type_name from clusterconfigmapping)";
-    Set<String> nonSelectedConfigs = new HashSet<>();
-    ResultSet rs = null;
-    Statement statement = null;
-
-    ensureConnection();
-
-    try {
-      statement = connection.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
-      rs = statement.executeQuery(GET_NOT_MAPPED_CONFIGS_QUERY);
-      if (rs != null) {
-        while (rs.next()) {
-          nonSelectedConfigs.add(rs.getString("type_name"));
-        }
-      }
-      if (!nonSelectedConfigs.isEmpty()) {
-        warning("You have config(s): {} that is(are) not mapped (in clusterconfigmapping
table) to any cluster!",
-            nonSelectedConfigs);
-      }
-    } catch (SQLException e) {
-      LOG.error("Exception occurred during check for not mapped configs to cluster procedure:
", e);
-    } finally {
-      if (rs != null) {
-        try {
-          rs.close();
-        } catch (SQLException e) {
-          LOG.error("Exception occurred during result set closing procedure: ", e);
-        }
-      }
-
-      if (statement != null) {
-        try {
-          statement.close();
-        } catch (SQLException e) {
-          LOG.error("Exception occurred during statement closing procedure: ", e);
-        }
-      }
-    }
-  }
-
   /**
    * This method checks if ambari database has tables with too big size (according to limit).
    * First of all we are trying to get table size from schema information, but if it's not
possible,
@@ -373,7 +329,7 @@ public class DatabaseConsistencyCheckHelper {
             throw new SQLException();
           }
         } catch (SQLException ex) {
-          LOG.error(String.format("Failed to get %s row count: ", tableName), e);
+          error(String.format("Failed to get %s row count: ", tableName), e);
         }
       } finally {
         if (rs != null) {
@@ -397,7 +353,7 @@ public class DatabaseConsistencyCheckHelper {
   }
 
   /**
-  * This method checks if any config type in clusterconfigmapping table, has
+  * This method checks if any config type in clusterconfig table, has
   * more than one versions selected. If config version is selected(in selected column = 1),
   * it means that this version of config is actual. So, if any config type has more
   * than one selected version it's a bug and we are showing error message for user.
@@ -405,10 +361,10 @@ public class DatabaseConsistencyCheckHelper {
   static void checkForConfigsSelectedMoreThanOnce() {
     LOG.info("Checking for configs selected more than once");
 
-    String GET_CONFIGS_SELECTED_MORE_THAN_ONCE_QUERY = "select c.cluster_name, ccm.type_name
from clusterconfigmapping ccm " +
-            "join clusters c on ccm.cluster_id=c.cluster_id " +
-            "group by c.cluster_name, ccm.type_name " +
-            "having sum(selected) > 1";
+    String GET_CONFIGS_SELECTED_MORE_THAN_ONCE_QUERY = "select c.cluster_name, cc.type_name
from clusterconfig cc " +
+            "join clusters c on cc.cluster_id=c.cluster_id " +
+            "group by c.cluster_name, cc.type_name " +
+            "having sum(cc.selected) > 1";
     Multimap<String, String> clusterConfigTypeMap = HashMultimap.create();
     ResultSet rs = null;
     Statement statement = null;
@@ -424,13 +380,13 @@ public class DatabaseConsistencyCheckHelper {
         }
 
         for (String clusterName : clusterConfigTypeMap.keySet()) {
-          error("You have config(s), in cluster {}, that is(are) selected more than once
in clusterconfigmapping table: {}",
+          error("You have config(s), in cluster {}, that is(are) selected more than once
in clusterconfig table: {}",
                   clusterName ,StringUtils.join(clusterConfigTypeMap.get(clusterName), ","));
         }
       }
 
     } catch (SQLException e) {
-      LOG.error("Exception occurred during check for config selected more than ones procedure:
", e);
+      error("Exception occurred during check for config selected more than once procedure:
", e);
     } finally {
       if (rs != null) {
         try {
@@ -479,7 +435,7 @@ public class DatabaseConsistencyCheckHelper {
       }
 
     } catch (SQLException e) {
-      LOG.error("Exception occurred during check for host without state procedure: ", e);
+      error("Exception occurred during check for host without state procedure: ", e);
     } finally {
       if (rs != null) {
         try {
@@ -547,7 +503,7 @@ public class DatabaseConsistencyCheckHelper {
       }
 
     } catch (SQLException e) {
-      LOG.error("Exception occurred during topology request tables check: ", e);
+      error("Exception occurred during topology request tables check: ", e);
     } finally {
       if (statement != null) {
         try {
@@ -573,7 +529,7 @@ public class DatabaseConsistencyCheckHelper {
       }
 
     } catch (SQLException e) {
-      LOG.error("Exception occurred during topology request tables check: ", e);
+      error("Exception occurred during topology request tables check: ", e);
     } finally {
       if (rs != null) {
         try {
@@ -636,7 +592,7 @@ public class DatabaseConsistencyCheckHelper {
         error("Your host component states (hostcomponentstate table) count not equals host
component desired states (hostcomponentdesiredstate table) count!");
       }
     } catch (SQLException e) {
-      LOG.error("Exception occurred during check for same count of host component states
and host component desired states: ", e);
+      error("Exception occurred during check for same count of host component states and
host component desired states: ", e);
     } finally {
       if (rs != null) {
         try {
@@ -867,7 +823,7 @@ public class DatabaseConsistencyCheckHelper {
         }
       }
     } catch (SQLException e) {
-      LOG.error("Exception occurred during checking MySQL engine to be innodb: ", e);
+      error("Exception occurred during checking MySQL engine to be innodb: ", e);
     } finally {
       if (rs != null) {
         try {
@@ -884,7 +840,7 @@ public class DatabaseConsistencyCheckHelper {
   * 1) Check if we have services in cluster which doesn't have service config id(not available
in serviceconfig table).
   * 2) Check if service has no mapped configs to it's service config id.
   * 3) Check if service has all required configs mapped to it.
-  * 4) Check if service has config which is not selected(has no actual config version) in
clusterconfigmapping table.
+  * 4) Check if service has config which is not selected(has no actual config version) in
clusterconfig table.
   * If any issue was discovered, we are showing error message for user.
   * */
   static void checkServiceConfigs()  {
@@ -909,11 +865,10 @@ public class DatabaseConsistencyCheckHelper {
             "join serviceconfig sc on cs.service_name=sc.service_name and cs.cluster_id=sc.cluster_id
" +
             "join serviceconfigmapping scm on sc.service_config_id=scm.service_config_id
" +
             "join clusterconfig cc on scm.config_id=cc.config_id and cc.cluster_id=sc.cluster_id
" +
-            "join clusterconfigmapping ccm on cc.type_name=ccm.type_name and cc.version_tag=ccm.version_tag
and cc.cluster_id=ccm.cluster_id " +
-            "join clusters c on ccm.cluster_id=c.cluster_id " +
+            "join clusters c on cc.cluster_id=c.cluster_id " +
             "where sc.group_id is null and sc.service_config_id = (select max(service_config_id)
from serviceconfig sc2 where sc2.service_name=sc.service_name and sc2.cluster_id=sc.cluster_id)
" +
             "group by c.cluster_name, cs.service_name, cc.type_name " +
-            "having sum(ccm.selected) < 1";
+            "having sum(cc.selected) < 1";
     Multimap<String, String> clusterServiceMap = HashMultimap.create();
     Map<String, Map<String, String>>  clusterStackInfo = new HashMap<>();
     Map<String, Multimap<String, String>> clusterServiceVersionMap = new HashMap<>();
@@ -1086,8 +1041,8 @@ public class DatabaseConsistencyCheckHelper {
         }
       }
 
-      //getting services which has mapped configs which are not selected in clusterconfigmapping
-      LOG.info("Getting services which has mapped configs which are not selected in clusterconfigmapping");
+      //getting services which has mapped configs which are not selected in clusterconfig
+      LOG.info("Getting services which has mapped configs which are not selected in clusterconfig");
       rs = statement.executeQuery(GET_NOT_SELECTED_SERVICE_CONFIGS_QUERY);
       if (rs != null) {
         String serviceName = null, configType = null, clusterName = null;
@@ -1118,9 +1073,9 @@ public class DatabaseConsistencyCheckHelper {
         }
       }
     } catch (SQLException e) {
-      LOG.error("Exception occurred during complex service check procedure: ", e);
+      error("Exception occurred during complex service check procedure: ", e);
     } catch (AmbariException e) {
-      LOG.error("Exception occurred during complex service check procedure: ", e);
+      error("Exception occurred during complex service check procedure: ", e);
     } finally {
       if (rs != null) {
         try {
@@ -1236,7 +1191,7 @@ public class DatabaseConsistencyCheckHelper {
       }
     }
 
-    if (warnIfFound) {
+    if (warnIfFound && !configGroupMap.isEmpty()) {
       output.replace(output.lastIndexOf(","), output.length(), "]");
       warning("You have config groups present in the database with no " +
         "corresponding service found, {}. Run --auto-fix-database to fix " +

http://git-wip-us.apache.org/repos/asf/ambari/blob/43432ae3/ambari-server/src/test/java/org/apache/ambari/server/checks/DatabaseConsistencyCheckHelperTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/checks/DatabaseConsistencyCheckHelperTest.java
b/ambari-server/src/test/java/org/apache/ambari/server/checks/DatabaseConsistencyCheckHelperTest.java
index 5ce03a3..6c6c00f 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/checks/DatabaseConsistencyCheckHelperTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/checks/DatabaseConsistencyCheckHelperTest.java
@@ -64,45 +64,7 @@ import com.google.inject.Injector;
 
 public class DatabaseConsistencyCheckHelperTest {
 
-  @Test
-  public void testCheckForNotMappedConfigs() throws Exception {
-    EasyMockSupport easyMockSupport = new EasyMockSupport();
-
-    final DBAccessor mockDBDbAccessor = easyMockSupport.createNiceMock(DBAccessor.class);
-    final Connection mockConnection = easyMockSupport.createNiceMock(Connection.class);
-    final ResultSet mockResultSet = easyMockSupport.createNiceMock(ResultSet.class);
-    final Statement mockStatement = easyMockSupport.createNiceMock(Statement.class);
-
-    final StackManagerFactory mockStackManagerFactory = easyMockSupport.createNiceMock(StackManagerFactory.class);
-    final EntityManager mockEntityManager = easyMockSupport.createNiceMock(EntityManager.class);
-    final Clusters mockClusters = easyMockSupport.createNiceMock(Clusters.class);
-    final OsFamily mockOSFamily = easyMockSupport.createNiceMock(OsFamily.class);
-    final Injector mockInjector = Guice.createInjector(new AbstractModule() {
-      @Override
-      protected void configure() {
 
-        bind(StackManagerFactory.class).toInstance(mockStackManagerFactory);
-        bind(EntityManager.class).toInstance(mockEntityManager);
-        bind(DBAccessor.class).toInstance(mockDBDbAccessor);
-        bind(Clusters.class).toInstance(mockClusters);
-        bind(OsFamily.class).toInstance(mockOSFamily);
-      }
-    });
-
-
-
-    expect(mockConnection.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE)).andReturn(mockStatement);
-    expect(mockStatement.executeQuery("select type_name from clusterconfig where type_name
not in (select type_name from clusterconfigmapping)")).andReturn(mockResultSet);
-
-    DatabaseConsistencyCheckHelper.setInjector(mockInjector);
-    DatabaseConsistencyCheckHelper.setConnection(mockConnection);
-
-    easyMockSupport.replayAll();
-
-    DatabaseConsistencyCheckHelper.checkForNotMappedConfigsToCluster();
-
-    easyMockSupport.verifyAll();
-  }
 
   @Test
   public void testCheckForConfigsSelectedMoreThanOnce() throws Exception {
@@ -130,10 +92,10 @@ public class DatabaseConsistencyCheckHelperTest {
     });
 
     expect(mockConnection.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE)).andReturn(mockStatement);
-    expect(mockStatement.executeQuery("select c.cluster_name, ccm.type_name from clusterconfigmapping
ccm " +
-            "join clusters c on ccm.cluster_id=c.cluster_id " +
-            "group by c.cluster_name, ccm.type_name " +
-            "having sum(selected) > 1")).andReturn(mockResultSet);
+    expect(mockStatement.executeQuery("select c.cluster_name, cc.type_name from clusterconfig
cc " +
+            "join clusters c on cc.cluster_id=c.cluster_id " +
+            "group by c.cluster_name, cc.type_name " +
+            "having sum(cc.selected) > 1")).andReturn(mockResultSet);
 
 
 
@@ -360,11 +322,10 @@ public class DatabaseConsistencyCheckHelperTest {
             "join serviceconfig sc on cs.service_name=sc.service_name and cs.cluster_id=sc.cluster_id
" +
             "join serviceconfigmapping scm on sc.service_config_id=scm.service_config_id
" +
             "join clusterconfig cc on scm.config_id=cc.config_id and cc.cluster_id=sc.cluster_id
" +
-            "join clusterconfigmapping ccm on cc.type_name=ccm.type_name and cc.version_tag=ccm.version_tag
and cc.cluster_id=ccm.cluster_id " +
-            "join clusters c on ccm.cluster_id=c.cluster_id " +
+            "join clusters c on cc.cluster_id=c.cluster_id " +
             "where sc.group_id is null and sc.service_config_id = (select max(service_config_id)
from serviceconfig sc2 where sc2.service_name=sc.service_name and sc2.cluster_id=sc.cluster_id)
" +
             "group by c.cluster_name, cs.service_name, cc.type_name " +
-            "having sum(ccm.selected) < 1")).andReturn(mockResultSet);
+            "having sum(cc.selected) < 1")).andReturn(mockResultSet);
 
     DatabaseConsistencyCheckHelper.setInjector(mockInjector);
     DatabaseConsistencyCheckHelper.setConnection(mockConnection);
@@ -561,11 +522,10 @@ public class DatabaseConsistencyCheckHelperTest {
         "join serviceconfig sc on cs.service_name=sc.service_name and cs.cluster_id=sc.cluster_id
" +
         "join serviceconfigmapping scm on sc.service_config_id=scm.service_config_id " +
         "join clusterconfig cc on scm.config_id=cc.config_id and cc.cluster_id=sc.cluster_id
" +
-        "join clusterconfigmapping ccm on cc.type_name=ccm.type_name and cc.version_tag=ccm.version_tag
and cc.cluster_id=ccm.cluster_id " +
-        "join clusters c on ccm.cluster_id=c.cluster_id " +
+        "join clusters c on cc.cluster_id=c.cluster_id " +
         "where sc.group_id is null and sc.service_config_id = (select max(service_config_id)
from serviceconfig sc2 where sc2.service_name=sc.service_name and sc2.cluster_id=sc.cluster_id)
" +
         "group by c.cluster_name, cs.service_name, cc.type_name " +
-        "having sum(ccm.selected) < 1")).andReturn(mockResultSet);
+        "having sum(cc.selected) < 1")).andReturn(mockResultSet);
 
     DatabaseConsistencyCheckHelper.setInjector(mockInjector);
     DatabaseConsistencyCheckHelper.setConnection(mockConnection);


Mime
View raw message