tejasiyer-dev commented on code in PR #40543:
URL: https://github.com/apache/beam/pull/40543#discussion_r4606736041
##########
sdks/java/core/src/main/java/org/apache/beam/sdk/io/WriteFiles.java:
##########
@@ -923,30 +991,56 @@ public void finishBundle(FinishBundleContext c) throws
Exception {
BoundedWindow window = evictedResult.getWindow();
c.output(evictedResult, window.maxTimestamp(), window);
}
- for (Map.Entry<WriterKey<DestinationT>, Writer<DestinationT, OutputT>>
entry :
- writers.entrySet()) {
- WriterKey<DestinationT> key = entry.getKey();
- Writer<DestinationT, OutputT> writer = entry.getValue();
- try {
- writer.close();
- } catch (Exception e) {
- // If anything goes wrong, make sure to delete the temporary file.
- writer.cleanup();
- throw e;
- }
- BoundedWindow window = key.window;
- c.output(
- new FileResult<>(
- writer.getOutputFile(), UNKNOWN_SHARDNUM, window,
key.paneInfo, key.destination),
- window.maxTimestamp(),
- window);
- }
+ closeAllWritersAndOutputFileResults(writers, c);
writers.clear();
evictedFileResults.clear();
}
}
}
+ private Writer<DestinationT, OutputT> openAndRegisterWriter(
+ Map<WriterKey<DestinationT>, Writer<DestinationT, OutputT>> writers,
+ WriterKey<DestinationT> key)
+ throws Exception {
+ String uuid = UUID.randomUUID().toString();
+ LOG.info(
+ "Opening writer {} for window {} pane {} destination {}",
+ uuid,
+ key.window,
+ key.paneInfo,
+ key.destination);
+ Writer<DestinationT, OutputT> writer = writeOperation.createWriter();
+ writer.setDestination(key.destination);
+ writer.open(uuid);
+ writers.put(key, writer);
Review Comment:
Done. checkState takes a boolean expression so I changed to
checkState(writers.put(key, writer) == null, "A writer is already open for %s",
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]