Search in sources :

Example 16 with KsqlHostInfo

use of io.confluent.ksql.util.KsqlHostInfo in project ksql by confluentinc.

the class KsLocatorTest method shouldReturnLocalOwnerIfExplicitlyLocalHostOnSamePortAsSuppliedLocalHost.

@Test
public void shouldReturnLocalOwnerIfExplicitlyLocalHostOnSamePortAsSuppliedLocalHost() {
    // Given:
    final HostInfo localHostInfo = new HostInfo("LocalHOST", LOCAL_HOST_URL.getPort());
    final KsqlHostInfo localHost = locator.asKsqlHost(localHostInfo);
    getActiveAndStandbyMetadata(localHostInfo);
    when(activeFilter.filter(eq(localHost))).thenReturn(Host.include(localHost));
    when(livenessFilter.filter(eq(localHost))).thenReturn(Host.include(localHost));
    // When:
    final List<KsqlPartitionLocation> result = locator.locate(ImmutableList.of(KEY), routingOptions, routingFilterFactoryActive, false);
    // Then:
    List<KsqlNode> nodeList = result.get(0).getNodes();
    assertThat(nodeList.stream().findFirst().map(KsqlNode::isLocal), is(Optional.of(true)));
}
Also used : KsqlHostInfo(io.confluent.ksql.util.KsqlHostInfo) KsqlPartitionLocation(io.confluent.ksql.execution.streams.materialization.Locator.KsqlPartitionLocation) KsqlNode(io.confluent.ksql.execution.streams.materialization.Locator.KsqlNode) HostInfo(org.apache.kafka.streams.state.HostInfo) KsqlHostInfo(io.confluent.ksql.util.KsqlHostInfo) Test(org.junit.Test)

Example 17 with KsqlHostInfo

use of io.confluent.ksql.util.KsqlHostInfo in project ksql by confluentinc.

the class HARoutingTest method setUp.

@Before
public void setUp() {
    when(pullPhysicalPlan.getMaterialization()).thenReturn(materialization);
    when(pullPhysicalPlan.getMaterialization().locator()).thenReturn(locator);
    when(statement.getStatementText()).thenReturn("foo");
    when(statement.getSessionConfig()).thenReturn(SessionConfig.of(ksqlConfig, ImmutableMap.of()));
    when(node1.isLocal()).thenReturn(true);
    when(node2.isLocal()).thenReturn(false);
    when(node1.location()).thenReturn(URI.create("http://node1:8088"));
    when(node2.location()).thenReturn(URI.create("http://node2:8089"));
    when(badNode.location()).thenReturn(URI.create("http://badnode:8090"));
    when(node1.getHost()).thenReturn(Host.include(new KsqlHostInfo("node1", 8088)));
    when(node2.getHost()).thenReturn(Host.include(new KsqlHostInfo("node2", 8089)));
    when(badNode.getHost()).thenReturn(Host.exclude(new KsqlHostInfo("badnode", 8090), "BAD"));
    location1 = new PartitionLocation(Optional.empty(), 1, ImmutableList.of(node1, node2));
    location2 = new PartitionLocation(Optional.empty(), 2, ImmutableList.of(node2, node1));
    location3 = new PartitionLocation(Optional.empty(), 3, ImmutableList.of(node1, node2));
    location4 = new PartitionLocation(Optional.empty(), 4, ImmutableList.of(node2, node1));
    location5 = new PartitionLocation(Optional.empty(), 4, ImmutableList.of(node2));
    // We require at least two threads, one for the orchestrator, and the other for the partitions.
    when(ksqlConfig.getInt(KsqlConfig.KSQL_QUERY_PULL_THREAD_POOL_SIZE_CONFIG)).thenReturn(1);
    when(ksqlConfig.getInt(KsqlConfig.KSQL_QUERY_PULL_ROUTER_THREAD_POOL_SIZE_CONFIG)).thenReturn(1);
    when(serviceContext.getKsqlClient()).thenReturn(ksqlClient);
    pullMetrics = new PullQueryExecutorMetrics(KSQL_SERVICE_ID, Collections.emptyMap(), time, new Metrics());
    haRouting = new HARouting(routingFilterFactory, Optional.of(pullMetrics), ksqlConfig);
}
Also used : Metrics(org.apache.kafka.common.metrics.Metrics) PullQueryExecutorMetrics(io.confluent.ksql.internal.PullQueryExecutorMetrics) KsqlHostInfo(io.confluent.ksql.util.KsqlHostInfo) PullQueryExecutorMetrics(io.confluent.ksql.internal.PullQueryExecutorMetrics) PartitionLocation(io.confluent.ksql.execution.streams.materialization.ks.KsLocator.PartitionLocation) KsqlPartitionLocation(io.confluent.ksql.execution.streams.materialization.Locator.KsqlPartitionLocation) Before(org.junit.Before)

Example 18 with KsqlHostInfo

use of io.confluent.ksql.util.KsqlHostInfo in project ksql by confluentinc.

the class LagReportingAgent method receiveHostLag.

/**
 * Stores the host lag received from a remote Ksql server.
 * @param lagReportingMessage The host lag information sent directly from the other node.
 */
public void receiveHostLag(final LagReportingMessage lagReportingMessage) {
    final HostStoreLags hostStoreLags = lagReportingMessage.getHostStoreLags();
    final long updateTimeMs = hostStoreLags.getUpdateTimeMs();
    final KsqlHostInfoEntity KsqlHostInfoEntity = lagReportingMessage.getKsqlHost();
    final KsqlHostInfo KsqlHostInfo = KsqlHostInfoEntity.toKsqlHost();
    LOG.debug("Receive lag at: {} from host: {} lag: {} ", updateTimeMs, KsqlHostInfoEntity, hostStoreLags.getStateStoreLags());
    receivedLagInfo.compute(KsqlHostInfo, (hi, previousHostLagInfo) -> previousHostLagInfo != null && previousHostLagInfo.getUpdateTimeMs() > updateTimeMs ? previousHostLagInfo : hostStoreLags);
}
Also used : HostStoreLags(io.confluent.ksql.rest.entity.HostStoreLags) KsqlHostInfo(io.confluent.ksql.util.KsqlHostInfo) KsqlHostInfoEntity(io.confluent.ksql.rest.entity.KsqlHostInfoEntity)

Example 19 with KsqlHostInfo

use of io.confluent.ksql.util.KsqlHostInfo in project ksql by confluentinc.

the class KsLocator method getFilteredHosts.

/**
 * Returns the filtered, ordered list of nodes which host the given partition. The returned nodes
 * will be contacted to run the query, in order.
 * @param routingOptions The routing options to use when determining the list of nodes
 * @param routingFilterFactory The factory used to create the RoutingFilter used to filter the
 *                             list of nodes
 * @param activeHost Which node is active for the given partition
 * @param standByHosts Which nodes are standbys for the given partition
 * @param partition The partition being located
 * @return The filtered, ordered list of nodes used to run the given query
 */
private List<KsqlNode> getFilteredHosts(final RoutingOptions routingOptions, final RoutingFilterFactory routingFilterFactory, final HostInfo activeHost, final Set<HostInfo> standByHosts, final int partition) {
    // If the lookup is for a forwarded request, only filter localhost
    final List<KsqlHostInfo> allHosts;
    if (routingOptions.getIsSkipForwardRequest()) {
        LOG.debug("Before filtering: Local host {} ", localHost);
        allHosts = ImmutableList.of(new KsqlHostInfo(localHost.getHost(), localHost.getPort()));
    } else {
        LOG.debug("Before filtering: Active host {} , standby hosts {}", activeHost, standByHosts);
        allHosts = Stream.concat(Stream.of(activeHost), standByHosts.stream()).map(this::asKsqlHost).collect(Collectors.toList());
    }
    final RoutingFilter routingFilter = routingFilterFactory.createRoutingFilter(routingOptions, allHosts, activeHost, applicationId, storeName, partition);
    // Filter out hosts based on active, liveness and max lag filters.
    // The list is ordered by routing preference: active node is first, then standby nodes.
    // If heartbeat is not enabled, all hosts are considered alive.
    // If the request is forwarded internally from another ksql server, only the max lag filter
    // is applied.
    final ImmutableList<KsqlNode> filteredHosts = allHosts.stream().map(routingFilter::filter).map(this::asNode).collect(ImmutableList.toImmutableList());
    LOG.debug("Filtered and ordered hosts: {}", filteredHosts);
    return filteredHosts;
}
Also used : RoutingFilter(io.confluent.ksql.execution.streams.RoutingFilter) KsqlHostInfo(io.confluent.ksql.util.KsqlHostInfo)

Aggregations

KsqlHostInfo (io.confluent.ksql.util.KsqlHostInfo)19 HostInfo (org.apache.kafka.streams.state.HostInfo)9 Test (org.junit.Test)7 KsqlPartitionLocation (io.confluent.ksql.execution.streams.materialization.Locator.KsqlPartitionLocation)6 KsqlNode (io.confluent.ksql.execution.streams.materialization.Locator.KsqlNode)5 Before (org.junit.Before)4 HostStatus (io.confluent.ksql.util.HostStatus)3 RoutingFilter (io.confluent.ksql.execution.streams.RoutingFilter)2 DataSource (io.confluent.ksql.metastore.model.DataSource)2 MetricCollectors (io.confluent.ksql.metrics.MetricCollectors)2 KsqlHostInfoEntity (io.confluent.ksql.rest.entity.KsqlHostInfoEntity)2 List (java.util.List)2 Optional (java.util.Optional)2 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)2 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2 Preconditions (com.google.common.base.Preconditions)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 KsqlTopic (io.confluent.ksql.execution.ddl.commands.KsqlTopic)1 RoutingOptions (io.confluent.ksql.execution.streams.RoutingOptions)1