Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
milvus
milvus
提交
f9553970
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 搜索 >>
未验证
提交
f9553970
编写于
6月 14, 2022
作者:
C
congqixia
提交者:
GitHub
6月 14, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add BindContext function for querycoord task scheduler (#17531)
Signed-off-by:
N
Congqi Xia
<
congqi.xia@zilliz.com
>
上级
ed3a1164
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
82 addition
and
0 deletion
+82
-0
internal/querycoord/task.go
internal/querycoord/task.go
+8
-0
internal/querycoord/task_scheduler.go
internal/querycoord/task_scheduler.go
+26
-0
internal/querycoord/task_scheduler_test.go
internal/querycoord/task_scheduler_test.go
+48
-0
未找到文件。
internal/querycoord/task.go
浏览文件 @
f9553970
...
...
@@ -99,6 +99,7 @@ type task interface {
getResultInfo
()
*
commonpb
.
Status
updateTaskProcess
()
elapseSpan
()
time
.
Duration
finishContext
()
}
type
baseTask
struct
{
...
...
@@ -298,6 +299,13 @@ func (bt *baseTask) elapseSpan() time.Duration {
return
bt
.
timeRecorder
.
ElapseSpan
()
}
// finishContext calls the cancel function for the trace ctx.
func
(
bt
*
baseTask
)
finishContext
()
{
if
bt
.
cancel
!=
nil
{
bt
.
cancel
()
}
}
type
loadCollectionTask
struct
{
*
baseTask
*
querypb
.
LoadCollectionRequest
...
...
internal/querycoord/task_scheduler.go
浏览文件 @
f9553970
...
...
@@ -521,6 +521,10 @@ func (scheduler *TaskScheduler) processTask(t task) error {
t
.
postExecute
(
ctx
)
}()
// bind schedular context with task context
// cancel cannot be deferred here, since child task may rely on the parent context
ctx
,
_
=
scheduler
.
BindContext
(
ctx
)
// task preExecute
span
.
LogFields
(
oplog
.
Int64
(
"processTask: scheduler process PreExecute"
,
t
.
getTaskID
()))
err
=
t
.
preExecute
(
ctx
)
...
...
@@ -710,6 +714,8 @@ func (scheduler *TaskScheduler) scheduleLoop() {
triggerTask
.
notify
(
nil
)
}
}
// calling context cancel so that bind context goroutine may quit
triggerTask
.
finishContext
()
}
}
}
...
...
@@ -887,6 +893,26 @@ func (scheduler *TaskScheduler) Close() {
scheduler
.
wg
.
Wait
()
}
// BindContext binds input context with shceduler context.
// the result context will be canceled when either context is done.
func
(
scheduler
*
TaskScheduler
)
BindContext
(
ctx
context
.
Context
)
(
context
.
Context
,
context
.
CancelFunc
)
{
// use input context as parent
nCtx
,
cancel
:=
context
.
WithCancel
(
ctx
)
go
func
()
{
select
{
case
<-
scheduler
.
ctx
.
Done
()
:
// scheduler done
cancel
()
case
<-
ctx
.
Done
()
:
// input ctx done
cancel
()
case
<-
nCtx
.
Done
()
:
// result context done, cancel called to make goroutine quit
}
}()
return
nCtx
,
cancel
}
func
updateSegmentInfoFromTask
(
ctx
context
.
Context
,
triggerTask
task
,
meta
Meta
)
error
{
segmentInfosToSave
:=
make
(
map
[
UniqueID
][]
*
querypb
.
SegmentInfo
)
segmentInfosToRemove
:=
make
(
map
[
UniqueID
][]
*
querypb
.
SegmentInfo
)
...
...
internal/querycoord/task_scheduler_test.go
浏览文件 @
f9553970
...
...
@@ -21,6 +21,7 @@ import (
"fmt"
"strconv"
"testing"
"time"
etcdkv
"github.com/milvus-io/milvus/internal/kv/etcd"
"github.com/milvus-io/milvus/internal/log"
...
...
@@ -553,3 +554,50 @@ func Test_generateDerivedInternalTasks(t *testing.T) {
err
=
removeAllSession
()
assert
.
Nil
(
t
,
err
)
}
func
TestTaskScheduler_BindContext
(
t
*
testing
.
T
)
{
ctx
,
cancel
:=
context
.
WithCancel
(
context
.
Background
())
s
:=
&
TaskScheduler
{
ctx
:
ctx
,
cancel
:
cancel
,
}
t
.
Run
(
"normal finish"
,
func
(
t
*
testing
.
T
)
{
ctx
,
cancel
:=
context
.
WithCancel
(
context
.
Background
())
defer
cancel
()
ctx
,
cancel
=
s
.
BindContext
(
ctx
)
cancel
()
// normal finish
assert
.
Eventually
(
t
,
func
()
bool
{
return
ctx
.
Err
()
==
context
.
Canceled
},
time
.
Second
,
time
.
Millisecond
*
10
)
})
t
.
Run
(
"input context canceled"
,
func
(
t
*
testing
.
T
)
{
ctx
,
cancel
:=
context
.
WithCancel
(
context
.
Background
())
nctx
,
ncancel
:=
s
.
BindContext
(
ctx
)
defer
ncancel
()
cancel
()
// input context cancel
assert
.
Eventually
(
t
,
func
()
bool
{
return
nctx
.
Err
()
==
context
.
Canceled
},
time
.
Second
,
time
.
Millisecond
*
10
)
})
t
.
Run
(
"scheduler context cancel"
,
func
(
t
*
testing
.
T
)
{
ctx
,
cancel
:=
context
.
WithCancel
(
context
.
Background
())
defer
cancel
()
nctx
,
ncancel
:=
s
.
BindContext
(
ctx
)
defer
ncancel
()
s
.
cancel
()
// scheduler cancel
assert
.
Eventually
(
t
,
func
()
bool
{
return
nctx
.
Err
()
==
context
.
Canceled
},
time
.
Second
,
time
.
Millisecond
*
10
)
})
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录