You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@inlong.apache.org by "TYzzt (via GitHub)" <gi...@apache.org> on 2023/03/07 12:24:34 UTC

[GitHub] [inlong] TYzzt opened a new pull request, #7549: [INLONG-7548]Resource should be close

TYzzt opened a new pull request, #7549:
URL: https://github.com/apache/inlong/pull/7549

   ### Prepare a Pull Request
   Resource should be close
   
   
   - Fixes #7548 
   
   ### Motivation
   
   resource should be created using "try-with-resources" pattern and will be closed automatically.
   
   ### Verifying this change
   
   *(Please pick either of the following options)*
   
   - [ ] This change is a trivial rework/code cleanup without any test coverage.
   
   - [ ] This change is already covered by existing tests, such as:
     *(please describe tests)*
   
   - [ ] This change added tests and can be verified as follows:
   
     *(example:)*
     - *Added integration tests for end-to-end deployment with large payloads (10MB)*
     - *Extended integration test for recovery after broker failure*
   
   ### Documentation
   
     - Does this pull request introduce a new feature? (yes / no)
     - If yes, how is the feature documented? (not applicable / docs / JavaDocs / not documented)
     - If a feature is not applicable for documentation, explain why?
     - If a feature is not documented yet in this PR, please create a follow-up issue for adding the documentation
   


-- 
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: commits-unsubscribe@inlong.apache.org

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


[GitHub] [inlong] gong commented on a diff in pull request #7549: [INLONG-7548][Agent][Manager] Use try-with-resource to close resources

Posted by "gong (via GitHub)" <gi...@apache.org>.
gong commented on code in PR #7549:
URL: https://github.com/apache/inlong/pull/7549#discussion_r1129400873


##########
inlong-sort/sort-connectors/jdbc/src/main/java/org/apache/inlong/sort/jdbc/dialect/MySQLDialect.java:
##########
@@ -156,9 +156,10 @@ public List<LogicalTypeRoot> unsupportedTypes() {
 
     @Override
     public PreparedStatement setQueryPrimaryKeySql(Connection conn, String tableIdentifier) throws SQLException {
-        PreparedStatement st = conn.prepareStatement(QUERY_PRIMARY_KEY_SQL);
-        st.setString(1, JdbcMultiBatchingComm.getDatabaseNameFromIdentifier(tableIdentifier));
-        st.setString(2, JdbcMultiBatchingComm.getTableNameFromIdentifier(tableIdentifier));
-        return st;
+        try (PreparedStatement st = conn.prepareStatement(QUERY_PRIMARY_KEY_SQL)) {

Review Comment:
   I don't think here need to use try. AbstractJdbcDialect will close it.



-- 
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: commits-unsubscribe@inlong.apache.org

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


[GitHub] [inlong] TYzzt commented on a diff in pull request #7549: [INLONG-7548][Agent][Manager] Use try-with-resource to close resources

Posted by "TYzzt (via GitHub)" <gi...@apache.org>.
TYzzt commented on code in PR #7549:
URL: https://github.com/apache/inlong/pull/7549#discussion_r1129482377


##########
inlong-sort/sort-connectors/jdbc/src/main/java/org/apache/inlong/sort/jdbc/dialect/PostgresDialect.java:
##########
@@ -165,8 +165,9 @@ public List<LogicalTypeRoot> unsupportedTypes() {
     @Override
     public PreparedStatement setQueryPrimaryKeySql(Connection conn,
             String tableIdentifier) throws SQLException {
-        PreparedStatement st = conn.prepareStatement(QUERY_PRIMARY_KEY_SQL);
-        st.setString(1, JdbcMultiBatchingComm.getTableNameFromIdentifier(tableIdentifier));
-        return st;
+        try (PreparedStatement st = conn.prepareStatement(QUERY_PRIMARY_KEY_SQL)) {
+            st.setString(1, JdbcMultiBatchingComm.getTableNameFromIdentifier(tableIdentifier));
+            return st;
+        }
     }

Review Comment:
   restored



-- 
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: commits-unsubscribe@inlong.apache.org

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


[GitHub] [inlong] TYzzt commented on a diff in pull request #7549: [INLONG-7548][Agent][Manager] Use try-with-resource to close resources

Posted by "TYzzt (via GitHub)" <gi...@apache.org>.
TYzzt commented on code in PR #7549:
URL: https://github.com/apache/inlong/pull/7549#discussion_r1128992395


##########
inlong-manager/manager-common/src/main/java/org/apache/inlong/manager/common/util/AESUtils.java:
##########
@@ -58,8 +58,9 @@ public class AESUtils {
     private static Properties getApplicationProperties() throws IOException {
         Properties properties = new Properties();
         String path = Thread.currentThread().getContextClassLoader().getResource("").getPath() + CONFIG_FILE;
-        InputStream inputStream = new BufferedInputStream(Files.newInputStream(Paths.get(path)));
-        properties.load(inputStream);
+        try (InputStream inputStream = new BufferedInputStream(Files.newInputStream(Paths.get(path)))) {

Review Comment:
   two modifications have been added. not everyone resource should be close with try-with-resource



-- 
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: commits-unsubscribe@inlong.apache.org

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


[GitHub] [inlong] healchow merged pull request #7549: [INLONG-7548][Agent][Manager] Use try-with-resource to close resources

Posted by "healchow (via GitHub)" <gi...@apache.org>.
healchow merged PR #7549:
URL: https://github.com/apache/inlong/pull/7549


-- 
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: commits-unsubscribe@inlong.apache.org

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


[GitHub] [inlong] healchow commented on a diff in pull request #7549: [INLONG-7548][Agent][Manager] Use try-with-resource to close resources

Posted by "healchow (via GitHub)" <gi...@apache.org>.
healchow commented on code in PR #7549:
URL: https://github.com/apache/inlong/pull/7549#discussion_r1129017747


##########
inlong-sort/sort-connectors/jdbc/src/main/java/org/apache/inlong/sort/jdbc/dialect/MySQLDialect.java:
##########
@@ -156,9 +156,10 @@ public List<LogicalTypeRoot> unsupportedTypes() {
 
     @Override
     public PreparedStatement setQueryPrimaryKeySql(Connection conn, String tableIdentifier) throws SQLException {
-        PreparedStatement st = conn.prepareStatement(QUERY_PRIMARY_KEY_SQL);
-        st.setString(1, JdbcMultiBatchingComm.getDatabaseNameFromIdentifier(tableIdentifier));
-        st.setString(2, JdbcMultiBatchingComm.getTableNameFromIdentifier(tableIdentifier));
-        return st;
+        try (PreparedStatement st = conn.prepareStatement(QUERY_PRIMARY_KEY_SQL)) {

Review Comment:
   @gong Hi, please take a look at this modification.



-- 
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: commits-unsubscribe@inlong.apache.org

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


[GitHub] [inlong] vernedeng commented on a diff in pull request #7549: [INLONG-7548][Agent][Manager] Use try-with-resource to close resources

Posted by "vernedeng (via GitHub)" <gi...@apache.org>.
vernedeng commented on code in PR #7549:
URL: https://github.com/apache/inlong/pull/7549#discussion_r1128878288


##########
inlong-agent/agent-core/src/main/java/org/apache/inlong/agent/core/conf/ConfigJetty.java:
##########
@@ -62,10 +62,11 @@ public ConfigJetty(JobManager jobManager, TriggerManager triggerManager) {
     }
 
     private void initJetty() throws Exception {
-        ServerConnector connector = new ServerConnector(this.server);
-        connector.setPort(conf.getInt(
-                AgentConstants.AGENT_HTTP_PORT, AgentConstants.DEFAULT_AGENT_HTTP_PORT));
-        server.setConnectors(new Connector[]{connector});
+        try (ServerConnector connector = new ServerConnector(this.server)) {
+            connector.setPort(conf.getInt(
+                    AgentConstants.AGENT_HTTP_PORT, AgentConstants.DEFAULT_AGENT_HTTP_PORT));
+            server.setConnectors(new Connector[]{connector});
+        }

Review Comment:
   It seems that the server needs to hold this connector rather than close it immediately.
   The connector will be closed when call server.stop().



-- 
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: commits-unsubscribe@inlong.apache.org

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


[GitHub] [inlong] TYzzt commented on a diff in pull request #7549: [INLONG-7548][Agent][Manager] Use try-with-resource to close resources

Posted by "TYzzt (via GitHub)" <gi...@apache.org>.
TYzzt commented on code in PR #7549:
URL: https://github.com/apache/inlong/pull/7549#discussion_r1128991249


##########
inlong-agent/agent-core/src/main/java/org/apache/inlong/agent/core/conf/ConfigJetty.java:
##########
@@ -62,10 +62,11 @@ public ConfigJetty(JobManager jobManager, TriggerManager triggerManager) {
     }
 
     private void initJetty() throws Exception {
-        ServerConnector connector = new ServerConnector(this.server);
-        connector.setPort(conf.getInt(
-                AgentConstants.AGENT_HTTP_PORT, AgentConstants.DEFAULT_AGENT_HTTP_PORT));
-        server.setConnectors(new Connector[]{connector});
+        try (ServerConnector connector = new ServerConnector(this.server)) {
+            connector.setPort(conf.getInt(
+                    AgentConstants.AGENT_HTTP_PORT, AgentConstants.DEFAULT_AGENT_HTTP_PORT));
+            server.setConnectors(new Connector[]{connector});
+        }

Review Comment:
   restored



-- 
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: commits-unsubscribe@inlong.apache.org

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


[GitHub] [inlong] healchow commented on a diff in pull request #7549: [INLONG-7548][Agent][Manager] Use try-with-resource to close resources

Posted by "healchow (via GitHub)" <gi...@apache.org>.
healchow commented on code in PR #7549:
URL: https://github.com/apache/inlong/pull/7549#discussion_r1128795523


##########
inlong-manager/manager-common/src/main/java/org/apache/inlong/manager/common/util/AESUtils.java:
##########
@@ -58,8 +58,9 @@ public class AESUtils {
     private static Properties getApplicationProperties() throws IOException {
         Properties properties = new Properties();
         String path = Thread.currentThread().getContextClassLoader().getResource("").getPath() + CONFIG_FILE;
-        InputStream inputStream = new BufferedInputStream(Files.newInputStream(Paths.get(path)));
-        properties.load(inputStream);
+        try (InputStream inputStream = new BufferedInputStream(Files.newInputStream(Paths.get(path)))) {

Review Comment:
   Hello @TYzzt, thanks for your contribution.
   
   Is there any other similar code that needs to be modified?



-- 
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: commits-unsubscribe@inlong.apache.org

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


[GitHub] [inlong] gong commented on a diff in pull request #7549: [INLONG-7548][Agent][Manager] Use try-with-resource to close resources

Posted by "gong (via GitHub)" <gi...@apache.org>.
gong commented on code in PR #7549:
URL: https://github.com/apache/inlong/pull/7549#discussion_r1129401143


##########
inlong-sort/sort-connectors/jdbc/src/main/java/org/apache/inlong/sort/jdbc/dialect/PostgresDialect.java:
##########
@@ -165,8 +165,9 @@ public List<LogicalTypeRoot> unsupportedTypes() {
     @Override
     public PreparedStatement setQueryPrimaryKeySql(Connection conn,
             String tableIdentifier) throws SQLException {
-        PreparedStatement st = conn.prepareStatement(QUERY_PRIMARY_KEY_SQL);
-        st.setString(1, JdbcMultiBatchingComm.getTableNameFromIdentifier(tableIdentifier));
-        return st;
+        try (PreparedStatement st = conn.prepareStatement(QUERY_PRIMARY_KEY_SQL)) {
+            st.setString(1, JdbcMultiBatchingComm.getTableNameFromIdentifier(tableIdentifier));
+            return st;
+        }
     }

Review Comment:
   I don't think here need to use try. AbstractJdbcDialect will close it.



-- 
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: commits-unsubscribe@inlong.apache.org

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