Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
ce842ec8
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看板
提交
ce842ec8
编写于
7月 23, 2022
作者:
K
kailixu
浏览文件
操作
浏览文件
下载
差异文件
Merge branch '3.0' into enh/TD-24987-3.0
上级
b6bfdf2b
321be1f8
变更
17
展开全部
显示空白变更内容
内联
并排
Showing
17 changed file
with
681 addition
and
349 deletion
+681
-349
include/libs/stream/tstream.h
include/libs/stream/tstream.h
+37
-17
source/dnode/mgmt/mgmt_snode/src/smHandle.c
source/dnode/mgmt/mgmt_snode/src/smHandle.c
+1
-0
source/dnode/mgmt/mgmt_vnode/src/vmHandle.c
source/dnode/mgmt/mgmt_vnode/src/vmHandle.c
+1
-0
source/dnode/mnode/impl/src/mndScheduler.c
source/dnode/mnode/impl/src/mndScheduler.c
+24
-7
source/dnode/snode/src/snode.c
source/dnode/snode/src/snode.c
+11
-10
source/dnode/vnode/src/inc/vnodeInt.h
source/dnode/vnode/src/inc/vnodeInt.h
+2
-2
source/dnode/vnode/src/tq/tq.c
source/dnode/vnode/src/tq/tq.c
+139
-120
source/dnode/vnode/src/tq/tqRestore.c
source/dnode/vnode/src/tq/tqRestore.c
+8
-2
source/dnode/vnode/src/vnd/vnodeSvr.c
source/dnode/vnode/src/vnd/vnodeSvr.c
+2
-2
source/libs/executor/src/executor.c
source/libs/executor/src/executor.c
+1
-1
source/libs/stream/inc/streamInt.h
source/libs/stream/inc/streamInt.h
+9
-0
source/libs/stream/src/stream.c
source/libs/stream/src/stream.c
+22
-9
source/libs/stream/src/streamDispatch.c
source/libs/stream/src/streamDispatch.c
+114
-19
source/libs/stream/src/streamExec.c
source/libs/stream/src/streamExec.c
+37
-26
source/libs/stream/src/streamMeta.c
source/libs/stream/src/streamMeta.c
+2
-2
source/libs/stream/src/streamRecover.c
source/libs/stream/src/streamRecover.c
+241
-115
source/libs/stream/src/streamTask.c
source/libs/stream/src/streamTask.c
+30
-17
未找到文件。
include/libs/stream/tstream.h
浏览文件 @
ce842ec8
...
...
@@ -45,8 +45,8 @@ enum {
TASK_STATUS__FAIL
,
TASK_STATUS__STOP
,
TASK_STATUS__SCAN_HISTORY
,
// stream task scan history data by using tsdbread in the stream scanner
TASK_STATUS__HALT
,
// stream task will handle all data in the input queue, and then paused
TASK_STATUS__PAUSE
,
TASK_STATUS__HALT
,
// stream task will handle all data in the input queue, and then paused
, todo remove it?
TASK_STATUS__PAUSE
,
// pause
};
enum
{
...
...
@@ -272,6 +272,7 @@ typedef struct SStreamStatus {
int8_t
keepTaskStatus
;
bool
transferState
;
int8_t
timerActive
;
// timer is active
int8_t
pauseAllowed
;
// allowed task status to be set to be paused
}
SStreamStatus
;
typedef
struct
SHistDataRange
{
...
...
@@ -296,15 +297,15 @@ typedef struct SDispatchMsgInfo {
}
SDispatchMsgInfo
;
typedef
struct
{
int8_t
outputT
ype
;
int8_t
outputS
tatus
;
SStreamQueue
*
outputQ
ueue
;
}
S
S
TaskOutputInfo
;
int8_t
t
ype
;
int8_t
s
tatus
;
SStreamQueue
*
q
ueue
;
}
STaskOutputInfo
;
struct
SStreamTask
{
SStreamId
id
;
SSTaskBasicInfo
info
;
int8_t
outputType
;
STaskOutputInfo
outputInfo
;
SDispatchMsgInfo
msgInfo
;
SStreamStatus
status
;
SCheckpointInfo
chkInfo
;
...
...
@@ -315,7 +316,7 @@ struct SStreamTask {
SArray
*
pUpstreamEpInfoList
;
// SArray<SStreamChildEpInfo*>, // children info
int32_t
nextCheckId
;
SArray
*
checkpointInfo
;
// SArray<SStreamCheckpointInfo>
int64_t
initTs
;
// output
union
{
STaskDispatcherFixedEp
fixedEpDispatcher
;
...
...
@@ -326,9 +327,7 @@ struct SStreamTask {
};
int8_t
inputStatus
;
int8_t
outputStatus
;
SStreamQueue
*
inputQueue
;
SStreamQueue
*
outputQueue
;
// trigger
int8_t
triggerStatus
;
...
...
@@ -337,6 +336,8 @@ struct SStreamTask {
void
*
launchTaskTimer
;
SMsgCb
*
pMsgCb
;
// msg handle
SStreamState
*
pState
;
// state backend
SArray
*
pRspMsgList
;
TdThreadMutex
lock
;
// the followings attributes don't be serialized
int32_t
notReadyTasks
;
...
...
@@ -458,7 +459,9 @@ typedef struct {
typedef
struct
{
int64_t
streamId
;
int32_t
taskId
;
int32_t
upstreamTaskId
;
int32_t
downstreamTaskId
;
int32_t
upstreamNodeId
;
int32_t
childId
;
}
SStreamScanHistoryFinishReq
,
SStreamTransferReq
;
...
...
@@ -519,6 +522,17 @@ int32_t tDecodeSStreamCheckpointReq(SDecoder* pDecoder, SStreamCheckpointReq* pR
int32_t
tEncodeSStreamCheckpointRsp
(
SEncoder
*
pEncoder
,
const
SStreamCheckpointRsp
*
pRsp
);
int32_t
tDecodeSStreamCheckpointRsp
(
SDecoder
*
pDecoder
,
SStreamCheckpointRsp
*
pRsp
);
typedef
struct
{
int64_t
streamId
;
int32_t
upstreamTaskId
;
int32_t
upstreamNodeId
;
int32_t
downstreamId
;
int32_t
downstreamNode
;
}
SStreamCompleteHistoryMsg
;
int32_t
tEncodeCompleteHistoryDataMsg
(
SEncoder
*
pEncoder
,
const
SStreamCompleteHistoryMsg
*
pReq
);
int32_t
tDecodeCompleteHistoryDataMsg
(
SDecoder
*
pDecoder
,
SStreamCompleteHistoryMsg
*
pReq
);
typedef
struct
{
int64_t
streamId
;
int32_t
downstreamTaskId
;
...
...
@@ -559,7 +573,6 @@ int32_t streamProcessDispatchMsg(SStreamTask* pTask, SStreamDispatchReq* pReq, S
int32_t
streamProcessDispatchRsp
(
SStreamTask
*
pTask
,
SStreamDispatchRsp
*
pRsp
,
int32_t
code
);
int32_t
streamProcessRetrieveReq
(
SStreamTask
*
pTask
,
SStreamRetrieveReq
*
pReq
,
SRpcMsg
*
pMsg
);
// int32_t streamProcessRetrieveRsp(SStreamTask* pTask, SStreamRetrieveRsp* pRsp);
void
streamTaskInputFail
(
SStreamTask
*
pTask
);
int32_t
streamTryExec
(
SStreamTask
*
pTask
);
...
...
@@ -569,17 +582,20 @@ bool streamTaskShouldStop(const SStreamStatus* pStatus);
bool
streamTaskShouldPause
(
const
SStreamStatus
*
pStatus
);
bool
streamTaskIsIdle
(
const
SStreamTask
*
pTask
);
SStreamChildEpInfo
*
streamTaskGetUpstreamTaskEpInfo
(
SStreamTask
*
pTask
,
int32_t
taskId
);
int32_t
streamScanExec
(
SStreamTask
*
pTask
,
int32_t
batchSz
);
char
*
createStreamTaskIdStr
(
int64_t
streamId
,
int32_t
taskId
);
// recover and fill history
void
stream
PrepareNdoCheckDownstream
(
SStreamTask
*
pTask
);
int32_t
streamTaskCheckDownstreamTasks
(
SStreamTask
*
pTask
);
void
stream
TaskCheckDownstreamTasks
(
SStreamTask
*
pTask
);
int32_t
streamTask
Do
CheckDownstreamTasks
(
SStreamTask
*
pTask
);
int32_t
streamTaskLaunchScanHistory
(
SStreamTask
*
pTask
);
int32_t
streamTaskCheckStatus
(
SStreamTask
*
pTask
);
int32_t
streamSendCheckRsp
(
const
SStreamMeta
*
pMeta
,
const
SStreamTaskCheckReq
*
pReq
,
SStreamTaskCheckRsp
*
pRsp
,
SRpcHandleInfo
*
pRpcInfo
,
int32_t
taskId
);
int32_t
streamProcessCheckRsp
(
SStreamTask
*
pTask
,
const
SStreamTaskCheckRsp
*
pRsp
);
int32_t
stream
CheckHistoryTaskDownstream
(
SStreamTask
*
pTask
);
int32_t
stream
LaunchFillHistoryTask
(
SStreamTask
*
pTask
);
int32_t
streamTaskScanHistoryDataComplete
(
SStreamTask
*
pTask
);
int32_t
streamStartRecoverTask
(
SStreamTask
*
pTask
,
int8_t
igUntreated
);
void
streamHistoryTaskSetVerRangeStep2
(
SStreamTask
*
pTask
);
...
...
@@ -593,6 +609,9 @@ int32_t streamSetParamForScanHistory(SStreamTask* pTask);
int32_t
streamRestoreParam
(
SStreamTask
*
pTask
);
int32_t
streamSetStatusNormal
(
SStreamTask
*
pTask
);
const
char
*
streamGetTaskStatusStr
(
int32_t
status
);
void
streamTaskPause
(
SStreamTask
*
pTask
);
void
streamTaskDisablePause
(
SStreamTask
*
pTask
);
void
streamTaskEnablePause
(
SStreamTask
*
pTask
);
// source level
int32_t
streamSetParamForStreamScannerStep1
(
SStreamTask
*
pTask
,
SVersionRange
*
pVerRange
,
STimeWindow
*
pWindow
);
...
...
@@ -604,8 +623,9 @@ int32_t streamDispatchScanHistoryFinishMsg(SStreamTask* pTask);
int32_t
streamDispatchTransferStateMsg
(
SStreamTask
*
pTask
);
// agg level
int32_t
streamAggScanHistoryPrepare
(
SStreamTask
*
pTask
);
int32_t
streamProcessScanHistoryFinishReq
(
SStreamTask
*
pTask
,
int32_t
taskId
,
int32_t
childId
);
int32_t
streamTaskScanHistoryPrepare
(
SStreamTask
*
pTask
);
int32_t
streamProcessScanHistoryFinishReq
(
SStreamTask
*
pTask
,
SStreamScanHistoryFinishReq
*
pReq
,
SRpcHandleInfo
*
pRpcInfo
);
int32_t
streamProcessScanHistoryFinishRsp
(
SStreamTask
*
pTask
);
// stream task meta
void
streamMetaInit
();
...
...
source/dnode/mgmt/mgmt_snode/src/smHandle.c
浏览文件 @
ce842ec8
...
...
@@ -79,6 +79,7 @@ SArray *smGetMsgHandles() {
if
(
dmSetMgmtHandle
(
pArray
,
TDMT_STREAM_TASK_CHECK
,
smPutNodeMsgToStreamQueue
,
1
)
==
NULL
)
goto
_OVER
;
if
(
dmSetMgmtHandle
(
pArray
,
TDMT_STREAM_TASK_CHECK_RSP
,
smPutNodeMsgToStreamQueue
,
1
)
==
NULL
)
goto
_OVER
;
if
(
dmSetMgmtHandle
(
pArray
,
TDMT_STREAM_SCAN_HISTORY_FINISH
,
smPutNodeMsgToStreamQueue
,
1
)
==
NULL
)
goto
_OVER
;
if
(
dmSetMgmtHandle
(
pArray
,
TDMT_STREAM_SCAN_HISTORY_FINISH_RSP
,
smPutNodeMsgToStreamQueue
,
1
)
==
NULL
)
goto
_OVER
;
code
=
0
;
_OVER:
...
...
source/dnode/mgmt/mgmt_vnode/src/vmHandle.c
浏览文件 @
ce842ec8
...
...
@@ -740,6 +740,7 @@ SArray *vmGetMsgHandles() {
if
(
dmSetMgmtHandle
(
pArray
,
TDMT_STREAM_RETRIEVE
,
vmPutMsgToStreamQueue
,
0
)
==
NULL
)
goto
_OVER
;
if
(
dmSetMgmtHandle
(
pArray
,
TDMT_STREAM_RETRIEVE_RSP
,
vmPutMsgToStreamQueue
,
0
)
==
NULL
)
goto
_OVER
;
if
(
dmSetMgmtHandle
(
pArray
,
TDMT_STREAM_SCAN_HISTORY_FINISH
,
vmPutMsgToStreamQueue
,
0
)
==
NULL
)
goto
_OVER
;
if
(
dmSetMgmtHandle
(
pArray
,
TDMT_STREAM_SCAN_HISTORY_FINISH_RSP
,
vmPutMsgToStreamQueue
,
0
)
==
NULL
)
goto
_OVER
;
if
(
dmSetMgmtHandle
(
pArray
,
TDMT_STREAM_TRANSFER_STATE
,
vmPutMsgToStreamQueue
,
0
)
==
NULL
)
goto
_OVER
;
if
(
dmSetMgmtHandle
(
pArray
,
TDMT_STREAM_TASK_CHECK
,
vmPutMsgToStreamQueue
,
0
)
==
NULL
)
goto
_OVER
;
if
(
dmSetMgmtHandle
(
pArray
,
TDMT_STREAM_TASK_CHECK_RSP
,
vmPutMsgToStreamQueue
,
0
)
==
NULL
)
goto
_OVER
;
...
...
source/dnode/mnode/impl/src/mndScheduler.c
浏览文件 @
ce842ec8
...
...
@@ -25,6 +25,7 @@
#define SINK_NODE_LEVEL (0)
extern
bool
tsDeployOnSnode
;
static
int32_t
setTaskUpstreamEpInfo
(
const
SStreamTask
*
pTask
,
SStreamTask
*
pDownstream
);
static
int32_t
mndAddSinkTaskToStream
(
SStreamObj
*
pStream
,
SArray
*
pTaskList
,
SMnode
*
pMnode
,
int32_t
vgId
,
SVgObj
*
pVgroup
,
int32_t
fillHistory
);
static
void
setFixedDownstreamEpInfo
(
SStreamTask
*
pDstTask
,
const
SStreamTask
*
pTask
);
...
...
@@ -87,10 +88,10 @@ END:
int32_t
mndSetSinkTaskInfo
(
SStreamObj
*
pStream
,
SStreamTask
*
pTask
)
{
if
(
pStream
->
smaId
!=
0
)
{
pTask
->
output
T
ype
=
TASK_OUTPUT__SMA
;
pTask
->
output
Info
.
t
ype
=
TASK_OUTPUT__SMA
;
pTask
->
smaSink
.
smaId
=
pStream
->
smaId
;
}
else
{
pTask
->
output
T
ype
=
TASK_OUTPUT__TABLE
;
pTask
->
output
Info
.
t
ype
=
TASK_OUTPUT__TABLE
;
pTask
->
tbSink
.
stbUid
=
pStream
->
targetStbUid
;
memcpy
(
pTask
->
tbSink
.
stbFullName
,
pStream
->
targetSTbName
,
TSDB_TABLE_FNAME_LEN
);
pTask
->
tbSink
.
pSchemaWrapper
=
tCloneSSchemaWrapper
(
&
pStream
->
outputSchema
);
...
...
@@ -110,7 +111,7 @@ int32_t mndAddDispatcherForInternalTask(SMnode* pMnode, SStreamObj* pStream, SAr
SDbObj
*
pDb
=
mndAcquireDb
(
pMnode
,
pStream
->
targetDb
);
if
(
pDb
!=
NULL
&&
pDb
->
cfg
.
numOfVgroups
>
1
)
{
isShuffle
=
true
;
pTask
->
output
T
ype
=
TASK_OUTPUT__SHUFFLE_DISPATCH
;
pTask
->
output
Info
.
t
ype
=
TASK_OUTPUT__SHUFFLE_DISPATCH
;
pTask
->
msgInfo
.
msgType
=
TDMT_STREAM_TASK_DISPATCH
;
if
(
mndExtractDbInfo
(
pMnode
,
pDb
,
&
pTask
->
shuffleDispatcher
.
dbInfo
,
NULL
)
<
0
)
{
return
-
1
;
...
...
@@ -267,10 +268,15 @@ static int32_t addSourceStreamTask(SMnode* pMnode, SVgObj* pVgroup, SArray* pTas
return
terrno
;
}
for
(
int32_t
i
=
0
;
i
<
taosArrayGetSize
(
pSinkTaskList
);
++
i
)
{
SStreamTask
*
pSinkTask
=
taosArrayGetP
(
pSinkTaskList
,
i
);
setTaskUpstreamEpInfo
(
pTask
,
pSinkTask
);
}
return
TSDB_CODE_SUCCESS
;
}
static
SStreamChildEpInfo
*
createStreamTaskEpInfo
(
SStreamTask
*
pTask
)
{
static
SStreamChildEpInfo
*
createStreamTaskEpInfo
(
const
SStreamTask
*
pTask
)
{
SStreamChildEpInfo
*
pEpInfo
=
taosMemoryMalloc
(
sizeof
(
SStreamChildEpInfo
));
if
(
pEpInfo
==
NULL
)
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
...
...
@@ -291,11 +297,11 @@ void setFixedDownstreamEpInfo(SStreamTask* pDstTask, const SStreamTask* pTask) {
pDispatcher
->
nodeId
=
pTask
->
info
.
nodeId
;
pDispatcher
->
epSet
=
pTask
->
info
.
epSet
;
pDstTask
->
output
T
ype
=
TASK_OUTPUT__FIXED_DISPATCH
;
pDstTask
->
output
Info
.
t
ype
=
TASK_OUTPUT__FIXED_DISPATCH
;
pDstTask
->
msgInfo
.
msgType
=
TDMT_STREAM_TASK_DISPATCH
;
}
int32_t
set
EpToDownstreamTask
(
SStreamTask
*
pTask
,
SStreamTask
*
pDownstream
)
{
int32_t
set
TaskUpstreamEpInfo
(
const
SStreamTask
*
pTask
,
SStreamTask
*
pDownstream
)
{
SStreamChildEpInfo
*
pEpInfo
=
createStreamTaskEpInfo
(
pTask
);
if
(
pEpInfo
==
NULL
)
{
return
TSDB_CODE_OUT_OF_MEMORY
;
...
...
@@ -418,7 +424,7 @@ static int32_t doAddSourceTask(SArray* pTaskList, int8_t fillHistory, int64_t ui
return
-
1
;
}
return
set
EpToDownstreamTask
(
pTask
,
pDownstreamTask
);
return
set
TaskUpstreamEpInfo
(
pTask
,
pDownstreamTask
);
}
static
int32_t
doAddAggTask
(
uint64_t
uid
,
SArray
*
pTaskList
,
SArray
*
pSinkNodeList
,
SMnode
*
pMnode
,
SStreamObj
*
pStream
,
...
...
@@ -586,6 +592,14 @@ static int32_t addSinkTasks(SArray* pTasksList, SMnode* pMnode, SStreamObj* pStr
return
TSDB_CODE_SUCCESS
;
}
static
void
setSinkTaskUpstreamInfo
(
SArray
*
pTasksList
,
const
SStreamTask
*
pUpstreamTask
)
{
SArray
*
pSinkTaskList
=
taosArrayGetP
(
pTasksList
,
SINK_NODE_LEVEL
);
for
(
int32_t
i
=
0
;
i
<
taosArrayGetSize
(
pSinkTaskList
);
++
i
)
{
SStreamTask
*
pSinkTask
=
taosArrayGetP
(
pSinkTaskList
,
i
);
setTaskUpstreamEpInfo
(
pUpstreamTask
,
pSinkTask
);
}
}
static
int32_t
doScheduleStream
(
SStreamObj
*
pStream
,
SMnode
*
pMnode
,
SQueryPlan
*
pPlan
,
int64_t
nextWindowSkey
)
{
SSdb
*
pSdb
=
pMnode
->
pSdb
;
int32_t
numOfPlanLevel
=
LIST_LENGTH
(
pPlan
->
pSubplans
);
...
...
@@ -637,6 +651,9 @@ static int32_t doScheduleStream(SStreamObj* pStream, SMnode* pMnode, SQueryPlan*
return
code
;
}
setSinkTaskUpstreamInfo
(
pStream
->
tasks
,
pAggTask
);
setSinkTaskUpstreamInfo
(
pStream
->
pHTasksList
,
pHAggTask
);
// source level
return
addSourceTasksForMultiLevelStream
(
pMnode
,
pPlan
,
pStream
,
pAggTask
,
pHAggTask
,
nextWindowSkey
);
}
else
if
(
numOfPlanLevel
==
1
)
{
...
...
source/dnode/snode/src/snode.c
浏览文件 @
ce842ec8
...
...
@@ -66,14 +66,15 @@ int32_t sndExpandTask(SSnode *pSnode, SStreamTask *pTask, int64_t ver) {
pTask
->
status
.
schedStatus
=
TASK_SCHED_STATUS__INACTIVE
;
pTask
->
inputQueue
=
streamQueueOpen
(
512
<<
10
);
pTask
->
output
Q
ueue
=
streamQueueOpen
(
512
<<
10
);
pTask
->
output
Info
.
q
ueue
=
streamQueueOpen
(
512
<<
10
);
if
(
pTask
->
inputQueue
==
NULL
||
pTask
->
output
Q
ueue
==
NULL
)
{
if
(
pTask
->
inputQueue
==
NULL
||
pTask
->
output
Info
.
q
ueue
==
NULL
)
{
return
-
1
;
}
pTask
->
initTs
=
taosGetTimestampMs
();
pTask
->
inputStatus
=
TASK_INPUT_STATUS__NORMAL
;
pTask
->
output
S
tatus
=
TASK_OUTPUT_STATUS__NORMAL
;
pTask
->
output
Info
.
s
tatus
=
TASK_OUTPUT_STATUS__NORMAL
;
pTask
->
pMsgCb
=
&
pSnode
->
msgCb
;
pTask
->
chkInfo
.
version
=
ver
;
pTask
->
pMeta
=
pSnode
->
pMeta
;
...
...
@@ -90,6 +91,7 @@ int32_t sndExpandTask(SSnode *pSnode, SStreamTask *pTask, int64_t ver) {
pTask
->
exec
.
pExecutor
=
qCreateStreamExecTaskInfo
(
pTask
->
exec
.
qmsg
,
&
handle
,
0
);
ASSERT
(
pTask
->
exec
.
pExecutor
);
taosThreadMutexInit
(
&
pTask
->
lock
,
NULL
);
streamSetupScheduleTrigger
(
pTask
);
qDebug
(
"snode:%d expand stream task on snode, s-task:%s, checkpoint ver:%"
PRId64
" child id:%d, level:%d"
,
SNODE_HANDLE
,
...
...
@@ -166,11 +168,10 @@ int32_t sndProcessTaskDeployReq(SSnode *pSnode, char *msg, int32_t msgLen) {
int32_t
numOfTasks
=
streamMetaGetNumOfTasks
(
pSnode
->
pMeta
);
taosWUnLockLatch
(
&
pSnode
->
pMeta
->
lock
);
streamPrepareNdoCheckDownstream
(
pTask
);
qDebug
(
"snode:%d s-task:%s is deployed on snode and add into meta, status:%s, numOfTasks:%d"
,
SNODE_HANDLE
,
pTask
->
id
.
idStr
,
streamGetTaskStatusStr
(
pTask
->
status
.
taskStatus
),
numOfTasks
);
streamTaskCheckDownstreamTasks
(
pTask
);
return
0
;
}
...
...
@@ -274,7 +275,7 @@ int32_t sndProcessWriteMsg(SSnode *pSnode, SRpcMsg *pMsg, SRpcMsg *pRsp) {
return
0
;
}
int32_t
sndProcess
TaskRecover
FinishReq
(
SSnode
*
pSnode
,
SRpcMsg
*
pMsg
)
{
int32_t
sndProcess
StreamTaskScanHistory
FinishReq
(
SSnode
*
pSnode
,
SRpcMsg
*
pMsg
)
{
char
*
msg
=
POINTER_SHIFT
(
pMsg
->
pCont
,
sizeof
(
SMsgHead
));
int32_t
msgLen
=
pMsg
->
contLen
-
sizeof
(
SMsgHead
);
...
...
@@ -287,12 +288,12 @@ int32_t sndProcessTaskRecoverFinishReq(SSnode *pSnode, SRpcMsg *pMsg) {
tDecoderClear
(
&
decoder
);
// find task
SStreamTask
*
pTask
=
streamMetaAcquireTask
(
pSnode
->
pMeta
,
req
.
t
askId
);
SStreamTask
*
pTask
=
streamMetaAcquireTask
(
pSnode
->
pMeta
,
req
.
downstreamT
askId
);
if
(
pTask
==
NULL
)
{
return
-
1
;
}
// do process request
if
(
streamProcessScanHistoryFinishReq
(
pTask
,
req
.
taskId
,
req
.
childId
)
<
0
)
{
if
(
streamProcessScanHistoryFinishReq
(
pTask
,
&
req
,
&
pMsg
->
info
)
<
0
)
{
streamMetaReleaseTask
(
pSnode
->
pMeta
,
pTask
);
return
-
1
;
}
...
...
@@ -415,7 +416,7 @@ int32_t sndProcessStreamMsg(SSnode *pSnode, SRpcMsg *pMsg) {
case
TDMT_STREAM_RETRIEVE_RSP
:
return
sndProcessTaskRetrieveRsp
(
pSnode
,
pMsg
);
case
TDMT_STREAM_SCAN_HISTORY_FINISH
:
return
sndProcess
TaskRecover
FinishReq
(
pSnode
,
pMsg
);
return
sndProcess
StreamTaskScanHistory
FinishReq
(
pSnode
,
pMsg
);
case
TDMT_STREAM_SCAN_HISTORY_FINISH_RSP
:
return
sndProcessTaskRecoverFinishRsp
(
pSnode
,
pMsg
);
case
TDMT_STREAM_TASK_CHECK
:
...
...
source/dnode/vnode/src/inc/vnodeInt.h
浏览文件 @
ce842ec8
...
...
@@ -250,8 +250,8 @@ int32_t tqProcessTaskRetrieveReq(STQ* pTq, SRpcMsg* pMsg);
int32_t
tqProcessTaskRetrieveRsp
(
STQ
*
pTq
,
SRpcMsg
*
pMsg
);
int32_t
tqProcessTaskScanHistory
(
STQ
*
pTq
,
SRpcMsg
*
pMsg
);
int32_t
tqProcessTaskTransferStateReq
(
STQ
*
pTq
,
SRpcMsg
*
pMsg
);
int32_t
tqProcess
Stream
TaskScanHistoryFinishReq
(
STQ
*
pTq
,
SRpcMsg
*
pMsg
);
int32_t
tqProcessTask
Recover
FinishRsp
(
STQ
*
pTq
,
SRpcMsg
*
pMsg
);
int32_t
tqProcessTaskScanHistoryFinishReq
(
STQ
*
pTq
,
SRpcMsg
*
pMsg
);
int32_t
tqProcessTask
ScanHistory
FinishRsp
(
STQ
*
pTq
,
SRpcMsg
*
pMsg
);
int32_t
tqCheckLogInWal
(
STQ
*
pTq
,
int64_t
version
);
// sma
...
...
source/dnode/vnode/src/tq/tq.c
浏览文件 @
ce842ec8
此差异已折叠。
点击以展开。
source/dnode/vnode/src/tq/tqRestore.c
浏览文件 @
ce842ec8
...
...
@@ -80,11 +80,17 @@ int32_t tqStreamTasksStatusCheck(STQ* pTq) {
continue
;
}
streamTaskCheckDownstreamTasks
(
pTask
);
if
(
pTask
->
info
.
fillHistory
==
1
)
{
tqDebug
(
"s-task:%s fill-history task, wait for related stream task:0x%x to launch it"
,
pTask
->
id
.
idStr
,
pTask
->
streamTaskId
.
taskId
);
continue
;
}
streamTaskDoCheckDownstreamTasks
(
pTask
);
streamMetaReleaseTask
(
pMeta
,
pTask
);
}
taosArrayDestroy
(
pTaskList
);
taosArrayDestroy
(
pTaskList
);
return
0
;
}
...
...
source/dnode/vnode/src/vnd/vnodeSvr.c
浏览文件 @
ce842ec8
...
...
@@ -664,9 +664,9 @@ int32_t vnodeProcessStreamMsg(SVnode *pVnode, SRpcMsg *pMsg, SQueueInfo *pInfo)
case
TDMT_STREAM_TRANSFER_STATE
:
return
tqProcessTaskTransferStateReq
(
pVnode
->
pTq
,
pMsg
);
case
TDMT_STREAM_SCAN_HISTORY_FINISH
:
return
tqProcess
Stream
TaskScanHistoryFinishReq
(
pVnode
->
pTq
,
pMsg
);
return
tqProcessTaskScanHistoryFinishReq
(
pVnode
->
pTq
,
pMsg
);
case
TDMT_STREAM_SCAN_HISTORY_FINISH_RSP
:
return
tqProcessTask
Recover
FinishRsp
(
pVnode
->
pTq
,
pMsg
);
return
tqProcessTask
ScanHistory
FinishRsp
(
pVnode
->
pTq
,
pMsg
);
default:
vError
(
"unknown msg type:%d in stream queue"
,
pMsg
->
msgType
);
return
TSDB_CODE_APP_ERROR
;
...
...
source/libs/executor/src/executor.c
浏览文件 @
ce842ec8
...
...
@@ -122,7 +122,7 @@ void qResetStreamInfoTimeWindow(qTaskInfo_t tinfo) {
return
;
}
qDebug
(
"%s set fill history start key:%"
PRId64
,
GET_TASKID
(
pTaskInfo
),
INT64_MIN
);
qDebug
(
"%s set fill history start key:%"
PRId64
,
GET_TASKID
(
pTaskInfo
),
INT64_MIN
);
pTaskInfo
->
streamInfo
.
fillHistoryWindow
.
skey
=
INT64_MIN
;
}
...
...
source/libs/stream/inc/streamInt.h
浏览文件 @
ce842ec8
...
...
@@ -31,6 +31,12 @@ typedef struct {
void
*
timer
;
}
SStreamGlobalEnv
;
typedef
struct
{
SEpSet
epset
;
int32_t
taskId
;
SRpcMsg
msg
;
}
SStreamContinueExecInfo
;
extern
SStreamGlobalEnv
streamEnv
;
void
streamRetryDispatchStreamBlock
(
SStreamTask
*
pTask
,
int64_t
waitDuration
);
...
...
@@ -54,6 +60,9 @@ int32_t streamDoDispatchScanHistoryFinishMsg(SStreamTask* pTask, const SStreamSc
SStreamQueueItem
*
streamMergeQueueItem
(
SStreamQueueItem
*
dst
,
SStreamQueueItem
*
pElem
);
int32_t
streamAddEndScanHistoryMsg
(
SStreamTask
*
pTask
,
SRpcHandleInfo
*
pRpcInfo
,
SStreamScanHistoryFinishReq
*
pReq
);
int32_t
streamNotifyUpstreamContinue
(
SStreamTask
*
pTask
);
extern
int32_t
streamBackendId
;
extern
int32_t
streamBackendCfWrapperId
;
...
...
source/libs/stream/src/stream.c
浏览文件 @
ce842ec8
...
...
@@ -216,15 +216,16 @@ int32_t streamTaskEnqueueRetrieve(SStreamTask* pTask, SStreamRetrieveReq* pReq,
// todo add log
int32_t
streamTaskOutputResultBlock
(
SStreamTask
*
pTask
,
SStreamDataBlock
*
pBlock
)
{
int32_t
code
=
0
;
if
(
pTask
->
outputType
==
TASK_OUTPUT__TABLE
)
{
int32_t
type
=
pTask
->
outputInfo
.
type
;
if
(
type
==
TASK_OUTPUT__TABLE
)
{
pTask
->
tbSink
.
tbSinkFunc
(
pTask
,
pTask
->
tbSink
.
vnode
,
0
,
pBlock
->
blocks
);
destroyStreamDataBlock
(
pBlock
);
}
else
if
(
pTask
->
outputT
ype
==
TASK_OUTPUT__SMA
)
{
}
else
if
(
t
ype
==
TASK_OUTPUT__SMA
)
{
pTask
->
smaSink
.
smaSink
(
pTask
->
smaSink
.
vnode
,
pTask
->
smaSink
.
smaId
,
pBlock
->
blocks
);
destroyStreamDataBlock
(
pBlock
);
}
else
{
ASSERT
(
pTask
->
outputType
==
TASK_OUTPUT__FIXED_DISPATCH
||
pTask
->
outputT
ype
==
TASK_OUTPUT__SHUFFLE_DISPATCH
);
code
=
taosWriteQitem
(
pTask
->
output
Q
ueue
->
queue
,
pBlock
);
ASSERT
(
type
==
TASK_OUTPUT__FIXED_DISPATCH
||
t
ype
==
TASK_OUTPUT__SHUFFLE_DISPATCH
);
code
=
taosWriteQitem
(
pTask
->
output
Info
.
q
ueue
->
queue
,
pBlock
);
if
(
code
!=
0
)
{
// todo failed to add it into the output queue, free it.
return
code
;
}
...
...
@@ -274,7 +275,7 @@ int32_t streamProcessDispatchRsp(SStreamTask* pTask, SStreamDispatchRsp* pRsp, i
qDebug
(
"s-task:%s receive dispatch rsp, output status:%d code:%d"
,
pTask
->
id
.
idStr
,
pRsp
->
inputStatus
,
code
);
// there are other dispatch message not response yet
if
(
pTask
->
output
T
ype
==
TASK_OUTPUT__SHUFFLE_DISPATCH
)
{
if
(
pTask
->
output
Info
.
t
ype
==
TASK_OUTPUT__SHUFFLE_DISPATCH
)
{
int32_t
leftRsp
=
atomic_sub_fetch_32
(
&
pTask
->
shuffleDispatcher
.
waitingRspCnt
,
1
);
qDebug
(
"s-task:%s is shuffle, left waiting rsp %d"
,
pTask
->
id
.
idStr
,
leftRsp
);
if
(
leftRsp
>
0
)
{
...
...
@@ -283,9 +284,9 @@ int32_t streamProcessDispatchRsp(SStreamTask* pTask, SStreamDispatchRsp* pRsp, i
}
pTask
->
msgInfo
.
retryCount
=
0
;
ASSERT
(
pTask
->
output
S
tatus
==
TASK_OUTPUT_STATUS__WAIT
);
ASSERT
(
pTask
->
output
Info
.
s
tatus
==
TASK_OUTPUT_STATUS__WAIT
);
qDebug
(
"s-task:%s output status is set to:%d"
,
pTask
->
id
.
idStr
,
pTask
->
output
S
tatus
);
qDebug
(
"s-task:%s output status is set to:%d"
,
pTask
->
id
.
idStr
,
pTask
->
output
Info
.
s
tatus
);
// the input queue of the (down stream) task that receive the output data is full,
// so the TASK_INPUT_STATUS_BLOCKED is rsp
...
...
@@ -309,7 +310,7 @@ int32_t streamProcessDispatchRsp(SStreamTask* pTask, SStreamDispatchRsp* pRsp, i
}
// now ready for next data output
atomic_store_8
(
&
pTask
->
output
S
tatus
,
TASK_OUTPUT_STATUS__NORMAL
);
atomic_store_8
(
&
pTask
->
output
Info
.
s
tatus
,
TASK_OUTPUT_STATUS__NORMAL
);
// otherwise, continue dispatch the first block to down stream task in pipeline
streamDispatchStreamBlock
(
pTask
);
...
...
@@ -419,3 +420,15 @@ void* streamQueueNextItem(SStreamQueue* pQueue) {
}
void
streamTaskInputFail
(
SStreamTask
*
pTask
)
{
atomic_store_8
(
&
pTask
->
inputStatus
,
TASK_INPUT_STATUS__FAILED
);
}
SStreamChildEpInfo
*
streamTaskGetUpstreamTaskEpInfo
(
SStreamTask
*
pTask
,
int32_t
taskId
)
{
int32_t
num
=
taosArrayGetSize
(
pTask
->
pUpstreamEpInfoList
);
for
(
int32_t
i
=
0
;
i
<
num
;
++
i
)
{
SStreamChildEpInfo
*
pInfo
=
taosArrayGetP
(
pTask
->
pUpstreamEpInfoList
,
i
);
if
(
pInfo
->
taskId
==
taskId
)
{
return
pInfo
;
}
}
return
NULL
;
}
\ No newline at end of file
source/libs/stream/src/streamDispatch.c
浏览文件 @
ce842ec8
...
...
@@ -25,6 +25,12 @@ typedef struct SBlockName {
char
parTbName
[
TSDB_TABLE_NAME_LEN
];
}
SBlockName
;
static
void
initRpcMsg
(
SRpcMsg
*
pMsg
,
int32_t
msgType
,
void
*
pCont
,
int32_t
contLen
)
{
pMsg
->
msgType
=
msgType
;
pMsg
->
pCont
=
pCont
;
pMsg
->
contLen
=
contLen
;
}
static
int32_t
tEncodeStreamDispatchReq
(
SEncoder
*
pEncoder
,
const
SStreamDispatchReq
*
pReq
)
{
if
(
tStartEncode
(
pEncoder
)
<
0
)
return
-
1
;
if
(
tEncodeI64
(
pEncoder
,
pReq
->
streamId
)
<
0
)
return
-
1
;
...
...
@@ -311,13 +317,12 @@ int32_t streamDoDispatchScanHistoryFinishMsg(SStreamTask* pTask, const SStreamSc
msg
.
contLen
=
tlen
+
sizeof
(
SMsgHead
);
msg
.
pCont
=
buf
;
msg
.
msgType
=
TDMT_STREAM_SCAN_HISTORY_FINISH
;
msg
.
info
.
noResp
=
1
;
tmsgSendReq
(
pEpSet
,
&
msg
);
const
char
*
pStatus
=
streamGetTaskStatusStr
(
pTask
->
status
.
taskStatus
);
qDebug
(
"s-task:%s status:%s dispatch scan-history
-data
finish msg to taskId:0x%x (vgId:%d)"
,
pTask
->
id
.
idStr
,
pStatus
,
pReq
->
t
askId
,
vgId
);
qDebug
(
"s-task:%s status:%s dispatch scan-history finish msg to taskId:0x%x (vgId:%d)"
,
pTask
->
id
.
idStr
,
pStatus
,
pReq
->
downstreamT
askId
,
vgId
);
return
0
;
}
...
...
@@ -437,7 +442,7 @@ int32_t streamDispatchAllBlocks(SStreamTask* pTask, const SStreamDataBlock* pDat
int32_t
numOfBlocks
=
taosArrayGetSize
(
pData
->
blocks
);
ASSERT
(
numOfBlocks
!=
0
);
if
(
pTask
->
output
T
ype
==
TASK_OUTPUT__FIXED_DISPATCH
)
{
if
(
pTask
->
output
Info
.
t
ype
==
TASK_OUTPUT__FIXED_DISPATCH
)
{
SStreamDispatchReq
req
=
{
0
};
int32_t
downstreamTaskId
=
pTask
->
fixedEpDispatcher
.
taskId
;
...
...
@@ -467,7 +472,7 @@ int32_t streamDispatchAllBlocks(SStreamTask* pTask, const SStreamDataBlock* pDat
taosArrayDestroyP
(
req
.
data
,
taosMemoryFree
);
taosArrayDestroy
(
req
.
dataLen
);
return
code
;
}
else
if
(
pTask
->
output
T
ype
==
TASK_OUTPUT__SHUFFLE_DISPATCH
)
{
}
else
if
(
pTask
->
output
Info
.
t
ype
==
TASK_OUTPUT__SHUFFLE_DISPATCH
)
{
int32_t
rspCnt
=
atomic_load_32
(
&
pTask
->
shuffleDispatcher
.
waitingRspCnt
);
ASSERT
(
rspCnt
==
0
);
...
...
@@ -545,7 +550,7 @@ int32_t streamDispatchAllBlocks(SStreamTask* pTask, const SStreamDataBlock* pDat
static
void
doRetryDispatchData
(
void
*
param
,
void
*
tmrId
)
{
SStreamTask
*
pTask
=
param
;
ASSERT
(
pTask
->
output
S
tatus
==
TASK_OUTPUT_STATUS__WAIT
);
ASSERT
(
pTask
->
output
Info
.
s
tatus
==
TASK_OUTPUT_STATUS__WAIT
);
int32_t
code
=
streamDispatchAllBlocks
(
pTask
,
pTask
->
msgInfo
.
pData
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
...
...
@@ -561,29 +566,29 @@ void streamRetryDispatchStreamBlock(SStreamTask* pTask, int64_t waitDuration) {
}
int32_t
streamDispatchStreamBlock
(
SStreamTask
*
pTask
)
{
ASSERT
((
pTask
->
outputType
==
TASK_OUTPUT__FIXED_DISPATCH
||
pTask
->
outputType
==
TASK_OUTPUT__SHUFFLE_DISPATCH
));
STaskOutputInfo
*
pInfo
=
&
pTask
->
outputInfo
;
ASSERT
((
pInfo
->
type
==
TASK_OUTPUT__FIXED_DISPATCH
||
pInfo
->
type
==
TASK_OUTPUT__SHUFFLE_DISPATCH
));
int32_t
numOfElems
=
taosQueueItemSize
(
p
Task
->
outputQ
ueue
->
queue
);
int32_t
numOfElems
=
taosQueueItemSize
(
p
Info
->
q
ueue
->
queue
);
if
(
numOfElems
>
0
)
{
qDebug
(
"s-task:%s try to dispatch intermediate result block to downstream, elem in outputQ:%d"
,
pTask
->
id
.
idStr
,
numOfElems
);
}
// to make sure only one dispatch is running
int8_t
old
=
atomic_val_compare_exchange_8
(
&
pTask
->
outputStatus
,
TASK_OUTPUT_STATUS__NORMAL
,
TASK_OUTPUT_STATUS__WAIT
);
int8_t
old
=
atomic_val_compare_exchange_8
(
&
pInfo
->
status
,
TASK_OUTPUT_STATUS__NORMAL
,
TASK_OUTPUT_STATUS__WAIT
);
if
(
old
!=
TASK_OUTPUT_STATUS__NORMAL
)
{
qDebug
(
"s-task:%s wait for dispatch rsp, not dispatch now, output status:%d"
,
pTask
->
id
.
idStr
,
old
);
return
0
;
}
ASSERT
(
pTask
->
msgInfo
.
pData
==
NULL
);
qDebug
(
"s-task:%s start to dispatch msg, set output status:%d"
,
pTask
->
id
.
idStr
,
p
Task
->
outputS
tatus
);
qDebug
(
"s-task:%s start to dispatch msg, set output status:%d"
,
pTask
->
id
.
idStr
,
p
Info
->
s
tatus
);
SStreamDataBlock
*
pBlock
=
streamQueueNextItem
(
p
Task
->
outputQ
ueue
);
SStreamDataBlock
*
pBlock
=
streamQueueNextItem
(
p
Info
->
q
ueue
);
if
(
pBlock
==
NULL
)
{
atomic_store_8
(
&
p
Task
->
outputS
tatus
,
TASK_OUTPUT_STATUS__NORMAL
);
qDebug
(
"s-task:%s not dispatch since no elems in outputQ, output status:%d"
,
pTask
->
id
.
idStr
,
p
Task
->
outputS
tatus
);
atomic_store_8
(
&
p
Info
->
s
tatus
,
TASK_OUTPUT_STATUS__NORMAL
);
qDebug
(
"s-task:%s not dispatch since no elems in outputQ, output status:%d"
,
pTask
->
id
.
idStr
,
p
Info
->
s
tatus
);
return
0
;
}
...
...
@@ -599,7 +604,7 @@ int32_t streamDispatchStreamBlock(SStreamTask* pTask) {
}
qDebug
(
"s-task:%s failed to dispatch msg to downstream, code:%s, output status:%d, retry cnt:%d"
,
pTask
->
id
.
idStr
,
tstrerror
(
terrno
),
p
Task
->
outputS
tatus
,
retryCount
);
tstrerror
(
terrno
),
p
Info
->
s
tatus
,
retryCount
);
// todo deal with only partially success dispatch case
atomic_store_32
(
&
pTask
->
shuffleDispatcher
.
waitingRspCnt
,
0
);
...
...
@@ -610,8 +615,8 @@ int32_t streamDispatchStreamBlock(SStreamTask* pTask) {
}
if
(
++
retryCount
>
MAX_CONTINUE_RETRY_COUNT
)
{
// add to timer to retry
qDebug
(
"s-task:%s failed to dispatch msg to downstream for %d times, code:%s, add timer to retry in %dms"
,
pTask
->
id
.
idStr
,
retryCount
,
tstrerror
(
terrno
),
DISPATCH_RETRY_INTERVAL_MS
);
qDebug
(
"s-task:%s failed to dispatch msg to downstream for %d times, code:%s, add timer to retry in %dms"
,
pTask
->
id
.
idStr
,
retryCount
,
tstrerror
(
terrno
),
DISPATCH_RETRY_INTERVAL_MS
);
streamRetryDispatchStreamBlock
(
pTask
,
DISPATCH_RETRY_INTERVAL_MS
);
break
;
}
...
...
@@ -620,3 +625,93 @@ int32_t streamDispatchStreamBlock(SStreamTask* pTask) {
// this block can not be deleted until it has been sent to downstream task successfully.
return
TSDB_CODE_SUCCESS
;
}
int32_t
tEncodeCompleteHistoryDataMsg
(
SEncoder
*
pEncoder
,
const
SStreamCompleteHistoryMsg
*
pReq
)
{
if
(
tStartEncode
(
pEncoder
)
<
0
)
return
-
1
;
if
(
tEncodeI64
(
pEncoder
,
pReq
->
streamId
)
<
0
)
return
-
1
;
if
(
tEncodeI32
(
pEncoder
,
pReq
->
downstreamId
)
<
0
)
return
-
1
;
if
(
tEncodeI32
(
pEncoder
,
pReq
->
downstreamNode
)
<
0
)
return
-
1
;
if
(
tEncodeI32
(
pEncoder
,
pReq
->
upstreamTaskId
)
<
0
)
return
-
1
;
if
(
tEncodeI32
(
pEncoder
,
pReq
->
upstreamNodeId
)
<
0
)
return
-
1
;
tEndEncode
(
pEncoder
);
return
pEncoder
->
pos
;
}
int32_t
tDecodeCompleteHistoryDataMsg
(
SDecoder
*
pDecoder
,
SStreamCompleteHistoryMsg
*
pRsp
)
{
if
(
tStartDecode
(
pDecoder
)
<
0
)
return
-
1
;
if
(
tDecodeI64
(
pDecoder
,
&
pRsp
->
streamId
)
<
0
)
return
-
1
;
if
(
tDecodeI32
(
pDecoder
,
&
pRsp
->
downstreamId
)
<
0
)
return
-
1
;
if
(
tDecodeI32
(
pDecoder
,
&
pRsp
->
downstreamNode
)
<
0
)
return
-
1
;
if
(
tDecodeI32
(
pDecoder
,
&
pRsp
->
upstreamTaskId
)
<
0
)
return
-
1
;
if
(
tDecodeI32
(
pDecoder
,
&
pRsp
->
upstreamNodeId
)
<
0
)
return
-
1
;
tEndDecode
(
pDecoder
);
return
0
;
}
int32_t
streamAddEndScanHistoryMsg
(
SStreamTask
*
pTask
,
SRpcHandleInfo
*
pRpcInfo
,
SStreamScanHistoryFinishReq
*
pReq
)
{
int32_t
len
=
0
;
int32_t
code
=
0
;
SEncoder
encoder
;
SStreamCompleteHistoryMsg
msg
=
{
.
streamId
=
pReq
->
streamId
,
.
upstreamTaskId
=
pReq
->
upstreamTaskId
,
.
upstreamNodeId
=
pReq
->
upstreamNodeId
,
.
downstreamId
=
pReq
->
downstreamTaskId
,
.
downstreamNode
=
pTask
->
pMeta
->
vgId
,
};
tEncodeSize
(
tEncodeCompleteHistoryDataMsg
,
&
msg
,
len
,
code
);
if
(
code
<
0
)
{
return
code
;
}
void
*
pBuf
=
rpcMallocCont
(
sizeof
(
SMsgHead
)
+
len
);
if
(
pBuf
==
NULL
)
{
return
TSDB_CODE_OUT_OF_MEMORY
;
}
((
SMsgHead
*
)
pBuf
)
->
vgId
=
htonl
(
pReq
->
upstreamNodeId
);
void
*
abuf
=
POINTER_SHIFT
(
pBuf
,
sizeof
(
SMsgHead
));
tEncoderInit
(
&
encoder
,
(
uint8_t
*
)
abuf
,
len
);
tEncodeCompleteHistoryDataMsg
(
&
encoder
,
&
msg
);
tEncoderClear
(
&
encoder
);
SStreamChildEpInfo
*
pInfo
=
streamTaskGetUpstreamTaskEpInfo
(
pTask
,
pReq
->
upstreamTaskId
);
SStreamContinueExecInfo
info
=
{.
taskId
=
pReq
->
upstreamTaskId
,
.
epset
=
pInfo
->
epSet
};
initRpcMsg
(
&
info
.
msg
,
0
,
pBuf
,
sizeof
(
SMsgHead
)
+
len
);
info
.
msg
.
info
=
*
pRpcInfo
;
taosThreadMutexLock
(
&
pTask
->
lock
);
if
(
pTask
->
pRspMsgList
==
NULL
)
{
pTask
->
pRspMsgList
=
taosArrayInit
(
4
,
sizeof
(
SStreamContinueExecInfo
));
}
taosArrayPush
(
pTask
->
pRspMsgList
,
&
info
);
taosThreadMutexUnlock
(
&
pTask
->
lock
);
int32_t
num
=
taosArrayGetSize
(
pTask
->
pRspMsgList
);
qDebug
(
"s-task:%s add scan history finish rsp msg for task:0x%x, total:%d"
,
pTask
->
id
.
idStr
,
pReq
->
upstreamTaskId
,
num
);
return
TSDB_CODE_SUCCESS
;
}
int32_t
streamNotifyUpstreamContinue
(
SStreamTask
*
pTask
)
{
ASSERT
(
pTask
->
info
.
taskLevel
==
TASK_LEVEL__AGG
||
pTask
->
info
.
taskLevel
==
TASK_LEVEL__SINK
);
int32_t
num
=
taosArrayGetSize
(
pTask
->
pRspMsgList
);
for
(
int32_t
i
=
0
;
i
<
num
;
++
i
)
{
SStreamContinueExecInfo
*
pInfo
=
taosArrayGet
(
pTask
->
pRspMsgList
,
i
);
tmsgSendRsp
(
&
pInfo
->
msg
);
qDebug
(
"s-task:%s level:%d notify upstream:0x%x to continue process data from WAL"
,
pTask
->
id
.
idStr
,
pTask
->
info
.
taskLevel
,
pInfo
->
taskId
);
}
taosArrayClear
(
pTask
->
pRspMsgList
);
qDebug
(
"s-task:%s level:%d checkpoint ready msg sent to all %d upstreams"
,
pTask
->
id
.
idStr
,
pTask
->
info
.
taskLevel
,
num
);
return
0
;
}
source/libs/stream/src/streamExec.c
浏览文件 @
ce842ec8
...
...
@@ -351,30 +351,40 @@ static void waitForTaskIdle(SStreamTask* pTask, SStreamTask* pStreamTask) {
}
static
int32_t
streamTransferStateToStreamTask
(
SStreamTask
*
pTask
)
{
SStreamTask
*
pStreamTask
=
streamMetaAcquireTask
(
pTask
->
pMeta
,
pTask
->
streamTaskId
.
taskId
);
SStreamMeta
*
pMeta
=
pTask
->
pMeta
;
SStreamTask
*
pStreamTask
=
streamMetaAcquireTask
(
pMeta
,
pTask
->
streamTaskId
.
taskId
);
if
(
pStreamTask
==
NULL
)
{
qError
(
"s-task:%s failed to find related stream task:0x%x, it may have been destroyed or closed"
,
pTask
->
id
.
idStr
,
pTask
->
streamTaskId
.
taskId
);
pTask
->
status
.
transferState
=
false
;
// reset this value, to avoid transfer state again
qError
(
"s-task:%s failed to find related stream task:0x%x, it may have been destroyed or closed"
,
pTask
->
id
.
idStr
,
pTask
->
streamTaskId
.
taskId
);
return
TSDB_CODE_STREAM_TASK_NOT_EXIST
;
}
else
{
qDebug
(
"s-task:%s fill-history task end, update related stream task:%s info, transfer exec state"
,
pTask
->
id
.
idStr
,
pStreamTask
->
id
.
idStr
);
}
ASSERT
(
pStreamTask
!=
NULL
&&
pStreamTask
->
historyTaskId
.
taskId
==
pTask
->
id
.
taskId
);
// todo fix race condition
streamTaskDisablePause
(
pTask
);
streamTaskDisablePause
(
pStreamTask
);
ASSERT
(
pStreamTask
->
historyTaskId
.
taskId
==
pTask
->
id
.
taskId
&&
pTask
->
status
.
transferState
==
true
);
STimeWindow
*
pTimeWindow
=
&
pStreamTask
->
dataRange
.
window
;
// It must be halted for a source stream task, since when the related scan-history-data task start scan the history
// for the step 2. For a agg task
int8_t
status
=
pStreamTask
->
status
.
taskStatus
;
if
(
pStreamTask
->
info
.
taskLevel
==
TASK_LEVEL__SOURCE
)
{
ASSERT
(
pStreamTask
->
status
.
taskS
tatus
==
TASK_STATUS__HALT
);
ASSERT
(
s
tatus
==
TASK_STATUS__HALT
);
}
else
{
ASSERT
(
pStreamTask
->
status
.
taskStatus
==
TASK_STATUS__NORMAL
);
ASSERT
(
status
==
TASK_STATUS__SCAN_HISTORY
);
pStreamTask
->
status
.
taskStatus
=
TASK_STATUS__HALT
;
qDebug
(
"s-task:%s
status:
halt by related fill history task:%s"
,
pStreamTask
->
id
.
idStr
,
pTask
->
id
.
idStr
);
qDebug
(
"s-task:%s halt by related fill history task:%s"
,
pStreamTask
->
id
.
idStr
,
pTask
->
id
.
idStr
);
}
// wait for the stream task to be idle
// wait for the stream task to
handle all in the inputQ, and to
be idle
waitForTaskIdle
(
pTask
,
pStreamTask
);
// In case of sink tasks, no need to be halted for them.
...
...
@@ -399,10 +409,27 @@ static int32_t streamTransferStateToStreamTask(SStreamTask* pTask) {
streamTaskReleaseState
(
pTask
);
streamTaskReloadState
(
pStreamTask
);
// reset the status of stream task
streamSetStatusNormal
(
pStreamTask
);
pTask
->
status
.
taskStatus
=
TASK_STATUS__DROPPING
;
qDebug
(
"s-task:%s fill-history task set status to be dropping, save the state into disk"
,
pTask
->
id
.
idStr
);
// save to disk
taosWLockLatch
(
&
pMeta
->
lock
);
streamMetaSaveTask
(
pMeta
,
pTask
);
streamMetaSaveTask
(
pMeta
,
pStreamTask
);
if
(
streamMetaCommit
(
pMeta
)
<
0
)
{
// persist to disk
}
taosWUnLockLatch
(
&
pMeta
->
lock
);
// pause allowed
streamTaskEnablePause
(
pStreamTask
);
streamTaskEnablePause
(
pTask
);
streamSchedExec
(
pStreamTask
);
streamMetaReleaseTask
(
p
Task
->
p
Meta
,
pStreamTask
);
streamMetaReleaseTask
(
pMeta
,
pStreamTask
);
return
TSDB_CODE_SUCCESS
;
}
...
...
@@ -480,7 +507,6 @@ int32_t streamExecForAll(SStreamTask* pTask) {
ASSERT
(
batchSize
==
0
);
if
(
pTask
->
info
.
fillHistory
&&
pTask
->
status
.
transferState
)
{
int32_t
code
=
streamTransferStateToStreamTask
(
pTask
);
pTask
->
status
.
transferState
=
false
;
// reset this value, to avoid transfer state again
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
// todo handle this
return
0
;
}
...
...
@@ -550,22 +576,7 @@ int32_t streamExecForAll(SStreamTask* pTask) {
}
bool
streamTaskIsIdle
(
const
SStreamTask
*
pTask
)
{
int32_t
numOfItems
=
taosQueueItemSize
(
pTask
->
inputQueue
->
queue
);
if
(
numOfItems
>
0
)
{
return
false
;
}
numOfItems
=
taosQallItemSize
(
pTask
->
inputQueue
->
qall
);
if
(
numOfItems
>
0
)
{
return
false
;
}
// blocked by downstream task
if
(
pTask
->
outputStatus
==
TASK_OUTPUT_STATUS__BLOCKED
)
{
return
false
;
}
return
(
pTask
->
status
.
schedStatus
==
TASK_SCHED_STATUS__INACTIVE
);
return
(
pTask
->
status
.
schedStatus
==
TASK_SCHED_STATUS__INACTIVE
/* && pTask->status.taskStatus != TASK_STATUS__HALT*/
);
}
int32_t
streamTryExec
(
SStreamTask
*
pTask
)
{
...
...
source/libs/stream/src/streamMeta.c
浏览文件 @
ce842ec8
...
...
@@ -266,7 +266,7 @@ SStreamTask* streamMetaAcquireTask(SStreamMeta* pMeta, int32_t taskId) {
if
(
!
streamTaskShouldStop
(
&
(
*
ppTask
)
->
status
))
{
int32_t
ref
=
atomic_add_fetch_32
(
&
(
*
ppTask
)
->
refCnt
,
1
);
taosRUnLockLatch
(
&
pMeta
->
lock
);
q
Debug
(
"s-task:%s acquire task, ref:%d"
,
(
*
ppTask
)
->
id
.
idStr
,
ref
);
q
Trace
(
"s-task:%s acquire task, ref:%d"
,
(
*
ppTask
)
->
id
.
idStr
,
ref
);
return
*
ppTask
;
}
}
...
...
@@ -278,7 +278,7 @@ SStreamTask* streamMetaAcquireTask(SStreamMeta* pMeta, int32_t taskId) {
void
streamMetaReleaseTask
(
SStreamMeta
*
pMeta
,
SStreamTask
*
pTask
)
{
int32_t
ref
=
atomic_sub_fetch_32
(
&
pTask
->
refCnt
,
1
);
if
(
ref
>
0
)
{
q
Debug
(
"s-task:%s release task, ref:%d"
,
pTask
->
id
.
idStr
,
ref
);
q
Trace
(
"s-task:%s release task, ref:%d"
,
pTask
->
id
.
idStr
,
ref
);
}
else
if
(
ref
==
0
)
{
ASSERT
(
streamTaskShouldStop
(
&
pTask
->
status
));
tFreeStreamTask
(
pTask
);
...
...
source/libs/stream/src/streamRecover.c
浏览文件 @
ce842ec8
此差异已折叠。
点击以展开。
source/libs/stream/src/streamTask.c
浏览文件 @
ce842ec8
...
...
@@ -13,6 +13,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <libs/transport/trpc.h>
#include <streamInt.h>
#include "executor.h"
#include "tstream.h"
#include "wal.h"
...
...
@@ -44,7 +46,7 @@ SStreamTask* tNewStreamTask(int64_t streamId, int8_t taskLevel, int8_t fillHisto
pTask
->
status
.
schedStatus
=
TASK_SCHED_STATUS__INACTIVE
;
pTask
->
status
.
taskStatus
=
TASK_STATUS__SCAN_HISTORY
;
pTask
->
inputStatus
=
TASK_INPUT_STATUS__NORMAL
;
pTask
->
output
S
tatus
=
TASK_OUTPUT_STATUS__NORMAL
;
pTask
->
output
Info
.
s
tatus
=
TASK_OUTPUT_STATUS__NORMAL
;
addToTaskset
(
pTaskList
,
pTask
);
return
pTask
;
...
...
@@ -74,7 +76,7 @@ int32_t tEncodeStreamTask(SEncoder* pEncoder, const SStreamTask* pTask) {
if
(
tEncodeI32
(
pEncoder
,
pTask
->
id
.
taskId
)
<
0
)
return
-
1
;
if
(
tEncodeI32
(
pEncoder
,
pTask
->
info
.
totalLevel
)
<
0
)
return
-
1
;
if
(
tEncodeI8
(
pEncoder
,
pTask
->
info
.
taskLevel
)
<
0
)
return
-
1
;
if
(
tEncodeI8
(
pEncoder
,
pTask
->
output
T
ype
)
<
0
)
return
-
1
;
if
(
tEncodeI8
(
pEncoder
,
pTask
->
output
Info
.
t
ype
)
<
0
)
return
-
1
;
if
(
tEncodeI16
(
pEncoder
,
pTask
->
msgInfo
.
msgType
)
<
0
)
return
-
1
;
if
(
tEncodeI8
(
pEncoder
,
pTask
->
status
.
taskStatus
)
<
0
)
return
-
1
;
...
...
@@ -109,19 +111,19 @@ int32_t tEncodeStreamTask(SEncoder* pEncoder, const SStreamTask* pTask) {
if
(
tEncodeCStr
(
pEncoder
,
pTask
->
exec
.
qmsg
)
<
0
)
return
-
1
;
}
if
(
pTask
->
output
T
ype
==
TASK_OUTPUT__TABLE
)
{
if
(
pTask
->
output
Info
.
t
ype
==
TASK_OUTPUT__TABLE
)
{
if
(
tEncodeI64
(
pEncoder
,
pTask
->
tbSink
.
stbUid
)
<
0
)
return
-
1
;
if
(
tEncodeCStr
(
pEncoder
,
pTask
->
tbSink
.
stbFullName
)
<
0
)
return
-
1
;
if
(
tEncodeSSchemaWrapper
(
pEncoder
,
pTask
->
tbSink
.
pSchemaWrapper
)
<
0
)
return
-
1
;
}
else
if
(
pTask
->
output
T
ype
==
TASK_OUTPUT__SMA
)
{
}
else
if
(
pTask
->
output
Info
.
t
ype
==
TASK_OUTPUT__SMA
)
{
if
(
tEncodeI64
(
pEncoder
,
pTask
->
smaSink
.
smaId
)
<
0
)
return
-
1
;
}
else
if
(
pTask
->
output
T
ype
==
TASK_OUTPUT__FETCH
)
{
}
else
if
(
pTask
->
output
Info
.
t
ype
==
TASK_OUTPUT__FETCH
)
{
if
(
tEncodeI8
(
pEncoder
,
pTask
->
fetchSink
.
reserved
)
<
0
)
return
-
1
;
}
else
if
(
pTask
->
output
T
ype
==
TASK_OUTPUT__FIXED_DISPATCH
)
{
}
else
if
(
pTask
->
output
Info
.
t
ype
==
TASK_OUTPUT__FIXED_DISPATCH
)
{
if
(
tEncodeI32
(
pEncoder
,
pTask
->
fixedEpDispatcher
.
taskId
)
<
0
)
return
-
1
;
if
(
tEncodeI32
(
pEncoder
,
pTask
->
fixedEpDispatcher
.
nodeId
)
<
0
)
return
-
1
;
if
(
tEncodeSEpSet
(
pEncoder
,
&
pTask
->
fixedEpDispatcher
.
epSet
)
<
0
)
return
-
1
;
}
else
if
(
pTask
->
output
T
ype
==
TASK_OUTPUT__SHUFFLE_DISPATCH
)
{
}
else
if
(
pTask
->
output
Info
.
t
ype
==
TASK_OUTPUT__SHUFFLE_DISPATCH
)
{
if
(
tSerializeSUseDbRspImp
(
pEncoder
,
&
pTask
->
shuffleDispatcher
.
dbInfo
)
<
0
)
return
-
1
;
if
(
tEncodeCStr
(
pEncoder
,
pTask
->
shuffleDispatcher
.
stbFullName
)
<
0
)
return
-
1
;
}
...
...
@@ -137,7 +139,7 @@ int32_t tDecodeStreamTask(SDecoder* pDecoder, SStreamTask* pTask) {
if
(
tDecodeI32
(
pDecoder
,
&
pTask
->
id
.
taskId
)
<
0
)
return
-
1
;
if
(
tDecodeI32
(
pDecoder
,
&
pTask
->
info
.
totalLevel
)
<
0
)
return
-
1
;
if
(
tDecodeI8
(
pDecoder
,
&
pTask
->
info
.
taskLevel
)
<
0
)
return
-
1
;
if
(
tDecodeI8
(
pDecoder
,
&
pTask
->
output
T
ype
)
<
0
)
return
-
1
;
if
(
tDecodeI8
(
pDecoder
,
&
pTask
->
output
Info
.
t
ype
)
<
0
)
return
-
1
;
if
(
tDecodeI16
(
pDecoder
,
&
pTask
->
msgInfo
.
msgType
)
<
0
)
return
-
1
;
if
(
tDecodeI8
(
pDecoder
,
&
pTask
->
status
.
taskStatus
)
<
0
)
return
-
1
;
...
...
@@ -179,21 +181,21 @@ int32_t tDecodeStreamTask(SDecoder* pDecoder, SStreamTask* pTask) {
if
(
tDecodeCStrAlloc
(
pDecoder
,
&
pTask
->
exec
.
qmsg
)
<
0
)
return
-
1
;
}
if
(
pTask
->
output
T
ype
==
TASK_OUTPUT__TABLE
)
{
if
(
pTask
->
output
Info
.
t
ype
==
TASK_OUTPUT__TABLE
)
{
if
(
tDecodeI64
(
pDecoder
,
&
pTask
->
tbSink
.
stbUid
)
<
0
)
return
-
1
;
if
(
tDecodeCStrTo
(
pDecoder
,
pTask
->
tbSink
.
stbFullName
)
<
0
)
return
-
1
;
pTask
->
tbSink
.
pSchemaWrapper
=
taosMemoryCalloc
(
1
,
sizeof
(
SSchemaWrapper
));
if
(
pTask
->
tbSink
.
pSchemaWrapper
==
NULL
)
return
-
1
;
if
(
tDecodeSSchemaWrapper
(
pDecoder
,
pTask
->
tbSink
.
pSchemaWrapper
)
<
0
)
return
-
1
;
}
else
if
(
pTask
->
output
T
ype
==
TASK_OUTPUT__SMA
)
{
}
else
if
(
pTask
->
output
Info
.
t
ype
==
TASK_OUTPUT__SMA
)
{
if
(
tDecodeI64
(
pDecoder
,
&
pTask
->
smaSink
.
smaId
)
<
0
)
return
-
1
;
}
else
if
(
pTask
->
output
T
ype
==
TASK_OUTPUT__FETCH
)
{
}
else
if
(
pTask
->
output
Info
.
t
ype
==
TASK_OUTPUT__FETCH
)
{
if
(
tDecodeI8
(
pDecoder
,
&
pTask
->
fetchSink
.
reserved
)
<
0
)
return
-
1
;
}
else
if
(
pTask
->
output
T
ype
==
TASK_OUTPUT__FIXED_DISPATCH
)
{
}
else
if
(
pTask
->
output
Info
.
t
ype
==
TASK_OUTPUT__FIXED_DISPATCH
)
{
if
(
tDecodeI32
(
pDecoder
,
&
pTask
->
fixedEpDispatcher
.
taskId
)
<
0
)
return
-
1
;
if
(
tDecodeI32
(
pDecoder
,
&
pTask
->
fixedEpDispatcher
.
nodeId
)
<
0
)
return
-
1
;
if
(
tDecodeSEpSet
(
pDecoder
,
&
pTask
->
fixedEpDispatcher
.
epSet
)
<
0
)
return
-
1
;
}
else
if
(
pTask
->
output
T
ype
==
TASK_OUTPUT__SHUFFLE_DISPATCH
)
{
}
else
if
(
pTask
->
output
Info
.
t
ype
==
TASK_OUTPUT__SHUFFLE_DISPATCH
)
{
if
(
tDeserializeSUseDbRspImp
(
pDecoder
,
&
pTask
->
shuffleDispatcher
.
dbInfo
)
<
0
)
return
-
1
;
if
(
tDecodeCStrTo
(
pDecoder
,
pTask
->
shuffleDispatcher
.
stbFullName
)
<
0
)
return
-
1
;
}
...
...
@@ -203,6 +205,11 @@ int32_t tDecodeStreamTask(SDecoder* pDecoder, SStreamTask* pTask) {
return
0
;
}
static
void
freeItem
(
void
*
p
)
{
SStreamContinueExecInfo
*
pInfo
=
p
;
rpcFreeCont
(
pInfo
->
msg
.
pCont
);
}
void
tFreeStreamTask
(
SStreamTask
*
pTask
)
{
qDebug
(
"free s-task:%s"
,
pTask
->
id
.
idStr
);
...
...
@@ -211,8 +218,8 @@ void tFreeStreamTask(SStreamTask* pTask) {
streamQueueClose
(
pTask
->
inputQueue
);
}
if
(
pTask
->
output
Q
ueue
)
{
streamQueueClose
(
pTask
->
output
Q
ueue
);
if
(
pTask
->
output
Info
.
q
ueue
)
{
streamQueueClose
(
pTask
->
output
Info
.
q
ueue
);
}
if
(
pTask
->
exec
.
qmsg
)
{
...
...
@@ -229,11 +236,11 @@ void tFreeStreamTask(SStreamTask* pTask) {
}
taosArrayDestroyP
(
pTask
->
pUpstreamEpInfoList
,
taosMemoryFree
);
if
(
pTask
->
output
T
ype
==
TASK_OUTPUT__TABLE
)
{
if
(
pTask
->
output
Info
.
t
ype
==
TASK_OUTPUT__TABLE
)
{
tDeleteSchemaWrapper
(
pTask
->
tbSink
.
pSchemaWrapper
);
taosMemoryFree
(
pTask
->
tbSink
.
pTSchema
);
tSimpleHashCleanup
(
pTask
->
tbSink
.
pTblInfo
);
}
else
if
(
pTask
->
output
T
ype
==
TASK_OUTPUT__SHUFFLE_DISPATCH
)
{
}
else
if
(
pTask
->
output
Info
.
t
ype
==
TASK_OUTPUT__SHUFFLE_DISPATCH
)
{
taosArrayDestroy
(
pTask
->
shuffleDispatcher
.
dbInfo
.
pVgroupInfos
);
taosArrayDestroy
(
pTask
->
checkReqIds
);
pTask
->
checkReqIds
=
NULL
;
...
...
@@ -251,5 +258,11 @@ void tFreeStreamTask(SStreamTask* pTask) {
tSimpleHashCleanup
(
pTask
->
pNameMap
);
}
if
(
pTask
->
pRspMsgList
!=
NULL
)
{
taosArrayDestroyEx
(
pTask
->
pRspMsgList
,
freeItem
);
pTask
->
pRspMsgList
=
NULL
;
}
taosThreadMutexDestroy
(
&
pTask
->
lock
);
taosMemoryFree
(
pTask
);
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录