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/02/24 07:23:16 UTC

[GitHub] [incubator-inlong] imvan opened a new pull request #2692: [INLONG-2650][Feature][Sort] Define sort stand-alone CLS context and config bean

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


   
   ### Title Name: [INLONG-2650][Feature][Sort] Define sort stand-alone CLS context and config bean
   
   Fixes #2650 
   
   ### Motivation
   
   *Explain here the context, and why you're making that change. What is the problem you're trying to solve.*
   
   ### 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] dockerzhang merged pull request #2692: [INLONG-2650][Feature][Sort] Define sort stand-alone CLS context and config bean

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


   


-- 
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] wardlican commented on a change in pull request #2692: [INLONG-2650][Feature][Sort] Define sort stand-alone CLS context and config bean

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



##########
File path: inlong-sort-standalone/pom.xml
##########
@@ -59,6 +59,7 @@
         <mockito.version>2.23.0</mockito.version>
         <jakarta.validation.version>2.0.2</jakarta.validation.version>
         <elasticsearch-version>6.8.13</elasticsearch-version>
+        <cls-version>1.0.5</cls-version>

Review comment:
       The same style “xxx.version” is recommended




-- 
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 #2692: [INLONG-2650][Feature][Sort] Define sort stand-alone CLS context and config bean

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



##########
File path: inlong-sort-standalone/sort-standalone-source/src/main/java/org/apache/inlong/sort/standalone/sink/cls/ClsSinkContext.java
##########
@@ -0,0 +1,181 @@
+/**
+ * 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.inlong.sort.standalone.sink.cls;
+
+import com.alibaba.fastjson.JSON;
+import com.tencentcloudapi.cls.producer.AsyncProducerClient;
+import com.tencentcloudapi.cls.producer.AsyncProducerConfig;
+import com.tencentcloudapi.cls.producer.errors.ProducerException;
+import com.tencentcloudapi.cls.producer.util.NetworkUtils;
+import org.apache.flume.Channel;
+import org.apache.flume.Context;
+import org.apache.inlong.sort.standalone.config.holder.SortClusterConfigHolder;
+import org.apache.inlong.sort.standalone.config.pojo.InlongId;
+import org.apache.inlong.sort.standalone.config.pojo.SortTaskConfig;
+import org.apache.inlong.sort.standalone.sink.SinkContext;
+import org.apache.inlong.sort.standalone.utils.Constants;
+import org.apache.inlong.sort.standalone.utils.InlongLoggerFactory;
+import org.slf4j.Logger;
+
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.atomic.AtomicLong;
+
+/**
+ * Cls sink context.
+ */
+public class ClsSinkContext extends SinkContext {
+
+    private static final Logger LOG = InlongLoggerFactory.getLogger(ClsSinkContext.class);
+    // key of sink params
+    private static final String KEY_TOTAL_SIZE_IN_BYTES = "totalSizeInBytes";
+    private static final String KEY_MAX_SEND_THREAD_COUNT = "maxSendThreadCount";
+    private static final String KEY_MAX_BLOCK_SEC = "maxBlockSec";
+    private static final String KEY_MAX_BATCH_SIZE = "maxBatchSize";
+    private static final String KEY_MAX_BATCH_COUNT = "maxBatchCount";
+    private static final String KEY_LINGER_MS = "lingerMs";
+    private static final String KEY_RETRIES = "retries";
+    private static final String KEY_MAX_RESERVED_ATTEMPTS = "maxReservedAttempts";
+    private static final String KEY_BASE_RETRY_BACKOFF_MS = "baseRetryBackoffMs";
+    private static final String KEY_MAX_RETRY_BACKOFF_MS = "maxRetryBackoffMs";
+
+    private final Map<String, AsyncProducerClient> clientMap;
+    private List<AsyncProducerClient> deletingClients;
+    private Context sinkContext;
+    private Map<String, ClsIdConfig> idConfigMap = new ConcurrentHashMap<>();
+    private AtomicLong offerCounter = new AtomicLong(0);
+    private AtomicLong takeCounter = new AtomicLong(0);
+    private AtomicLong backCounter = new AtomicLong(0);
+    private IEvent2LogItemHandler iEvent2LogItemHandler;
+
+    // default sink params
+
+    /**
+     * Constructor
+     *
+     * @param sinkName Name of sink.
+     * @param context Basic context.
+     * @param channel Channel which worker acquire profile event from.
+     */
+    public ClsSinkContext(String sinkName, Context context, Channel channel) {
+        super(sinkName, context, channel);
+        this.clientMap = new ConcurrentHashMap<>();
+    }
+
+    @Override
+    public void reload() {
+        // remove deleting clients.
+        deletingClients.forEach(client -> {
+            try {
+                client.close();
+            } catch (InterruptedException e) {
+                LOG.error("close client failed, got InterruptedException" + e.getMessage(), e);
+            } catch (ProducerException e) {
+                LOG.error("close client failed, got ProducerException" + e.getMessage(), e);
+            }
+        });
+
+        SortTaskConfig newSortTaskConfig = SortClusterConfigHolder.getTaskConfig(taskName);
+        if (this.sortTaskConfig != null && this.sortTaskConfig.equals(newSortTaskConfig)) {
+            return;
+        }
+        LOG.info("get new SortTaskConfig:taskName:{}:config:{}", taskName,
+                JSON.toJSONString(newSortTaskConfig));
+        this.sortTaskConfig = newSortTaskConfig;
+        this.sinkContext = new Context(this.sortTaskConfig.getSinkParams());
+        this.reloadIdParams();
+        this.reloadClients();
+        // todo get IEvent2LogItemHandler
+    }
+
+    /**
+     * Reload id params.
+     */
+    private void reloadIdParams() {
+        List<Map<String, String>> idList = this.sortTaskConfig.getIdParams();
+        Map<String, ClsIdConfig> newIdConfigMap = new ConcurrentHashMap<>();
+        for (Map<String, String> idParam : idList) {
+            String inlongGroupId = idParam.get(Constants.INLONG_GROUP_ID);
+            String inlongStreamId = idParam.get(Constants.INLONG_STREAM_ID);
+            String uid = InlongId.generateUid(inlongGroupId, inlongStreamId);
+            String jsonIdConfig = JSON.toJSONString(idParam);
+            ClsIdConfig idConfig = JSON.parseObject(jsonIdConfig, ClsIdConfig.class);
+            newIdConfigMap.put(uid, idConfig);
+        }
+        this.idConfigMap = newIdConfigMap;
+    }
+
+    /**
+     * Close expire clients and start new clients.
+     * <p>Each client response for data of one uid.</p>
+     * <p>First, find all UIDs that are in the active clientMap but not in the updated id config (or to say EXPIRE UID),
+     * and put those clients into deletingClientsMap.
+     * The real close process will be done at the beginning of next period of reloading.
+     * Second, find all UIDs that in the updated id config but not in the active clientMap(or to say NEW UID),
+     * and start new clients for these UIDs and put them into the active clientMap.</p>
+     */
+    private void reloadClients() {
+        clientMap.keySet()
+                .stream()
+                .filter(uid -> !idConfigMap.containsKey(uid))
+                .forEach(this::removeExpireClient);
+        idConfigMap.keySet()
+                .stream()
+                .filter(uid -> !clientMap.containsKey(uid))
+                .forEach(this::startNewClient);
+    }
+
+    /**
+     * Start new cls client and put it to the active clientMap.
+     *
+     * @param uid UID of new client.
+     */
+    private void startNewClient(String uid) {
+        ClsIdConfig idConfig = idConfigMap.get(uid);
+        if (idConfig == null) {
+            LOG.error("Start client failed, there is not cls config of {}", uid);
+            return;
+        }
+        AsyncProducerConfig producerConfig = new AsyncProducerConfig(
+                idConfig.getEndpoint(),
+                idConfig.getSecretId(),
+                idConfig.getSecretKey(),
+                NetworkUtils.getLocalMachineIP());
+        // todo set other configs
+        AsyncProducerClient client = new AsyncProducerClient(producerConfig);
+        clientMap.put(uid, client);

Review comment:
       It is better to create AsyncProducerClient by endpoint, not to create AsyncProducerClient by id.




-- 
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] imvan commented on a change in pull request #2692: [INLONG-2650][Feature][Sort] Define sort stand-alone CLS context and config bean

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



##########
File path: inlong-sort-standalone/sort-standalone-source/src/main/java/org/apache/inlong/sort/standalone/sink/cls/ClsSinkContext.java
##########
@@ -0,0 +1,181 @@
+/**
+ * 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.inlong.sort.standalone.sink.cls;
+
+import com.alibaba.fastjson.JSON;
+import com.tencentcloudapi.cls.producer.AsyncProducerClient;
+import com.tencentcloudapi.cls.producer.AsyncProducerConfig;
+import com.tencentcloudapi.cls.producer.errors.ProducerException;
+import com.tencentcloudapi.cls.producer.util.NetworkUtils;
+import org.apache.flume.Channel;
+import org.apache.flume.Context;
+import org.apache.inlong.sort.standalone.config.holder.SortClusterConfigHolder;
+import org.apache.inlong.sort.standalone.config.pojo.InlongId;
+import org.apache.inlong.sort.standalone.config.pojo.SortTaskConfig;
+import org.apache.inlong.sort.standalone.sink.SinkContext;
+import org.apache.inlong.sort.standalone.utils.Constants;
+import org.apache.inlong.sort.standalone.utils.InlongLoggerFactory;
+import org.slf4j.Logger;
+
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.atomic.AtomicLong;
+
+/**
+ * Cls sink context.
+ */
+public class ClsSinkContext extends SinkContext {
+
+    private static final Logger LOG = InlongLoggerFactory.getLogger(ClsSinkContext.class);
+    // key of sink params
+    private static final String KEY_TOTAL_SIZE_IN_BYTES = "totalSizeInBytes";
+    private static final String KEY_MAX_SEND_THREAD_COUNT = "maxSendThreadCount";
+    private static final String KEY_MAX_BLOCK_SEC = "maxBlockSec";
+    private static final String KEY_MAX_BATCH_SIZE = "maxBatchSize";
+    private static final String KEY_MAX_BATCH_COUNT = "maxBatchCount";
+    private static final String KEY_LINGER_MS = "lingerMs";
+    private static final String KEY_RETRIES = "retries";
+    private static final String KEY_MAX_RESERVED_ATTEMPTS = "maxReservedAttempts";
+    private static final String KEY_BASE_RETRY_BACKOFF_MS = "baseRetryBackoffMs";
+    private static final String KEY_MAX_RETRY_BACKOFF_MS = "maxRetryBackoffMs";
+
+    private final Map<String, AsyncProducerClient> clientMap;
+    private List<AsyncProducerClient> deletingClients;
+    private Context sinkContext;
+    private Map<String, ClsIdConfig> idConfigMap = new ConcurrentHashMap<>();
+    private AtomicLong offerCounter = new AtomicLong(0);
+    private AtomicLong takeCounter = new AtomicLong(0);
+    private AtomicLong backCounter = new AtomicLong(0);
+    private IEvent2LogItemHandler iEvent2LogItemHandler;
+
+    // default sink params
+
+    /**
+     * Constructor
+     *
+     * @param sinkName Name of sink.
+     * @param context Basic context.
+     * @param channel Channel which worker acquire profile event from.
+     */
+    public ClsSinkContext(String sinkName, Context context, Channel channel) {
+        super(sinkName, context, channel);
+        this.clientMap = new ConcurrentHashMap<>();
+    }
+
+    @Override
+    public void reload() {
+        // remove deleting clients.
+        deletingClients.forEach(client -> {
+            try {
+                client.close();
+            } catch (InterruptedException e) {
+                LOG.error("close client failed, got InterruptedException" + e.getMessage(), e);
+            } catch (ProducerException e) {
+                LOG.error("close client failed, got ProducerException" + e.getMessage(), e);
+            }
+        });
+
+        SortTaskConfig newSortTaskConfig = SortClusterConfigHolder.getTaskConfig(taskName);
+        if (this.sortTaskConfig != null && this.sortTaskConfig.equals(newSortTaskConfig)) {
+            return;
+        }
+        LOG.info("get new SortTaskConfig:taskName:{}:config:{}", taskName,
+                JSON.toJSONString(newSortTaskConfig));
+        this.sortTaskConfig = newSortTaskConfig;
+        this.sinkContext = new Context(this.sortTaskConfig.getSinkParams());
+        this.reloadIdParams();
+        this.reloadClients();
+        // todo get IEvent2LogItemHandler
+    }
+
+    /**
+     * Reload id params.
+     */
+    private void reloadIdParams() {
+        List<Map<String, String>> idList = this.sortTaskConfig.getIdParams();
+        Map<String, ClsIdConfig> newIdConfigMap = new ConcurrentHashMap<>();
+        for (Map<String, String> idParam : idList) {
+            String inlongGroupId = idParam.get(Constants.INLONG_GROUP_ID);
+            String inlongStreamId = idParam.get(Constants.INLONG_STREAM_ID);
+            String uid = InlongId.generateUid(inlongGroupId, inlongStreamId);
+            String jsonIdConfig = JSON.toJSONString(idParam);
+            ClsIdConfig idConfig = JSON.parseObject(jsonIdConfig, ClsIdConfig.class);
+            newIdConfigMap.put(uid, idConfig);
+        }
+        this.idConfigMap = newIdConfigMap;
+    }
+
+    /**
+     * Close expire clients and start new clients.
+     * <p>Each client response for data of one uid.</p>
+     * <p>First, find all UIDs that are in the active clientMap but not in the updated id config (or to say EXPIRE UID),
+     * and put those clients into deletingClientsMap.
+     * The real close process will be done at the beginning of next period of reloading.
+     * Second, find all UIDs that in the updated id config but not in the active clientMap(or to say NEW UID),
+     * and start new clients for these UIDs and put them into the active clientMap.</p>
+     */
+    private void reloadClients() {
+        clientMap.keySet()
+                .stream()
+                .filter(uid -> !idConfigMap.containsKey(uid))
+                .forEach(this::removeExpireClient);
+        idConfigMap.keySet()
+                .stream()
+                .filter(uid -> !clientMap.containsKey(uid))
+                .forEach(this::startNewClient);
+    }
+
+    /**
+     * Start new cls client and put it to the active clientMap.
+     *
+     * @param uid UID of new client.
+     */
+    private void startNewClient(String uid) {
+        ClsIdConfig idConfig = idConfigMap.get(uid);
+        if (idConfig == null) {
+            LOG.error("Start client failed, there is not cls config of {}", uid);
+            return;
+        }
+        AsyncProducerConfig producerConfig = new AsyncProducerConfig(
+                idConfig.getEndpoint(),
+                idConfig.getSecretId(),
+                idConfig.getSecretKey(),
+                NetworkUtils.getLocalMachineIP());
+        // todo set other configs
+        AsyncProducerClient client = new AsyncProducerClient(producerConfig);
+        clientMap.put(uid, client);

Review comment:
       The init process of AsyncProducerClient requires two important parameters, secretId and secretKey. 
   Each id has unique secretId and secretKey but may share the same endpoint. 
   Hence we have to new one client for each task, although it cost more resouces, it's the price that we hand over the controll of dispatch and fail retry to CLS SDK.




-- 
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] imvan commented on a change in pull request #2692: [INLONG-2650][Feature][Sort] Define sort stand-alone CLS context and config bean

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



##########
File path: inlong-sort-standalone/sort-standalone-source/src/main/java/org/apache/inlong/sort/standalone/sink/cls/ClsSinkContext.java
##########
@@ -0,0 +1,181 @@
+/**
+ * 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.inlong.sort.standalone.sink.cls;
+
+import com.alibaba.fastjson.JSON;
+import com.tencentcloudapi.cls.producer.AsyncProducerClient;
+import com.tencentcloudapi.cls.producer.AsyncProducerConfig;
+import com.tencentcloudapi.cls.producer.errors.ProducerException;
+import com.tencentcloudapi.cls.producer.util.NetworkUtils;
+import org.apache.flume.Channel;
+import org.apache.flume.Context;
+import org.apache.inlong.sort.standalone.config.holder.SortClusterConfigHolder;
+import org.apache.inlong.sort.standalone.config.pojo.InlongId;
+import org.apache.inlong.sort.standalone.config.pojo.SortTaskConfig;
+import org.apache.inlong.sort.standalone.sink.SinkContext;
+import org.apache.inlong.sort.standalone.utils.Constants;
+import org.apache.inlong.sort.standalone.utils.InlongLoggerFactory;
+import org.slf4j.Logger;
+
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.atomic.AtomicLong;
+
+/**
+ * Cls sink context.
+ */
+public class ClsSinkContext extends SinkContext {
+
+    private static final Logger LOG = InlongLoggerFactory.getLogger(ClsSinkContext.class);
+    // key of sink params
+    private static final String KEY_TOTAL_SIZE_IN_BYTES = "totalSizeInBytes";
+    private static final String KEY_MAX_SEND_THREAD_COUNT = "maxSendThreadCount";
+    private static final String KEY_MAX_BLOCK_SEC = "maxBlockSec";
+    private static final String KEY_MAX_BATCH_SIZE = "maxBatchSize";
+    private static final String KEY_MAX_BATCH_COUNT = "maxBatchCount";
+    private static final String KEY_LINGER_MS = "lingerMs";
+    private static final String KEY_RETRIES = "retries";
+    private static final String KEY_MAX_RESERVED_ATTEMPTS = "maxReservedAttempts";
+    private static final String KEY_BASE_RETRY_BACKOFF_MS = "baseRetryBackoffMs";
+    private static final String KEY_MAX_RETRY_BACKOFF_MS = "maxRetryBackoffMs";
+
+    private final Map<String, AsyncProducerClient> clientMap;
+    private List<AsyncProducerClient> deletingClients;
+    private Context sinkContext;
+    private Map<String, ClsIdConfig> idConfigMap = new ConcurrentHashMap<>();
+    private AtomicLong offerCounter = new AtomicLong(0);
+    private AtomicLong takeCounter = new AtomicLong(0);
+    private AtomicLong backCounter = new AtomicLong(0);
+    private IEvent2LogItemHandler iEvent2LogItemHandler;
+
+    // default sink params
+
+    /**
+     * Constructor
+     *
+     * @param sinkName Name of sink.
+     * @param context Basic context.
+     * @param channel Channel which worker acquire profile event from.
+     */
+    public ClsSinkContext(String sinkName, Context context, Channel channel) {
+        super(sinkName, context, channel);
+        this.clientMap = new ConcurrentHashMap<>();
+    }
+
+    @Override
+    public void reload() {
+        // remove deleting clients.
+        deletingClients.forEach(client -> {
+            try {
+                client.close();
+            } catch (InterruptedException e) {
+                LOG.error("close client failed, got InterruptedException" + e.getMessage(), e);
+            } catch (ProducerException e) {
+                LOG.error("close client failed, got ProducerException" + e.getMessage(), e);
+            }
+        });
+
+        SortTaskConfig newSortTaskConfig = SortClusterConfigHolder.getTaskConfig(taskName);
+        if (this.sortTaskConfig != null && this.sortTaskConfig.equals(newSortTaskConfig)) {
+            return;
+        }
+        LOG.info("get new SortTaskConfig:taskName:{}:config:{}", taskName,
+                JSON.toJSONString(newSortTaskConfig));
+        this.sortTaskConfig = newSortTaskConfig;
+        this.sinkContext = new Context(this.sortTaskConfig.getSinkParams());
+        this.reloadIdParams();
+        this.reloadClients();
+        // todo get IEvent2LogItemHandler
+    }
+
+    /**
+     * Reload id params.
+     */
+    private void reloadIdParams() {
+        List<Map<String, String>> idList = this.sortTaskConfig.getIdParams();
+        Map<String, ClsIdConfig> newIdConfigMap = new ConcurrentHashMap<>();
+        for (Map<String, String> idParam : idList) {
+            String inlongGroupId = idParam.get(Constants.INLONG_GROUP_ID);
+            String inlongStreamId = idParam.get(Constants.INLONG_STREAM_ID);
+            String uid = InlongId.generateUid(inlongGroupId, inlongStreamId);
+            String jsonIdConfig = JSON.toJSONString(idParam);
+            ClsIdConfig idConfig = JSON.parseObject(jsonIdConfig, ClsIdConfig.class);
+            newIdConfigMap.put(uid, idConfig);
+        }
+        this.idConfigMap = newIdConfigMap;
+    }
+
+    /**
+     * Close expire clients and start new clients.
+     * <p>Each client response for data of one uid.</p>
+     * <p>First, find all UIDs that are in the active clientMap but not in the updated id config (or to say EXPIRE UID),
+     * and put those clients into deletingClientsMap.
+     * The real close process will be done at the beginning of next period of reloading.
+     * Second, find all UIDs that in the updated id config but not in the active clientMap(or to say NEW UID),
+     * and start new clients for these UIDs and put them into the active clientMap.</p>
+     */
+    private void reloadClients() {
+        clientMap.keySet()
+                .stream()
+                .filter(uid -> !idConfigMap.containsKey(uid))
+                .forEach(this::removeExpireClient);
+        idConfigMap.keySet()
+                .stream()
+                .filter(uid -> !clientMap.containsKey(uid))
+                .forEach(this::startNewClient);
+    }
+
+    /**
+     * Start new cls client and put it to the active clientMap.
+     *
+     * @param uid UID of new client.
+     */
+    private void startNewClient(String uid) {
+        ClsIdConfig idConfig = idConfigMap.get(uid);
+        if (idConfig == null) {
+            LOG.error("Start client failed, there is not cls config of {}", uid);
+            return;
+        }
+        AsyncProducerConfig producerConfig = new AsyncProducerConfig(
+                idConfig.getEndpoint(),
+                idConfig.getSecretId(),
+                idConfig.getSecretKey(),
+                NetworkUtils.getLocalMachineIP());
+        // todo set other configs
+        AsyncProducerClient client = new AsyncProducerClient(producerConfig);
+        clientMap.put(uid, client);

Review comment:
       details can be seen at  https://github.com/TencentCloud/tencentcloud-cls-sdk-java




-- 
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] imvan commented on a change in pull request #2692: [INLONG-2650][Feature][Sort] Define sort stand-alone CLS context and config bean

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



##########
File path: inlong-sort-standalone/pom.xml
##########
@@ -59,6 +59,7 @@
         <mockito.version>2.23.0</mockito.version>
         <jakarta.validation.version>2.0.2</jakarta.validation.version>
         <elasticsearch-version>6.8.13</elasticsearch-version>
+        <cls-version>1.0.5</cls-version>

Review comment:
       thx, fixed




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