Java Code Examples for io.prestosql.spi.HostAddress

The following examples show how to use io.prestosql.spi.HostAddress. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: presto   Source File: KafkaSplit.java    License: Apache License 2.0 6 votes vote down vote up
@JsonCreator
public KafkaSplit(
        @JsonProperty("topicName") String topicName,
        @JsonProperty("keyDataFormat") String keyDataFormat,
        @JsonProperty("messageDataFormat") String messageDataFormat,
        @JsonProperty("keyDataSchemaContents") Optional<String> keyDataSchemaContents,
        @JsonProperty("messageDataSchemaContents") Optional<String> messageDataSchemaContents,
        @JsonProperty("partitionId") int partitionId,
        @JsonProperty("messagesRange") Range messagesRange,
        @JsonProperty("leader") HostAddress leader)
{
    this.topicName = requireNonNull(topicName, "topicName is null");
    this.keyDataFormat = requireNonNull(keyDataFormat, "dataFormat is null");
    this.messageDataFormat = requireNonNull(messageDataFormat, "messageDataFormat is null");
    this.keyDataSchemaContents = keyDataSchemaContents;
    this.messageDataSchemaContents = messageDataSchemaContents;
    this.partitionId = partitionId;
    this.messagesRange = requireNonNull(messagesRange, "messagesRange is null");
    this.leader = requireNonNull(leader, "leader is null");
}
 
Example 2
Source Project: presto   Source File: TestPrometheusSplit.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testAddresses()
{
    // http split with default port
    PrometheusSplit httpSplit = new PrometheusSplit(URI.create("http://prometheus.com/prometheus"));
    assertEquals(httpSplit.getAddresses(), ImmutableList.of(HostAddress.fromString("prometheus.com")));
    assertEquals(httpSplit.isRemotelyAccessible(), true);

    // http split with custom port
    httpSplit = new PrometheusSplit(URI.create("http://prometheus.com:8080/prometheus"));
    assertEquals(httpSplit.getAddresses(), ImmutableList.of(HostAddress.fromParts("prometheus.com", 8080)));
    assertEquals(httpSplit.isRemotelyAccessible(), true);

    // http split with default port
    PrometheusSplit httpsSplit = new PrometheusSplit(URI.create("https://prometheus.com/prometheus"));
    assertEquals(httpsSplit.getAddresses(), ImmutableList.of(HostAddress.fromString("prometheus.com")));
    assertEquals(httpsSplit.isRemotelyAccessible(), true);

    // http split with custom port
    httpsSplit = new PrometheusSplit(URI.create("https://prometheus.com:8443/prometheus"));
    assertEquals(httpsSplit.getAddresses(), ImmutableList.of(HostAddress.fromParts("prometheus.com", 8443)));
    assertEquals(httpsSplit.isRemotelyAccessible(), true);
}
 
Example 3
Source Project: presto   Source File: TestExampleSplit.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testAddresses()
{
    // http split with default port
    ExampleSplit httpSplit = new ExampleSplit(URI.create("http://example.com/example"));
    assertEquals(httpSplit.getAddresses(), ImmutableList.of(HostAddress.fromString("example.com")));
    assertEquals(httpSplit.isRemotelyAccessible(), true);

    // http split with custom port
    httpSplit = new ExampleSplit(URI.create("http://example.com:8080/example"));
    assertEquals(httpSplit.getAddresses(), ImmutableList.of(HostAddress.fromParts("example.com", 8080)));
    assertEquals(httpSplit.isRemotelyAccessible(), true);

    // http split with default port
    ExampleSplit httpsSplit = new ExampleSplit(URI.create("https://example.com/example"));
    assertEquals(httpsSplit.getAddresses(), ImmutableList.of(HostAddress.fromString("example.com")));
    assertEquals(httpsSplit.isRemotelyAccessible(), true);

    // http split with custom port
    httpsSplit = new ExampleSplit(URI.create("https://example.com:8443/example"));
    assertEquals(httpsSplit.getAddresses(), ImmutableList.of(HostAddress.fromParts("example.com", 8443)));
    assertEquals(httpsSplit.isRemotelyAccessible(), true);
}
 
Example 4
Source Project: presto   Source File: RedisSplit.java    License: Apache License 2.0 6 votes vote down vote up
@JsonCreator
public RedisSplit(
        @JsonProperty("schemaName") String schemaName,
        @JsonProperty("tableName") String tableName,
        @JsonProperty("keyDataFormat") String keyDataFormat,
        @JsonProperty("valueDataFormat") String valueDataFormat,
        @JsonProperty("keyName") String keyName,
        @JsonProperty("start") long start,
        @JsonProperty("end") long end,
        @JsonProperty("nodes") List<HostAddress> nodes)
{
    this.schemaName = requireNonNull(schemaName, "schemaName is null");
    this.tableName = requireNonNull(tableName, "tableName is null");
    this.keyDataFormat = requireNonNull(keyDataFormat, "keyDataFormat is null");
    this.valueDataFormat = requireNonNull(valueDataFormat, "valueDataFormat is null");
    this.keyName = keyName;
    this.nodes = ImmutableList.copyOf(requireNonNull(nodes, "nodes is null"));
    this.start = start;
    this.end = end;
    this.valueDataType = toRedisDataType(valueDataFormat);
    this.keyDataType = toRedisDataType(keyDataFormat);
}
 
Example 5
Source Project: presto   Source File: CassandraSplitManager.java    License: Apache License 2.0 6 votes vote down vote up
private List<ConnectorSplit> getSplitsByTokenRange(CassandraTable table, String partitionId, Optional<Long> sessionSplitsPerNode)
{
    String schema = table.getTableHandle().getSchemaName();
    String tableName = table.getTableHandle().getTableName();
    String tokenExpression = table.getTokenExpression();

    ImmutableList.Builder<ConnectorSplit> builder = ImmutableList.builder();
    List<CassandraTokenSplitManager.TokenSplit> tokenSplits = tokenSplitMgr.getSplits(schema, tableName, sessionSplitsPerNode);
    for (CassandraTokenSplitManager.TokenSplit tokenSplit : tokenSplits) {
        String condition = buildTokenCondition(tokenExpression, tokenSplit.getStartToken(), tokenSplit.getEndToken());
        List<HostAddress> addresses = new HostAddressFactory().hostAddressNamesToHostAddressList(tokenSplit.getHosts());
        CassandraSplit split = new CassandraSplit(partitionId, condition, addresses);
        builder.add(split);
    }

    return builder.build();
}
 
Example 6
Source Project: presto   Source File: AccumuloSplit.java    License: Apache License 2.0 6 votes vote down vote up
@JsonCreator
public AccumuloSplit(
        @JsonProperty("ranges") List<WrappedRange> ranges,
        @JsonProperty("hostPort") Optional<String> hostPort)
{
    this.hostPort = requireNonNull(hostPort, "hostPort is null");
    this.ranges = ImmutableList.copyOf(requireNonNull(ranges, "ranges is null"));

    // Parse the host address into a list of addresses, this would be an Accumulo Tablet server or some localhost thing
    if (hostPort.isPresent()) {
        addresses = ImmutableList.of(HostAddress.fromString(hostPort.get()));
    }
    else {
        addresses = ImmutableList.of();
    }
}
 
Example 7
Source Project: presto   Source File: MemoryMetadata.java    License: Apache License 2.0 6 votes vote down vote up
private void updateRowsOnHosts(long tableId, Collection<Slice> fragments)
{
    TableInfo info = tables.get(tableId);
    checkState(
            info != null,
            "Uninitialized tableId [%s.%s]",
            info.getSchemaName(),
            info.getTableName());

    Map<HostAddress, MemoryDataFragment> dataFragments = new HashMap<>(info.getDataFragments());
    for (Slice fragment : fragments) {
        MemoryDataFragment memoryDataFragment = MemoryDataFragment.fromSlice(fragment);
        dataFragments.merge(memoryDataFragment.getHostAddress(), memoryDataFragment, MemoryDataFragment::merge);
    }

    tables.put(tableId, new TableInfo(tableId, info.getSchemaName(), info.getTableName(), info.getColumns(), dataFragments));
}
 
Example 8
Source Project: presto   Source File: TpcdsSplit.java    License: Apache License 2.0 6 votes vote down vote up
@JsonCreator
public TpcdsSplit(
        @JsonProperty("partNumber") int partNumber,
        @JsonProperty("totalParts") int totalParts,
        @JsonProperty("addresses") List<HostAddress> addresses,
        @JsonProperty("noSexism") boolean noSexism)
{
    checkState(partNumber >= 0, "partNumber must be >= 0");
    checkState(totalParts >= 1, "totalParts must be >= 1");
    checkState(totalParts > partNumber, "totalParts must be > partNumber");
    requireNonNull(addresses, "addresses is null");

    this.partNumber = partNumber;
    this.totalParts = totalParts;
    this.addresses = ImmutableList.copyOf(addresses);
    this.noSexism = noSexism;
}
 
Example 9
Source Project: presto   Source File: IcebergSplit.java    License: Apache License 2.0 6 votes vote down vote up
@JsonCreator
public IcebergSplit(
        @JsonProperty("path") String path,
        @JsonProperty("start") long start,
        @JsonProperty("length") long length,
        @JsonProperty("fileFormat") FileFormat fileFormat,
        @JsonProperty("addresses") List<HostAddress> addresses,
        @JsonProperty("partitionKeys") Map<Integer, String> partitionKeys)
{
    this.path = requireNonNull(path, "path is null");
    this.start = start;
    this.length = length;
    this.fileFormat = requireNonNull(fileFormat, "fileFormat is null");
    this.addresses = ImmutableList.copyOf(requireNonNull(addresses, "addresses is null"));
    this.partitionKeys = Collections.unmodifiableMap(requireNonNull(partitionKeys, "partitionKeys is null"));
}
 
Example 10
Source Project: presto   Source File: HeartbeatFailureDetector.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public State getState(HostAddress hostAddress)
{
    for (MonitoringTask task : tasks.values()) {
        if (hostAddress.equals(fromUri(task.uri))) {
            if (!task.isFailed()) {
                return ALIVE;
            }

            Exception lastFailureException = task.getStats().getLastFailureException();
            if (lastFailureException instanceof ConnectException) {
                return GONE;
            }
            if (lastFailureException instanceof SocketTimeoutException) {
                // TODO: distinguish between process unresponsiveness (e.g GC pause) and host reboot
                return UNRESPONSIVE;
            }

            return UNKNOWN;
        }
    }

    return UNKNOWN;
}
 
Example 11
Source Project: presto   Source File: UniformNodeSelector.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Helper method to determine if a split is local to a node irrespective of whether splitAddresses contain port information or not
 */
private static boolean isSplitLocal(List<HostAddress> splitAddresses, HostAddress nodeAddress, SetMultimap<InetAddress, InternalNode> nodesByHost)
{
    for (HostAddress address : splitAddresses) {
        if (nodeAddress.equals(address)) {
            return true;
        }
        InetAddress inetAddress;
        try {
            inetAddress = address.toInetAddress();
        }
        catch (UnknownHostException e) {
            continue;
        }
        if (!address.hasPort()) {
            Set<InternalNode> localNodes = nodesByHost.get(inetAddress);
            return localNodes.stream()
                    .anyMatch(node -> node.getHostAndPort().equals(nodeAddress));
        }
    }
    return false;
}
 
Example 12
Source Project: presto   Source File: TestHostAddressFactory.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testToHostAddressList()
        throws Exception
{
    Set<Host> hosts = ImmutableSet.of(
            new TestHost(
                    new InetSocketAddress(
                            InetAddress.getByAddress(new byte[] {
                                    1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16
                            }),
                            3000)),
            new TestHost(new InetSocketAddress(InetAddress.getByAddress(new byte[] {1, 2, 3, 4}), 3000)));

    HostAddressFactory hostAddressFactory = new HostAddressFactory();
    List<HostAddress> list = hostAddressFactory.toHostAddressList(hosts);

    assertEquals(list.toString(), "[[102:304:506:708:90a:b0c:d0e:f10], 1.2.3.4]");
}
 
Example 13
Source Project: presto   Source File: TestFileBasedNetworkTopology.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testRefresh()
        throws Exception
{
    try (TempFile tempFile = new TempFile()) {
        Files.copy(topologyFile, tempFile.file());

        TestingTicker ticker = new TestingTicker();
        FileBasedNetworkTopology topology = new FileBasedNetworkTopology(tempFile.file(), Duration.valueOf("1d"), ticker);

        assertEquals(topology.locate(HostAddress.fromString("not-exist.example.com")), new NetworkLocation());
        assertEquals(topology.locate(HostAddress.fromString("192.168.0.1")), new NetworkLocation("region1", "rack1", "machine1"));
        assertEquals(topology.locate(HostAddress.fromString("192.168.0.2")), new NetworkLocation("region1", "rack1", "machine2"));
        assertEquals(topology.locate(HostAddress.fromString("192.168.0.3")), new NetworkLocation());

        assertEquals(topology.locate(HostAddress.fromString("new")), new NetworkLocation());
        Files.copy(topologyNewFile, tempFile.file());
        ticker.increment(1, TimeUnit.DAYS);

        assertEquals(topology.locate(HostAddress.fromString("new")), new NetworkLocation("new", "rack", "machine"));
        assertEquals(topology.locate(HostAddress.fromString("not-exist.example.com")), new NetworkLocation());
        assertEquals(topology.locate(HostAddress.fromString("192.168.0.1")), new NetworkLocation("region1", "rack1", "machine5"));
        assertEquals(topology.locate(HostAddress.fromString("192.168.0.2")), new NetworkLocation());
        assertEquals(topology.locate(HostAddress.fromString("192.168.0.3")), new NetworkLocation("region1", "rack1", "machine6"));
    }
}
 
Example 14
Source Project: presto   Source File: KafkaConfig.java    License: Apache License 2.0 5 votes vote down vote up
private static ImmutableSet<HostAddress> parseNodes(String nodes)
{
    Splitter splitter = Splitter.on(',').omitEmptyStrings().trimResults();
    return StreamSupport.stream(splitter.split(nodes).spliterator(), false)
            .map(KafkaConfig::toHostAddress)
            .collect(toImmutableSet());
}
 
Example 15
Source Project: presto   Source File: CassandraSplit.java    License: Apache License 2.0 5 votes vote down vote up
@JsonCreator
public CassandraSplit(
        @JsonProperty("partitionId") String partitionId,
        @JsonProperty("splitCondition") String splitCondition,
        @JsonProperty("addresses") List<HostAddress> addresses)
{
    requireNonNull(partitionId, "partitionName is null");
    requireNonNull(addresses, "addresses is null");

    this.partitionId = partitionId;
    this.addresses = ImmutableList.copyOf(addresses);
    this.splitCondition = splitCondition;
}
 
Example 16
Source Project: presto   Source File: PlainTextKafkaConsumerFactory.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Properties configure()
{
    Properties properties = new Properties();
    properties.put(
            BOOTSTRAP_SERVERS_CONFIG,
            nodes.stream()
                    .map(HostAddress::toString)
                    .collect(joining(",")));
    properties.put(KEY_DESERIALIZER_CLASS_CONFIG, ByteArrayDeserializer.class.getName());
    properties.put(VALUE_DESERIALIZER_CLASS_CONFIG, ByteArrayDeserializer.class.getName());
    properties.put(RECEIVE_BUFFER_CONFIG, Long.toString(kafkaBufferSize.toBytes()));
    properties.put(ENABLE_AUTO_COMMIT_CONFIG, Boolean.toString(false));
    return properties;
}
 
Example 17
Source Project: presto   Source File: MemoryDataFragment.java    License: Apache License 2.0 5 votes vote down vote up
@JsonCreator
public MemoryDataFragment(
        @JsonProperty("hostAddress") HostAddress hostAddress,
        @JsonProperty("rows") long rows)
{
    this.hostAddress = requireNonNull(hostAddress, "hostAddress is null");
    checkArgument(rows >= 0, "Rows number cannot be negative");
    this.rows = rows;
}
 
Example 18
Source Project: presto   Source File: PrometheusSplit.java    License: Apache License 2.0 5 votes vote down vote up
@JsonCreator
public PrometheusSplit(
        @JsonProperty("uri") URI uri)
{
    this.uri = requireNonNull(uri, "uri is null");

    addresses = ImmutableList.of(HostAddress.fromUri(uri));
}
 
Example 19
Source Project: presto   Source File: RedisJedisManager.java    License: Apache License 2.0 5 votes vote down vote up
@PreDestroy
public void tearDown()
{
    for (Map.Entry<HostAddress, JedisPool> entry : jedisPoolCache.asMap().entrySet()) {
        try {
            entry.getValue().destroy();
        }
        catch (Exception e) {
            log.warn(e, "While destroying JedisPool %s:", entry.getKey());
        }
    }
}
 
Example 20
Source Project: presto   Source File: RedisJedisManager.java    License: Apache License 2.0 5 votes vote down vote up
private JedisPool createConsumer(HostAddress host)
{
    log.info("Creating new JedisPool for %s", host);
    return new JedisPool(jedisPoolConfig,
            host.getHostText(),
            host.getPort(),
            toIntExact(redisConnectorConfig.getRedisConnectTimeout().toMillis()),
            redisConnectorConfig.getRedisPassword(),
            redisConnectorConfig.getRedisDataBaseIndex());
}
 
Example 21
Source Project: presto-hbase-connector   Source File: HBaseSplitManager.java    License: Apache License 2.0 5 votes vote down vote up
private List<HostAddress> getHostAddresses(int index) {
    List<HostAddress> addresses = new ArrayList<>();
    // If split-remotely-accessible is true, presto-workers-ip may be null
    if (config.isRandomScheduleRedundantSplit()) {
        String[] workers = config.getPrestoWorkersIp().split(Constant.COMMA);
        String workerIp = workers[index % workers.length];
        addresses.add(HostAddress.fromParts(workerIp, config.getPrestoServerPort()));
    }
    return addresses;
}
 
Example 22
Source Project: presto   Source File: PhoenixSplitManager.java    License: Apache License 2.0 5 votes vote down vote up
private List<HostAddress> getSplitAddresses(PhoenixInputSplit split)
{
    try {
        return ImmutableList.of(HostAddress.fromString(split.getLocations()[0]));
    }
    catch (IOException | InterruptedException e) {
        if (e instanceof InterruptedException) {
            Thread.currentThread().interrupt();
        }
        throw new PrestoException(PHOENIX_INTERNAL_ERROR, "Exception when getting split addresses", e);
    }
}
 
Example 23
Source Project: presto   Source File: PhoenixSplit.java    License: Apache License 2.0 5 votes vote down vote up
@JsonCreator
public PhoenixSplit(
        @JsonProperty("addresses") List<HostAddress> addresses,
        @JsonProperty("phoenixInputSplit") WrappedPhoenixInputSplit wrappedPhoenixInputSplit,
        @JsonProperty("constraint") TupleDomain<ColumnHandle> constraint)
{
    super(Optional.empty());
    this.addresses = requireNonNull(addresses, "addresses is null");
    this.phoenixInputSplit = requireNonNull(wrappedPhoenixInputSplit, "wrappedPhoenixInputSplit is null");
    this.constraint = requireNonNull(constraint, "constraint is null");
}
 
Example 24
Source Project: presto   Source File: InformationSchemaSplitManager.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public ConnectorSplitSource getSplits(ConnectorTransactionHandle transaction, ConnectorSession session, ConnectorTableHandle table, SplitSchedulingStrategy splitSchedulingStrategy)
{
    List<HostAddress> localAddress = ImmutableList.of(nodeManager.getCurrentNode().getHostAndPort());
    ConnectorSplit split = new InformationSchemaSplit(localAddress);
    return new FixedSplitSource(ImmutableList.of(split));
}
 
Example 25
Source Project: presto   Source File: RaptorSplit.java    License: Apache License 2.0 5 votes vote down vote up
public RaptorSplit(
        UUID shardUuid,
        List<HostAddress> addresses,
        OptionalLong transactionId)
{
    this(ImmutableSet.of(shardUuid), OptionalInt.empty(), addresses, transactionId);
}
 
Example 26
Source Project: presto   Source File: UniformNodeSelectorFactory.java    License: Apache License 2.0 5 votes vote down vote up
private NodeMap createNodeMap(Optional<CatalogName> catalogName)
{
    Set<InternalNode> nodes = catalogName
            .map(nodeManager::getActiveConnectorNodes)
            .orElseGet(() -> nodeManager.getNodes(ACTIVE));

    Set<String> coordinatorNodeIds = nodeManager.getCoordinators().stream()
            .map(InternalNode::getNodeIdentifier)
            .collect(toImmutableSet());

    ImmutableSetMultimap.Builder<HostAddress, InternalNode> byHostAndPort = ImmutableSetMultimap.builder();
    ImmutableSetMultimap.Builder<InetAddress, InternalNode> byHost = ImmutableSetMultimap.builder();
    for (InternalNode node : nodes) {
        try {
            byHostAndPort.put(node.getHostAndPort(), node);

            InetAddress host = InetAddress.getByName(node.getInternalUri().getHost());
            byHost.put(host, node);
        }
        catch (UnknownHostException e) {
            if (inaccessibleNodeLogCache.getIfPresent(node) == null) {
                inaccessibleNodeLogCache.put(node, true);
                LOG.warn(e, "Unable to resolve host name for node: %s", node);
            }
        }
    }

    return new NodeMap(byHostAndPort.build(), byHost.build(), ImmutableSetMultimap.of(), coordinatorNodeIds);
}
 
Example 27
Source Project: presto   Source File: TopologyAwareNodeSelectorFactory.java    License: Apache License 2.0 5 votes vote down vote up
private NodeMap createNodeMap(Optional<CatalogName> catalogName)
{
    Set<InternalNode> nodes = catalogName
            .map(nodeManager::getActiveConnectorNodes)
            .orElseGet(() -> nodeManager.getNodes(ACTIVE));

    Set<String> coordinatorNodeIds = nodeManager.getCoordinators().stream()
            .map(InternalNode::getNodeIdentifier)
            .collect(toImmutableSet());

    ImmutableSetMultimap.Builder<HostAddress, InternalNode> byHostAndPort = ImmutableSetMultimap.builder();
    ImmutableSetMultimap.Builder<InetAddress, InternalNode> byHost = ImmutableSetMultimap.builder();
    ImmutableSetMultimap.Builder<NetworkLocation, InternalNode> workersByNetworkPath = ImmutableSetMultimap.builder();
    for (InternalNode node : nodes) {
        if (includeCoordinator || !coordinatorNodeIds.contains(node.getNodeIdentifier())) {
            NetworkLocation location = networkTopology.locate(node.getHostAndPort());
            for (int i = 0; i <= location.getSegments().size(); i++) {
                workersByNetworkPath.put(location.subLocation(0, i), node);
            }
        }
        try {
            byHostAndPort.put(node.getHostAndPort(), node);

            InetAddress host = InetAddress.getByName(node.getInternalUri().getHost());
            byHost.put(host, node);
        }
        catch (UnknownHostException e) {
            if (inaccessibleNodeLogCache.getIfPresent(node) == null) {
                inaccessibleNodeLogCache.put(node, true);
                LOG.warn(e, "Unable to resolve host name for node: %s", node);
            }
        }
    }

    return new NodeMap(byHostAndPort.build(), byHost.build(), workersByNetworkPath.build(), coordinatorNodeIds);
}
 
Example 28
Source Project: presto   Source File: LocalFileRecordCursor.java    License: Apache License 2.0 5 votes vote down vote up
public LocalFileRecordCursor(LocalFileTables localFileTables, List<LocalFileColumnHandle> columns, SchemaTableName tableName, HostAddress address, TupleDomain<LocalFileColumnHandle> predicate)
{
    this.columns = requireNonNull(columns, "columns is null");
    this.address = requireNonNull(address, "address is null");

    fieldToColumnIndex = new int[columns.size()];
    for (int i = 0; i < columns.size(); i++) {
        LocalFileColumnHandle columnHandle = columns.get(i);
        fieldToColumnIndex[i] = columnHandle.getOrdinalPosition();
    }
    this.includeServer = isThisServerIncluded(address, predicate, localFileTables.getTable(tableName));
    this.reader = includeServer ? getFilesReader(localFileTables, predicate, tableName) : null;
}
 
Example 29
Source Project: presto   Source File: HostAddressFactory.java    License: Apache License 2.0 5 votes vote down vote up
public HostAddress toHostAddress(String hostAddressName)
{
    HostAddress address = hostMap.get(hostAddressName);
    if (address == null) {
        address = HostAddress.fromString(hostAddressName);
        hostMap.put(hostAddressName, address);
    }
    return address;
}
 
Example 30
Source Project: presto   Source File: ContinuousTaskStatusFetcher.java    License: Apache License 2.0 5 votes vote down vote up
void updateTaskStatus(TaskStatus newValue)
{
    // change to new value if old value is not changed and new value has a newer version
    AtomicBoolean taskMismatch = new AtomicBoolean();
    taskStatus.setIf(newValue, oldValue -> {
        // did the task instance id change
        if (!isNullOrEmpty(oldValue.getTaskInstanceId()) && !oldValue.getTaskInstanceId().equals(newValue.getTaskInstanceId())) {
            taskMismatch.set(true);
            return false;
        }

        if (oldValue.getState().isDone()) {
            // never update if the task has reached a terminal state
            return false;
        }
        if (newValue.getVersion() < oldValue.getVersion()) {
            // don't update to an older version (same version is ok)
            return false;
        }
        return true;
    });

    if (taskMismatch.get()) {
        // This will also set the task status to FAILED state directly.
        // Additionally, this will issue a DELETE for the task to the worker.
        // While sending the DELETE is not required, it is preferred because a task was created by the previous request.
        onFail.accept(new PrestoException(REMOTE_TASK_MISMATCH, format("%s (%s)", REMOTE_TASK_MISMATCH_ERROR, HostAddress.fromUri(getTaskStatus().getSelf()))));
    }
}