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 2020/01/16 04:00:04 UTC

[GitHub] [incubator-shardingsphere] SteNicholas commented on a change in pull request #3988: Using multithreading make loadDefaultTables faster and remove repeat load tableMetaData

SteNicholas commented on a change in pull request #3988: Using multithreading make loadDefaultTables faster and remove repeat load tableMetaData
URL: https://github.com/apache/incubator-shardingsphere/pull/3988#discussion_r367220920
 
 

 ##########
 File path: sharding-core/sharding-core-execute/src/main/java/org/apache/shardingsphere/sharding/execute/metadata/loader/ShardingTableMetaDataLoader.java
 ##########
 @@ -206,19 +207,46 @@ public TableMetas loadAll(final ShardingRule shardingRule) throws SQLException {
         return result;
     }
     
-    private Map<String, TableMetaData> loadDefaultTables(final ShardingRule shardingRule) throws SQLException {
+    private Map<String, TableMetaData> loadDefaultTables(final ShardingRule shardingRule, final Map<String, TableMetaData> result) throws SQLException {
         Optional<String> actualDefaultDataSourceName = shardingRule.findActualDefaultDataSourceName();
         if (!actualDefaultDataSourceName.isPresent()) {
             return Collections.emptyMap();
         }
         Collection<String> tableNames = loadAllTableNames(actualDefaultDataSourceName.get());
-        Map<String, TableMetaData> result = new HashMap<>(tableNames.size(), 1);
-        for (String each : tableNames) {
-            result.put(each, load(each, shardingRule));
+        removeRepeatTable(tableNames, result);
+        List<TableMetaData> metaList = executorEngine.execute(getTableNamesInput(tableNames), new GroupedCallback<String, TableMetaData>() {
+            @Override
+            public Collection<TableMetaData> execute(final Collection<String> inputs, final boolean isTrunkThread, final Map<String, Object> dataMap) throws SQLException {
+                String logicTableName = inputs.iterator().next();
+                Collection<TableMetaData> result = new LinkedList<>();
+                result.add(load(logicTableName, shardingRule));
+                return result;
+            }
+        });
+        Object[] tableNameArr = tableNames.toArray();
+        for (int i = 0, size = tableNames.size(); i < size; i++) {
 
 Review comment:
   Why not `for (int i = 0; i < tableNames.size(); i++) `?

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services