#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>
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 @@
 		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 @@
 	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 @@
 	_, 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)
+	}
+}