hudi-agent commented on code in PR #18909:
URL: https://github.com/apache/hudi/pull/18909#discussion_r3348085523
##########
hudi-hadoop-common/src/main/java/org/apache/hudi/common/table/log/HoodieLogFormatWriter.java:
##########
@@ -237,14 +242,59 @@ public void close() throws IOException {
}
private void closeStream() throws IOException {
- if (output != null) {
+ if (output == null) {
+ return;
+ }
+
+ Exception syncException = null;
+ try {
// Persist all buffered data to DataNodes before closing so downstream
// readers can observe a fully-written log file at commit-level
visibility.
sync();
- output.close();
- output = null;
- closed = true;
+ } catch (IOException | RuntimeException e) {
+ syncException = e;
+ }
+
+ try {
+ closeOutputStream();
+ } catch (IOException | RuntimeException closeException) {
+ if (syncException != null) {
+ syncException.addSuppressed(closeException);
+ throwAsIOExceptionOrRuntimeException(syncException);
+ }
+ throwAsIOExceptionOrRuntimeException(closeException);
+ }
+
+ if (syncException != null) {
+ throwAsIOExceptionOrRuntimeException(syncException);
+ }
+ }
+
+ private void closeOutputStreamOnAppendFailure(Throwable failure) {
+ try {
+ closeOutputStream();
+ } catch (IOException | RuntimeException closeException) {
+ failure.addSuppressed(closeException);
+ log.warn("Failed to close output stream after append failure for log
file {}", logFile, closeException);
+ }
+ }
+
+ private void closeOutputStream() throws IOException {
+ if (output != null) {
+ try {
+ output.close();
+ } finally {
+ output = null;
+ closed = true;
+ }
+ }
+ }
+
+ private void throwAsIOExceptionOrRuntimeException(Exception exception)
throws IOException {
Review Comment:
🤖 nit: `throwAsIOExceptionOrRuntimeException` is a mouthful and describes
the mechanism rather than the intent — could you rename it to something like
`rethrow`? It would read more naturally at the call sites (e.g.
`rethrow(syncException)`) and matches the idiom used in libraries like Guava's
`Throwables`.
<sub><i>- AI-generated; verify before applying. React 👍/👎 to flag
quality.</i></sub>
--
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]