Skip to content

Commit

Permalink
Merge branch '3.0' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexStocks committed Aug 18, 2021
2 parents 727e346 + f8f38b5 commit 3da71a1
Show file tree
Hide file tree
Showing 248 changed files with 6,758 additions and 5,458 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/github-actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: CI

on:
push:
branches: [master, develop]
branches: [master, develop, "1.5", "3.0"]
pull_request:
branches: "*"

Expand Down Expand Up @@ -59,7 +59,7 @@ jobs:
# diff -u <(echo -n) <(gofmt -d -s .)
- name: Install go ci lint
run: curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.27.0
run: curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.41.1

- name: Run Linter
run: golangci-lint run --timeout=10m -v
Expand Down
4 changes: 1 addition & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*.so
*.dylib
*.jar
*.log

# Test binary, build with `go test -c`
*.test
Expand All @@ -28,9 +29,6 @@ remoting/zookeeper/zookeeper-4unittest/
config_center/zookeeper/zookeeper-4unittest/
registry/zookeeper/zookeeper-4unittest/
metadata/report/zookeeper/zookeeper-4unittest/
registry/consul/agent*
metadata/report/consul/agent*
remoting/consul/agent*
config_center/apollo/mockDubbog.properties.json

# vim stuff
Expand Down
13 changes: 9 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ Apache Dubbo-go, a Dubbo implementation written in Golang, is born to bridge the

## Architecture

![dubbo go extend](https://dubbogo.github.io/img/doc/dubbo-go-arch.png)
![dubbo go extend](https://dubbogo.github.io/img/doc/dubbo-go3.0-arch.jpg)

Dubbo-go has been implemented most layers of Dubbo, like protocol layer, registry layer, etc. An extension module is applied to Dubbo-go in order to achieve a more flexible architecture. Developers are allowed to implement a customized layer conformed to the layer interface and use then in Dubbo-go via `extension.Set` method without modifying the source code.
Dubbo-go has been implemented most layers of Dubbo, like protocol layer, registry layer, etc. An extension module is applied to Dubbo-go in order to achieve a more flexible architecture. Developers are allowed to implement a customized layer conformed to the layer interface and use them in Dubbo-go via `extension.Set` method without modifying the source code.

## Features

Expand All @@ -31,12 +31,12 @@ The features that are available for Dubbo-go are:
- **Dynamic Configure Center & Service Management Configurator**: Zookeeper, [Apollo](https://github.com/apache/dubbo-go/pull/250), [Nacos](https://github.com/apache/dubbo-go/pull/357)
- **Cluster Strategy**: Failover, [Failfast](https://github.com/apache/dubbo-go/pull/140), [Failsafe/Failback](https://github.com/apache/dubbo-go/pull/136), [Available](https://github.com/apache/dubbo-go/pull/155), [Broadcast](https://github.com/apache/dubbo-go/pull/158), [Forking](https://github.com/apache/dubbo-go/pull/161)
- **Load Balance**: Random, [RoundRobin](https://github.com/apache/dubbo-go/pull/66), [LeastActive](https://github.com/apache/dubbo-go/pull/65), [ConsistentHash](https://github.com/apache/dubbo-go/pull/261)
- **Filter**: Echo Health Check, [Circuit Break and Service Downgrade](https://github.com/apache/dubbo-go/pull/133), [TokenFilter](https://github.com/apache/dubbo-go/pull/202), [AccessLogFilter](https://github.com/apache/dubbo-go/pull/214), [TpsLimitFilter](https://github.com/apache/dubbo-go/pull/237), [ExecuteLimitFilter](https://github.com/apache/dubbo-go/pull/246), [GenericServiceFilter](https://github.com/apache/dubbo-go/pull/291), [Auth/Sign](https://github.com/apache/dubbo-go/pull/323), [MetricsFilter](https://github.com/apache/dubbo-go/pull/342), [TracingFilter](https://github.com/apache/dubbo-go/pull/335)
- [**Filter**](./filter): Echo, Hystrix, Token, AccessLog, TpsLimiter, ExecuteLimit, Generic, Auth/Sign, Metrics, Tracing, Active, Seata, Sentinel
- **Invoke**: [Generic Invoke](https://github.com/apache/dubbo-go/pull/122)
- **Monitor**: Opentracing API, [Prometheus](https://github.com/apache/dubbo-go/pull/342)
- **Tracing**: [For JsonRPC](https://github.com/apache/dubbo-go/pull/335), [For Dubbo](https://github.com/apache/dubbo-go/pull/344), [For gRPC](https://github.com/apache/dubbo-go/pull/397)
- **Metadata Center**: [Nacos(Local)](https://github.com/apache/dubbo-go/pull/522), [ZooKeeper(Local)](https://github.com/apache/dubbo-go/pull/633), [etcd(Local)](https://github.com/apache/dubbo-go/blob/9a5990d9a9c3d5e6633c0d7d926c156416bcb931/metadata/report/etcd/report.go), [Consul(Local)](https://github.com/apache/dubbo-go/pull/633), [ZooKeeper(Remoting)](https://github.com/apache/dubbo-go/pull/1161)
- **Tool**: [Dubbo-go-cli](https://github.com/apache/dubbo-go/pull/818)
- **Tool**: [Dubbo-go-cli](https://github.com/dubbogo/tools)

## Getting started

Expand Down Expand Up @@ -151,6 +151,11 @@ If you are using [apache/dubbo-go](https://github.com/apache/dubbo-go) and think
<img width="222px" src="https://gw.alicdn.com/tfs/TB1HPATMrrpK1RjSZTEXXcWAVXa-260-74.png">
</a>
</td>
<td align="center" valign="middle">
<a href="https://www.autohome.com.cn" target="_blank">
<img width="222px" src="https://avatars.githubusercontent.com/u/18279051?s=200&v=4">
</a>
</td>
</tr>
<tr></tr>
</tbody>
Expand Down
11 changes: 8 additions & 3 deletions README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Apache Dubbo Go 语言实现,架起 Java 和 Golang 之间的桥梁,与 gRPC

## 架构

![dubbo go extend](https://dubbogo.github.io/img/doc/dubbo-go-arch.png)
![dubbo go extend](https://dubbogo.github.io/img/doc/dubbo-go3.0-arch.jpg)

Dubbo-go已经实现了Dubbo的大部分层级,包括协议层(protocol layer)、注册层(registry layer))等等。在Dubbo-go中使用了拓展模块(extension module)以实现更灵活的系统架构,开发者可以根据层接口实现一个自定义的层,并在不改动源代码的前提下通过`extension.Set`方法将它应用到Dubbo-go中。

Expand All @@ -31,12 +31,12 @@ Dubbo-go中已实现的特性:
- **动态配置中心与服务治理配置器**: Zookeeper, [Apollo](https://github.com/apache/dubbo-go/pull/250), [Nacos](https://github.com/apache/dubbo-go/pull/357)
- **集群策略**: Failover, [Failfast](https://github.com/apache/dubbo-go/pull/140), [Failsafe/Failback](https://github.com/apache/dubbo-go/pull/136), [Available](https://github.com/apache/dubbo-go/pull/155), [Broadcast](https://github.com/apache/dubbo-go/pull/158), [Forking](https://github.com/apache/dubbo-go/pull/161)
- **负载均衡策略**: Random, [RoundRobin](https://github.com/apache/dubbo-go/pull/66), [LeastActive](https://github.com/apache/dubbo-go/pull/65), [ConsistentHash](https://github.com/apache/dubbo-go/pull/261)
- **过滤器**: Echo Health Check, [Circuit Break and Service Downgrade](https://github.com/apache/dubbo-go/pull/133), [TokenFilter](https://github.com/apache/dubbo-go/pull/202), [AccessLogFilter](https://github.com/apache/dubbo-go/pull/214), [TpsLimitFilter](https://github.com/apache/dubbo-go/pull/237), [ExecuteLimitFilter](https://github.com/apache/dubbo-go/pull/246), [GenericServiceFilter](https://github.com/apache/dubbo-go/pull/291), [Auth/Sign](https://github.com/apache/dubbo-go/pull/323), [MetricsFilter](https://github.com/apache/dubbo-go/pull/342), [TracingFilter](https://github.com/apache/dubbo-go/pull/335)
- [**过滤器**](./filter): Echo, Hystrix, Token, AccessLog, TpsLimiter, ExecuteLimit, Generic, Auth/Sign, Metrics, Tracing, Active, Seata, Sentinel
- **调用**: [Generic Invoke](https://github.com/apache/dubbo-go/pull/122)
- **监控**: Opentracing API, [Prometheus](https://github.com/apache/dubbo-go/pull/342)
- **Tracing**: [For JsonRPC](https://github.com/apache/dubbo-go/pull/335), [For Dubbo](https://github.com/apache/dubbo-go/pull/344), [For gRPC](https://github.com/apache/dubbo-go/pull/397)
- **元数据中心**: [Nacos(Local)](https://github.com/apache/dubbo-go/pull/522), [ZooKeeper(Local)](https://github.com/apache/dubbo-go/pull/633), [etcd(Local)](https://github.com/apache/dubbo-go/blob/9a5990d9a9c3d5e6633c0d7d926c156416bcb931/metadata/report/etcd/report.go), [Consul(Local)](https://github.com/apache/dubbo-go/pull/633), [ZooKeeper(Remoting)](https://github.com/apache/dubbo-go/pull/1161)
- **工具**: [Dubbo-go-cli](https://github.com/apache/dubbo-go/pull/818)
- **工具**: [Dubbo-go-cli](https://github.com/dubbogo/tools)

## 开始

Expand Down Expand Up @@ -150,6 +150,11 @@ go get dubbo.apache.org/dubbo-go/v3
<img width="222px" src="https://gw.alicdn.com/tfs/TB1HPATMrrpK1RjSZTEXXcWAVXa-260-74.png">
</a>
</td>
<td align="center" valign="middle">
<a href="https://www.autohome.com.cn" target="_blank">
<img width="222px" src="https://avatars.githubusercontent.com/u/18279051?s=200&v=4">
</a>
</td>
</tr>
<tr></tr>
</tbody>
Expand Down
4 changes: 0 additions & 4 deletions cluster/cluster_impl/failover_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,6 @@ import (
"dubbo.apache.org/dubbo-go/v3/protocol/invocation"
)

// ///////////////////////////
// mock invoker
// ///////////////////////////

// nolint
type MockInvoker struct {
url *common.URL
Expand Down
6 changes: 3 additions & 3 deletions cluster/loadbalance/consistent_hash_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import (
const (
ip = "192.168.1.0"
port8080 = 8080
port8082 = 8082
port8081 = 8081

url8080Short = "dubbo://192.168.1.0:8080"
url8081Short = "dubbo://192.168.1.0:8081"
Expand Down Expand Up @@ -114,9 +114,9 @@ func (s *consistentHashLoadBalanceSuite) SetupTest() {
func (s *consistentHashLoadBalanceSuite) TestSelect() {
args := []interface{}{"name", "password", "age"}
invoker := s.lb.Select(s.invokers, invocation.NewRPCInvocation("echo", args, nil))
s.Equal(invoker.GetURL().Location, fmt.Sprintf("%s:%d", ip, port8080))
s.Equal(fmt.Sprintf("%s:%d", ip, port8081), invoker.GetURL().Location)

args = []interface{}{"ok", "abc"}
invoker = s.lb.Select(s.invokers, invocation.NewRPCInvocation("echo", args, nil))
s.Equal(invoker.GetURL().Location, fmt.Sprintf("%s:%d", ip, port8082))
s.Equal(fmt.Sprintf("%s:%d", ip, port8080), invoker.GetURL().Location)
}
2 changes: 0 additions & 2 deletions cluster/router/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,4 @@ type Chain interface {
SetInvokers([]protocol.Invoker)
// AddRouters Add routers
AddRouters([]PriorityRouter)
// GetNotifyChan get notify channel of this chain
GetNotifyChan() chan struct{}
}
62 changes: 5 additions & 57 deletions cluster/router/chain/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ package chain
import (
"sort"
"sync"
"time"
)

import (
Expand All @@ -31,7 +30,6 @@ import (
import (
"dubbo.apache.org/dubbo-go/v3/cluster/router"
"dubbo.apache.org/dubbo-go/v3/common"
"dubbo.apache.org/dubbo-go/v3/common/constant"
"dubbo.apache.org/dubbo-go/v3/common/extension"
"dubbo.apache.org/dubbo-go/v3/common/logger"
"dubbo.apache.org/dubbo-go/v3/protocol"
Expand All @@ -53,21 +51,6 @@ type RouterChain struct {
builtinRouters []router.PriorityRouter

mutex sync.RWMutex

url *common.URL

// The times of address notification since last update for address cache
count int64
// The timestamp of last update for address cache
last time.Time
// Channel for notify to update the address cache
notify chan struct{}
// Address cache
cache atomic.Value
}

func (c *RouterChain) GetNotifyChan() chan struct{} {
return c.notify
}

// Route Loop routers in RouterChain and call Route method to determine the target invokers list.
Expand All @@ -91,9 +74,6 @@ func (c *RouterChain) AddRouters(routers []router.PriorityRouter) {
c.mutex.Lock()
defer c.mutex.Unlock()
c.routers = newRouters
go func() {
c.notify <- struct{}{}
}()
}

// SetInvokers receives updated invokers from registry center. If the times of notification exceeds countThreshold and
Expand All @@ -102,10 +82,6 @@ func (c *RouterChain) SetInvokers(invokers []protocol.Invoker) {
c.mutex.Lock()
c.invokers = invokers
c.mutex.Unlock()

go func() {
c.notify <- struct{}{}
}()
}

// copyRouters make a snapshot copy from RouterChain's router list.
Expand Down Expand Up @@ -142,18 +118,13 @@ func NewRouterChain(url *common.URL) (*RouterChain, error) {
return nil, perrors.Errorf("No routerFactory exits , create one please")
}

chain := &RouterChain{
last: time.Now(),
notify: make(chan struct{}),
}

routers := make([]router.PriorityRouter, 0, len(routerFactories))

for key, routerFactory := range routerFactories {
if virtualServiceConfigByte == nil || destinationRuleConfigByte == nil {
logger.Warnf("virtual Service Config or destinationRule Confi Byte may be empty, pls check your CONF_VIRTUAL_SERVICE_FILE_PATH and CONF_DEST_RULE_FILE_PATH env is correctly point to your yaml file\n")
}
r, err := routerFactory().NewPriorityRouter(virtualServiceConfigByte, destinationRuleConfigByte, chain.notify)
r, err := routerFactory().NewPriorityRouter(virtualServiceConfigByte, destinationRuleConfigByte)
if r == nil || err != nil {
logger.Errorf("router chain build router fail! routerFactories key:%s error:%vv", key, err)
continue
Expand All @@ -168,36 +139,13 @@ func NewRouterChain(url *common.URL) (*RouterChain, error) {

routerNeedsUpdateInit := atomic.Bool{}
routerNeedsUpdateInit.Store(false)
chain.routers = newRouters
chain.builtinRouters = routers
if url != nil {
chain.url = url
}

return chain, nil
}

// isInvokersChanged compares new invokers on the right changes, compared with the old invokers on the left.
func isInvokersChanged(left []protocol.Invoker, right []protocol.Invoker) bool {
if len(right) != len(left) {
return true
chain := &RouterChain{
routers: newRouters,
builtinRouters: routers,
}

for _, r := range right {
found := false
rurl := r.GetURL()
for _, l := range left {
lurl := l.GetURL()
if common.GetCompareURLEqualFunc()(lurl, rurl, constant.TIMESTAMP_KEY, constant.REMOTE_TIMESTAMP_KEY) {
found = true
break
}
}
if !found {
return true
}
}
return false
return chain, nil
}

// sortRouter Sort router instance by priority with stable algorithm
Expand Down
78 changes: 0 additions & 78 deletions cluster/router/chain/invoker_cache.go

This file was deleted.

2 changes: 1 addition & 1 deletion cluster/router/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (
// PriorityRouterFactory creates creates priority router with url
type PriorityRouterFactory interface {
// NewPriorityRouter creates router instance with URL
NewPriorityRouter([]byte, []byte, chan struct{}) (PriorityRouter, error)
NewPriorityRouter([]byte, []byte) (PriorityRouter, error)
}

// Router
Expand Down
4 changes: 2 additions & 2 deletions cluster/router/v3router/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@ func NewUniformRouterFactory() router.PriorityRouterFactory {
}

// NewPriorityRouter construct a new UniformRouteFactory as PriorityRouter
func (f *UniformRouteFactory) NewPriorityRouter(vsConfigBytes, distConfigBytes []byte, notify chan struct{}) (router.PriorityRouter, error) {
return NewUniformRouterChain(vsConfigBytes, distConfigBytes, notify)
func (f *UniformRouteFactory) NewPriorityRouter(vsConfigBytes, distConfigBytes []byte) (router.PriorityRouter, error) {
return NewUniformRouterChain(vsConfigBytes, distConfigBytes)
}
2 changes: 1 addition & 1 deletion cluster/router/v3router/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (
func TestUniformRouterFacotry(t *testing.T) {
factory := NewUniformRouterFactory()
assert.NotNil(t, factory)
router, err := factory.NewPriorityRouter([]byte{}, []byte{}, make(chan struct{}))
router, err := factory.NewPriorityRouter([]byte{}, []byte{})
assert.Nil(t, err)
assert.NotNil(t, router)
}
Loading

0 comments on commit 3da71a1

Please sign in to comment.