Skip to content

Commit

Permalink
解决服务实例同步健康状态不一致问题 (#913)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewshan authored Feb 9, 2023
1 parent 65fd429 commit 8e4197d
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 10 deletions.
2 changes: 1 addition & 1 deletion apiserver/eurekaserver/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ func (h *EurekaServer) Run(errCh chan error) {
} else {
err = server.ServeTLS(ln, h.tlsInfo.CertFile, h.tlsInfo.KeyFile)
}
if err != nil {
if err != nil && err != http.ErrServerClosed {
log.Errorf("%+v", err)
if !h.restart {
log.Infof("not in restart progress, broadcast error")
Expand Down
2 changes: 2 additions & 0 deletions bootstrap/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,8 @@ func SelfDeregister() {
log.Errorf("Deregister instance error: %s", resp.GetInfo().GetValue())
}
}
// wait the async event handler to finish
time.Sleep(5 * time.Second)
}

// getLocalHost 获取本地IP地址
Expand Down
4 changes: 1 addition & 3 deletions cache/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,9 +304,7 @@ func doClientPage(ret []*model.Client, offset, limit uint32) []*model.Client {
endIndex = totalCount
}

for i := range ret {
clients = append(clients, ret[i])
}
clients = append(clients, ret...)

sort.Slice(clients, func(i, j int) bool {
return clients[i].ModifyTime().After(clients[j].ModifyTime())
Expand Down
9 changes: 9 additions & 0 deletions common/model/naming.go
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,15 @@ func (i *InstanceEvent) InjectMetadata(ctx context.Context) {
i.MetaData = value.(map[string]string)
}

func (i *InstanceEvent) String() string {
if nil == i {
return "nil"
}
hostPortStr := fmt.Sprintf("%s:%d", i.Instance.GetHost().GetValue(), i.Instance.GetPort().GetValue())
return fmt.Sprintf("InstanceEvent(id=%s, namespace=%s, service=%s, type=%v, instance=%s, healthy=%v)",
i.Id, i.Namespace, i.Service, i.EType, hostPortStr, i.Instance.GetHealthy().GetValue())
}

// InstanceCount Service instance statistics
type InstanceCount struct {
// HealthyInstanceCount 健康实例数
Expand Down
13 changes: 7 additions & 6 deletions service/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,12 @@ func (s *Server) CreateInstance(ctx context.Context, req *api.Instance) *api.Res
Name: req.GetService().GetValue(),
Namespace: req.GetNamespace().GetValue(),
}
instanceProto := data.Proto
event := &model.InstanceEvent{
Id: instanceID,
Namespace: svc.Namespace,
Service: svc.Name,
Instance: &ins,
Instance: instanceProto,
EType: model.EventInstanceOnline,
CreateTime: time.Time{},
}
Expand All @@ -127,11 +128,11 @@ func (s *Server) CreateInstance(ctx context.Context, req *api.Instance) *api.Res
s.RecordHistory(instanceRecordEntry(ctx, svc, data, model.OCreate))
out := &api.Instance{
Id: ins.GetId(),
Service: req.GetService(),
Namespace: req.GetNamespace(),
VpcId: req.GetVpcId(),
Host: req.GetHost(),
Port: req.GetPort(),
Service: &wrappers.StringValue{Value: svc.Name},
Namespace: &wrappers.StringValue{Value: svc.Namespace},
VpcId: instanceProto.GetVpcId(),
Host: instanceProto.GetHost(),
Port: instanceProto.GetPort(),
}
return api.NewInstanceResponse(api.ExecuteSuccess, out)
}
Expand Down

0 comments on commit 8e4197d

Please sign in to comment.