You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by GitBox <gi...@apache.org> on 2020/12/30 09:29:02 UTC

[GitHub] [servicecomb-service-center] yeyiwei opened a new pull request #803: sync data processer

yeyiwei opened a new pull request #803:
URL: https://github.com/apache/servicecomb-service-center/pull/803


   1. 实例增量数据校验,增量数据类型转换。
   2. 向syncer发送同步数据。
   3. 缓存中若无增量实例对应的服务数据,将访问一次数据库。
   修改:
   1. 删除读取配置文件的代码,采用系统自带mongo配置
   2. 删除notify状态检查
   3. 常量应用和代码规范
   


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [servicecomb-service-center] lilai23 commented on a change in pull request #803: sync data processer

Posted by GitBox <gi...@apache.org>.
lilai23 commented on a change in pull request #803:
URL: https://github.com/apache/servicecomb-service-center/pull/803#discussion_r550112984



##########
File path: datasource/mongo/event/instance_event_handler_test.go
##########
@@ -0,0 +1,75 @@
+package event
+
+import (
+	"testing"
+
+	"github.com/apache/servicecomb-service-center/datasource/mongo/client"
+	"github.com/apache/servicecomb-service-center/datasource/mongo/sd"
+	"github.com/go-chassis/cari/discovery"
+	"github.com/go-chassis/go-chassis/v2/storage"
+	"github.com/stretchr/testify/assert"
+)
+
+func init() {
+	config := storage.Options{
+		URI: "mongodb://localhost:27017",
+	}
+	client.NewMongoClient(config)
+}
+
+func TestInstanceEventHandler_OnEvent(t *testing.T) {
+
+	t.Run("OnEvent test by request config", func(t *testing.T) {
+		h := InstanceEventHandler{}
+		h.OnEvent(mongoAssign())
+		assert.NotNil(t, discovery.MicroService{})
+	})
+	t.Run("OnEvent test by request config", func(t *testing.T) {

Review comment:
       和上面重名




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [servicecomb-service-center] tianxiaoliang commented on a change in pull request #803: sync data processer

Posted by GitBox <gi...@apache.org>.
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:
users@infra.apache.org



[GitHub] [servicecomb-service-center] yeyiwei commented on a change in pull request #803: sync data processer

Posted by GitBox <gi...@apache.org>.
yeyiwei commented on a change in pull request #803:
URL: https://github.com/apache/servicecomb-service-center/pull/803#discussion_r550369670



##########
File path: datasource/mongo/event/instance_event_handler_test.go
##########
@@ -0,0 +1,75 @@
+package event
+
+import (
+	"testing"
+
+	"github.com/apache/servicecomb-service-center/datasource/mongo/client"
+	"github.com/apache/servicecomb-service-center/datasource/mongo/sd"
+	"github.com/go-chassis/cari/discovery"
+	"github.com/go-chassis/go-chassis/v2/storage"
+	"github.com/stretchr/testify/assert"
+)
+
+func init() {
+	config := storage.Options{
+		URI: "mongodb://localhost:27017",
+	}
+	client.NewMongoClient(config)
+}
+
+func TestInstanceEventHandler_OnEvent(t *testing.T) {
+
+	t.Run("OnEvent test by request config", func(t *testing.T) {
+		h := InstanceEventHandler{}
+		h.OnEvent(mongoAssign())
+		assert.NotNil(t, discovery.MicroService{})
+	})
+	t.Run("OnEvent test by request config", func(t *testing.T) {

Review comment:
       ut名称已改




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [servicecomb-service-center] lilai23 commented on a change in pull request #803: sync data processer

Posted by GitBox <gi...@apache.org>.
lilai23 commented on a change in pull request #803:
URL: https://github.com/apache/servicecomb-service-center/pull/803#discussion_r550112404



##########
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:
       1.err为nil则service一定不为nil
   2.err不为nil则service一定为nil




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [servicecomb-service-center] yeyiwei commented on a change in pull request #803: sync data processer

Posted by GitBox <gi...@apache.org>.
yeyiwei commented on a change in pull request #803:
URL: https://github.com/apache/servicecomb-service-center/pull/803#discussion_r550369598



##########
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:
       已改为两次判断




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [servicecomb-service-center] lilai23 commented on a change in pull request #803: sync data processer

Posted by GitBox <gi...@apache.org>.
lilai23 commented on a change in pull request #803:
URL: https://github.com/apache/servicecomb-service-center/pull/803#discussion_r550370107



##########
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:
       调用的GetService函数返回值有同时为nil的情况,先判断err不为nil进行处理 然后再判断service为nil




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [servicecomb-service-center] yeyiwei commented on a change in pull request #803: sync data processer

Posted by GitBox <gi...@apache.org>.
yeyiwei commented on a change in pull request #803:
URL: https://github.com/apache/servicecomb-service-center/pull/803#discussion_r550404600



##########
File path: datasource/mongo/event/instance_event_handler.go
##########
@@ -0,0 +1,117 @@
+/*
+ * 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})

Review comment:
       变量名已改

##########
File path: datasource/mongo/event/instance_event_handler.go
##########
@@ -0,0 +1,117 @@
+/*
+ * 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 errs != nil {
+			log.Error("get service from database error", errs)
+			return
+		}
+		if service == nil {

Review comment:
       日志信息已明确描述错误原因




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [servicecomb-service-center] tianxiaoliang commented on a change in pull request #803: sync data processer

Posted by GitBox <gi...@apache.org>.
tianxiaoliang commented on a change in pull request #803:
URL: https://github.com/apache/servicecomb-service-center/pull/803#discussion_r550427723



##########
File path: datasource/mongo/event/instance_event_handler.go
##########
@@ -0,0 +1,117 @@
+/*
+ * 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 errs != nil {
+			log.Error("get service from database error", errs)
+			return
+		}
+		if service == nil {

Review comment:
       要由GetService返回具体的错误类型来判断是否存在,不可依赖于是否为nil




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [servicecomb-service-center] tianxiaoliang merged pull request #803: sync data processer

Posted by GitBox <gi...@apache.org>.
tianxiaoliang merged pull request #803:
URL: https://github.com/apache/servicecomb-service-center/pull/803


   


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [servicecomb-service-center] yeyiwei commented on a change in pull request #803: sync data processer

Posted by GitBox <gi...@apache.org>.
yeyiwei commented on a change in pull request #803:
URL: https://github.com/apache/servicecomb-service-center/pull/803#discussion_r550370054



##########
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:
       GetService()方法存在service和err都为nil的情况,已改为两次判断




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [servicecomb-service-center] tianxiaoliang commented on a change in pull request #803: sync data processer

Posted by GitBox <gi...@apache.org>.
tianxiaoliang commented on a change in pull request #803:
URL: https://github.com/apache/servicecomb-service-center/pull/803#discussion_r550382343



##########
File path: datasource/mongo/event/instance_event_handler.go
##########
@@ -0,0 +1,117 @@
+/*
+ * 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})

Review comment:
       为何err是复数

##########
File path: datasource/mongo/event/instance_event_handler.go
##########
@@ -0,0 +1,117 @@
+/*
+ * 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 errs != nil {
+			log.Error("get service from database error", errs)
+			return
+		}
+		if service == nil {

Review comment:
       这里无法分辨出是服务真的不存在,还是查询时出错了




----------------------------------------------------------------
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:
users@infra.apache.org