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/10/14 06:58:47 UTC

[GitHub] [shardingsphere] roodkcab opened a new pull request #13034: #13033 close connection after get source of information_schema

roodkcab opened a new pull request #13034:
URL: https://github.com/apache/shardingsphere/pull/13034


   Fixes #13033 .
   
   Changes proposed in this pull request:
   - close connection after get source of information_schema
   


-- 
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] lanchengx commented on a change in pull request #13034: #13033 close connection after get source of information_schema

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



##########
File path: shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/information/AbstractSelectInformationExecutor.java
##########
@@ -153,7 +153,14 @@ protected Object getSourceData(final String schemaName) throws SQLException {
             ShardingSphereResource resource = ProxyContext.getInstance().getContextManager().getMetaDataContexts().getMetaData(schemaName).getResource();
             Optional<Entry<String, DataSource>> dataSourceEntry = resource.getDataSources().entrySet().stream().findFirst();
             log.info("Actual SQL: {} ::: {}", dataSourceEntry.orElseThrow(DatabaseNotExistedException::new).getKey(), sql);
-            return dataSourceEntry.get().getValue().getConnection().prepareStatement(sql).executeQuery();
+            Connection conn = dataSourceEntry.get().getValue().getConnection();
+            try {
+                return conn.prepareStatement(sql).executeQuery();
+            } catch (SQLException e) {
+                throw e;
+            } finally {
+                conn.close();
+            }

Review comment:
       It is correct, but after closing, we can't get the query result in `ResultSet`, so we need to copy the data in `ResultSet` as the return 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.

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

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



[GitHub] [shardingsphere] roodkcab commented on pull request #13034: #13033 close connection after get source of information_schema

Posted by GitBox <gi...@apache.org>.
roodkcab commented on pull request #13034:
URL: https://github.com/apache/shardingsphere/pull/13034#issuecomment-945329217


   @lanchengx @RaigorJiang @tristaZero  it seems everything is ok, do I need to squash all commits into one? and any other thing to do?


-- 
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] RaigorJiang commented on pull request #13034: #13033 close connection after get source of information_schema

Posted by GitBox <gi...@apache.org>.
RaigorJiang commented on pull request #13034:
URL: https://github.com/apache/shardingsphere/pull/13034#issuecomment-945332174


   > @lanchengx @RaigorJiang @tristaZero it seems everything is ok, do I need to squash all commits into one? and any other thing to do?
   
   Hi @roodkcab, thanks for your work, @lanchengx will review again.


-- 
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] roodkcab commented on pull request #13034: #13033 close connection after get source of information_schema

Posted by GitBox <gi...@apache.org>.
roodkcab commented on pull request #13034:
URL: https://github.com/apache/shardingsphere/pull/13034#issuecomment-945382916


   @lanchengx check again please


-- 
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] RaigorJiang commented on pull request #13034: #13033 close connection after get source of information_schema

Posted by GitBox <gi...@apache.org>.
RaigorJiang commented on pull request #13034:
URL: https://github.com/apache/shardingsphere/pull/13034#issuecomment-945566285


   Hi @tristaZero, please take a review, thank you!


-- 
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] tristaZero merged pull request #13034: #13033 close connection after get source of information_schema

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


   


-- 
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] roodkcab commented on a change in pull request #13034: #13033 close connection after get source of information_schema

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



##########
File path: shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/information/AbstractSelectInformationExecutor.java
##########
@@ -153,7 +153,14 @@ protected Object getSourceData(final String schemaName) throws SQLException {
             ShardingSphereResource resource = ProxyContext.getInstance().getContextManager().getMetaDataContexts().getMetaData(schemaName).getResource();
             Optional<Entry<String, DataSource>> dataSourceEntry = resource.getDataSources().entrySet().stream().findFirst();
             log.info("Actual SQL: {} ::: {}", dataSourceEntry.orElseThrow(DatabaseNotExistedException::new).getKey(), sql);
-            return dataSourceEntry.get().getValue().getConnection().prepareStatement(sql).executeQuery();
+            Connection conn = dataSourceEntry.get().getValue().getConnection();
+            try {
+                return conn.prepareStatement(sql).executeQuery();
+            } catch (SQLException e) {
+                throw e;
+            } finally {
+                conn.close();
+            }

Review comment:
       how about 
   ```
   try (Connection conn = dataSourceEntry.get().getValue().getConnection(); PreparedStatement ps = conn.prepareStatement(sql);) {
     return ps.executeQuery();
   }
   ```




-- 
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] roodkcab commented on pull request #13034: #13033 close connection after get source of information_schema

Posted by GitBox <gi...@apache.org>.
roodkcab commented on pull request #13034:
URL: https://github.com/apache/shardingsphere/pull/13034#issuecomment-945238530


   > @roodkcab I found there are a few failed CI tests. Could you check them again?
   
   sure, I'll have a check


-- 
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] roodkcab commented on a change in pull request #13034: #13033 close connection after get source of information_schema

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



##########
File path: shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/information/AbstractSelectInformationExecutor.java
##########
@@ -153,7 +153,14 @@ protected Object getSourceData(final String schemaName) throws SQLException {
             ShardingSphereResource resource = ProxyContext.getInstance().getContextManager().getMetaDataContexts().getMetaData(schemaName).getResource();
             Optional<Entry<String, DataSource>> dataSourceEntry = resource.getDataSources().entrySet().stream().findFirst();
             log.info("Actual SQL: {} ::: {}", dataSourceEntry.orElseThrow(DatabaseNotExistedException::new).getKey(), sql);
-            return dataSourceEntry.get().getValue().getConnection().prepareStatement(sql).executeQuery();
+            Connection conn = dataSourceEntry.get().getValue().getConnection();
+            try {
+                return conn.prepareStatement(sql).executeQuery();
+            } catch (SQLException e) {
+                throw e;
+            } finally {
+                conn.close();
+            }

Review comment:
       then I'd prefer to use closure instead of copy




-- 
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] lanchengx commented on a change in pull request #13034: #13033 close connection after get source of information_schema

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



##########
File path: shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/information/AbstractSelectInformationExecutor.java
##########
@@ -64,7 +71,7 @@
     public final void execute(final BackendConnection backendConnection) throws SQLException {
         List<String> schemaNames = getSchemaNames();
         for (String schemaName : schemaNames) {
-            constructRowData(schemaName, getSourceData(schemaName));
+            getSourceData(schemaName, constructRowData(schemaName));
         }

Review comment:
       Sry, I'm not sure if you saw this comment https://github.com/apache/shardingsphere/pull/13034#discussion_r728881662, do you have any other good ideas about naming?




-- 
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] tristaZero commented on pull request #13034: #13033 close connection after get source of information_schema

Posted by GitBox <gi...@apache.org>.
tristaZero commented on pull request #13034:
URL: https://github.com/apache/shardingsphere/pull/13034#issuecomment-944843605


   @roodkcab Hey thanks @lanchengx Please review again


-- 
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] lanchengx commented on a change in pull request #13034: #13033 close connection after get source of information_schema

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



##########
File path: shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/information/AbstractSelectInformationExecutor.java
##########
@@ -153,7 +153,14 @@ protected Object getSourceData(final String schemaName) throws SQLException {
             ShardingSphereResource resource = ProxyContext.getInstance().getContextManager().getMetaDataContexts().getMetaData(schemaName).getResource();
             Optional<Entry<String, DataSource>> dataSourceEntry = resource.getDataSources().entrySet().stream().findFirst();
             log.info("Actual SQL: {} ::: {}", dataSourceEntry.orElseThrow(DatabaseNotExistedException::new).getKey(), sql);
-            return dataSourceEntry.get().getValue().getConnection().prepareStatement(sql).executeQuery();
+            Connection conn = dataSourceEntry.get().getValue().getConnection();
+            try {
+                return conn.prepareStatement(sql).executeQuery();
+            } catch (SQLException e) {
+                throw e;
+            } finally {
+                conn.close();
+            }

Review comment:
       Good idea, do you think we should modify the method name to make the intent of the method better understandable?  
   For example, modify `getSourceData` to `constructRowData`, modify the original `constructRowData` to `doConstruct`, or other better names




-- 
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] tristaZero removed a comment on pull request #13034: #13033 close connection after get source of information_schema

Posted by GitBox <gi...@apache.org>.
tristaZero removed a comment on pull request #13034:
URL: https://github.com/apache/shardingsphere/pull/13034#issuecomment-944843605


   @roodkcab Hey thanks @lanchengx Please review again


-- 
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] lanchengx commented on a change in pull request #13034: #13033 close connection after get source of information_schema

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



##########
File path: shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/information/AbstractSelectInformationExecutor.java
##########
@@ -153,7 +153,14 @@ protected Object getSourceData(final String schemaName) throws SQLException {
             ShardingSphereResource resource = ProxyContext.getInstance().getContextManager().getMetaDataContexts().getMetaData(schemaName).getResource();
             Optional<Entry<String, DataSource>> dataSourceEntry = resource.getDataSources().entrySet().stream().findFirst();
             log.info("Actual SQL: {} ::: {}", dataSourceEntry.orElseThrow(DatabaseNotExistedException::new).getKey(), sql);
-            return dataSourceEntry.get().getValue().getConnection().prepareStatement(sql).executeQuery();
+            Connection conn = dataSourceEntry.get().getValue().getConnection();
+            try {
+                return conn.prepareStatement(sql).executeQuery();
+            } catch (SQLException e) {
+                throw e;
+            } finally {
+                conn.close();
+            }

Review comment:
       In addition, you can use the `checkStyle` plugin to check the code format, this is the result of my checking this file.
   
   ![image](https://user-images.githubusercontent.com/52209337/137307961-f94af765-5aab-409e-b59e-b8f18b5dd84f.png)
   
   ![image](https://user-images.githubusercontent.com/52209337/137308385-b8933abe-e7b3-4df8-9d1e-8dc10252a84f.png)
   




-- 
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] lanchengx commented on a change in pull request #13034: #13033 close connection after get source of information_schema

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



##########
File path: shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/information/AbstractSelectInformationExecutor.java
##########
@@ -153,7 +153,14 @@ protected Object getSourceData(final String schemaName) throws SQLException {
             ShardingSphereResource resource = ProxyContext.getInstance().getContextManager().getMetaDataContexts().getMetaData(schemaName).getResource();
             Optional<Entry<String, DataSource>> dataSourceEntry = resource.getDataSources().entrySet().stream().findFirst();
             log.info("Actual SQL: {} ::: {}", dataSourceEntry.orElseThrow(DatabaseNotExistedException::new).getKey(), sql);
-            return dataSourceEntry.get().getValue().getConnection().prepareStatement(sql).executeQuery();
+            Connection conn = dataSourceEntry.get().getValue().getConnection();
+            try {
+                return conn.prepareStatement(sql).executeQuery();
+            } catch (SQLException e) {
+                throw e;
+            } finally {
+                conn.close();
+            }

Review comment:
       I'm not sure if you saw this comment https://github.com/apache/shardingsphere/pull/13034#discussion_r728881662, do you have any other good ideas?




-- 
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] roodkcab commented on a change in pull request #13034: #13033 close connection after get source of information_schema

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



##########
File path: shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/information/AbstractSelectInformationExecutor.java
##########
@@ -153,7 +153,14 @@ protected Object getSourceData(final String schemaName) throws SQLException {
             ShardingSphereResource resource = ProxyContext.getInstance().getContextManager().getMetaDataContexts().getMetaData(schemaName).getResource();
             Optional<Entry<String, DataSource>> dataSourceEntry = resource.getDataSources().entrySet().stream().findFirst();
             log.info("Actual SQL: {} ::: {}", dataSourceEntry.orElseThrow(DatabaseNotExistedException::new).getKey(), sql);
-            return dataSourceEntry.get().getValue().getConnection().prepareStatement(sql).executeQuery();
+            Connection conn = dataSourceEntry.get().getValue().getConnection();
+            try {
+                return conn.prepareStatement(sql).executeQuery();
+            } catch (SQLException e) {
+                throw e;
+            } finally {
+                conn.close();
+            }

Review comment:
       > In addition, you can use the `checkStyle` plugin to check the code format, this is the result of my checking this file.
   > 
   > ![image](https://user-images.githubusercontent.com/52209337/137307961-f94af765-5aab-409e-b59e-b8f18b5dd84f.png)
   > 
   > ![image](https://user-images.githubusercontent.com/52209337/137308385-b8933abe-e7b3-4df8-9d1e-8dc10252a84f.png)
   
   sorry, forget to open such plugin, will resubmit later




-- 
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] lanchengx commented on a change in pull request #13034: #13033 close connection after get source of information_schema

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



##########
File path: shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/information/AbstractSelectInformationExecutor.java
##########
@@ -153,7 +153,14 @@ protected Object getSourceData(final String schemaName) throws SQLException {
             ShardingSphereResource resource = ProxyContext.getInstance().getContextManager().getMetaDataContexts().getMetaData(schemaName).getResource();
             Optional<Entry<String, DataSource>> dataSourceEntry = resource.getDataSources().entrySet().stream().findFirst();
             log.info("Actual SQL: {} ::: {}", dataSourceEntry.orElseThrow(DatabaseNotExistedException::new).getKey(), sql);
-            return dataSourceEntry.get().getValue().getConnection().prepareStatement(sql).executeQuery();
+            Connection conn = dataSourceEntry.get().getValue().getConnection();
+            try {
+                return conn.prepareStatement(sql).executeQuery();
+            } catch (SQLException e) {
+                throw e;
+            } finally {
+                conn.close();
+            }

Review comment:
       @roodkcab Thanks for your PR,could you use `try-with-resources`?
   More importantly, it may be necessary to copy the `ResultSet as` the return result, and then close the connection

##########
File path: shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/information/AbstractSelectInformationExecutor.java
##########
@@ -153,7 +153,14 @@ protected Object getSourceData(final String schemaName) throws SQLException {
             ShardingSphereResource resource = ProxyContext.getInstance().getContextManager().getMetaDataContexts().getMetaData(schemaName).getResource();
             Optional<Entry<String, DataSource>> dataSourceEntry = resource.getDataSources().entrySet().stream().findFirst();
             log.info("Actual SQL: {} ::: {}", dataSourceEntry.orElseThrow(DatabaseNotExistedException::new).getKey(), sql);
-            return dataSourceEntry.get().getValue().getConnection().prepareStatement(sql).executeQuery();
+            Connection conn = dataSourceEntry.get().getValue().getConnection();
+            try {
+                return conn.prepareStatement(sql).executeQuery();
+            } catch (SQLException e) {
+                throw e;
+            } finally {
+                conn.close();
+            }

Review comment:
       @roodkcab Thanks for your PR,could you use `try-with-resources`?
   More importantly, it may be necessary to copy the `ResultSet` as the return result, and then close the connection




-- 
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] roodkcab commented on a change in pull request #13034: #13033 close connection after get source of information_schema

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



##########
File path: shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/information/AbstractSelectInformationExecutor.java
##########
@@ -153,7 +153,14 @@ protected Object getSourceData(final String schemaName) throws SQLException {
             ShardingSphereResource resource = ProxyContext.getInstance().getContextManager().getMetaDataContexts().getMetaData(schemaName).getResource();
             Optional<Entry<String, DataSource>> dataSourceEntry = resource.getDataSources().entrySet().stream().findFirst();
             log.info("Actual SQL: {} ::: {}", dataSourceEntry.orElseThrow(DatabaseNotExistedException::new).getKey(), sql);
-            return dataSourceEntry.get().getValue().getConnection().prepareStatement(sql).executeQuery();
+            Connection conn = dataSourceEntry.get().getValue().getConnection();
+            try {
+                return conn.prepareStatement(sql).executeQuery();
+            } catch (SQLException e) {
+                throw e;
+            } finally {
+                conn.close();
+            }

Review comment:
       use callback in try-with-resouce
   ```
   try (Connection conn = dataSourceEntry.get().getValue().getConnection(); PreparedStatement ps = conn.prepareStatement(sql);) {
     callback(ps.executeQuery());
   }
   ```
   where build callback functor from constructRowData




-- 
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] roodkcab commented on pull request #13034: #13033 close connection after get source of information_schema

Posted by GitBox <gi...@apache.org>.
roodkcab commented on pull request #13034:
URL: https://github.com/apache/shardingsphere/pull/13034#issuecomment-945244399


   @tristaZero run workflow again please, or can I have permission to run ci?


-- 
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] lanchengx commented on pull request #13034: #13033 close connection after get source of information_schema

Posted by GitBox <gi...@apache.org>.
lanchengx commented on pull request #13034:
URL: https://github.com/apache/shardingsphere/pull/13034#issuecomment-945333954


   > @lanchengx @RaigorJiang @tristaZero it seems everything is ok, do I need to squash all commits into one? and any other thing to do?
   
   Thank you for your work, but we still have some requirements on the format and capitalization,
   You still need to deal with the issue of my previous comment.
   
   such as
   
   ![image](https://user-images.githubusercontent.com/52209337/137665024-633bed4b-3ae1-44ad-95be-83cf7c1f6195.png)
   
   ![image](https://user-images.githubusercontent.com/52209337/137665080-e411b1c2-9466-4858-815a-09669c9fd1cd.png)
   


-- 
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] lanchengx commented on a change in pull request #13034: #13033 close connection after get source of information_schema

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



##########
File path: shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/information/AbstractSelectInformationExecutor.java
##########
@@ -153,7 +153,14 @@ protected Object getSourceData(final String schemaName) throws SQLException {
             ShardingSphereResource resource = ProxyContext.getInstance().getContextManager().getMetaDataContexts().getMetaData(schemaName).getResource();
             Optional<Entry<String, DataSource>> dataSourceEntry = resource.getDataSources().entrySet().stream().findFirst();
             log.info("Actual SQL: {} ::: {}", dataSourceEntry.orElseThrow(DatabaseNotExistedException::new).getKey(), sql);
-            return dataSourceEntry.get().getValue().getConnection().prepareStatement(sql).executeQuery();
+            Connection conn = dataSourceEntry.get().getValue().getConnection();
+            try {
+                return conn.prepareStatement(sql).executeQuery();
+            } catch (SQLException e) {
+                throw e;
+            } finally {
+                conn.close();
+            }

Review comment:
       In addition, you can use the `checkStyle` plugin to check the code format, this is the result of my checking this file.
   
   ![image](https://user-images.githubusercontent.com/52209337/137307961-f94af765-5aab-409e-b59e-b8f18b5dd84f.png)
   




-- 
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] lanchengx commented on a change in pull request #13034: #13033 close connection after get source of information_schema

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



##########
File path: shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/information/AbstractSelectInformationExecutor.java
##########
@@ -81,20 +96,18 @@ public final void execute(final BackendConnection backendConnection) throws SQLE
      * Get the source object of the row data.
      *
      * @param schemaName schema name
-     * @return source object of row data
-     * @throws SQLException SQLException
+     * @param FunctionWithException callback
      */
-    protected abstract Object getSourceData(String schemaName) throws SQLException;
-    
+    protected abstract void getSourceData(String schemaName, FunctionWithException<ResultSet, Void, SQLException> callback) throws SQLException;
+
     /**
-     * Construct row data from source data.
+     * Get the source object of the row data.
      *
      * @param schemaName schema name
-     * @param sourceData source data of row data
-     * @throws SQLException SQLException
+     * @param Map rows
      */

Review comment:
       Here we should probably use the parameter name instead of the parameter type

##########
File path: shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/information/AbstractSelectInformationExecutor.java
##########
@@ -50,7 +52,7 @@
  * The abstract class of select information schema, used to define the template.
  */
 public abstract class AbstractSelectInformationExecutor implements DatabaseAdminQueryExecutor {
-    
+
     @Getter

Review comment:
       Sorry for the late reply, Could you adjust your format? We want to modify as little as possible.

##########
File path: shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/information/FunctionWithException.java
##########
@@ -0,0 +1,34 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.proxy.backend.text.admin.mysql.executor.information;
+
+/**
+ * FunctionWithException Interface.
+ */
+@FunctionalInterface
+public interface FunctionWithException<T, R, E extends Exception> {
+
+    /**
+     * apply function.

Review comment:
       The first letter of apply may need to be capitalized.

##########
File path: shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/information/FunctionWithException.java
##########
@@ -0,0 +1,34 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.proxy.backend.text.admin.mysql.executor.information;
+
+/**
+ * FunctionWithException Interface.
+ */

Review comment:
       Interface should probably be lowercase.

##########
File path: shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/information/AbstractSelectInformationExecutor.java
##########
@@ -145,46 +159,26 @@ public DefaultSelectInformationExecutor(final String sql) {
          * Get the source data of the row data.
          *
          * @param schemaName schema name
-         * @return source data of row data
          * @throws SQLException SQLException
          */
         @Override
-        protected Object getSourceData(final String schemaName) throws SQLException {
+        protected void getSourceData(final String schemaName, final FunctionWithException<ResultSet, Void, SQLException> callback) throws SQLException {
             ShardingSphereResource resource = ProxyContext.getInstance().getContextManager().getMetaDataContexts().getMetaData(schemaName).getResource();
             Optional<Entry<String, DataSource>> dataSourceEntry = resource.getDataSources().entrySet().stream().findFirst();
             log.info("Actual SQL: {} ::: {}", dataSourceEntry.orElseThrow(DatabaseNotExistedException::new).getKey(), sql);
-            return dataSourceEntry.get().getValue().getConnection().prepareStatement(sql).executeQuery();
-        }
-        
-        /**
-         * Construct row data from source data.
-         *
-         * @param schemaName schema name
-         * @param sourceData source data of row data
-         * @throws SQLException SQLException
-         */
-        @Override
-        protected void constructRowData(final String schemaName, final Object sourceData) throws SQLException {
-            ResultSet resultSet = (ResultSet) sourceData;
-            while (resultSet.next()) {
-                Map<String, Object> row = new HashMap<>();
-                ResultSetMetaData metaData = resultSet.getMetaData();
-                for (int i = 1; i < metaData.getColumnCount() + 1; i++) {
-                    row.put(resultSet.getMetaData().getColumnName(i), resultSet.getString(i));
-                }
-                rowPostProcessing(schemaName, row);
-                if (!row.isEmpty()) {
-                    getRows().addFirst(row);
-                }
+            try (Connection conn = dataSourceEntry.get().getValue().getConnection();
+                 PreparedStatement ps = conn.prepareStatement(sql)) {
+                callback.apply(ps.executeQuery());
             }
         }
-        
+

Review comment:
       This line should be indented the same as the previous line

##########
File path: shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/information/AbstractSelectInformationExecutor.java
##########
@@ -81,20 +96,18 @@ public final void execute(final BackendConnection backendConnection) throws SQLE
      * Get the source object of the row data.
      *
      * @param schemaName schema name
-     * @return source object of row data
-     * @throws SQLException SQLException
+     * @param FunctionWithException callback

Review comment:
       Here we should probably use the parameter name instead of the parameter type.

##########
File path: shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/information/AbstractSelectInformationExecutor.java
##########
@@ -59,12 +61,25 @@
     
     @Getter
     private final LinkedList<Map<String, Object>> rows = new LinkedList<>();
-    
+

Review comment:
       This line should be indented the same as the previous line




-- 
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] lanchengx edited a comment on pull request #13034: #13033 close connection after get source of information_schema

Posted by GitBox <gi...@apache.org>.
lanchengx edited a comment on pull request #13034:
URL: https://github.com/apache/shardingsphere/pull/13034#issuecomment-945333954


   > @lanchengx @RaigorJiang @tristaZero it seems everything is ok, do I need to squash all commits into one? and any other thing to do?
   
   Thank you for your work, but we still have some requirements on the format and capitalization,
   You still need to deal with the issue of my previous comment.
   


-- 
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] lanchengx edited a comment on pull request #13034: #13033 close connection after get source of information_schema

Posted by GitBox <gi...@apache.org>.
lanchengx edited a comment on pull request #13034:
URL: https://github.com/apache/shardingsphere/pull/13034#issuecomment-945395990


   > @lanchengx check again please
   
   @roodkcab Thank you for your work, Do you think there is any problem? @RaigorJiang 
   


-- 
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] tristaZero commented on pull request #13034: #13033 close connection after get source of information_schema

Posted by GitBox <gi...@apache.org>.
tristaZero commented on pull request #13034:
URL: https://github.com/apache/shardingsphere/pull/13034#issuecomment-945056396


   @roodkcab I found there are a few failed CI tests. Could you check them again?


-- 
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] roodkcab commented on a change in pull request #13034: #13033 close connection after get source of information_schema

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



##########
File path: shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/information/AbstractSelectInformationExecutor.java
##########
@@ -153,7 +153,14 @@ protected Object getSourceData(final String schemaName) throws SQLException {
             ShardingSphereResource resource = ProxyContext.getInstance().getContextManager().getMetaDataContexts().getMetaData(schemaName).getResource();
             Optional<Entry<String, DataSource>> dataSourceEntry = resource.getDataSources().entrySet().stream().findFirst();
             log.info("Actual SQL: {} ::: {}", dataSourceEntry.orElseThrow(DatabaseNotExistedException::new).getKey(), sql);
-            return dataSourceEntry.get().getValue().getConnection().prepareStatement(sql).executeQuery();
+            Connection conn = dataSourceEntry.get().getValue().getConnection();
+            try {
+                return conn.prepareStatement(sql).executeQuery();
+            } catch (SQLException e) {
+                throw e;
+            } finally {
+                conn.close();
+            }

Review comment:
       use callback in try-with-resouce
   ```
   try (Connection conn = dataSourceEntry.get().getValue().getConnection(); PreparedStatement ps = conn.prepareStatement(sql);) {
     callback(ps.executeQuery());
   }
   ```
   where build callback functor from constructRowData
   then turn ```constructRowData(schemaName, getSourceData(schemaName))``` into ```getSourceData(schemaName, constructRowData(schemaName))```




-- 
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] lanchengx commented on pull request #13034: #13033 close connection after get source of information_schema

Posted by GitBox <gi...@apache.org>.
lanchengx commented on pull request #13034:
URL: https://github.com/apache/shardingsphere/pull/13034#issuecomment-945395990


   > @lanchengx check again please
   
   Thank you for your work, Do you think there is any problem? @RaigorJiang 
   


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