You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by GitBox <gi...@apache.org> on 2021/09/29 09:18:54 UTC

[GitHub] [shardingsphere] menghaoranss opened a new pull request #12820: Refresh memory meta data for create and drop database

menghaoranss opened a new pull request #12820:
URL: https://github.com/apache/shardingsphere/pull/12820


   For #12619 .
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [shardingsphere] taojintianxia commented on a change in pull request #12820: Refresh memory meta data for create and drop database

Posted by GitBox <gi...@apache.org>.
taojintianxia commented on a change in pull request #12820:
URL: https://github.com/apache/shardingsphere/pull/12820#discussion_r718321437



##########
File path: shardingsphere-mode/shardingsphere-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/ContextManager.java
##########
@@ -63,6 +79,74 @@ public synchronized void renewTransactionContexts(final TransactionContexts tran
         this.transactionContexts = transactionContexts;
     }
     
+    /**
+     * Add schema.
+     * 
+     * @param schemaName schema name
+     * @throws SQLException SQL exception                  
+     */
+    public void addSchema(final String schemaName) throws SQLException {
+        if (metaDataContexts.getMetaDataMap().containsKey(schemaName)) {
+            return;
+        }
+        MetaDataContexts newMetaDataContexts = buildNewMetaDataContext(schemaName);
+        metaDataContexts.getOptimizerContext().getMetaData().getSchemas().put(schemaName,
+                newMetaDataContexts.getOptimizerContext().getMetaData().getSchemas().get(schemaName));
+        metaDataContexts.getMetaDataMap().put(schemaName, newMetaDataContexts.getMetaData(schemaName));
+    }
+    
+    /**
+     * Delete schema.
+     * 
+     * @param schemaName schema name
+     */
+    public void deleteSchema(final String schemaName) {
+        if (metaDataContexts.getMetaDataMap().containsKey(schemaName)) {
+            metaDataContexts.getOptimizerContext().getMetaData().getSchemas().remove(schemaName);
+            metaDataContexts.getOptimizerContext().getParserContexts().remove(schemaName);
+            metaDataContexts.getOptimizerContext().getPlannerContexts().remove(schemaName);
+            ShardingSphereMetaData removeMetaData = metaDataContexts.getMetaDataMap().remove(schemaName);
+            closeDataSources(removeMetaData);
+            closeTransactionEngine(schemaName);
+        }
+    }
+    
+    private MetaDataContexts buildNewMetaDataContext(final String schemaName) throws SQLException {
+        Map<String, Map<String, DataSource>> dataSourcesMap = Collections.singletonMap(schemaName, new HashMap<>());

Review comment:
       map inside a map ? I'm not sure if multimap is better here . not formaliar with that . 
   
   multimap ... from guava.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [shardingsphere] strongduanmu merged pull request #12820: Refresh memory meta data for create and drop database

Posted by GitBox <gi...@apache.org>.
strongduanmu merged pull request #12820:
URL: https://github.com/apache/shardingsphere/pull/12820


   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [shardingsphere] taojintianxia commented on a change in pull request #12820: Refresh memory meta data for create and drop database

Posted by GitBox <gi...@apache.org>.
taojintianxia commented on a change in pull request #12820:
URL: https://github.com/apache/shardingsphere/pull/12820#discussion_r718321437



##########
File path: shardingsphere-mode/shardingsphere-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/ContextManager.java
##########
@@ -63,6 +79,74 @@ public synchronized void renewTransactionContexts(final TransactionContexts tran
         this.transactionContexts = transactionContexts;
     }
     
+    /**
+     * Add schema.
+     * 
+     * @param schemaName schema name
+     * @throws SQLException SQL exception                  
+     */
+    public void addSchema(final String schemaName) throws SQLException {
+        if (metaDataContexts.getMetaDataMap().containsKey(schemaName)) {
+            return;
+        }
+        MetaDataContexts newMetaDataContexts = buildNewMetaDataContext(schemaName);
+        metaDataContexts.getOptimizerContext().getMetaData().getSchemas().put(schemaName,
+                newMetaDataContexts.getOptimizerContext().getMetaData().getSchemas().get(schemaName));
+        metaDataContexts.getMetaDataMap().put(schemaName, newMetaDataContexts.getMetaData(schemaName));
+    }
+    
+    /**
+     * Delete schema.
+     * 
+     * @param schemaName schema name
+     */
+    public void deleteSchema(final String schemaName) {
+        if (metaDataContexts.getMetaDataMap().containsKey(schemaName)) {
+            metaDataContexts.getOptimizerContext().getMetaData().getSchemas().remove(schemaName);
+            metaDataContexts.getOptimizerContext().getParserContexts().remove(schemaName);
+            metaDataContexts.getOptimizerContext().getPlannerContexts().remove(schemaName);
+            ShardingSphereMetaData removeMetaData = metaDataContexts.getMetaDataMap().remove(schemaName);
+            closeDataSources(removeMetaData);
+            closeTransactionEngine(schemaName);
+        }
+    }
+    
+    private MetaDataContexts buildNewMetaDataContext(final String schemaName) throws SQLException {
+        Map<String, Map<String, DataSource>> dataSourcesMap = Collections.singletonMap(schemaName, new HashMap<>());

Review comment:
       map inside a map ? I'm not sure if multimap is better here . not formaliar with that . 
   
   multimap ... from guava.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [shardingsphere] strongduanmu merged pull request #12820: Refresh memory meta data for create and drop database

Posted by GitBox <gi...@apache.org>.
strongduanmu merged pull request #12820:
URL: https://github.com/apache/shardingsphere/pull/12820


   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org