umesh9794 commented on code in PR #10549:
URL: https://github.com/apache/ozone/pull/10549#discussion_r3451509361
##########
hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/persistence/ContainerHealthSchemaManager.java:
##########
@@ -205,28 +223,76 @@ public void replaceUnhealthyContainerRecordsAtomically(
private int deleteScmStatesForContainers(DSLContext dslContext,
List<Long> containerIds) {
+
+ // Sort and de-duplicate so contiguous runs are detectable regardless of
the
+ // order in which the caller supplied the ids.
+ List<Long> sortedIds = containerIds.stream()
+ .distinct()
+ .sorted()
+ .collect(Collectors.toList());
+
int totalDeleted = 0;
+ List<Long> inClauseBatch = new ArrayList<>(MAX_IN_CLAUSE_CHUNK_SIZE);
+
+ int i = 0;
+ while (i < sortedIds.size()) {
+ int runStart = i;
+ while (i + 1 < sortedIds.size()
+ && sortedIds.get(i + 1) == sortedIds.get(i) + 1) {
+ i++;
+ }
- for (int from = 0; from < containerIds.size(); from +=
MAX_IN_CLAUSE_CHUNK_SIZE) {
- int to = Math.min(from + MAX_IN_CLAUSE_CHUNK_SIZE, containerIds.size());
- List<Long> chunk = containerIds.subList(from, to);
-
- int deleted = dslContext.deleteFrom(UNHEALTHY_CONTAINERS)
- .where(UNHEALTHY_CONTAINERS.CONTAINER_ID.in(chunk))
- .and(UNHEALTHY_CONTAINERS.CONTAINER_STATE.in(
- UnHealthyContainerStates.MISSING.toString(),
- UnHealthyContainerStates.EMPTY_MISSING.toString(),
- UnHealthyContainerStates.UNDER_REPLICATED.toString(),
- UnHealthyContainerStates.OVER_REPLICATED.toString(),
- UnHealthyContainerStates.MIS_REPLICATED.toString(),
- UnHealthyContainerStates.NEGATIVE_SIZE.toString(),
- UnHealthyContainerStates.REPLICA_MISMATCH.toString()))
- .execute();
- totalDeleted += deleted;
+ if (i - runStart + 1 >= MIN_RANGE_DELETE_RUN) {
+ // Long contiguous run: a single constant-size BETWEEN removes the
whole
+ // range without straining Derby's per-statement bytecode budget.
+ totalDeleted += deleteScmStatesByRange(dslContext,
+ sortedIds.get(runStart), sortedIds.get(i));
Review Comment:
> Using `BETWEEN` instead of `IN` for contiguous range of IDs is a good idea.
>
> But I don't think the current change has much effect on production
behavior, a range of 1000+ "unhealthy" containers in Recon is not real life
scenario. So it adds complexity without benefit.
>
> We should apply this logic for shorter ranges, without executing too many
small statements. For that, we need to find the threshold (number of container
IDs) over which `BETWEEN n AND n+k OR` yields shorter code than the
corresponding `IN` clause. Any number of IDs beyond that is a win.
@adoroszlai I have applied the changes, please take a look. Thanks!
--
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]