Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
milvus
milvus
提交
69cc68ca
M
milvus
项目概览
milvus
/
milvus
大约 1 年 前同步成功
通知
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,发现更多精彩内容 >>
未验证
提交
69cc68ca
编写于
3月 16, 2023
作者:
W
wei liu
提交者:
GitHub
3月 16, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
support first or random strategy (#22766)
Signed-off-by:
N
Wei Liu
<
wei.liu@zilliz.com
>
上级
80c6adb3
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
54 addition
and
3 deletion
+54
-3
internal/proxy/meta_cache.go
internal/proxy/meta_cache.go
+14
-3
internal/proxy/meta_cache_test.go
internal/proxy/meta_cache_test.go
+40
-0
未找到文件。
internal/proxy/meta_cache.go
浏览文件 @
69cc68ca
...
...
@@ -19,6 +19,7 @@ package proxy
import
(
"context"
"fmt"
"math/rand"
"strconv"
"sync"
"time"
...
...
@@ -123,12 +124,22 @@ type shardLeadersReader struct {
// Shuffle returns the shuffled shard leader list.
func
(
it
shardLeadersReader
)
Shuffle
()
map
[
string
][]
nodeInfo
{
result
:=
make
(
map
[
string
][]
nodeInfo
)
rand
.
Seed
(
time
.
Now
()
.
UnixNano
())
for
channel
,
leaders
:=
range
it
.
leaders
.
shardLeaders
{
l
:=
len
(
leaders
)
shuffled
:=
make
([]
nodeInfo
,
0
,
len
(
leaders
))
for
i
:=
0
;
i
<
l
;
i
++
{
shuffled
=
append
(
shuffled
,
leaders
[(
i
+
int
(
it
.
idx
))
%
l
])
// shuffle all replica at random order
shuffled
:=
make
([]
nodeInfo
,
l
)
for
i
,
randIndex
:=
range
rand
.
Perm
(
l
)
{
shuffled
[
i
]
=
leaders
[
randIndex
]
}
// make each copy has same probability to be first replica
for
index
,
leader
:=
range
shuffled
{
if
leader
==
leaders
[
int
(
it
.
idx
)
%
l
]
{
shuffled
[
0
],
shuffled
[
index
]
=
shuffled
[
index
],
shuffled
[
0
]
}
}
result
[
channel
]
=
shuffled
}
return
result
...
...
internal/proxy/meta_cache_test.go
浏览文件 @
69cc68ca
...
...
@@ -25,6 +25,7 @@ import (
"time"
"github.com/cockroachdb/errors"
uatomic
"go.uber.org/atomic"
"github.com/milvus-io/milvus/internal/util/funcutil"
"github.com/milvus-io/milvus/internal/util/paramtable"
...
...
@@ -880,3 +881,42 @@ func TestMetaCache_ExpireShardLeaderCache(t *testing.T) {
return
len
(
nodeInfos
[
"channel-1"
])
==
3
&&
len
(
nodeInfos
[
"channel-2"
])
==
3
},
3
*
time
.
Second
,
1
*
time
.
Second
)
}
func
TestGlobalMetaCache_ShuffleShardLeaders
(
t
*
testing
.
T
)
{
shards
:=
map
[
string
][]
nodeInfo
{
"channel-1"
:
{
{
nodeID
:
1
,
address
:
"localhost:9000"
,
},
{
nodeID
:
2
,
address
:
"localhost:9000"
,
},
{
nodeID
:
3
,
address
:
"localhost:9000"
,
},
},
}
sl
:=
&
shardLeaders
{
deprecated
:
uatomic
.
NewBool
(
false
),
idx
:
uatomic
.
NewInt64
(
5
),
shardLeaders
:
shards
,
}
reader
:=
sl
.
GetReader
()
result
:=
reader
.
Shuffle
()
assert
.
Len
(
t
,
result
[
"channel-1"
],
3
)
assert
.
Equal
(
t
,
int64
(
1
),
result
[
"channel-1"
][
0
]
.
nodeID
)
reader
=
sl
.
GetReader
()
result
=
reader
.
Shuffle
()
assert
.
Len
(
t
,
result
[
"channel-1"
],
3
)
assert
.
Equal
(
t
,
int64
(
2
),
result
[
"channel-1"
][
0
]
.
nodeID
)
reader
=
sl
.
GetReader
()
result
=
reader
.
Shuffle
()
assert
.
Len
(
t
,
result
[
"channel-1"
],
3
)
assert
.
Equal
(
t
,
int64
(
3
),
result
[
"channel-1"
][
0
]
.
nodeID
)
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录