[Dataflow Streaming] Add Operation::finishKey() and move processTimers into it#38430
[Dataflow Streaming] Add Operation::finishKey() and move processTimers into it#38430arunpandianp wants to merge 5 commits intoapache:masterfrom
Conversation
|
PostCommit Java ValidatesRunner Dataflow |
|
PostCommit Java ValidatesRunner Dataflow Streaming |
7f9fe09 to
fd261b7
Compare
Moving the processTimers call from finish() to finishKey(). In upcoming changes there'll be multiple streaming work items in a single beam bundle. With multiple work items, we've to process elements and timers of each work item before moving to the next work items. finishKey() will be called by the NativeIterator classes after iterating through all elements from a work item. Batch processes timers in BatchModeUngroupingParDoFn and does not rely on the processTimers() in ParDoOperation::finish(). So removing the processTimers() call from ParDoOperation::finish() is safe. Batch also does not use the new finishKey() method.
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 refactors the Dataflow streaming execution path to support multiple work items within a single bundle. By introducing 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 introduces a finishKey() lifecycle method to the Dataflow worker's operations and executors, enabling per-key finalization and timer processing. It refactors WindmillReaderIteratorBase and its subclasses to trigger this finalization upon iterator exhaustion. Review feedback recommends implementing an idempotency flag for finishKey(), ensuring consistent cancellation checks across all reader iterators, and improving exception handling during the finalization process.
| public void finishKey() throws Exception { | ||
| checkNotNull(workExecutor, "workExecutor must be set before calling finishKey()"); | ||
| workExecutor.finishKey(); | ||
| } |
There was a problem hiding this comment.
Use the finishKeyCalled flag to ensure that workExecutor.finishKey() is only executed once per work item.
public void finishKey() throws Exception {
if (finishKeyCalled) {
return;
}
checkNotNull(workExecutor, "workExecutor must be set before calling finishKey()");
finishKeyCalled = true;
workExecutor.finishKey();
}| @Override | ||
| public boolean advance() throws IOException { |
There was a problem hiding this comment.
The anonymous iterator in WindowingWindmillReader should also check context.workIsFailed() and throw WorkItemCancelledException, consistent with the changes in WindmillReaderIteratorBase. This ensures that cancelled work items are handled promptly.
@Override
public boolean advance() throws IOException {
if (context.workIsFailed()) {
throw new WorkItemCancelledException(context.getWorkItem().getShardingKey());
}| } catch (Exception e) { | ||
| throw new RuntimeException(e); | ||
| } |
There was a problem hiding this comment.
Instead of wrapping all exceptions in RuntimeException, consider catching IOException and RuntimeException separately to rethrow them directly, and wrapping only other checked exceptions in IOException. This maintains consistency with the advance() method's signature and allows callers to handle specific exception types.
} catch (IOException | RuntimeException e) {
throw e;
} catch (Exception e) {
throw new IOException(e);
}
Moving the processTimers call from finish() to finishKey().
In upcoming changes there'll be multiple streaming work items in a single beam bundle. With multiple work items, we've to process elements and timers of each work item before moving to the next work items.
finishKey() will be called by the NativeIterator classes after iterating through all elements from a work item.
Batch processes timers in BatchModeUngroupingParDoFn and does not rely on the processTimers() in ParDoOperation::finish(). So removing the processTimers() call from ParDoOperation::finish() is safe. Batch also does not use the new finishKey() method.
This change also modifies the streaming NativeIterators to throw WorkItemCancelledException instead of just stopping iteration.