You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@dubbo.apache.org by GitBox <gi...@apache.org> on 2020/04/26 06:56:05 UTC
[GitHub] [dubbo-go] cvictory opened a new pull request #494: 重构网络模块
cvictory opened a new pull request #494:
URL: https://github.com/apache/dubbo-go/pull/494
现在dubbo和getty耦合度很高,所以先进行第一轮抽象,部分逻辑后续待优化。
做的改动:
1. 增加exchange层做中转,连接dubbo协议和网络交互。exchange入参出参是invocation和result, 网络层入参出参是request和response
2. 在dubbo_protocol中增加共用相同连接(客户端访问server,当ip和端口相同,就共用exchange)
3. 将getty相关的逻辑移到remoting/getty下, 将addr和requestTimeout删除,getty服务管理连接,每个请求的超时,都是请求的入口传入,方便前面提到的连接共享
4. 抽象codec接口
5.requestId变成全局,PendingResponse也变成全局
待优化的小的功能点:
1. codec和remoting.client下后续可以抽象成扩展。现在还是编码形式存在。
2. codec中的hessian编解码,期望能对hessian进行抽象
3. getty中的逻辑尽量保持了和原来的逻辑一直,没有做调整,后续看下getty和remoting/getty之间的api层是否可以抽象。
-----
代码主干流程完成,部分异常和分支流程待完善,单元测试待完善。 先提交给大家看下
----------------------------------------------------------------
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] [dubbo-go] pantianying commented on a change in pull request #494: 重构网络模块
Posted by GitBox <gi...@apache.org>.
pantianying commented on a change in pull request #494:
URL: https://github.com/apache/dubbo-go/pull/494#discussion_r415292100
##########
File path: protocol/dubbo/dubbo_codec.go
##########
@@ -0,0 +1,297 @@
+package dubbo
+
+import (
+ "bufio"
+ "bytes"
+ "fmt"
+ hessian "github.com/apache/dubbo-go-hessian2"
+ "github.com/apache/dubbo-go/common/constant"
+ "github.com/apache/dubbo-go/common/logger"
+ "github.com/apache/dubbo-go/protocol"
+ "github.com/apache/dubbo-go/protocol/invocation"
+ "github.com/apache/dubbo-go/remoting"
+ perrors "github.com/pkg/errors"
+ "strconv"
+ "time"
+)
+
+//SerialID serial ID
+type SerialID byte
+type SequenceType int64
+
+const (
+ // S_Dubbo dubbo serial id
+ S_Dubbo SerialID = 2
+)
+
+// DubboPackage ...
+type DubboPackage struct {
+ Header hessian.DubboHeader
+ Service hessian.Service
+ Body interface{}
+ Err error
+}
+
+func (p DubboPackage) String() string {
+ return fmt.Sprintf("DubboPackage: Header-%v, Path-%v, Body-%v", p.Header, p.Service, p.Body)
+}
+
+//
+//// Marshal ...
+//func (p *DubboPackage) Marshal() (*bytes.Buffer, error) {
+// codec := hessian.NewHessianCodec(nil)
+//
+// pkg, err := codec.Write(p.Service, p.Header, p.Body)
+// if err != nil {
+// return nil, perrors.WithStack(err)
+// }
+//
+// return bytes.NewBuffer(pkg), nil
+//}
+//
+// Unmarshal ...
+func (p *DubboPackage) Unmarshal(buf *bytes.Buffer, resp *remoting.Response) error {
+ // fix issue https://github.com/apache/dubbo-go/issues/380
+ bufLen := buf.Len()
+ if bufLen < hessian.HEADER_LENGTH {
+ return perrors.WithStack(hessian.ErrHeaderNotEnough)
+ }
+
+ codec := hessian.NewHessianCodec(bufio.NewReaderSize(buf, bufLen))
+
+ // read header
+ err := codec.ReadHeader(&p.Header)
+ if err != nil {
+ return perrors.WithStack(err)
+ }
+
+ if resp != nil { // for client
+ if p.Header.Type&hessian.PackageRequest != 0x00 {
+ // size of this array must be '7'
+ // https://github.com/apache/dubbo-go-hessian2/blob/master/request.go#L272
+ p.Body = make([]interface{}, 7)
+ } else {
+ //pendingRsp, ok := client.pendingResponses.Load(SequenceType(p.Header.ID))
+ //if !ok {
+ // return perrors.Errorf("client.GetPendingResponse(%v) = nil", p.Header.ID)
+ //}
+ p.Body = &hessian.Response{RspObj: resp.Reply}
+ }
+ }
+
+ // read body
+ err = codec.ReadBody(p.Body)
+ return perrors.WithStack(err)
+}
+
+/////////////////////////////////////////
+/////////////////////////////////////////
+
+type DubboCodec struct {
+}
+
+func (c *DubboCodec) EncodeRequest(request remoting.Request) (*bytes.Buffer, error) {
+ invocation := request.Data.(invocation.RPCInvocation)
+
+ p := &DubboPackage{}
+ p.Service.Path = invocation.AttachmentsByKey(constant.PATH_KEY, "")
+ p.Service.Interface = invocation.AttachmentsByKey(constant.INTERFACE_KEY, "")
+ p.Service.Version = invocation.AttachmentsByKey(constant.VERSION_KEY, "")
+ p.Service.Group = invocation.AttachmentsByKey(constant.GROUP_KEY, "")
+ p.Service.Method = invocation.MethodName()
+
+ timeout, err := strconv.Atoi(invocation.AttachmentsByKey(constant.TIMEOUT_KEY, "3000"))
+ if err != nil {
+ panic(err)
Review comment:
后续panic不能用的,不能因为某个请求挂掉整个进程
##########
File path: protocol/dubbo/dubbo_invoker.go
##########
@@ -51,14 +52,14 @@ var (
// DubboInvoker ...
type DubboInvoker struct {
protocol.BaseInvoker
- client *Client
+ client *getty.Client
Review comment:
这样的话invoker只有一个getty client,和之前的逻辑不符了,需要确认下是否这样搞
----------------------------------------------------------------
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] [dubbo-go] cvictory commented on a change in pull request #494: 重构网络模块
Posted by GitBox <gi...@apache.org>.
cvictory commented on a change in pull request #494:
URL: https://github.com/apache/dubbo-go/pull/494#discussion_r415296263
##########
File path: protocol/dubbo/dubbo_codec.go
##########
@@ -0,0 +1,297 @@
+package dubbo
+
+import (
+ "bufio"
+ "bytes"
+ "fmt"
+ hessian "github.com/apache/dubbo-go-hessian2"
+ "github.com/apache/dubbo-go/common/constant"
+ "github.com/apache/dubbo-go/common/logger"
+ "github.com/apache/dubbo-go/protocol"
+ "github.com/apache/dubbo-go/protocol/invocation"
+ "github.com/apache/dubbo-go/remoting"
+ perrors "github.com/pkg/errors"
+ "strconv"
+ "time"
+)
+
+//SerialID serial ID
+type SerialID byte
+type SequenceType int64
+
+const (
+ // S_Dubbo dubbo serial id
+ S_Dubbo SerialID = 2
+)
+
+// DubboPackage ...
+type DubboPackage struct {
+ Header hessian.DubboHeader
+ Service hessian.Service
+ Body interface{}
+ Err error
+}
+
+func (p DubboPackage) String() string {
+ return fmt.Sprintf("DubboPackage: Header-%v, Path-%v, Body-%v", p.Header, p.Service, p.Body)
+}
+
+//
+//// Marshal ...
+//func (p *DubboPackage) Marshal() (*bytes.Buffer, error) {
+// codec := hessian.NewHessianCodec(nil)
+//
+// pkg, err := codec.Write(p.Service, p.Header, p.Body)
+// if err != nil {
+// return nil, perrors.WithStack(err)
+// }
+//
+// return bytes.NewBuffer(pkg), nil
+//}
+//
+// Unmarshal ...
+func (p *DubboPackage) Unmarshal(buf *bytes.Buffer, resp *remoting.Response) error {
+ // fix issue https://github.com/apache/dubbo-go/issues/380
+ bufLen := buf.Len()
+ if bufLen < hessian.HEADER_LENGTH {
+ return perrors.WithStack(hessian.ErrHeaderNotEnough)
+ }
+
+ codec := hessian.NewHessianCodec(bufio.NewReaderSize(buf, bufLen))
+
+ // read header
+ err := codec.ReadHeader(&p.Header)
+ if err != nil {
+ return perrors.WithStack(err)
+ }
+
+ if resp != nil { // for client
+ if p.Header.Type&hessian.PackageRequest != 0x00 {
+ // size of this array must be '7'
+ // https://github.com/apache/dubbo-go-hessian2/blob/master/request.go#L272
+ p.Body = make([]interface{}, 7)
+ } else {
+ //pendingRsp, ok := client.pendingResponses.Load(SequenceType(p.Header.ID))
+ //if !ok {
+ // return perrors.Errorf("client.GetPendingResponse(%v) = nil", p.Header.ID)
+ //}
+ p.Body = &hessian.Response{RspObj: resp.Reply}
+ }
+ }
+
+ // read body
+ err = codec.ReadBody(p.Body)
+ return perrors.WithStack(err)
+}
+
+/////////////////////////////////////////
+/////////////////////////////////////////
+
+type DubboCodec struct {
+}
+
+func (c *DubboCodec) EncodeRequest(request remoting.Request) (*bytes.Buffer, error) {
+ invocation := request.Data.(invocation.RPCInvocation)
+
+ p := &DubboPackage{}
+ p.Service.Path = invocation.AttachmentsByKey(constant.PATH_KEY, "")
+ p.Service.Interface = invocation.AttachmentsByKey(constant.INTERFACE_KEY, "")
+ p.Service.Version = invocation.AttachmentsByKey(constant.VERSION_KEY, "")
+ p.Service.Group = invocation.AttachmentsByKey(constant.GROUP_KEY, "")
+ p.Service.Method = invocation.MethodName()
+
+ timeout, err := strconv.Atoi(invocation.AttachmentsByKey(constant.TIMEOUT_KEY, "3000"))
+ if err != nil {
+ panic(err)
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] [dubbo-go] cvictory commented on pull request #494: 重构网络模块
Posted by GitBox <gi...@apache.org>.
cvictory commented on pull request #494:
URL: https://github.com/apache/dubbo-go/pull/494#issuecomment-619497367
先不要合,这个只是跑通了主干,细节待完善的还有好多,作为方案讨论中。
----------------------------------------------------------------
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