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 2022/01/22 14:12:55 UTC

[GitHub] [shardingsphere] terrymanu commented on a change in pull request #14998: Fixes #14814, optimize query result of `SHOW SCHEMA RESOURCES`

terrymanu commented on a change in pull request #14998:
URL: https://github.com/apache/shardingsphere/pull/14998#discussion_r790146254



##########
File path: shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rql/resource/DataSourceQueryResultSet.java
##########
@@ -72,18 +90,66 @@ public boolean next() {
     @Override
     public Collection<Object> getRowData() {
         String dataSourceName = dataSourceNames.next();
+        DataSourceProperties dataSourceProperties = dataSourcePropsMap.get(dataSourceName);
+        DataSourcePoolMetaData poolMetaData = DataSourcePoolMetaDataFactory.newInstance(dataSourceProperties.getDataSourceClassName());
+        Map<String, Object> allProperties = getAllProperties(resource.getDataSources().get(dataSourceName));

Review comment:
       It is unnecessary to get all data source properties, display PoolPropertySynonyms is enough for display.
    

##########
File path: shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rql/resource/DataSourceQueryResultSet.java
##########
@@ -72,18 +90,66 @@ public boolean next() {
     @Override
     public Collection<Object> getRowData() {
         String dataSourceName = dataSourceNames.next();
+        DataSourceProperties dataSourceProperties = dataSourcePropsMap.get(dataSourceName);
+        DataSourcePoolMetaData poolMetaData = DataSourcePoolMetaDataFactory.newInstance(dataSourceProperties.getDataSourceClassName());
+        Map<String, Object> allProperties = getAllProperties(resource.getDataSources().get(dataSourceName));
+        Map<String, Object> standardProps = getStandardProperties(dataSourceProperties, poolMetaData, allProperties);
+        return getRowData(dataSourceName, poolMetaData, allProperties, standardProps);
+    }
+    
+    private Collection<Object> getRowData(final String dataSourceName, final DataSourcePoolMetaData poolMetaData, final Map<String, Object> allProperties, final Map<String, Object> standardProps) {
         DataSourceMetaData metaData = resource.getDataSourcesMetaData().getDataSourceMetaData(dataSourceName);
-        return Arrays.asList(dataSourceName, resource.getDatabaseType().getName(), metaData.getHostname(), metaData.getPort(), metaData.getCatalog(), 
-                new Gson().toJson(getFilteredUndisplayedProperties(dataSourcePropsMap.get(dataSourceName))));
+        Collection<Object> result = new LinkedList<>();
+        result.add(dataSourceName);
+        result.add(resource.getDatabaseType().getName());
+        result.add(metaData.getHostname());
+        result.add(metaData.getPort());
+        result.add(metaData.getCatalog());
+        result.add(getStandardProperty(standardProps, CONNECTION_TIMEOUT_MILLISECONDS));
+        result.add(getStandardProperty(standardProps, IDLE_TIMEOUT_MILLISECONDS));
+        result.add(getStandardProperty(standardProps, MAX_LIFETIME_MILLISECONDS));
+        result.add(getStandardProperty(standardProps, MAX_POOL_SIZE));
+        result.add(getStandardProperty(standardProps, MIN_POOL_SIZE));
+        result.add(getStandardProperty(standardProps, READ_ONLY));
+        result.add(new Gson().toJson(getFilteredUndisplayedProperties(poolMetaData, allProperties, standardProps)));
+        return result;
+    }
+    
+    private Map<String, Object> getAllProperties(final DataSource dataSource) {
+        DataSourceReflection dataSourceReflection = new DataSourceReflection(dataSource);
+        Map<String, Object> result = dataSourceReflection.convertToProperties();
+        return result;
     }
     
-    private Map<String, Object> getFilteredUndisplayedProperties(final DataSourceProperties dataSourceProperties) {
-        Map<String, Object> result = new HashMap<>(dataSourceProperties.getPoolPropertySynonyms().getStandardProperties());
-        for (Entry<String, Object> entry : dataSourceProperties.getCustomDataSourceProperties().getProperties().entrySet()) {
-            if (!(entry.getValue() instanceof Collection) && !(entry.getValue() instanceof Map)) {
-                result.put(entry.getKey(), entry.getValue());
+    private Map<String, Object> getStandardProperties(final DataSourceProperties dataSourceProperties, final DataSourcePoolMetaData poolMetaData, final Map<String, Object> allProperties) {

Review comment:
       It is unnecessary to call poolMetaData.getPropertySynonyms() again, just use dataSourceProperties.getPoolPropertySynonyms(), which has already set all necessary informations.

##########
File path: shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rql/resource/DataSourceQueryResultSet.java
##########
@@ -72,18 +90,66 @@ public boolean next() {
     @Override
     public Collection<Object> getRowData() {
         String dataSourceName = dataSourceNames.next();
+        DataSourceProperties dataSourceProperties = dataSourcePropsMap.get(dataSourceName);
+        DataSourcePoolMetaData poolMetaData = DataSourcePoolMetaDataFactory.newInstance(dataSourceProperties.getDataSourceClassName());
+        Map<String, Object> allProperties = getAllProperties(resource.getDataSources().get(dataSourceName));
+        Map<String, Object> standardProps = getStandardProperties(dataSourceProperties, poolMetaData, allProperties);
+        return getRowData(dataSourceName, poolMetaData, allProperties, standardProps);
+    }
+    
+    private Collection<Object> getRowData(final String dataSourceName, final DataSourcePoolMetaData poolMetaData, final Map<String, Object> allProperties, final Map<String, Object> standardProps) {
         DataSourceMetaData metaData = resource.getDataSourcesMetaData().getDataSourceMetaData(dataSourceName);
-        return Arrays.asList(dataSourceName, resource.getDatabaseType().getName(), metaData.getHostname(), metaData.getPort(), metaData.getCatalog(), 
-                new Gson().toJson(getFilteredUndisplayedProperties(dataSourcePropsMap.get(dataSourceName))));
+        Collection<Object> result = new LinkedList<>();
+        result.add(dataSourceName);
+        result.add(resource.getDatabaseType().getName());
+        result.add(metaData.getHostname());
+        result.add(metaData.getPort());
+        result.add(metaData.getCatalog());
+        result.add(getStandardProperty(standardProps, CONNECTION_TIMEOUT_MILLISECONDS));
+        result.add(getStandardProperty(standardProps, IDLE_TIMEOUT_MILLISECONDS));
+        result.add(getStandardProperty(standardProps, MAX_LIFETIME_MILLISECONDS));
+        result.add(getStandardProperty(standardProps, MAX_POOL_SIZE));
+        result.add(getStandardProperty(standardProps, MIN_POOL_SIZE));
+        result.add(getStandardProperty(standardProps, READ_ONLY));
+        result.add(new Gson().toJson(getFilteredUndisplayedProperties(poolMetaData, allProperties, standardProps)));
+        return result;
+    }
+    
+    private Map<String, Object> getAllProperties(final DataSource dataSource) {
+        DataSourceReflection dataSourceReflection = new DataSourceReflection(dataSource);
+        Map<String, Object> result = dataSourceReflection.convertToProperties();
+        return result;

Review comment:
       Just use `DataSourcePropertiesCreator.create()` to create DataSourceProperties, which include all processed properties.
   Please do not call `DataSourceReflection` directly, which is for DataSourceProperties's internal call only.

##########
File path: shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/datasource/pool/metadata/impl/HikariDataSourcePoolMetaData.java
##########
@@ -71,6 +71,8 @@ private void buildPropertySynonyms() {
     }
     
     private void buildTransientFieldNames() {
+        transientFieldNames.add("username");
+        transientFieldNames.add("password");

Review comment:
       The attributes of `username` and `password` should not add here.
   They are not transient fields, they just belong to connection properties.




-- 
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