Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
milvus
milvus
提交
a2dd1647
M
milvus
项目概览
milvus
/
milvus
11 个月 前同步成功
通知
261
Star
22476
Fork
2472
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
M
milvus
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
a2dd1647
编写于
5月 28, 2021
作者:
C
congqixia
提交者:
zhenshan.cao
6月 15, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Implement random reassign and add test case (#5474)
Signed-off-by:
N
Congqi Xia
<
congqi.xia@zilliz.com
>
上级
8657251f
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
96 addition
and
18 deletion
+96
-18
internal/dataservice/policy.go
internal/dataservice/policy.go
+26
-18
internal/dataservice/policy_test.go
internal/dataservice/policy_test.go
+70
-0
未找到文件。
internal/dataservice/policy.go
浏览文件 @
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
{
...
...
internal/dataservice/policy_test.go
浏览文件 @
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
)
}
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录