Search in sources :

Example 6 with ConnectorId

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

the class DiscoveryNodeManager method refreshNodesInternal.

private synchronized PrestoNode refreshNodesInternal() {
    lastUpdateTimestamp = System.nanoTime();
    // This is currently a blacklist.
    // TODO: make it a whitelist (a failure-detecting service selector) and maybe build in support for injecting this in airlift
    Set<ServiceDescriptor> services = serviceSelector.selectAllServices().stream().filter(service -> !failureDetector.getFailed().contains(service)).collect(toImmutableSet());
    PrestoNode currentNode = null;
    ImmutableSet.Builder<Node> activeNodesBuilder = ImmutableSet.builder();
    ImmutableSet.Builder<Node> inactiveNodesBuilder = ImmutableSet.builder();
    ImmutableSet.Builder<Node> shuttingDownNodesBuilder = ImmutableSet.builder();
    ImmutableSet.Builder<Node> coordinatorsBuilder = ImmutableSet.builder();
    ImmutableSetMultimap.Builder<ConnectorId, Node> byConnectorIdBuilder = ImmutableSetMultimap.builder();
    for (ServiceDescriptor service : services) {
        URI uri = getHttpUri(service);
        NodeVersion nodeVersion = getNodeVersion(service);
        boolean coordinator = isCoordinator(service);
        if (uri != null && nodeVersion != null) {
            PrestoNode node = new PrestoNode(service.getNodeId(), uri, nodeVersion, coordinator);
            NodeState nodeState = getNodeState(node);
            // record current node
            if (node.getNodeIdentifier().equals(nodeInfo.getNodeId())) {
                currentNode = node;
                checkState(currentNode.getNodeVersion().equals(expectedNodeVersion), "INVARIANT: current node version (%s) should be equal to %s", currentNode.getNodeVersion(), expectedNodeVersion);
            }
            switch(nodeState) {
                case ACTIVE:
                    activeNodesBuilder.add(node);
                    if (coordinator) {
                        coordinatorsBuilder.add(node);
                    }
                    // record available active nodes organized by connector id
                    String connectorIds = service.getProperties().get("connectorIds");
                    if (connectorIds != null) {
                        connectorIds = connectorIds.toLowerCase(ENGLISH);
                        for (String connectorId : CONNECTOR_ID_SPLITTER.split(connectorIds)) {
                            byConnectorIdBuilder.put(new ConnectorId(connectorId), node);
                        }
                    }
                    // always add system connector
                    byConnectorIdBuilder.put(new ConnectorId(GlobalSystemConnector.NAME), node);
                    break;
                case INACTIVE:
                    inactiveNodesBuilder.add(node);
                    break;
                case SHUTTING_DOWN:
                    shuttingDownNodesBuilder.add(node);
                    break;
                default:
                    throw new IllegalArgumentException("Unknown node state " + nodeState);
            }
        }
    }
    if (allNodes != null) {
        // log node that are no longer active (but not shutting down)
        SetView<Node> missingNodes = difference(allNodes.getActiveNodes(), Sets.union(activeNodesBuilder.build(), shuttingDownNodesBuilder.build()));
        for (Node missingNode : missingNodes) {
            log.info("Previously active node is missing: %s (last seen at %s)", missingNode.getNodeIdentifier(), missingNode.getHostAndPort());
        }
    }
    allNodes = new AllNodes(activeNodesBuilder.build(), inactiveNodesBuilder.build(), shuttingDownNodesBuilder.build());
    activeNodesByConnectorId = byConnectorIdBuilder.build();
    coordinators = coordinatorsBuilder.build();
    checkState(currentNode != null, "INVARIANT: current node not returned from service selector");
    return currentNode;
}
Also used : HttpClient(io.airlift.http.client.HttpClient) ServiceType(io.airlift.discovery.client.ServiceType) Logger(io.airlift.log.Logger) URISyntaxException(java.net.URISyntaxException) NodeInfo(io.airlift.node.NodeInfo) NodeVersion(com.facebook.presto.client.NodeVersion) Duration(io.airlift.units.Duration) ACTIVE(com.facebook.presto.spi.NodeState.ACTIVE) ServiceSelector(io.airlift.discovery.client.ServiceSelector) Inject(javax.inject.Inject) PreDestroy(javax.annotation.PreDestroy) Sets.difference(com.google.common.collect.Sets.difference) Executors.newSingleThreadScheduledExecutor(java.util.concurrent.Executors.newSingleThreadScheduledExecutor) Node(com.facebook.presto.spi.Node) Managed(org.weakref.jmx.Managed) GlobalSystemConnector(com.facebook.presto.connector.system.GlobalSystemConnector) Arrays.asList(java.util.Arrays.asList) Objects.requireNonNull(java.util.Objects.requireNonNull) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) ImmutableCollectors.toImmutableSet(com.facebook.presto.util.ImmutableCollectors.toImmutableSet) URI(java.net.URI) Splitter(com.google.common.base.Splitter) ENGLISH(java.util.Locale.ENGLISH) ImmutableSetMultimap(com.google.common.collect.ImmutableSetMultimap) ImmutableSet(com.google.common.collect.ImmutableSet) SHUTTING_DOWN(com.facebook.presto.spi.NodeState.SHUTTING_DOWN) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) SetView(com.google.common.collect.Sets.SetView) Set(java.util.Set) ThreadSafe(javax.annotation.concurrent.ThreadSafe) GuardedBy(javax.annotation.concurrent.GuardedBy) Threads.threadsNamed(io.airlift.concurrent.Threads.threadsNamed) NodeState(com.facebook.presto.spi.NodeState) SetMultimap(com.google.common.collect.SetMultimap) Sets(com.google.common.collect.Sets) Preconditions.checkState(com.google.common.base.Preconditions.checkState) TimeUnit(java.util.concurrent.TimeUnit) ServiceDescriptor(io.airlift.discovery.client.ServiceDescriptor) FailureDetector(com.facebook.presto.failureDetector.FailureDetector) PostConstruct(javax.annotation.PostConstruct) HttpUriBuilder.uriBuilderFrom(io.airlift.http.client.HttpUriBuilder.uriBuilderFrom) Optional(java.util.Optional) ConnectorId(com.facebook.presto.connector.ConnectorId) INACTIVE(com.facebook.presto.spi.NodeState.INACTIVE) NodeState(com.facebook.presto.spi.NodeState) ImmutableSetMultimap(com.google.common.collect.ImmutableSetMultimap) Node(com.facebook.presto.spi.Node) URI(java.net.URI) NodeVersion(com.facebook.presto.client.NodeVersion) ImmutableCollectors.toImmutableSet(com.facebook.presto.util.ImmutableCollectors.toImmutableSet) ImmutableSet(com.google.common.collect.ImmutableSet) ServiceDescriptor(io.airlift.discovery.client.ServiceDescriptor) ConnectorId(com.facebook.presto.connector.ConnectorId)

Example 7 with ConnectorId

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

the class SqlQueryExecution method extractConnectors.

private Set<ConnectorId> extractConnectors(Analysis analysis) {
    ImmutableSet.Builder<ConnectorId> connectors = ImmutableSet.builder();
    for (TableHandle tableHandle : analysis.getTables()) {
        connectors.add(tableHandle.getConnectorId());
    }
    if (analysis.getInsert().isPresent()) {
        TableHandle target = analysis.getInsert().get().getTarget();
        connectors.add(target.getConnectorId());
    }
    return connectors.build();
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) TableHandle(com.facebook.presto.metadata.TableHandle) ConnectorId(com.facebook.presto.connector.ConnectorId)

Example 8 with ConnectorId

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

the class MetadataManager method createView.

@Override
public void createView(Session session, QualifiedObjectName viewName, String viewData, boolean replace) {
    CatalogMetadata catalogMetadata = getCatalogMetadataForWrite(session, viewName.getCatalogName());
    ConnectorId connectorId = catalogMetadata.getConnectorId();
    ConnectorMetadata metadata = catalogMetadata.getMetadata();
    metadata.createView(session.toConnectorSession(connectorId), viewName.asSchemaTableName(), viewData, replace);
}
Also used : ConnectorMetadata(com.facebook.presto.spi.connector.ConnectorMetadata) ConnectorId(com.facebook.presto.connector.ConnectorId)

Example 9 with ConnectorId

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

the class MetadataManager method listViews.

@Override
public List<QualifiedObjectName> listViews(Session session, QualifiedTablePrefix prefix) {
    requireNonNull(prefix, "prefix is null");
    Optional<CatalogMetadata> catalog = getOptionalCatalogMetadata(session, prefix.getCatalogName());
    Set<QualifiedObjectName> views = new LinkedHashSet<>();
    if (catalog.isPresent()) {
        CatalogMetadata catalogMetadata = catalog.get();
        String schemaNameOrNull = prefix.getSchemaName().orElse(null);
        for (ConnectorId connectorId : catalogMetadata.listConnectorIds()) {
            ConnectorMetadata metadata = catalogMetadata.getMetadataFor(connectorId);
            ConnectorSession connectorSession = session.toConnectorSession(connectorId);
            metadata.listViews(connectorSession, schemaNameOrNull).stream().map(convertFromSchemaTableName(prefix.getCatalogName())::apply).forEach(views::add);
        }
    }
    return ImmutableList.copyOf(views);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ConnectorSession(com.facebook.presto.spi.ConnectorSession) ConnectorMetadata(com.facebook.presto.spi.connector.ConnectorMetadata) ConnectorId(com.facebook.presto.connector.ConnectorId)

Example 10 with ConnectorId

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

the class MetadataManager method getLayouts.

@Override
public List<TableLayoutResult> getLayouts(Session session, TableHandle table, Constraint<ColumnHandle> constraint, Optional<Set<ColumnHandle>> desiredColumns) {
    if (constraint.getSummary().isNone()) {
        return ImmutableList.of();
    }
    ConnectorId connectorId = table.getConnectorId();
    ConnectorTableHandle connectorTable = table.getConnectorHandle();
    CatalogMetadata catalogMetadata = getCatalogMetadata(session, connectorId);
    ConnectorMetadata metadata = catalogMetadata.getMetadataFor(connectorId);
    ConnectorTransactionHandle transaction = catalogMetadata.getTransactionHandleFor(connectorId);
    ConnectorSession connectorSession = session.toConnectorSession(connectorId);
    List<ConnectorTableLayoutResult> layouts = metadata.getTableLayouts(connectorSession, connectorTable, constraint, desiredColumns);
    return layouts.stream().map(layout -> new TableLayoutResult(fromConnectorLayout(connectorId, transaction, layout.getTableLayout()), layout.getUnenforcedConstraint())).collect(toImmutableList());
}
Also used : TypeManager(com.facebook.presto.spi.type.TypeManager) TypeRegistry(com.facebook.presto.type.TypeRegistry) BETWEEN(com.facebook.presto.spi.function.OperatorType.BETWEEN) ConnectorTransactionHandle(com.facebook.presto.spi.connector.ConnectorTransactionHandle) TableIdentity(com.facebook.presto.spi.TableIdentity) BIGINT(com.facebook.presto.spi.type.BigintType.BIGINT) Privilege(com.facebook.presto.spi.security.Privilege) ObjectMapperProvider(io.airlift.json.ObjectMapperProvider) SchemaTableName(com.facebook.presto.spi.SchemaTableName) HashMultimap(com.google.common.collect.HashMultimap) BOOLEAN(com.facebook.presto.spi.type.BooleanType.BOOLEAN) Map(java.util.Map) ImmutableCollectors.toImmutableList(com.facebook.presto.util.ImmutableCollectors.toImmutableList) LESS_THAN(com.facebook.presto.spi.function.OperatorType.LESS_THAN) LESS_THAN_OR_EQUAL(com.facebook.presto.spi.function.OperatorType.LESS_THAN_OR_EQUAL) ENGLISH(java.util.Locale.ENGLISH) ImmutableSet(com.google.common.collect.ImmutableSet) EQUAL(com.facebook.presto.spi.function.OperatorType.EQUAL) ImmutableMap(com.google.common.collect.ImmutableMap) Collection(java.util.Collection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) ConnectorResolvedIndex(com.facebook.presto.spi.ConnectorResolvedIndex) String.format(java.lang.String.format) ConnectorSession(com.facebook.presto.spi.ConnectorSession) FeaturesConfig(com.facebook.presto.sql.analyzer.FeaturesConfig) TupleDomain(com.facebook.presto.spi.predicate.TupleDomain) List(java.util.List) ColumnMetadata(com.facebook.presto.spi.ColumnMetadata) OperatorType(com.facebook.presto.spi.function.OperatorType) QualifiedObjectName.convertFromSchemaTableName(com.facebook.presto.metadata.QualifiedObjectName.convertFromSchemaTableName) JsonCodecFactory(io.airlift.json.JsonCodecFactory) Entry(java.util.Map.Entry) Optional(java.util.Optional) GREATER_THAN(com.facebook.presto.spi.function.OperatorType.GREATER_THAN) ConnectorId(com.facebook.presto.connector.ConnectorId) Joiner(com.google.common.base.Joiner) JsonCodec(io.airlift.json.JsonCodec) TypeSignature(com.facebook.presto.spi.type.TypeSignature) ConnectorMetadata(com.facebook.presto.spi.connector.ConnectorMetadata) QualifiedName(com.facebook.presto.sql.tree.QualifiedName) Slice(io.airlift.slice.Slice) HASH_CODE(com.facebook.presto.spi.function.OperatorType.HASH_CODE) ConnectorTableHandle(com.facebook.presto.spi.ConnectorTableHandle) HashMap(java.util.HashMap) ConnectorOutputTableHandle(com.facebook.presto.spi.ConnectorOutputTableHandle) PrestoException(com.facebook.presto.spi.PrestoException) Multimap(com.google.common.collect.Multimap) ArrayList(java.util.ArrayList) ConcurrentMap(java.util.concurrent.ConcurrentMap) Inject(javax.inject.Inject) LinkedHashMap(java.util.LinkedHashMap) OptionalLong(java.util.OptionalLong) BlockEncodingSerde(com.facebook.presto.spi.block.BlockEncodingSerde) ImmutableList(com.google.common.collect.ImmutableList) Type(com.facebook.presto.spi.type.Type) Objects.requireNonNull(java.util.Objects.requireNonNull) TransactionManager(com.facebook.presto.transaction.TransactionManager) LinkedHashSet(java.util.LinkedHashSet) ConnectorInsertTableHandle(com.facebook.presto.spi.ConnectorInsertTableHandle) ConnectorTableMetadata(com.facebook.presto.spi.ConnectorTableMetadata) NOT_EQUAL(com.facebook.presto.spi.function.OperatorType.NOT_EQUAL) ConnectorOutputMetadata(com.facebook.presto.spi.connector.ConnectorOutputMetadata) Session(com.facebook.presto.Session) CatalogSchemaName(com.facebook.presto.spi.CatalogSchemaName) ConnectorTableLayout(com.facebook.presto.spi.ConnectorTableLayout) ColumnIdentity(com.facebook.presto.spi.ColumnIdentity) Constraint(com.facebook.presto.spi.Constraint) ConnectorTableLayoutResult(com.facebook.presto.spi.ConnectorTableLayoutResult) INVALID_VIEW(com.facebook.presto.spi.StandardErrorCode.INVALID_VIEW) TypeDeserializer(com.facebook.presto.type.TypeDeserializer) SYNTAX_ERROR(com.facebook.presto.spi.StandardErrorCode.SYNTAX_ERROR) SchemaTablePrefix(com.facebook.presto.spi.SchemaTablePrefix) ColumnHandle(com.facebook.presto.spi.ColumnHandle) ViewColumn(com.facebook.presto.metadata.ViewDefinition.ViewColumn) QueryId(com.facebook.presto.spi.QueryId) GREATER_THAN_OR_EQUAL(com.facebook.presto.spi.function.OperatorType.GREATER_THAN_OR_EQUAL) ConnectorNewTableLayout(com.facebook.presto.spi.ConnectorNewTableLayout) VisibleForTesting(com.google.common.annotations.VisibleForTesting) TransactionManager.createTestTransactionManager(com.facebook.presto.transaction.TransactionManager.createTestTransactionManager) TableLayout.fromConnectorLayout(com.facebook.presto.metadata.TableLayout.fromConnectorLayout) ConnectorViewDefinition(com.facebook.presto.spi.ConnectorViewDefinition) BlockEncodingManager(com.facebook.presto.block.BlockEncodingManager) ConnectorTableLayoutResult(com.facebook.presto.spi.ConnectorTableLayoutResult) ConnectorTransactionHandle(com.facebook.presto.spi.connector.ConnectorTransactionHandle) ConnectorSession(com.facebook.presto.spi.ConnectorSession) ConnectorMetadata(com.facebook.presto.spi.connector.ConnectorMetadata) ConnectorTableLayoutResult(com.facebook.presto.spi.ConnectorTableLayoutResult) ConnectorId(com.facebook.presto.connector.ConnectorId) ConnectorTableHandle(com.facebook.presto.spi.ConnectorTableHandle)

Aggregations

ConnectorId (com.facebook.presto.connector.ConnectorId)76 ConnectorMetadata (com.facebook.presto.spi.connector.ConnectorMetadata)39 ConnectorSession (com.facebook.presto.spi.ConnectorSession)14 Session (com.facebook.presto.Session)12 PrestoException (com.facebook.presto.spi.PrestoException)9 ConnectorTransactionHandle (com.facebook.presto.spi.connector.ConnectorTransactionHandle)7 Test (org.testng.annotations.Test)7 ConnectorId.createInformationSchemaConnectorId (com.facebook.presto.connector.ConnectorId.createInformationSchemaConnectorId)5 ConnectorId.createSystemTablesConnectorId (com.facebook.presto.connector.ConnectorId.createSystemTablesConnectorId)5 TableHandle (com.facebook.presto.metadata.TableHandle)5 ConnectorTableMetadata (com.facebook.presto.spi.ConnectorTableMetadata)5 SchemaTableName (com.facebook.presto.spi.SchemaTableName)5 PlanNodeId (com.facebook.presto.sql.planner.plan.PlanNodeId)5 ImmutableList (com.google.common.collect.ImmutableList)5 QualifiedObjectName (com.facebook.presto.metadata.QualifiedObjectName)4 QualifiedObjectName.convertFromSchemaTableName (com.facebook.presto.metadata.QualifiedObjectName.convertFromSchemaTableName)4 SessionPropertyManager (com.facebook.presto.metadata.SessionPropertyManager)4 ConnectorInsertTableHandle (com.facebook.presto.spi.ConnectorInsertTableHandle)4 SemanticException (com.facebook.presto.sql.analyzer.SemanticException)4 TransactionManager (com.facebook.presto.transaction.TransactionManager)4