This is an automated email from the ASF dual-hosted git repository. xxyu pushed a commit to branch kylin5 in repository https://gitbox.apache.org/repos/asf/kylin.git
commit f2788dee93974338ca0e6fb1a3e325259ff5459d Author: Pengfei Zhan <pengfei.z...@kyligence.io> AuthorDate: Thu Nov 10 14:43:21 2022 +0800 KYLIN-5403 fix potential deadlock of class loading of RoutingRule.java --- .../apache/kylin/query/routing/QueryRouter.java | 48 ++++++++++++- .../apache/kylin/query/routing/RoutingRule.java | 81 ---------------------- 2 files changed, 46 insertions(+), 83 deletions(-) diff --git a/src/query-common/src/main/java/org/apache/kylin/query/routing/QueryRouter.java b/src/query-common/src/main/java/org/apache/kylin/query/routing/QueryRouter.java index b9200608f3..3a5e89c27d 100644 --- a/src/query-common/src/main/java/org/apache/kylin/query/routing/QueryRouter.java +++ b/src/query-common/src/main/java/org/apache/kylin/query/routing/QueryRouter.java @@ -26,6 +26,11 @@ import org.apache.kylin.metadata.model.FunctionDesc; import org.apache.kylin.metadata.realization.IRealization; import org.apache.kylin.query.relnode.OLAPContext; import org.apache.kylin.query.relnode.OLAPContextProp; +import org.apache.kylin.query.routing.rules.PartitionPruningRule; +import org.apache.kylin.query.routing.rules.RealizationSortRule; +import org.apache.kylin.query.routing.rules.RemoveBlackoutRealizationsRule; +import org.apache.kylin.query.routing.rules.RemoveUncapableRealizationsRule; +import org.apache.kylin.query.routing.rules.SegmentPruningRule; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -42,6 +47,45 @@ public class QueryRouter { private QueryRouter() { } + private static final List<RoutingRule> LAYOUT_CHOOSING_RULES = Lists.newLinkedList(); + + static { + LAYOUT_CHOOSING_RULES.add(new RemoveBlackoutRealizationsRule()); + LAYOUT_CHOOSING_RULES.add(new SegmentPruningRule()); + LAYOUT_CHOOSING_RULES.add(new PartitionPruningRule()); + LAYOUT_CHOOSING_RULES.add(new RemoveUncapableRealizationsRule()); + LAYOUT_CHOOSING_RULES.add(new RealizationSortRule()); + } + + public static void applyRules(List<Candidate> candidates) { + for (RoutingRule rule : LAYOUT_CHOOSING_RULES) { + String before = getPrintableText(candidates); + rule.apply(candidates); + String after = getPrintableText(candidates); + if (!before.equals(after)) { + logger.info("Applying rule: {}, realizations before:{}, realizations after: {}", rule, before, after); + } + } + } + + public static String getPrintableText(List<Candidate> candidates) { + StringBuilder sb = new StringBuilder(); + sb.append("["); + for (Candidate candidate : candidates) { + IRealization r = candidate.realization; + sb.append(r.getCanonicalName()); + sb.append(","); + } + if (sb.charAt(sb.length() - 1) != '[') + sb.deleteCharAt(sb.length() - 1); + sb.append("]"); + return sb.toString(); + } + + public static void removeRule(RoutingRule rule) { + LAYOUT_CHOOSING_RULES.removeIf(r -> r.getClass() == rule.getClass()); + } + public static Candidate selectRealization(OLAPContext olapContext, IRealization realization, Map<String, String> aliasMap) { if (!realization.isReady()) { @@ -56,7 +100,7 @@ public class QueryRouter { List<Candidate> originCandidates = Lists.newArrayList(candidates); // rule based realization selection, rules might reorder realizations or remove specific realization - RoutingRule.applyRules(candidates); + QueryRouter.applyRules(candidates); collectIncapableReason(olapContext, originCandidates); if (candidates.isEmpty()) { @@ -66,7 +110,7 @@ public class QueryRouter { Candidate chosen = candidates.get(0); chosen.setRewrittenCtx(preserveRewriteProps(olapContext)); logger.info("The realizations remaining: {}, and the final chosen one for current olap context {} is {}", - RoutingRule.getPrintableText(candidates), olapContext.id, chosen.realization.getCanonicalName()); + QueryRouter.getPrintableText(candidates), olapContext.id, chosen.realization.getCanonicalName()); return chosen; } diff --git a/src/query-common/src/main/java/org/apache/kylin/query/routing/RoutingRule.java b/src/query-common/src/main/java/org/apache/kylin/query/routing/RoutingRule.java index 6f85b9374c..e228c7c49a 100644 --- a/src/query-common/src/main/java/org/apache/kylin/query/routing/RoutingRule.java +++ b/src/query-common/src/main/java/org/apache/kylin/query/routing/RoutingRule.java @@ -18,92 +18,11 @@ package org.apache.kylin.query.routing; -import java.util.Iterator; import java.util.List; -import org.apache.kylin.metadata.realization.IRealization; -import org.apache.kylin.query.routing.rules.PartitionPruningRule; -import org.apache.kylin.query.routing.rules.RealizationSortRule; -import org.apache.kylin.query.routing.rules.RemoveBlackoutRealizationsRule; -import org.apache.kylin.query.routing.rules.RemoveUncapableRealizationsRule; -import org.apache.kylin.query.routing.rules.SegmentPruningRule; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.collect.Lists; - /** */ public abstract class RoutingRule { - private static final Logger logger = LoggerFactory.getLogger(QueryRouter.class); - private static List<RoutingRule> rules = Lists.newLinkedList(); - - static { - rules.add(new RemoveBlackoutRealizationsRule()); - rules.add(new SegmentPruningRule()); - rules.add(new PartitionPruningRule()); - rules.add(new RemoveUncapableRealizationsRule()); - rules.add(new RealizationSortRule()); - } - - public static void applyRules(List<Candidate> candidates) { - for (RoutingRule rule : rules) { - String before = getPrintableText(candidates); - rule.apply(candidates); - String after = getPrintableText(candidates); - if (!before.equals(after)) { - logger.info("Applying rule: {}, realizations before:{}, realizations after: {}", rule, before, after); - } - } - } - - public static String getPrintableText(List<Candidate> candidates) { - StringBuilder sb = new StringBuilder(); - sb.append("["); - for (Candidate candidate : candidates) { - IRealization r = candidate.realization; - sb.append(r.getCanonicalName()); - sb.append(","); - } - if (sb.charAt(sb.length() - 1) != '[') - sb.deleteCharAt(sb.length() - 1); - sb.append("]"); - return sb.toString(); - } - - /** - * - * @param rule - * @param applyOrder RoutingRule are applied in order, latter rules can override previous rules - */ - public static void registerRule(RoutingRule rule, int applyOrder) { - if (applyOrder > rules.size()) { - logger.warn("apply order {} is larger than rules size {}, will put the new rule at the end", applyOrder, - rules.size()); - rules.add(rule); - } - - rules.add(applyOrder, rule); - } - - public static void removeRule(RoutingRule rule) { - for (Iterator<RoutingRule> iter = rules.iterator(); iter.hasNext();) { - RoutingRule r = iter.next(); - if (r.getClass() == rule.getClass()) { - iter.remove(); - } - } - } - - protected List<Integer> findRealizationsOf(List<IRealization> realizations, String type) { - List<Integer> itemIndices = Lists.newArrayList(); - for (int i = 0; i < realizations.size(); ++i) { - if (realizations.get(i).getType().equals(type)) { - itemIndices.add(i); - } - } - return itemIndices; - } @Override public String toString() {