aryangupta1998 commented on code in PR #8409: URL: https://github.com/apache/ozone/pull/8409#discussion_r2078000650
########## hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/debug/logs/container/utils/ContainerDatanodeDatabase.java: ########## @@ -541,5 +541,69 @@ private List<DatanodeContainerInfo> getContainerLogData(Long containerID, Connec return logEntries; } + + private void createIdxContainerlogContainerId(Connection conn) throws SQLException { + String sql = SQLDBConstants.CREATE_CONTAINER_ID_INDEX; + try (Statement stmt = conn.createStatement()) { + stmt.execute(sql); + } + } + + public void findDuplicateOpenContainer() throws SQLException { + String sql = SQLDBConstants.SELECT_DISTINCT_CONTAINER_IDS_QUERY; + + try (Connection connection = getConnection()) { + + createIdxContainerlogContainerId(connection); + + try (PreparedStatement statement = connection.prepareStatement(sql); + ResultSet resultSet = statement.executeQuery()) { + int count = 0; + + while (resultSet.next()) { + Long containerID = resultSet.getLong("container_id"); + List<DatanodeContainerInfo> logEntries = getContainerLogDataFoOpen(containerID, connection); Review Comment: getContainerLogDataFoOpen -> getContainerLogDataForOpen/getContainerLogDataForOpenContainers ########## hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/debug/logs/container/utils/ContainerDatanodeDatabase.java: ########## @@ -541,5 +541,69 @@ private List<DatanodeContainerInfo> getContainerLogData(Long containerID, Connec return logEntries; } + + private void createIdxContainerlogContainerId(Connection conn) throws SQLException { + String sql = SQLDBConstants.CREATE_CONTAINER_ID_INDEX; + try (Statement stmt = conn.createStatement()) { + stmt.execute(sql); + } + } + + public void findDuplicateOpenContainer() throws SQLException { + String sql = SQLDBConstants.SELECT_DISTINCT_CONTAINER_IDS_QUERY; + + try (Connection connection = getConnection()) { + + createIdxContainerlogContainerId(connection); + + try (PreparedStatement statement = connection.prepareStatement(sql); + ResultSet resultSet = statement.executeQuery()) { + int count = 0; + + while (resultSet.next()) { + Long containerID = resultSet.getLong("container_id"); + List<DatanodeContainerInfo> logEntries = getContainerLogDataFoOpen(containerID, connection); + boolean hasIssue = checkForMultipleOpenStates(logEntries); + if (hasIssue) { + int openStateCount = (int) logEntries.stream() + .filter(entry -> "OPEN".equalsIgnoreCase(entry.getState())) + .count(); + count++; + out.println("Container ID: " + containerID + " - OPEN state count: " + openStateCount); + } + } + + out.println("Total containers that might have duplicate OPEN state : " + count); + + } + } catch (SQLException e) { + throw new SQLException("Error while retrieving containers." + e.getMessage(), e); + } catch (Exception e) { + throw new RuntimeException("Unexpected error: " + e); + } + } + + private List<DatanodeContainerInfo> getContainerLogDataFoOpen(Long containerID, Connection connection) Review Comment: Same here -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: issues-unsubscr...@ozone.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@ozone.apache.org For additional commands, e-mail: issues-h...@ozone.apache.org