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 2c0e952
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
19 changes: 17 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 All @@ -68,6 +69,20 @@ func Reload() error {
return nil
}

func ReloadConfig() {
peersFile := archaius.Get("sync.peers").([]interface{})
config.Sync.Peers = []*Peer{}
for _, va := range peersFile {
val := va.(map[string]interface{})
peer := &Peer{}
peer.Name = val["name"].(string)
peer.Kind = val["kind"].(string)
peer.Endpoints = val["endpoints"].([]string)
peer.Mode = val["mode"].([]string)
config.Sync.Peers = append(config.Sync.Peers, peer)
}
}

// GetConfig return the syncer full configurations
func GetConfig() Config {
return config
Expand Down
2 changes: 2 additions & 0 deletions syncer/service/admin/health.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ 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)
config.ReloadConfig()
Init()
return rpc.HealthStatusAbnormal
}
reportClockDiff(peerName, local, reply.LocalTimestamp)
Expand Down
7 changes: 5 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,8 @@ func (r *replicatorManager) replicate(ctx context.Context, el *v1sync.EventList)
for _, in := range els {
res, err := set.EventServiceClient.Sync(ctx, in)
if err != nil {
config.ReloadConfig()
InitSyncClient()
return nil, err
}

Expand Down

0 comments on commit 2c0e952

Please sign in to comment.