Skip to content

Commit

Permalink
fix some problems (apache#1470)
Browse files Browse the repository at this point in the history
* [fix] fix the problem that the config will be synced many times when updated in some condition(mulit-engine,one engine has a late task of undate one microservice)

* [fix] fix the problem that get the microservice of sc itself occur a error will cause the failure of healthCheck

---------

Co-authored-by: songshiyuan 00649746 <[email protected]>
  • Loading branch information
2 people authored and sunhaidong (A) committed Sep 20, 2024
1 parent 3e77a20 commit 0739c96
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 8 deletions.
3 changes: 2 additions & 1 deletion eventbase/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ github.com/go-chassis/cari v0.5.1-0.20210823023004-74041d1363c4/go.mod h1:av/19f
github.com/go-chassis/cari v0.6.0/go.mod h1:mSDRCOQXGmlD69A6NG0hsv0UP1xbVPtL6HCGI6X1tqs=
github.com/go-chassis/cari v0.9.1-0.20240328115504-88da93faaca7 h1:XlCtMt+l1hcpfbiFRoSYWYr0q6Ak9g/UGFXSKoqmbT4=
github.com/go-chassis/cari v0.9.1-0.20240328115504-88da93faaca7/go.mod h1:ibqLyh+Q+1n9PlldW3glD9G+2s/yeSyVMCCkQWKRwuE=
github.com/go-chassis/etcdadpt v0.3.2/go.mod h1:HnRRpIrVEVNWobkiCvG2EHLWKKZ+L047EcI29ma2zA4=
github.com/go-chassis/etcdadpt v0.5.3-0.20240328092602-984e34b756fe h1:peLHEt3wzab6nKVcmcu0qkj1+ZXK6D1ymtiyyMBv/XA=
github.com/go-chassis/etcdadpt v0.5.3-0.20240328092602-984e34b756fe/go.mod h1:HV8OZ1Npu+lttD+pJA5nUxWZR3/SBFetTh7w8nYFkUA=
github.com/go-chassis/foundation v0.2.2-0.20201210043510-9f6d3de40234/go.mod h1:2PjwqpVwYEVaAldl5A58a08viH8p27pNeYaiE3ZxOBA=
Expand Down Expand Up @@ -367,7 +368,7 @@ github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/leodido/go-urn v1.2.1/go.mod h1:zt4jvISO2HfUBqxjfIshjdMTYS56ZS/qv49ictyFfxY=
github.com/go-chassis/etcdadpt v0.3.2/go.mod h1:HnRRpIrVEVNWobkiCvG2EHLWKKZ+L047EcI29ma2zA4=
github.com/little-cui/etcdadpt v0.3.2/go.mod h1:HnRRpIrVEVNWobkiCvG2EHLWKKZ+L047EcI29ma2zA4=
github.com/magiconair/properties v1.8.1/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
github.com/mailru/easyjson v0.0.0-20160728113105-d5b7844b561a/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
github.com/markbates/oncer v0.0.0-20181203154359-bf2de49a0be2/go.mod h1:Ld9puTsIW75CHf65OeIOkyKbteujpZVXDpWK6YGZbxE=
Expand Down
3 changes: 2 additions & 1 deletion server/service/registry/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,12 @@ func registerService(ctx context.Context) error {
}

log.Warn(fmt.Sprintf("service center service[%s] already registered", serviceID))
core.Service, err = discosvc.GetService(ctx, core.GetServiceRequest(serviceID))
service, err := discosvc.GetService(ctx, core.GetServiceRequest(serviceID))
if err != nil {
log.Error(fmt.Sprintf("query service center service[%s] info failed", serviceID), err)
return err
}
core.Service = service
return nil
}

Expand Down
18 changes: 13 additions & 5 deletions syncer/service/replicator/resource/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@ import (
"context"
"errors"
"fmt"
"sync"

kiemodel "github.com/apache/servicecomb-kie/pkg/model"
kiedb "github.com/apache/servicecomb-kie/server/datasource"

"github.com/apache/servicecomb-service-center/pkg/log"
"github.com/apache/servicecomb-service-center/pkg/util"
"github.com/apache/servicecomb-service-center/server/config"
Expand All @@ -32,19 +34,25 @@ import (

const Config = "config"

var configOnce sync.Once

func NewConfig(e *v1sync.Event) Resource {
kind := config.GetString("registry.kind", "etcd", config.WithStandby("registry_plugin"))
err := kiedb.Init(kind)
if err != nil {
log.Fatal(fmt.Sprintf("kie datasource[%s] init failed", kind), err)
}
configOnce.Do(initKieResouece)
c := &kvConfig{
event: e,
}
c.resource = c
return c
}

func initKieResouece() {
kind := config.GetString("registry.kind", "etcd", config.WithStandby("registry_plugin"))
err := kiedb.Init(kind)
if err != nil {
log.Fatal(fmt.Sprintf("kie datasource[%s] init failed", kind), err)
}
}

type kvConfig struct {
defaultFailHandler

Expand Down
5 changes: 5 additions & 0 deletions syncer/service/replicator/resource/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"errors"
"fmt"
"strconv"
"time"

"github.com/apache/servicecomb-service-center/eventbase/datasource"
"github.com/apache/servicecomb-service-center/eventbase/model"
Expand Down Expand Up @@ -50,6 +51,7 @@ const (
ResultStatusMicroNonExist = "microNonExist"
ResultStatusInstNonExist = "instNonExist"
ResultStatusNonImplement = "nonImplement"
oneDaySecond = 86400
)

var codeDescriber = map[int32]string{
Expand Down Expand Up @@ -346,6 +348,9 @@ func (o *checker) needOperate(ctx context.Context) *Result {
if len(o.resourceID) == 0 {
return nil
}
if o.event.Timestamp+oneDaySecond >= time.Now().Unix() {
return SkipResult()
}

ts, err := o.tombstoneLoader.get(ctx, &model.GetTombstoneRequest{
ResourceType: o.event.Subject,
Expand Down
6 changes: 5 additions & 1 deletion syncer/service/task/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"time"

"github.com/apache/servicecomb-service-center/eventbase/service/task"

"github.com/apache/servicecomb-service-center/pkg/log"
"github.com/apache/servicecomb-service-center/pkg/util"
v1sync "github.com/apache/servicecomb-service-center/syncer/api/v1"
Expand Down Expand Up @@ -254,7 +255,10 @@ func (m *manager) handleResult(res *event.Result) {
if res.Error != nil || res.Data.Code == resource.Fail {
log.Error(fmt.Sprintf("get task %s result, return error", res.ID), res.Error)
m.cache.Range(func(key, value interface{}) bool {
m.cache.Delete(key)
if key == res.ID {
m.cache.Delete(key)
return false
}
return true
})
return
Expand Down

0 comments on commit 0739c96

Please sign in to comment.