You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by al...@apache.org on 2021/06/27 13:18:42 UTC

[dubbo-go] branch 3.0 updated: fix: add arch picture in readme and delete unused router field. (#1279)

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

alexstocks pushed a commit to branch 3.0
in repository https://gitbox.apache.org/repos/asf/dubbo-go.git


The following commit(s) were added to refs/heads/3.0 by this push:
     new 893bfb5  fix: add arch picture in readme and delete unused router field. (#1279)
893bfb5 is described below

commit 893bfb5020a9e53861f87d20663c1ebdedfa9217
Author: Laurence <45...@users.noreply.github.com>
AuthorDate: Sun Jun 27 21:18:35 2021 +0800

    fix: add arch picture in readme and delete unused router field. (#1279)
    
    * fix
    
    * fix: delete notify
---
 README.md                                    |  2 +-
 README_CN.md                                 |  2 +-
 cluster/router/chain.go                      |  2 -
 cluster/router/chain/chain.go                | 62 ++--------------------
 cluster/router/chain/invoker_cache.go        | 78 ----------------------------
 cluster/router/router.go                     |  2 +-
 cluster/router/rule.go                       | 31 -----------
 cluster/router/v3router/factory.go           |  4 +-
 cluster/router/v3router/factory_test.go      |  2 +-
 cluster/router/v3router/router_chain.go      | 13 +++--
 cluster/router/v3router/router_chain_test.go |  6 +--
 cluster/router/v3router/uniform_route.go     |  4 +-
 12 files changed, 21 insertions(+), 187 deletions(-)

diff --git a/README.md b/README.md
index c3031e8..7b35696 100644
--- a/README.md
+++ b/README.md
@@ -14,7 +14,7 @@ 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.
 
diff --git a/README_CN.md b/README_CN.md
index 2f7963f..d6b5dcb 100644
--- a/README_CN.md
+++ b/README_CN.md
@@ -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中。
 
diff --git a/cluster/router/chain.go b/cluster/router/chain.go
index bde5aec..6c7c034 100644
--- a/cluster/router/chain.go
+++ b/cluster/router/chain.go
@@ -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{}
 }
diff --git a/cluster/router/chain/chain.go b/cluster/router/chain/chain.go
index 9268baf..616909a 100644
--- a/cluster/router/chain/chain.go
+++ b/cluster/router/chain/chain.go
@@ -20,7 +20,6 @@ package chain
 import (
 	"sort"
 	"sync"
-	"time"
 )
 
 import (
@@ -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"
@@ -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.
@@ -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
@@ -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.
@@ -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
@@ -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
diff --git a/cluster/router/chain/invoker_cache.go b/cluster/router/chain/invoker_cache.go
deleted file mode 100644
index 8fde0dd..0000000
--- a/cluster/router/chain/invoker_cache.go
+++ /dev/null
@@ -1,78 +0,0 @@
-/*
- * 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 chain
-
-import (
-	"github.com/RoaringBitmap/roaring"
-)
-
-import (
-	"dubbo.apache.org/dubbo-go/v3/cluster/router"
-	"dubbo.apache.org/dubbo-go/v3/protocol"
-)
-
-// Cache caches all addresses relevant info for a snapshot of received invokers. It keeps a snapshot of the received
-// address list, and also keeps address pools and address metadata from routers based on the same address snapshot, if
-// the router implements Poolable.
-type InvokerCache struct {
-	// The snapshot of invokers
-	invokers []protocol.Invoker
-
-	// The bitmap representation for invokers snapshot
-	bitmap *roaring.Bitmap
-
-	// Address pool from routers which implement Poolable
-	pools map[string]router.AddrPool
-
-	// Address metadata from routers which implement Poolable
-	metadatas map[string]router.AddrMetadata
-}
-
-// BuildCache builds address cache from the given invokers.
-func BuildCache(invokers []protocol.Invoker) *InvokerCache {
-	return &InvokerCache{
-		invokers:  invokers,
-		pools:     make(map[string]router.AddrPool, 8),
-		metadatas: make(map[string]router.AddrMetadata, 8),
-	}
-}
-
-// GetInvokers get invokers snapshot.
-func (c *InvokerCache) GetInvokers() []protocol.Invoker {
-	return c.invokers
-}
-
-// FindAddrPool finds address pool for a poolable router.
-func (c *InvokerCache) FindAddrPool(p router.Poolable) router.AddrPool {
-	return c.pools[p.Name()]
-}
-
-// FindAddrMeta finds address metadata for a poolable router.
-func (c *InvokerCache) FindAddrMeta(p router.Poolable) router.AddrMetadata {
-	return c.metadatas[p.Name()]
-}
-
-// SetAddrPool sets address pool for a poolable router, for unit test only
-func (c *InvokerCache) SetAddrPool(name string, pool router.AddrPool) {
-	c.pools[name] = pool
-}
-
-// SetAddrMeta sets address metadata for a poolable router, for unit test only
-func (c *InvokerCache) SetAddrMeta(name string, meta router.AddrMetadata) {
-	c.metadatas[name] = meta
-}
diff --git a/cluster/router/router.go b/cluster/router/router.go
index 5d653cd..d3d2fe5 100644
--- a/cluster/router/router.go
+++ b/cluster/router/router.go
@@ -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
diff --git a/cluster/router/rule.go b/cluster/router/rule.go
deleted file mode 100644
index 42c08a7..0000000
--- a/cluster/router/rule.go
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- * 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 router
-
-// BaseRouterRule
-type BaseRouterRule struct {
-	RawRule  string
-	Runtime  bool
-	Force    bool
-	Valid    bool
-	Enabled  bool
-	Priority int
-	Dynamic  bool
-	Scope    string
-	Key      string
-}
diff --git a/cluster/router/v3router/factory.go b/cluster/router/v3router/factory.go
index 0b164e7..afd14af 100644
--- a/cluster/router/v3router/factory.go
+++ b/cluster/router/v3router/factory.go
@@ -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)
 }
diff --git a/cluster/router/v3router/factory_test.go b/cluster/router/v3router/factory_test.go
index 365d755..a5ea415 100644
--- a/cluster/router/v3router/factory_test.go
+++ b/cluster/router/v3router/factory_test.go
@@ -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)
 }
diff --git a/cluster/router/v3router/router_chain.go b/cluster/router/v3router/router_chain.go
index dc14c73..ce82694 100644
--- a/cluster/router/v3router/router_chain.go
+++ b/cluster/router/v3router/router_chain.go
@@ -48,9 +48,9 @@ type RouterChain struct {
 }
 
 // NewUniformRouterChain return
-func NewUniformRouterChain(virtualServiceConfig, destinationRuleConfig []byte, notify chan struct{}) (router.PriorityRouter, error) {
+func NewUniformRouterChain(virtualServiceConfig, destinationRuleConfig []byte) (router.PriorityRouter, error) {
 	fromFileConfig := true
-	uniformRouters, err := parseFromConfigToRouters(virtualServiceConfig, destinationRuleConfig, notify)
+	uniformRouters, err := parseFromConfigToRouters(virtualServiceConfig, destinationRuleConfig)
 	if err != nil {
 		fromFileConfig = false
 		logger.Warnf("parse router config form local file failed, error = %+v", err)
@@ -59,7 +59,6 @@ func NewUniformRouterChain(virtualServiceConfig, destinationRuleConfig []byte, n
 		virtualServiceConfigBytes:  virtualServiceConfig,
 		destinationRuleConfigBytes: destinationRuleConfig,
 		routers:                    uniformRouters,
-		notify:                     notify,
 	}
 	if err := k8s_api.SetK8sEventListener(r); err != nil {
 		logger.Warnf("try listen K8s router config failed, error = %+v", err)
@@ -110,7 +109,7 @@ func (r *RouterChain) Process(event *config_center.ConfigChangeEvent) {
 				logger.Error("Process change of virtual service: event.Value marshal error:", err)
 				return
 			}
-			r.routers, err = parseFromConfigToRouters(data, r.destinationRuleConfigBytes, r.notify)
+			r.routers, err = parseFromConfigToRouters(data, r.destinationRuleConfigBytes)
 			if err != nil {
 				logger.Error("Process change of virtual service: parseFromConfigToRouters:", err)
 				return
@@ -142,7 +141,7 @@ func (r *RouterChain) Process(event *config_center.ConfigChangeEvent) {
 				logger.Error("Process change of dest rule: event.Value marshal error:", err)
 				return
 			}
-			r.routers, err = parseFromConfigToRouters(r.virtualServiceConfigBytes, data, r.notify)
+			r.routers, err = parseFromConfigToRouters(r.virtualServiceConfigBytes, data)
 			if err != nil {
 				logger.Error("Process change of dest rule: parseFromConfigToRouters:", err)
 				return
@@ -174,7 +173,7 @@ func (r *RouterChain) URL() *common.URL {
 }
 
 // parseFromConfigToRouters parse virtualService and destinationRule yaml file bytes to target router list
-func parseFromConfigToRouters(virtualServiceConfig, destinationRuleConfig []byte, notify chan struct{}) ([]*UniformRouter, error) {
+func parseFromConfigToRouters(virtualServiceConfig, destinationRuleConfig []byte) ([]*UniformRouter, error) {
 	var virtualServiceConfigList []*config.VirtualServiceConfig
 	destRuleConfigsMap := make(map[string]map[string]map[string]string)
 
@@ -234,7 +233,7 @@ func parseFromConfigToRouters(virtualServiceConfig, destinationRuleConfig []byte
 			logger.Error("Parse config to uniform rule err = ", err)
 			return nil, err
 		}
-		rtr, err := NewUniformRouter(newRule, notify)
+		rtr, err := NewUniformRouter(newRule)
 		if err != nil {
 			logger.Error("new uniform router err = ", err)
 			return nil, err
diff --git a/cluster/router/v3router/router_chain_test.go b/cluster/router/v3router/router_chain_test.go
index 4ce4eef..9e12da1 100644
--- a/cluster/router/v3router/router_chain_test.go
+++ b/cluster/router/v3router/router_chain_test.go
@@ -51,7 +51,7 @@ const (
 func TestNewUniformRouterChain(t *testing.T) {
 	vsBytes, _ := yaml.LoadYMLConfig(mockVSConfigPath)
 	drBytes, _ := yaml.LoadYMLConfig(mockDRConfigPath)
-	rc, err := NewUniformRouterChain(vsBytes, drBytes, make(chan struct{}))
+	rc, err := NewUniformRouterChain(vsBytes, drBytes)
 	assert.Nil(t, err)
 	assert.NotNil(t, rc)
 }
@@ -72,7 +72,7 @@ type ruleTestItemStruct struct {
 func TestParseConfigFromFile(t *testing.T) {
 	vsBytes, _ := yaml.LoadYMLConfig(mockVSConfigPath)
 	drBytes, _ := yaml.LoadYMLConfig(mockDRConfigPath)
-	routers, err := parseFromConfigToRouters(vsBytes, drBytes, make(chan struct{}, 1))
+	routers, err := parseFromConfigToRouters(vsBytes, drBytes)
 	fmt.Println(routers, err)
 	assert.Equal(t, len(routers), 1)
 	assert.NotNil(t, routers[0].dubboRouter)
@@ -199,7 +199,7 @@ func TestParseConfigFromFile(t *testing.T) {
 func TestRouterChain_Route(t *testing.T) {
 	vsBytes, _ := yaml.LoadYMLConfig(mockVSConfigPath)
 	drBytes, _ := yaml.LoadYMLConfig(mockDRConfigPath)
-	rc, err := NewUniformRouterChain(vsBytes, drBytes, make(chan struct{}))
+	rc, err := NewUniformRouterChain(vsBytes, drBytes)
 	assert.Nil(t, err)
 	assert.NotNil(t, rc)
 	newGoodURL, _ := common.NewURL("dubbo://127.0.0.1:20000/com.ikurento.user.UserProvider?interface=com.ikurento.user.UserProvider&group=&version=2.6.0")
diff --git a/cluster/router/v3router/uniform_route.go b/cluster/router/v3router/uniform_route.go
index f44eff1..9ea12dd 100644
--- a/cluster/router/v3router/uniform_route.go
+++ b/cluster/router/v3router/uniform_route.go
@@ -30,14 +30,12 @@ const (
 // UniformRouter have
 type UniformRouter struct {
 	dubboRouter *DubboRouterRule
-	notify      chan struct{}
 }
 
 // NewUniformRouter construct an NewConnCheckRouter via url
-func NewUniformRouter(dubboRouter *DubboRouterRule, notify chan struct{}) (*UniformRouter, error) {
+func NewUniformRouter(dubboRouter *DubboRouterRule) (*UniformRouter, error) {
 	r := &UniformRouter{
 		dubboRouter: dubboRouter,
-		notify:      notify,
 	}
 	return r, nil
 }