lilai23 commented on a change in pull request #817:
URL: 
https://github.com/apache/servicecomb-service-center/pull/817#discussion_r553711402



##########
File path: syncer/server/server.go
##########
@@ -297,10 +299,15 @@ func instFromOtherSC(instance *dump.Instance, m 
*pb.MappingEntry) bool {
 func (s *Server) addToQueue(event *dump.WatchInstanceChangedEvent) {
        mapping := s.servicecenter.GetSyncMapping()
 
-       for _, m := range mapping {
+       for index, m := range mapping {
                if instFromOtherSC(event.Instance, m) {
-                       log.Debugf("instance[curId:%s, originId:%s] is from 
another sc, no need to put to queue",
-                               m.CurInstanceID, m.OrgInstanceID)
+                       log.Debug(fmt.Sprintf("instance[curId:%s, originId:%s] 
is from another sc, no need to put to queue",
+                               m.CurInstanceID, m.OrgInstanceID))
+
+                       if event.Action == string(discovery.EVT_DELETE) {
+                               mapping = append(mapping[:index], 
mapping[index+1:]...)

Review comment:
       之前的写法也担心越界问题用case分类了,后来验证了go里面用append(mapping[:index], 
mapping[index+1:]...)就可以删除任意位置的元素,包括头和尾元素,数组长度为1也可以,都不会越界




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

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


Reply via email to