github-actions[bot] commented on code in PR #62183: URL: https://github.com/apache/doris/pull/62183#discussion_r3077686011
########## fe/fe-core/src/main/java/org/apache/doris/datasource/PluginDrivenExternalCatalog.java: ########## @@ -0,0 +1,244 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package org.apache.doris.datasource; + +import org.apache.doris.common.DdlException; +import org.apache.doris.connector.ConnectorFactory; +import org.apache.doris.connector.ConnectorSessionBuilder; +import org.apache.doris.connector.DefaultConnectorContext; +import org.apache.doris.connector.api.Connector; +import org.apache.doris.connector.api.ConnectorSession; +import org.apache.doris.connector.api.ConnectorTestResult; +import org.apache.doris.qe.ConnectContext; +import org.apache.doris.transaction.PluginDrivenTransactionManager; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +import java.io.IOException; +import java.util.List; +import java.util.Map; + +/** + * An {@link ExternalCatalog} backed by a Connector SPI plugin. + * + * <p>This adapter bridges the connector SPI ({@link Connector}) with the existing + * ExternalCatalog hierarchy. Metadata operations are delegated to the connector's + * {@link org.apache.doris.connector.api.ConnectorMetadata} implementation.</p> + * + * <p>When created via {@link CatalogFactory}, the Connector instance is provided + * directly. After GSON deserialization (FE restart), the Connector is recreated + * from catalog properties during {@link #initLocalObjectsImpl()}.</p> + */ +public class PluginDrivenExternalCatalog extends ExternalCatalog { + + private static final Logger LOG = LogManager.getLogger(PluginDrivenExternalCatalog.class); + + private transient Connector connector; + + /** No-arg constructor for GSON deserialization. */ + public PluginDrivenExternalCatalog() { + } + + /** + * Creates a plugin-driven catalog with an already-created Connector. + * + * @param catalogId unique catalog id + * @param name catalog name + * @param resource optional resource name + * @param props catalog properties + * @param comment catalog comment + * @param connector the SPI connector instance + */ + public PluginDrivenExternalCatalog(long catalogId, String name, String resource, + Map<String, String> props, String comment, Connector connector) { + super(catalogId, name, InitCatalogLog.Type.PLUGIN, comment); + this.catalogProperty = new CatalogProperty(resource, props); + this.connector = connector; + } + + @Override + protected void initLocalObjectsImpl() { + if (connector != null) { + transactionManager = new PluginDrivenTransactionManager(); + initPreExecutionAuthenticator(); + return; + } + // After GSON deserialization, recreate the Connector from catalog properties. + String catalogType = catalogProperty.getOrDefault(CatalogMgr.CATALOG_TYPE_PROP, ""); Review Comment: Blocking: this reconstructs the connector solely from `catalogProperty.getOrDefault("type", "")`. Legacy JDBC/ES catalogs created via a resource derive their type from `CatalogProperty.resource`, and that value is not guaranteed to be copied into the properties map. After checkpoint/restart, `catalogType` can therefore be empty here, `createConnector()` returns `null`, and FE can no longer initialize the catalog. Please persist the resolved type when constructing `PluginDrivenExternalCatalog`, or fall back to the serialized resource when `type` is absent. ########## fe/fe-core/src/main/java/org/apache/doris/datasource/CatalogFactory.java: ########## @@ -84,42 +92,60 @@ private static CatalogIf createCatalog(long catalogId, String name, String resou } // create catalog - ExternalCatalog catalog; - switch (catalogType) { - case "hms": - catalog = new HMSExternalCatalog(catalogId, name, resource, props, comment); - break; - case "es": - catalog = new EsExternalCatalog(catalogId, name, resource, props, comment); - break; - case "jdbc": - catalog = new JdbcExternalCatalog(catalogId, name, resource, props, comment); - break; - case "iceberg": - catalog = IcebergExternalCatalogFactory.createCatalog(catalogId, name, resource, props, comment); - break; - case "paimon": - catalog = PaimonExternalCatalogFactory.createCatalog(catalogId, name, resource, props, comment); - break; - case "trino-connector": - catalog = TrinoConnectorExternalCatalogFactory.createCatalog(catalogId, name, resource, props, comment); - break; - case "max_compute": - catalog = new MaxComputeExternalCatalog(catalogId, name, resource, props, comment); - break; - case "lakesoul": - throw new DdlException("Lakesoul catalog is no longer supported"); - case "doris": - catalog = new RemoteDorisExternalCatalog(catalogId, name, resource, props, comment); - break; - case "test": - if (!FeConstants.runningUnitTest) { - throw new DdlException("test catalog is only for FE unit test"); - } - catalog = new TestExternalCatalog(catalogId, name, resource, props, comment); - break; - default: - throw new DdlException("Unknown catalog type: " + catalogType); + ExternalCatalog catalog = null; + + // Try SPI connector plugin path first, but only for whitelisted types. + // Returns null if no ConnectorProvider matches the catalog type. + Connector spiConnector = null; + if (SPI_READY_TYPES.contains(catalogType)) { + spiConnector = ConnectorFactory.createConnector( + catalogType, props, new DefaultConnectorContext(name, catalogId)); + } + if (spiConnector != null) { + LOG.info("Created plugin-driven catalog '{}' via SPI connector for type '{}'", + name, catalogType); + catalog = new PluginDrivenExternalCatalog( + catalogId, name, resource, props, comment, spiConnector); + } + + // Fallback to built-in catalog types if no SPI connector matched. + if (catalog == null) { + switch (catalogType) { + case "hms": + catalog = new HMSExternalCatalog(catalogId, name, resource, props, comment); + break; + case "iceberg": + catalog = IcebergExternalCatalogFactory.createCatalog( + catalogId, name, resource, props, comment); + break; + case "paimon": + catalog = PaimonExternalCatalogFactory.createCatalog( + catalogId, name, resource, props, comment); + break; + case "trino-connector": + catalog = TrinoConnectorExternalCatalogFactory.createCatalog( + catalogId, name, resource, props, comment); + break; + case "max_compute": + catalog = new MaxComputeExternalCatalog( + catalogId, name, resource, props, comment); + break; + case "lakesoul": + throw new DdlException("Lakesoul catalog is no longer supported"); + case "doris": + catalog = new RemoteDorisExternalCatalog( + catalogId, name, resource, props, comment); + break; + case "test": + if (!FeConstants.runningUnitTest) { + throw new DdlException("test catalog is only for FE unit test"); + } + catalog = new TestExternalCatalog( + catalogId, name, resource, props, comment); Review Comment: Blocking: the fallback switch no longer handles `es`/`jdbc`, so replay now depends on the plugin loading successfully. But `initConnectorPluginManager()` only logs plugin-load failures and continues, and `build.sh` also skips deployment when a connector zip is absent. In that state, replaying an existing ES/JDBC catalog reaches this `default` branch and fails with `Unknown catalog type`. We need a compatibility path here (or a hard startup failure as soon as a required connector plugin is missing). -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
