github-advanced-security[bot] commented on code in PR #16775: URL: https://github.com/apache/druid/pull/16775#discussion_r1687135614
########## processing/src/main/java/org/apache/druid/frame/processor/SuperSorter.java: ########## @@ -704,33 +782,68 @@ @GuardedBy("runWorkersLock") private void setTotalInputFrames(final long totalInputFrames) { + if (this.totalInputFrames != UNKNOWN_TOTAL) { + throw DruidException.defensive( + "Cannot set totalInputFrames twice (first[%s], second[%s])", + this.totalInputFrames, + totalInputFrames + ); + } + this.totalInputFrames = totalInputFrames; // Mark the progress tracker as trivially complete, if there is nothing to sort. if (totalInputFrames == 0) { superSorterProgressTracker.markTriviallyComplete(); } + } - // Set totalMergingLevels too - long totalMergersInLevel = totalInputFrames; + @GuardedBy("runWorkersLock") + private void setTotalMergingLevelsIfPossible() + { + if (totalMergingLevels != UNKNOWN_LEVEL + || totalInputFrames == UNKNOWN_TOTAL + || !outputPartitionsFuture.isDone()) { + return; + } + + if (levelZeroMergersRunSoFar == 0) { + // All frames fit in memory. + totalMergingLevels = 1; + superSorterProgressTracker.setTotalMergingLevels(1); + superSorterProgressTracker.setTotalMergersForLevel(0, getOutputPartitions().size()); + return; + } + + // Need to do a multi-level merge. Figure out how many levels. int level = 0; + long inputsForLevel = totalInputFrames; - while (totalMergersInLevel > maxChannelsPerProcessor) { - totalMergersInLevel = LongMath.divide(totalMergersInLevel, maxChannelsPerProcessor, RoundingMode.CEILING); + while (inputsForLevel > maxChannelsPerMerger) { Review Comment: ## Comparison of narrow type with wide type in loop condition Comparison between [expression](1) of type int and [expression](2) of wider type long. [Show more details](https://github.com/apache/druid/security/code-scanning/7581) -- 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: commits-unsubscr...@druid.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@druid.apache.org For additional commands, e-mail: commits-h...@druid.apache.org