Skip to content
Snippets Groups Projects
Commit 305aa06b authored by 邹毅贤's avatar 邹毅贤
Browse files

fix router init bug

parent 09d77773
No related branches found
No related tags found
No related merge requests found
......@@ -23,6 +23,7 @@ import (
import (
"github.com/dubbogo/gost/container/set"
perrors "github.com/pkg/errors"
"go.uber.org/atomic"
)
......@@ -33,6 +34,7 @@ import (
"github.com/apache/dubbo-go/common/constant"
"github.com/apache/dubbo-go/common/extension"
"github.com/apache/dubbo-go/common/logger"
"github.com/apache/dubbo-go/protocol"
)
var routerURLSet = gxset.NewSet()
......@@ -131,3 +133,17 @@ func GetRouterURLSet() *gxset.HashSet {
func AddRouterURLSet(url *common.URL) {
routerURLSet.Add(url)
}
// BuildRouterChain build router chain by invokers
func (dir *staticDirectory) BuildRouterChain(invokers []protocol.Invoker) error {
if len(invokers) == 0 {
return perrors.Errorf("invokers == null")
}
url := invokers[0].GetUrl()
routerChain, e := chain.NewRouterChain(&url)
if e != nil {
return e
}
dir.SetRouterChain(routerChain)
return nil
}
......@@ -49,7 +49,7 @@ type RouterChain struct {
}
// Route Loop routers in RouterChain and call Route method to determine the target invokers list.
func (c RouterChain) Route(invoker []protocol.Invoker, url *common.URL, invocation protocol.Invocation) []protocol.Invoker {
func (c *RouterChain) Route(invoker []protocol.Invoker, url *common.URL, invocation protocol.Invocation) []protocol.Invoker {
finalInvokers := invoker
l := len(c.routers)
rs := make([]router.Router, l, int(math.Ceil(float64(l)*1.2)))
......@@ -67,7 +67,7 @@ func (c RouterChain) Route(invoker []protocol.Invoker, url *common.URL, invocati
// New a array add builtinRouters which is not sorted in RouterChain and routers
// Sort the array
// Replace router array in RouterChain
func (c RouterChain) AddRouters(routers []router.Router) {
func (c *RouterChain) AddRouters(routers []router.Router) {
newRouters := make([]router.Router, 0, len(c.builtinRouters)+len(routers))
newRouters = append(newRouters, c.builtinRouters...)
newRouters = append(newRouters, routers...)
......
......@@ -29,7 +29,6 @@ import (
import (
"github.com/apache/dubbo-go/cluster/directory"
"github.com/apache/dubbo-go/cluster/router/chain"
"github.com/apache/dubbo-go/common"
"github.com/apache/dubbo-go/common/constant"
"github.com/apache/dubbo-go/common/extension"
......@@ -178,34 +177,19 @@ func (dir *registryDirectory) toGroupInvokers() []protocol.Invoker {
//len is 1 it means no group setting ,so do not need cluster again
for _, invokers := range groupInvokersMap {
groupInvokersList = invokers
dir.buildRouterChain(invokers)
}
} else {
for _, invokers := range groupInvokersMap {
staticDir := directory.NewStaticDirectory(invokers)
cluster := extension.GetCluster(dir.GetUrl().SubURL.GetParam(constant.CLUSTER_KEY, constant.DEFAULT_CLUSTER))
staticDir.BuildRouterChain(invokers)
groupInvokersList = append(groupInvokersList, cluster.Join(staticDir))
dir.buildRouterChain(invokers)
}
}
return groupInvokersList
}
func (dir *registryDirectory) buildRouterChain(invokers []protocol.Invoker) error {
if len(invokers) == 0 {
return perrors.Errorf("invokers == null")
}
url := invokers[0].GetUrl()
routerChain, e := chain.NewRouterChain(&url)
if e != nil {
return e
}
dir.SetRouterChain(routerChain)
return nil
}
func (dir *registryDirectory) uncacheInvoker(url *common.URL) {
logger.Debugf("service will be deleted in cache invokers: invokers key is %s!", url.Key())
dir.cacheInvokersMap.Delete(url.Key())
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment