You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@iceberg.apache.org by GitBox <gi...@apache.org> on 2021/07/28 18:02:17 UTC

[GitHub] [iceberg] yyanyy commented on a change in pull request #2878: API: extend CloseableGroup and close resources when closing aws catalogs

yyanyy commented on a change in pull request #2878:
URL: https://github.com/apache/iceberg/pull/2878#discussion_r678535373



##########
File path: api/src/main/java/org/apache/iceberg/io/CloseableGroup.java
##########
@@ -23,20 +23,47 @@
 import java.io.IOException;
 import java.util.Deque;
 import org.apache.iceberg.relocated.com.google.common.collect.Lists;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 public abstract class CloseableGroup implements Closeable {
-  private final Deque<Closeable> closeables = Lists.newLinkedList();
+  private static final Logger LOG = LoggerFactory.getLogger(CloseableGroup.class);
 
-  protected void addCloseable(Closeable closeable) {
+  private final Deque<AutoCloseable> closeables = Lists.newLinkedList();
+  private boolean suppressCloseFailure = false;
+
+  protected void addCloseable(AutoCloseable closeable) {
     closeables.add(closeable);
   }
 
+  protected void setSuppressCloseFailure(boolean shouldSuppress) {
+    this.suppressCloseFailure = shouldSuppress;
+  }
+
   @Override
   public void close() throws IOException {
     while (!closeables.isEmpty()) {
-      Closeable toClose = closeables.removeFirst();
+      AutoCloseable toClose = closeables.removeFirst();
       if (toClose != null) {
-        toClose.close();
+        if (suppressCloseFailure) {

Review comment:
       Thanks for the quick review! 
   
   This is more of a helper utility function to me and on opt-in basis. In the case we were looking at (aws catalogs), if one of the resource fails to be closed, we don't really plan to handle it further, and we want to make sure an earlier close failure shouldn't block other resources from getting closed. So we either do something like 
   ```
   try {
     resource1.close();
   } catch (Exception e) {
     log.error("Error closing resource1, suppressing");
   }
   
   try {
     resource2.close();
   } catch (Exception e) {
     log.error("Error closing resource2, suppressing");
   }
   ```
   or reuse this class to make the code simpler (the current solution). 




-- 
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: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org