Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
2b74583b
T
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
2b74583b
编写于
4月 21, 2023
作者:
H
Haojun Liao
提交者:
GitHub
4月 21, 2023
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #21002 from taosdata/fix/liaohj_main
fix(stream): set the correct number of tasks.
上级
95f4c81a
b6f4cac6
变更
12
隐藏空白更改
内联
并排
Showing
12 changed file
with
97 addition
and
152 deletion
+97
-152
include/libs/stream/tstream.h
include/libs/stream/tstream.h
+2
-0
source/dnode/mgmt/mgmt_vnode/src/vmInt.c
source/dnode/mgmt/mgmt_vnode/src/vmInt.c
+1
-1
source/dnode/vnode/src/inc/tq.h
source/dnode/vnode/src/inc/tq.h
+0
-7
source/dnode/vnode/src/inc/vnodeInt.h
source/dnode/vnode/src/inc/vnodeInt.h
+1
-0
source/dnode/vnode/src/tq/tq.c
source/dnode/vnode/src/tq/tq.c
+39
-23
source/dnode/vnode/src/tq/tqRead.c
source/dnode/vnode/src/tq/tqRead.c
+3
-0
source/dnode/vnode/src/tq/tqRestore.c
source/dnode/vnode/src/tq/tqRestore.c
+15
-20
source/dnode/vnode/src/tq/tqUtil.c
source/dnode/vnode/src/tq/tqUtil.c
+0
-84
source/libs/executor/src/timewindowoperator.c
source/libs/executor/src/timewindowoperator.c
+15
-0
source/libs/stream/src/streamExec.c
source/libs/stream/src/streamExec.c
+11
-6
source/libs/stream/src/streamMeta.c
source/libs/stream/src/streamMeta.c
+9
-10
tests/script/tsim/stream/basic1.sim
tests/script/tsim/stream/basic1.sim
+1
-1
未找到文件。
include/libs/stream/tstream.h
浏览文件 @
2b74583b
...
...
@@ -273,6 +273,7 @@ typedef struct SStreamId {
typedef
struct
SCheckpointInfo
{
int64_t
id
;
int64_t
version
;
// offset in WAL
int64_t
currentVer
;
// current offset in WAL, not serialize it
}
SCheckpointInfo
;
typedef
struct
SStreamStatus
{
...
...
@@ -537,6 +538,7 @@ void streamTaskInputFail(SStreamTask* pTask);
int32_t
streamTryExec
(
SStreamTask
*
pTask
);
int32_t
streamSchedExec
(
SStreamTask
*
pTask
);
int32_t
streamTaskOutput
(
SStreamTask
*
pTask
,
SStreamDataBlock
*
pBlock
);
bool
streamTaskShouldStop
(
const
SStreamStatus
*
pStatus
);
int32_t
streamScanExec
(
SStreamTask
*
pTask
,
int32_t
batchSz
);
...
...
source/dnode/mgmt/mgmt_vnode/src/vmInt.c
浏览文件 @
2b74583b
...
...
@@ -119,6 +119,7 @@ void vmCloseVnode(SVnodeMgmt *pMgmt, SVnodeObj *pVnode, bool commitAndRemoveWal)
pVnode
->
pFetchQ
->
threadId
);
while
(
!
taosQueueEmpty
(
pVnode
->
pFetchQ
))
taosMsleep
(
10
);
tqNotifyClose
(
pVnode
->
pImpl
->
pTq
);
dInfo
(
"vgId:%d, wait for vnode stream queue:%p is empty"
,
pVnode
->
vgId
,
pVnode
->
pStreamQ
);
while
(
!
taosQueueEmpty
(
pVnode
->
pStreamQ
))
taosMsleep
(
10
);
...
...
@@ -141,7 +142,6 @@ void vmCloseVnode(SVnodeMgmt *pMgmt, SVnodeObj *pVnode, bool commitAndRemoveWal)
dInfo
(
"vgId:%d, vnode is closed"
,
pVnode
->
vgId
);
if
(
commitAndRemoveWal
)
{
char
path
[
TSDB_FILENAME_LEN
]
=
{
0
};
snprintf
(
path
,
TSDB_FILENAME_LEN
,
"vnode%svnode%d%swal"
,
TD_DIRSEP
,
pVnode
->
vgId
,
TD_DIRSEP
);
dInfo
(
"vgId:%d, remove all wals, path:%s"
,
pVnode
->
vgId
,
path
);
tfsRmdir
(
pMgmt
->
pTfs
,
path
);
...
...
source/dnode/vnode/src/inc/tq.h
浏览文件 @
2b74583b
...
...
@@ -180,16 +180,9 @@ int32_t tqStreamTasksScanWal(STQ* pTq);
// tq util
char
*
createStreamTaskIdStr
(
int64_t
streamId
,
int32_t
taskId
);
void
createStreamTaskOffsetKey
(
char
*
dst
,
uint64_t
streamId
,
uint32_t
taskId
);
int32_t
tqAddInputBlockNLaunchTask
(
SStreamTask
*
pTask
,
SStreamQueueItem
*
pQueueItem
,
int64_t
ver
);
int32_t
launchTaskForWalBlock
(
SStreamTask
*
pTask
,
SFetchRet
*
pRet
,
STqOffset
*
pOffset
);
int32_t
tqExtractDataForMq
(
STQ
*
pTq
,
STqHandle
*
pHandle
,
const
SMqPollReq
*
pRequest
,
SRpcMsg
*
pMsg
);
void
doSaveTaskOffset
(
STqOffsetStore
*
pOffsetStore
,
const
char
*
pKey
,
int64_t
ver
);
void
saveOffsetForAllTasks
(
STQ
*
pTq
,
int64_t
ver
);
void
initOffsetForAllRestoreTasks
(
STQ
*
pTq
);
int32_t
transferToWalReadTask
(
SStreamMeta
*
pStreamMeta
,
SArray
*
pTaskList
);
#ifdef __cplusplus
}
#endif
...
...
source/dnode/vnode/src/inc/vnodeInt.h
浏览文件 @
2b74583b
...
...
@@ -190,6 +190,7 @@ int32_t tsdbSetKeepCfg(STsdb* pTsdb, STsdbCfg* pCfg);
int
tqInit
();
void
tqCleanUp
();
STQ
*
tqOpen
(
const
char
*
path
,
SVnode
*
pVnode
);
void
tqNotifyClose
(
STQ
*
);
void
tqClose
(
STQ
*
);
int
tqPushMsg
(
STQ
*
,
void
*
msg
,
int32_t
msgLen
,
tmsg_t
msgType
,
int64_t
ver
);
int
tqRegisterPushHandle
(
STQ
*
pTq
,
void
*
pHandle
,
const
SMqPollReq
*
pRequest
,
SRpcMsg
*
pRpcMsg
,
SMqDataRsp
*
pDataRsp
,
...
...
source/dnode/vnode/src/tq/tq.c
浏览文件 @
2b74583b
...
...
@@ -154,6 +154,31 @@ void tqClose(STQ* pTq) {
taosMemoryFree
(
pTq
);
}
void
tqNotifyClose
(
STQ
*
pTq
)
{
if
(
pTq
!=
NULL
)
{
taosWLockLatch
(
&
pTq
->
pStreamMeta
->
lock
);
void
*
pIter
=
NULL
;
while
(
1
)
{
pIter
=
taosHashIterate
(
pTq
->
pStreamMeta
->
pTasks
,
pIter
);
if
(
pIter
==
NULL
)
{
break
;
}
SStreamTask
*
pTask
=
*
(
SStreamTask
**
)
pIter
;
tqDebug
(
"vgId:%d s-task:%s set dropping flag"
,
pTq
->
pStreamMeta
->
vgId
,
pTask
->
id
.
idStr
);
pTask
->
status
.
taskStatus
=
TASK_STATUS__STOP
;
int64_t
st
=
taosGetTimestampMs
();
qKillTask
(
pTask
->
exec
.
pExecutor
,
TSDB_CODE_SUCCESS
);
int64_t
el
=
taosGetTimestampMs
()
-
st
;
tqDebug
(
"vgId:%d s-task:%s is closed in %"
PRId64
"ms"
,
pTq
->
pStreamMeta
->
vgId
,
pTask
->
id
.
idStr
,
el
);
}
taosWUnLockLatch
(
&
pTq
->
pStreamMeta
->
lock
);
}
}
static
int32_t
doSendDataRsp
(
const
SRpcHandleInfo
*
pRpcHandleInfo
,
const
SMqDataRsp
*
pRsp
,
int32_t
epoch
,
int64_t
consumerId
,
int32_t
type
)
{
int32_t
len
=
0
;
...
...
@@ -573,6 +598,7 @@ int32_t tqExpandTask(STQ* pTq, SStreamTask* pTask, int64_t ver) {
pTask
->
pMsgCb
=
&
pTq
->
pVnode
->
msgCb
;
pTask
->
pMeta
=
pTq
->
pStreamMeta
;
pTask
->
chkInfo
.
version
=
ver
;
pTask
->
chkInfo
.
currentVer
=
ver
;
// expand executor
if
(
pTask
->
fillHistory
)
{
...
...
@@ -966,14 +992,21 @@ int32_t tqProcessDelReq(STQ* pTq, void* pReq, int32_t len, int64_t ver) {
int32_t
*
pRef
=
taosMemoryMalloc
(
sizeof
(
int32_t
));
*
pRef
=
1
;
taosWLockLatch
(
&
pTq
->
pStreamMeta
->
lock
);
void
*
pIter
=
NULL
;
while
(
1
)
{
pIter
=
taosHashIterate
(
pTq
->
pStreamMeta
->
pTasks
,
pIter
);
if
(
pIter
==
NULL
)
break
;
if
(
pIter
==
NULL
)
{
break
;
}
SStreamTask
*
pTask
=
*
(
SStreamTask
**
)
pIter
;
if
(
pTask
->
taskLevel
!=
TASK_LEVEL__SOURCE
)
continue
;
if
(
pTask
->
taskLevel
!=
TASK_LEVEL__SOURCE
)
{
continue
;
}
qDebug
(
"
delete req enqueue stream task: %d, ver: %"
PRId64
,
pTask
->
id
.
taskId
,
ver
);
qDebug
(
"
s-task:%s delete req enqueue, ver: %"
PRId64
,
pTask
->
id
.
idStr
,
ver
);
if
(
!
failed
)
{
SStreamRefDataBlock
*
pRefBlock
=
taosAllocateQitem
(
sizeof
(
SStreamRefDataBlock
),
DEF_QITEM
,
0
);
...
...
@@ -983,15 +1016,13 @@ int32_t tqProcessDelReq(STQ* pTq, void* pReq, int32_t len, int64_t ver) {
atomic_add_fetch_32
(
pRefBlock
->
dataRef
,
1
);
if
(
tAppendDataToInputQueue
(
pTask
,
(
SStreamQueueItem
*
)
pRefBlock
)
<
0
)
{
qError
(
"stream task input del failed, task id %d"
,
pTask
->
id
.
taskId
);
atomic_sub_fetch_32
(
pRef
,
1
);
taosFreeQitem
(
pRefBlock
);
continue
;
}
if
(
streamSchedExec
(
pTask
)
<
0
)
{
qError
(
"s
tream task launch failed, task id %d"
,
pTask
->
id
.
taskId
);
qError
(
"s
-task:%s stream task launch failed"
,
pTask
->
id
.
idStr
);
continue
;
}
...
...
@@ -1000,8 +1031,9 @@ int32_t tqProcessDelReq(STQ* pTq, void* pReq, int32_t len, int64_t ver) {
}
}
taosWUnLockLatch
(
&
pTq
->
pStreamMeta
->
lock
);
int32_t
ref
=
atomic_sub_fetch_32
(
pRef
,
1
);
/*A(ref >= 0);*/
if
(
ref
==
0
)
{
blockDataDestroy
(
pDelBlock
);
taosMemoryFree
(
pRef
);
...
...
@@ -1032,23 +1064,9 @@ int32_t tqProcessDelReq(STQ* pTq, void* pReq, int32_t len, int64_t ver) {
}
blockDataDestroy(pDelBlock);
#endif
return
0
;
}
static
int32_t
addSubmitBlockNLaunchTask
(
STqOffsetStore
*
pOffsetStore
,
SStreamTask
*
pTask
,
SStreamDataSubmit2
*
pSubmit
,
const
char
*
key
,
int64_t
ver
)
{
doSaveTaskOffset
(
pOffsetStore
,
key
,
ver
);
int32_t
code
=
tqAddInputBlockNLaunchTask
(
pTask
,
(
SStreamQueueItem
*
)
pSubmit
,
ver
);
// remove the offset, if all functions are completed successfully.
if
(
code
==
TSDB_CODE_SUCCESS
)
{
tqOffsetDelete
(
pOffsetStore
,
key
);
}
return
code
;
}
int32_t
tqProcessSubmitReq
(
STQ
*
pTq
,
SPackedData
submit
)
{
#if 0
void* pIter = NULL;
...
...
@@ -1310,8 +1328,6 @@ int32_t tqStartStreamTasks(STQ* pTq) {
}
tqDebug
(
"vgId:%d start wal scan stream tasks, tasks:%d"
,
vgId
,
numOfTasks
);
initOffsetForAllRestoreTasks
(
pTq
);
pRunReq
->
head
.
vgId
=
vgId
;
pRunReq
->
streamId
=
0
;
pRunReq
->
taskId
=
WAL_READ_TASKS_ID
;
...
...
source/dnode/vnode/src/tq/tqRead.c
浏览文件 @
2b74583b
...
...
@@ -1023,6 +1023,7 @@ int32_t tqUpdateTbUidList(STQ* pTq, const SArray* tbUidList, bool isAdd) {
}
// update the table list handle for each stream scanner/wal reader
taosWLockLatch
(
&
pTq
->
pStreamMeta
->
lock
);
while
(
1
)
{
pIter
=
taosHashIterate
(
pTq
->
pStreamMeta
->
pTasks
,
pIter
);
if
(
pIter
==
NULL
)
{
...
...
@@ -1039,5 +1040,7 @@ int32_t tqUpdateTbUidList(STQ* pTq, const SArray* tbUidList, bool isAdd) {
}
}
taosWUnLockLatch
(
&
pTq
->
pStreamMeta
->
lock
);
return
0
;
}
source/dnode/vnode/src/tq/tqRestore.c
浏览文件 @
2b74583b
...
...
@@ -15,12 +15,12 @@
#include "tq.h"
static
int32_t
doCreateReqsByScanWal
(
SStreamMeta
*
pStreamMeta
,
STqOffsetStore
*
pOffsetStore
,
bool
*
pScanIdle
);
static
int32_t
createStreamRunReq
(
SStreamMeta
*
pStreamMeta
,
bool
*
pScanIdle
);
// this function should be executed by stream threads.
// there is a case that the WAL increases more fast than the restore procedure, and this restore procedure
// will not stop eventually.
int
tqStreamTasksScanWal
(
STQ
*
pTq
)
{
int
32_t
tqStreamTasksScanWal
(
STQ
*
pTq
)
{
int32_t
vgId
=
TD_VID
(
pTq
->
pVnode
);
SStreamMeta
*
pMeta
=
pTq
->
pStreamMeta
;
int64_t
st
=
taosGetTimestampMs
();
...
...
@@ -31,7 +31,7 @@ int tqStreamTasksScanWal(STQ* pTq) {
// check all restore tasks
bool
shouldIdle
=
true
;
doCreateReqsByScanWal
(
pTq
->
pStreamMeta
,
pTq
->
pOffsetStore
,
&
shouldIdle
);
createStreamRunReq
(
pTq
->
pStreamMeta
,
&
shouldIdle
);
int32_t
times
=
0
;
...
...
@@ -76,7 +76,7 @@ static SArray* extractTaskIdList(SStreamMeta* pStreamMeta, int32_t numOfTasks) {
return
pTaskIdList
;
}
int32_t
doCreateReqsByScanWal
(
SStreamMeta
*
pStreamMeta
,
STqOffsetStore
*
pOffsetStore
,
bool
*
pScanIdle
)
{
int32_t
createStreamRunReq
(
SStreamMeta
*
pStreamMeta
,
bool
*
pScanIdle
)
{
*
pScanIdle
=
true
;
bool
noNewDataInWal
=
true
;
int32_t
vgId
=
pStreamMeta
->
vgId
;
...
...
@@ -89,6 +89,8 @@ int32_t doCreateReqsByScanWal(SStreamMeta* pStreamMeta, STqOffsetStore* pOffsetS
tqDebug
(
"vgId:%d start to check wal to extract new submit block for %d tasks"
,
vgId
,
numOfTasks
);
SArray
*
pTaskIdList
=
extractTaskIdList
(
pStreamMeta
,
numOfTasks
);
// update the new task number
numOfTasks
=
taosArrayGetSize
(
pTaskIdList
);
for
(
int32_t
i
=
0
;
i
<
numOfTasks
;
++
i
)
{
int32_t
*
pTaskId
=
taosArrayGet
(
pTaskIdList
,
i
);
SStreamTask
*
pTask
=
streamMetaAcquireTask
(
pStreamMeta
,
*
pTaskId
);
...
...
@@ -97,21 +99,19 @@ int32_t doCreateReqsByScanWal(SStreamMeta* pStreamMeta, STqOffsetStore* pOffsetS
}
int32_t
status
=
pTask
->
status
.
taskStatus
;
if
((
pTask
->
taskLevel
!=
TASK_LEVEL__SOURCE
)
||
(
status
==
TASK_STATUS__DROPPING
))
{
if
(
pTask
->
taskLevel
!=
TASK_LEVEL__SOURCE
)
{
tqDebug
(
"s-task:%s not source task, no need to start"
,
pTask
->
id
.
idStr
);
streamMetaReleaseTask
(
pStreamMeta
,
pTask
);
continue
;
}
if
(
status
==
TASK_STATUS__RECOVER_PREPARE
||
status
==
TASK_STATUS__WAIT_DOWNSTREAM
)
{
if
(
streamTaskShouldStop
(
&
pTask
->
status
)
||
status
==
TASK_STATUS__RECOVER_PREPARE
||
status
==
TASK_STATUS__WAIT_DOWNSTREAM
)
{
tqDebug
(
"s-task:%s skip push data, not ready for processing, status %d"
,
pTask
->
id
.
idStr
,
status
);
streamMetaReleaseTask
(
pStreamMeta
,
pTask
);
continue
;
}
// check if offset value exists
char
key
[
128
]
=
{
0
};
createStreamTaskOffsetKey
(
key
,
pTask
->
id
.
streamId
,
pTask
->
id
.
taskId
);
if
(
tInputQueueIsFull
(
pTask
))
{
tqDebug
(
"vgId:%d s-task:%s input queue is full, do nothing"
,
vgId
,
pTask
->
id
.
idStr
);
streamMetaReleaseTask
(
pStreamMeta
,
pTask
);
...
...
@@ -120,19 +120,15 @@ int32_t doCreateReqsByScanWal(SStreamMeta* pStreamMeta, STqOffsetStore* pOffsetS
*
pScanIdle
=
false
;
// check if offset value exists
STqOffset
*
pOffset
=
tqOffsetRead
(
pOffsetStore
,
key
);
ASSERT
(
pOffset
!=
NULL
);
// seek the stored version and extract data from WAL
int32_t
code
=
walReadSeekVer
(
pTask
->
exec
.
pWalReader
,
p
Offset
->
val
.
version
);
int32_t
code
=
walReadSeekVer
(
pTask
->
exec
.
pWalReader
,
p
Task
->
chkInfo
.
currentVer
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
// no data in wal, quit
streamMetaReleaseTask
(
pStreamMeta
,
pTask
);
continue
;
}
// append the data for the stream
tqDebug
(
"vgId:%d
wal reader seek to ver:%"
PRId64
" %s"
,
vgId
,
pOffset
->
val
.
version
,
pTask
->
id
.
idSt
r
);
tqDebug
(
"vgId:%d
s-task:%s wal reader seek to ver:%"
PRId64
,
vgId
,
pTask
->
id
.
idStr
,
pTask
->
chkInfo
.
currentVe
r
);
SPackedData
packData
=
{
0
};
code
=
extractSubmitMsgFromWal
(
pTask
->
exec
.
pWalReader
,
&
packData
);
...
...
@@ -151,14 +147,13 @@ int32_t doCreateReqsByScanWal(SStreamMeta* pStreamMeta, STqOffsetStore* pOffsetS
noNewDataInWal
=
false
;
tqDebug
(
"s-task:%s submit data extracted from WAL"
,
pTask
->
id
.
idStr
);
code
=
tqAddInputBlockNLaunchTask
(
pTask
,
(
SStreamQueueItem
*
)
p
,
packData
.
ver
);
if
(
code
==
TSDB_CODE_SUCCESS
)
{
p
Offset
->
val
.
version
=
walReaderGetCurrentVer
(
pTask
->
exec
.
pWalReader
);
p
Task
->
chkInfo
.
currentVer
=
walReaderGetCurrentVer
(
pTask
->
exec
.
pWalReader
);
tqDebug
(
"s-task:%s set the ver:%"
PRId64
" from WALReader after extract block from WAL"
,
pTask
->
id
.
idStr
,
p
Offset
->
val
.
version
);
p
Task
->
chkInfo
.
currentVer
);
}
else
{
// do nothing
tqError
(
"s-task:%s append input queue failed, ver:%"
PRId64
,
pTask
->
id
.
idStr
,
pTask
->
chkInfo
.
currentVer
);
}
streamDataSubmitDestroy
(
p
);
...
...
source/dnode/vnode/src/tq/tqUtil.c
浏览文件 @
2b74583b
...
...
@@ -25,21 +25,6 @@ char* createStreamTaskIdStr(int64_t streamId, int32_t taskId) {
return
taosStrdup
(
buf
);
}
// stream_task:stream_id:task_id
void
createStreamTaskOffsetKey
(
char
*
dst
,
uint64_t
streamId
,
uint32_t
taskId
)
{
int32_t
n
=
12
;
char
*
p
=
dst
;
memcpy
(
p
,
"stream_task:"
,
n
);
p
+=
n
;
int32_t
inc
=
tintToHex
(
streamId
,
p
);
p
+=
inc
;
*
(
p
++
)
=
':'
;
tintToHex
(
taskId
,
p
);
}
int32_t
tqAddInputBlockNLaunchTask
(
SStreamTask
*
pTask
,
SStreamQueueItem
*
pQueueItem
,
int64_t
ver
)
{
int32_t
code
=
tAppendDataToInputQueue
(
pTask
,
pQueueItem
);
if
(
code
<
0
)
{
...
...
@@ -55,75 +40,6 @@ int32_t tqAddInputBlockNLaunchTask(SStreamTask* pTask, SStreamQueueItem* pQueueI
return
TSDB_CODE_SUCCESS
;
}
void
initOffsetForAllRestoreTasks
(
STQ
*
pTq
)
{
void
*
pIter
=
NULL
;
while
(
1
)
{
pIter
=
taosHashIterate
(
pTq
->
pStreamMeta
->
pTasks
,
pIter
);
if
(
pIter
==
NULL
)
{
break
;
}
SStreamTask
*
pTask
=
*
(
SStreamTask
**
)
pIter
;
if
(
pTask
->
taskLevel
!=
TASK_LEVEL__SOURCE
)
{
continue
;
}
if
(
pTask
->
status
.
taskStatus
==
TASK_STATUS__RECOVER_PREPARE
||
pTask
->
status
.
taskStatus
==
TASK_STATUS__WAIT_DOWNSTREAM
)
{
tqDebug
(
"s-task:%s skip push data, since not ready, status %d"
,
pTask
->
id
.
idStr
,
pTask
->
status
.
taskStatus
);
continue
;
}
char
key
[
128
]
=
{
0
};
createStreamTaskOffsetKey
(
key
,
pTask
->
id
.
streamId
,
pTask
->
id
.
taskId
);
STqOffset
*
pOffset
=
tqOffsetRead
(
pTq
->
pOffsetStore
,
key
);
if
(
pOffset
==
NULL
)
{
doSaveTaskOffset
(
pTq
->
pOffsetStore
,
key
,
pTask
->
chkInfo
.
version
);
}
}
}
void
saveOffsetForAllTasks
(
STQ
*
pTq
,
int64_t
ver
)
{
void
*
pIter
=
NULL
;
while
(
1
)
{
pIter
=
taosHashIterate
(
pTq
->
pStreamMeta
->
pTasks
,
pIter
);
if
(
pIter
==
NULL
)
{
break
;
}
SStreamTask
*
pTask
=
*
(
SStreamTask
**
)
pIter
;
if
(
pTask
->
taskLevel
!=
TASK_LEVEL__SOURCE
)
{
continue
;
}
if
(
pTask
->
status
.
taskStatus
==
TASK_STATUS__RECOVER_PREPARE
||
pTask
->
status
.
taskStatus
==
TASK_STATUS__WAIT_DOWNSTREAM
)
{
tqDebug
(
"s-task:%s skip push data, not ready for processing, status %d"
,
pTask
->
id
.
idStr
,
pTask
->
status
.
taskStatus
);
continue
;
}
char
key
[
128
]
=
{
0
};
createStreamTaskOffsetKey
(
key
,
pTask
->
id
.
streamId
,
pTask
->
id
.
taskId
);
STqOffset
*
pOffset
=
tqOffsetRead
(
pTq
->
pOffsetStore
,
key
);
if
(
pOffset
==
NULL
)
{
doSaveTaskOffset
(
pTq
->
pOffsetStore
,
key
,
ver
);
}
}
}
void
doSaveTaskOffset
(
STqOffsetStore
*
pOffsetStore
,
const
char
*
pKey
,
int64_t
ver
)
{
STqOffset
offset
=
{
0
};
tqOffsetResetToLog
(
&
offset
.
val
,
ver
);
tstrncpy
(
offset
.
subKey
,
pKey
,
tListLen
(
offset
.
subKey
));
// keep the offset info in the offset store
tqOffsetWrite
(
pOffsetStore
,
&
offset
);
}
static
int32_t
tqInitDataRsp
(
SMqDataRsp
*
pRsp
,
const
SMqPollReq
*
pReq
,
int8_t
subType
)
{
pRsp
->
reqOffset
=
pReq
->
reqOffset
;
...
...
source/libs/executor/src/timewindowoperator.c
浏览文件 @
2b74583b
...
...
@@ -2541,6 +2541,20 @@ static SSDataBlock* doStreamFinalIntervalAgg(SOperatorInfo* pOperator) {
}
while
(
1
)
{
if
(
isTaskKilled
(
pTaskInfo
))
{
if
(
pInfo
->
pUpdated
!=
NULL
)
{
pInfo
->
pUpdated
=
taosArrayDestroy
(
pInfo
->
pUpdated
);
}
if
(
pInfo
->
pUpdatedMap
!=
NULL
)
{
tSimpleHashCleanup
(
pInfo
->
pUpdatedMap
);
pInfo
->
pUpdatedMap
=
NULL
;
}
T_LONG_JMP
(
pTaskInfo
->
env
,
pTaskInfo
->
code
);
}
SSDataBlock
*
pBlock
=
downstream
->
fpSet
.
getNextFn
(
downstream
);
if
(
pBlock
==
NULL
)
{
pOperator
->
status
=
OP_RES_TO_RETURN
;
...
...
@@ -2635,6 +2649,7 @@ static SSDataBlock* doStreamFinalIntervalAgg(SOperatorInfo* pOperator) {
while
((
pIte
=
tSimpleHashIterate
(
pInfo
->
pUpdatedMap
,
pIte
,
&
iter
))
!=
NULL
)
{
taosArrayPush
(
pInfo
->
pUpdated
,
pIte
);
}
tSimpleHashCleanup
(
pInfo
->
pUpdatedMap
);
pInfo
->
pUpdatedMap
=
NULL
;
taosArraySort
(
pInfo
->
pUpdated
,
winKeyCmprImpl
);
...
...
source/libs/stream/src/streamExec.c
浏览文件 @
2b74583b
...
...
@@ -17,6 +17,11 @@
#define STREAM_EXEC_MAX_BATCH_NUM 100
bool
streamTaskShouldStop
(
const
SStreamStatus
*
pStatus
)
{
int32_t
status
=
atomic_load_8
((
int8_t
*
)
&
pStatus
->
taskStatus
);
return
(
status
==
TASK_STATUS__STOP
)
||
(
status
==
TASK_STATUS__DROPPING
);
}
static
int32_t
streamTaskExecImpl
(
SStreamTask
*
pTask
,
const
void
*
data
,
SArray
*
pRes
)
{
int32_t
code
=
TSDB_CODE_SUCCESS
;
void
*
pExecutor
=
pTask
->
exec
.
pExecutor
;
...
...
@@ -66,7 +71,7 @@ static int32_t streamTaskExecImpl(SStreamTask* pTask, const void* data, SArray*
// pExecutor
while
(
1
)
{
if
(
pTask
->
status
.
taskStatus
==
TASK_STATUS__DROPPING
)
{
if
(
streamTaskShouldStop
(
&
pTask
->
status
)
)
{
return
0
;
}
...
...
@@ -106,7 +111,7 @@ static int32_t streamTaskExecImpl(SStreamTask* pTask, const void* data, SArray*
continue
;
}
qDebug
(
"
task %d(child %d) executed and get block"
,
pTask
->
id
.
taskId
,
pTask
->
selfChildId
);
qDebug
(
"
s-task:%s (child %d) executed and get block"
,
pTask
->
id
.
idStr
,
pTask
->
selfChildId
);
SSDataBlock
block
=
{
0
};
assignOneDataBlock
(
&
block
,
output
);
...
...
@@ -134,7 +139,7 @@ int32_t streamScanExec(SStreamTask* pTask, int32_t batchSz) {
int32_t
batchCnt
=
0
;
while
(
1
)
{
if
(
atomic_load_8
(
&
pTask
->
status
.
taskStatus
)
==
TASK_STATUS__DROPPING
)
{
if
(
streamTaskShouldStop
(
&
pTask
->
status
)
)
{
taosArrayDestroy
(
pRes
);
return
0
;
}
...
...
@@ -270,7 +275,7 @@ int32_t streamExecForAll(SStreamTask* pTask) {
}
}
if
(
pTask
->
status
.
taskStatus
==
TASK_STATUS__DROPPING
)
{
if
(
streamTaskShouldStop
(
&
pTask
->
status
)
)
{
if
(
pInput
)
{
streamFreeQitem
(
pInput
);
}
...
...
@@ -301,7 +306,7 @@ int32_t streamExecForAll(SStreamTask* pTask) {
", checkPoint id:%"
PRId64
" -> %"
PRId64
,
pTask
->
id
.
idStr
,
pTask
->
chkInfo
.
version
,
dataVer
,
pTask
->
chkInfo
.
id
,
ckId
);
pTask
->
chkInfo
=
(
SCheckpointInfo
)
{.
version
=
dataVer
,
.
id
=
ckId
};
pTask
->
chkInfo
=
(
SCheckpointInfo
)
{.
version
=
dataVer
,
.
id
=
ckId
,
.
currentVer
=
pTask
->
chkInfo
.
currentVer
};
taosWLockLatch
(
&
pTask
->
pMeta
->
lock
);
streamMetaSaveTask
(
pTask
->
pMeta
,
pTask
);
...
...
@@ -368,7 +373,7 @@ int32_t streamTryExec(SStreamTask* pTask) {
atomic_store_8
(
&
pTask
->
status
.
schedStatus
,
TASK_SCHED_STATUS__INACTIVE
);
qDebug
(
"s-task:%s exec completed"
,
pTask
->
id
.
idStr
);
if
(
!
taosQueueEmpty
(
pTask
->
inputQueue
->
queue
)
&&
(
pTask
->
status
.
taskStatus
!=
TASK_STATUS__DROPPING
))
{
if
(
!
taosQueueEmpty
(
pTask
->
inputQueue
->
queue
)
&&
(
!
streamTaskShouldStop
(
&
pTask
->
status
)
))
{
streamSchedExec
(
pTask
);
}
}
...
...
source/libs/stream/src/streamMeta.c
浏览文件 @
2b74583b
...
...
@@ -191,10 +191,12 @@ SStreamTask* streamMetaAcquireTask(SStreamMeta* pMeta, int32_t taskId) {
taosRLockLatch
(
&
pMeta
->
lock
);
SStreamTask
**
ppTask
=
(
SStreamTask
**
)
taosHashGet
(
pMeta
->
pTasks
,
&
taskId
,
sizeof
(
int32_t
));
if
(
ppTask
!=
NULL
&&
(
atomic_load_8
(
&
((
*
ppTask
)
->
status
.
taskStatus
))
!=
TASK_STATUS__DROPPING
))
{
atomic_add_fetch_32
(
&
(
*
ppTask
)
->
refCnt
,
1
);
taosRUnLockLatch
(
&
pMeta
->
lock
);
return
*
ppTask
;
if
(
ppTask
!=
NULL
)
{
if
(
!
streamTaskShouldStop
(
&
(
*
ppTask
)
->
status
))
{
atomic_add_fetch_32
(
&
(
*
ppTask
)
->
refCnt
,
1
);
taosRUnLockLatch
(
&
pMeta
->
lock
);
return
*
ppTask
;
}
}
taosRUnLockLatch
(
&
pMeta
->
lock
);
...
...
@@ -205,7 +207,7 @@ void streamMetaReleaseTask(SStreamMeta* pMeta, SStreamTask* pTask) {
int32_t
left
=
atomic_sub_fetch_32
(
&
pTask
->
refCnt
,
1
);
ASSERT
(
left
>=
0
);
if
(
left
==
0
)
{
ASSERT
(
atomic_load_8
(
&
pTask
->
status
.
taskStatus
)
==
TASK_STATUS__DROPPING
);
ASSERT
(
streamTaskShouldStop
(
&
pTask
->
status
)
);
tFreeStreamTask
(
pTask
);
}
}
...
...
@@ -216,11 +218,8 @@ void streamMetaRemoveTask(SStreamMeta* pMeta, int32_t taskId) {
SStreamTask
*
pTask
=
*
ppTask
;
taosHashRemove
(
pMeta
->
pTasks
,
&
taskId
,
sizeof
(
int32_t
));
tdbTbDelete
(
pMeta
->
pTaskDb
,
&
taskId
,
sizeof
(
int32_t
),
pMeta
->
txn
);
/*if (pTask->timer) {
* taosTmrStop(pTask->timer);*/
/*pTask->timer = NULL;*/
/*}*/
atomic_store_8
(
&
pTask
->
status
.
taskStatus
,
TASK_STATUS__DROPPING
);
atomic_store_8
(
&
pTask
->
status
.
taskStatus
,
TASK_STATUS__STOP
);
taosWLockLatch
(
&
pMeta
->
lock
);
streamMetaReleaseTask
(
pMeta
,
pTask
);
...
...
tests/script/tsim/stream/basic1.sim
浏览文件 @
2b74583b
...
...
@@ -37,7 +37,7 @@ if $loop_count == 20 then
endi
if $rows != 4 then
print =====rows=$rows
,
expect 4
print =====rows=$rows
expect 4
goto loop0
endi
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录