Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions nessie/src/main/java/org/apache/iceberg/nessie/NessieCatalog.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

package org.apache.iceberg.nessie;

import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.Set;
Expand All @@ -36,6 +37,7 @@
import org.apache.iceberg.exceptions.NamespaceNotEmptyException;
import org.apache.iceberg.exceptions.NoSuchNamespaceException;
import org.apache.iceberg.hadoop.HadoopFileIO;
import org.apache.iceberg.io.CloseableGroup;
import org.apache.iceberg.io.FileIO;
import org.apache.iceberg.relocated.com.google.common.annotations.VisibleForTesting;
import org.apache.iceberg.relocated.com.google.common.base.Joiner;
Expand Down Expand Up @@ -69,6 +71,7 @@ public class NessieCatalog extends BaseMetastoreCatalog implements AutoCloseable
private String name;
private FileIO fileIO;
private Map<String, String> catalogOptions;
private CloseableGroup closeableGroup;

public NessieCatalog() {
}
Expand Down Expand Up @@ -107,6 +110,10 @@ public void initialize(String name, NessieIcebergClient client, FileIO fileIO, M
this.fileIO = Preconditions.checkNotNull(fileIO, "fileIO must be non-null");
this.catalogOptions = Preconditions.checkNotNull(catalogOptions, "catalogOptions must be non-null");
this.warehouseLocation = validateWarehouseLocation(name, catalogOptions);
this.closeableGroup = new CloseableGroup();
closeableGroup.addCloseable(client);
closeableGroup.addCloseable(fileIO);
closeableGroup.setSuppressCloseFailure(true);
}

@SuppressWarnings("checkstyle:HiddenField")
Expand Down Expand Up @@ -151,8 +158,10 @@ private static NessieClientBuilder<?> createNessieClientBuilder(String customBui
}

@Override
public void close() {
client.close();
public void close() throws IOException {
if (null != closeableGroup) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: do we need this null check? I don't see other catalogs doing it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know others don't have it but I feel that we could potentially still run into a case where closeableGroup hasn't been initialized because some preivous code in initialize(...) failed and if close() is called at some place, then it would throw a NPE

closeableGroup.close();
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public void beforeEach(@NessieUri URI nessieUri) throws IOException {
}

@AfterEach
public void afterEach() throws NessieConflictException, NessieNotFoundException {
public void afterEach() throws IOException {
resetData();
try {
if (catalog != null) {
Expand Down