This is an automated email from the ASF dual-hosted git repository.

littlecui pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/servicecomb-service-center.git


The following commit(s) were added to refs/heads/master by this push:
     new d2c74a6  #1228 replica instance fail when service not exist, resend 
again (#1270)
d2c74a6 is described below

commit d2c74a6c5e2bf20ff262618b8d917daa427f2f71
Author: aseTo2016 <[email protected]>
AuthorDate: Thu Feb 17 20:48:47 2022 +0800

    #1228 replica instance fail when service not exist, resend again (#1270)
    
    * #1228 replica instance fail when service not exist, resend again
    
    * #1228 replica instance fail when service not exist, resend again
    
    Co-authored-by: aseTo2016 <tys201193111>
---
 syncer/service/replicator/replicator.go            |  1 +
 syncer/service/replicator/resource/instance.go     | 25 ++++++++++++++++
 .../service/replicator/resource/instance_test.go   | 34 ++++++++++++++++++++++
 3 files changed, 60 insertions(+)

diff --git a/syncer/service/replicator/replicator.go 
b/syncer/service/replicator/replicator.go
index 29de1f2..e835c5e 100644
--- a/syncer/service/replicator/replicator.go
+++ b/syncer/service/replicator/replicator.go
@@ -154,6 +154,7 @@ func (r *replicatorManager) replicate(ctx context.Context, 
el *v1sync.EventList)
                log.Info(fmt.Sprintf("replicate events success, count is %d", 
len(in.Events)))
 
                for k, v := range res.Results {
+                       log.Info(fmt.Sprintf("replicate event %s, %v", k, v))
                        result.Results[k] = v
                }
        }
diff --git a/syncer/service/replicator/resource/instance.go 
b/syncer/service/replicator/resource/instance.go
index e174604..016e5c1 100644
--- a/syncer/service/replicator/resource/instance.go
+++ b/syncer/service/replicator/resource/instance.go
@@ -168,6 +168,31 @@ func (i *instance) NeedOperate(ctx context.Context) 
*Result {
        return c.needOperate(ctx)
 }
 
+func (i *instance) FailHandle(ctx context.Context, code int32) (*v1sync.Event, 
error) {
+       if code != MicroNonExist {
+               return nil, nil
+       }
+
+       err := i.loadInput()
+       if err != nil {
+               return nil, err
+       }
+
+       serviceID := i.serviceID
+       _, err = i.manager.GetService(ctx,
+               &pb.GetServiceRequest{
+                       ServiceId: serviceID,
+               })
+
+       if err != nil {
+               if errsvc.IsErrEqualCode(err, pb.ErrServiceNotExists) {
+                       return nil, nil
+               }
+               return nil, nil
+       }
+       return i.event, nil
+}
+
 func (i *instance) CanDrop() bool {
        return false
 }
diff --git a/syncer/service/replicator/resource/instance_test.go 
b/syncer/service/replicator/resource/instance_test.go
index e66318c..54a16b0 100644
--- a/syncer/service/replicator/resource/instance_test.go
+++ b/syncer/service/replicator/resource/instance_test.go
@@ -164,3 +164,37 @@ func TestFailHandlerInstance(t *testing.T) {
        _, err := h.FailHandle(context.TODO(), NonImplement)
        assert.Nil(t, err)
 }
+
+func TestInstanceFailHandle(t *testing.T) {
+       manager := &mockMetadata{
+               services: make(map[string]*pb.MicroService),
+       }
+       serviceID := "xxxx"
+       manager.services = map[string]*pb.MicroService{
+               serviceID: {
+                       ServiceId: serviceID,
+               },
+       }
+       inst := &pb.RegisterInstanceRequest{
+               Instance: &pb.MicroServiceInstance{
+                       ServiceId: serviceID,
+               },
+       }
+       v, _ := json.Marshal(inst)
+       e1 := &v1sync.Event{
+               Id:        "xx",
+               Action:    sync.CreateAction,
+               Subject:   Instance,
+               Opts:      nil,
+               Value:     v,
+               Timestamp: v1sync.Timestamp(),
+       }
+       res := &instance{
+               event:   e1,
+               manager: manager,
+       }
+       re, err := res.FailHandle(context.TODO(), MicroNonExist)
+       if assert.Nil(t, err) {
+               assert.Equal(t, "xx", re.Id)
+       }
+}

Reply via email to