Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
82922152
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看板
提交
82922152
编写于
1月 15, 2022
作者:
D
dapan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feature/qnode
上级
51ef795d
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
86 addition
and
107 deletion
+86
-107
source/libs/qworker/inc/qworkerInt.h
source/libs/qworker/inc/qworkerInt.h
+3
-1
source/libs/qworker/src/qworker.c
source/libs/qworker/src/qworker.c
+77
-66
source/libs/qworker/src/qworkerMsg.c
source/libs/qworker/src/qworkerMsg.c
+6
-40
未找到文件。
source/libs/qworker/inc/qworkerInt.h
浏览文件 @
82922152
...
...
@@ -42,6 +42,8 @@ enum {
QW_EVENT_READY
,
QW_EVENT_FETCH
,
QW_EVENT_DROP
,
QW_EVENT_SCH_SINK
,
QW_EVENT_SCH_QUERY
,
QW_EVENT_MAX
,
};
...
...
@@ -100,7 +102,7 @@ typedef struct SQWTaskCtx {
SRWLatch
lock
;
int32_t
phase
;
int
8_t
sinkInQ
;
int
32_t
sinkId
;
int8_t
queryInQ
;
int8_t
events
[
QW_EVENT_MAX
];
...
...
source/libs/qworker/src/qworker.c
浏览文件 @
82922152
...
...
@@ -450,13 +450,51 @@ _return:
QW_RET
(
code
);
}
int32_t
qwScheduleDataSink
(
SQWorkerMgmt
*
mgmt
,
uint64_t
sId
,
uint64_t
qId
,
uint64_t
tId
,
SQWTaskCtx
*
ctx
,
SRpcMsg
*
pMsg
)
{
if
(
atomic_load_8
(
&
handles
->
sinkScheduled
))
{
qDebug
(
"data sink already scheduled"
);
return
TSDB_CODE_SUCCESS
;
}
SSinkDataReq
*
req
=
(
SSinkDataReq
*
)
rpcMallocCont
(
sizeof
(
SSinkDataReq
));
if
(
NULL
==
req
)
{
qError
(
"rpcMallocCont %d failed"
,
(
int32_t
)
sizeof
(
SSinkDataReq
));
QW_ERR_RET
(
TSDB_CODE_QRY_OUT_OF_MEMORY
);
}
req
->
header
.
vgId
=
mgmt
->
nodeId
;
req
->
sId
=
sId
;
req
->
queryId
=
qId
;
req
->
taskId
=
tId
;
SRpcMsg
pNewMsg
=
{
.
handle
=
pMsg
->
handle
,
.
ahandle
=
pMsg
->
ahandle
,
.
msgType
=
TDMT_VND_SCHEDULE_DATA_SINK
,
.
pCont
=
req
,
.
contLen
=
sizeof
(
SSinkDataReq
),
.
code
=
0
,
};
int32_t
qwGetResFromSink
(
SQWorkerMgmt
*
mgmt
,
uint64_t
sId
,
uint64_t
qId
,
uint64_t
tId
,
SQWTaskCtx
*
ctx
,
int32_t
*
dataLen
,
void
**
rspMsg
)
{
int32_t
code
=
(
*
mgmt
->
putToQueueFp
)(
mgmt
->
nodeObj
,
&
pNewMsg
);
if
(
TSDB_CODE_SUCCESS
!=
code
)
{
qError
(
"put data sink schedule msg to queue failed, code:%x"
,
code
);
rpcFreeCont
(
req
);
QW_ERR_RET
(
code
);
}
qDebug
(
"put data sink schedule msg to query queue"
);
return
TSDB_CODE_SUCCESS
;
}
int32_t
qwGetResFromSink
(
QW_FPARAMS_DEF
,
SQWTaskCtx
*
ctx
,
int32_t
*
dataLen
,
void
**
rspMsg
,
SOutputData
*
pOutput
)
{
int32_t
len
=
0
;
SRetrieveTableRsp
*
rsp
=
NULL
;
bool
queryEnd
=
false
;
int32_t
code
=
0
;
SOutputData
output
=
{
0
};
dsGetDataLength
(
ctx
->
sinkHandle
,
&
len
,
&
queryEnd
);
...
...
@@ -467,7 +505,7 @@ int32_t qwGetResFromSink(SQWorkerMgmt *mgmt, uint64_t sId, uint64_t qId, uint64_
if
(
len
==
0
)
{
if
(
queryEnd
)
{
code
=
dsGetDataBlock
(
ctx
->
sinkHandle
,
&
o
utput
);
code
=
dsGetDataBlock
(
ctx
->
sinkHandle
,
pO
utput
);
if
(
code
)
{
QW_TASK_ELOG
(
"dsGetDataBlock failed, code:%x"
,
code
);
QW_ERR_RET
(
code
);
...
...
@@ -479,10 +517,10 @@ int32_t qwGetResFromSink(SQWorkerMgmt *mgmt, uint64_t sId, uint64_t qId, uint64_
QW_ERR_RET
(
qwMallocFetchRsp
(
len
,
&
rsp
));
qwBuildFetchRsp
(
rsp
,
&
output
,
0
);
*
rspMsg
=
rsp
;
*
dataLen
=
0
;
return
TSDB_CODE_SUCCESS
;
}
...
...
@@ -494,42 +532,33 @@ int32_t qwGetResFromSink(SQWorkerMgmt *mgmt, uint64_t sId, uint64_t qId, uint64_
// Got data from sink
// Note: schedule data sink firstly and will schedule query after it's done
if
(
output
.
needSchedule
)
{
QW_TASK_DLOG
(
"sink need schedule, queryEnd:%d"
,
output
.
queryEnd
);
QW_ERR_RET
(
qwScheduleDataSink
(
handles
,
mgmt
,
sId
,
qId
,
tId
,
pMsg
));
}
else
if
((
!
output
.
queryEnd
)
&&
(
DS_BUF_LOW
==
output
.
bufStatus
||
DS_BUF_EMPTY
==
output
.
bufStatus
))
{
QW_TASK_DLOG
(
"task not end, need to continue, bufStatus:%d"
,
output
.
bufStatus
);
QW_ERR_RET
(
qwScheduleQuery
(
handles
,
mgmt
,
sId
,
qId
,
tId
,
pMsg
));
}
*
dataLen
=
len
;
QW_TASK_DLOG
(
"task got data in sink, dataLength:%d"
,
len
);
QW_ERR_RET
(
qwMallocFetchRsp
(
len
,
&
rsp
));
*
rspMsg
=
rsp
;
output
.
pData
=
rsp
->
data
;
pOutput
->
pData
=
rsp
->
data
;
code
=
dsGetDataBlock
(
ctx
->
sinkHandle
,
&
o
utput
);
code
=
dsGetDataBlock
(
ctx
->
sinkHandle
,
pO
utput
);
if
(
code
)
{
QW_TASK_ELOG
(
"dsGetDataBlock failed, code:%x"
,
code
);
qwFreeFetchRsp
(
rsp
);
QW_ERR_RET
(
code
);
}
queryEnd
=
output
.
queryEnd
;
output
.
queryEnd
=
false
;
queryEnd
=
pOutput
->
queryEnd
;
pOutput
->
queryEnd
=
false
;
if
(
DS_BUF_EMPTY
==
output
.
bufStatus
&&
queryEnd
)
{
output
.
queryEnd
=
true
;
if
(
DS_BUF_EMPTY
==
pOutput
->
bufStatus
&&
queryEnd
)
{
pOutput
->
queryEnd
=
true
;
QW_SCH_TASK_DLOG
(
"task all fetched, status:%d"
,
JOB_TASK_STATUS_SUCCEED
);
QW_ERR_RET
(
qwUpdateTaskStatus
(
QW_FPARAMS
(),
JOB_TASK_STATUS_SUCCEED
));
}
qwBuildFetchRsp
(
rsp
,
&
output
,
len
);
return
TSDB_CODE_SUCCESS
;
}
...
...
@@ -783,13 +812,29 @@ int32_t qwProcessFetch(SQWorkerMgmt *mgmt, uint64_t sId, uint64_t qId, uint64_t
}
QW_ERR_JRET
(
qwAcquireTaskCtx
(
QW_FPARAMS
(),
QW_READ
,
&
ctx
));
QW_LOCK
(
QW_WRITE
,
&
ctx
->
lock
);
QW_LOCK
(
QW_WRITE
,
&
ctx
->
lock
);
locked
=
true
;
SOutputData
sOutput
=
{
0
};
QW_ERR_JRET
(
qwGetResFromSink
(
QW_FPARAMS
(),
ctx
,
&
dataLen
,
&
rsp
,
&
sOutput
));
QW_ERR_JRET
(
qwGetResFromSink
(
QW_FPARAMS
(),
ctx
,
&
dataLen
,
&
rsp
));
// Note: schedule data sink firstly and will schedule query after it's done
if
(
sOutput
.
needSchedule
)
{
QW_TASK_DLOG
(
"sink need schedule, queryEnd:%d"
,
sOutput
.
queryEnd
);
if
(
sOutput
.
needSchedule
>
ctx
.
sinkId
)
{
QW_ERR_RET
(
qwScheduleDataSink
(
ctx
,
mgmt
,
sId
,
qId
,
tId
,
pMsg
));
}
}
else
if
((
!
sOutput
.
queryEnd
)
&&
(
DS_BUF_LOW
==
sOutput
.
bufStatus
||
DS_BUF_EMPTY
==
sOutput
.
bufStatus
))
{
QW_TASK_DLOG
(
"task not end, need to continue, bufStatus:%d"
,
output
.
bufStatus
);
QW_ERR_RET
(
qwScheduleQuery
(
ctx
,
mgmt
,
sId
,
qId
,
tId
,
pMsg
));
}
if
(
rsp
)
{
qwBuildFetchRsp
(
rsp
,
&
sOutput
,
dataLen
);
}
_return:
if
(
locked
)
{
...
...
@@ -800,8 +845,12 @@ _return:
qwReleaseTaskCtx
(
QW_READ
,
mgmt
);
}
if
(
needRsp
)
{
qwBuildAndSendFetchRsp
(
pMsg
,
rsp
,
dataLen
,
code
);
if
(
code
)
{
qwFreeFetchRsp
(
rsp
);
rsp
=
NULL
;
qwBuildAndSendFetchRsp
(
qwMsg
->
connection
,
rsp
,
0
,
code
);
}
else
if
(
rsp
)
{
qwBuildAndSendFetchRsp
(
qwMsg
->
connection
,
rsp
,
dataLen
,
code
);
}
QW_RET
(
code
);
...
...
@@ -910,44 +959,6 @@ void qWorkerDestroy(void **qWorkerMgmt) {
int32_t
qwScheduleDataSink
(
SQWorkerMgmt
*
mgmt
,
uint64_t
sId
,
uint64_t
qId
,
uint64_t
tId
,
SQWTaskCtx
*
ctx
,
SRpcMsg
*
pMsg
)
{
if
(
atomic_load_8
(
&
handles
->
sinkScheduled
))
{
qDebug
(
"data sink already scheduled"
);
return
TSDB_CODE_SUCCESS
;
}
SSinkDataReq
*
req
=
(
SSinkDataReq
*
)
rpcMallocCont
(
sizeof
(
SSinkDataReq
));
if
(
NULL
==
req
)
{
qError
(
"rpcMallocCont %d failed"
,
(
int32_t
)
sizeof
(
SSinkDataReq
));
QW_ERR_RET
(
TSDB_CODE_QRY_OUT_OF_MEMORY
);
}
req
->
header
.
vgId
=
mgmt
->
nodeId
;
req
->
sId
=
sId
;
req
->
queryId
=
queryId
;
req
->
taskId
=
taskId
;
SRpcMsg
pNewMsg
=
{
.
handle
=
pMsg
->
handle
,
.
ahandle
=
pMsg
->
ahandle
,
.
msgType
=
TDMT_VND_SCHEDULE_DATA_SINK
,
.
pCont
=
req
,
.
contLen
=
sizeof
(
SSinkDataReq
),
.
code
=
0
,
};
int32_t
code
=
(
*
mgmt
->
putToQueueFp
)(
mgmt
->
nodeObj
,
&
pNewMsg
);
if
(
TSDB_CODE_SUCCESS
!=
code
)
{
qError
(
"put data sink schedule msg to queue failed, code:%x"
,
code
);
rpcFreeCont
(
req
);
QW_ERR_RET
(
code
);
}
qDebug
(
"put data sink schedule msg to query queue"
);
return
TSDB_CODE_SUCCESS
;
}
int32_t
qwGetSchTasksStatus
(
SQWorkerMgmt
*
mgmt
,
uint64_t
sId
,
uint64_t
qId
,
uint64_t
tId
,
SSchedulerStatusRsp
**
rsp
)
{
...
...
source/libs/qworker/src/qworkerMsg.c
浏览文件 @
82922152
...
...
@@ -36,7 +36,9 @@ void qwBuildFetchRsp(SRetrieveTableRsp *rsp, SOutputData *input, int32_t len) {
void
qwFreeFetchRsp
(
void
*
msg
)
{
rpcFreeCont
(
msg
);
if
(
msg
)
{
rpcFreeCont
(
msg
);
}
}
int32_t
qwBuildAndSendQueryRsp
(
void
*
connection
,
int32_t
code
)
{
...
...
@@ -106,7 +108,9 @@ int32_t qwBuildAndSendStatusRsp(SRpcMsg *pMsg, SSchedulerStatusRsp *sStatus) {
return
TSDB_CODE_SUCCESS
;
}
int32_t
qwBuildAndSendFetchRsp
(
SRpcMsg
*
pMsg
,
SRetrieveTableRsp
*
pRsp
,
int32_t
dataLength
,
int32_t
code
)
{
int32_t
qwBuildAndSendFetchRsp
(
void
*
connection
,
SRetrieveTableRsp
*
pRsp
,
int32_t
dataLength
,
int32_t
code
)
{
SRpcMsg
*
pMsg
=
(
SRpcMsg
*
)
connection
;
if
(
NULL
==
pRsp
)
{
pRsp
=
(
SRetrieveTableRsp
*
)
rpcMallocCont
(
sizeof
(
SRetrieveTableRsp
));
memset
(
pRsp
,
0
,
sizeof
(
SRetrieveTableRsp
));
...
...
@@ -264,44 +268,6 @@ _return:
}
int32_t
qwScheduleDataSink
(
SQWorkerMgmt
*
mgmt
,
uint64_t
sId
,
uint64_t
qId
,
uint64_t
tId
,
SQWTaskCtx
*
handles
,
SRpcMsg
*
pMsg
)
{
if
(
atomic_load_8
(
&
handles
->
sinkScheduled
))
{
qDebug
(
"data sink already scheduled"
);
return
TSDB_CODE_SUCCESS
;
}
SSinkDataReq
*
req
=
(
SSinkDataReq
*
)
rpcMallocCont
(
sizeof
(
SSinkDataReq
));
if
(
NULL
==
req
)
{
qError
(
"rpcMallocCont %d failed"
,
(
int32_t
)
sizeof
(
SSinkDataReq
));
QW_ERR_RET
(
TSDB_CODE_QRY_OUT_OF_MEMORY
);
}
req
->
header
.
vgId
=
mgmt
->
nodeId
;
req
->
sId
=
sId
;
req
->
queryId
=
queryId
;
req
->
taskId
=
taskId
;
SRpcMsg
pNewMsg
=
{
.
handle
=
pMsg
->
handle
,
.
ahandle
=
pMsg
->
ahandle
,
.
msgType
=
TDMT_VND_SCHEDULE_DATA_SINK
,
.
pCont
=
req
,
.
contLen
=
sizeof
(
SSinkDataReq
),
.
code
=
0
,
};
int32_t
code
=
(
*
mgmt
->
putToQueueFp
)(
mgmt
->
nodeObj
,
&
pNewMsg
);
if
(
TSDB_CODE_SUCCESS
!=
code
)
{
qError
(
"put data sink schedule msg to queue failed, code:%x"
,
code
);
rpcFreeCont
(
req
);
QW_ERR_RET
(
code
);
}
qDebug
(
"put data sink schedule msg to query queue"
);
return
TSDB_CODE_SUCCESS
;
}
int32_t
qwScheduleQuery
(
SQWorkerMgmt
*
mgmt
,
uint64_t
sId
,
uint64_t
qId
,
uint64_t
tId
,
SQWTaskCtx
*
handles
,
SRpcMsg
*
pMsg
)
{
if
(
atomic_load_8
(
&
handles
->
queryScheduled
))
{
QW_SCH_TASK_ELOG
(
"query already scheduled, queryScheduled:%d"
,
handles
->
queryScheduled
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录