Search in sources :

Example 1 with PullQueryConfigRoutingOptions

use of io.confluent.ksql.rest.server.resources.streaming.PullQueryConfigRoutingOptions in project ksql by confluentinc.

the class QueryExecutor method handleTablePullQuery.

private QueryMetadataHolder handleTablePullQuery(final ImmutableAnalysis analysis, final ServiceContext serviceContext, final ConfiguredStatement<Query> configured, final Map<String, Object> requestProperties, final Optional<Boolean> isInternalRequest, final SlidingWindowRateLimiter pullBandRateLimiter, final AtomicReference<PullQueryResult> resultForMetrics, final Optional<ConsistencyOffsetVector> consistencyOffsetVector) {
    final RoutingOptions routingOptions = new PullQueryConfigRoutingOptions(configured.getSessionConfig().getConfig(false), configured.getSessionConfig().getOverrides(), requestProperties);
    final PullQueryConfigPlannerOptions plannerOptions = new PullQueryConfigPlannerOptions(configured.getSessionConfig().getConfig(false), configured.getSessionConfig().getOverrides());
    // A request is considered forwarded if the request has the forwarded flag or if the request
    // is from an internal listener.
    final boolean isAlreadyForwarded = routingOptions.getIsSkipForwardRequest() && // Trust the forward request option if isInternalRequest isn't available.
    isInternalRequest.orElse(true);
    // Only check the rate limit at the forwarding host
    Decrementer decrementer = null;
    try {
        if (!isAlreadyForwarded) {
            rateLimiter.checkLimit();
            decrementer = concurrencyLimiter.increment();
        }
        pullBandRateLimiter.allow(KsqlQueryType.PULL);
        final Optional<Decrementer> optionalDecrementer = Optional.ofNullable(decrementer);
        final PullQueryResult result = ksqlEngine.executeTablePullQuery(analysis, serviceContext, configured, routing, routingOptions, plannerOptions, pullQueryMetrics, false, consistencyOffsetVector);
        resultForMetrics.set(result);
        result.onCompletionOrException((v, t) -> optionalDecrementer.ifPresent(Decrementer::decrementAtMostOnce));
        return QueryMetadataHolder.of(result);
    } catch (final Throwable t) {
        if (decrementer != null) {
            decrementer.decrementAtMostOnce();
        }
        throw t;
    }
}
Also used : RoutingOptions(io.confluent.ksql.execution.streams.RoutingOptions) PullQueryConfigRoutingOptions(io.confluent.ksql.rest.server.resources.streaming.PullQueryConfigRoutingOptions) PushQueryConfigRoutingOptions(io.confluent.ksql.rest.server.resources.streaming.PushQueryConfigRoutingOptions) PullQueryConfigRoutingOptions(io.confluent.ksql.rest.server.resources.streaming.PullQueryConfigRoutingOptions) PullQueryConfigPlannerOptions(io.confluent.ksql.rest.server.resources.streaming.PullQueryConfigPlannerOptions) Decrementer(io.confluent.ksql.rest.util.ConcurrencyLimiter.Decrementer) PullQueryResult(io.confluent.ksql.physical.pull.PullQueryResult)

Aggregations

RoutingOptions (io.confluent.ksql.execution.streams.RoutingOptions)1 PullQueryResult (io.confluent.ksql.physical.pull.PullQueryResult)1 PullQueryConfigPlannerOptions (io.confluent.ksql.rest.server.resources.streaming.PullQueryConfigPlannerOptions)1 PullQueryConfigRoutingOptions (io.confluent.ksql.rest.server.resources.streaming.PullQueryConfigRoutingOptions)1 PushQueryConfigRoutingOptions (io.confluent.ksql.rest.server.resources.streaming.PushQueryConfigRoutingOptions)1 Decrementer (io.confluent.ksql.rest.util.ConcurrencyLimiter.Decrementer)1