You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@inlong.apache.org by GitBox <gi...@apache.org> on 2022/03/19 05:59:55 UTC

[GitHub] [incubator-inlong] vernedeng opened a new pull request #3240: [INLONG-3237][Sort-Standalone] SdkSource support periodiclly update sdk config and remove expire client.

vernedeng opened a new pull request #3240:
URL: https://github.com/apache/incubator-inlong/pull/3240


   ### Title Name: [INLONG-3237][Sort-Standalone] SdkSource support periodiclly update sdk config and remove expire client.
   
   Fixes #3237 
   
   ### Motivation
   
   1. update sdk config periodiclly, to avoid the case that the init manager node offline and sdk cannot request config.
   2. remove expire client, if the task has been removed from SortClusterConfig.
   
   ### Modifications
   
   *Describe the modifications you've done.*
   
   ### Verifying this change
   
   - [ ] Make sure that the change passes the CI checks.
   
   *(Please pick either of the following options)*
   
   This change is a trivial rework / code cleanup without any test coverage.
   
   *(or)*
   
   This change is already covered by existing tests, such as *(please describe tests)*.
   
   *(or)*
   
   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 followup 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] [incubator-inlong] vernedeng commented on a change in pull request #3240: [INLONG-3237][Sort-Standalone] SdkSource support periodiclly update sdk config and remove expire client.

Posted by GitBox <gi...@apache.org>.
vernedeng commented on a change in pull request #3240:
URL: https://github.com/apache/incubator-inlong/pull/3240#discussion_r830459694



##########
File path: inlong-sort-standalone/sort-standalone-source/src/main/java/org/apache/inlong/sort/standalone/source/sortsdk/SortSdkSource.java
##########
@@ -132,30 +136,78 @@ private void initReloadExecutor() {
      * <p> Create new clients with new sort task id, and remove the finished or scheduled ones. </p>
      *
      * <p> Current version of SortSdk <b>DO NOT</b> support to get the corresponding sort id of {@link SortClient}.
-     * Hence, the maintenance of mapping of {@literal sortId, SortClient} should be done by Source itself. Which
-     * is not elegant, the <b>REMOVE</b> of expire clients will <b>NOT</b> be supported right now. </p>
+     * Hence, the maintenance of mapping of {@literal sortId, SortClient} should be done by Source itself.
      */
-    private void reload() {
+    private void reloadAll() {
 
         final List<SortTaskConfig> configs = SortClusterConfigHolder.getClusterConfig().getSortTasks();
         LOG.info("start to reload SortSdkSource");
+        this.startNewClients(configs);
+        this.stopExpiryClients(configs);
+        this.updateAllClientConfig();
+    }
 
-        // Start new clients
-        for (SortTaskConfig taskConfig : configs) {
-
-            // If exits, skip.
-            final String sortId = taskConfig.getName();
-            SortClient client = this.clients.get(sortId);
-            if (client != null) {
-                continue;
-            }
-
-            // Otherwise, new one client.
-            client = this.newClient(sortId);
-            if (client != null) {
-                this.clients.put(sortId, client);
-            }
-        }
+    /**
+     * Start a new client from SortTaskConfig.
+     * <p>
+     *     If the sortId is in configs, but not in active clients, start it.
+     * </p>
+     *
+     * @param configs Updated SortTaskConfig
+     */
+    private void startNewClients(final List<SortTaskConfig> configs) {
+        configs.stream()
+                .map(SortTaskConfig::getName)
+                .filter(sortId -> !clients.containsKey(sortId))
+                .forEach(sortId -> {
+                    final SortClient client = this.newClient(sortId);
+                    Optional.ofNullable(client)
+                            .ifPresent(c -> clients.put(sortId, c));
+                });
+    }
+
+    /**
+     * Stop an expiry client from SortTaskConfig.
+     * <p>
+     *     If the sortId is not in active clients, but not in configs, stop it.
+     * </p>
+     *
+     * @param configs Updated SortTaskConfig
+     */
+    private void stopExpiryClients(final List<SortTaskConfig> configs) {
+        Set<String> updatedSortIds = configs.stream()
+                .map(SortTaskConfig::getName)
+                .collect(Collectors.toSet());
+
+        clients.keySet().stream()
+                .filter(updatedSortIds::contains)
+                .forEach(sortId -> {
+                    final SortClient client = clients.get(sortId);
+                    try {
+                        client.close();
+                    } catch (Throwable th) {
+                        LOG.error("Got a throwable when close client {}, {}", sortId, th.getMessage());
+                    }
+                    clients.remove(sortId);
+                });
+    }
+
+    /**
+     * Update all client config.
+     */
+    private void updateAllClientConfig() {
+        clients.values().stream()
+                .map(SortClient::getConfig)
+                .forEach(this::updateClientConfig);
+    }
+
+    /**
+     * Update one client config.
+     *
+     * @param config The config to be updated.
+     */
+    private void updateClientConfig(SortClientConfig config) {
+        config.setManagerApiUrl(CommonPropertiesHolder.getSourceConfigManagerUrl());

Review comment:
       it will support in #3243

##########
File path: inlong-sort-standalone/sort-standalone-source/src/main/java/org/apache/inlong/sort/standalone/source/sortsdk/SortSdkSource.java
##########
@@ -132,30 +136,78 @@ private void initReloadExecutor() {
      * <p> Create new clients with new sort task id, and remove the finished or scheduled ones. </p>
      *
      * <p> Current version of SortSdk <b>DO NOT</b> support to get the corresponding sort id of {@link SortClient}.
-     * Hence, the maintenance of mapping of {@literal sortId, SortClient} should be done by Source itself. Which
-     * is not elegant, the <b>REMOVE</b> of expire clients will <b>NOT</b> be supported right now. </p>
+     * Hence, the maintenance of mapping of {@literal sortId, SortClient} should be done by Source itself.
      */
-    private void reload() {
+    private void reloadAll() {
 
         final List<SortTaskConfig> configs = SortClusterConfigHolder.getClusterConfig().getSortTasks();
         LOG.info("start to reload SortSdkSource");
+        this.startNewClients(configs);
+        this.stopExpiryClients(configs);
+        this.updateAllClientConfig();
+    }
 
-        // Start new clients
-        for (SortTaskConfig taskConfig : configs) {
-
-            // If exits, skip.
-            final String sortId = taskConfig.getName();
-            SortClient client = this.clients.get(sortId);
-            if (client != null) {
-                continue;
-            }
-
-            // Otherwise, new one client.
-            client = this.newClient(sortId);
-            if (client != null) {
-                this.clients.put(sortId, client);
-            }
-        }
+    /**
+     * Start a new client from SortTaskConfig.
+     * <p>
+     *     If the sortId is in configs, but not in active clients, start it.
+     * </p>
+     *
+     * @param configs Updated SortTaskConfig
+     */
+    private void startNewClients(final List<SortTaskConfig> configs) {
+        configs.stream()
+                .map(SortTaskConfig::getName)
+                .filter(sortId -> !clients.containsKey(sortId))
+                .forEach(sortId -> {
+                    final SortClient client = this.newClient(sortId);
+                    Optional.ofNullable(client)
+                            .ifPresent(c -> clients.put(sortId, c));
+                });
+    }
+
+    /**
+     * Stop an expiry client from SortTaskConfig.
+     * <p>
+     *     If the sortId is not in active clients, but not in configs, stop it.
+     * </p>
+     *
+     * @param configs Updated SortTaskConfig
+     */
+    private void stopExpiryClients(final List<SortTaskConfig> configs) {
+        Set<String> updatedSortIds = configs.stream()
+                .map(SortTaskConfig::getName)
+                .collect(Collectors.toSet());
+
+        clients.keySet().stream()
+                .filter(updatedSortIds::contains)
+                .forEach(sortId -> {
+                    final SortClient client = clients.get(sortId);
+                    try {
+                        client.close();
+                    } catch (Throwable th) {
+                        LOG.error("Got a throwable when close client {}, {}", sortId, th.getMessage());
+                    }
+                    clients.remove(sortId);
+                });
+    }
+
+    /**
+     * Update all client config.
+     */
+    private void updateAllClientConfig() {
+        clients.values().stream()
+                .map(SortClient::getConfig)
+                .forEach(this::updateClientConfig);
+    }
+
+    /**
+     * Update one client config.
+     *
+     * @param config The config to be updated.
+     */
+    private void updateClientConfig(SortClientConfig config) {
+        config.setManagerApiUrl(CommonPropertiesHolder.getSourceConfigManagerUrl());

Review comment:
       it will be supportted in #3243

##########
File path: inlong-sort-standalone/sort-standalone-source/src/main/java/org/apache/inlong/sort/standalone/source/sortsdk/SortSdkSource.java
##########
@@ -132,30 +136,78 @@ private void initReloadExecutor() {
      * <p> Create new clients with new sort task id, and remove the finished or scheduled ones. </p>
      *
      * <p> Current version of SortSdk <b>DO NOT</b> support to get the corresponding sort id of {@link SortClient}.
-     * Hence, the maintenance of mapping of {@literal sortId, SortClient} should be done by Source itself. Which
-     * is not elegant, the <b>REMOVE</b> of expire clients will <b>NOT</b> be supported right now. </p>
+     * Hence, the maintenance of mapping of {@literal sortId, SortClient} should be done by Source itself.
      */
-    private void reload() {
+    private void reloadAll() {
 
         final List<SortTaskConfig> configs = SortClusterConfigHolder.getClusterConfig().getSortTasks();
         LOG.info("start to reload SortSdkSource");
+        this.startNewClients(configs);
+        this.stopExpiryClients(configs);
+        this.updateAllClientConfig();
+    }
 
-        // Start new clients
-        for (SortTaskConfig taskConfig : configs) {
-
-            // If exits, skip.
-            final String sortId = taskConfig.getName();
-            SortClient client = this.clients.get(sortId);
-            if (client != null) {
-                continue;
-            }
-
-            // Otherwise, new one client.
-            client = this.newClient(sortId);
-            if (client != null) {
-                this.clients.put(sortId, client);
-            }
-        }
+    /**
+     * Start a new client from SortTaskConfig.
+     * <p>
+     *     If the sortId is in configs, but not in active clients, start it.
+     * </p>
+     *
+     * @param configs Updated SortTaskConfig
+     */
+    private void startNewClients(final List<SortTaskConfig> configs) {
+        configs.stream()
+                .map(SortTaskConfig::getName)
+                .filter(sortId -> !clients.containsKey(sortId))
+                .forEach(sortId -> {
+                    final SortClient client = this.newClient(sortId);
+                    Optional.ofNullable(client)
+                            .ifPresent(c -> clients.put(sortId, c));
+                });
+    }
+
+    /**
+     * Stop an expiry client from SortTaskConfig.
+     * <p>
+     *     If the sortId is not in active clients, but not in configs, stop it.
+     * </p>
+     *
+     * @param configs Updated SortTaskConfig
+     */
+    private void stopExpiryClients(final List<SortTaskConfig> configs) {
+        Set<String> updatedSortIds = configs.stream()
+                .map(SortTaskConfig::getName)
+                .collect(Collectors.toSet());
+
+        clients.keySet().stream()
+                .filter(updatedSortIds::contains)
+                .forEach(sortId -> {
+                    final SortClient client = clients.get(sortId);
+                    try {
+                        client.close();
+                    } catch (Throwable th) {
+                        LOG.error("Got a throwable when close client {}, {}", sortId, th.getMessage());
+                    }
+                    clients.remove(sortId);
+                });
+    }
+
+    /**
+     * Update all client config.
+     */
+    private void updateAllClientConfig() {
+        clients.values().stream()
+                .map(SortClient::getConfig)
+                .forEach(this::updateClientConfig);
+    }
+
+    /**
+     * Update one client config.
+     *
+     * @param config The config to be updated.
+     */
+    private void updateClientConfig(SortClientConfig config) {
+        config.setManagerApiUrl(CommonPropertiesHolder.getSourceConfigManagerUrl());

Review comment:
       it will be supported in #3243




-- 
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] [incubator-inlong] luchunliang commented on a change in pull request #3240: [INLONG-3237][Sort-Standalone] SdkSource support periodiclly update sdk config and remove expire client.

Posted by GitBox <gi...@apache.org>.
luchunliang commented on a change in pull request #3240:
URL: https://github.com/apache/incubator-inlong/pull/3240#discussion_r830450018



##########
File path: inlong-sort-standalone/sort-standalone-source/src/main/java/org/apache/inlong/sort/standalone/source/sortsdk/SortSdkSource.java
##########
@@ -132,30 +136,78 @@ private void initReloadExecutor() {
      * <p> Create new clients with new sort task id, and remove the finished or scheduled ones. </p>
      *
      * <p> Current version of SortSdk <b>DO NOT</b> support to get the corresponding sort id of {@link SortClient}.
-     * Hence, the maintenance of mapping of {@literal sortId, SortClient} should be done by Source itself. Which
-     * is not elegant, the <b>REMOVE</b> of expire clients will <b>NOT</b> be supported right now. </p>
+     * Hence, the maintenance of mapping of {@literal sortId, SortClient} should be done by Source itself.
      */
-    private void reload() {
+    private void reloadAll() {
 
         final List<SortTaskConfig> configs = SortClusterConfigHolder.getClusterConfig().getSortTasks();
         LOG.info("start to reload SortSdkSource");
+        this.startNewClients(configs);
+        this.stopExpiryClients(configs);
+        this.updateAllClientConfig();
+    }
 
-        // Start new clients
-        for (SortTaskConfig taskConfig : configs) {
-
-            // If exits, skip.
-            final String sortId = taskConfig.getName();
-            SortClient client = this.clients.get(sortId);
-            if (client != null) {
-                continue;
-            }
-
-            // Otherwise, new one client.
-            client = this.newClient(sortId);
-            if (client != null) {
-                this.clients.put(sortId, client);
-            }
-        }
+    /**
+     * Start a new client from SortTaskConfig.
+     * <p>
+     *     If the sortId is in configs, but not in active clients, start it.
+     * </p>
+     *
+     * @param configs Updated SortTaskConfig
+     */
+    private void startNewClients(final List<SortTaskConfig> configs) {
+        configs.stream()
+                .map(SortTaskConfig::getName)
+                .filter(sortId -> !clients.containsKey(sortId))
+                .forEach(sortId -> {
+                    final SortClient client = this.newClient(sortId);
+                    Optional.ofNullable(client)
+                            .ifPresent(c -> clients.put(sortId, c));
+                });
+    }
+
+    /**
+     * Stop an expiry client from SortTaskConfig.
+     * <p>
+     *     If the sortId is not in active clients, but not in configs, stop it.
+     * </p>
+     *
+     * @param configs Updated SortTaskConfig
+     */
+    private void stopExpiryClients(final List<SortTaskConfig> configs) {
+        Set<String> updatedSortIds = configs.stream()
+                .map(SortTaskConfig::getName)
+                .collect(Collectors.toSet());
+
+        clients.keySet().stream()
+                .filter(updatedSortIds::contains)
+                .forEach(sortId -> {
+                    final SortClient client = clients.get(sortId);
+                    try {
+                        client.close();
+                    } catch (Throwable th) {
+                        LOG.error("Got a throwable when close client {}, {}", sortId, th.getMessage());
+                    }
+                    clients.remove(sortId);
+                });
+    }
+
+    /**
+     * Update all client config.
+     */
+    private void updateAllClientConfig() {
+        clients.values().stream()
+                .map(SortClient::getConfig)
+                .forEach(this::updateClientConfig);
+    }
+
+    /**
+     * Update one client config.
+     *
+     * @param config The config to be updated.
+     */
+    private void updateClientConfig(SortClientConfig config) {
+        config.setManagerApiUrl(CommonPropertiesHolder.getSourceConfigManagerUrl());

Review comment:
       "CommonPropertiesHolder.getSourceConfigManagerUrl()" do not support to periodiclly update.




-- 
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] [incubator-inlong] healchow merged pull request #3240: [INLONG-3237][Sort-Standalone] SdkSource support periodiclly update sdk config and remove expire client.

Posted by GitBox <gi...@apache.org>.
healchow merged pull request #3240:
URL: https://github.com/apache/incubator-inlong/pull/3240


   


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