clintropolis commented on a change in pull request #9492: add manual laning strategy, integration test URL: https://github.com/apache/druid/pull/9492#discussion_r391243279
########## File path: server/src/main/java/org/apache/druid/server/scheduling/ManualQueryLaningStrategy.java ########## @@ -0,0 +1,77 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.druid.server.scheduling; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.google.common.base.Preconditions; +import it.unimi.dsi.fastutil.objects.Object2IntArrayMap; +import it.unimi.dsi.fastutil.objects.Object2IntMap; +import org.apache.druid.client.SegmentServerSelector; +import org.apache.druid.query.QueryContexts; +import org.apache.druid.query.QueryPlus; +import org.apache.druid.server.QueryLaningStrategy; + +import javax.annotation.Nullable; +import java.util.Map; +import java.util.Optional; +import java.util.Set; + +public class ManualQueryLaningStrategy implements QueryLaningStrategy +{ + @JsonProperty + private Map<String, Integer> lanes; + + @JsonProperty + private boolean isLimitPercent; + + @JsonCreator + public ManualQueryLaningStrategy( + @JsonProperty("lanes") Map<String, Integer> lanes, + @JsonProperty("isLimitPercent") @Nullable Boolean isLimitPercent + ) + { + this.lanes = Preconditions.checkNotNull(lanes, "lanes must be set"); + this.isLimitPercent = isLimitPercent != null ? isLimitPercent : false; + Preconditions.checkArgument(lanes.size() > 0, "lanes must define at least one lane"); + Preconditions.checkArgument( + lanes.values().stream().allMatch(x -> this.isLimitPercent ? 0 < x && x <= 100 : x > 0), + this.isLimitPercent ? "All lane limits must be in the range 1 to 100" : "All lane limits must be greater than 0" + ); + } + + @Override + public Object2IntMap<String> getLaneLimits(int totalLimit) + { + + if (isLimitPercent) { + Object2IntMap<String> laneLimits = new Object2IntArrayMap<>(lanes.size()); + lanes.forEach((key, value) -> laneLimits.put(key, computeLimitFromPercent(totalLimit, value))); + return laneLimits; + } + return new Object2IntArrayMap<>(lanes); + } + + @Override + public <T> Optional<String> computeLane(QueryPlus<T> query, Set<SegmentServerSelector> segments) Review comment: `QueryLaningStrategy` are intended to compute the `lane` on the query context, which the `QueryScheduler` can then use to enforce limits. This laning strategy is a bit of a special case because it only preserves what was already there, but other strategies could consider all sorts of information to allow them to make informed decisions about lane assignment based on details of the query. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected] With regards, Apache Git Services --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
