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-18309. Add check to DB conistency checker for duplicate hostcomponentstate.(vbrodetskyi)
Date Wed, 07 Sep 2016 22:37:44 GMT
Repository: ambari
Updated Branches:
  refs/heads/trunk 4d285cddd -> 6180afee4


AMBARI-18309. Add check to DB conistency checker for duplicate hostcomponentstate.(vbrodetskyi)


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

Branch: refs/heads/trunk
Commit: 6180afee4680cba15fbfcd0d0e7d15cdbb3b1852
Parents: 4d285cd
Author: Vitaly Brodetskyi <vbrodetskyi@hortonworks.com>
Authored: Thu Sep 8 01:36:57 2016 +0300
Committer: Vitaly Brodetskyi <vbrodetskyi@hortonworks.com>
Committed: Thu Sep 8 01:36:57 2016 +0300

----------------------------------------------------------------------
 .../checks/DatabaseConsistencyCheckHelper.java  | 20 +++++++++++++++++++-
 .../checks/DatabaseConsistencyChecker.java      |  2 +-
 .../DatabaseConsistencyCheckHelperTest.java     |  6 +++---
 3 files changed, 23 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/6180afee/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 f302b8b..7403dba 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
@@ -318,16 +318,21 @@ 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
   * showing error for user.
+  *
+  * One more, we are checking if all components has only one host
+  * component state. If some component has more, it can cause issues
   * */
-  public static void checkHostComponentStatesCountEqualsHostComponentsDesiredStates() {
+  public static void checkHostComponentStates() {
     LOG.info("Checking host component states count equals host component desired states count");
 
     String GET_HOST_COMPONENT_STATE_COUNT_QUERY = "select count(*) from hostcomponentstate";
     String GET_HOST_COMPONENT_DESIRED_STATE_COUNT_QUERY = "select count(*) from hostcomponentdesiredstate";
     String GET_MERGED_TABLE_ROW_COUNT_QUERY = "select count(*) FROM hostcomponentstate hcs
" +
             "JOIN hostcomponentdesiredstate hcds ON hcs.service_name=hcds.service_name AND
hcs.component_name=hcds.component_name AND hcs.host_id=hcds.host_id";
+    String GET_HOST_COMPONENT_STATE_DUPLICATES_QUERY = "select component_name, host_id from
hostcomponentstate group by component_name, host_id having count(component_name) > 1";
     int hostComponentStateCount = 0;
     int hostComponentDesiredStateCount = 0;
+    Map<String, String> hostComponentStateDuplicates = new HashMap<>();
     int mergedCount = 0;
     ResultSet rs = null;
     Statement statement = null;
@@ -368,6 +373,19 @@ public class DatabaseConsistencyCheckHelper {
         errorAvailable = true;
       }
 
+
+      rs = statement.executeQuery(GET_HOST_COMPONENT_STATE_DUPLICATES_QUERY);
+      if (rs != null) {
+        while (rs.next()) {
+          hostComponentStateDuplicates.put(rs.getString("component_name"), rs.getString("host_id"));
+        }
+      }
+
+      for (Map.Entry<String, String> component : hostComponentStateDuplicates.entrySet())
{
+        LOG.error("Component {} on host with id {}, has more than one host component state
(hostcomponentstate table)!", component.getKey(), component.getValue());
+        errorAvailable = true;
+      }
+
     } catch (SQLException e) {
       LOG.error("Exception occurred during check for same count of host component states
and host component desired states: ", e);
     } finally {

http://git-wip-us.apache.org/repos/asf/ambari/blob/6180afee/ambari-server/src/main/java/org/apache/ambari/server/checks/DatabaseConsistencyChecker.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/checks/DatabaseConsistencyChecker.java
b/ambari-server/src/main/java/org/apache/ambari/server/checks/DatabaseConsistencyChecker.java
index 535d74f..89987fe 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/checks/DatabaseConsistencyChecker.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/checks/DatabaseConsistencyChecker.java
@@ -110,7 +110,7 @@ public class DatabaseConsistencyChecker {
 
       DatabaseConsistencyCheckHelper.checkForHostsWithoutState();
 
-      DatabaseConsistencyCheckHelper.checkHostComponentStatesCountEqualsHostComponentsDesiredStates();
+      DatabaseConsistencyCheckHelper.checkHostComponentStates();
 
       DatabaseConsistencyCheckHelper.checkServiceConfigs();
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/6180afee/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 4663310..bce4b08 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
@@ -19,6 +19,7 @@ package org.apache.ambari.server.checks;
 
 
 import javax.persistence.EntityManager;
+import junit.framework.Assert;
 import static org.easymock.EasyMock.expect;
 
 import java.sql.Connection;
@@ -27,7 +28,6 @@ import java.sql.Statement;
 import java.util.HashMap;
 import java.util.Map;
 
-import junit.framework.Assert;
 import org.apache.ambari.server.api.services.AmbariMetaInfo;
 import org.apache.ambari.server.orm.DBAccessor;
 import org.apache.ambari.server.stack.StackManagerFactory;
@@ -35,7 +35,6 @@ import org.apache.ambari.server.state.Clusters;
 import org.apache.ambari.server.state.ServiceInfo;
 import org.apache.ambari.server.state.stack.OsFamily;
 import org.easymock.EasyMockSupport;
-import org.junit.Ignore;
 import org.junit.Test;
 
 import com.google.inject.AbstractModule;
@@ -203,6 +202,7 @@ public class DatabaseConsistencyCheckHelperTest {
     expect(mockStatement.executeQuery("select count(*) FROM hostcomponentstate hcs " +
             "JOIN hostcomponentdesiredstate hcds ON hcs.service_name=hcds.service_name AND
" +
             "hcs.component_name=hcds.component_name AND hcs.host_id=hcds.host_id")).andReturn(mockResultSet);
+    expect(mockStatement.executeQuery("select component_name, host_id from hostcomponentstate
group by component_name, host_id having count(component_name) > 1")).andReturn(mockResultSet);
 
     DatabaseConsistencyCheckHelper.setInjector(mockInjector);
     DatabaseConsistencyCheckHelper.setConnection(mockConnection);
@@ -210,7 +210,7 @@ public class DatabaseConsistencyCheckHelperTest {
     easyMockSupport.replayAll();
 
 
-    DatabaseConsistencyCheckHelper.checkHostComponentStatesCountEqualsHostComponentsDesiredStates();
+    DatabaseConsistencyCheckHelper.checkHostComponentStates();
 
     easyMockSupport.verifyAll();
   }


Mime
View raw message