From e8e13a42d2fafa9a4353188b44ce8d19f816abb4 Mon Sep 17 00:00:00 2001 From: tornado-ssy <64736788+tornado-ssy@users.noreply.github.com> Date: Sat, 25 May 2024 10:04:57 +0800 Subject: [PATCH] fix some problems (#1470) * [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 --- eventbase/go.sum | 3 ++- server/service/registry/registry.go | 3 ++- syncer/service/replicator/resource/config.go | 18 +++++++++++++----- syncer/service/replicator/resource/resource.go | 5 +++++ syncer/service/task/manager.go | 6 +++++- 5 files changed, 27 insertions(+), 8 deletions(-) diff --git a/eventbase/go.sum b/eventbase/go.sum index adebbb128..1e96d1f26 100644 --- a/eventbase/go.sum +++ b/eventbase/go.sum @@ -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= @@ -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= diff --git a/server/service/registry/registry.go b/server/service/registry/registry.go index 612103d03..65211d5bc 100644 --- a/server/service/registry/registry.go +++ b/server/service/registry/registry.go @@ -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 } diff --git a/syncer/service/replicator/resource/config.go b/syncer/service/replicator/resource/config.go index d431f5a28..c48b89ddb 100644 --- a/syncer/service/replicator/resource/config.go +++ b/syncer/service/replicator/resource/config.go @@ -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" @@ -32,12 +34,10 @@ 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, } @@ -45,6 +45,14 @@ func NewConfig(e *v1sync.Event) Resource { 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 diff --git a/syncer/service/replicator/resource/resource.go b/syncer/service/replicator/resource/resource.go index 0ee278e75..7d8c7950e 100644 --- a/syncer/service/replicator/resource/resource.go +++ b/syncer/service/replicator/resource/resource.go @@ -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" @@ -50,6 +51,7 @@ const ( ResultStatusMicroNonExist = "microNonExist" ResultStatusInstNonExist = "instNonExist" ResultStatusNonImplement = "nonImplement" + oneDaySecond = 86400 ) var codeDescriber = map[int32]string{ @@ -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, diff --git a/syncer/service/task/manager.go b/syncer/service/task/manager.go index e9cf5fb80..4e884eab6 100644 --- a/syncer/service/task/manager.go +++ b/syncer/service/task/manager.go @@ -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" @@ -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