sreejasahithi commented on code in PR #8282:
URL: https://github.com/apache/ozone/pull/8282#discussion_r2044839581
##########
hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/containerlog/parser/ContainerDatanodeDatabase.java:
##########
@@ -233,5 +238,65 @@ private void dropTable(String tableName, Statement stmt)
throws SQLException {
stmt.executeUpdate(dropTableSQL);
}
+ private void createContainerLogIndex(Statement stmt) throws SQLException {
+ String createIndexSQL = queries.get("CREATE_INDEX_LATEST_STATE");
+ stmt.execute(createIndexSQL);
+ }
+
+ /**
+ * Lists containers filtered by the specified state and writes their details
to a file.
+ * <p>
+ * The output includes timestamp, datanode ID, container ID, BCSID, error
message, and index value,
+ * written in a human-readable table format to a file named {@code
<state>_containers_by_state.txt}.
+ *
+ * @param state the container state to filter by (e.g., "OPEN", "CLOSED")
+ */
+
+ public void listContainersByState(String state) throws SQLException {
+ int count = 0;
+ String query = queries.get("SELECT_LATEST_CONTAINER_LOGS_BY_STATE");
+
+ Path outputPath = Paths.get(state + "_containers_by_state.txt");
+
+ try (Connection connection = getConnection();
+ Statement stmt = connection.createStatement();
+ BufferedWriter writer = Files.newBufferedWriter(outputPath,
StandardCharsets.UTF_8)) {
+
+ createContainerLogIndex(stmt);
+
+ try (PreparedStatement pstmt = connection.prepareStatement(query)) {
+ pstmt.setString(1, state);
+ try (ResultSet rs = pstmt.executeQuery()) {
+ writer.write(String.format("%-25s | %-35s | %-15s | %-15s | %-40s |
%-12s%n",
+ "Timestamp", "Datanode ID", "Container ID", "BCSID", "Message",
"Index Value"));
+
writer.write("-------------------------------------------------------------------------------------"
+
+
"---------------------------------------------------------------------------------------\n");
+
+ while (rs.next()) {
+ String timestamp = rs.getString("timestamp");
+ String datanodeId = rs.getString("datanode_id");
+ long containerId = rs.getLong("container_id");
+ String latestState = rs.getString("latest_state");
+ long latestBcsid = rs.getLong("latest_bcsid");
+ String errorMessage = rs.getString("error_message");
+ int indexValue = rs.getInt("index_value");
+ count++;
+
+ writer.write(String.format("%-25s | %-15s | %-15d | %-15d | %-40s
| %-12d%n",
+ timestamp, datanodeId, containerId, latestBcsid, errorMessage,
indexValue));
Review Comment:
it was not intended , Thanks for identifying.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]