You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by pa...@apache.org on 2021/12/03 08:59:29 UTC
[shardingsphere] branch master updated: Add drop tables in ContextManager (#13917)
This is an automated email from the ASF dual-hosted git repository.
panjuan 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 8cbcb7b Add drop tables in ContextManager (#13917)
8cbcb7b is described below
commit 8cbcb7bc42e88e4bdb22a49faeb4cdff11091e88
Author: Haoran Meng <me...@gmail.com>
AuthorDate: Fri Dec 3 16:56:43 2021 +0800
Add drop tables in ContextManager (#13917)
Co-authored-by: shardingsphere <de...@shardingsphere.apache.org>
---
.../shardingsphere/mode/manager/ContextManager.java | 17 +++++++++++++++++
1 file changed, 17 insertions(+)
diff --git a/shardingsphere-mode/shardingsphere-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/ContextManager.java b/shardingsphere-mode/shardingsphere-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/ContextManager.java
index 226ea75..a7d25eb 100644
--- a/shardingsphere-mode/shardingsphere-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/ContextManager.java
+++ b/shardingsphere-mode/shardingsphere-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/ContextManager.java
@@ -38,6 +38,7 @@ import org.apache.shardingsphere.infra.metadata.schema.model.TableMetaData;
import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
import org.apache.shardingsphere.infra.rule.builder.global.GlobalRulesBuilder;
import org.apache.shardingsphere.infra.rule.builder.schema.SchemaRulesBuilder;
+import org.apache.shardingsphere.infra.rule.identifier.type.MutableDataNodeRule;
import org.apache.shardingsphere.infra.state.StateContext;
import org.apache.shardingsphere.mode.metadata.MetaDataContexts;
import org.apache.shardingsphere.mode.metadata.MetaDataContextsBuilder;
@@ -305,6 +306,22 @@ public final class ContextManager implements AutoCloseable {
}
}
+ /**
+ * Drop tables.
+ *
+ * @param schemaName schema name
+ * @param tables tables
+ */
+ public void dropTables(final String schemaName, final Collection<String> tables) {
+ Collection<MutableDataNodeRule> rules = metaDataContexts.getMetaData(schemaName).getRuleMetaData().findRules(MutableDataNodeRule.class);
+ for (String table : tables) {
+ metaDataContexts.getMetaData(schemaName).getSchema().remove(table);
+ metaDataContexts.getOptimizerContext().getMetaData().getSchemas().get(schemaName).remove(table);
+ rules.forEach(rule -> rule.remove(table));
+ }
+ metaDataContexts.getMetaDataPersistService().ifPresent(optional -> optional.getSchemaMetaDataService().persist(schemaName, metaDataContexts.getMetaData(schemaName).getSchema()));
+ }
+
private void loadTableMetaData(final String schemaName, final String tableName, final SchemaBuilderMaterials materials) throws SQLException {
TableMetaData tableMetaData = Optional.ofNullable(TableMetaDataBuilder.load(Collections.singletonList(tableName), materials).get(tableName))
.map(each -> TableMetaDataBuilder.decorateKernelTableMetaData(each, materials.getRules())).orElseGet(TableMetaData::new);