-
Notifications
You must be signed in to change notification settings - Fork 4.7k
[Dataflow Streaming] [Multi Key] Flush streaming sinks at key boundaries and bundle completion #39961
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
[Dataflow Streaming] [Multi Key] Flush streaming sinks at key boundaries and bundle completion #39961
Changes from all commits
82059f5
1027f56
4cbbf84
9deeefc
2b2be9e
1fec61c
1ddbe0f
a93c0e2
36d3c71
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -135,24 +135,27 @@ public PubsubSink<?> create( | |
|
|
||
| @Override | ||
| public SinkWriter<WindowedValue<T>> writer() { | ||
| return new PubsubWriter(topic); | ||
| return new PubsubWriter(); | ||
| } | ||
|
|
||
| /** The SinkWriter for a PubsubSink. */ | ||
| class PubsubWriter implements SinkWriter<WindowedValue<T>> { | ||
| private Windmill.PubSubMessageBundle.Builder outputBuilder; | ||
| private ByteStringOutputStream stream; // Kept across adds for buffer reuse. | ||
|
|
||
| private PubsubWriter(String topic) { | ||
| outputBuilder = | ||
| Windmill.PubSubMessageBundle.newBuilder() | ||
| .setTopic(topic) | ||
| .setTimestampLabel(timestampLabel) | ||
| .setIdLabel(idLabel) | ||
| .setWithAttributes(withAttributes); | ||
| private PubsubWriter() { | ||
| outputBuilder = createOutputBuilder(); | ||
| stream = new ByteStringOutputStream(); | ||
| } | ||
|
|
||
| private Windmill.PubSubMessageBundle.Builder createOutputBuilder() { | ||
| return Windmill.PubSubMessageBundle.newBuilder() | ||
| .setTopic(topic) | ||
| .setTimestampLabel(timestampLabel) | ||
| .setIdLabel(idLabel) | ||
| .setWithAttributes(withAttributes); | ||
| } | ||
|
|
||
| @Override | ||
| public long add(WindowedValue<T> data) throws IOException { | ||
| if (!stream.isEmpty()) { | ||
|
|
@@ -187,18 +190,31 @@ public long add(WindowedValue<T> data) throws IOException { | |
| return byteString.size(); | ||
| } | ||
|
|
||
| private void flush(boolean bundleLevel) { | ||
| try { | ||
| Windmill.PubSubMessageBundle pubsubMessages = outputBuilder.build(); | ||
| if (pubsubMessages.getMessagesCount() > 0) { | ||
| if (bundleLevel) { | ||
| // If/when we add support for ordering keys, the flush needs to happen at the key level | ||
| context.addBundlePubsubMessages(pubsubMessages); | ||
|
arunpandianp marked this conversation as resolved.
|
||
| } else { | ||
| context.getOutputBuilder().addPubsubMessages(pubsubMessages); | ||
| } | ||
| } | ||
| } finally { | ||
| outputBuilder = createOutputBuilder(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. previously we cleared the builder (though see other comment that seems buggy). However should we consider just clearing the messages from the bundle so we don't have to recreate builder, and it can cache message array etc? |
||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public void close() throws IOException { | ||
| Windmill.PubSubMessageBundle pubsubMessages = outputBuilder.build(); | ||
| if (pubsubMessages.getMessagesCount() > 0) { | ||
| context.getOutputBuilder().addPubsubMessages(pubsubMessages); | ||
| } | ||
| outputBuilder.clear(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. how did this work previously? It seems if we ever closed and then reused this object, the outputBuilder would not have the topic etc set. Are these sinks not actually reused in streaming? |
||
| flush(/* bundleLevel= */ context.multiKeyBundleEnabled()); | ||
| } | ||
|
|
||
| @Override | ||
| public void abort() throws IOException { | ||
| close(); | ||
| outputBuilder = createOutputBuilder(); | ||
| stream.reset(); | ||
| } | ||
| } | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.