scwhittle commented on code in PR #22780:
URL: https://github.com/apache/beam/pull/22780#discussion_r949503843
##########
runners/google-cloud-dataflow-java/worker/src/main/java/org/apache/beam/runners/dataflow/worker/WindmillSink.java:
##########
@@ -129,16 +129,17 @@ public SinkWriter<WindowedValue<T>> writer() {
class WindmillStreamWriter implements SinkWriter<WindowedValue<T>> {
private Map<ByteString, Windmill.KeyedMessageBundle.Builder> productionMap;
private final String destinationName;
+ private final ByteStringOutputStream stream;
private WindmillStreamWriter(String destinationName) {
this.destinationName = destinationName;
productionMap = new HashMap<>();
+ stream = new ByteStringOutputStream();
}
private <EncodeT> ByteString encode(Coder<EncodeT> coder, EncodeT object)
throws IOException {
- ByteStringOutputStream stream = new ByteStringOutputStream();
coder.encode(object, stream, Coder.Context.OUTER);
Review Comment:
can we assert that the stream is empty?
##########
runners/google-cloud-dataflow-java/worker/src/main/java/org/apache/beam/runners/dataflow/worker/WindmillSink.java:
##########
@@ -129,16 +129,17 @@ public SinkWriter<WindowedValue<T>> writer() {
class WindmillStreamWriter implements SinkWriter<WindowedValue<T>> {
private Map<ByteString, Windmill.KeyedMessageBundle.Builder> productionMap;
private final String destinationName;
+ private final ByteStringOutputStream stream;
Review Comment:
// Kept across encodes for buffer reuse.
##########
runners/google-cloud-dataflow-java/worker/src/main/java/org/apache/beam/runners/dataflow/worker/PubsubSink.java:
##########
@@ -141,6 +141,7 @@ public SinkWriter<WindowedValue<T>> writer() {
/** The SinkWriter for a PubsubSink. */
class PubsubWriter implements SinkWriter<WindowedValue<T>> {
private Windmill.PubSubMessageBundle.Builder outputBuilder;
+ private ByteStringOutputStream stream;
Review Comment:
// Kept across adds for buffer reuse.
##########
runners/google-cloud-dataflow-java/worker/src/main/java/org/apache/beam/runners/dataflow/worker/PubsubSink.java:
##########
@@ -161,13 +163,11 @@ public long add(WindowedValue<T> data) throws IOException
{
if (formatted.getAttributeMap() != null) {
pubsubMessageBuilder.putAllAttributes(formatted.getAttributeMap());
}
- ByteStringOutputStream output = new ByteStringOutputStream();
- pubsubMessageBuilder.build().writeTo(output);
- byteString = output.toByteString();
+ pubsubMessageBuilder.build().writeTo(stream);
Review Comment:
can we assert the stream is empty at the beginning of this function?
--
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]