dimas-b commented on code in PR #8857:
URL: https://github.com/apache/iceberg/pull/8857#discussion_r1364134288


##########
nessie/src/main/java/org/apache/iceberg/nessie/NessieIcebergClient.java:
##########
@@ -181,23 +183,65 @@ public IcebergTable table(TableIdentifier 
tableIdentifier) {
   }
 
   public void createNamespace(Namespace namespace, Map<String, String> 
metadata) {
+    getRef().checkMutable();
+
+    if (namespace.isEmpty()) {
+      throw new IllegalArgumentException("Creating empty namespaces is not 
supported");
+    }
+
     try {
-      getRef().checkMutable();
-      withReference(
-              getApi()
-                  .createNamespace()
-                  
.namespace(org.projectnessie.model.Namespace.of(namespace.levels()))
-                  .properties(metadata))
-          .create();
-      refresh();
-    } catch (NessieNamespaceAlreadyExistsException e) {
-      throw new AlreadyExistsException(e, "Namespace already exists: %s", 
namespace);
-    } catch (NessieNotFoundException e) {
+      org.projectnessie.model.Namespace content =
+          org.projectnessie.model.Namespace.of(metadata, namespace.levels());
+      ContentKey key = content.toContentKey();
+
+      CommitMultipleOperationsBuilder commitBuilder =
+          api.commitMultipleOperations()
+              .commitMeta(NessieUtil.buildCommitMetadata("create namespace " + 
key, catalogOptions))
+              .operation(Operation.Put.of(key, content));
+
+      Tasks.foreach(commitBuilder)
+          .retry(5)
+          // conflict can be thrown when parent namespace doesn't exist;
+          // bad request can be thrown when namespace already exists.
+          .stopRetryOn(
+              NessieNotFoundException.class,
+              NessieConflictException.class,
+              NessieBadRequestException.class)
+          .throwFailureWhenFinished()
+          .onFailure((o, exception) -> refresh())
+          .run(
+              b -> {
+                Branch branch = b.branch((Branch) 
getRef().getReference()).commit();
+                getRef().updateReference(branch);

Review Comment:
   I'm not sure this is actually effective. We stop retries on 
`NessieConflictException`, which is basically the only reason for refreshing a 
reference :thinking: 
   
   Also, modern Nessie Servers will be able to automatically resolve 
non-conflicting changes since the last branch refresh.
   
   I suppose it we only need to refresh the reference when we refresh metadata.



##########
nessie/src/main/java/org/apache/iceberg/nessie/NessieIcebergClient.java:
##########
@@ -181,23 +183,65 @@ public IcebergTable table(TableIdentifier 
tableIdentifier) {
   }
 
   public void createNamespace(Namespace namespace, Map<String, String> 
metadata) {
+    getRef().checkMutable();
+
+    if (namespace.isEmpty()) {
+      throw new IllegalArgumentException("Creating empty namespaces is not 
supported");
+    }
+
     try {
-      getRef().checkMutable();
-      withReference(
-              getApi()
-                  .createNamespace()
-                  
.namespace(org.projectnessie.model.Namespace.of(namespace.levels()))
-                  .properties(metadata))
-          .create();
-      refresh();
-    } catch (NessieNamespaceAlreadyExistsException e) {
-      throw new AlreadyExistsException(e, "Namespace already exists: %s", 
namespace);
-    } catch (NessieNotFoundException e) {
+      org.projectnessie.model.Namespace content =
+          org.projectnessie.model.Namespace.of(metadata, namespace.levels());

Review Comment:
   The use of `metadata` is a functional change beyond fixing authorship... 
maybe expand this PR's description to mention a reimplementaion of namespace 
operations?



-- 
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-unsubscr...@iceberg.apache.org

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


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

Reply via email to