Skip to content

Commit

Permalink
fix comment.
Browse files Browse the repository at this point in the history
Signed-off-by: imxyb <xyb4638@gmail.com>
  • Loading branch information
imxyb committed Nov 27, 2019
1 parent 7fb327e commit f8470a2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
20 changes: 10 additions & 10 deletions cluster/loadbalance/consistent_hash.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ import (
"sort"
"strconv"
"strings"
)

import (
"github.com/apache/dubbo-go/cluster"
"github.com/apache/dubbo-go/common/constant"
"github.com/apache/dubbo-go/common/extension"
Expand All @@ -39,17 +41,19 @@ const (
HashArguments = "hash.arguments"
)

var selectors = make(map[string]*ConsistentHashSelector)
var re = regexp.MustCompile(constant.COMMA_SPLIT_PATTERN)
var (
selectors = make(map[string]*ConsistentHashSelector)
re = regexp.MustCompile(constant.COMMA_SPLIT_PATTERN)
)

func init() {
extension.SetLoadbalance(ConsistentHash, NewConsistentHash)
extension.SetLoadbalance(ConsistentHash, NewConsistentHashLoadBalance)
}

type ConsistentHashLoadBalance struct {
}

func NewConsistentHash() cluster.LoadBalance {
func NewConsistentHashLoadBalance() cluster.LoadBalance {
return &ConsistentHashLoadBalance{}
}

Expand All @@ -69,7 +73,7 @@ func (lb *ConsistentHashLoadBalance) Select(invokers []protocol.Invoker, invocat
hashCode := crc32.ChecksumIEEE(bs)
selector, ok := selectors[key]
if !ok || selector.hashCode != hashCode {
selectors[key] = NewConsistentHashSelector(invokers, methodName, hashCode)
selectors[key] = newConsistentHashSelector(invokers, methodName, hashCode)
selector = selectors[key]
}
return selector.Select(invocation)
Expand Down Expand Up @@ -97,12 +101,8 @@ type ConsistentHashSelector struct {
argumentIndex []int
}

func NewConsistentHashSelector(invokers []protocol.Invoker, methodName string,
func newConsistentHashSelector(invokers []protocol.Invoker, methodName string,
hashCode uint32) *ConsistentHashSelector {
if len(invokers) == 0 {
panic("none of invokers")
}

selector := &ConsistentHashSelector{}
selector.virtualInvokers = make(map[uint32]protocol.Invoker)
selector.hashCode = hashCode
Expand Down
4 changes: 2 additions & 2 deletions cluster/loadbalance/consistent_hash_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func (s *consistentHashSelectorSuite) SetupTest() {
url, _ := common.NewURL(context.TODO(),
"dubbo://192.168.1.0:20000/org.apache.demo.HelloService?methods.echo.hash.arguments=0,1")
invokers = append(invokers, protocol.NewBaseInvoker(url))
s.selector = NewConsistentHashSelector(invokers, "echo", 999944)
s.selector = newConsistentHashSelector(invokers, "echo", 999944)
}

func (s *consistentHashSelectorSuite) TestToKey() {
Expand Down Expand Up @@ -92,7 +92,7 @@ func (s *consistentHashLoadBalanceSuite) SetupTest() {
s.invoker3 = protocol.NewBaseInvoker(s.url3)

s.invokers = append(s.invokers, s.invoker1, s.invoker2, s.invoker3)
s.lb = NewConsistentHash()
s.lb = NewConsistentHashLoadBalance()
}

func (s *consistentHashLoadBalanceSuite) TestSelect() {
Expand Down

0 comments on commit f8470a2

Please sign in to comment.