Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
milvus
milvus
提交
7da870f5
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,发现更多精彩内容 >>
未验证
提交
7da870f5
编写于
4月 03, 2023
作者:
Y
yah01
提交者:
GitHub
4月 03, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Remove useCustomConfig and simpilify the session type (#23166)
Signed-off-by:
N
yah01
<
yang.cen@zilliz.com
>
上级
17d3190f
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
16 addition
and
28 deletion
+16
-28
cmd/tools/migration/migration/runner.go
cmd/tools/migration/migration/runner.go
+7
-2
internal/util/sessionutil/session_util.go
internal/util/sessionutil/session_util.go
+8
-24
internal/util/sessionutil/session_util_test.go
internal/util/sessionutil/session_util_test.go
+1
-2
未找到文件。
cmd/tools/migration/migration/runner.go
浏览文件 @
7da870f5
...
...
@@ -88,8 +88,13 @@ func (r *Runner) initEtcdCli() {
func
(
r
*
Runner
)
init
()
{
r
.
initEtcdCli
()
r
.
session
=
sessionutil
.
NewSession
(
r
.
ctx
,
r
.
cfg
.
EtcdCfg
.
MetaRootPath
.
GetValue
(),
r
.
etcdCli
,
sessionutil
.
WithCustomConfigEnable
(),
sessionutil
.
WithTTL
(
60
),
sessionutil
.
WithRetryTimes
(
30
))
r
.
session
=
sessionutil
.
NewSession
(
r
.
ctx
,
r
.
cfg
.
EtcdCfg
.
MetaRootPath
.
GetValue
(),
r
.
etcdCli
,
sessionutil
.
WithTTL
(
60
),
sessionutil
.
WithRetryTimes
(
30
),
)
// address not important here.
address
:=
time
.
Now
()
.
String
()
r
.
address
=
address
...
...
internal/util/sessionutil/session_util.go
浏览文件 @
7da870f5
...
...
@@ -107,7 +107,6 @@ type Session struct {
enableActiveStandBy
bool
activeKey
string
useCustomConfig
bool
sessionTTL
int64
sessionRetryTimes
int64
reuseNodeID
bool
...
...
@@ -115,10 +114,6 @@ type Session struct {
type
SessionOption
func
(
session
*
Session
)
func
WithCustomConfigEnable
()
SessionOption
{
return
func
(
session
*
Session
)
{
session
.
useCustomConfig
=
true
}
}
func
WithTTL
(
ttl
int64
)
SessionOption
{
return
func
(
session
*
Session
)
{
session
.
sessionTTL
=
ttl
}
}
...
...
@@ -204,9 +199,8 @@ func NewSession(ctx context.Context, metaRoot string, client *clientv3.Client, o
Version
:
common
.
Version
,
// options
useCustomConfig
:
false
,
sessionTTL
:
60
,
sessionRetryTimes
:
30
,
sessionTTL
:
paramtable
.
Get
()
.
CommonCfg
.
SessionTTL
.
GetAsInt64
(),
sessionRetryTimes
:
paramtable
.
Get
()
.
CommonCfg
.
SessionRetryTimes
.
GetAsInt64
(),
reuseNodeID
:
true
,
}
...
...
@@ -247,14 +241,11 @@ func (s *Session) Init(serverName, address string, exclusive bool, triggerKill b
s
.
Exclusive
=
exclusive
s
.
TriggerKill
=
triggerKill
s
.
checkIDExist
()
// TO AVOID PANIC IN MIGRATION SCRIPT.
if
!
s
.
useCustomConfig
{
serverID
,
err
:=
s
.
getServerID
()
if
err
!=
nil
{
panic
(
err
)
}
s
.
ServerID
=
serverID
serverID
,
err
:=
s
.
getServerID
()
if
err
!=
nil
{
panic
(
err
)
}
s
.
ServerID
=
serverID
log
.
Info
(
"start server"
,
zap
.
String
(
"name"
,
serverName
),
zap
.
String
(
"address"
,
address
),
zap
.
Int64
(
"id"
,
s
.
ServerID
))
}
...
...
@@ -374,15 +365,8 @@ func (s *Session) registerService() (<-chan *clientv3.LeaseKeepAliveResponse, er
var
ch
<-
chan
*
clientv3
.
LeaseKeepAliveResponse
log
.
Debug
(
"service begin to register to etcd"
,
zap
.
String
(
"serverName"
,
s
.
ServerName
),
zap
.
Int64
(
"ServerID"
,
s
.
ServerID
))
ttl
:=
s
.
sessionTTL
retryTimes
:=
s
.
sessionRetryTimes
if
!
s
.
useCustomConfig
{
ttl
=
paramtable
.
Get
()
.
CommonCfg
.
SessionTTL
.
GetAsInt64
()
retryTimes
=
paramtable
.
Get
()
.
CommonCfg
.
SessionRetryTimes
.
GetAsInt64
()
}
registerFn
:=
func
()
error
{
resp
,
err
:=
s
.
etcdCli
.
Grant
(
s
.
ctx
,
ttl
)
resp
,
err
:=
s
.
etcdCli
.
Grant
(
s
.
ctx
,
s
.
sessionTTL
)
if
err
!=
nil
{
log
.
Error
(
"register service"
,
zap
.
Error
(
err
))
return
err
...
...
@@ -424,7 +408,7 @@ func (s *Session) registerService() (<-chan *clientv3.LeaseKeepAliveResponse, er
log
.
Info
(
"Service registered successfully"
,
zap
.
String
(
"ServerName"
,
s
.
ServerName
),
zap
.
Int64
(
"serverID"
,
s
.
ServerID
))
return
nil
}
err
:=
retry
.
Do
(
s
.
ctx
,
registerFn
,
retry
.
Attempts
(
uint
(
r
etryTimes
)))
err
:=
retry
.
Do
(
s
.
ctx
,
registerFn
,
retry
.
Attempts
(
uint
(
s
.
sessionR
etryTimes
)))
if
err
!=
nil
{
return
nil
,
err
}
...
...
internal/util/sessionutil/session_util_test.go
浏览文件 @
7da870f5
...
...
@@ -704,9 +704,8 @@ func TestSessionEventType_String(t *testing.T) {
func
TestSession_apply
(
t
*
testing
.
T
)
{
session
:=
&
Session
{}
opts
:=
[]
SessionOption
{
With
CustomConfigEnable
(),
With
TTL
(
100
),
WithRetryTimes
(
200
)}
opts
:=
[]
SessionOption
{
WithTTL
(
100
),
WithRetryTimes
(
200
)}
session
.
apply
(
opts
...
)
assert
.
True
(
t
,
session
.
useCustomConfig
)
assert
.
Equal
(
t
,
int64
(
100
),
session
.
sessionTTL
)
assert
.
Equal
(
t
,
int64
(
200
),
session
.
sessionRetryTimes
)
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录