Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
2
22a7f0099
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Summer2022
22a7f0099
Commits
80e5bf59
Commit
80e5bf59
authored
5 years ago
by
imxyb
Browse files
Options
Downloads
Patches
Plain Diff
fix comment.
Signed-off-by:
imxyb
<
xyb4638@gmail.com
>
parent
7fb327ea
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
cluster/loadbalance/consistent_hash.go
+12
-11
12 additions, 11 deletions
cluster/loadbalance/consistent_hash.go
cluster/loadbalance/consistent_hash_test.go
+6
-2
6 additions, 2 deletions
cluster/loadbalance/consistent_hash_test.go
with
18 additions
and
13 deletions
cluster/loadbalance/consistent_hash.go
+
12
−
11
View file @
80e5bf59
...
...
@@ -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"
...
...
@@ -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
,
NewConsistentHash
LoadBalance
)
}
type
ConsistentHashLoadBalance
struct
{
}
func
NewConsistentHash
()
cluster
.
LoadBalance
{
func
NewConsistentHash
LoadBalance
()
cluster
.
LoadBalance
{
return
&
ConsistentHashLoadBalance
{}
}
...
...
@@ -62,14 +66,14 @@ func (lb *ConsistentHashLoadBalance) Select(invokers []protocol.Invoker, invocat
for
_
,
invoker
:=
range
invokers
{
b
,
err
:=
json
.
Marshal
(
invoker
)
if
err
!=
nil
{
panic
(
fmt
.
Sprintf
(
"parse json failed:%s"
,
err
.
Error
()))
return
nil
}
bs
=
append
(
bs
,
b
...
)
}
hashCode
:=
crc32
.
ChecksumIEEE
(
bs
)
selector
,
ok
:=
selectors
[
key
]
if
!
ok
||
selector
.
hashCode
!=
hashCode
{
selectors
[
key
]
=
N
ewConsistentHashSelector
(
invokers
,
methodName
,
hashCode
)
selectors
[
key
]
=
n
ewConsistentHashSelector
(
invokers
,
methodName
,
hashCode
)
selector
=
selectors
[
key
]
}
return
selector
.
Select
(
invocation
)
...
...
@@ -97,11 +101,8 @@ type ConsistentHashSelector struct {
argumentIndex
[]
int
}
func
N
ewConsistentHashSelector
(
invokers
[]
protocol
.
Invoker
,
methodName
string
,
func
n
ewConsistentHashSelector
(
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
)
...
...
@@ -112,7 +113,7 @@ func NewConsistentHashSelector(invokers []protocol.Invoker, methodName string,
for
_
,
index
:=
range
indices
{
i
,
err
:=
strconv
.
Atoi
(
index
)
if
err
!=
nil
{
panic
(
err
)
return
nil
}
selector
.
argumentIndex
=
append
(
selector
.
argumentIndex
,
i
)
}
...
...
This diff is collapsed.
Click to expand it.
cluster/loadbalance/consistent_hash_test.go
+
6
−
2
View file @
80e5bf59
...
...
@@ -20,9 +20,13 @@ package loadbalance
import
(
"context"
"testing"
)
import
(
"github.com/stretchr/testify/suite"
)
import
(
"github.com/apache/dubbo-go/cluster"
"github.com/apache/dubbo-go/common"
"github.com/apache/dubbo-go/protocol"
...
...
@@ -43,7 +47,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
=
N
ewConsistentHashSelector
(
invokers
,
"echo"
,
999944
)
s
.
selector
=
n
ewConsistentHashSelector
(
invokers
,
"echo"
,
999944
)
}
func
(
s
*
consistentHashSelectorSuite
)
TestToKey
()
{
...
...
@@ -92,7 +96,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
=
NewConsistentHash
LoadBalance
()
}
func
(
s
*
consistentHashLoadBalanceSuite
)
TestSelect
()
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment