DRILL-1355: Ensure Drill optimizer will use storage plugin specific rules, when a new storage plugin is added.
Project: http://git-wip-us.apache.org/repos/asf/incubator-drill/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-drill/commit/2754321c Tree: http://git-wip-us.apache.org/repos/asf/incubator-drill/tree/2754321c Diff: http://git-wip-us.apache.org/repos/asf/incubator-drill/diff/2754321c Branch: refs/heads/master Commit: 2754321c46cc34bbf272f456a60f141b8c42ad45 Parents: f148694 Author: Jinfeng Ni <[email protected]> Authored: Thu Aug 28 07:21:06 2014 -0700 Committer: Jacques Nadeau <[email protected]> Committed: Fri Aug 29 00:14:31 2014 -0700 ---------------------------------------------------------------------- .../drill/exec/planner/sql/DrillSqlWorker.java | 17 +++++----------- .../drill/exec/store/StoragePluginRegistry.java | 21 ++++++++++---------- 2 files changed, 15 insertions(+), 23 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/2754321c/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/DrillSqlWorker.java ---------------------------------------------------------------------- diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/DrillSqlWorker.java b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/DrillSqlWorker.java index 321d79d..2238155 100644 --- a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/DrillSqlWorker.java +++ b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/DrillSqlWorker.java @@ -57,7 +57,6 @@ public class DrillSqlWorker { public final static int PHYSICAL_MEM_RULES = 1; private final QueryContext context; - private static volatile RuleSet[] allRules; public DrillSqlWorker(QueryContext context) throws Exception { final List<RelTraitDef> traitDefs = new ArrayList<RelTraitDef>(); @@ -83,18 +82,12 @@ public class DrillSqlWorker { } - private static RuleSet[] getRules(QueryContext context) { + private RuleSet[] getRules(QueryContext context) { StoragePluginRegistry storagePluginRegistry = context.getStorage(); - if (allRules == null) { - synchronized (DrillSqlWorker.class) { - if (allRules == null) { - RuleSet drillPhysicalMem = DrillRuleSets.mergedRuleSets( - DrillRuleSets.getPhysicalRules(context), - storagePluginRegistry.getStoragePluginRuleSet()); - allRules = new RuleSet[] {DrillRuleSets.getDrillBasicRules(context), drillPhysicalMem}; - } - } - } + RuleSet drillPhysicalMem = DrillRuleSets.mergedRuleSets( + DrillRuleSets.getPhysicalRules(context), + storagePluginRegistry.getStoragePluginRuleSet()); + RuleSet[] allRules = new RuleSet[] {DrillRuleSets.getDrillBasicRules(context), drillPhysicalMem}; return allRules; } http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/2754321c/exec/java-exec/src/main/java/org/apache/drill/exec/store/StoragePluginRegistry.java ---------------------------------------------------------------------- diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/store/StoragePluginRegistry.java b/exec/java-exec/src/main/java/org/apache/drill/exec/store/StoragePluginRegistry.java index 0b773dd..a876ea5 100644 --- a/exec/java-exec/src/main/java/org/apache/drill/exec/store/StoragePluginRegistry.java +++ b/exec/java-exec/src/main/java/org/apache/drill/exec/store/StoragePluginRegistry.java @@ -80,7 +80,6 @@ public class StoragePluginRegistry implements Iterable<Map.Entry<String, Storage private final PStore<StoragePluginConfig> pluginSystemTable; private final Object updateLock = new Object(); private volatile long lastUpdate = 0; - private RuleSet storagePluginsRuleSet; private static final long UPDATE_FREQUENCY = 2 * 60 * 1000; public StoragePluginRegistry(DrillbitContext context) { @@ -130,15 +129,6 @@ public class StoragePluginRegistry implements Iterable<Map.Entry<String, Storage this.plugins = Maps.newConcurrentMap(); this.plugins.putAll(createPlugins()); - // query registered engines for optimizer rules and build the storage plugin RuleSet - Builder<RelOptRule> setBuilder = ImmutableSet.builder(); - for (StoragePlugin plugin : this.plugins.values()) { - Set<StoragePluginOptimizerRule> rules = plugin.getOptimizerRules(); - if (rules != null && rules.size() > 0) { - setBuilder.addAll(rules); - } - } - this.storagePluginsRuleSet = DrillRuleSets.create(setBuilder.build()); } private Map<String, StoragePlugin> createPlugins() throws DrillbitStartupException { @@ -279,7 +269,16 @@ public class StoragePluginRegistry implements Iterable<Map.Entry<String, Storage } public RuleSet getStoragePluginRuleSet() { - return storagePluginsRuleSet; + // query registered engines for optimizer rules and build the storage plugin RuleSet + Builder<RelOptRule> setBuilder = ImmutableSet.builder(); + for (StoragePlugin plugin : this.plugins.values()) { + Set<StoragePluginOptimizerRule> rules = plugin.getOptimizerRules(); + if (rules != null && rules.size() > 0) { + setBuilder.addAll(rules); + } + } + + return DrillRuleSets.create(setBuilder.build()); } public DrillSchemaFactory getSchemaFactory() {
