[Dataflow Streaming] Prepare BoundedQueueExecutor for MultiKey bundles#38592
[Dataflow Streaming] Prepare BoundedQueueExecutor for MultiKey bundles#38592arunpandianp wants to merge 1 commit into
Conversation
|
R: @scwhittle |
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request prepares the BoundedQueueExecutor for multi-key bundles by updating the work execution lifecycle. By introducing a WorkResult object, the system can now accurately track and decrement resource budgets (items and bytes) after work execution. The changes include refactoring existing interfaces to support this return type, improving error handling via a new utility class, and ensuring that resource budgets are correctly reclaimed even in the event of task submission failures. Highlights
New Features🧠 You can now enable Memory (public preview) to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. Footnotes
|
|
Stopping reviewer notifications for this pull request: review requested by someone other than the bot, ceding control. If you'd like to restart, comment |
There was a problem hiding this comment.
Code Review
This pull request refactors the streaming worker's execution logic by introducing a WorkResult class to track processed items and bytes. ExecutableWork is updated to return this result, and BoundedQueueExecutor is modified to manage resource budgets using WorkResult instead of raw byte counts. Additionally, an ExceptionUtils utility is added for standardized exception propagation. A critical review comment identifies a potential resource leak in BoundedQueueExecutor where the executeMonitorHeld method for ExecutableWork lacks error handling for task submission and execution failures, which could lead to permanent capacity leaks in the JVM if not addressed.
| executor.execute( | ||
| () -> { | ||
| // Any execution exception thrown by work.run() propagates uncaught, triggering | ||
| // the default JVM UncaughtExceptionHandler which immediately crashes/terminates | ||
| // the JVM. Since the process exits immediately, reclaiming resource budgets in | ||
| // this JVM is unnecessary. Furthermore, since a failed execution does not return | ||
| // a WorkResult, we do not have a good/accurate fallback value to decrement. | ||
| WorkResult result = work.run(); | ||
| decrementCounters(result); | ||
| }); |
There was a problem hiding this comment.
The executeMonitorHeld method for ExecutableWork lacks error handling for task submission and execution failures, which can lead to resource leaks in elementsOutstanding and bytesOutstanding.
- If
executor.execute()throws aRejectedExecutionException(e.g., during worker shutdown), the counters incremented just before will never be decremented, leading to a permanent capacity leak in the JVM. - If
work.run()throws an exception and the JVM does not immediately terminate (e.g., if the exception is caught by the thread pool's uncaught exception handler but the process continues), the counters will also leak.
This implementation should be made consistent with the Runnable version of executeMonitorHeld (lines 248-272), which correctly handles these scenarios. Even if a JVM crash is expected on work failure, providing a defensive decrement (using the initial workBytes as a fallback) is safer.
try {
executor.execute(
() -> {
WorkResult result = null;
try {
result = work.run();
} finally {
// Any execution exception thrown by work.run() propagates uncaught, triggering
// the default JVM UncaughtExceptionHandler which immediately crashes/terminates
// the JVM. Since the process exits immediately, reclaiming resource budgets in
// this JVM is unnecessary. Furthermore, since a failed execution does not return
// a WorkResult, we fallback to decrementing the initial budget to prevent
// resource leaks in case the JVM does not crash.
decrementCounters(result != null ? result : WorkResult.create(1, workBytes));
}
});
} catch (Throwable e) {
// If the execute() call threw an exception, decrement counters here.
decrementCounters(WorkResult.create(1, workBytes));
throw ExceptionUtils.propagate(e);
}|
Changing a few things, not ready for review. |
ExecutableWork.run()now returns aWorkResultwhich informs BoundedQueueExecutor how many items and bytes to decrement from the budgets. In future, an executing work may pull in more work from BoundedQueueExecutor and execute them in the same bundle. When that happens the returned WorkResult will be the sum of all Work executed in the bundle.