Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ftr: Triple Protocol Support #1071

Merged
merged 45 commits into from
Apr 3, 2021
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
789d3b0
ftr: add triple support
LaurenceLiZhixin Mar 1, 2021
8ebf52e
fix: change name
LaurenceLiZhixin Mar 1, 2021
b0bd3d8
Fix: delete unused replace
LaurenceLiZhixin Mar 1, 2021
e0e2993
fix: go fmt
LaurenceLiZhixin Mar 1, 2021
72ae2c1
fix
LaurenceLiZhixin Mar 1, 2021
72e91db
fix: dependency bug
LaurenceLiZhixin Mar 2, 2021
3aa8f1c
fix: dependency bug
LaurenceLiZhixin Mar 2, 2021
e930603
fix: add gen-dubbo3 go mod to pass ci
LaurenceLiZhixin Mar 2, 2021
c5fcc1f
Fix: fix ci lint
LaurenceLiZhixin Mar 2, 2021
956e382
fix: change ci go-version
LaurenceLiZhixin Mar 2, 2021
a96927f
fix: add liscense
LaurenceLiZhixin Mar 2, 2021
3466d14
Fix: change gost version
LaurenceLiZhixin Mar 2, 2021
83ff336
fix: fix cr
LaurenceLiZhixin Mar 7, 2021
7553e83
fix: destroy invoker smoothly
LaurenceLiZhixin Mar 8, 2021
57b92f9
fix: change triple struct
LaurenceLiZhixin Mar 14, 2021
53799e8
Fix: change triple api and add test file
LaurenceLiZhixin Mar 18, 2021
bbc9af2
fix: fix ci
LaurenceLiZhixin Mar 18, 2021
c1f9073
fix: change ctx key type
LaurenceLiZhixin Mar 18, 2021
98100e8
fix: fix linter
LaurenceLiZhixin Mar 18, 2021
c5e638d
fix: fix linter
LaurenceLiZhixin Mar 18, 2021
1d0f9fc
fix: add liscense
LaurenceLiZhixin Mar 18, 2021
95e0460
Fix: fix test
LaurenceLiZhixin Mar 18, 2021
90e3a32
fix: change port
LaurenceLiZhixin Mar 18, 2021
b37dd9f
fix: change port
LaurenceLiZhixin Mar 18, 2021
25cdffb
fix: change port
LaurenceLiZhixin Mar 18, 2021
31d9cd2
fix: change lock range
LaurenceLiZhixin Mar 18, 2021
e4f7549
Fix: delete debug
LaurenceLiZhixin Mar 19, 2021
5a359fa
fix: restart ci
LaurenceLiZhixin Mar 19, 2021
4152114
fix: fix test
LaurenceLiZhixin Mar 19, 2021
a7a2c30
fix: add serializer option
LaurenceLiZhixin Mar 26, 2021
fb540d9
fix: change triple
LaurenceLiZhixin Mar 26, 2021
3452103
fixï: add hessian support
LaurenceLiZhixin Apr 2, 2021
d785615
feat: add triple hessian support
LaurenceLiZhixin Apr 2, 2021
6a76922
fix: change go mod
LaurenceLiZhixin Apr 2, 2021
69136b3
fix: change consul
LaurenceLiZhixin Apr 2, 2021
00ae936
fix: triple finish
LaurenceLiZhixin Apr 3, 2021
e8bad05
fix: fix import block
LaurenceLiZhixin Apr 3, 2021
8b5ac5d
fix: restart ci
LaurenceLiZhixin Apr 3, 2021
5a5103b
fix: restart ci
LaurenceLiZhixin Apr 3, 2021
36fc244
fix: restart ci
LaurenceLiZhixin Apr 3, 2021
9202654
fix: update golang ci
LaurenceLiZhixin Apr 3, 2021
6ff62af
fix: fix conflict
LaurenceLiZhixin Apr 3, 2021
72abb01
fix: fix zk import
LaurenceLiZhixin Apr 3, 2021
9b0e5ea
fix: change ci lint vesion
LaurenceLiZhixin Apr 3, 2021
2d54f5c
fix: conflict
LaurenceLiZhixin Apr 3, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/github-actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
# If you want to matrix build , you can append the following list.
matrix:
go_version:
- 1.13
- 1.15
AlexStocks marked this conversation as resolved.
Show resolved Hide resolved
os:
- ubuntu-latest

Expand Down
24 changes: 8 additions & 16 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ module github.com/apache/dubbo-go
go 1.13

require (
github.com/NYTimes/gziphandler v1.1.1 // indirect
github.com/RoaringBitmap/roaring v0.5.5
github.com/Workiva/go-datastructures v1.0.52
github.com/afex/hystrix-go v0.0.0-20180502004556-fa1af6a1f4f5
Expand All @@ -14,46 +13,39 @@ require (
github.com/creasty/defaults v1.5.1
github.com/dubbogo/go-zookeeper v1.0.2
github.com/dubbogo/gost v1.11.0
github.com/elazarl/go-bindata-assetfs v1.0.0 // indirect
github.com/dubbogo/triple v0.0.0-20210301083516-185f5a3b1234
github.com/emicklei/go-restful/v3 v3.4.0
github.com/frankban/quicktest v1.4.1 // indirect
github.com/fsnotify/fsnotify v1.4.9
github.com/go-co-op/gocron v0.1.1
github.com/go-resty/resty/v2 v2.3.0
github.com/golang/mock v1.4.4
github.com/golang/protobuf v1.4.3
github.com/grpc-ecosystem/grpc-opentracing v0.0.0-20180507213350-8e809c8a8645
github.com/hashicorp/consul v1.8.0
github.com/hashicorp/consul/api v1.5.0
github.com/hashicorp/go-raftchunking v0.6.3-0.20191002164813-7e9e8525653a // indirect
github.com/hashicorp/vault/api v1.0.5-0.20191108163347-bdd38fca2cff // indirect
github.com/hashicorp/vault/sdk v0.1.14-0.20191112033314-390e96e22eb2
github.com/hashicorp/consul v1.8.5
github.com/hashicorp/consul/api v1.8.0
github.com/hashicorp/vault/sdk v0.1.14-0.20200519221838-e0cfd64bc267
github.com/jinzhu/copier v0.0.0-20190625015134-976e0346caa8
github.com/magiconair/properties v1.8.4
github.com/mitchellh/mapstructure v1.4.1
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd
github.com/nacos-group/nacos-sdk-go v1.0.6
github.com/opentracing/opentracing-go v1.2.0
github.com/pierrec/lz4 v2.2.6+incompatible // indirect
github.com/pkg/errors v0.9.1
github.com/prometheus/client_golang v1.8.0
github.com/prometheus/client_golang v1.9.0
github.com/satori/go.uuid v1.2.1-0.20181028125025-b2ce2384e17b
github.com/stretchr/objx v0.2.0 // indirect
github.com/stretchr/testify v1.7.0
github.com/zouyx/agollo/v3 v3.4.5
go.uber.org/atomic v1.7.0
go.uber.org/zap v1.16.0
golang.org/x/sys v0.0.0-20201223074533-0d417f636930 // indirect
google.golang.org/grpc v1.26.0
google.golang.org/grpc v1.33.1
gopkg.in/yaml.v2 v2.4.0
k8s.io/api v0.16.9
k8s.io/apimachinery v0.16.9
k8s.io/client-go v0.16.9
k8s.io/kube-openapi v0.0.0-20191107075043-30be4d16710a // indirect
)

replace (
github.com/coreos/bbolt => go.etcd.io/bbolt v1.3.4
github.com/envoyproxy/go-control-plane => github.com/envoyproxy/go-control-plane v0.8.0
github.com/shirou/gopsutil => github.com/shirou/gopsutil v0.0.0-20181107111621-48177ef5f880
go.etcd.io/bbolt v1.3.4 => github.com/coreos/bbolt v1.3.3
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

go.etcd.io/bbolt v1.3.4 => github.com/coreos/bbolt v1.3.4

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed!

google.golang.org/grpc => google.golang.org/grpc v1.26.0
)
364 changes: 344 additions & 20 deletions go.sum

Large diffs are not rendered by default.

53 changes: 53 additions & 0 deletions protocol/dubbo3/dubbo3_exporter.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* 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 dubbo3

import (
"sync"
)

import (
"github.com/apache/dubbo-go/common"
"github.com/apache/dubbo-go/common/constant"
"github.com/apache/dubbo-go/common/logger"
"github.com/apache/dubbo-go/protocol"
)

// DubboExporter is dubbo3 service exporter.
type DubboExporter struct {
protocol.BaseExporter
}

// NewDubboExporter get a Dubbo3Exporter.
func NewDubboExporter(key string, invoker protocol.Invoker, exporterMap *sync.Map) *DubboExporter {
return &DubboExporter{
BaseExporter: *protocol.NewBaseExporter(key, invoker, exporterMap),
}
}

// Unexport unexport dubbo3 service exporter.
func (de *DubboExporter) Unexport() {
url := de.GetInvoker().GetUrl()
serviceId := url.GetParam(constant.BEAN_NAME_KEY, "")
interfaceName := url.GetParam(constant.INTERFACE_KEY, "")
de.BaseExporter.Unexport()
err := common.ServiceMap.UnRegister(interfaceName, DUBBO3, serviceId)
if err != nil {
logger.Errorf("[DubboExporter.Unexport] error: %v", err)
}
}
144 changes: 144 additions & 0 deletions protocol/dubbo3/dubbo3_invoker.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
/*
* 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 dubbo3

import (
"context"
"reflect"
"strconv"
"strings"
"sync"
"time"
)

import (
hessian2 "github.com/apache/dubbo-go-hessian2"
)

import (
"github.com/apache/dubbo-go/common"
"github.com/apache/dubbo-go/common/constant"
"github.com/apache/dubbo-go/common/logger"
"github.com/apache/dubbo-go/config"
"github.com/apache/dubbo-go/protocol"
invocation_impl "github.com/apache/dubbo-go/protocol/invocation"
dubbo3 "github.com/dubbogo/triple/pkg/triple"
AlexStocks marked this conversation as resolved.
Show resolved Hide resolved
)

// DubboInvoker is implement of protocol.Invoker. A dubboInvoker refer to one service and ip.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please refact implementation follow

#1045

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed!

type DubboInvoker struct {
protocol.BaseInvoker
// the net layer client, it is focus on network communication.
client *dubbo3.TripleClient
quitOnce sync.Once
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

quitOnce for which object?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed, for quit dubbo3 invoker.

// timeout for service(interface) level.
timeout time.Duration
// Used to record the number of requests. -1 represent this DubboInvoker is destroyed
reqNum int64
}

// NewDubboInvoker constructor
func NewDubboInvoker(url *common.URL) (*DubboInvoker, error) {
requestTimeout := config.GetConsumerConfig().RequestTimeout
requestTimeoutStr := url.GetParam(constant.TIMEOUT_KEY, config.GetConsumerConfig().Request_Timeout)
if t, err := time.ParseDuration(requestTimeoutStr); err == nil {
requestTimeout = t
}

key := url.GetParam(constant.BEAN_NAME_KEY, "")
consumerService := config.GetConsumerService(key)
client, err := dubbo3.NewTripleClient(url, consumerService)
if err != nil {
return nil, err
}

return &DubboInvoker{
BaseInvoker: *protocol.NewBaseInvoker(url),
client: client,
reqNum: 0,
timeout: requestTimeout,
}, nil
}

// Invoke call remoting.
func (di *DubboInvoker) Invoke(ctx context.Context, invocation protocol.Invocation) protocol.Result {
var (
result protocol.RPCResult
)

in := make([]reflect.Value, 0, 16)
in = append(in, reflect.ValueOf(ctx))
if len(invocation.ParameterValues()) > 0 {
in = append(in, invocation.ParameterValues()...)
}

methodName := invocation.MethodName()
method := di.client.Invoker.MethodByName(methodName)
res := method.Call(in)

result.Rest = res[0]
// check err
if !res[1].IsNil() {
result.Err = res[1].Interface().(error)
} else {
_ = hessian2.ReflectResponse(res[0], invocation.Reply())
}

return &result
}

// get timeout including methodConfig
func (di *DubboInvoker) getTimeout(invocation *invocation_impl.RPCInvocation) time.Duration {
timeout := di.GetUrl().GetParam(strings.Join([]string{constant.METHOD_KEYS, invocation.MethodName(), constant.TIMEOUT_KEY}, "."), "")
if len(timeout) != 0 {
if t, err := time.ParseDuration(timeout); err == nil {
// config timeout into attachment
invocation.SetAttachments(constant.TIMEOUT_KEY, strconv.Itoa(int(t.Milliseconds())))
return t
}
}
// set timeout into invocation at method level
invocation.SetAttachments(constant.TIMEOUT_KEY, strconv.Itoa(int(di.timeout.Milliseconds())))
return di.timeout
}

// IsAvailable check if invoker is available, now it is useless
func (di *DubboInvoker) IsAvailable() bool {
return di.client.IsAvailable()
flycash marked this conversation as resolved.
Show resolved Hide resolved
}

// Destroy destroy dubbo3 client invoker.
func (di *DubboInvoker) Destroy() {
AlexStocks marked this conversation as resolved.
Show resolved Hide resolved
di.quitOnce.Do(func() {
for {
if di.reqNum == 0 {
di.reqNum = -1
logger.Infof("dubboInvoker is destroyed,url:{%s}", di.GetUrl().Key())
di.BaseInvoker.Destroy()
if di.client != nil {
di.client.Close()
di.client = nil
}
break
}
logger.Warnf("DubboInvoker is to be destroyed, wait {%v} req end,url:{%s}", di.reqNum, di.GetUrl().Key())
time.Sleep(1 * time.Second)
}

})
}
Loading