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
Original file line number Diff line number Diff line change
Expand Up @@ -534,8 +534,15 @@ private Catalog loadCatalog(Config config, Map<String, String> icebergConfig) th
Catalog catalog;
if (EtcdCatalog.class.getName().equals(catalogImpl)) {
catalog = newEctdCatalog(catalogName, icebergConfig);
logger.info("Catalog backend: etcd");
} else {
catalog = CatalogUtil.buildIcebergCatalog(catalogName, icebergConfig, null);
String uri = icebergConfig.getOrDefault(CatalogProperties.URI, "");
if (uri.toLowerCase().startsWith("jdbc:sqlite:")) {
logger.warn("Catalog backend: SQLite ({}); not recommended for production use", uri);
} else {
logger.info("Catalog backend: {} ({})", catalogImpl, uri);
}
}
return catalog;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import org.apache.iceberg.BaseMetastoreCatalog;
import org.apache.iceberg.BaseMetastoreTableOperations;
import org.apache.iceberg.CatalogUtil;
Expand Down Expand Up @@ -61,6 +63,8 @@ public class EtcdCatalog extends BaseMetastoreCatalog implements SupportsNamespa

private static final Logger logger = LoggerFactory.getLogger(EtcdCatalog.class);

private static final long DEFAULT_TIMEOUT_SECONDS = 30;

private static final String NAMESPACE_PREFIX = "n/";
private static final String TABLE_PREFIX = "t/";

Expand All @@ -79,6 +83,28 @@ public EtcdCatalog(String name, String uri, String warehouseLocation, FileIO io)
Client.builder().endpoints(uri.split(",")).keepaliveWithoutCalls(false).build();
this.client = etcdClient;
this.kv = etcdClient.getKVClient();
try {
kv.get(ByteSequence.from("/", StandardCharsets.UTF_8))
.get(DEFAULT_TIMEOUT_SECONDS, TimeUnit.SECONDS);
logger.info("Connected to etcd at {}", uri);
} catch (TimeoutException e) {
throw new RuntimeIOException(
new IOException(
"Failed to connect to etcd at "
+ uri
+ ": timed out after "
+ DEFAULT_TIMEOUT_SECONDS
+ "s",
e));
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new RuntimeIOException(new IOException("Interrupted connecting to etcd at " + uri, e));
} catch (ExecutionException e) {
Throwable cause = e.getCause() != null ? e.getCause() : e;
throw new RuntimeIOException(
new IOException(
"Failed to connect to etcd at " + uri + ": " + cause.getMessage(), cause));
}
this.io = io;
}

Expand Down Expand Up @@ -145,19 +171,30 @@ private String namespacePrefix() {

private static <T> T unwrapCommit(java.util.concurrent.CompletableFuture<T> x) {
try {
return x.get();
} catch (InterruptedException | ExecutionException e) {
// TODO: Thread.currentThread().interrupt();?
return x.get(DEFAULT_TIMEOUT_SECONDS, TimeUnit.SECONDS);
} catch (TimeoutException e) {
throw new CommitStateUnknownException(
new IOException("etcd commit timed out after " + DEFAULT_TIMEOUT_SECONDS + "s", e));
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new CommitStateUnknownException(e);
} catch (ExecutionException e) {
throw new CommitStateUnknownException(e);
}
}

private static <T> T unwrap(java.util.concurrent.CompletableFuture<T> x) {
try {
return x.get();
} catch (InterruptedException | ExecutionException e) {
// TODO: Thread.currentThread().interrupt();?
return x.get(DEFAULT_TIMEOUT_SECONDS, TimeUnit.SECONDS);
} catch (TimeoutException e) {
throw new RuntimeIOException(
new IOException("etcd request timed out after " + DEFAULT_TIMEOUT_SECONDS + "s", e));
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new RuntimeIOException(new IOException(e));
} catch (ExecutionException e) {
Throwable cause = e.getCause() != null ? e.getCause() : e;
throw new RuntimeIOException(new IOException(cause.getMessage(), cause));
}
}

Expand Down
Loading