Search in sources :

Example 1 with QueryStateStoreId

use of io.confluent.ksql.rest.entity.QueryStateStoreId in project ksql by confluentinc.

the class MaximumLagFilter method create.

/**
 * Creates a FreshnessFilter
 * @param lagReportingAgent The optional lag reporting agent.
 * @param routingOptions The routing options
 * @param hosts The set of all hosts that have the store, including actives and standbys
 * @param applicationQueryId The query id of the persistent query that materialized the table
 * @param storeName The state store name of the materialized table
 * @param partition The partition of the topic
 * @return a new FreshnessFilter, unless lag reporting is disabled.
 */
public static Optional<MaximumLagFilter> create(final Optional<LagReportingAgent> lagReportingAgent, final RoutingOptions routingOptions, final List<KsqlHostInfo> hosts, final String applicationQueryId, final String storeName, final int partition) {
    if (!lagReportingAgent.isPresent()) {
        return Optional.empty();
    }
    final QueryStateStoreId queryStateStoreId = QueryStateStoreId.of(applicationQueryId, storeName);
    final ImmutableMap<KsqlHostInfo, Optional<LagInfoEntity>> lagByHost = hosts.stream().collect(ImmutableMap.toImmutableMap(Function.identity(), host -> lagReportingAgent.get().getLagInfoForHost(host, queryStateStoreId, partition)));
    final OptionalLong maxEndOffset = lagByHost.values().stream().filter(Optional::isPresent).map(Optional::get).mapToLong(LagInfoEntity::getEndOffsetPosition).max();
    return Optional.of(new MaximumLagFilter(routingOptions, lagByHost, maxEndOffset));
}
Also used : OptionalLong(java.util.OptionalLong) List(java.util.List) ImmutableMap(com.google.common.collect.ImmutableMap) Objects.requireNonNull(java.util.Objects.requireNonNull) RoutingOptions(io.confluent.ksql.execution.streams.RoutingOptions) Optional(java.util.Optional) Preconditions(com.google.common.base.Preconditions) LagInfoEntity(io.confluent.ksql.rest.entity.LagInfoEntity) QueryStateStoreId(io.confluent.ksql.rest.entity.QueryStateStoreId) Function(java.util.function.Function) RoutingFilter(io.confluent.ksql.execution.streams.RoutingFilter) KsqlHostInfo(io.confluent.ksql.util.KsqlHostInfo) Optional(java.util.Optional) KsqlHostInfo(io.confluent.ksql.util.KsqlHostInfo) QueryStateStoreId(io.confluent.ksql.rest.entity.QueryStateStoreId) OptionalLong(java.util.OptionalLong)

Aggregations

Preconditions (com.google.common.base.Preconditions)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 RoutingFilter (io.confluent.ksql.execution.streams.RoutingFilter)1 RoutingOptions (io.confluent.ksql.execution.streams.RoutingOptions)1 LagInfoEntity (io.confluent.ksql.rest.entity.LagInfoEntity)1 QueryStateStoreId (io.confluent.ksql.rest.entity.QueryStateStoreId)1 KsqlHostInfo (io.confluent.ksql.util.KsqlHostInfo)1 List (java.util.List)1 Objects.requireNonNull (java.util.Objects.requireNonNull)1 Optional (java.util.Optional)1 OptionalLong (java.util.OptionalLong)1 Function (java.util.function.Function)1