Search in sources :

Example 81 with ConnectorId

use of com.facebook.presto.spi.ConnectorId in project presto by prestodb.

the class TestResourceManagerClusterStateProvider method testResourceGroups.

@Test(timeOut = 15_000)
public void testResourceGroups() throws Exception {
    InMemoryNodeManager nodeManager = new InMemoryNodeManager();
    nodeManager.addNode(new ConnectorId("x"), new InternalNode("node1", URI.create("local://127.0.0.1"), NodeVersion.UNKNOWN, true));
    nodeManager.addNode(new ConnectorId("x"), new InternalNode("node2", URI.create("local://127.0.0.1"), NodeVersion.UNKNOWN, true));
    nodeManager.addNode(new ConnectorId("x"), new InternalNode("node3", URI.create("local://127.0.0.1"), NodeVersion.UNKNOWN, true));
    ResourceManagerClusterStateProvider provider = new ResourceManagerClusterStateProvider(nodeManager, new SessionPropertyManager(), 10, Duration.valueOf("4s"), Duration.valueOf("8s"), Duration.valueOf("50s"), Duration.valueOf("0s"), true, newSingleThreadScheduledExecutor());
    provider.registerNodeHeartbeat(createCoordinatorNodeStatus("local"));
    provider.registerNodeHeartbeat(createCoordinatorNodeStatus("node1"));
    provider.registerNodeHeartbeat(createCoordinatorNodeStatus("node2"));
    provider.registerNodeHeartbeat(createCoordinatorNodeStatus("node3"));
    assertEquals(provider.getClusterQueries(), ImmutableList.of());
    long query1Sequence = 0;
    long query2Sequence = 0;
    long query3Sequence = 0;
    long query4Sequence = 0;
    long query5Sequence = 0;
    long query6Sequence = 0;
    provider.registerQueryHeartbeat("node1", createQueryInfo("1", QUEUED, "rg1", GENERAL_POOL), query1Sequence++);
    provider.registerQueryHeartbeat("node1", createQueryInfo("2", RUNNING, "rg2", GENERAL_POOL), query2Sequence++);
    provider.registerQueryHeartbeat("node1", createQueryInfo("3", FINISHING, "rg3", GENERAL_POOL), query3Sequence++);
    provider.registerQueryHeartbeat("node1", createQueryInfo("4", FINISHED, "rg4", GENERAL_POOL), query4Sequence++);
    provider.registerQueryHeartbeat("node1", createQueryInfo("5", FAILED, "rg5", GENERAL_POOL), query5Sequence++);
    assertResourceGroups(provider, "node1", 0);
    assertResourceGroups(provider, "node2", 3);
    // Add an existing leaf node from another node
    provider.registerQueryHeartbeat("node3", createQueryInfo("6", QUEUED, "rg6", GENERAL_POOL), query6Sequence++);
    assertResourceGroups(provider, "node1", 1);
    assertResourceGroups(provider, "node2", 4);
    assertResourceGroups(provider, "node3", 3);
    // Expire running queries
    Thread.sleep(SECONDS.toMillis(5));
    assertResourceGroups(provider, "node1", 0);
    assertResourceGroups(provider, "node2", 0);
    assertResourceGroups(provider, "node3", 0);
}
Also used : SessionPropertyManager(com.facebook.presto.metadata.SessionPropertyManager) InternalNode(com.facebook.presto.metadata.InternalNode) InMemoryNodeManager(com.facebook.presto.metadata.InMemoryNodeManager) ConnectorId(com.facebook.presto.spi.ConnectorId) Test(org.testng.annotations.Test)

Example 82 with ConnectorId

use of com.facebook.presto.spi.ConnectorId in project presto by prestodb.

the class ConnectorManager method createConnection.

private synchronized ConnectorId createConnection(String catalogName, ConnectorFactory connectorFactory, Map<String, String> properties) {
    checkState(!stopped.get(), "ConnectorManager is stopped");
    requireNonNull(catalogName, "catalogName is null");
    requireNonNull(properties, "properties is null");
    requireNonNull(connectorFactory, "connectorFactory is null");
    checkArgument(!catalogManager.getCatalog(catalogName).isPresent(), "A catalog already exists for %s", catalogName);
    ConnectorId connectorId = new ConnectorId(catalogName);
    checkState(!connectors.containsKey(connectorId), "A connector %s already exists", connectorId);
    addCatalogConnector(catalogName, connectorId, connectorFactory, properties);
    return connectorId;
}
Also used : ConnectorId.createInformationSchemaConnectorId(com.facebook.presto.spi.ConnectorId.createInformationSchemaConnectorId) ConnectorId(com.facebook.presto.spi.ConnectorId) ConnectorId.createSystemTablesConnectorId(com.facebook.presto.spi.ConnectorId.createSystemTablesConnectorId)

Example 83 with ConnectorId

use of com.facebook.presto.spi.ConnectorId in project presto by prestodb.

the class ConnectorManager method addCatalogConnector.

private synchronized void addCatalogConnector(String catalogName, ConnectorId connectorId, ConnectorFactory factory, Map<String, String> properties) {
    // create all connectors before adding, so a broken connector does not leave the system half updated
    MaterializedConnector connector = new MaterializedConnector(connectorId, createConnector(connectorId, factory, properties));
    MaterializedConnector informationSchemaConnector = new MaterializedConnector(createInformationSchemaConnectorId(connectorId), new InformationSchemaConnector(catalogName, nodeManager, metadataManager, accessControlManager, connector.getSessionProperties()));
    ConnectorId systemId = createSystemTablesConnectorId(connectorId);
    SystemTablesProvider systemTablesProvider;
    if (nodeManager.getCurrentNode().isCoordinator()) {
        systemTablesProvider = new DelegatingSystemTablesProvider(new StaticSystemTablesProvider(connector.getSystemTables()), new MetadataBasedSystemTablesProvider(metadataManager, catalogName));
    } else {
        systemTablesProvider = new StaticSystemTablesProvider(connector.getSystemTables());
    }
    MaterializedConnector systemConnector = new MaterializedConnector(systemId, new SystemConnector(systemId, nodeManager, systemTablesProvider, transactionId -> transactionManager.getConnectorTransaction(transactionId, connectorId), connector.getSessionProperties()));
    Catalog catalog = new Catalog(catalogName, connector.getConnectorId(), connector.getConnector(), informationSchemaConnector.getConnectorId(), informationSchemaConnector.getConnector(), systemConnector.getConnectorId(), systemConnector.getConnector());
    try {
        addConnectorInternal(connector);
        addConnectorInternal(informationSchemaConnector);
        addConnectorInternal(systemConnector);
        catalogManager.registerCatalog(catalog);
    } catch (Throwable e) {
        catalogManager.removeCatalog(catalog.getCatalogName());
        removeConnectorInternal(systemConnector.getConnectorId());
        removeConnectorInternal(informationSchemaConnector.getConnectorId());
        removeConnectorInternal(connector.getConnectorId());
        throw e;
    }
}
Also used : SystemConnector(com.facebook.presto.connector.system.SystemConnector) MetadataBasedSystemTablesProvider(com.facebook.presto.connector.system.MetadataBasedSystemTablesProvider) MetadataManager(com.facebook.presto.metadata.MetadataManager) ConnectorFilterStatsCalculatorService(com.facebook.presto.cost.ConnectorFilterStatsCalculatorService) RecordPageSourceProvider(com.facebook.presto.split.RecordPageSourceProvider) RowExpressionOptimizer(com.facebook.presto.sql.relational.RowExpressionOptimizer) ConnectorPlanOptimizerManager(com.facebook.presto.sql.planner.ConnectorPlanOptimizerManager) PropertyMetadata(com.facebook.presto.spi.session.PropertyMetadata) ConnectorNodePartitioningProvider(com.facebook.presto.spi.connector.ConnectorNodePartitioningProvider) PreDestroy(javax.annotation.PreDestroy) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) InternalNodeManager(com.facebook.presto.metadata.InternalNodeManager) ConnectorRecordSetProvider(com.facebook.presto.spi.connector.ConnectorRecordSetProvider) Map(java.util.Map) PageIndexerFactory(com.facebook.presto.spi.PageIndexerFactory) SystemTable(com.facebook.presto.spi.SystemTable) ConnectorMetadataUpdaterManager(com.facebook.presto.metadata.ConnectorMetadataUpdaterManager) ConnectorPageSourceProvider(com.facebook.presto.spi.connector.ConnectorPageSourceProvider) FilterStatsCalculator(com.facebook.presto.cost.FilterStatsCalculator) ConnectorSplitManager(com.facebook.presto.spi.connector.ConnectorSplitManager) ImmutableSet(com.google.common.collect.ImmutableSet) PageSinkManager(com.facebook.presto.split.PageSinkManager) ConnectorId.createInformationSchemaConnectorId(com.facebook.presto.spi.ConnectorId.createInformationSchemaConnectorId) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) DomainTranslator(com.facebook.presto.spi.relation.DomainTranslator) Set(java.util.Set) ThreadSafe(javax.annotation.concurrent.ThreadSafe) SplitManager(com.facebook.presto.split.SplitManager) GuardedBy(javax.annotation.concurrent.GuardedBy) String.format(java.lang.String.format) SystemTablesProvider(com.facebook.presto.connector.system.SystemTablesProvider) Preconditions.checkState(com.google.common.base.Preconditions.checkState) Procedure(com.facebook.presto.spi.procedure.Procedure) List(java.util.List) Catalog(com.facebook.presto.metadata.Catalog) Optional(java.util.Optional) SystemConnector(com.facebook.presto.connector.system.SystemConnector) PredicateCompiler(com.facebook.presto.spi.relation.PredicateCompiler) ConnectorId(com.facebook.presto.spi.ConnectorId) StaticSystemTablesProvider(com.facebook.presto.connector.system.StaticSystemTablesProvider) ConnectorRowExpressionService(com.facebook.presto.sql.relational.ConnectorRowExpressionService) DeterminismEvaluator(com.facebook.presto.spi.relation.DeterminismEvaluator) Logger(com.facebook.airlift.log.Logger) NodeInfo(com.facebook.airlift.node.NodeInfo) DelegatingSystemTablesProvider(com.facebook.presto.connector.system.DelegatingSystemTablesProvider) AccessControlManager(com.facebook.presto.security.AccessControlManager) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) BlockEncodingSerde(com.facebook.presto.common.block.BlockEncodingSerde) ConcurrentMap(java.util.concurrent.ConcurrentMap) InformationSchemaConnector(com.facebook.presto.connector.informationSchema.InformationSchemaConnector) ConnectorPlanOptimizerProvider(com.facebook.presto.spi.connector.ConnectorPlanOptimizerProvider) Inject(javax.inject.Inject) RowExpressionFormatter(com.facebook.presto.sql.planner.planPrinter.RowExpressionFormatter) ImmutableList(com.google.common.collect.ImmutableList) PageSourceManager(com.facebook.presto.split.PageSourceManager) TypeManager(com.facebook.presto.common.type.TypeManager) Objects.requireNonNull(java.util.Objects.requireNonNull) ConnectorId.createSystemTablesConnectorId(com.facebook.presto.spi.ConnectorId.createSystemTablesConnectorId) IndexManager(com.facebook.presto.index.IndexManager) ThreadContextClassLoader(com.facebook.presto.spi.classloader.ThreadContextClassLoader) FunctionResolution(com.facebook.presto.sql.relational.FunctionResolution) PageSorter(com.facebook.presto.spi.PageSorter) ConnectorContext(com.facebook.presto.spi.connector.ConnectorContext) ConnectorPageSinkProvider(com.facebook.presto.spi.connector.ConnectorPageSinkProvider) TransactionManager(com.facebook.presto.transaction.TransactionManager) Connector(com.facebook.presto.spi.connector.Connector) ConnectorIndexProvider(com.facebook.presto.spi.connector.ConnectorIndexProvider) ConnectorFactory(com.facebook.presto.spi.connector.ConnectorFactory) CatalogManager(com.facebook.presto.metadata.CatalogManager) ConnectorMetadataUpdaterProvider(com.facebook.presto.spi.connector.ConnectorMetadataUpdaterProvider) HandleResolver(com.facebook.presto.metadata.HandleResolver) ConnectorAccessControl(com.facebook.presto.spi.connector.ConnectorAccessControl) PartitioningProviderManager(com.facebook.presto.sql.planner.PartitioningProviderManager) StaticSystemTablesProvider(com.facebook.presto.connector.system.StaticSystemTablesProvider) InformationSchemaConnector(com.facebook.presto.connector.informationSchema.InformationSchemaConnector) DelegatingSystemTablesProvider(com.facebook.presto.connector.system.DelegatingSystemTablesProvider) MetadataBasedSystemTablesProvider(com.facebook.presto.connector.system.MetadataBasedSystemTablesProvider) MetadataBasedSystemTablesProvider(com.facebook.presto.connector.system.MetadataBasedSystemTablesProvider) SystemTablesProvider(com.facebook.presto.connector.system.SystemTablesProvider) StaticSystemTablesProvider(com.facebook.presto.connector.system.StaticSystemTablesProvider) DelegatingSystemTablesProvider(com.facebook.presto.connector.system.DelegatingSystemTablesProvider) Catalog(com.facebook.presto.metadata.Catalog) ConnectorId.createInformationSchemaConnectorId(com.facebook.presto.spi.ConnectorId.createInformationSchemaConnectorId) ConnectorId(com.facebook.presto.spi.ConnectorId) ConnectorId.createSystemTablesConnectorId(com.facebook.presto.spi.ConnectorId.createSystemTablesConnectorId)

Example 84 with ConnectorId

use of com.facebook.presto.spi.ConnectorId in project presto by prestodb.

the class CatalogSystemTable method cursor.

@Override
public RecordCursor cursor(ConnectorTransactionHandle transactionHandle, ConnectorSession connectorSession, TupleDomain<Integer> constraint) {
    Session session = toSession(transactionHandle, connectorSession);
    Builder table = InMemoryRecordSet.builder(CATALOG_TABLE);
    for (Map.Entry<String, ConnectorId> entry : listCatalogs(session, metadata, accessControl).entrySet()) {
        table.addRow(entry.getKey(), entry.getValue().toString());
    }
    return table.build().cursor();
}
Also used : TableMetadataBuilder.tableMetadataBuilder(com.facebook.presto.metadata.MetadataUtil.TableMetadataBuilder.tableMetadataBuilder) Builder(com.facebook.presto.spi.InMemoryRecordSet.Builder) Map(java.util.Map) Session(com.facebook.presto.Session) ConnectorSession(com.facebook.presto.spi.ConnectorSession) SystemConnectorSessionUtil.toSession(com.facebook.presto.connector.system.SystemConnectorSessionUtil.toSession) ConnectorId(com.facebook.presto.spi.ConnectorId)

Example 85 with ConnectorId

use of com.facebook.presto.spi.ConnectorId in project presto by prestodb.

the class SessionPropertyManager method getAllSessionProperties.

public List<SessionPropertyValue> getAllSessionProperties(Session session, Map<String, ConnectorId> catalogs) {
    requireNonNull(session, "session is null");
    ImmutableList.Builder<SessionPropertyValue> sessionPropertyValues = ImmutableList.builder();
    Map<String, String> systemProperties = session.getSystemProperties();
    for (PropertyMetadata<?> property : new TreeMap<>(systemSessionProperties).values()) {
        String defaultValue = firstNonNull(property.getDefaultValue(), "").toString();
        String value = systemProperties.getOrDefault(property.getName(), defaultValue);
        sessionPropertyValues.add(new SessionPropertyValue(value, defaultValue, property.getName(), Optional.empty(), property.getName(), property.getDescription(), property.getSqlType().getDisplayName(), property.isHidden()));
    }
    for (Entry<String, ConnectorId> entry : new TreeMap<>(catalogs).entrySet()) {
        String catalog = entry.getKey();
        ConnectorId connectorId = entry.getValue();
        Map<String, String> connectorProperties = session.getConnectorProperties(connectorId);
        for (PropertyMetadata<?> property : new TreeMap<>(connectorSessionProperties.get(connectorId)).values()) {
            String defaultValue = firstNonNull(property.getDefaultValue(), "").toString();
            String value = connectorProperties.getOrDefault(property.getName(), defaultValue);
            sessionPropertyValues.add(new SessionPropertyValue(value, defaultValue, catalog + "." + property.getName(), Optional.of(catalog), property.getName(), property.getDescription(), property.getSqlType().getDisplayName(), property.isHidden()));
        }
    }
    return sessionPropertyValues.build();
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) ConnectorId(com.facebook.presto.spi.ConnectorId)

Aggregations

ConnectorId (com.facebook.presto.spi.ConnectorId)162 ConnectorMetadata (com.facebook.presto.spi.connector.ConnectorMetadata)75 TableHandle (com.facebook.presto.spi.TableHandle)33 Test (org.testng.annotations.Test)29 ConnectorSession (com.facebook.presto.spi.ConnectorSession)26 ConnectorTableHandle (com.facebook.presto.spi.ConnectorTableHandle)18 PrestoException (com.facebook.presto.spi.PrestoException)18 ConnectorTransactionHandle (com.facebook.presto.spi.connector.ConnectorTransactionHandle)18 Session (com.facebook.presto.Session)16 ImmutableList (com.google.common.collect.ImmutableList)16 QualifiedObjectName (com.facebook.presto.common.QualifiedObjectName)15 List (java.util.List)15 PlanNodeId (com.facebook.presto.spi.plan.PlanNodeId)14 Map (java.util.Map)12 Optional (java.util.Optional)12 InMemoryNodeManager (com.facebook.presto.metadata.InMemoryNodeManager)11 ConnectorOutputTableHandle (com.facebook.presto.spi.ConnectorOutputTableHandle)11 SchemaTableName (com.facebook.presto.spi.SchemaTableName)11 ImmutableMap (com.google.common.collect.ImmutableMap)11 ConnectorInsertTableHandle (com.facebook.presto.spi.ConnectorInsertTableHandle)10