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