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