You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by wu...@apache.org on 2021/03/23 16:56:34 UTC

[shardingsphere] branch master updated: Use OrderedSPIRegister to replace cache from engine details (#9790)

This is an automated email from the ASF dual-hosted git repository.

wuweijie pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git


The following commit(s) were added to refs/heads/master by this push:
     new 16e1833  Use OrderedSPIRegister to replace cache from engine details (#9790)
16e1833 is described below

commit 16e1833a02f0d1b06670209cc57871ae4474869a
Author: Liang Zhang <te...@163.com>
AuthorDate: Wed Mar 24 00:56:05 2021 +0800

    Use OrderedSPIRegister to replace cache from engine details (#9790)
---
 .../executor/sql/prepare/AbstractExecutionPrepareEngine.java   |  6 +-----
 .../org/apache/shardingsphere/infra/merge/MergeEngine.java     | 10 +++-------
 .../apache/shardingsphere/infra/rewrite/SQLRewriteEntry.java   | 10 +++-------
 .../infra/route/engine/impl/PartialSQLRouteExecutor.java       |  6 +-----
 4 files changed, 8 insertions(+), 24 deletions(-)

diff --git a/shardingsphere-infra/shardingsphere-infra-executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/prepare/AbstractExecutionPrepareEngine.java b/shardingsphere-infra/shardingsphere-infra-executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/prepare/AbstractExecutionPrepareEngine.java
index 9528283..d06c11e 100644
--- a/shardingsphere-infra/shardingsphere-infra-executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/prepare/AbstractExecutionPrepareEngine.java
+++ b/shardingsphere-infra/shardingsphere-infra-executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/prepare/AbstractExecutionPrepareEngine.java
@@ -35,7 +35,6 @@ import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
-import java.util.concurrent.ConcurrentHashMap;
 
 /**
  * Abstract execution prepare engine.
@@ -48,9 +47,6 @@ public abstract class AbstractExecutionPrepareEngine<T> implements ExecutionPrep
         ShardingSphereServiceLoader.register(ExecutionPrepareDecorator.class);
     }
     
-    @SuppressWarnings("rawtypes")
-    private static final Map<Collection<ShardingSphereRule>, Map<ShardingSphereRule, ExecutionPrepareDecorator>> RULES_TO_DECORATORS_MAP = new ConcurrentHashMap<>(32, 1);
-    
     private final int maxConnectionsSizePerQuery;
     
     @SuppressWarnings("rawtypes")
@@ -58,7 +54,7 @@ public abstract class AbstractExecutionPrepareEngine<T> implements ExecutionPrep
     
     protected AbstractExecutionPrepareEngine(final int maxConnectionsSizePerQuery, final Collection<ShardingSphereRule> rules) {
         this.maxConnectionsSizePerQuery = maxConnectionsSizePerQuery;
-        decorators = RULES_TO_DECORATORS_MAP.computeIfAbsent(rules, key -> OrderedSPIRegistry.getRegisteredServices(key, ExecutionPrepareDecorator.class));
+        decorators = OrderedSPIRegistry.getRegisteredServices(rules, ExecutionPrepareDecorator.class);
     }
     
     @Override
diff --git a/shardingsphere-infra/shardingsphere-infra-merge/src/main/java/org/apache/shardingsphere/infra/merge/MergeEngine.java b/shardingsphere-infra/shardingsphere-infra-merge/src/main/java/org/apache/shardingsphere/infra/merge/MergeEngine.java
index 0d3b442..deb7f86 100644
--- a/shardingsphere-infra/shardingsphere-infra-merge/src/main/java/org/apache/shardingsphere/infra/merge/MergeEngine.java
+++ b/shardingsphere-infra/shardingsphere-infra-merge/src/main/java/org/apache/shardingsphere/infra/merge/MergeEngine.java
@@ -17,6 +17,7 @@
 
 package org.apache.shardingsphere.infra.merge;
 
+import org.apache.shardingsphere.infra.binder.statement.SQLStatementContext;
 import org.apache.shardingsphere.infra.config.properties.ConfigurationProperties;
 import org.apache.shardingsphere.infra.database.type.DatabaseType;
 import org.apache.shardingsphere.infra.executor.sql.execute.result.query.QueryResult;
@@ -27,11 +28,10 @@ import org.apache.shardingsphere.infra.merge.engine.merger.ResultMerger;
 import org.apache.shardingsphere.infra.merge.engine.merger.ResultMergerEngine;
 import org.apache.shardingsphere.infra.merge.result.MergedResult;
 import org.apache.shardingsphere.infra.merge.result.impl.transparent.TransparentMergedResult;
+import org.apache.shardingsphere.infra.metadata.schema.ShardingSphereSchema;
 import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
 import org.apache.shardingsphere.infra.spi.ShardingSphereServiceLoader;
 import org.apache.shardingsphere.infra.spi.ordered.OrderedSPIRegistry;
-import org.apache.shardingsphere.infra.metadata.schema.ShardingSphereSchema;
-import org.apache.shardingsphere.infra.binder.statement.SQLStatementContext;
 
 import java.sql.SQLException;
 import java.util.Collection;
@@ -39,7 +39,6 @@ import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
 import java.util.Optional;
-import java.util.concurrent.ConcurrentHashMap;
 
 /**
  * Merge engine.
@@ -50,9 +49,6 @@ public final class MergeEngine {
         ShardingSphereServiceLoader.register(ResultProcessEngine.class);
     }
     
-    @SuppressWarnings("rawtypes")
-    private static final Map<Collection<ShardingSphereRule>, Map<ShardingSphereRule, ResultProcessEngine>> RULES_TO_ENGINES_MAP = new ConcurrentHashMap<>(32, 1);
-    
     private final DatabaseType databaseType;
     
     private final ShardingSphereSchema schema;
@@ -66,7 +62,7 @@ public final class MergeEngine {
         this.databaseType = databaseType;
         this.schema = schema;
         this.props = props;
-        engines = RULES_TO_ENGINES_MAP.computeIfAbsent(rules, key -> OrderedSPIRegistry.getRegisteredServices(key, ResultProcessEngine.class));
+        engines = OrderedSPIRegistry.getRegisteredServices(rules, ResultProcessEngine.class);
     }
     
     /**
diff --git a/shardingsphere-infra/shardingsphere-infra-rewrite/shardingsphere-infra-rewrite-engine/src/main/java/org/apache/shardingsphere/infra/rewrite/SQLRewriteEntry.java b/shardingsphere-infra/shardingsphere-infra-rewrite/shardingsphere-infra-rewrite-engine/src/main/java/org/apache/shardingsphere/infra/rewrite/SQLRewriteEntry.java
index 88261e7..a0e26cc 100644
--- a/shardingsphere-infra/shardingsphere-infra-rewrite/shardingsphere-infra-rewrite-engine/src/main/java/org/apache/shardingsphere/infra/rewrite/SQLRewriteEntry.java
+++ b/shardingsphere-infra/shardingsphere-infra-rewrite/shardingsphere-infra-rewrite-engine/src/main/java/org/apache/shardingsphere/infra/rewrite/SQLRewriteEntry.java
@@ -17,7 +17,9 @@
 
 package org.apache.shardingsphere.infra.rewrite;
 
+import org.apache.shardingsphere.infra.binder.statement.SQLStatementContext;
 import org.apache.shardingsphere.infra.config.properties.ConfigurationProperties;
+import org.apache.shardingsphere.infra.metadata.schema.ShardingSphereSchema;
 import org.apache.shardingsphere.infra.rewrite.context.SQLRewriteContext;
 import org.apache.shardingsphere.infra.rewrite.context.SQLRewriteContextDecorator;
 import org.apache.shardingsphere.infra.rewrite.engine.GenericSQLRewriteEngine;
@@ -27,13 +29,10 @@ import org.apache.shardingsphere.infra.route.context.RouteContext;
 import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
 import org.apache.shardingsphere.infra.spi.ShardingSphereServiceLoader;
 import org.apache.shardingsphere.infra.spi.ordered.OrderedSPIRegistry;
-import org.apache.shardingsphere.infra.metadata.schema.ShardingSphereSchema;
-import org.apache.shardingsphere.infra.binder.statement.SQLStatementContext;
 
 import java.util.Collection;
 import java.util.List;
 import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
 
 /**
  * SQL rewrite entry.
@@ -44,9 +43,6 @@ public final class SQLRewriteEntry {
         ShardingSphereServiceLoader.register(SQLRewriteContextDecorator.class);
     }
     
-    @SuppressWarnings("rawtypes")
-    private static final Map<Collection<ShardingSphereRule>, Map<ShardingSphereRule, SQLRewriteContextDecorator>> RULES_TO_DECORATORS_MAP = new ConcurrentHashMap<>(32, 1);
-    
     private final ShardingSphereSchema schema;
     
     private final ConfigurationProperties props;
@@ -57,7 +53,7 @@ public final class SQLRewriteEntry {
     public SQLRewriteEntry(final ShardingSphereSchema schema, final ConfigurationProperties props, final Collection<ShardingSphereRule> rules) {
         this.schema = schema;
         this.props = props;
-        decorators = RULES_TO_DECORATORS_MAP.computeIfAbsent(rules, key -> OrderedSPIRegistry.getRegisteredServices(key, SQLRewriteContextDecorator.class));
+        decorators = OrderedSPIRegistry.getRegisteredServices(rules, SQLRewriteContextDecorator.class);
     }
     
     /**
diff --git a/shardingsphere-infra/shardingsphere-infra-route/src/main/java/org/apache/shardingsphere/infra/route/engine/impl/PartialSQLRouteExecutor.java b/shardingsphere-infra/shardingsphere-infra-route/src/main/java/org/apache/shardingsphere/infra/route/engine/impl/PartialSQLRouteExecutor.java
index 8c179c6..c0cd197 100644
--- a/shardingsphere-infra/shardingsphere-infra-route/src/main/java/org/apache/shardingsphere/infra/route/engine/impl/PartialSQLRouteExecutor.java
+++ b/shardingsphere-infra/shardingsphere-infra-route/src/main/java/org/apache/shardingsphere/infra/route/engine/impl/PartialSQLRouteExecutor.java
@@ -33,7 +33,6 @@ import java.util.Collection;
 import java.util.Collections;
 import java.util.Map;
 import java.util.Map.Entry;
-import java.util.concurrent.ConcurrentHashMap;
 
 /**
  * Partial SQL route executor.
@@ -44,9 +43,6 @@ public final class PartialSQLRouteExecutor implements SQLRouteExecutor {
         ShardingSphereServiceLoader.register(SQLRouter.class);
     }
     
-    @SuppressWarnings("rawtypes")
-    private static final Map<Collection<ShardingSphereRule>, Map<ShardingSphereRule, SQLRouter>> RULES_TO_ROUTERS_MAP = new ConcurrentHashMap<>(32, 1);
-    
     private final ConfigurationProperties props;
     
     @SuppressWarnings("rawtypes")
@@ -54,7 +50,7 @@ public final class PartialSQLRouteExecutor implements SQLRouteExecutor {
     
     public PartialSQLRouteExecutor(final Collection<ShardingSphereRule> rules, final ConfigurationProperties props) {
         this.props = props;
-        routers = RULES_TO_ROUTERS_MAP.computeIfAbsent(rules, key -> OrderedSPIRegistry.getRegisteredServices(key, SQLRouter.class));
+        routers = OrderedSPIRegistry.getRegisteredServices(rules, SQLRouter.class);
     }
     
     @Override