You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by li...@apache.org on 2021/04/12 14:20:02 UTC

[servicecomb-service-center] branch test updated (7d0b7ba -> 39422e9)

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

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


 discard 7d0b7ba  SCB-2176 Fix: failed to connect mongo
     add cf01f42  SCB-2176 Fix: remove bou.ke/monkey (#940)
     new 39422e9  SCB-2176 Fix: failed to connect mongo

This update added new revisions after undoing existing revisions.
That is to say, some revisions that were in the old version of the
branch are not in the new version.  This situation occurs
when a user --force pushes a change and generates a repository
containing something like this:

 * -- * -- B -- O -- O -- O   (7d0b7ba)
            \
             N -- N -- N   refs/heads/test (39422e9)

You should already have received notification emails for all of the O
revisions, and so the following emails describe only the N revisions
from the common base, B.

Any revisions marked "omit" are not gone; other references still
refer to them.  Any revisions marked "discard" are gone forever.

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../mongo/event/instance_event_handler_test.go     |  8 +------
 datasource/mongo/sd/listwatch_inner.go             | 16 ++++++++-----
 go.mod                                             |  1 -
 syncer/client/sync_client_test.go                  | 26 ----------------------
 4 files changed, 11 insertions(+), 40 deletions(-)

[servicecomb-service-center] 01/01: SCB-2176 Fix: failed to connect mongo

Posted by li...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 39422e9a3267b4734cc940352024e990a994303a
Author: little-cui <su...@qq.com>
AuthorDate: Mon Apr 12 19:27:16 2021 +0800

    SCB-2176 Fix: failed to connect mongo
---
 datasource/mongo/client/errortypes.go  |  6 ++++--
 datasource/mongo/mongo.go              | 11 +++++------
 datasource/mongo/sd/listwatch_inner.go | 16 ++++++++++------
 3 files changed, 19 insertions(+), 14 deletions(-)

diff --git a/datasource/mongo/client/errortypes.go b/datasource/mongo/client/errortypes.go
index 759315f..64dd599 100644
--- a/datasource/mongo/client/errortypes.go
+++ b/datasource/mongo/client/errortypes.go
@@ -20,8 +20,10 @@ import (
 )
 
 const (
-	DuplicateKey      = 11000
-	CollectionsExists = 48
+	DuplicateKey = 11000
+
+	MsgDBExists  = "already exists"
+	MsgDuplicate = "duplicate key error collection"
 )
 
 func IsDuplicateKey(err error) bool {
diff --git a/datasource/mongo/mongo.go b/datasource/mongo/mongo.go
index 8addf8f..1c34550 100644
--- a/datasource/mongo/mongo.go
+++ b/datasource/mongo/mongo.go
@@ -21,6 +21,7 @@ import (
 	"context"
 	"fmt"
 	"github.com/apache/servicecomb-service-center/pkg/util"
+	"strings"
 
 	"github.com/go-chassis/go-chassis/v2/storage"
 	"go.mongodb.org/mongo-driver/mongo"
@@ -210,9 +211,8 @@ func EnsureDep() {
 
 func wrapCreateCollectionError(err error) {
 	if err != nil {
-		// commandError can be returned by any operation
-		cmdErr, ok := err.(mongo.CommandError)
-		if ok && cmdErr.Code == client.CollectionsExists {
+		if strings.Contains(err.Error(), client.MsgDBExists) {
+			log.Info(fmt.Sprintf("failed to create collection, %s", err))
 			return
 		}
 		log.Fatal(fmt.Sprintf("failed to create collection with validation, err type: %s", util.Reflect(err).FullName), err)
@@ -221,9 +221,8 @@ func wrapCreateCollectionError(err error) {
 
 func wrapCreateIndexesError(err error) {
 	if err != nil {
-		// commandError can be returned by any operation
-		cmdErr, ok := err.(mongo.CommandError)
-		if ok && cmdErr.Code == client.DuplicateKey {
+		if strings.Contains(err.Error(), client.MsgDuplicate) {
+			log.Info(fmt.Sprintf("failed to create indexes, %s", err))
 			return
 		}
 		log.Fatal(fmt.Sprintf("failed to create indexes, err type: %s", util.Reflect(err).FullName), err)
diff --git a/datasource/mongo/sd/listwatch_inner.go b/datasource/mongo/sd/listwatch_inner.go
index da673c4..ff05add 100644
--- a/datasource/mongo/sd/listwatch_inner.go
+++ b/datasource/mongo/sd/listwatch_inner.go
@@ -132,9 +132,11 @@ func (lw *mongoListWatch) doParseDocumentToResource(fullDocument bson.Raw) (reso
 			log.Error("error to parse bson raw to documentInfo", err)
 			return
 		}
-		resource.Key = instance.Instance.InstanceId
-		resource.Value = instance
-		resource.Index = instance.Instance.ServiceId
+		if instance.Instance != nil {
+			resource.Key = instance.Instance.InstanceId
+			resource.Value = instance
+			resource.Index = instance.Instance.ServiceId
+		}
 	case service:
 		service := model.Service{}
 		err := bson.Unmarshal(fullDocument, &service)
@@ -142,9 +144,11 @@ func (lw *mongoListWatch) doParseDocumentToResource(fullDocument bson.Raw) (reso
 			log.Error("error to parse bson raw to documentInfo", err)
 			return
 		}
-		resource.Key = service.Service.ServiceId
-		resource.Value = service
-		resource.Index = util.StringJoin([]string{service.Domain, service.Project, service.Service.ServiceName, service.Service.Version, service.Service.AppId, service.Service.Environment}, "/")
+		if service.Service != nil {
+			resource.Key = service.Service.ServiceId
+			resource.Value = service
+			resource.Index = util.StringJoin([]string{service.Domain, service.Project, service.Service.ServiceName, service.Service.Version, service.Service.AppId, service.Service.Environment}, "/")
+		}
 	default:
 		return
 	}