Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
milvus
milvus
提交
c6950eb7
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,发现更多精彩内容 >>
提交
c6950eb7
编写于
4月 01, 2021
作者:
Z
zhenshan.cao
提交者:
yefu.chen
4月 01, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add log for allocator
Signed-off-by:
N
zhenshan.cao
<
zhenshan.cao@zilliz.com
>
上级
a532444d
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
94 addition
and
35 deletion
+94
-35
internal/allocator/allocator.go
internal/allocator/allocator.go
+27
-8
internal/allocator/id.go
internal/allocator/id.go
+32
-12
internal/allocator/timestamp.go
internal/allocator/timestamp.go
+30
-10
internal/proxynode/segment.go
internal/proxynode/segment.go
+5
-5
未找到文件。
internal/allocator/allocator.go
浏览文件 @
c6950eb7
...
...
@@ -2,10 +2,13 @@ package allocator
import
(
"context"
"errors"
"fmt"
"sync"
"time"
"errors"
"github.com/zilliztech/milvus-distributed/internal/log"
"go.uber.org/zap"
)
const
(
...
...
@@ -106,11 +109,13 @@ type Allocator struct {
TChan
TickerChan
ForceSyncChan
chan
Request
SyncFunc
func
()
bool
SyncFunc
func
()
(
bool
,
error
)
ProcessFunc
func
(
req
Request
)
error
CheckSyncFunc
func
(
timeout
bool
)
bool
PickCanDoFunc
func
()
SyncErr
error
Role
string
}
func
(
ta
*
Allocator
)
Start
()
error
{
...
...
@@ -183,7 +188,7 @@ func (ta *Allocator) pickCanDo() {
func
(
ta
*
Allocator
)
sync
(
timeout
bool
)
bool
{
if
ta
.
SyncFunc
==
nil
||
ta
.
CheckSyncFunc
==
nil
{
ta
.
CanDoReqs
=
ta
.
ToDoReqs
ta
.
ToDoReqs
=
ta
.
ToDoReqs
[
0
:
0
]
ta
.
ToDoReqs
=
nil
return
true
}
if
!
timeout
&&
len
(
ta
.
ToDoReqs
)
==
0
{
...
...
@@ -193,7 +198,8 @@ func (ta *Allocator) sync(timeout bool) bool {
return
false
}
ret
:=
ta
.
SyncFunc
()
var
ret
bool
ret
,
ta
.
SyncErr
=
ta
.
SyncFunc
()
if
!
timeout
{
ta
.
TChan
.
Reset
()
...
...
@@ -207,16 +213,28 @@ func (ta *Allocator) finishSyncRequest() {
req
.
Notify
(
nil
)
}
}
ta
.
SyncReqs
=
ta
.
SyncReqs
[
0
:
0
]
ta
.
SyncReqs
=
nil
}
func
(
ta
*
Allocator
)
failRemainRequest
()
{
var
err
error
if
ta
.
SyncErr
!=
nil
{
err
=
fmt
.
Errorf
(
"%s failRemainRequest err:%w"
,
ta
.
Role
,
ta
.
SyncErr
)
}
else
{
errMsg
:=
fmt
.
Sprintf
(
"%s failRemainRequest unexpected error"
,
ta
.
Role
)
err
=
errors
.
New
(
errMsg
)
}
if
len
(
ta
.
ToDoReqs
)
>
0
{
log
.
Debug
(
"Allocator has some reqs to fail"
,
zap
.
Any
(
"Role"
,
ta
.
Role
),
zap
.
Any
(
"reqLen"
,
len
(
ta
.
ToDoReqs
)))
}
for
_
,
req
:=
range
ta
.
ToDoReqs
{
if
req
!=
nil
{
req
.
Notify
(
err
ors
.
New
(
"failed: unexpected error"
)
)
req
.
Notify
(
err
)
}
}
ta
.
ToDoReqs
=
[]
Request
{}
ta
.
ToDoReqs
=
nil
}
func
(
ta
*
Allocator
)
finishRequest
()
{
...
...
@@ -241,7 +259,8 @@ func (ta *Allocator) Close() {
ta
.
CancelFunc
()
ta
.
wg
.
Wait
()
ta
.
TChan
.
Close
()
ta
.
revokeRequest
(
errors
.
New
(
"closing"
))
errMsg
:=
fmt
.
Sprintf
(
"%s is closing"
,
ta
.
Role
)
ta
.
revokeRequest
(
errors
.
New
(
errMsg
))
}
func
(
ta
*
Allocator
)
CleanCache
()
{
...
...
internal/allocator/id.go
浏览文件 @
c6950eb7
...
...
@@ -2,14 +2,16 @@ package allocator
import
(
"context"
"
log
"
"
fmt
"
"time"
"g
ithub.com/zilliztech/milvus-distributed/internal/util/retry
"
"g
o.uber.org/zap
"
"google.golang.org/grpc"
"github.com/zilliztech/milvus-distributed/internal/log"
"github.com/zilliztech/milvus-distributed/internal/proto/commonpb"
"github.com/zilliztech/milvus-distributed/internal/proto/masterpb"
"github.com/zilliztech/milvus-distributed/internal/util/retry"
"github.com/zilliztech/milvus-distributed/internal/util/typeutil"
)
...
...
@@ -41,6 +43,7 @@ func NewIDAllocator(ctx context.Context, masterAddr string) (*IDAllocator, error
Allocator
:
Allocator
{
Ctx
:
ctx1
,
CancelFunc
:
cancel
,
Role
:
"IDAllocator"
,
},
countPerRPC
:
IDCountPerRPC
,
masterAddress
:
masterAddr
,
...
...
@@ -58,12 +61,11 @@ func (ia *IDAllocator) Start() error {
connectMasterFn
:=
func
()
error
{
return
ia
.
connectMaster
()
}
err
:=
retry
.
Retry
(
10
,
time
.
Millisecond
*
200
,
connectMasterFn
)
err
:=
retry
.
Retry
(
10
00
,
time
.
Millisecond
*
200
,
connectMasterFn
)
if
err
!=
nil
{
panic
(
"connect to master failed"
)
}
ia
.
Allocator
.
Start
()
return
nil
return
ia
.
Allocator
.
Start
()
}
func
(
ia
*
IDAllocator
)
connectMaster
()
error
{
...
...
@@ -71,16 +73,31 @@ func (ia *IDAllocator) connectMaster() error {
defer
cancel
()
conn
,
err
:=
grpc
.
DialContext
(
ctx
,
ia
.
masterAddress
,
grpc
.
WithInsecure
(),
grpc
.
WithBlock
())
if
err
!=
nil
{
log
.
Printf
(
"Connect to master failed, error= %v"
,
err
)
log
.
Error
(
"Connect to master failed"
,
zap
.
Any
(
"Role"
,
ia
.
Role
),
zap
.
Error
(
err
)
)
return
err
}
log
.
Printf
(
"Connected to master, master_addr=%s"
,
ia
.
masterAddress
)
log
.
Debug
(
"Connected to master"
,
zap
.
Any
(
"Role"
,
ia
.
Role
),
zap
.
Any
(
"masterAddress"
,
ia
.
masterAddress
)
)
ia
.
masterConn
=
conn
ia
.
masterClient
=
masterpb
.
NewMasterServiceClient
(
conn
)
return
nil
}
func
(
ia
*
IDAllocator
)
syncID
()
bool
{
func
(
ia
*
IDAllocator
)
gatherReqIDCount
()
uint32
{
need
:=
uint32
(
0
)
for
_
,
req
:=
range
ia
.
ToDoReqs
{
tReq
:=
req
.
(
*
IDRequest
)
need
+=
tReq
.
count
}
return
need
}
func
(
ia
*
IDAllocator
)
syncID
()
(
bool
,
error
)
{
need
:=
ia
.
gatherReqIDCount
()
if
need
<
ia
.
countPerRPC
{
need
=
ia
.
countPerRPC
}
ctx
,
cancel
:=
context
.
WithTimeout
(
context
.
Background
(),
5
*
time
.
Second
)
req
:=
&
masterpb
.
AllocIDRequest
{
Base
:
&
commonpb
.
MsgBase
{
...
...
@@ -89,18 +106,17 @@ func (ia *IDAllocator) syncID() bool {
Timestamp
:
0
,
SourceID
:
ia
.
PeerID
,
},
Count
:
ia
.
countPerRPC
,
Count
:
need
,
}
resp
,
err
:=
ia
.
masterClient
.
AllocID
(
ctx
,
req
)
cancel
()
if
err
!=
nil
{
log
.
Println
(
"syncID Failed!!!!!"
)
return
false
return
false
,
fmt
.
Errorf
(
"syncID Failed:%w"
,
err
)
}
ia
.
idStart
=
resp
.
GetID
()
ia
.
idEnd
=
ia
.
idStart
+
int64
(
resp
.
GetCount
())
return
true
return
true
,
nil
}
func
(
ia
*
IDAllocator
)
checkSyncFunc
(
timeout
bool
)
bool
{
...
...
@@ -122,6 +138,10 @@ func (ia *IDAllocator) pickCanDoFunc() {
}
}
ia
.
ToDoReqs
=
ia
.
ToDoReqs
[
idx
:
]
log
.
Debug
(
"IDAllocator pickCanDoFunc"
,
zap
.
Any
(
"need"
,
need
),
zap
.
Any
(
"total"
,
total
),
zap
.
Any
(
"remainReqCnt"
,
len
(
ia
.
ToDoReqs
)))
}
func
(
ia
*
IDAllocator
)
processFunc
(
req
Request
)
error
{
...
...
internal/allocator/timestamp.go
浏览文件 @
c6950eb7
...
...
@@ -3,9 +3,11 @@ package allocator
import
(
"context"
"fmt"
"log"
"time"
"go.uber.org/zap"
"github.com/zilliztech/milvus-distributed/internal/log"
"github.com/zilliztech/milvus-distributed/internal/proto/commonpb"
"github.com/zilliztech/milvus-distributed/internal/proto/masterpb"
"github.com/zilliztech/milvus-distributed/internal/util/retry"
...
...
@@ -38,6 +40,7 @@ func NewTimestampAllocator(ctx context.Context, masterAddr string) (*TimestampAl
Allocator
:
Allocator
{
Ctx
:
ctx1
,
CancelFunc
:
cancel
,
Role
:
"TimestampAllocator"
,
},
masterAddress
:
masterAddr
,
countPerRPC
:
tsCountPerRPC
,
...
...
@@ -57,7 +60,7 @@ func (ta *TimestampAllocator) Start() error {
connectMasterFn
:=
func
()
error
{
return
ta
.
connectMaster
()
}
err
:=
retry
.
Retry
(
10
,
time
.
Millisecond
*
200
,
connectMasterFn
)
err
:=
retry
.
Retry
(
10
00
,
time
.
Millisecond
*
200
,
connectMasterFn
)
if
err
!=
nil
{
panic
(
"Timestamp local allocator connect to master failed"
)
}
...
...
@@ -70,10 +73,10 @@ func (ta *TimestampAllocator) connectMaster() error {
defer
cancel
()
conn
,
err
:=
grpc
.
DialContext
(
ctx
,
ta
.
masterAddress
,
grpc
.
WithInsecure
(),
grpc
.
WithBlock
())
if
err
!=
nil
{
log
.
Printf
(
"Connect to master failed, error= %v"
,
err
)
log
.
Error
(
"TimestampAllocator Connect to master failed"
,
zap
.
Error
(
err
)
)
return
err
}
log
.
Printf
(
"Connected to master, master_addr=%s"
,
ta
.
masterAddress
)
log
.
Debug
(
"TimestampAllocator connected to master"
,
zap
.
Any
(
"masterAddress"
,
ta
.
masterAddress
)
)
ta
.
masterConn
=
conn
ta
.
masterClient
=
masterpb
.
NewMasterServiceClient
(
conn
)
return
nil
...
...
@@ -98,9 +101,26 @@ func (ta *TimestampAllocator) pickCanDoFunc() {
}
}
ta
.
ToDoReqs
=
ta
.
ToDoReqs
[
idx
:
]
log
.
Debug
(
"TimestampAllocator pickCanDoFunc"
,
zap
.
Any
(
"need"
,
need
),
zap
.
Any
(
"total"
,
total
),
zap
.
Any
(
"remainReqCnt"
,
len
(
ta
.
ToDoReqs
)))
}
func
(
ta
*
TimestampAllocator
)
syncTs
()
bool
{
func
(
ta
*
TimestampAllocator
)
gatherReqTsCount
()
uint32
{
need
:=
uint32
(
0
)
for
_
,
req
:=
range
ta
.
ToDoReqs
{
tReq
:=
req
.
(
*
TSORequest
)
need
+=
tReq
.
count
}
return
need
}
func
(
ta
*
TimestampAllocator
)
syncTs
()
(
bool
,
error
)
{
need
:=
ta
.
gatherReqTsCount
()
if
need
<
ta
.
countPerRPC
{
need
=
ta
.
countPerRPC
}
ctx
,
cancel
:=
context
.
WithTimeout
(
context
.
Background
(),
5
*
time
.
Second
)
req
:=
&
masterpb
.
AllocTimestampRequest
{
Base
:
&
commonpb
.
MsgBase
{
...
...
@@ -109,18 +129,18 @@ func (ta *TimestampAllocator) syncTs() bool {
Timestamp
:
0
,
SourceID
:
ta
.
PeerID
,
},
Count
:
ta
.
countPerRPC
,
Count
:
need
,
}
resp
,
err
:=
ta
.
masterClient
.
AllocTimestamp
(
ctx
,
req
)
defer
cancel
()
cancel
()
if
err
!=
nil
{
log
.
Println
(
"syncTimestamp Failed!!!!!"
)
return
false
return
false
,
fmt
.
Errorf
(
"syncTimestamp Failed:%w"
,
err
)
}
ta
.
lastTsBegin
=
resp
.
GetTimestamp
()
ta
.
lastTsEnd
=
ta
.
lastTsBegin
+
uint64
(
resp
.
GetCount
())
return
true
return
true
,
nil
}
func
(
ta
*
TimestampAllocator
)
processFunc
(
req
Request
)
error
{
...
...
internal/proxynode/segment.go
浏览文件 @
c6950eb7
...
...
@@ -138,6 +138,7 @@ func NewSegIDAssigner(ctx context.Context, dataService types.DataService, getTic
Allocator
:
Allocator
{
Ctx
:
ctx1
,
CancelFunc
:
cancel
,
Role
:
"SegmentIDAllocator"
,
},
countPerRPC
:
SegCountPerRPC
,
dataService
:
dataService
,
...
...
@@ -275,9 +276,9 @@ func (sa *SegIDAssigner) reduceSegReqs() {
sa
.
segReqs
=
newSegReqs
}
func
(
sa
*
SegIDAssigner
)
syncSegments
()
bool
{
func
(
sa
*
SegIDAssigner
)
syncSegments
()
(
bool
,
error
)
{
if
len
(
sa
.
segReqs
)
==
0
{
return
true
return
true
,
nil
}
sa
.
reduceSegReqs
()
ctx
,
cancel
:=
context
.
WithTimeout
(
context
.
Background
(),
5
*
time
.
Second
)
...
...
@@ -292,8 +293,7 @@ func (sa *SegIDAssigner) syncSegments() bool {
resp
,
err
:=
sa
.
dataService
.
AssignSegmentID
(
ctx
,
req
)
if
err
!=
nil
{
log
.
Debug
(
"proxynode"
,
zap
.
String
(
"GRPC AssignSegmentID Failed"
,
err
.
Error
()))
return
false
return
false
,
fmt
.
Errorf
(
"syncSegmentID Failed:%w"
,
err
)
}
now
:=
time
.
Now
()
...
...
@@ -331,7 +331,7 @@ func (sa *SegIDAssigner) syncSegments() bool {
assign
.
lastInsertTime
=
now
success
=
true
}
return
success
return
success
,
nil
}
func
(
sa
*
SegIDAssigner
)
processFunc
(
req
allocator
.
Request
)
error
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录