ArafatKhan2198 commented on code in PR #10162:
URL: https://github.com/apache/ozone/pull/10162#discussion_r3188161352
##########
hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/persistence/ContainerHealthSchemaManager.java:
##########
@@ -395,6 +396,82 @@ public void clearAllUnhealthyContainerRecords() {
}
}
+ /**
+ * Returns a streaming cursor over unhealthy container records for a given
state.
+ * Caller MUST close the cursor.
+ *
+ * Generated SQL example (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
+ *
+ * @param state filter by state (required)
+ * @param limit max records to return, -1 = unlimited
+ * @param prevKey previous container ID to skip, for cursor-based pagination
+ * @return Cursor returning UnhealthyContainersRecord
+ */
+ /**
+ * Get the total count of unhealthy containers for a given state.
+ *
+ * @param state The container health state to filter by
+ * @param limit Maximum number of records to count (-1 for unlimited)
+ * @param prevKey Container ID offset for cursor-based pagination
+ * @return Total count of matching containers
+ */
+ public long getUnhealthyContainersCount(
+ UnHealthyContainerStates state, int limit, long prevKey) {
+ DSLContext dslContext = containerSchemaDefinition.getDSLContext();
+
+ Condition whereCondition =
UNHEALTHY_CONTAINERS.CONTAINER_STATE.eq(state.toString());
+
+ if (prevKey > 0) {
+ whereCondition =
whereCondition.and(UNHEALTHY_CONTAINERS.CONTAINER_ID.gt(prevKey));
+ }
+
+ long totalCount = dslContext.selectCount()
+ .from(UNHEALTHY_CONTAINERS)
+ .where(whereCondition)
+ .fetchOne(0, long.class);
+
+ // If limit is set and less than total, return the limit as estimated total
+ if (limit > 0 && limit < totalCount) {
+ return limit;
+ }
+
+ return totalCount;
+ }
+
+ public Cursor<UnhealthyContainersRecord> getUnhealthyContainersCursor(
+ UnHealthyContainerStates state, int limit, long prevKey) {
+ DSLContext dslContext = containerSchemaDefinition.getDSLContext();
+ SelectQuery<UnhealthyContainersRecord> query =
dslContext.selectFrom(UNHEALTHY_CONTAINERS).getQuery();
+
+ // WHERE container_state = ?
+
query.addConditions(UNHEALTHY_CONTAINERS.CONTAINER_STATE.eq(state.toString()));
+
+ if (prevKey > 0) {
+ // AND container_id > ? (cursor-based pagination)
+ query.addConditions(UNHEALTHY_CONTAINERS.CONTAINER_ID.gt(prevKey));
+ }
+
+ // ORDER BY container_id ASC — matches composite index (state,
container_id),
+ // so Derby walks it in order with no sort step.
+ query.addOrderBy(UNHEALTHY_CONTAINERS.CONTAINER_ID.asc());
+
+ if (limit > 0) {
+ query.addLimit(limit);
+ }
+
+ // Controls how many rows Derby returns per JDBC round-trip.
+ // Default is 10,000 rows.
+ query.fetchSize(10000);
Review Comment:
**`fetchSize(10000)` hardcoded** Fixed. Now reads from
`ozone.recon.unhealthy.container.fetch.size` (default 10,000) wired in
`ContainerHealthSchemaManager` constructor via `OzoneConfiguration`.
--
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]