Search in sources :

Example 16 with HostAddress

use of io.trino.spi.HostAddress in project trino by trinodb.

the class InformationSchemaSplitManager method getSplits.

@Override
public ConnectorSplitSource getSplits(ConnectorTransactionHandle transaction, ConnectorSession session, ConnectorTableHandle table, SplitSchedulingStrategy splitSchedulingStrategy, DynamicFilter dynamicFilter) {
    List<HostAddress> localAddress = ImmutableList.of(nodeManager.getCurrentNode().getHostAndPort());
    ConnectorSplit split = new InformationSchemaSplit(localAddress);
    return new FixedSplitSource(ImmutableList.of(split));
}
Also used : FixedSplitSource(io.trino.spi.connector.FixedSplitSource) HostAddress(io.trino.spi.HostAddress) ConnectorSplit(io.trino.spi.connector.ConnectorSplit)

Example 17 with HostAddress

use of io.trino.spi.HostAddress in project trino by trinodb.

the class TestStageTaskSourceFactory method testSourceDistributionTaskSource.

@Test
public void testSourceDistributionTaskSource() {
    TaskSource taskSource = createSourceDistributionTaskSource(ImmutableList.of(), ImmutableListMultimap.of(), 2, 0, 3 * STANDARD_WEIGHT, 1000);
    assertFalse(taskSource.isFinished());
    assertEquals(taskSource.getMoreTasks(), ImmutableList.of());
    assertTrue(taskSource.isFinished());
    Split split1 = createSplit(1);
    Split split2 = createSplit(2);
    Split split3 = createSplit(3);
    taskSource = createSourceDistributionTaskSource(ImmutableList.of(split1), ImmutableListMultimap.of(), 2, 0, 2 * STANDARD_WEIGHT, 1000);
    assertEquals(taskSource.getMoreTasks(), ImmutableList.of(new TaskDescriptor(0, ImmutableListMultimap.of(PLAN_NODE_1, split1), ImmutableListMultimap.of(), new NodeRequirements(Optional.of(CATALOG), ImmutableSet.of(), DataSize.of(4, GIGABYTE)))));
    assertTrue(taskSource.isFinished());
    taskSource = createSourceDistributionTaskSource(ImmutableList.of(split1, split2, split3), ImmutableListMultimap.of(), 3, 0, 2 * STANDARD_WEIGHT, 1000);
    List<TaskDescriptor> tasks = readAllTasks(taskSource);
    assertThat(tasks).hasSize(2);
    assertThat(tasks.get(0).getSplits().values()).hasSize(2);
    assertThat(tasks.get(1).getSplits().values()).hasSize(1);
    assertThat(tasks).allMatch(taskDescriptor -> taskDescriptor.getNodeRequirements().equals(new NodeRequirements(Optional.of(CATALOG), ImmutableSet.of(), DataSize.of(4, GIGABYTE))));
    assertThat(tasks).allMatch(taskDescriptor -> taskDescriptor.getExchangeSourceHandles().isEmpty());
    assertThat(flattenSplits(tasks)).hasSameEntriesAs(ImmutableMultimap.of(PLAN_NODE_1, split1, PLAN_NODE_1, split2, PLAN_NODE_1, split3));
    assertTrue(taskSource.isFinished());
    ImmutableListMultimap<PlanNodeId, ExchangeSourceHandle> replicatedSources = ImmutableListMultimap.of(PLAN_NODE_2, new TestingExchangeSourceHandle(0, 1));
    taskSource = createSourceDistributionTaskSource(ImmutableList.of(split1, split2, split3), replicatedSources, 2, 0, 2 * STANDARD_WEIGHT, 1000);
    tasks = readAllTasks(taskSource);
    assertThat(tasks).hasSize(2);
    assertThat(tasks.get(0).getSplits().values()).hasSize(2);
    assertThat(tasks.get(1).getSplits().values()).hasSize(1);
    assertThat(tasks).allMatch(taskDescriptor -> taskDescriptor.getNodeRequirements().equals(new NodeRequirements(Optional.of(CATALOG), ImmutableSet.of(), DataSize.of(4, GIGABYTE))));
    assertThat(tasks).allMatch(taskDescriptor -> taskDescriptor.getExchangeSourceHandles().equals(replicatedSources));
    assertThat(flattenSplits(tasks)).hasSameEntriesAs(ImmutableMultimap.of(PLAN_NODE_1, split1, PLAN_NODE_1, split2, PLAN_NODE_1, split3));
    assertTrue(taskSource.isFinished());
    // non remotely accessible splits
    ImmutableList<Split> splits = ImmutableList.of(createSplit(1, "host1:8080", "host2:8080"), createSplit(2, "host2:8080"), createSplit(3, "host1:8080", "host3:8080"), createSplit(4, "host3:8080", "host1:8080"), createSplit(5, "host1:8080", "host2:8080"), createSplit(6, "host2:8080", "host3:8080"), createSplit(7, "host3:8080", "host4:8080"));
    taskSource = createSourceDistributionTaskSource(splits, ImmutableListMultimap.of(), 3, 0, 2 * STANDARD_WEIGHT, 1000);
    tasks = readAllTasks(taskSource);
    assertThat(tasks).hasSize(4);
    assertThat(tasks.stream()).allMatch(taskDescriptor -> taskDescriptor.getExchangeSourceHandles().isEmpty());
    assertThat(flattenSplits(tasks)).hasSameEntriesAs(Multimaps.index(splits, split -> PLAN_NODE_1));
    assertThat(tasks).allMatch(task -> task.getSplits().values().stream().allMatch(split -> {
        HostAddress requiredAddress = getOnlyElement(task.getNodeRequirements().getAddresses());
        return split.getAddresses().contains(requiredAddress);
    }));
    assertTrue(taskSource.isFinished());
}
Also used : PlanNodeId(io.trino.sql.planner.plan.PlanNodeId) QueryId(io.trino.spi.QueryId) Arrays(java.util.Arrays) ArbitraryDistributionTaskSource(io.trino.execution.scheduler.StageTaskSourceFactory.ArbitraryDistributionTaskSource) ListMultimap(com.google.common.collect.ListMultimap) SingleDistributionTaskSource(io.trino.execution.scheduler.StageTaskSourceFactory.SingleDistributionTaskSource) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Test(org.testng.annotations.Test) SplitWeight(io.trino.spi.SplitWeight) CatalogName(io.trino.connector.CatalogName) HashMultimap(com.google.common.collect.HashMultimap) PlanNodeId(io.trino.sql.planner.plan.PlanNodeId) Map(java.util.Map) Assert.assertFalse(org.testng.Assert.assertFalse) ImmutableSet(com.google.common.collect.ImmutableSet) IdentityHashMap(java.util.IdentityHashMap) ImmutableMap(com.google.common.collect.ImmutableMap) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) SplitSource(io.trino.split.SplitSource) Objects(java.util.Objects) DataSize(io.airlift.units.DataSize) List(java.util.List) ClassLayout(org.openjdk.jol.info.ClassLayout) SizeOf.sizeOf(io.airlift.slice.SizeOf.sizeOf) Split(io.trino.metadata.Split) ImmutableListMultimap(com.google.common.collect.ImmutableListMultimap) Optional(java.util.Optional) Assertions.assertThat(org.assertj.guava.api.Assertions.assertThat) ExchangeSourceHandle(io.trino.spi.exchange.ExchangeSourceHandle) HostAddress(io.trino.spi.HostAddress) MoreObjects.toStringHelper(com.google.common.base.MoreObjects.toStringHelper) SizeOf.estimatedSizeOf(io.airlift.slice.SizeOf.estimatedSizeOf) Assert.assertEquals(org.testng.Assert.assertEquals) Multimap(com.google.common.collect.Multimap) OptionalInt(java.util.OptionalInt) ExchangeId.createRandomExchangeId(io.trino.spi.exchange.ExchangeId.createRandomExchangeId) Multimaps(com.google.common.collect.Multimaps) HashDistributionTaskSource(io.trino.execution.scheduler.StageTaskSourceFactory.HashDistributionTaskSource) GIGABYTE(io.airlift.units.DataSize.Unit.GIGABYTE) ImmutableList(com.google.common.collect.ImmutableList) Multimaps.toMultimap(com.google.common.collect.Multimaps.toMultimap) SourceDistributionTaskSource(io.trino.execution.scheduler.StageTaskSourceFactory.SourceDistributionTaskSource) Objects.requireNonNull(java.util.Objects.requireNonNull) Lifespan(io.trino.execution.Lifespan) Exchange(io.trino.spi.exchange.Exchange) ImmutableMultimap(com.google.common.collect.ImmutableMultimap) DynamicBucketNodeMap(io.trino.execution.scheduler.group.DynamicBucketNodeMap) TableExecuteContextManager(io.trino.execution.TableExecuteContextManager) ConnectorSplit(io.trino.spi.connector.ConnectorSplit) Iterables.getOnlyElement(com.google.common.collect.Iterables.getOnlyElement) ExchangeContext(io.trino.spi.exchange.ExchangeContext) TestingExchangeSourceHandle(io.trino.execution.scheduler.TestingExchange.TestingExchangeSourceHandle) Assert.assertTrue(org.testng.Assert.assertTrue) BYTE(io.airlift.units.DataSize.Unit.BYTE) ExchangeManager(io.trino.spi.exchange.ExchangeManager) ExchangeSourceHandle(io.trino.spi.exchange.ExchangeSourceHandle) TestingExchangeSourceHandle(io.trino.execution.scheduler.TestingExchange.TestingExchangeSourceHandle) Split(io.trino.metadata.Split) ConnectorSplit(io.trino.spi.connector.ConnectorSplit) HostAddress(io.trino.spi.HostAddress) ArbitraryDistributionTaskSource(io.trino.execution.scheduler.StageTaskSourceFactory.ArbitraryDistributionTaskSource) SingleDistributionTaskSource(io.trino.execution.scheduler.StageTaskSourceFactory.SingleDistributionTaskSource) HashDistributionTaskSource(io.trino.execution.scheduler.StageTaskSourceFactory.HashDistributionTaskSource) SourceDistributionTaskSource(io.trino.execution.scheduler.StageTaskSourceFactory.SourceDistributionTaskSource) TestingExchangeSourceHandle(io.trino.execution.scheduler.TestingExchange.TestingExchangeSourceHandle) Test(org.testng.annotations.Test)

Example 18 with HostAddress

use of io.trino.spi.HostAddress in project trino by trinodb.

the class CassandraSplitManager method getSplitsByTokenRange.

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();
}
Also used : HostAddressFactory(io.trino.plugin.cassandra.util.HostAddressFactory) ImmutableList(com.google.common.collect.ImmutableList) HostAddress(io.trino.spi.HostAddress) ConnectorSplit(io.trino.spi.connector.ConnectorSplit)

Example 19 with HostAddress

use of io.trino.spi.HostAddress in project trino by trinodb.

the class TestHiveSplit method testJsonRoundTrip.

@Test
public void testJsonRoundTrip() {
    ObjectMapperProvider objectMapperProvider = new ObjectMapperProvider();
    objectMapperProvider.setJsonDeserializers(ImmutableMap.of(Type.class, new TypeDeserializer(new TestingTypeManager())));
    JsonCodec<HiveSplit> codec = new JsonCodecFactory(objectMapperProvider).jsonCodec(HiveSplit.class);
    Properties schema = new Properties();
    schema.setProperty("foo", "bar");
    schema.setProperty("bar", "baz");
    ImmutableList<HivePartitionKey> partitionKeys = ImmutableList.of(new HivePartitionKey("a", "apple"), new HivePartitionKey("b", "42"));
    ImmutableList<HostAddress> addresses = ImmutableList.of(HostAddress.fromParts("127.0.0.1", 44), HostAddress.fromParts("127.0.0.1", 45));
    AcidInfo.Builder acidInfoBuilder = AcidInfo.builder(new Path("file:///data/fullacid"));
    acidInfoBuilder.addDeleteDelta(new Path("file:///data/fullacid/delete_delta_0000004_0000004_0000"));
    acidInfoBuilder.addDeleteDelta(new Path("file:///data/fullacid/delete_delta_0000007_0000007_0000"));
    AcidInfo acidInfo = acidInfoBuilder.build().get();
    HiveSplit expected = new HiveSplit("db", "table", "partitionId", "path", 42, 87, 88, Instant.now().toEpochMilli(), schema, partitionKeys, addresses, OptionalInt.empty(), 0, true, TableToPartitionMapping.mapColumnsByIndex(ImmutableMap.of(1, new HiveTypeName("string"))), Optional.of(new HiveSplit.BucketConversion(BUCKETING_V1, 32, 16, ImmutableList.of(createBaseColumn("col", 5, HIVE_LONG, BIGINT, ColumnType.REGULAR, Optional.of("comment"))))), Optional.empty(), false, Optional.of(acidInfo), 555534, // some non-standard value
    SplitWeight.fromProportion(2.0));
    String json = codec.toJson(expected);
    HiveSplit actual = codec.fromJson(json);
    assertEquals(actual.getDatabase(), expected.getDatabase());
    assertEquals(actual.getTable(), expected.getTable());
    assertEquals(actual.getPartitionName(), expected.getPartitionName());
    assertEquals(actual.getPath(), expected.getPath());
    assertEquals(actual.getStart(), expected.getStart());
    assertEquals(actual.getLength(), expected.getLength());
    assertEquals(actual.getEstimatedFileSize(), expected.getEstimatedFileSize());
    assertEquals(actual.getSchema(), expected.getSchema());
    assertEquals(actual.getPartitionKeys(), expected.getPartitionKeys());
    assertEquals(actual.getAddresses(), expected.getAddresses());
    assertEquals(actual.getTableToPartitionMapping().getPartitionColumnCoercions(), expected.getTableToPartitionMapping().getPartitionColumnCoercions());
    assertEquals(actual.getTableToPartitionMapping().getTableToPartitionColumns(), expected.getTableToPartitionMapping().getTableToPartitionColumns());
    assertEquals(actual.getBucketConversion(), expected.getBucketConversion());
    assertEquals(actual.isForceLocalScheduling(), expected.isForceLocalScheduling());
    assertEquals(actual.isS3SelectPushdownEnabled(), expected.isS3SelectPushdownEnabled());
    assertEquals(actual.getAcidInfo().get(), expected.getAcidInfo().get());
    assertEquals(actual.getSplitNumber(), expected.getSplitNumber());
    assertEquals(actual.getSplitWeight(), expected.getSplitWeight());
}
Also used : Path(org.apache.hadoop.fs.Path) Properties(java.util.Properties) HostAddress(io.trino.spi.HostAddress) ObjectMapperProvider(io.airlift.json.ObjectMapperProvider) Type(io.trino.spi.type.Type) ColumnType(io.trino.plugin.hive.HiveColumnHandle.ColumnType) TypeDeserializer(io.trino.plugin.base.TypeDeserializer) JsonCodecFactory(io.airlift.json.JsonCodecFactory) TestingTypeManager(io.trino.spi.type.TestingTypeManager) Test(org.testng.annotations.Test)

Example 20 with HostAddress

use of io.trino.spi.HostAddress in project trino by trinodb.

the class NodeScheduler method selectExactNodes.

public static List<InternalNode> selectExactNodes(NodeMap nodeMap, List<HostAddress> hosts, boolean includeCoordinator) {
    Set<InternalNode> chosen = new LinkedHashSet<>();
    Set<String> coordinatorIds = nodeMap.getCoordinatorNodeIds();
    for (HostAddress host : hosts) {
        nodeMap.getNodesByHostAndPort().get(host).stream().filter(node -> includeCoordinator || !coordinatorIds.contains(node.getNodeIdentifier())).forEach(chosen::add);
        InetAddress address;
        try {
            address = host.toInetAddress();
        } catch (UnknownHostException e) {
            // skip hosts that don't resolve
            continue;
        }
        // consider a split with a host without a port as being accessible by all nodes in that host
        if (!host.hasPort()) {
            nodeMap.getNodesByHost().get(address).stream().filter(node -> includeCoordinator || !coordinatorIds.contains(node.getNodeIdentifier())).forEach(chosen::add);
        }
    }
    // if the chosen set is empty and the host is the coordinator, force pick the coordinator
    if (chosen.isEmpty() && !includeCoordinator) {
        for (HostAddress host : hosts) {
            // In the code below, before calling `chosen::add`, it could have been checked that
            // `coordinatorIds.contains(node.getNodeIdentifier())`. But checking the condition isn't necessary
            // because every node satisfies it. Otherwise, `chosen` wouldn't have been empty.
            chosen.addAll(nodeMap.getNodesByHostAndPort().get(host));
            InetAddress address;
            try {
                address = host.toInetAddress();
            } catch (UnknownHostException e) {
                // skip hosts that don't resolve
                continue;
            }
            // consider a split with a host without a port as being accessible by all nodes in that host
            if (!host.hasPort()) {
                chosen.addAll(nodeMap.getNodesByHost().get(address));
            }
        }
    }
    return ImmutableList.copyOf(chosen);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) NodeTaskMap(io.trino.execution.NodeTaskMap) HashMap(java.util.HashMap) Multimap(com.google.common.collect.Multimap) SplitWeight(io.trino.spi.SplitWeight) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) InetAddress(java.net.InetAddress) HashSet(java.util.HashSet) CatalogName(io.trino.connector.CatalogName) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) HashMultimap(com.google.common.collect.HashMultimap) ImmutableList(com.google.common.collect.ImmutableList) MoreFutures.whenAnyCompleteCancelOthers(io.airlift.concurrent.MoreFutures.whenAnyCompleteCancelOthers) Map(java.util.Map) Objects.requireNonNull(java.util.Objects.requireNonNull) ImmutableMultimap(com.google.common.collect.ImmutableMultimap) LinkedHashSet(java.util.LinkedHashSet) Futures.immediateVoidFuture(com.google.common.util.concurrent.Futures.immediateVoidFuture) Iterator(java.util.Iterator) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) RemoteTask(io.trino.execution.RemoteTask) Set(java.util.Set) UnknownHostException(java.net.UnknownHostException) MoreExecutors.directExecutor(com.google.common.util.concurrent.MoreExecutors.directExecutor) Objects(java.util.Objects) Futures(com.google.common.util.concurrent.Futures) InternalNode(io.trino.metadata.InternalNode) List(java.util.List) Math.addExact(java.lang.Math.addExact) Split(io.trino.metadata.Split) Optional(java.util.Optional) HostAddress(io.trino.spi.HostAddress) Session(io.trino.Session) UnknownHostException(java.net.UnknownHostException) InternalNode(io.trino.metadata.InternalNode) HostAddress(io.trino.spi.HostAddress) InetAddress(java.net.InetAddress)

Aggregations

HostAddress (io.trino.spi.HostAddress)24 ImmutableList (com.google.common.collect.ImmutableList)9 ConnectorSplit (io.trino.spi.connector.ConnectorSplit)8 Test (org.testng.annotations.Test)7 InternalNode (io.trino.metadata.InternalNode)6 HashSet (java.util.HashSet)5 List (java.util.List)5 Map (java.util.Map)5 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)4 ImmutableSet (com.google.common.collect.ImmutableSet)4 HashMap (java.util.HashMap)4 Objects.requireNonNull (java.util.Objects.requireNonNull)4 Split (io.trino.metadata.Split)3 TrinoException (io.trino.spi.TrinoException)3 FixedSplitSource (io.trino.spi.connector.FixedSplitSource)3 Objects (java.util.Objects)3 Properties (java.util.Properties)3 Host (com.datastax.driver.core.Host)2 HashMultimap (com.google.common.collect.HashMultimap)2 ImmutableMultimap (com.google.common.collect.ImmutableMultimap)2