scwhittle commented on code in PR #39961:
URL: https://github.com/apache/beam/pull/39961#discussion_r4020509380
##########
runners/google-cloud-dataflow-java/worker/src/main/java/org/apache/beam/runners/dataflow/worker/PubsubDynamicSink.java:
##########
@@ -127,32 +134,52 @@ public long add(WindowedValue<PubsubMessage> data) throws
IOException {
!dataTopic.isEmpty(), "No topic set for message when using dynamic
topics.");
ByteString byteString = getDataFromMessage(data.getValue(), stream);
Windmill.PubSubMessageBundle.Builder builder =
- outputBuilders.computeIfAbsent(
- dataTopic,
- topic ->
- context
- .getOutputBuilder()
- .addPubsubMessagesBuilder()
- .setTopic(topic)
- .setTimestampLabel(timestampLabel)
- .setIdLabel(idLabel)
- .setWithAttributes(true));
+ outputBuilders.computeIfAbsent(dataTopic, this::createOutputBuilder);
builder.addMessages(
Windmill.Message.newBuilder()
.setData(byteString)
.setTimestamp(WindmillTimeUtils.harnessToWindmillTimestamp(data.getTimestamp()))
.build());
+ bufferedBytes += byteString.size();
+
return byteString.size();
}
+ private void flush(boolean bundleLevel) {
+ try {
+ for (Windmill.PubSubMessageBundle.Builder builder :
outputBuilders.values()) {
+ if (builder.getMessagesCount() > 0) {
+ Windmill.PubSubMessageBundle pubsubMessages = builder.build();
+ if (bundleLevel) {
+ context.addBundlePubsubMessages(pubsubMessages);
+ } else {
+ context.getOutputBuilder().addPubsubMessages(pubsubMessages);
+ }
+ }
+ }
+ } finally {
+ outputBuilders.clear();
+ bufferedBytes = 0;
+ }
+ }
+
+ @Override
+ public void finishKey(@Nullable Object key) throws IOException {
+ if (context.multiKeyBundleEnabled() && bufferedBytes >=
MAX_PUBSUB_BUNDLE_BYTES) {
+ flush(/* bundleLevel= */ false);
Review Comment:
Should we just change that implementation? If we do add key-ordering,
putting these on a key may affect performance if we try to respect that they
are attached to a particular key.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]