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/08/02 07:40:10 UTC

[GitHub] [inlong] charlely commented on a diff in pull request #5326: [INLONG-5314][TubeMQ] Reconnect to another address if heartbeat encounters exception

charlely commented on code in PR #5326:
URL: https://github.com/apache/inlong/pull/5326#discussion_r935203444


##########
inlong-tubemq/tubemq-client-twins/tubemq-client-go/client/heartbeat.go:
##########
@@ -99,36 +99,43 @@ func (h *heartbeatManager) consumerHB2Master() {
 	}
 
 	rsp, err := h.sendHeartbeatC2M(m)
-	if err != nil {
-		log.Errorf("consumer hb err %s", err.Error())
+	if err != nil || !rsp.GetSuccess() {
+		errMsg := ""
+		if err != nil {
+			if e, ok := err.(*errs.Error); !ok {
+				log.Errorf("consumer hb err %s", err.Error())
+				h.consumer.masterHBRetry++
+				h.resetMasterHeartbeat()
+				return
+			} else {
+				errMsg = e.Msg
+			}
+		}
+
 		h.consumer.masterHBRetry++
-	} else {
-		if !rsp.GetSuccess() {
-			h.consumer.masterHBRetry++
-			if rsp.GetErrCode() == errs.RetErrHBNoNode || strings.Index(rsp.GetErrMsg(), "StandbyException") != -1 {
-				log.Warnf("[CONSUMER] hb2master found no-node or standby, re-register, client=%s", h.consumer.clientID)
-				address := h.consumer.master.Address
-				go func() {
-					err := h.consumer.register2Master(rsp.GetErrCode() != errs.RetErrHBNoNode)
-					if err != nil {
-						return
-					}
-					h.resetMasterHeartbeat()
-				}()
-				if rsp.GetErrCode() != errs.RetErrHBNoNode {
-					h.mu.Lock()
-					defer h.mu.Unlock()
-					hm := h.heartbeats[address]
-					hm.numConnections--
-					if hm.numConnections == 0 {
-						delete(h.heartbeats, address)
-					}
+		if (rsp != nil && rsp.GetErrCode() == errs.RetErrHBNoNode) || strings.Index(errMsg, "StandbyException") != -1 {
+			log.Warnf("[CONSUMER] hb2master found no-node or standby, re-register, client=%s", h.consumer.clientID)
+			address := h.consumer.master.Address
+			go func() {
+				err := h.consumer.register2Master(rsp.GetErrCode() != errs.RetErrHBNoNode)
+				if err != nil {
 					return
 				}
-				log.Warnf("[CONSUMER] heartBeat2Master failure to (%s) : %s, client=%s", h.consumer.master.Address, rsp.GetErrMsg(), h.consumer.clientID)
+			}()
+			if rsp != nil && rsp.GetErrCode() != errs.RetErrHBNoNode {
+				h.mu.Lock()

Review Comment:
   L126-L132 After you can package a heartbeats struct, support Incr Add function to manage heartbeats.



##########
inlong-tubemq/tubemq-client-twins/tubemq-client-go/client/heartbeat.go:
##########
@@ -99,36 +99,43 @@ func (h *heartbeatManager) consumerHB2Master() {
 	}
 
 	rsp, err := h.sendHeartbeatC2M(m)
-	if err != nil {
-		log.Errorf("consumer hb err %s", err.Error())
+	if err != nil || !rsp.GetSuccess() {
+		errMsg := ""
+		if err != nil {
+			if e, ok := err.(*errs.Error); !ok {
+				log.Errorf("consumer hb err %s", err.Error())
+				h.consumer.masterHBRetry++
+				h.resetMasterHeartbeat()
+				return
+			} else {
+				errMsg = e.Msg
+			}
+		}
+
 		h.consumer.masterHBRetry++
-	} else {
-		if !rsp.GetSuccess() {
-			h.consumer.masterHBRetry++
-			if rsp.GetErrCode() == errs.RetErrHBNoNode || strings.Index(rsp.GetErrMsg(), "StandbyException") != -1 {
-				log.Warnf("[CONSUMER] hb2master found no-node or standby, re-register, client=%s", h.consumer.clientID)
-				address := h.consumer.master.Address
-				go func() {
-					err := h.consumer.register2Master(rsp.GetErrCode() != errs.RetErrHBNoNode)
-					if err != nil {
-						return
-					}
-					h.resetMasterHeartbeat()
-				}()
-				if rsp.GetErrCode() != errs.RetErrHBNoNode {
-					h.mu.Lock()
-					defer h.mu.Unlock()
-					hm := h.heartbeats[address]
-					hm.numConnections--
-					if hm.numConnections == 0 {
-						delete(h.heartbeats, address)
-					}
+		if (rsp != nil && rsp.GetErrCode() == errs.RetErrHBNoNode) || strings.Index(errMsg, "StandbyException") != -1 {
+			log.Warnf("[CONSUMER] hb2master found no-node or standby, re-register, client=%s", h.consumer.clientID)
+			address := h.consumer.master.Address
+			go func() {
+				err := h.consumer.register2Master(rsp.GetErrCode() != errs.RetErrHBNoNode)
+				if err != nil {
 					return
 				}
-				log.Warnf("[CONSUMER] heartBeat2Master failure to (%s) : %s, client=%s", h.consumer.master.Address, rsp.GetErrMsg(), h.consumer.clientID)
+			}()
+			if rsp != nil && rsp.GetErrCode() != errs.RetErrHBNoNode {

Review Comment:
   Always cann't run here.



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