healchow commented on code in PR #7989:
URL: https://github.com/apache/inlong/pull/7989#discussion_r1189433864


##########
inlong-manager/manager-service/src/main/java/org/apache/inlong/manager/service/heartbeat/HeartbeatManager.java:
##########
@@ -162,6 +177,23 @@ public void reportHeartbeat(HeartbeatMsg heartbeat) {
                     handlerNum += insertClusterNode(clusterInfo, heartbeatMsg, 
clusterInfo.getCreator());
                 } else {
                     handlerNum += updateClusterNode(clusterNode, heartbeatMsg);
+                    // If the agent report succeeds, restore the source status
+                    if (Objects.equals(clusterNode.getType(), 
ClusterType.AGENT)) {
+                        List<StreamSourceEntity> sourceEntities = 
sourceMapper.selectByAgentIpAndCluster(
+                                
Collections.singletonList(SourceStatus.HEARTBEAT_TIMEOUT.getCode()),
+                                Lists.newArrayList(SourceType.FILE), 
heartbeat.getIp(), heartbeatMsg.getClusterName());
+                        for (StreamSourceEntity sourceEntity : sourceEntities) 
{
+                            // restore state for all source by ip and type
+                            if (sourceEntity.getIsDeleted() != 0) {
+                                
sourceEntity.setPreviousStatus(sourceEntity.getStatus());
+                                
sourceEntity.setStatus(SourceStatus.TO_BE_ISSUED_DELETE.getCode());
+                            } else {
+                                
sourceEntity.setStatus(sourceEntity.getPreviousStatus());
+                                
sourceEntity.setPreviousStatus(SourceStatus.HEARTBEAT_TIMEOUT.getCode());
+                            }
+                            
sourceMapper.updateByPrimaryKeySelective(sourceEntity);

Review Comment:
   It is a bad practice to read and write DB in a loop.
   Can you change to update records in batches?



##########
inlong-manager/manager-service/src/main/java/org/apache/inlong/manager/service/core/impl/AgentServiceImpl.java:
##########
@@ -416,6 +418,24 @@ private void preProcessLabelFileTasks(TaskRequest 
taskRequest) {
         });
     }
 
+    private void preTimeoutTasks(TaskRequest taskRequest) {
+        // If the agent report succeeds, restore the source status
+        List<StreamSourceEntity> sourceEntities = 
sourceMapper.selectByAgentIpAndCluster(
+                
Collections.singletonList(SourceStatus.HEARTBEAT_TIMEOUT.getCode()),
+                Lists.newArrayList(SourceType.FILE), taskRequest.getAgentIp(), 
taskRequest.getClusterName());
+        for (StreamSourceEntity sourceEntity : sourceEntities) {
+            // restore state for all source by ip and type
+            if (sourceEntity.getIsDeleted() != 0) {
+                sourceEntity.setPreviousStatus(sourceEntity.getStatus());
+                
sourceEntity.setStatus(SourceStatus.TO_BE_ISSUED_DELETE.getCode());
+            } else {
+                sourceEntity.setStatus(sourceEntity.getPreviousStatus());
+                
sourceEntity.setPreviousStatus(SourceStatus.HEARTBEAT_TIMEOUT.getCode());
+            }
+            sourceMapper.updateByPrimaryKeySelective(sourceEntity);

Review Comment:
   ditto



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to