Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
2
210310676
Manage
Activity
Members
Labels
Plan
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package Registry
Operate
Terraform modules
Analyze
Value stream analytics
Contributor 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
Summer2021
210310676
Commits
a2dd1647
Commit
a2dd1647
authored
3 years ago
by
congqixia
Committed by
zhenshan.cao
3 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Implement random reassign and add test case (#5474)
Signed-off-by:
Congqi Xia
<
congqi.xia@zilliz.com
>
parent
8657251f
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
internal/dataservice/policy.go
+26
-18
26 additions, 18 deletions
internal/dataservice/policy.go
internal/dataservice/policy_test.go
+70
-0
70 additions, 0 deletions
internal/dataservice/policy_test.go
with
96 additions
and
18 deletions
internal/dataservice/policy.go
+
26
−
18
View file @
a2dd1647
...
...
@@ -84,35 +84,43 @@ type randomAssignUnregisterPolicy struct{}
func
(
p
*
randomAssignUnregisterPolicy
)
apply
(
cluster
map
[
string
]
*
datapb
.
DataNodeInfo
,
session
*
datapb
.
DataNodeInfo
)
[]
*
datapb
.
DataNodeInfo
{
if
len
(
cluster
)
==
0
||
// no available node
session
==
nil
||
len
(
session
.
Channels
)
==
0
{
// lost node not watching any channels
return
[]
*
datapb
.
DataNodeInfo
{}
}
mChan
:=
make
(
map
[
string
]
struct
{},
len
(
session
.
Channels
))
appliedNodes
:=
make
([]
*
datapb
.
DataNodeInfo
,
0
,
len
(
session
.
Channels
))
raResult
:=
make
(
map
[
int
][]
*
datapb
.
ChannelStatus
)
for
_
,
chanSt
:=
range
session
.
Channels
{
mChan
[
chanSt
.
Name
]
=
struct
{}{}
bIdx
,
err
:=
rand
.
Int
(
rand
.
Reader
,
big
.
NewInt
(
int64
(
len
(
cluster
))))
if
err
!=
nil
{
log
.
Error
(
"error generated rand idx"
,
zap
.
Error
(
err
))
return
[]
*
datapb
.
DataNodeInfo
{}
}
idx
:=
bIdx
.
Int64
()
if
int
(
idx
)
>=
len
(
cluster
)
{
continue
}
cs
,
ok
:=
raResult
[
int
(
idx
)]
if
!
ok
{
cs
=
make
([]
*
datapb
.
ChannelStatus
,
0
,
10
)
}
chanSt
.
State
=
datapb
.
ChannelWatchState_Uncomplete
cs
=
append
(
cs
,
chanSt
)
raResult
[
int
(
idx
)]
=
cs
}
bIdx
,
err
:=
rand
.
Int
(
rand
.
Reader
,
big
.
NewInt
(
int64
(
len
(
cluster
))))
if
err
!=
nil
{
log
.
Error
(
"error generated rand idx"
,
zap
.
Error
(
err
))
return
[]
*
datapb
.
DataNodeInfo
{}
}
idx
:=
bIdx
.
Int64
()
if
int
(
idx
)
>=
len
(
cluster
)
{
return
[]
*
datapb
.
DataNodeInfo
{}
}
i
:=
0
for
_
,
node
:=
range
cluster
{
if
i
==
int
(
idx
)
{
//TODO add channel to node
return
[]
*
datapb
.
DataNodeInfo
{
node
,
}
}
cs
,
ok
:=
raResult
[
i
]
i
++
if
ok
{
node
.
Channels
=
append
(
node
.
Channels
,
cs
...
)
appliedNodes
=
append
(
appliedNodes
,
node
)
}
}
return
[]
*
datapb
.
DataNodeInfo
{}
return
appliedNodes
}
type
channelAssignPolicy
interface
{
...
...
This diff is collapsed.
Click to expand it.
internal/dataservice/policy_test.go
+
70
−
0
View file @
a2dd1647
// Copyright (C) 2019-2020 Zilliz. All rights reserved.
//
// Licensed 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
dataservice
import
(
...
...
@@ -44,3 +55,62 @@ func TestWatchRestartsPolicy(t *testing.T) {
assert
.
EqualValues
(
t
,
1
,
len
(
nodes
))
assert
.
EqualValues
(
t
,
datapb
.
ChannelWatchState_Uncomplete
,
nodes
[
0
]
.
Channels
[
0
]
.
State
)
}
func
TestRandomReassign
(
t
*
testing
.
T
)
{
p
:=
randomAssignUnregisterPolicy
{}
clusters
:=
make
(
map
[
string
]
*
datapb
.
DataNodeInfo
)
clusters
[
"addr1"
]
=
&
datapb
.
DataNodeInfo
{
Address
:
"addr1"
,
Channels
:
make
([]
*
datapb
.
ChannelStatus
,
0
,
10
),
}
clusters
[
"addr2"
]
=
&
datapb
.
DataNodeInfo
{
Address
:
"addr2"
,
Channels
:
make
([]
*
datapb
.
ChannelStatus
,
0
,
10
),
}
clusters
[
"addr3"
]
=
&
datapb
.
DataNodeInfo
{
Address
:
"addr3"
,
Channels
:
make
([]
*
datapb
.
ChannelStatus
,
0
,
10
),
}
cases
:=
[]
*
datapb
.
DataNodeInfo
{
{
Channels
:
[]
*
datapb
.
ChannelStatus
{},
},
{
Channels
:
[]
*
datapb
.
ChannelStatus
{
{
Name
:
"VChan1"
,
CollectionID
:
1
},
{
Name
:
"VChan2"
,
CollectionID
:
2
},
},
},
{
Channels
:
[]
*
datapb
.
ChannelStatus
{
{
Name
:
"VChan3"
,
CollectionID
:
1
},
{
Name
:
"VChan4"
,
CollectionID
:
2
},
},
},
nil
,
}
for
_
,
ca
:=
range
cases
{
nodes
:=
p
.
apply
(
clusters
,
ca
)
if
ca
==
nil
||
len
(
ca
.
Channels
)
==
0
{
assert
.
Equal
(
t
,
0
,
len
(
nodes
))
}
else
{
for
_
,
ch
:=
range
ca
.
Channels
{
found
:=
false
loop
:
for
_
,
node
:=
range
nodes
{
for
_
,
nch
:=
range
node
.
Channels
{
if
nch
.
Name
==
ch
.
Name
{
found
=
true
assert
.
EqualValues
(
t
,
datapb
.
ChannelWatchState_Uncomplete
,
nch
.
State
)
break
loop
}
}
}
assert
.
Equal
(
t
,
true
,
found
)
}
}
}
}
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