You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iceberg.apache.org by ry...@apache.org on 2021/04/26 15:24:44 UTC

[iceberg] branch master updated: Use `CommitStatusUnknownException` for Nessie (#2515)

This is an automated email from the ASF dual-hosted git repository.

rymurr pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/iceberg.git


The following commit(s) were added to refs/heads/master by this push:
     new cd17555  Use `CommitStatusUnknownException` for Nessie (#2515)
cd17555 is described below

commit cd175556b7e0ca2c1bc433aeffa47f4692fe9514
Author: Robert Stupp <sn...@snazy.de>
AuthorDate: Mon Apr 26 17:24:34 2021 +0200

    Use `CommitStatusUnknownException` for Nessie (#2515)
    
    In case the Nessie endpoint did not respond or some other network error that makes it impossible
    to detect whether the Nessie server got the request and, more importantly, get the response.
    
    This PR adds a `catch (org.projectnessie.client.http.HttpClientException)` and re-throws it as
    the new `CommitStateUnknownException`.
    
    Related to #2328
---
 .../iceberg/nessie/NessieTableOperations.java      | 26 +++++++++++++++++-----
 1 file changed, 20 insertions(+), 6 deletions(-)

diff --git a/nessie/src/main/java/org/apache/iceberg/nessie/NessieTableOperations.java b/nessie/src/main/java/org/apache/iceberg/nessie/NessieTableOperations.java
index 01b006c..bc0dad2 100644
--- a/nessie/src/main/java/org/apache/iceberg/nessie/NessieTableOperations.java
+++ b/nessie/src/main/java/org/apache/iceberg/nessie/NessieTableOperations.java
@@ -24,15 +24,18 @@ import org.apache.iceberg.BaseMetastoreTableOperations;
 import org.apache.iceberg.Snapshot;
 import org.apache.iceberg.TableMetadata;
 import org.apache.iceberg.exceptions.CommitFailedException;
+import org.apache.iceberg.exceptions.CommitStateUnknownException;
 import org.apache.iceberg.exceptions.NoSuchTableException;
 import org.apache.iceberg.io.FileIO;
 import org.projectnessie.client.NessieClient;
+import org.projectnessie.client.http.HttpClientException;
 import org.projectnessie.error.NessieConflictException;
 import org.projectnessie.error.NessieNotFoundException;
 import org.projectnessie.model.CommitMeta;
 import org.projectnessie.model.Contents;
 import org.projectnessie.model.ContentsKey;
 import org.projectnessie.model.IcebergTable;
+import org.projectnessie.model.ImmutableCommitMeta.Builder;
 import org.projectnessie.model.ImmutableIcebergTable;
 import org.projectnessie.model.ImmutableOperations;
 import org.projectnessie.model.Operation;
@@ -92,22 +95,33 @@ public class NessieTableOperations extends BaseMetastoreTableOperations {
 
     String newMetadataLocation = writeNewMetadata(metadata, currentVersion() + 1);
 
-    boolean threw = true;
+    boolean delete = true;
     try {
       IcebergTable newTable = ImmutableIcebergTable.builder().metadataLocation(newMetadataLocation).build();
+      Builder cm = CommitMeta.builder().message("iceberg commit");
+      String appId = applicationId();
+      if (appId != null) {
+        cm.putProperties("spark.app.id", appId);
+      }
       Operations op = ImmutableOperations.builder().addOperations(Operation.Put.of(key, newTable))
-          .commitMeta(CommitMeta.fromMessage(String.format("iceberg commit%s", applicationId())))
-          .build();
+          .commitMeta(cm.build()).build();
       client.getTreeApi().commitMultipleOperations(reference.getAsBranch().getName(), reference.getHash(), op);
 
-      threw = false;
+      delete = false;
     } catch (NessieConflictException ex) {
       throw new CommitFailedException(ex, "Commit failed: Reference hash is out of date. " +
           "Update the reference %s and try again", reference.getName());
+    } catch (HttpClientException ex) {
+      // Intentionally catch all nessie-client-exceptions here and not just the "timeout" variant
+      // to catch all kinds of network errors (e.g. connection reset). Network code implementation
+      // details and all kinds of network devices can induce unexpected behavior. So better be
+      // safe than sorry.
+      delete = false;
+      throw new CommitStateUnknownException(ex);
     } catch (NessieNotFoundException ex) {
       throw new RuntimeException(String.format("Commit failed: Reference %s no longer exist", reference.getName()), ex);
     } finally {
-      if (threw) {
+      if (delete) {
         io().deleteFile(newMetadataLocation);
       }
     }
@@ -137,7 +151,7 @@ public class NessieTableOperations extends BaseMetastoreTableOperations {
       }
 
     }
-    return appId == null ? "" : ("\nspark.app.id= " + appId);
+    return appId;
   }
 
 }