diff --git a/etc/conf/syncer.yaml b/etc/conf/syncer/syncer.yaml similarity index 100% rename from etc/conf/syncer.yaml rename to etc/conf/syncer/syncer.yaml diff --git a/syncer/config/config.go b/syncer/config/config.go index de01f5ece..cbf1a7fc6 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 diff --git a/syncer/service/admin/health.go b/syncer/service/admin/health.go index 99c9db79a..385dc11b1 100644 --- a/syncer/service/admin/health.go +++ b/syncer/service/admin/health.go @@ -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("reload syncer config fail", err1) + return rpc.HealthStatusAbnormal + } + 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..b19bfbcaf 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,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 }