This is an automated email from the ASF dual-hosted git repository. laurence pushed a commit to branch bugfix-3.0 in repository https://gitbox.apache.org/repos/asf/dubbo-go.git
commit 6111d1a82daf3e42c33267468f6409e3c1a837af Author: LaurenceLiZhixin <[email protected]> AuthorDate: Fri Nov 12 16:16:10 2021 +0800 fix: some bugs --- common/proxy/proxy.go | 31 ++++++++++++++++++++++++------- config_center/nacos/listener.go | 2 +- go.mod | 4 ++-- go.sum | 8 ++++---- protocol/dubbo3/dubbo3_invoker.go | 19 +++++++++++++++++-- protocol/dubbo3/dubbo3_protocol.go | 8 +------- registry/base_registry.go | 6 +++--- remoting/zookeeper/listener.go | 2 +- 8 files changed, 53 insertions(+), 27 deletions(-) diff --git a/common/proxy/proxy.go b/common/proxy/proxy.go index e1c6222..c32eedc 100644 --- a/common/proxy/proxy.go +++ b/common/proxy/proxy.go @@ -19,6 +19,7 @@ package proxy import ( "context" + "errors" "reflect" "sync" ) @@ -116,13 +117,6 @@ func DefaultProxyImplementFunc(p *Proxy, v common.RPCService) { valueOf := reflect.ValueOf(v) valueOfElem := valueOf.Elem() - typeOf := valueOfElem.Type() - - // check incoming interface, incoming interface's elem must be a struct. - if typeOf.Kind() != reflect.Struct { - logger.Errorf("The type of RPCService(=\"%T\") must be a pointer of a struct.", v) - return - } makeDubboCallProxy := func(methodName string, outs []reflect.Type) func(in []reflect.Value) []reflect.Value { return func(in []reflect.Value) []reflect.Value { @@ -227,6 +221,18 @@ func DefaultProxyImplementFunc(p *Proxy, v common.RPCService) { } } + if err := refectAndMakeObjectFunc(valueOfElem, makeDubboCallProxy); err != nil { + logger.Errorf("The type or combination type of RPCService %T must be a pointer of a struct. error is %s", v, err) + return + } +} + +func refectAndMakeObjectFunc(valueOfElem reflect.Value, makeDubboCallProxy func(methodName string, outs []reflect.Type) func(in []reflect.Value) []reflect.Value) error { + typeOf := valueOfElem.Type() + // check incoming interface, incoming interface's elem must be a struct. + if typeOf.Kind() != reflect.Struct { + return errors.New("invalid type kind") + } numField := valueOfElem.NumField() for i := 0; i < numField; i++ { t := typeOf.Field(i) @@ -258,6 +264,17 @@ func DefaultProxyImplementFunc(p *Proxy, v common.RPCService) { // do method proxy here: f.Set(reflect.MakeFunc(f.Type(), makeDubboCallProxy(methodName, funcOuts))) logger.Debugf("set method [%s]", methodName) + } else if f.IsValid() && f.CanSet() { + // for struct combination + valueOfSub := reflect.New(t.Type) + valueOfElemInterface := valueOfSub.Elem() + if valueOfElemInterface.Type().Kind() == reflect.Struct { + if err := refectAndMakeObjectFunc(valueOfElemInterface, makeDubboCallProxy); err != nil { + return err + } + f.Set(valueOfElemInterface) + } } } + return nil } diff --git a/config_center/nacos/listener.go b/config_center/nacos/listener.go index 3d60d2a..a4cf589 100644 --- a/config_center/nacos/listener.go +++ b/config_center/nacos/listener.go @@ -22,6 +22,7 @@ import ( ) import ( + constant2 "github.com/nacos-group/nacos-sdk-go/common/constant" "github.com/nacos-group/nacos-sdk-go/vo" ) @@ -30,7 +31,6 @@ import ( "dubbo.apache.org/dubbo-go/v3/common/logger" "dubbo.apache.org/dubbo-go/v3/config_center" "dubbo.apache.org/dubbo-go/v3/remoting" - constant2 "github.com/nacos-group/nacos-sdk-go/common/constant" ) func callback(listener config_center.ConfigurationListener, _, _, dataId, data string) { diff --git a/go.mod b/go.mod index 30d3bb8..b8081b2 100644 --- a/go.mod +++ b/go.mod @@ -13,8 +13,8 @@ require ( github.com/creasty/defaults v1.5.2 github.com/dubbogo/go-zookeeper v1.0.3 github.com/dubbogo/gost v1.11.19 - github.com/dubbogo/grpc-go v1.42.4-triple - github.com/dubbogo/triple v1.1.2 + github.com/dubbogo/grpc-go v1.42.5-triple + github.com/dubbogo/triple v1.1.3 github.com/emicklei/go-restful/v3 v3.7.1 github.com/fsnotify/fsnotify v1.5.1 github.com/ghodss/yaml v1.0.0 diff --git a/go.sum b/go.sum index 2fbdc68..a98656a 100644 --- a/go.sum +++ b/go.sum @@ -177,13 +177,13 @@ github.com/dubbogo/gost v1.11.12/go.mod h1:vIcP9rqz2KsXHPjsAwIUtfJIJjppQLQDcYaZT github.com/dubbogo/gost v1.11.18/go.mod h1:vIcP9rqz2KsXHPjsAwIUtfJIJjppQLQDcYaZTy/61jI= github.com/dubbogo/gost v1.11.19 h1:R1rZ3TNJKV9W5XHLMv+GDO2Wy6UDnwGQtVWbsWYvo0A= github.com/dubbogo/gost v1.11.19/go.mod h1:vIcP9rqz2KsXHPjsAwIUtfJIJjppQLQDcYaZTy/61jI= -github.com/dubbogo/grpc-go v1.42.4-triple h1:ysiabUrEGcaeXgnjSBT0bB1M7EexSJFiO0Mebg/Iqa4= -github.com/dubbogo/grpc-go v1.42.4-triple/go.mod h1:F1T9hnUvYGW4JLK1QNriavpOkhusU677ovPzLkk6zHM= +github.com/dubbogo/grpc-go v1.42.5-triple h1:Ed5z/ikkpdZHBMA4mTEthQFTQeKlHtkdAsQrZjTbFk8= +github.com/dubbogo/grpc-go v1.42.5-triple/go.mod h1:F1T9hnUvYGW4JLK1QNriavpOkhusU677ovPzLkk6zHM= github.com/dubbogo/jsonparser v1.0.1/go.mod h1:tYAtpctvSP/tWw4MeelsowSPgXQRVHHWbqL6ynps8jU= github.com/dubbogo/net v0.0.4/go.mod h1:1CGOnM7X3he+qgGNqjeADuE5vKZQx/eMSeUkpU3ujIc= github.com/dubbogo/triple v1.0.9/go.mod h1:1t9me4j4CTvNDcsMZy6/OGarbRyAUSY0tFXGXHCp7Iw= -github.com/dubbogo/triple v1.1.2 h1:7lmQ0uNvcIYlMj5gNwPQadFx8w8UDEtcYl4DL6X+idM= -github.com/dubbogo/triple v1.1.2/go.mod h1:x+H41M5yP1ULnJu4b+o8VrgsIKdTPslTum2yUqA9N1I= +github.com/dubbogo/triple v1.1.3 h1:XKSh42lE2HLud++g4Fif7XY2hSMEsohFpegZPvsNXVQ= +github.com/dubbogo/triple v1.1.3/go.mod h1:suMeAfZliq0p/lWIytgEdiuKcRlmeJC9pYeNHVE7FWU= github.com/dustin/go-humanize v0.0.0-20171111073723-bb3d318650d4/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk= github.com/dustin/go-humanize v1.0.0 h1:VSnTsYCnlFHaM2/igO1h6X3HA71jcobQuxemgkq4zYo= github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk= diff --git a/protocol/dubbo3/dubbo3_invoker.go b/protocol/dubbo3/dubbo3_invoker.go index c978f85..da42a32 100644 --- a/protocol/dubbo3/dubbo3_invoker.go +++ b/protocol/dubbo3/dubbo3_invoker.go @@ -27,6 +27,8 @@ import ( ) import ( + "github.com/dubbogo/grpc-go/metadata" + tripleConstant "github.com/dubbogo/triple/pkg/common/constant" triConfig "github.com/dubbogo/triple/pkg/config" "github.com/dubbogo/triple/pkg/triple" @@ -134,7 +136,19 @@ func (di *DubboInvoker) Invoke(ctx context.Context, invocation protocol.Invocati } // append interface id to ctx - ctx = context.WithValue(ctx, tripleConstant.CtxAttachmentKey, invocation.Attachments()) + gRPCMD := make(metadata.MD, 0) + for k, v := range invocation.Attachments() { + if str, ok := v.(string); ok { + gRPCMD.Set(k, str) + continue + } + if str, ok := v.([]string); ok { + gRPCMD.Set(k, str...) + continue + } + logger.Warnf("triple attachment value with key = %s is invalid, which should be string or []string", k) + } + ctx = metadata.NewOutgoingContext(ctx, gRPCMD) ctx = context.WithValue(ctx, tripleConstant.InterfaceKey, di.BaseInvoker.GetURL().GetParam(constant.InterfaceKey, "")) in := make([]reflect.Value, 0, 16) in = append(in, reflect.ValueOf(ctx)) @@ -146,8 +160,9 @@ func (di *DubboInvoker) Invoke(ctx context.Context, invocation protocol.Invocati methodName := invocation.MethodName() triAttachmentWithErr := di.client.Invoke(methodName, in, invocation.Reply()) result.Err = triAttachmentWithErr.GetError() + result.Attrs = make(map[string]interface{}) for k, v := range triAttachmentWithErr.GetAttachments() { - result.Attachment(k, v) + result.Attrs[k] = v } result.Rest = invocation.Reply() return &result diff --git a/protocol/dubbo3/dubbo3_protocol.go b/protocol/dubbo3/dubbo3_protocol.go index 3e097c7..2ad3dff 100644 --- a/protocol/dubbo3/dubbo3_protocol.go +++ b/protocol/dubbo3/dubbo3_protocol.go @@ -190,13 +190,7 @@ func (d *UnaryService) GetReqParamsInterfaces(methodName string) ([]interface{}, } func (d *UnaryService) InvokeWithArgs(ctx context.Context, methodName string, arguments []interface{}) (interface{}, error) { - dubboAttachment := make(map[string]interface{}) - tripleAttachment, ok := ctx.Value(tripleConstant.TripleAttachement).(tripleCommon.TripleAttachment) - if ok { - for k, v := range tripleAttachment { - dubboAttachment[k] = v - } - } + dubboAttachment, _ := ctx.Value(tripleConstant.TripleAttachement).(tripleCommon.DubboAttachment) res := d.proxyImpl.Invoke(ctx, invocation.NewRPCInvocation(methodName, arguments, dubboAttachment)) return res, res.Error() } diff --git a/registry/base_registry.go b/registry/base_registry.go index 7ac9f2b..c6151e8 100644 --- a/registry/base_registry.go +++ b/registry/base_registry.go @@ -358,7 +358,7 @@ func (r *BaseRegistry) consumerRegistry(c *common.URL, params url.Values, f crea rawURL string err error ) - dubboPath = fmt.Sprintf("/%s/%s/%s", r.URL.GetParam(constant.RegistryGroupKey, "dubbo"), r.service(c), common.DubboNodes[common.PROVIDER]) + dubboPath = fmt.Sprintf("/%s/%s/%s", r.URL.GetParam(constant.RegistryGroupKey, "dubbo"), r.service(c), common.DubboNodes[common.CONSUMER]) if f != nil { err = f(dubboPath) @@ -412,7 +412,7 @@ func (r *BaseRegistry) Subscribe(url *common.URL, notifyListener NotifyListener) listener.Close() break } else { - logger.Infof("[Zookeeper Registry] update begin, service event: %v", serviceEvent.String()) + logger.Debugf("[Zookeeper Registry] update begin, service event: %v", serviceEvent.String()) notifyListener.Notify(serviceEvent) } } @@ -443,7 +443,7 @@ func (r *BaseRegistry) UnSubscribe(url *common.URL, notifyListener NotifyListene listener.Close() break } else { - logger.Infof("[Zookeeper Registry] update begin, service event: %v", serviceEvent.String()) + logger.Debugf("[Zookeeper Registry] update begin, service event: %v", serviceEvent.String()) notifyListener.Notify(serviceEvent) } } diff --git a/remoting/zookeeper/listener.go b/remoting/zookeeper/listener.go index b4a2503..fbe4749 100644 --- a/remoting/zookeeper/listener.go +++ b/remoting/zookeeper/listener.go @@ -175,7 +175,7 @@ func (l *ZkEventListener) handleZkNodeEvent(zkPath string, children []string, li for _, n := range newChildren { newNode = path.Join(zkPath, n) - logger.Infof("[Zookeeper Listener] add zkNode{%s}", newNode) + logger.Debugf("[Zookeeper Listener] add zkNode{%s}", newNode) content, _, connErr := l.client.Conn.Get(newNode) if connErr != nil { logger.Errorf("Get new node path {%v} 's content error,message is {%v}",
