Skip to content

[Dataflow Streaming] Prepare BoundedQueueExecutor for MultiKey bundles#38592

Draft
arunpandianp wants to merge 1 commit into
apache:masterfrom
arunpandianp:multikey4
Draft

[Dataflow Streaming] Prepare BoundedQueueExecutor for MultiKey bundles#38592
arunpandianp wants to merge 1 commit into
apache:masterfrom
arunpandianp:multikey4

Conversation

@arunpandianp
Copy link
Copy Markdown
Contributor

ExecutableWork.run() now returns a WorkResult which 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.

@arunpandianp
Copy link
Copy Markdown
Contributor Author

R: @scwhittle

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, 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

  • Introduced WorkResult: Added a new WorkResult class to encapsulate items and bytes processed, allowing for more granular resource management during work execution.
  • Refactored ExecutableWork: Updated ExecutableWork to return a WorkResult instead of using a Consumer, enabling better tracking of resource usage.
  • Enhanced BoundedQueueExecutor: Updated BoundedQueueExecutor to process WorkResult objects, ensuring accurate resource budget reclamation and handling potential execution failures.
  • Added ExceptionUtils: Introduced a utility class to safely propagate exceptions, ensuring consistent error handling across the worker.
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 Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@github-actions
Copy link
Copy Markdown
Contributor

Stopping reviewer notifications for this pull request: review requested by someone other than the bot, ceding control. If you'd like to restart, comment assign set of reviewers

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +236 to +245
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);
});
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The executeMonitorHeld method for ExecutableWork lacks error handling for task submission and execution failures, which can lead to resource leaks in elementsOutstanding and bytesOutstanding.

  1. If executor.execute() throws a RejectedExecutionException (e.g., during worker shutdown), the counters incremented just before will never be decremented, leading to a permanent capacity leak in the JVM.
  2. 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);
    }

@arunpandianp arunpandianp marked this pull request as draft May 22, 2026 10:27
@arunpandianp
Copy link
Copy Markdown
Contributor Author

Changing a few things, not ready for review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant