diff --git a/paimon-core/src/main/java/org/apache/paimon/jdbc/JdbcCatalog.java b/paimon-core/src/main/java/org/apache/paimon/jdbc/JdbcCatalog.java index 7e7718b5bee96..45600715b44d1 100644 --- a/paimon-core/src/main/java/org/apache/paimon/jdbc/JdbcCatalog.java +++ b/paimon-core/src/main/java/org/apache/paimon/jdbc/JdbcCatalog.java @@ -350,7 +350,7 @@ public Optional defaultLockFactory() { @Override public Optional lockContext() { - return Optional.of(new JdbcCatalogLockContext(connections, catalogKey, options)); + return Optional.of(new JdbcCatalogLockContext(catalogKey, options)); } private Lock lock(Identifier identifier) { diff --git a/paimon-core/src/main/java/org/apache/paimon/jdbc/JdbcCatalogLockContext.java b/paimon-core/src/main/java/org/apache/paimon/jdbc/JdbcCatalogLockContext.java index e56b3474ccb3e..b109f271d1a8d 100644 --- a/paimon-core/src/main/java/org/apache/paimon/jdbc/JdbcCatalogLockContext.java +++ b/paimon-core/src/main/java/org/apache/paimon/jdbc/JdbcCatalogLockContext.java @@ -19,17 +19,17 @@ package org.apache.paimon.jdbc; import org.apache.paimon.catalog.CatalogLockContext; +import org.apache.paimon.options.CatalogOptions; import org.apache.paimon.options.Options; /** Jdbc lock context. */ public class JdbcCatalogLockContext implements CatalogLockContext { - private final JdbcClientPool connections; + private transient JdbcClientPool connections; private final String catalogKey; private final Options options; - public JdbcCatalogLockContext(JdbcClientPool connections, String catalogKey, Options options) { - this.connections = connections; + public JdbcCatalogLockContext(String catalogKey, Options options) { this.catalogKey = catalogKey; this.options = options; } @@ -40,6 +40,13 @@ public Options options() { } public JdbcClientPool connections() { + if (connections == null) { + connections = + new JdbcClientPool( + options.get(CatalogOptions.CLIENT_POOL_SIZE), + options.get(CatalogOptions.URI.key()), + options.toMap()); + } return connections; }