Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
milvus
milvus
提交
2514e8b8
M
milvus
项目概览
milvus
/
milvus
11 个月 前同步成功
通知
260
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,体验更适合开发者的 AI 搜索 >>
提交
2514e8b8
编写于
11月 20, 2020
作者:
N
neza2017
提交者:
yefu.chen
11月 20, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Optimize code in Master module
Signed-off-by:
N
neza2017
<
yefu.chen@zilliz.com
>
上级
dfe395e1
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
28 addition
and
63 deletion
+28
-63
internal/master/timesync.go
internal/master/timesync.go
+28
-63
未找到文件。
internal/master/timesync.go
浏览文件 @
2514e8b8
...
...
@@ -4,6 +4,7 @@ import (
"context"
"log"
"math"
"sync/atomic"
"github.com/zilliztech/milvus-distributed/internal/errors"
ms
"github.com/zilliztech/milvus-distributed/internal/msgstream"
...
...
@@ -19,12 +20,11 @@ type (
softTimeTickBarrier
struct
{
peer2LastTt
map
[
UniqueID
]
Timestamp
minTtInterval
Timestamp
lastTt
Timestamp
lastTt
int64
outTt
chan
Timestamp
ttStream
ms
.
MsgStream
ctx
context
.
Context
closeCh
chan
struct
{}
// close goroutinue in Start()
closed
bool
cancel
context
.
CancelFunc
}
hardTimeTickBarrier
struct
{
...
...
@@ -32,46 +32,36 @@ type (
outTt
chan
Timestamp
ttStream
ms
.
MsgStream
ctx
context
.
Context
closeCh
chan
struct
{}
// close goroutinue in Start()
closed
bool
cancel
context
.
CancelFunc
}
)
func
(
ttBarrier
*
softTimeTickBarrier
)
GetTimeTick
()
(
Timestamp
,
error
)
{
isEmpty
:=
true
for
{
if
ttBarrier
.
closed
{
select
{
case
<-
ttBarrier
.
ctx
.
Done
()
:
return
0
,
errors
.
Errorf
(
"[GetTimeTick] closed."
)
case
ts
,
ok
:=
<-
ttBarrier
.
outTt
:
if
!
ok
{
return
0
,
errors
.
Errorf
(
"[GetTimeTick] closed."
)
}
select
{
case
ts
:=
<-
ttBarrier
.
outTt
:
isEmpty
=
false
ttBarrier
.
lastTt
=
ts
default
:
if
isEmpty
||
ttBarrier
.
closed
{
continue
num
:=
len
(
ttBarrier
.
outTt
)
for
i
:=
0
;
i
<
num
;
i
++
{
ts
,
ok
=
<-
ttBarrier
.
outTt
if
!
ok
{
return
0
,
errors
.
Errorf
(
"[GetTimeTick] closed."
)
}
return
ttBarrier
.
lastTt
,
nil
}
atomic
.
StoreInt64
(
&
(
ttBarrier
.
lastTt
),
int64
(
ts
))
return
ts
,
nil
}
}
func
(
ttBarrier
*
softTimeTickBarrier
)
Start
()
error
{
ttBarrier
.
closeCh
=
make
(
chan
struct
{},
1
)
go
func
()
{
for
{
select
{
case
<-
ttBarrier
.
closeCh
:
log
.
Printf
(
"[TtBarrierStart] closed
\n
"
)
return
case
<-
ttBarrier
.
ctx
.
Done
()
:
log
.
Printf
(
"[TtBarrierStart] %s
\n
"
,
ttBarrier
.
ctx
.
Err
())
ttBarrier
.
closed
=
true
return
case
ttmsgs
:=
<-
ttBarrier
.
ttStream
.
Chan
()
:
...
...
@@ -91,8 +81,8 @@ func (ttBarrier *softTimeTickBarrier) Start() error {
// get a legal Timestamp
ts
:=
ttBarrier
.
minTimestamp
()
if
ttBarrier
.
lastTt
!=
0
&&
ttBarrier
.
minTtInterval
>
ts
-
ttBarrier
.
lastTt
{
lastTt
:=
atomic
.
LoadInt64
(
&
(
ttBarrier
.
lastTt
))
if
ttBarrier
.
lastTt
!=
0
&&
ttBarrier
.
minTtInterval
>
ts
-
Timestamp
(
lastTt
)
{
continue
}
...
...
@@ -100,8 +90,6 @@ func (ttBarrier *softTimeTickBarrier) Start() error {
}
}
}
default
:
}
}
}()
...
...
@@ -122,9 +110,7 @@ func newSoftTimeTickBarrier(ctx context.Context,
sttbarrier
.
minTtInterval
=
minTtInterval
sttbarrier
.
ttStream
=
*
ttStream
sttbarrier
.
outTt
=
make
(
chan
Timestamp
,
1024
)
sttbarrier
.
ctx
=
ctx
sttbarrier
.
closed
=
false
sttbarrier
.
ctx
,
sttbarrier
.
cancel
=
context
.
WithCancel
(
ctx
)
sttbarrier
.
peer2LastTt
=
make
(
map
[
UniqueID
]
Timestamp
)
for
_
,
id
:=
range
peerIds
{
sttbarrier
.
peer2LastTt
[
id
]
=
Timestamp
(
0
)
...
...
@@ -137,12 +123,7 @@ func newSoftTimeTickBarrier(ctx context.Context,
}
func
(
ttBarrier
*
softTimeTickBarrier
)
Close
()
{
if
ttBarrier
.
closeCh
!=
nil
{
ttBarrier
.
closeCh
<-
struct
{}{}
}
ttBarrier
.
closed
=
true
ttBarrier
.
cancel
()
}
func
(
ttBarrier
*
softTimeTickBarrier
)
minTimestamp
()
Timestamp
{
...
...
@@ -156,36 +137,25 @@ func (ttBarrier *softTimeTickBarrier) minTimestamp() Timestamp {
}
func
(
ttBarrier
*
hardTimeTickBarrier
)
GetTimeTick
()
(
Timestamp
,
error
)
{
for
{
if
ttBarrier
.
closed
{
select
{
case
<-
ttBarrier
.
ctx
.
Done
()
:
return
0
,
errors
.
Errorf
(
"[GetTimeTick] closed."
)
case
ts
,
ok
:=
<-
ttBarrier
.
outTt
:
if
!
ok
{
return
0
,
errors
.
Errorf
(
"[GetTimeTick] closed."
)
}
select
{
case
ts
:=
<-
ttBarrier
.
outTt
:
return
ts
,
nil
default
:
}
}
}
func
(
ttBarrier
*
hardTimeTickBarrier
)
Start
()
error
{
ttBarrier
.
closeCh
=
make
(
chan
struct
{},
1
)
go
func
()
{
// Last timestamp synchronized
state
:=
Timestamp
(
0
)
for
{
select
{
case
<-
ttBarrier
.
closeCh
:
log
.
Printf
(
"[TtBarrierStart] closed
\n
"
)
return
case
<-
ttBarrier
.
ctx
.
Done
()
:
log
.
Printf
(
"[TtBarrierStart] %s
\n
"
,
ttBarrier
.
ctx
.
Err
())
ttBarrier
.
closed
=
true
return
case
ttmsgs
:=
<-
ttBarrier
.
ttStream
.
Chan
()
:
...
...
@@ -217,7 +187,6 @@ func (ttBarrier *hardTimeTickBarrier) Start() error {
}
}
}
default
:
}
}
}()
...
...
@@ -246,8 +215,7 @@ func newHardTimeTickBarrier(ctx context.Context,
sttbarrier
:=
hardTimeTickBarrier
{}
sttbarrier
.
ttStream
=
*
ttStream
sttbarrier
.
outTt
=
make
(
chan
Timestamp
,
1024
)
sttbarrier
.
ctx
=
ctx
sttbarrier
.
closed
=
false
sttbarrier
.
ctx
,
sttbarrier
.
cancel
=
context
.
WithCancel
(
ctx
)
sttbarrier
.
peer2Tt
=
make
(
map
[
UniqueID
]
Timestamp
)
for
_
,
id
:=
range
peerIds
{
...
...
@@ -261,8 +229,5 @@ func newHardTimeTickBarrier(ctx context.Context,
}
func
(
ttBarrier
*
hardTimeTickBarrier
)
Close
()
{
if
ttBarrier
.
closeCh
!=
nil
{
ttBarrier
.
closeCh
<-
struct
{}{}
}
ttBarrier
.
closed
=
true
ttBarrier
.
cancel
()
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录