AMBARI-21749. Remove DB consistency check for topology tables (magyari_sandor)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/5f6ce4ea Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/5f6ce4ea Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/5f6ce4ea Branch: refs/heads/branch-feature-logsearch-ui Commit: 5f6ce4ea53bcaaec35040c08600d606d7d194460 Parents: 1dba778 Author: Sandor Magyari <smagy...@hortonworks.com> Authored: Fri Aug 18 13:13:29 2017 +0200 Committer: Sandor Magyari <smagy...@hortonworks.com> Committed: Fri Aug 18 15:45:14 2017 +0200 ---------------------------------------------------------------------- .../checks/DatabaseConsistencyCheckHelper.java | 62 ------------------- .../server/topology/PersistedStateImpl.java | 23 +++---- .../DatabaseConsistencyCheckHelperTest.java | 63 -------------------- 3 files changed, 13 insertions(+), 135 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/5f6ce4ea/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 66baf8e..aae34ae 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 @@ -182,7 +182,6 @@ public class DatabaseConsistencyCheckHelper { checkForHostsWithoutState(); checkHostComponentStates(); checkServiceConfigs(); - checkTopologyTables(); checkForLargeTables(); LOG.info("******************************* Check database completed *******************************"); return checkResult; @@ -446,67 +445,6 @@ public class DatabaseConsistencyCheckHelper { } } - - /** - * This method checks that for each row in topology_request there is at least one row in topology_logical_request, - * topology_host_request, topology_host_task, topology_logical_task. - * */ - static void checkTopologyTables() { - LOG.info("Checking Topology tables"); - - String SELECT_REQUEST_COUNT_QUERY = "select count(tpr.id) from topology_request tpr"; - - String SELECT_JOINED_COUNT_QUERY = "select count(DISTINCT tpr.id) from topology_request tpr join " + - "topology_logical_request tlr on tpr.id = tlr.request_id"; - - String SELECT_HOST_REQUEST_COUNT_QUERY = "select count(thr.id) from topology_host_request thr"; - - String SELECT_HOST_JOINED_COUNT_QUERY = "select count(DISTINCT thr.id) from topology_host_request thr join " + - "topology_host_task tht on thr.id = tht.host_request_id join topology_logical_task " + - "tlt on tht.id = tlt.host_task_id"; - - Statement statement = null; - - if (connection == null) { - if (dbAccessor == null) { - dbAccessor = injector.getInstance(DBAccessor.class); - } - connection = dbAccessor.getConnection(); - } - - try { - statement = connection.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); - - int topologyRequestCount = runQuery(statement, SELECT_REQUEST_COUNT_QUERY); - int topologyRequestTablesJoinedCount = runQuery(statement, SELECT_JOINED_COUNT_QUERY); - - if (topologyRequestCount != topologyRequestTablesJoinedCount) { - error("Your topology request hierarchy is not complete for each row in topology_request should exist " + - "at least one row in topology_logical_request"); - } - - int topologyHostRequestCount = runQuery(statement, SELECT_HOST_REQUEST_COUNT_QUERY); - int topologyHostRequestTablesJoinedCount = runQuery(statement, SELECT_HOST_JOINED_COUNT_QUERY); - - if (topologyHostRequestCount != topologyHostRequestTablesJoinedCount) { - error("Your topology request hierarchy is not complete for each row in topology_host_request should exist " + - "at least one row in topology_host_task, topology_logical_task."); - } - - } catch (SQLException e) { - LOG.error("Exception occurred during topology request tables check: ", e); - } finally { - if (statement != null) { - try { - statement.close(); - } catch (SQLException e) { - LOG.error("Exception occurred during statement closing procedure: ", e); - } - } - } - - } - private static int runQuery(Statement statement, String query) { ResultSet rs = null; int result = 0; http://git-wip-us.apache.org/repos/asf/ambari/blob/5f6ce4ea/ambari-server/src/main/java/org/apache/ambari/server/topology/PersistedStateImpl.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/topology/PersistedStateImpl.java b/ambari-server/src/main/java/org/apache/ambari/server/topology/PersistedStateImpl.java index 0273564..12af131 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/topology/PersistedStateImpl.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/topology/PersistedStateImpl.java @@ -223,18 +223,21 @@ public class PersistedStateImpl implements PersistedState { } TopologyLogicalRequestEntity logicalRequestEntity = entity.getTopologyLogicalRequestEntity(); - Long logicalId = logicalRequestEntity.getId(); + if (logicalRequestEntity != null) { + try { + Long logicalId = logicalRequestEntity.getId(); - try { - //todo: fix initialization of ActionManager.requestCounter to account for logical requests - //todo: until this is fixed, increment the counter for every recovered logical request - //todo: this will cause gaps in the request id's after recovery - ambariContext.getNextRequestId(); - allRequests.get(clusterTopology).add(logicalRequestFactory.createRequest( - logicalId, replayedRequest, clusterTopology, logicalRequestEntity)); - } catch (AmbariException e) { - throw new RuntimeException("Failed to construct logical request during replay: " + e, e); + //todo: fix initialization of ActionManager.requestCounter to account for logical requests + //todo: until this is fixed, increment the counter for every recovered logical request + //todo: this will cause gaps in the request id's after recovery + ambariContext.getNextRequestId(); + allRequests.get(clusterTopology).add(logicalRequestFactory.createRequest( + logicalId, replayedRequest, clusterTopology, logicalRequestEntity)); + } catch (AmbariException e) { + throw new RuntimeException("Failed to construct logical request during replay: " + e, e); + } } + } return allRequests; http://git-wip-us.apache.org/repos/asf/ambari/blob/5f6ce4ea/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 9b00e43..ce7b783 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 @@ -144,69 +144,6 @@ public class DatabaseConsistencyCheckHelperTest { } @Test - public void testCheckTopologyTablesAreConsistent() throws Exception { - testCheckTopologyTablesConsistent(2); - Assert.assertFalse(DatabaseConsistencyCheckHelper.getLastCheckResult().isError()); - } - - @Test - public void testCheckTopologyTablesAreNotConsistent() throws Exception { - testCheckTopologyTablesConsistent(1); - Assert.assertTrue(DatabaseConsistencyCheckHelper.getLastCheckResult().isError()); - } - - private void testCheckTopologyTablesConsistent(int resultCount) throws Exception { - EasyMockSupport easyMockSupport = new EasyMockSupport(); - - final DBAccessor mockDBDbAccessor = easyMockSupport.createNiceMock(DBAccessor.class); - final Connection mockConnection = easyMockSupport.createNiceMock(Connection.class); - final ResultSet mockCountResultSet = easyMockSupport.createNiceMock(ResultSet.class); - final ResultSet mockJoinResultSet = 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(mockCountResultSet.next()).andReturn(true).once(); - expect(mockCountResultSet.getInt(1)).andReturn(2); - expect(mockJoinResultSet.next()).andReturn(true).once(); - expect(mockJoinResultSet.getInt(1)).andReturn(resultCount); - expect(mockStatement.executeQuery("select count(tpr.id) from topology_request tpr")).andReturn(mockCountResultSet); - expect(mockStatement.executeQuery("select count(DISTINCT tpr.id) from topology_request tpr join " + - "topology_logical_request tlr on tpr.id = tlr.request_id")).andReturn(mockJoinResultSet); - - expect(mockStatement.executeQuery("select count(thr.id) from topology_host_request thr")).andReturn(mockCountResultSet); - expect(mockStatement.executeQuery("select count(DISTINCT thr.id) from topology_host_request thr join " + - "topology_host_task tht on thr.id = tht.host_request_id join topology_logical_task " + - "tlt on tht.id = tlt.host_task_id")).andReturn(mockJoinResultSet); - - DatabaseConsistencyCheckHelper.setInjector(mockInjector); - DatabaseConsistencyCheckHelper.setConnection(mockConnection); - - easyMockSupport.replayAll(); - - - DatabaseConsistencyCheckHelper.checkTopologyTables(); - - easyMockSupport.verifyAll(); - - } - - @Test public void testCheckHostComponentStatesCountEqualsHostComponentsDesiredStates() throws Exception { EasyMockSupport easyMockSupport = new EasyMockSupport();