diff --git a/syncer/config/config.go b/syncer/config/config.go index de01f5ece..26f16f5b4 100644 --- a/syncer/config/config.go +++ b/syncer/config/config.go @@ -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 @@ -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 @@ -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 diff --git a/syncer/service/admin/health.go b/syncer/service/admin/health.go index 99c9db79a..c456d1738 100644 --- a/syncer/service/admin/health.go +++ b/syncer/service/admin/health.go @@ -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) diff --git a/syncer/service/replicator/replicator.go b/syncer/service/replicator/replicator.go index d7f1e3d49..622deb5a4 100644 --- a/syncer/service/replicator/replicator.go +++ b/syncer/service/replicator/replicator.go @@ -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" @@ -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 ( @@ -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 }