tianxiaoliang commented on a change in pull request #803:
URL: 
https://github.com/apache/servicecomb-service-center/pull/803#discussion_r550100131



##########
File path: datasource/mongo/event/instance_event_handler.go
##########
@@ -0,0 +1,113 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package event
+
+import (
+       "context"
+       "fmt"
+
+       "github.com/apache/servicecomb-service-center/datasource"
+       "github.com/apache/servicecomb-service-center/datasource/mongo"
+       "github.com/apache/servicecomb-service-center/datasource/mongo/sd"
+       "github.com/apache/servicecomb-service-center/pkg/dump"
+       "github.com/apache/servicecomb-service-center/pkg/log"
+       "github.com/apache/servicecomb-service-center/pkg/util"
+       "github.com/apache/servicecomb-service-center/server/syncernotify"
+       "github.com/go-chassis/cari/discovery"
+       "go.mongodb.org/mongo-driver/bson"
+)
+
+// InstanceEventHandler is the handler to handle events
+//as instance registry or instance delete, and notify syncer
+type InstanceEventHandler struct {
+}
+
+func (h InstanceEventHandler) Type() string {
+       return mongo.CollectionInstance
+}
+
+func (h InstanceEventHandler) OnEvent(evt sd.MongoEvent) {
+       action := evt.Type
+       instance := evt.Value.(sd.Instance)
+       providerID := instance.InstanceInfo.ServiceId
+       providerInstanceID := instance.InstanceInfo.InstanceId
+
+       cacheService := sd.Store().Service().Cache().Get(providerID)
+       var ms *discovery.MicroService
+       if cacheService != nil {
+               ms = cacheService.(sd.Service).ServiceInfo
+       }
+       if ms == nil {
+               log.Info("get cached service failed, then get from data base")
+               service, errs := mongo.GetService(context.Background(), 
bson.M{"serviceinfo.serviceid": providerID})
+               if service == nil || errs != nil {

Review comment:
       不可能出现if service == nil || errs != nil这样的判断语句产生,约定俗成:err不为nil则返回值一定为nil
   
   是否不存在由error变量来判断




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to