Search in sources :

Example 1 with Catalog

use of io.trino.metadata.Catalog in project trino by trinodb.

the class ConnectorManager method createCatalog.

private synchronized void createCatalog(CatalogName catalogName, String connectorName, InternalConnectorFactory factory, Map<String, String> properties) {
    // create all connectors before adding, so a broken connector does not leave the system half updated
    CatalogClassLoaderSupplier duplicatePluginClassLoaderFactory = new CatalogClassLoaderSupplier(catalogName, factory.getDuplicatePluginClassLoaderFactory(), handleResolver);
    MaterializedConnector connector = new MaterializedConnector(catalogName, createConnector(catalogName, factory.getConnectorFactory(), duplicatePluginClassLoaderFactory, properties), duplicatePluginClassLoaderFactory::destroy);
    MaterializedConnector informationSchemaConnector = new MaterializedConnector(createInformationSchemaCatalogName(catalogName), new InformationSchemaConnector(catalogName.getCatalogName(), nodeManager, metadataManager, accessControlManager), () -> {
    });
    CatalogName systemId = createSystemTablesCatalogName(catalogName);
    SystemTablesProvider systemTablesProvider;
    if (nodeManager.getCurrentNode().isCoordinator()) {
        systemTablesProvider = new CoordinatorSystemTablesProvider(transactionManager, metadataManager, catalogName.getCatalogName(), new StaticSystemTablesProvider(connector.getSystemTables()));
    } else {
        systemTablesProvider = new StaticSystemTablesProvider(connector.getSystemTables());
    }
    MaterializedConnector systemConnector = new MaterializedConnector(systemId, new SystemConnector(nodeManager, systemTablesProvider, transactionId -> transactionManager.getConnectorTransaction(transactionId, catalogName)), () -> {
    });
    SecurityManagement securityManagement = connector.getAccessControl().isPresent() ? CONNECTOR : SYSTEM;
    Catalog catalog = new Catalog(catalogName.getCatalogName(), connector.getCatalogName(), connectorName, connector.getConnector(), securityManagement, informationSchemaConnector.getCatalogName(), informationSchemaConnector.getConnector(), systemConnector.getCatalogName(), systemConnector.getConnector());
    try {
        addConnectorInternal(connector);
        addConnectorInternal(informationSchemaConnector);
        addConnectorInternal(systemConnector);
        catalogManager.registerCatalog(catalog);
    } catch (Throwable e) {
        catalogManager.removeCatalog(catalog.getCatalogName());
        removeConnectorInternal(systemConnector.getCatalogName());
        removeConnectorInternal(informationSchemaConnector.getCatalogName());
        removeConnectorInternal(connector.getCatalogName());
        throw e;
    }
    connector.getEventListeners().forEach(eventListenerManager::addEventListener);
}
Also used : CoordinatorSystemTablesProvider(io.trino.connector.system.CoordinatorSystemTablesProvider) SystemConnector(io.trino.connector.system.SystemConnector) StaticSystemTablesProvider(io.trino.connector.system.StaticSystemTablesProvider) AccessControlManager(io.trino.security.AccessControlManager) ConnectorRecordSetProvider(io.trino.spi.connector.ConnectorRecordSetProvider) ConnectorSplitManager(io.trino.spi.connector.ConnectorSplitManager) TableProceduresPropertyManager(io.trino.metadata.TableProceduresPropertyManager) TransactionManager(io.trino.transaction.TransactionManager) SecurityManagement(io.trino.metadata.Catalog.SecurityManagement) CoordinatorSystemTablesProvider(io.trino.connector.system.CoordinatorSystemTablesProvider) CatalogName.createSystemTablesCatalogName(io.trino.connector.CatalogName.createSystemTablesCatalogName) NodeInfo(io.airlift.node.NodeInfo) SplitManager(io.trino.split.SplitManager) ConnectorContext(io.trino.spi.connector.ConnectorContext) PreDestroy(javax.annotation.PreDestroy) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) HandleResolver(io.trino.metadata.HandleResolver) PageSorter(io.trino.spi.PageSorter) Map(java.util.Map) MetadataManager(io.trino.metadata.MetadataManager) ConnectorNodePartitioningProvider(io.trino.spi.connector.ConnectorNodePartitioningProvider) ImmutableSet(com.google.common.collect.ImmutableSet) NodeSchedulerConfig(io.trino.execution.scheduler.NodeSchedulerConfig) PageSinkManager(io.trino.split.PageSinkManager) ConnectorAccessControl(io.trino.spi.connector.ConnectorAccessControl) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) PropertyMetadata(io.trino.spi.session.PropertyMetadata) ThreadSafe(javax.annotation.concurrent.ThreadSafe) GuardedBy(javax.annotation.concurrent.GuardedBy) ThreadContextClassLoader(io.trino.spi.classloader.ThreadContextClassLoader) TableProcedureMetadata(io.trino.spi.connector.TableProcedureMetadata) ConnectorIndexProvider(io.trino.spi.connector.ConnectorIndexProvider) String.format(java.lang.String.format) Preconditions.checkState(com.google.common.base.Preconditions.checkState) SessionPropertyManager(io.trino.metadata.SessionPropertyManager) List(java.util.List) VersionEmbedder(io.trino.spi.VersionEmbedder) CONNECTOR(io.trino.metadata.Catalog.SecurityManagement.CONNECTOR) Optional(java.util.Optional) SystemConnector(io.trino.connector.system.SystemConnector) ColumnPropertyManager(io.trino.metadata.ColumnPropertyManager) SystemTable(io.trino.spi.connector.SystemTable) RecordPageSourceProvider(io.trino.split.RecordPageSourceProvider) InternalNodeManager(io.trino.metadata.InternalNodeManager) Logger(io.airlift.log.Logger) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) NodePartitioningManager(io.trino.sql.planner.NodePartitioningManager) Function(java.util.function.Function) Supplier(java.util.function.Supplier) ConcurrentMap(java.util.concurrent.ConcurrentMap) Inject(javax.inject.Inject) ImmutableList(com.google.common.collect.ImmutableList) Procedure(io.trino.spi.procedure.Procedure) Verify.verify(com.google.common.base.Verify.verify) CatalogName.createInformationSchemaCatalogName(io.trino.connector.CatalogName.createInformationSchemaCatalogName) PageIndexerFactory(io.trino.spi.PageIndexerFactory) Objects.requireNonNull(java.util.Objects.requireNonNull) TableProceduresRegistry(io.trino.metadata.TableProceduresRegistry) IndexManager(io.trino.index.IndexManager) ConnectorFactory(io.trino.spi.connector.ConnectorFactory) Catalog(io.trino.metadata.Catalog) SchemaPropertyManager(io.trino.metadata.SchemaPropertyManager) SYSTEM(io.trino.metadata.Catalog.SecurityManagement.SYSTEM) InformationSchemaConnector(io.trino.connector.informationschema.InformationSchemaConnector) PluginClassLoader(io.trino.server.PluginClassLoader) SystemTablesProvider(io.trino.connector.system.SystemTablesProvider) ConnectorPageSourceProvider(io.trino.spi.connector.ConnectorPageSourceProvider) PageSourceManager(io.trino.split.PageSourceManager) EventListenerManager(io.trino.eventlistener.EventListenerManager) CatalogManager(io.trino.metadata.CatalogManager) TablePropertyManager(io.trino.metadata.TablePropertyManager) ProcedureRegistry(io.trino.metadata.ProcedureRegistry) MaterializedViewPropertyManager(io.trino.metadata.MaterializedViewPropertyManager) EventListener(io.trino.spi.eventlistener.EventListener) TypeManager(io.trino.spi.type.TypeManager) AnalyzePropertyManager(io.trino.metadata.AnalyzePropertyManager) ConnectorPageSinkProvider(io.trino.spi.connector.ConnectorPageSinkProvider) Connector(io.trino.spi.connector.Connector) SecurityManagement(io.trino.metadata.Catalog.SecurityManagement) Catalog(io.trino.metadata.Catalog) StaticSystemTablesProvider(io.trino.connector.system.StaticSystemTablesProvider) InformationSchemaConnector(io.trino.connector.informationschema.InformationSchemaConnector) CatalogName.createSystemTablesCatalogName(io.trino.connector.CatalogName.createSystemTablesCatalogName) CatalogName.createInformationSchemaCatalogName(io.trino.connector.CatalogName.createInformationSchemaCatalogName) StaticSystemTablesProvider(io.trino.connector.system.StaticSystemTablesProvider) CoordinatorSystemTablesProvider(io.trino.connector.system.CoordinatorSystemTablesProvider) SystemTablesProvider(io.trino.connector.system.SystemTablesProvider)

Example 2 with Catalog

use of io.trino.metadata.Catalog in project trino by trinodb.

the class CatalogSystemTable method cursor.

@Override
public RecordCursor cursor(ConnectorTransactionHandle transactionHandle, ConnectorSession connectorSession, TupleDomain<Integer> constraint) {
    Session session = ((FullConnectorSession) connectorSession).getSession();
    Builder table = InMemoryRecordSet.builder(CATALOG_TABLE);
    for (Map.Entry<String, Catalog> entry : getCatalogs(session, metadata, accessControl).entrySet()) {
        table.addRow(entry.getKey(), entry.getValue().getConnectorCatalogName().toString(), entry.getValue().getConnectorName());
    }
    return table.build().cursor();
}
Also used : TableMetadataBuilder.tableMetadataBuilder(io.trino.metadata.MetadataUtil.TableMetadataBuilder.tableMetadataBuilder) Builder(io.trino.spi.connector.InMemoryRecordSet.Builder) Map(java.util.Map) Catalog(io.trino.metadata.Catalog) FullConnectorSession(io.trino.FullConnectorSession) ConnectorSession(io.trino.spi.connector.ConnectorSession) Session(io.trino.Session) FullConnectorSession(io.trino.FullConnectorSession)

Example 3 with Catalog

use of io.trino.metadata.Catalog in project trino by trinodb.

the class Server method updateConnectorIds.

private static void updateConnectorIds(Announcer announcer, CatalogManager metadata) {
    // get existing announcement
    ServiceAnnouncement announcement = getTrinoAnnouncement(announcer.getServiceAnnouncements());
    // automatically build connectorIds if not configured
    Set<String> connectorIds = metadata.getCatalogs().stream().map(Catalog::getConnectorCatalogName).map(Object::toString).collect(toImmutableSet());
    // build announcement with updated sources
    ServiceAnnouncementBuilder builder = serviceAnnouncement(announcement.getType());
    builder.addProperties(announcement.getProperties());
    builder.addProperty("connectorIds", Joiner.on(',').join(connectorIds));
    // update announcement
    announcer.removeServiceAnnouncement(announcement.getId());
    announcer.addServiceAnnouncement(builder.build());
}
Also used : ServiceAnnouncementBuilder(io.airlift.discovery.client.ServiceAnnouncement.ServiceAnnouncementBuilder) ServiceAnnouncement(io.airlift.discovery.client.ServiceAnnouncement) Catalog(io.trino.metadata.Catalog)

Aggregations

Catalog (io.trino.metadata.Catalog)3 Map (java.util.Map)2 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)1 Preconditions.checkState (com.google.common.base.Preconditions.checkState)1 Verify.verify (com.google.common.base.Verify.verify)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 ServiceAnnouncement (io.airlift.discovery.client.ServiceAnnouncement)1 ServiceAnnouncementBuilder (io.airlift.discovery.client.ServiceAnnouncement.ServiceAnnouncementBuilder)1 Logger (io.airlift.log.Logger)1 NodeInfo (io.airlift.node.NodeInfo)1 FullConnectorSession (io.trino.FullConnectorSession)1 Session (io.trino.Session)1 CatalogName.createInformationSchemaCatalogName (io.trino.connector.CatalogName.createInformationSchemaCatalogName)1 CatalogName.createSystemTablesCatalogName (io.trino.connector.CatalogName.createSystemTablesCatalogName)1 InformationSchemaConnector (io.trino.connector.informationschema.InformationSchemaConnector)1 CoordinatorSystemTablesProvider (io.trino.connector.system.CoordinatorSystemTablesProvider)1 StaticSystemTablesProvider (io.trino.connector.system.StaticSystemTablesProvider)1 SystemConnector (io.trino.connector.system.SystemConnector)1 SystemTablesProvider (io.trino.connector.system.SystemTablesProvider)1