Skip to content

Commit

Permalink
[feat] support refresh the config of syncer without redeploy servicec…
Browse files Browse the repository at this point in the history
…omb-center
  • Loading branch information
songshiyuan 00649746 committed Apr 13, 2024
1 parent 0534041 commit 83df60f
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 4 deletions.
File renamed without changes.
5 changes: 3 additions & 2 deletions syncer/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ import (
"fmt"
"path/filepath"

"github.com/go-chassis/go-archaius"

"github.com/apache/servicecomb-service-center/pkg/log"
"github.com/apache/servicecomb-service-center/pkg/util"
"github.com/go-chassis/go-archaius"
)

var config Config
Expand All @@ -45,7 +46,7 @@ type Peer struct {
}

func Init() error {
err := archaius.AddFile(filepath.Join(util.GetAppRoot(), "conf", "syncer.yaml"))
err := archaius.AddFile(filepath.Join(util.GetAppRoot(), "conf", "syncer", "syncer.yaml"))
if err != nil {
log.Warn(fmt.Sprintf("can not add syncer config file source, error: %s", err))
return err
Expand Down
6 changes: 6 additions & 0 deletions syncer/service/admin/health.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,12 @@ func getPeerStatus(peerName string, clientConn *grpc.ClientConn) string {
reply, err := set.EventServiceClient.Health(context.Background(), &v1sync.HealthRequest{})
if err != nil || reply == nil {
log.Error("get peer health failed", err)
err1 := config.Reload()
if err1 != nil {
log.Error("get peer health failed", err1)
return rpc.HealthStatusAbnormal
}
Init()
return rpc.HealthStatusAbnormal
}
reportClockDiff(peerName, local, reply.LocalTimestamp)
Expand Down
15 changes: 13 additions & 2 deletions syncer/service/replicator/replicator.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ import (
"context"
"fmt"

"github.com/go-chassis/foundation/gopool"
"google.golang.org/grpc"

"github.com/apache/servicecomb-service-center/client"
"github.com/apache/servicecomb-service-center/pkg/log"
"github.com/apache/servicecomb-service-center/pkg/rpc"
Expand All @@ -29,8 +32,6 @@ import (
syncerclient "github.com/apache/servicecomb-service-center/syncer/client"
"github.com/apache/servicecomb-service-center/syncer/config"
"github.com/apache/servicecomb-service-center/syncer/service/replicator/resource"
"github.com/go-chassis/foundation/gopool"
"google.golang.org/grpc"
)

const (
Expand Down Expand Up @@ -165,6 +166,16 @@ func (r *replicatorManager) replicate(ctx context.Context, el *v1sync.EventList)
for _, in := range els {
res, err := set.EventServiceClient.Sync(ctx, in)
if err != nil {
err1 := config.Reload()
if err1 != nil {
log.Error("reload syncer config fail", err1)
return nil, err
}
err2 := InitSyncClient()
if err2 != nil {
log.Error("reInit syncClient fail", err2)
return nil, err
}
return nil, err
}

Expand Down

0 comments on commit 83df60f

Please sign in to comment.