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
404cf384
Commit
404cf384
authored
4 years ago
by
aliiohs
Browse files
Options
Downloads
Patches
Plain Diff
add the comment of ConsistentHash
parent
fbba79fd
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
cluster/loadbalance/consistent_hash.go
+9
-6
9 additions, 6 deletions
cluster/loadbalance/consistent_hash.go
with
9 additions
and
6 deletions
cluster/loadbalance/consistent_hash.go
+
9
−
6
View file @
404cf384
...
...
@@ -53,16 +53,16 @@ func init() {
extension
.
SetLoadbalance
(
ConsistentHash
,
NewConsistentHashLoadBalance
)
}
// ConsistentHashLoadBalance
...
// ConsistentHashLoadBalance
Implementation of load balancing: using consistent hashing
type
ConsistentHashLoadBalance
struct
{
}
// NewConsistentHashLoadBalance
...
// NewConsistentHashLoadBalance
create NewConsistentHashLoadBalance
func
NewConsistentHashLoadBalance
()
cluster
.
LoadBalance
{
return
&
ConsistentHashLoadBalance
{}
}
// Select
...
// Select
Get invoker based on load balancing strategy
func
(
lb
*
ConsistentHashLoadBalance
)
Select
(
invokers
[]
protocol
.
Invoker
,
invocation
protocol
.
Invocation
)
protocol
.
Invoker
{
methodName
:=
invocation
.
MethodName
()
key
:=
invokers
[
0
]
.
GetUrl
()
.
ServiceKey
()
+
"."
+
methodName
...
...
@@ -85,22 +85,25 @@ func (lb *ConsistentHashLoadBalance) Select(invokers []protocol.Invoker, invocat
return
selector
.
Select
(
invocation
)
}
// Uint32Slice
...
// Uint32Slice
Slice of uint32
type
Uint32Slice
[]
uint32
// Len Get slice length
func
(
s
Uint32Slice
)
Len
()
int
{
return
len
(
s
)
}
// Less reports whether the element with index i should sort before the element with index j.
func
(
s
Uint32Slice
)
Less
(
i
,
j
int
)
bool
{
return
s
[
i
]
<
s
[
j
]
}
// Swap swaps the elements with indexes i and j.
func
(
s
Uint32Slice
)
Swap
(
i
,
j
int
)
{
s
[
i
],
s
[
j
]
=
s
[
j
],
s
[
i
]
}
// ConsistentHashSelector
...
// ConsistentHashSelector
Implementation of Selector:get invoker based on load balancing strategy
type
ConsistentHashSelector
struct
{
hashCode
uint32
replicaNum
int
...
...
@@ -141,7 +144,7 @@ func newConsistentHashSelector(invokers []protocol.Invoker, methodName string,
return
selector
}
// Select
...
// Select
Get invoker based on load balancing strategy
func
(
c
*
ConsistentHashSelector
)
Select
(
invocation
protocol
.
Invocation
)
protocol
.
Invoker
{
key
:=
c
.
toKey
(
invocation
.
Arguments
())
digest
:=
md5
.
Sum
([]
byte
(
key
))
...
...
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