[FLINK-38349][runtime] Address SpillingThread Zero-Division During Channel Merging Operations #27238
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What is the purpose of the change
This pull request addresses the issue detailed in FLINK-38349 which describes scenarios in which certain edge-case values for
maxFanInandchannelIDs.size()could result in floating-point errors that resulted in thrownArithmeticExceptionexceptions (specifically division by zero). This adds the appropriate safeguards to prevent these issues.The originating JIRA ticket provides detailed examples illustrating how the floating-point errors were reproduced. In summary, the issue occurs whenever the channel count (
channelIDs.size()) is greater than or equal to a power ofmaxFanIn:The overall change not only addresses the floating-point issues but also improves scaling calculation performance by 3-4x on average (see chart below).
Brief change log
SpillingThread.mergeChannelList()by replacing the previousMath.log()-based calculations, which could result in floating point errors, in favor of an iterative, exponential search.computeMergeScaleForChannelSize()function to encapsulate and document the updated scaling calculations.SpillingThreadTestfile with an associated, parameterizedtestMergeChannelListDivideByZeroSafetytest that was used to reproduce the original issue and was later adjusted to confirm the fix.Verifying this change
This change added tests and can be verified as follows:
SpillingThreadTest.testMergeChannelListDivideByZeroSafetywhich originally reproduced the issue by creating a series of parameterized tests founds within the originating JIRA ticket.Verifying Performance
In addition to these tests related to reproduction, I performed a series of manual tests to verify performance between the previous
Math.log()-based approach (prone to floating-point error) and the newer iterative, exponential approach.You can see the full gist here with all of the necessary code comparing the older and newer approaches (elected not to commit as it was purely for demonstration purposes).
Verifying Correctness
In addition to the above performance tests, I also performed a similar equivalence test comparing the generated results between the previous and new approaches to ensure parity (sans floating-point errors) for many of the common and edge case values presented earlier:
You can find a related gist containing these tests as well.
Does this pull request potentially affect one of the following parts:
@Public(Evolving): noDocumentation