Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
8dd9cc74
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
8dd9cc74
编写于
12月 18, 2021
作者:
D
dapan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
scheduler job code
上级
d61e2bd1
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
164 addition
and
43 deletion
+164
-43
include/libs/planner/planner.h
include/libs/planner/planner.h
+2
-0
source/libs/scheduler/inc/schedulerInt.h
source/libs/scheduler/inc/schedulerInt.h
+18
-11
source/libs/scheduler/src/scheduler.c
source/libs/scheduler/src/scheduler.c
+144
-32
未找到文件。
include/libs/planner/planner.h
浏览文件 @
8dd9cc74
...
...
@@ -105,6 +105,8 @@ typedef struct SSubplan {
}
SSubplan
;
typedef
struct
SQueryDag
{
uint64_t
queryId
;
int32_t
numOfSubplans
;
SArray
*
pSubplans
;
// Element is SArray*, and nested element is SSubplan. The execution level of subplan, starting from 0.
}
SQueryDag
;
...
...
source/libs/scheduler/inc/schedulerInt.h
浏览文件 @
8dd9cc74
...
...
@@ -44,14 +44,16 @@ typedef struct SSchedulerMgmt {
}
SSchedulerMgmt
;
typedef
struct
SQueryTask
{
uint64_t
taskId
;
// task id
SSubplan
*
plan
;
// subplan
char
*
msg
;
// operator tree
int8_t
status
;
// task status
SEpAddr
execAddr
;
// task actual executed node address
SQueryProfileSummary
summary
;
// task execution summary
SArray
*
childern
;
// the datasource tasks,from which to fetch the result, element is SQueryTask*
SArray
*
parents
;
// the data destination tasks, get data from current task, element is SQueryTask*
uint64_t
taskId
;
// task id
SSubplan
*
plan
;
// subplan
char
*
msg
;
// operator tree
int8_t
status
;
// task status
SEpAddr
execAddr
;
// task actual executed node address
SQueryProfileSummary
summary
;
// task execution summary
int32_t
childReady
;
// child task ready number
SArray
*
childSrcEp
;
// child Eps, element is SEpAddr
SArray
*
childern
;
// the datasource tasks,from which to fetch the result, element is SQueryTask*
SArray
*
parents
;
// the data destination tasks, get data from current task, element is SQueryTask*
}
SQueryTask
;
typedef
struct
SQueryLevel
{
...
...
@@ -67,11 +69,16 @@ typedef struct SQueryJob {
int32_t
levelIdx
;
int8_t
status
;
SQueryProfileSummary
summary
;
SArray
*
levels
;
// Element is SQueryLevel, starting from 0.
SArray
*
subPlans
;
// Element is SArray*, and nested element is SSubplan. The execution level of subplan, starting from 0.
SHashObj
*
execTasks
;
// executing tasks, key:taskid, value:SQueryTask*
SHashObj
*
succTasks
;
// succeed tasks, key:taskid, value:SQueryTask*
SArray
*
levels
;
// Element is SQueryLevel, starting from 0.
SArray
*
subPlans
;
// Element is SArray*, and nested element is SSubplan. The execution level of subplan, starting from 0.
}
SQueryJob
;
#define SCH_TASK_READY_TO_LUNCH(task) ((task)->childReady >= taosArrayGetSize((task)->children)) // MAY NEED TO ENHANCE
#define SCH_JOB_ERR_LOG(param, ...) qError("QID:%"PRIx64 param, job->queryId, __VA_ARGS__)
#define SCH_TASK_ERR_LOG(param, ...) qError("QID:%"PRIx64",TID:%"PRIx64 param, job->queryId, task->taskId, __VA_ARGS__)
...
...
source/libs/scheduler/src/scheduler.c
浏览文件 @
8dd9cc74
...
...
@@ -53,7 +53,7 @@ int32_t schBuildAndSendRequest(void *pRpc, const SEpSet* pMgmtEps, __taos_async_
int32_t
schBuildTaskRalation
(
SQueryJob
*
job
,
SHashObj
*
planToTask
)
{
for
(
int32_t
i
=
0
;
i
<
job
->
levelNum
;
++
i
)
{
SQueryLevel
*
level
=
taosArrayGet
(
job
->
levels
,
i
);
for
(
int32_t
m
=
0
;
m
<
level
->
taskNum
;
++
m
)
{
SQueryTask
*
task
=
taosArrayGet
(
level
->
subTasks
,
m
);
SSubplan
*
plan
=
task
->
plan
;
...
...
@@ -106,12 +106,31 @@ int32_t schBuildTaskRalation(SQueryJob *job, SHashObj *planToTask) {
}
}
SQueryLevel
*
level
=
taosArrayGet
(
job
->
levels
,
0
);
if
(
level
->
taskNum
>
1
)
{
qError
(
"invalid plan info, level 0, taskNum:%d"
,
level
->
taskNum
);
SCH_ERR_RET
(
TSDB_CODE_SCH_INTERNAL_ERROR
);
}
SQueryTask
*
task
=
taosArrayGet
(
level
->
subTasks
,
0
);
if
(
task
->
parents
&&
taosArrayGetSize
(
task
->
parents
)
>
0
)
{
qError
(
"invalid plan info, level 0, parentNum:%d"
,
(
int32_t
)
taosArrayGetSize
(
task
->
parents
));
SCH_ERR_RET
(
TSDB_CODE_SCH_INTERNAL_ERROR
);
}
return
TSDB_CODE_SUCCESS
;
}
int32_t
schValidateAndBuildJob
(
SQueryDag
*
dag
,
SQueryJob
*
job
)
{
int32_t
code
=
0
;
if
(
dag
->
numOfSubplans
<=
0
)
{
qError
(
"invalid subplan num:%d"
,
dag
->
numOfSubplans
);
SCH_ERR_RET
(
TSDB_CODE_QRY_INVALID_INPUT
);
}
int32_t
levelNum
=
(
int32_t
)
taosArrayGetSize
(
dag
->
pSubplans
);
if
(
levelNum
<=
0
)
{
qError
(
"invalid level num:%d"
,
levelNum
);
...
...
@@ -213,47 +232,126 @@ int32_t schAsyncLaunchTask(SQueryJob *job, SQueryTask *task) {
}
int32_t
schTaskCheckAndSetRetry
(
SQueryJob
*
job
,
SQueryTask
*
task
,
int32_t
errCode
,
bool
*
needRetry
)
{
}
int32_t
schProcessOnJobSuccess
(
SQueryJob
*
job
)
{
}
int32_t
schProcessOnJobFailure
(
SQueryJob
*
job
)
{
}
int32_t
schProcessOnTaskSuccess
(
SQueryJob
*
job
,
SQueryTask
*
task
)
{
bool
moved
=
false
;
SCH_ERR_RET
(
schMoveTaskToSuccList
(
job
,
task
,
&
moved
));
if
(
!
moved
)
{
qWarn
(
"task[%d] already moved"
,
task
->
taskId
);
return
TSDB_CODE_SUCCESS
;
}
int32_t
parentNum
=
(
int32_t
)
taosArrayGetSize
(
task
->
parents
);
if
(
parentNum
==
0
)
{
if
(
task
->
plan
->
level
!=
0
)
{
qError
(
"level error"
);
SCH_ERR_RET
(
TSDB_CODE_QRY_INVALID_INPUT
);
}
SCH_ERR_RET
(
schProcessOnJobSuccess
());
return
TSDB_CODE_SUCCESS
;
}
for
(
int32_t
i
=
0
;
i
<
parentNum
;
++
i
)
{
SQueryTask
*
par
=
taosArrayGet
(
task
->
parents
,
i
);
++
par
->
childReady
;
if
(
NULL
==
taosArrayPush
(
par
->
childSrcEp
,
&
task
->
execAddr
))
{
qError
(
"taosArrayPush failed"
);
SCH_ERR_RET
(
TSDB_CODE_QRY_OUT_OF_MEMORY
);
}
if
(
SCH_TASK_READY_TO_LUNCH
(
par
))
{
SCH_ERR_RET
(
schTaskRun
(
job
,
task
));
}
}
return
TSDB_CODE_SUCCESS
;
}
int32_t
schProcessOnTaskFailure
(
SQueryJob
*
job
,
SQueryTask
*
task
,
int32_t
errCode
)
{
bool
needRetry
=
false
;
SCH_ERR_RET
(
schTaskCheckAndSetRetry
(
job
,
task
,
errCode
,
&
needRetry
));
if
(
!
needRetry
)
{
SCH_TASK_ERR_LOG
(
"task failed[%x], no more retry"
,
errCode
);
job
->
status
=
SCH_STATUS_FAILED
;
SCH_ERR_RET
(
schProcessOnJobFailure
(
job
));
return
TSDB_CODE_SUCCESS
;
}
SCH_ERR_RET
(
schTaskRun
(
job
,
task
));
return
TSDB_CODE_SUCCESS
;
}
int32_t
schPushTaskToExecList
(
SQueryJob
*
job
,
SQueryTask
*
task
)
{
if
(
0
!=
taosHashPut
(
job
->
execTasks
,
&
task
->
taskId
,
sizeof
(
task
->
taskId
),
&
task
,
POINTER_BYTES
))
{
qError
(
"taosHashPut failed"
);
SCH_ERR_RET
(
TSDB_CODE_QRY_OUT_OF_MEMORY
);
}
return
TSDB_CODE_SUCCESS
;
}
int32_t
schMoveTaskToSuccList
(
SQueryJob
*
job
,
SQueryTask
*
task
,
bool
*
moved
)
{
if
(
0
!=
taosHashRemove
(
job
->
execTasks
,
&
task
->
taskId
,
sizeof
(
task
->
taskId
)))
{
qWarn
(
"remove task[%"
PRIx64
"] from execTasks failed"
,
task
->
taskId
);
return
TSDB_CODE_SUCCESS
}
if
(
0
!=
taosHashPut
(
job
->
execTasks
,
&
task
->
taskId
,
sizeof
(
task
->
taskId
),
&
task
,
POINTER_BYTES
))
{
qError
(
"taosHashPut failed"
);
SCH_ERR_RET
(
TSDB_CODE_QRY_OUT_OF_MEMORY
);
}
*
moved
=
true
;
return
TSDB_CODE_SUCCESS
;
}
int32_t
schTaskRun
(
SQueryJob
*
job
,
SQueryTask
*
task
)
{
SSubplan
*
plan
=
task
->
plan
;
switch
(
task
->
status
)
{
case
SCH_STATUS_NOT_START
:
SCH_ERR_RET
(
qSubPlanToString
(
plan
,
&
task
->
msg
));
if
(
plan
->
execEpSet
.
numOfEps
<=
0
)
{
SCH_ERR_RET
(
schAvailableEpSet
(
&
plan
->
execEpSet
));
}
SCH_ERR_RET
(
schAsyncLaunchTask
(
job
,
task
));
break
;
case
SCH_STATUS_EXECUTING
:
break
;
case
SCH_STATUS_SUCCEED
:
break
;
default:
SCH_JOB_ERR_LOG
(
"invalid level status:%d, levelIdx:%d"
,
job
->
status
,
job
->
levelIdx
);
SCH_ERR_RET
(
TSDB_CODE_SCH_STATUS_ERROR
);
SCH_ERR_RET
(
qSubPlanToString
(
plan
,
&
task
->
msg
));
if
(
plan
->
execEpSet
.
numOfEps
<=
0
)
{
SCH_ERR_RET
(
schAvailableEpSet
(
&
plan
->
execEpSet
));
}
SCH_ERR_RET
(
schAsyncLaunchTask
(
job
,
task
));
SCH_ERR_RET
(
schPushTaskToExecList
(
job
,
task
))
return
TSDB_CODE_SUCCESS
;
}
int32_t
schJobRun
(
SQueryJob
*
job
)
{
bool
cont
=
true
;
while
(
cont
)
{
switch
(
job
->
status
)
{
case
SCH_STATUS_NOT_START
:
case
SCH_STATUS_EXECUTING
:
break
;
default:
SCH_JOB_ERR_LOG
(
"invalid job status:%d"
,
job
->
status
);
SCH_ERR_RET
(
TSDB_CODE_SCH_STATUS_ERROR
);
}
SQueryLevel
*
level
=
taosArrayGet
(
job
->
levels
,
job
->
levelIdx
);
for
(
int32_t
i
=
0
;
i
<
level
->
taskNum
;
++
i
)
{
SQueryTask
*
task
=
taosArrayGet
(
level
->
subTasks
,
i
);
SCH_ERR_RET
(
schTaskRun
(
job
,
task
));
}
return
TSDB_CODE_SUCCESS
;
}
...
...
@@ -281,6 +379,18 @@ int32_t scheduleQueryJob(void *pRpc, SQueryDag* pDag, void** pJob) {
SCH_ERR_JRET
(
schValidateAndBuildJob
(
pDag
,
job
));
job
->
execTasks
=
taosHashInit
(
pDag
->
numOfSubplans
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_UBIGINT
),
false
,
HASH_ENTRY_LOCK
);
if
(
NULL
==
job
->
execTasks
)
{
qError
(
"taosHashInit %d failed"
,
pDag
->
numOfSubplans
);
SCH_ERR_JRET
(
TSDB_CODE_QRY_OUT_OF_MEMORY
);
}
job
->
succTasks
=
taosHashInit
(
pDag
->
numOfSubplans
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_UBIGINT
),
false
,
HASH_ENTRY_LOCK
);
if
(
NULL
==
job
->
succTasks
)
{
qError
(
"taosHashInit %d failed"
,
pDag
->
numOfSubplans
);
SCH_ERR_JRET
(
TSDB_CODE_QRY_OUT_OF_MEMORY
);
}
SCH_ERR_JRET
(
schJobRun
(
job
));
*
(
SQueryJob
**
)
pJob
=
job
;
...
...
@@ -299,8 +409,10 @@ int32_t scheduleFetchRows(void *pRpc, void *pJob, void *data);
int32_t
scheduleCancelJob
(
void
*
pRpc
,
void
*
pJob
);
void
scheduleFreeJob
(
void
*
pJob
)
{
void
scheduleFreeJob
(
void
*
job
)
{
if
(
NULL
==
job
)
{
return
;
}
}
void
schedulerDestroy
(
void
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录