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/05/08 14:55:44 UTC
[GitHub] [shardingsphere] terrymanu commented on a change in pull request #5471: Use multiple threads to load schemaMetaData
terrymanu commented on a change in pull request #5471:
URL: https://github.com/apache/shardingsphere/pull/5471#discussion_r422188395
##########
File path: shardingsphere-underlying/shardingsphere-common/src/main/java/org/apache/shardingsphere/underlying/common/metadata/schema/RuleSchemaMetaDataLoader.java
##########
@@ -142,6 +144,40 @@ public RuleSchemaMetaData load(final DatabaseType databaseType, final DataSource
return load(databaseType, dataSourceMap, tableName, properties);
}
+ private Map<String, SchemaMetaData> asyncLoad(final DatabaseType databaseType, final Map<String, DataSource> dataSourceMap, final ListeningExecutorService executorService,
+ final int maxConnectionCount, final Collection<String> excludedTableNames) {
+ Map<String, SchemaMetaData> unconfiguredSchemaMetaDataMap = new ConcurrentHashMap<>(dataSourceMap.size(), 1);
+ dataSourceMap.entrySet().stream().map(each -> executorService.submit(() -> {
+ try {
+ SchemaMetaData schemaMetaData = SchemaMetaDataLoader.load(each.getValue(), maxConnectionCount, databaseType.getName(), excludedTableNames);
+ if (!schemaMetaData.getAllTableNames().isEmpty()) {
+ unconfiguredSchemaMetaDataMap.put(each.getKey(), schemaMetaData);
+ }
+ } catch (SQLException e) {
+ throw new ShardingSphereException("RuleSchemaMetaData load faild", e);
+ }
+ })).forEach(listenableFuture -> {
+ try {
+ listenableFuture.get();
+ } catch (InterruptedException | ExecutionException e) {
+ throw new ShardingSphereException("RuleSchemaMetaData load faild", e);
+ }
+ });
+ return unconfiguredSchemaMetaDataMap;
Review comment:
It is better to rename return value as `result`
##########
File path: shardingsphere-underlying/shardingsphere-common/src/main/java/org/apache/shardingsphere/underlying/common/metadata/schema/RuleSchemaMetaDataLoader.java
##########
@@ -142,6 +144,40 @@ public RuleSchemaMetaData load(final DatabaseType databaseType, final DataSource
return load(databaseType, dataSourceMap, tableName, properties);
}
+ private Map<String, SchemaMetaData> asyncLoad(final DatabaseType databaseType, final Map<String, DataSource> dataSourceMap, final ListeningExecutorService executorService,
+ final int maxConnectionCount, final Collection<String> excludedTableNames) {
+ Map<String, SchemaMetaData> unconfiguredSchemaMetaDataMap = new ConcurrentHashMap<>(dataSourceMap.size(), 1);
+ dataSourceMap.entrySet().stream().map(each -> executorService.submit(() -> {
+ try {
+ SchemaMetaData schemaMetaData = SchemaMetaDataLoader.load(each.getValue(), maxConnectionCount, databaseType.getName(), excludedTableNames);
+ if (!schemaMetaData.getAllTableNames().isEmpty()) {
+ unconfiguredSchemaMetaDataMap.put(each.getKey(), schemaMetaData);
+ }
+ } catch (SQLException e) {
+ throw new ShardingSphereException("RuleSchemaMetaData load faild", e);
+ }
+ })).forEach(listenableFuture -> {
+ try {
+ listenableFuture.get();
+ } catch (InterruptedException | ExecutionException e) {
+ throw new ShardingSphereException("RuleSchemaMetaData load faild", e);
+ }
+ });
+ return unconfiguredSchemaMetaDataMap;
+ }
+
+ private Map<String, SchemaMetaData> syncLoad(final DatabaseType databaseType, final Map<String, DataSource> dataSourceMap,
+ final int maxConnectionCount, final Collection<String> excludedTableNames) throws SQLException {
+ Map<String, SchemaMetaData> unconfiguredSchemaMetaDataMap = new HashMap<>(dataSourceMap.size(), 1);
+ for (Entry<String, DataSource> entry : dataSourceMap.entrySet()) {
+ SchemaMetaData schemaMetaData = SchemaMetaDataLoader.load(entry.getValue(), maxConnectionCount, databaseType.getName(), excludedTableNames);
+ if (!schemaMetaData.getAllTableNames().isEmpty()) {
+ unconfiguredSchemaMetaDataMap.put(entry.getKey(), schemaMetaData);
+ }
+ }
+ return unconfiguredSchemaMetaDataMap;
Review comment:
It is better to rename return value as `result`
----------------------------------------------------------------
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