Skip to content

Commit

Permalink
fix: 解决eureka同步时,出现存量服务同步失败的问题 (#823)
Browse files Browse the repository at this point in the history
* feat: 支持eureka双向数据同步

* fix:golintci warnings

* feat: 调整import顺序

* fix:修复golint格式化问题

* fix:修复导入问题

* fix: 修复导入顺序问题

* feat:优化大小写问题,eureka插件默认大小写不敏感,无需配置

* feat:读取的时候进行大写转换

* feat:修改读取时候大小写

* feat:处理replication大小写

* fix:修复用例失败问题

* fix:修复用例失败问题

* fix:修复eureka心跳复制失败的问题

* fix:解决自注册时候,服务不存在需要动态创建的问题

* fix:修复服务不存在,创建报错问题
  • Loading branch information
andrewshan committed Nov 29, 2022
1 parent 10a8b12 commit 9bf2a8f
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 31 deletions.
16 changes: 0 additions & 16 deletions apiserver/eurekaserver/access.go
Original file line number Diff line number Diff line change
Expand Up @@ -455,11 +455,6 @@ func (h *EurekaServer) DeleteStatus(req *restful.Request, rsp *restful.Response)
log.Infof("[EUREKA-SERVER]instance status (instId=%s, appId=%s) has been deleted successfully",
instId, appId)
writeHeader(http.StatusOK, rsp)
h.replicateWorker.AddReplicateTask(&ReplicationInstance{
AppName: appId,
Id: instId,
Action: actionDeleteStatusOverride,
})
return
}
log.Errorf("[EUREKA-SERVER]instance status (instId=%s, appId=%s) has been deleted failed, code is %d",
Expand Down Expand Up @@ -494,12 +489,6 @@ func (h *EurekaServer) RenewInstance(req *restful.Request, rsp *restful.Response
writePolarisStatusCode(req, code)
if code == api.ExecuteSuccess || code == api.HeartbeatExceedLimit {
writeHeader(http.StatusOK, rsp)
h.replicateWorker.AddReplicateTask(&ReplicationInstance{
AppName: appId,
Id: instId,
Status: "UP",
Action: actionHeartbeat,
})
return
}
log.Errorf("[EUREKA-SERVER]instance (instId=%s, appId=%s) heartbeat failed, code is %d",
Expand Down Expand Up @@ -538,11 +527,6 @@ func (h *EurekaServer) CancelInstance(req *restful.Request, rsp *restful.Respons
writeHeader(http.StatusOK, rsp)
log.Infof("[EUREKA-SERVER]instance (instId=%s, appId=%s) has been deregistered successfully, code is %d",
instId, appId, code)
h.replicateWorker.AddReplicateTask(&ReplicationInstance{
AppName: appId,
Id: instId,
Action: actionCancel,
})
return
}
log.Errorf("[EUREKA-SERVER]instance (instId=%s, appId=%s) has been deregistered failed, code is %d",
Expand Down
3 changes: 2 additions & 1 deletion apiserver/eurekaserver/replicate_worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ func (r *ReplicateWorker) doReplicateToPeer(peer string, tasks []*ReplicationIns
if respInstance.StatusCode == http.StatusNotFound {
task := tasks[i]
if task.Action == actionHeartbeat {
log.Infof("[EUREKA-SERVER] instance %s of service %s not exists in %s, do register", task.Id, task.AppName, peer)
log.Infof("[EUREKA-SERVER] instance %s of service %s not exists in %s, do register instance info %+v",
task.Id, task.AppName, peer, task.InstanceInfo)
// do the re-register
registerTask := &ReplicationInstance{
AppName: task.AppName,
Expand Down
18 changes: 4 additions & 14 deletions bootstrap/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
"time"

"github.com/golang/protobuf/ptypes/wrappers"
yaml "gopkg.in/yaml.v2"
"gopkg.in/yaml.v2"

"github.com/polarismesh/polaris/apiserver"
"github.com/polarismesh/polaris/auth"
Expand Down Expand Up @@ -425,7 +425,10 @@ func FinishBootstrapOrder(tx store.Transaction) error {

func genContext() context.Context {
ctx := context.Background()
reqCtx := context.WithValue(context.Background(), utils.ContextAuthTokenKey, "")
ctx = context.WithValue(ctx, utils.StringContext("request-id"), fmt.Sprintf("self-%d", time.Now().Nanosecond()))
ctx = context.WithValue(ctx, utils.ContextAuthContextKey, model.NewAcquireContext(
model.WithOperation(model.Read), model.WithModule(model.BootstrapModule), model.WithRequestContext(reqCtx)))
return ctx
}

Expand Down Expand Up @@ -511,10 +514,6 @@ func selfRegister(
if err != nil {
return err
}
storage, err := store.GetStore()
if err != nil {
return err
}

name := boot_config.DefaultPolarisName
polarisNamespace := boot_config.DefaultPolarisNamespace
Expand All @@ -526,14 +525,6 @@ func selfRegister(
polarisNamespace = polarisService.Namespace
}

svc, err := storage.GetService(name, polarisNamespace)
if err != nil {
return err
}
if svc == nil {
return fmt.Errorf("self service(%s) in namespace(%s) not found", name, polarisNamespace)
}

metadata := polarisService.Metadata
if len(metadata) == 0 {
metadata = make(map[string]string)
Expand All @@ -547,7 +538,6 @@ func selfRegister(
Host: utils.NewStringValue(host),
Port: utils.NewUInt32Value(port),
Protocol: utils.NewStringValue(protocol),
ServiceToken: utils.NewStringValue(svc.Token),
Version: utils.NewStringValue(version.Get()),
EnableHealthCheck: utils.NewBoolValue(true),
Isolate: utils.NewBoolValue(isolated),
Expand Down
2 changes: 2 additions & 0 deletions common/model/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,8 @@ const (
AuthModule
// MaintainModule 运维操作模块
MaintainModule
// BootstrapModule 初始化模块
BootstrapModule
)

// UserRoleType 用户角色类型
Expand Down

0 comments on commit 9bf2a8f

Please sign in to comment.