Skip to content
Open
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
11 changes: 10 additions & 1 deletion core/src/main/java/org/apache/iceberg/CachingCatalog.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
import com.github.benmanes.caffeine.cache.RemovalCause;
import com.github.benmanes.caffeine.cache.RemovalListener;
import com.github.benmanes.caffeine.cache.Ticker;
import java.io.Closeable;
import java.io.IOException;
import java.time.Duration;
import java.util.List;
import java.util.Locale;
Expand All @@ -43,7 +45,7 @@
* <p>See {@link CatalogProperties#CACHE_EXPIRATION_INTERVAL_MS} for more details regarding special
* values for {@code expirationIntervalMillis}.
*/
public class CachingCatalog implements Catalog {
public class CachingCatalog implements Catalog, Closeable {
private static final Logger LOG = LoggerFactory.getLogger(CachingCatalog.class);
private static final MetadataTableType[] METADATA_TABLE_TYPE_VALUES = MetadataTableType.values();

Expand Down Expand Up @@ -214,6 +216,13 @@ public TableBuilder buildTable(TableIdentifier identifier, Schema schema) {
return new CachingTableBuilder(identifier, schema);
}

@Override
public void close() throws IOException {
if (catalog instanceof Closeable) {
((Closeable) catalog).close();
}
}

private class CachingTableBuilder implements TableBuilder {
private final TableIdentifier ident;
private final TableBuilder innerBuilder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public class AuthSessionCache implements AutoCloseable {
public AuthSessionCache(String name, Duration sessionTimeout) {
this(
sessionTimeout,
ThreadPools.newExitingWorkerPool(name + "-auth-session-evict", 1),
ThreadPools.newScheduledPool(name + "-auth-session-evict", 1),
Ticker.systemTicker());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import static org.apache.iceberg.TableProperties.GC_ENABLED;
import static org.apache.iceberg.TableProperties.GC_ENABLED_DEFAULT;

import java.io.Closeable;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -120,7 +122,7 @@
*
* <p>
*/
public class SparkCatalog extends BaseCatalog {
public class SparkCatalog extends BaseCatalog implements Closeable {
private static final Set<String> DEFAULT_NS_KEYS = ImmutableSet.of(TableCatalog.PROP_OWNER);
private static final Splitter COMMA = Splitter.on(",");
private static final Joiner COMMA_JOINER = Joiner.on(",");
Expand Down Expand Up @@ -173,6 +175,13 @@ public Table loadTable(Identifier ident) throws NoSuchTableException {
}
}

@Override
public void close() throws IOException {
if (icebergCatalog instanceof Closeable) {
((Closeable) icebergCatalog).close();
}
}

@Override
public Table loadTable(Identifier ident, String version) throws NoSuchTableException {
Table table = loadTable(ident);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import static org.apache.iceberg.TableProperties.GC_ENABLED;
import static org.apache.iceberg.TableProperties.GC_ENABLED_DEFAULT;

import java.io.Closeable;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -120,7 +122,7 @@
*
* <p>
*/
public class SparkCatalog extends BaseCatalog {
public class SparkCatalog extends BaseCatalog implements Closeable {
private static final Set<String> DEFAULT_NS_KEYS = ImmutableSet.of(TableCatalog.PROP_OWNER);
private static final Splitter COMMA = Splitter.on(",");
private static final Joiner COMMA_JOINER = Joiner.on(",");
Expand Down Expand Up @@ -164,6 +166,13 @@ protected TableIdentifier buildIdentifier(Identifier identifier) {
return Spark3Util.identifierToTableIdentifier(identifier);
}

@Override
public void close() throws IOException {
if (icebergCatalog instanceof Closeable) {
((Closeable) icebergCatalog).close();
}
}

@Override
public Table loadTable(Identifier ident) throws NoSuchTableException {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import static org.apache.iceberg.TableProperties.GC_ENABLED;
import static org.apache.iceberg.TableProperties.GC_ENABLED_DEFAULT;

import java.io.Closeable;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -121,7 +123,7 @@
*
* <p>
*/
public class SparkCatalog extends BaseCatalog {
public class SparkCatalog extends BaseCatalog implements Closeable {
private static final Set<String> DEFAULT_NS_KEYS = ImmutableSet.of(TableCatalog.PROP_OWNER);
private static final Splitter COMMA = Splitter.on(",");
private static final Joiner COMMA_JOINER = Joiner.on(",");
Expand Down Expand Up @@ -165,6 +167,13 @@ protected TableIdentifier buildIdentifier(Identifier identifier) {
return Spark3Util.identifierToTableIdentifier(identifier);
}

@Override
public void close() throws IOException {
if (icebergCatalog instanceof Closeable) {
((Closeable) icebergCatalog).close();
}
}

@Override
public Table loadTable(Identifier ident) throws NoSuchTableException {
try {
Expand Down