You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by zh...@apache.org on 2021/02/07 09:38:44 UTC

[shardingsphere] branch master updated: Create MetadataRefreshEngine (#9368)

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

zhangyonglun 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 b2c49f3  Create MetadataRefreshEngine (#9368)
b2c49f3 is described below

commit b2c49f31d6b023d005c49865deba05022ac94b7d
Author: Juan Pan(Trista) <pa...@apache.org>
AuthorDate: Sun Feb 7 17:38:18 2021 +0800

    Create MetadataRefreshEngine (#9368)
    
    * Create MetadataRefreshEngine
    
    * java doc
    
    * refactor MetadataRefresherFactory
---
 .../metadata/engine/MetadataRefreshEngine.java     | 84 ++++++++++++++++++++++
 .../infra/metadata/engine/MetadataRefresher.java   | 25 +++++++
 .../MetadataRefresherFactory.java}                 | 13 ++--
 .../refresher/PrivilegeRefresher.java}             | 26 +++----
 .../privilege/refresher/event/PrivilegeEvent.java  | 32 +++++++++
 .../refresher/spi/PrivilegeChangedNotifier.java}   | 27 +++----
 .../type/GrantStatementPrivilegeRefresher.java}    | 27 +++----
 .../metadata/schema/refresher/SchemaRefresher.java |  3 +-
 .../metadata/schema/builder/SchemaBuilderTest.java |  3 +-
 .../schema/builder/TableMetaDataBuilderTest.java   |  6 +-
 ...Test.java => MetadataRefresherFactoryTest.java} | 15 ++--
 .../driver/executor/DriverJDBCExecutor.java        | 11 +--
 .../communication/DatabaseCommunicationEngine.java | 34 +++------
 13 files changed, 208 insertions(+), 98 deletions(-)

diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/engine/MetadataRefreshEngine.java b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/engine/MetadataRefreshEngine.java
new file mode 100644
index 0000000..06d7aca
--- /dev/null
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/engine/MetadataRefreshEngine.java
@@ -0,0 +1,84 @@
+/*
+ * 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.shardingsphere.infra.metadata.engine;
+
+import org.apache.shardingsphere.infra.auth.Authentication;
+import org.apache.shardingsphere.infra.config.properties.ConfigurationProperties;
+import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
+import org.apache.shardingsphere.infra.metadata.privilege.refresher.PrivilegeRefresher;
+import org.apache.shardingsphere.infra.metadata.schema.ShardingSphereSchema;
+import org.apache.shardingsphere.infra.metadata.schema.builder.SchemaBuilderMaterials;
+import org.apache.shardingsphere.infra.metadata.schema.refresher.SchemaRefresher;
+import org.apache.shardingsphere.infra.metadata.schema.refresher.spi.SchemaChangedNotifier;
+import org.apache.shardingsphere.infra.spi.ordered.OrderedSPIRegistry;
+import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement;
+
+import java.sql.SQLException;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Optional;
+
+/**
+ * Metadata refresh engine.
+ */
+public final class MetadataRefreshEngine {
+    
+    private final ShardingSphereMetaData metaData;
+    
+    private final Authentication authentication;
+    
+    private final SchemaBuilderMaterials materials;
+    
+    public MetadataRefreshEngine(final ShardingSphereMetaData metaData, final Authentication authentication, final ConfigurationProperties properties) {
+        this.metaData = metaData;
+        this.authentication = authentication;
+        materials = new SchemaBuilderMaterials(metaData.getResource().getDatabaseType(), metaData.getResource().getDataSources(), metaData.getRuleMetaData().getRules(), properties);
+    }
+    
+    /**
+     * Refresh.
+     *
+     * @param sqlStatement sql statement
+     * @param routeDataSourceNames route data source names
+     * @throws SQLException sql exception
+     */
+    @SuppressWarnings("rawtypes")
+    public void refresh(final SQLStatement sqlStatement, final Collection<String> routeDataSourceNames) throws SQLException {
+        Optional<MetadataRefresher> metadataRefresher = MetadataRefresherFactory.newInstance(sqlStatement);
+        if (metadataRefresher.isPresent()) {
+            if (metadataRefresher.get() instanceof SchemaRefresher) {
+                refreshSchema(sqlStatement, routeDataSourceNames, (SchemaRefresher) metadataRefresher.get());
+            }
+            if (metadataRefresher.get() instanceof PrivilegeRefresher) {
+                refreshPrivilege(sqlStatement, (PrivilegeRefresher) metadataRefresher.get());
+            }
+        }
+    }
+    
+    @SuppressWarnings({"unchecked", "rawtypes"})
+    private void refreshSchema(final SQLStatement sqlStatement, final Collection<String> routeDataSourceNames, final SchemaRefresher refresher) throws SQLException {
+        ShardingSphereSchema schema = metaData.getSchema();
+        refresher.refresh(metaData.getSchema(), routeDataSourceNames, sqlStatement, materials);
+        OrderedSPIRegistry.getRegisteredServices(Collections.singletonList(schema), SchemaChangedNotifier.class).values().forEach(each -> each.notify(metaData.getName(), schema));
+    }
+    
+    private void refreshPrivilege(final SQLStatement sqlStatement, final PrivilegeRefresher refresher) {
+        refresher.refresh(authentication, sqlStatement, materials);
+        // TODO :notify
+    }
+}
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/engine/MetadataRefresher.java b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/engine/MetadataRefresher.java
new file mode 100644
index 0000000..f646850
--- /dev/null
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/engine/MetadataRefresher.java
@@ -0,0 +1,25 @@
+/*
+ * 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.shardingsphere.infra.metadata.engine;
+
+/**
+ * Metadata refresher.
+ *
+ */
+public interface MetadataRefresher {
+}
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/schema/refresher/SchemaRefresherFactory.java b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/engine/MetadataRefresherFactory.java
similarity index 86%
rename from shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/schema/refresher/SchemaRefresherFactory.java
rename to shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/engine/MetadataRefresherFactory.java
index afebd78..a8730e0 100644
--- a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/schema/refresher/SchemaRefresherFactory.java
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/engine/MetadataRefresherFactory.java
@@ -15,18 +15,20 @@
  * limitations under the License.
  */
 
-package org.apache.shardingsphere.infra.metadata.schema.refresher;
+package org.apache.shardingsphere.infra.metadata.engine;
 
 import lombok.AccessLevel;
 import lombok.NoArgsConstructor;
+import org.apache.shardingsphere.infra.metadata.privilege.refresher.type.GrantStatementPrivilegeRefresher;
+import org.apache.shardingsphere.infra.metadata.schema.refresher.type.AlterTableStatementSchemaRefresher;
 import org.apache.shardingsphere.infra.metadata.schema.refresher.type.CreateIndexStatementSchemaRefresher;
 import org.apache.shardingsphere.infra.metadata.schema.refresher.type.CreateTableStatementSchemaRefresher;
 import org.apache.shardingsphere.infra.metadata.schema.refresher.type.CreateViewStatementSchemaRefresher;
 import org.apache.shardingsphere.infra.metadata.schema.refresher.type.DropIndexStatementSchemaRefresher;
-import org.apache.shardingsphere.infra.metadata.schema.refresher.type.AlterTableStatementSchemaRefresher;
 import org.apache.shardingsphere.infra.metadata.schema.refresher.type.DropTableStatementSchemaRefresher;
 import org.apache.shardingsphere.infra.metadata.schema.refresher.type.DropViewStatementSchemaRefresher;
 import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement;
+import org.apache.shardingsphere.sql.parser.sql.common.statement.dcl.GrantStatement;
 import org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.AlterTableStatement;
 import org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.CreateIndexStatement;
 import org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.CreateTableStatement;
@@ -44,9 +46,9 @@ import java.util.Optional;
  * ShardingSphere schema refresher factory.
  */
 @NoArgsConstructor(access = AccessLevel.PRIVATE)
-public final class SchemaRefresherFactory {
+public final class MetadataRefresherFactory {
     
-    private static final Map<Class<?>, SchemaRefresher<?>> REGISTRY = new HashMap<>();
+    private static final Map<Class<?>, MetadataRefresher> REGISTRY = new HashMap<>();
     
     static {
         REGISTRY.put(CreateTableStatement.class, new CreateTableStatementSchemaRefresher());
@@ -56,6 +58,7 @@ public final class SchemaRefresherFactory {
         REGISTRY.put(DropIndexStatement.class, new DropIndexStatementSchemaRefresher());
         REGISTRY.put(CreateViewStatement.class, new CreateViewStatementSchemaRefresher());
         REGISTRY.put(DropViewStatement.class, new DropViewStatementSchemaRefresher());
+        REGISTRY.put(GrantStatement.class, new GrantStatementPrivilegeRefresher());
     }
     
     /**
@@ -64,7 +67,7 @@ public final class SchemaRefresherFactory {
      * @param sqlStatement SQL statement
      * @return instance of schema refresher
      */
-    public static Optional<SchemaRefresher> newInstance(final SQLStatement sqlStatement) {
+    public static Optional<MetadataRefresher> newInstance(final SQLStatement sqlStatement) {
         return REGISTRY.entrySet().stream().filter(entry -> entry.getKey().isAssignableFrom(sqlStatement.getClass())).findFirst().map(Entry::getValue);
     }
 }
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/schema/refresher/SchemaRefresher.java b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/privilege/refresher/PrivilegeRefresher.java
similarity index 56%
copy from shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/schema/refresher/SchemaRefresher.java
copy to shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/privilege/refresher/PrivilegeRefresher.java
index 22925da..e687482 100644
--- a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/schema/refresher/SchemaRefresher.java
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/privilege/refresher/PrivilegeRefresher.java
@@ -15,30 +15,24 @@
  * limitations under the License.
  */
 
-package org.apache.shardingsphere.infra.metadata.schema.refresher;
+package org.apache.shardingsphere.infra.metadata.privilege.refresher;
 
-import org.apache.shardingsphere.infra.metadata.schema.ShardingSphereSchema;
+import org.apache.shardingsphere.infra.auth.Authentication;
+import org.apache.shardingsphere.infra.metadata.engine.MetadataRefresher;
 import org.apache.shardingsphere.infra.metadata.schema.builder.SchemaBuilderMaterials;
 import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement;
 
-import java.sql.SQLException;
-import java.util.Collection;
-
 /**
- * ShardingSphere schema refresher.
- *
- * @param <T> type of SQL statement
+ * Privilege refresher.
  */
-public interface SchemaRefresher<T extends SQLStatement> {
+public interface PrivilegeRefresher extends MetadataRefresher {
     
     /**
-     * Refresh ShardingSphere schema.
+     * Refresh.
      *
-     * @param schema ShardingSphere schema to be refreshed
-     * @param routeDataSourceNames route dataSource names
-     * @param sqlStatement SQL statement
-     * @param materials schema builder materials
-     * @throws SQLException SQL exception
+     * @param authentication authentication
+     * @param sqlStatement sql statement
+     * @param materials materials
      */
-    void refresh(ShardingSphereSchema schema, Collection<String> routeDataSourceNames, T sqlStatement, SchemaBuilderMaterials materials) throws SQLException;
+    void refresh(Authentication authentication, SQLStatement sqlStatement, SchemaBuilderMaterials materials);
 }
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/privilege/refresher/event/PrivilegeEvent.java b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/privilege/refresher/event/PrivilegeEvent.java
new file mode 100644
index 0000000..0185b70
--- /dev/null
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/privilege/refresher/event/PrivilegeEvent.java
@@ -0,0 +1,32 @@
+/*
+ * 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.shardingsphere.infra.metadata.privilege.refresher.event;
+
+import lombok.Getter;
+import lombok.RequiredArgsConstructor;
+import org.apache.shardingsphere.infra.auth.user.ShardingSphereUser;
+
+/**
+ * Privilege event.
+ */
+@RequiredArgsConstructor
+@Getter
+public final class PrivilegeEvent {
+    
+    private final ShardingSphereUser user;
+}
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/schema/refresher/SchemaRefresher.java b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/privilege/refresher/spi/PrivilegeChangedNotifier.java
similarity index 50%
copy from shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/schema/refresher/SchemaRefresher.java
copy to shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/privilege/refresher/spi/PrivilegeChangedNotifier.java
index 22925da..36d4e93 100644
--- a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/schema/refresher/SchemaRefresher.java
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/privilege/refresher/spi/PrivilegeChangedNotifier.java
@@ -15,30 +15,21 @@
  * limitations under the License.
  */
 
-package org.apache.shardingsphere.infra.metadata.schema.refresher;
+package org.apache.shardingsphere.infra.metadata.privilege.refresher.spi;
 
+import org.apache.shardingsphere.infra.auth.user.ShardingSphereUser;
 import org.apache.shardingsphere.infra.metadata.schema.ShardingSphereSchema;
-import org.apache.shardingsphere.infra.metadata.schema.builder.SchemaBuilderMaterials;
-import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement;
-
-import java.sql.SQLException;
-import java.util.Collection;
+import org.apache.shardingsphere.infra.spi.ordered.OrderedSPI;
 
 /**
- * ShardingSphere schema refresher.
- *
- * @param <T> type of SQL statement
+ * ShardingSphere privilege changed notifier.
  */
-public interface SchemaRefresher<T extends SQLStatement> {
+public interface PrivilegeChangedNotifier extends OrderedSPI<ShardingSphereSchema> {
     
     /**
-     * Refresh ShardingSphere schema.
-     *
-     * @param schema ShardingSphere schema to be refreshed
-     * @param routeDataSourceNames route dataSource names
-     * @param sqlStatement SQL statement
-     * @param materials schema builder materials
-     * @throws SQLException SQL exception
+     * Notify when privilege changed.
+     * 
+     * @param user user
      */
-    void refresh(ShardingSphereSchema schema, Collection<String> routeDataSourceNames, T sqlStatement, SchemaBuilderMaterials materials) throws SQLException;
+    void notify(ShardingSphereUser user);
 }
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/schema/refresher/SchemaRefresher.java b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/privilege/refresher/type/GrantStatementPrivilegeRefresher.java
similarity index 55%
copy from shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/schema/refresher/SchemaRefresher.java
copy to shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/privilege/refresher/type/GrantStatementPrivilegeRefresher.java
index 22925da..be13fe5 100644
--- a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/schema/refresher/SchemaRefresher.java
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/privilege/refresher/type/GrantStatementPrivilegeRefresher.java
@@ -15,30 +15,19 @@
  * limitations under the License.
  */
 
-package org.apache.shardingsphere.infra.metadata.schema.refresher;
+package org.apache.shardingsphere.infra.metadata.privilege.refresher.type;
 
-import org.apache.shardingsphere.infra.metadata.schema.ShardingSphereSchema;
+import org.apache.shardingsphere.infra.auth.Authentication;
+import org.apache.shardingsphere.infra.metadata.privilege.refresher.PrivilegeRefresher;
 import org.apache.shardingsphere.infra.metadata.schema.builder.SchemaBuilderMaterials;
 import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement;
 
-import java.sql.SQLException;
-import java.util.Collection;
-
 /**
- * ShardingSphere schema refresher.
- *
- * @param <T> type of SQL statement
+ * Grant statement privilege refresher.
  */
-public interface SchemaRefresher<T extends SQLStatement> {
+public final class GrantStatementPrivilegeRefresher implements PrivilegeRefresher {
     
-    /**
-     * Refresh ShardingSphere schema.
-     *
-     * @param schema ShardingSphere schema to be refreshed
-     * @param routeDataSourceNames route dataSource names
-     * @param sqlStatement SQL statement
-     * @param materials schema builder materials
-     * @throws SQLException SQL exception
-     */
-    void refresh(ShardingSphereSchema schema, Collection<String> routeDataSourceNames, T sqlStatement, SchemaBuilderMaterials materials) throws SQLException;
+    @Override
+    public void refresh(final Authentication authentication, final SQLStatement sqlStatement, final SchemaBuilderMaterials materials) {
+    }
 }
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/schema/refresher/SchemaRefresher.java b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/schema/refresher/SchemaRefresher.java
index 22925da..a4a9946 100644
--- a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/schema/refresher/SchemaRefresher.java
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/schema/refresher/SchemaRefresher.java
@@ -17,6 +17,7 @@
 
 package org.apache.shardingsphere.infra.metadata.schema.refresher;
 
+import org.apache.shardingsphere.infra.metadata.engine.MetadataRefresher;
 import org.apache.shardingsphere.infra.metadata.schema.ShardingSphereSchema;
 import org.apache.shardingsphere.infra.metadata.schema.builder.SchemaBuilderMaterials;
 import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement;
@@ -29,7 +30,7 @@ import java.util.Collection;
  *
  * @param <T> type of SQL statement
  */
-public interface SchemaRefresher<T extends SQLStatement> {
+public interface SchemaRefresher<T extends SQLStatement> extends MetadataRefresher {
     
     /**
      * Refresh ShardingSphere schema.
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/schema/builder/SchemaBuilderTest.java b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/schema/builder/SchemaBuilderTest.java
index 48863d8..074d8a7 100644
--- a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/schema/builder/SchemaBuilderTest.java
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/schema/builder/SchemaBuilderTest.java
@@ -73,7 +73,8 @@ public final class SchemaBuilderTest {
     @Before
     public void setUp() {
         schemaBuilderMaterials = new SchemaBuilderMaterials(
-                databaseType, Collections.singletonMap("logic_db", dataSource), Arrays.asList(new CommonFixtureRule(), new DataNodeContainedFixtureRule()), props);
+                databaseType, Collections.singletonMap("logic_db", dataSource), Arrays.asList(new CommonFixtureRule(),
+                new DataNodeContainedFixtureRule()), props);
     }
     
     @Test
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/schema/builder/TableMetaDataBuilderTest.java b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/schema/builder/TableMetaDataBuilderTest.java
index 7f0f2d7..0d8016a 100644
--- a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/schema/builder/TableMetaDataBuilderTest.java
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/schema/builder/TableMetaDataBuilderTest.java
@@ -50,12 +50,14 @@ public final class TableMetaDataBuilderTest {
     @Test
     public void assertBuildWithExistedTableName() throws SQLException {
         assertTrue(TableMetaDataBuilder.build("data_node_routed_table1", new SchemaBuilderMaterials(
-                databaseType, Collections.singletonMap("logic_db", dataSource), Arrays.asList(new CommonFixtureRule(), new DataNodeContainedFixtureRule()), props)).isPresent());
+                databaseType, Collections.singletonMap("logic_db", dataSource), Arrays.asList(new CommonFixtureRule(),
+                new DataNodeContainedFixtureRule()), props)).isPresent());
     }
     
     @Test
     public void assertBuildWithNotExistedTableName() throws SQLException {
         assertFalse(TableMetaDataBuilder.build("invalid_table", new SchemaBuilderMaterials(
-                databaseType, Collections.singletonMap("logic_db", dataSource), Arrays.asList(new CommonFixtureRule(), new DataNodeContainedFixtureRule()), props)).isPresent());
+                databaseType, Collections.singletonMap("logic_db", dataSource), Arrays.asList(new CommonFixtureRule(), new DataNodeContainedFixtureRule()),
+                props)).isPresent());
     }
 }
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/schema/refresher/SchemaRefresherFactoryTest.java b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/schema/refresher/MetadataRefresherFactoryTest.java
similarity index 74%
rename from shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/schema/refresher/SchemaRefresherFactoryTest.java
rename to shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/schema/refresher/MetadataRefresherFactoryTest.java
index 5ea623a..07b1509 100644
--- a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/schema/refresher/SchemaRefresherFactoryTest.java
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/schema/refresher/MetadataRefresherFactoryTest.java
@@ -17,6 +17,7 @@
 
 package org.apache.shardingsphere.infra.metadata.schema.refresher;
 
+import org.apache.shardingsphere.infra.metadata.engine.MetadataRefresherFactory;
 import org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.AlterIndexStatement;
 import org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.AlterTableStatement;
 import org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.CreateIndexStatement;
@@ -32,35 +33,35 @@ import static org.junit.Assert.assertTrue;
 import static org.mockito.Mockito.mock;
 
 @RunWith(MockitoJUnitRunner.class)
-public final class SchemaRefresherFactoryTest {
+public final class MetadataRefresherFactoryTest {
     
     @Test
     public void assertNewInstanceWithCreateTableStatement() {
-        assertTrue(SchemaRefresherFactory.newInstance(mock(CreateTableStatement.class)).isPresent());
+        assertTrue(MetadataRefresherFactory.newInstance(mock(CreateTableStatement.class)).isPresent());
     }
     
     @Test
     public void assertNewInstanceWithAlterTableStatement() {
-        assertTrue(SchemaRefresherFactory.newInstance(mock(AlterTableStatement.class)).isPresent());
+        assertTrue(MetadataRefresherFactory.newInstance(mock(AlterTableStatement.class)).isPresent());
     }
     
     @Test
     public void assertNewInstanceWithDropTableStatement() {
-        assertTrue(SchemaRefresherFactory.newInstance(mock(DropTableStatement.class)).isPresent());
+        assertTrue(MetadataRefresherFactory.newInstance(mock(DropTableStatement.class)).isPresent());
     }
     
     @Test
     public void assertNewInstanceWithCreateIndexStatement() {
-        assertTrue(SchemaRefresherFactory.newInstance(mock(CreateIndexStatement.class)).isPresent());
+        assertTrue(MetadataRefresherFactory.newInstance(mock(CreateIndexStatement.class)).isPresent());
     }
     
     @Test
     public void assertNewInstanceWithDropIndexStatement() {
-        assertTrue(SchemaRefresherFactory.newInstance(mock(DropIndexStatement.class)).isPresent());
+        assertTrue(MetadataRefresherFactory.newInstance(mock(DropIndexStatement.class)).isPresent());
     }
     
     @Test
     public void assertNewInstanceWithSQLStatementNotNeedRefresh() {
-        assertFalse(SchemaRefresherFactory.newInstance(mock(AlterIndexStatement.class)).isPresent());
+        assertFalse(MetadataRefresherFactory.newInstance(mock(AlterIndexStatement.class)).isPresent());
     }
 }
diff --git a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/executor/DriverJDBCExecutor.java b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/executor/DriverJDBCExecutor.java
index 007d9ce..692a0f3 100644
--- a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/executor/DriverJDBCExecutor.java
+++ b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/executor/DriverJDBCExecutor.java
@@ -31,10 +31,11 @@ import org.apache.shardingsphere.infra.executor.sql.execute.engine.driver.jdbc.J
 import org.apache.shardingsphere.infra.executor.sql.execute.engine.driver.jdbc.JDBCExecutorCallback;
 import org.apache.shardingsphere.infra.executor.sql.execute.result.query.QueryResult;
 import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
+import org.apache.shardingsphere.infra.metadata.engine.MetadataRefresher;
+import org.apache.shardingsphere.infra.metadata.engine.MetadataRefresherFactory;
 import org.apache.shardingsphere.infra.metadata.schema.ShardingSphereSchema;
 import org.apache.shardingsphere.infra.metadata.schema.builder.SchemaBuilderMaterials;
 import org.apache.shardingsphere.infra.metadata.schema.refresher.SchemaRefresher;
-import org.apache.shardingsphere.infra.metadata.schema.refresher.SchemaRefresherFactory;
 import org.apache.shardingsphere.infra.metadata.schema.refresher.spi.SchemaChangedNotifier;
 import org.apache.shardingsphere.infra.route.context.RouteUnit;
 import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
@@ -149,17 +150,17 @@ public final class DriverJDBCExecutor {
     }
     
     private boolean needLock(final SQLStatement sqlStatement) {
-        return SchemaRefresherFactory.newInstance(sqlStatement).isPresent();
+        return MetadataRefresherFactory.newInstance(sqlStatement).isPresent();
     }
     
     @SuppressWarnings({"unchecked", "rawtypes"})
     private void refreshSchema(final ShardingSphereMetaData metaData, final SQLStatement sqlStatement, final Collection<RouteUnit> routeUnits) throws SQLException {
-        Optional<SchemaRefresher> schemaRefresher = SchemaRefresherFactory.newInstance(sqlStatement);
-        if (schemaRefresher.isPresent()) {
+        Optional<MetadataRefresher> metadataRefresher = MetadataRefresherFactory.newInstance(sqlStatement);
+        if (metadataRefresher.isPresent() && metadataRefresher.get() instanceof SchemaRefresher) {
             Collection<String> routeDataSourceNames = routeUnits.stream().map(each -> each.getDataSourceMapper().getLogicName()).collect(Collectors.toList());
             SchemaBuilderMaterials materials = new SchemaBuilderMaterials(metaDataContexts.getDefaultMetaData().getResource().getDatabaseType(),
                     dataSourceMap, metaData.getRuleMetaData().getRules(), metaDataContexts.getProps());
-            schemaRefresher.get().refresh(metaData.getSchema(), routeDataSourceNames, sqlStatement, materials);
+            ((SchemaRefresher) metadataRefresher.get()).refresh(metaData.getSchema(), routeDataSourceNames, sqlStatement, materials);
             notifySchemaChanged(metaData.getSchema());
         }
     }
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/DatabaseCommunicationEngine.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/DatabaseCommunicationEngine.java
index 23e453a..f5683be 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/DatabaseCommunicationEngine.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/DatabaseCommunicationEngine.java
@@ -31,14 +31,11 @@ import org.apache.shardingsphere.infra.executor.sql.prepare.driver.jdbc.JDBCDriv
 import org.apache.shardingsphere.infra.merge.MergeEngine;
 import org.apache.shardingsphere.infra.merge.result.MergedResult;
 import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
-import org.apache.shardingsphere.infra.metadata.schema.ShardingSphereSchema;
-import org.apache.shardingsphere.infra.metadata.schema.builder.SchemaBuilderMaterials;
-import org.apache.shardingsphere.infra.metadata.schema.refresher.SchemaRefresher;
-import org.apache.shardingsphere.infra.metadata.schema.refresher.SchemaRefresherFactory;
+import org.apache.shardingsphere.infra.metadata.engine.MetadataRefreshEngine;
+import org.apache.shardingsphere.infra.metadata.engine.MetadataRefresherFactory;
 import org.apache.shardingsphere.infra.metadata.schema.refresher.spi.SchemaChangedNotifier;
 import org.apache.shardingsphere.infra.rule.type.DataNodeContainedRule;
 import org.apache.shardingsphere.infra.spi.ShardingSphereServiceLoader;
-import org.apache.shardingsphere.infra.spi.ordered.OrderedSPIRegistry;
 import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.BackendConnection;
 import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
 import org.apache.shardingsphere.proxy.backend.exception.LockWaitTimeoutException;
@@ -56,7 +53,6 @@ import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement;
 import java.sql.SQLException;
 import java.util.ArrayList;
 import java.util.Collection;
-import java.util.Collections;
 import java.util.List;
 import java.util.Optional;
 import java.util.concurrent.TimeUnit;
@@ -82,6 +78,8 @@ public final class DatabaseCommunicationEngine {
     
     private final KernelProcessor kernelProcessor;
     
+    private final MetadataRefreshEngine engine;
+    
     private List<QueryHeader> queryHeaders;
     
     private MergedResult mergedResult;
@@ -92,6 +90,8 @@ public final class DatabaseCommunicationEngine {
         this.logicSQL = logicSQL;
         proxySQLExecutor = new ProxySQLExecutor(driverType, backendConnection);
         kernelProcessor = new KernelProcessor();
+        engine = new MetadataRefreshEngine(metaData,
+                ProxyContext.getInstance().getMetaDataContexts().getAuthentication(), ProxyContext.getInstance().getMetaDataContexts().getProps());
     }
     
     /**
@@ -114,7 +114,7 @@ public final class DatabaseCommunicationEngine {
             locked = tryGlobalLock(executionContext, ProxyContext.getInstance().getMetaDataContexts().getProps().<Long>getValue(ConfigurationPropertyKey.LOCK_WAIT_TIMEOUT_MILLISECONDS));
             proxySQLExecutor.checkExecutePrerequisites(executionContext);
             executeResults = proxySQLExecutor.execute(executionContext);
-            refreshSchema(executionContext);
+            refreshMetadata(executionContext);
         } finally {
             if (locked) {
                 releaseGlobalLock();
@@ -137,7 +137,7 @@ public final class DatabaseCommunicationEngine {
     }
     
     private boolean needLock(final ExecutionContext executionContext) {
-        return SchemaRefresherFactory.newInstance(executionContext.getSqlStatementContext().getSqlStatement()).isPresent();
+        return MetadataRefresherFactory.newInstance(executionContext.getSqlStatementContext().getSqlStatement()).isPresent();
     }
     
     private void releaseGlobalLock() {
@@ -192,23 +192,9 @@ public final class DatabaseCommunicationEngine {
         return result;
     }
     
-    @SuppressWarnings({"unchecked", "rawtypes"})
-    private void refreshSchema(final ExecutionContext executionContext) throws SQLException {
+    private void refreshMetadata(final ExecutionContext executionContext) throws SQLException {
         SQLStatement sqlStatement = executionContext.getSqlStatementContext().getSqlStatement();
-        Optional<SchemaRefresher> schemaRefresher = SchemaRefresherFactory.newInstance(sqlStatement);
-        if (schemaRefresher.isPresent()) {
-            Collection<String> routeDataSourceNames = executionContext.getRouteContext().getRouteUnits().stream()
-                    .map(each -> each.getDataSourceMapper().getLogicName()).collect(Collectors.toList());
-            SchemaBuilderMaterials materials = new SchemaBuilderMaterials(
-                    ProxyContext.getInstance().getMetaDataContexts().getMetaData(metaData.getName()).getResource().getDatabaseType(),
-                    metaData.getResource().getDataSources(), metaData.getRuleMetaData().getRules(), ProxyContext.getInstance().getMetaDataContexts().getProps());
-            schemaRefresher.get().refresh(metaData.getSchema(), routeDataSourceNames, sqlStatement, materials);
-            notifySchemaChanged(metaData.getName(), metaData.getSchema());
-        }
-    }
-    
-    private void notifySchemaChanged(final String schemaName, final ShardingSphereSchema schema) {
-        OrderedSPIRegistry.getRegisteredServices(Collections.singletonList(schema), SchemaChangedNotifier.class).values().forEach(each -> each.notify(schemaName, schema));
+        engine.refresh(sqlStatement, executionContext.getRouteContext().getRouteUnits().stream().map(each -> each.getDataSourceMapper().getLogicName()).collect(Collectors.toList()));
     }
     
     private void mergeUpdateCount(final SQLStatementContext<?> sqlStatementContext, final UpdateResponseHeader response) {