Search in sources :

Example 1 with RoutingFilter

use of io.confluent.ksql.execution.streams.RoutingFilter 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

RoutingFilter (io.confluent.ksql.execution.streams.RoutingFilter)1 KsqlHostInfo (io.confluent.ksql.util.KsqlHostInfo)1