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;
}
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();
}
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);
}
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);
}
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());
}
Aggregations