ArafatKhan2198 commented on code in PR #9994:
URL: https://github.com/apache/ozone/pull/9994#discussion_r3121806683
##########
hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/persistence/ContainerHealthSchemaManager.java:
##########
@@ -381,6 +382,73 @@ public List<UnhealthyContainerRecord>
getUnhealthyContainers(
}
}
+ /**
+ * Returns a streaming cursor over unhealthy container records.
+ * Caller MUST close the cursor.
+ *
+ * Final Complete Query Examples:
+ * Example 1: Export 50,000 MISSING containers, starting after container ID
12345
+ *
+ * SELECT * FROM unhealthy_containers
+ * WHERE container_state = 'MISSING'
+ * AND container_id > 12345
+ * ORDER BY container_id ASC
+ * LIMIT 50000
+ * JDBC will fetch 10,000 rows at a time (5 batches total)
+ *
+ * Example 2: Export all 100,000 containers (all states), no pagination
+ *
+ * SELECT * FROM unhealthy_containers
+ * ORDER BY container_state ASC, container_id ASC
+ * LIMIT 100000
+ * JDBC will fetch 10,000 rows at a time (10 batches total)
+ *
+ * @param state filter by state, or null for all states
+ * @param limit max records to return, 0 = unlimited
+ * @param prevKey previous container ID to skip, for pagination
+ * @return Cursor returning UnhealthyContainersRecord
+ */
+ public Cursor<UnhealthyContainersRecord> getUnhealthyContainersCursor(
+ UnHealthyContainerStates state, int limit, long prevKey) {
+ DSLContext dslContext = containerSchemaDefinition.getDSLContext();
+
+ // In plain SQL: SELECT * FROM unhealthy_containers
+ org.jooq.SelectQuery<UnhealthyContainersRecord> query =
dslContext.selectFrom(UNHEALTHY_CONTAINERS).getQuery();
+
+ if (state != null) {
+ // Filtering by ONE specific state (e.g., state = "MISSING")
+ // WHERE container_state = 'MISSING'
+
query.addConditions(UNHEALTHY_CONTAINERS.CONTAINER_STATE.eq(state.toString()));
+ if (prevKey > 0) {
+ // AND container_id > 12345
+ query.addConditions(UNHEALTHY_CONTAINERS.CONTAINER_ID.gt(prevKey));
+ }
+ // ORDER BY container_id ASC
+ query.addOrderBy(UNHEALTHY_CONTAINERS.CONTAINER_ID.asc());
+ } else {
+ // Exporting ALL states (state = null)
+ if (prevKey > 0) {
+ // WHERE container_id > 12345
+ query.addConditions(UNHEALTHY_CONTAINERS.CONTAINER_ID.gt(prevKey));
+ }
+ // ORDER BY container_state ASC, container_id ASC
+ query.addOrderBy(
+ UNHEALTHY_CONTAINERS.CONTAINER_STATE.asc(),
+ UNHEALTHY_CONTAINERS.CONTAINER_ID.asc()
+ );
Review Comment:
Thanks for pointing this out!
Looking at the UI, the state parameter is always provided since the export
is always tab-scoped. The all-states path is never used by the frontend and
mixing all five states into one paginated export with only container_id as the
cursor key is architecturally broken
Hence I'm removing the multi-state support entirely and making state a
required parameter. This also eliminates the pagination bug you flagged.
--
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]