Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
e0ac1027
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看板
未验证
提交
e0ac1027
编写于
8月 24, 2022
作者:
S
Shengliang Guan
提交者:
GitHub
8月 24, 2022
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #16376 from taosdata/feature/stream
refactor(stream): refine stream backend interface
上级
621ffbf2
24261cc9
变更
8
展开全部
隐藏空白更改
内联
并排
Showing
8 changed file
with
216 addition
and
104 deletion
+216
-104
examples/c/stream_demo.c
examples/c/stream_demo.c
+1
-1
include/common/tcommon.h
include/common/tcommon.h
+24
-0
include/libs/stream/tstream.h
include/libs/stream/tstream.h
+9
-8
source/dnode/vnode/src/tq/tq.c
source/dnode/vnode/src/tq/tq.c
+11
-5
source/libs/executor/src/scanoperator.c
source/libs/executor/src/scanoperator.c
+36
-0
source/libs/executor/src/timewindowoperator.c
source/libs/executor/src/timewindowoperator.c
+98
-71
source/libs/stream/src/streamDispatch.c
source/libs/stream/src/streamDispatch.c
+1
-1
source/libs/stream/src/streamState.c
source/libs/stream/src/streamState.c
+36
-18
未找到文件。
examples/c/stream_demo.c
浏览文件 @
e0ac1027
...
...
@@ -96,7 +96,7 @@ int32_t create_stream() {
taos_free_result
(
pRes
);
pRes
=
taos_query
(
pConn
,
"create stream stream1 trigger at_once watermark 10s into outstb as select _wstart start,
k from st1 partition by tbname state_window(k
)"
);
"create stream stream1 trigger at_once watermark 10s into outstb as select _wstart start,
avg(k) from st1 partition by tbname interval(10s
)"
);
if
(
taos_errno
(
pRes
)
!=
0
)
{
printf
(
"failed to create stream stream1, reason:%s
\n
"
,
taos_errstr
(
pRes
));
return
-
1
;
...
...
include/common/tcommon.h
浏览文件 @
e0ac1027
...
...
@@ -44,6 +44,30 @@ enum {
)
// clang-format on
typedef
struct
{
TSKEY
ts
;
uint64_t
groupId
;
}
SWinKey
;
static
inline
int
SWinKeyCmpr
(
const
void
*
pKey1
,
int
kLen1
,
const
void
*
pKey2
,
int
kLen2
)
{
SWinKey
*
pWin1
=
(
SWinKey
*
)
pKey1
;
SWinKey
*
pWin2
=
(
SWinKey
*
)
pKey2
;
if
(
pWin1
->
groupId
>
pWin2
->
groupId
)
{
return
1
;
}
else
if
(
pWin1
->
groupId
<
pWin2
->
groupId
)
{
return
-
1
;
}
if
(
pWin1
->
ts
>
pWin2
->
ts
)
{
return
1
;
}
else
if
(
pWin1
->
ts
<
pWin2
->
ts
)
{
return
-
1
;
}
return
0
;
}
enum
{
TMQ_MSG_TYPE__DUMMY
=
0
,
TMQ_MSG_TYPE__POLL_RSP
,
...
...
include/libs/stream/tstream.h
浏览文件 @
e0ac1027
...
...
@@ -551,16 +551,17 @@ typedef struct {
}
SStreamStateCur
;
#if 1
int32_t
streamStatePut
(
SStreamState
*
pState
,
const
void
*
key
,
int32_t
kLen
,
const
void
*
value
,
int32_t
vLen
);
int32_t
streamStateGet
(
SStreamState
*
pState
,
const
void
*
key
,
int32_t
kLen
,
void
**
pVal
,
int32_t
*
pVLen
);
int32_t
streamStateDel
(
SStreamState
*
pState
,
const
void
*
key
,
int32_t
kLen
);
SStreamStateCur
*
streamStateGetCur
(
SStreamState
*
pState
,
const
void
*
key
,
int32_t
kLen
);
SStreamStateCur
*
streamStateSeekKeyNext
(
SStreamState
*
pState
,
const
void
*
key
,
int32_t
kLen
);
SStreamStateCur
*
streamStateSeekKeyPrev
(
SStreamState
*
pState
,
const
void
*
key
,
int32_t
kLen
);
int32_t
streamStatePut
(
SStreamState
*
pState
,
const
SWinKey
*
key
,
const
void
*
value
,
int32_t
vLen
);
int32_t
streamStateGet
(
SStreamState
*
pState
,
const
SWinKey
*
key
,
void
**
pVal
,
int32_t
*
pVLen
);
int32_t
streamStateDel
(
SStreamState
*
pState
,
const
SWinKey
*
key
);
void
streamFreeVal
(
void
*
val
);
SStreamStateCur
*
streamStateGetCur
(
SStreamState
*
pState
,
const
SWinKey
*
key
);
SStreamStateCur
*
streamStateSeekKeyNext
(
SStreamState
*
pState
,
const
SWinKey
*
key
);
SStreamStateCur
*
streamStateSeekKeyPrev
(
SStreamState
*
pState
,
const
SWinKey
*
key
);
void
streamStateFreeCur
(
SStreamStateCur
*
pCur
);
int32_t
stream
GetKVByCur
(
SStreamStateCur
*
pCur
,
void
**
pKey
,
int32_t
*
pKLen
,
void
**
pVal
,
int32_t
*
pVLen
);
int32_t
stream
StateGetKVByCur
(
SStreamStateCur
*
pCur
,
SWinKey
*
pKey
,
const
void
**
pVal
,
int32_t
*
pVLen
);
int32_t
streamStateSeekFirst
(
SStreamState
*
pState
,
SStreamStateCur
*
pCur
);
int32_t
streamStateSeekLast
(
SStreamState
*
pState
,
SStreamStateCur
*
pCur
);
...
...
source/dnode/vnode/src/tq/tq.c
浏览文件 @
e0ac1027
...
...
@@ -652,27 +652,33 @@ int32_t tqExpandTask(STQ* pTq, SStreamTask* pTask) {
// expand executor
if
(
pTask
->
taskLevel
==
TASK_LEVEL__SOURCE
)
{
pTask
->
pState
=
streamStateOpen
(
pTq
->
pStreamMeta
->
path
,
pTask
);
if
(
pTask
->
pState
==
NULL
)
{
return
-
1
;
}
SReadHandle
handle
=
{
.
meta
=
pTq
->
pVnode
->
pMeta
,
.
vnode
=
pTq
->
pVnode
,
.
initTqReader
=
1
,
.
pStateBackend
=
pTask
->
pState
,
};
pTask
->
exec
.
executor
=
qCreateStreamExecTaskInfo
(
pTask
->
exec
.
qmsg
,
&
handle
);
ASSERT
(
pTask
->
exec
.
executor
);
}
else
if
(
pTask
->
taskLevel
==
TASK_LEVEL__AGG
)
{
pTask
->
pState
=
streamStateOpen
(
pTq
->
pStreamMeta
->
path
,
pTask
);
if
(
pTask
->
pState
==
NULL
)
{
return
-
1
;
}
SReadHandle
mgHandle
=
{
.
vnode
=
NULL
,
.
numOfVgroups
=
(
int32_t
)
taosArrayGetSize
(
pTask
->
childEpInfo
),
.
pStateBackend
=
pTask
->
pState
,
};
pTask
->
exec
.
executor
=
qCreateStreamExecTaskInfo
(
pTask
->
exec
.
qmsg
,
&
mgHandle
);
ASSERT
(
pTask
->
exec
.
executor
);
}
pTask
->
pState
=
streamStateOpen
(
pTq
->
pStreamMeta
->
path
,
pTask
);
if
(
pTask
->
pState
==
NULL
)
{
return
-
1
;
}
// sink
/*pTask->ahandle = pTq->pVnode;*/
if
(
pTask
->
outputType
==
TASK_OUTPUT__SMA
)
{
...
...
source/libs/executor/src/scanoperator.c
浏览文件 @
e0ac1027
...
...
@@ -1281,6 +1281,42 @@ static SSDataBlock* doStreamScan(SOperatorInfo* pOperator) {
SExecTaskInfo
*
pTaskInfo
=
pOperator
->
pTaskInfo
;
SStreamScanInfo
*
pInfo
=
pOperator
->
info
;
#if 0
SStreamState* pState = pTaskInfo->streamInfo.pState;
if (pState) {
printf(">>>>>>>> stream write backend\n");
SWinKey key = {
.ts = 1,
.groupId = 2,
};
char tmp[100] = "abcdefg1";
if (streamStatePut(pState, &key, &tmp, strlen(tmp) + 1) < 0) {
ASSERT(0);
}
key.ts = 2;
char tmp2[100] = "abcdefg2";
if (streamStatePut(pState, &key, &tmp2, strlen(tmp2) + 1) < 0) {
ASSERT(0);
}
key.groupId = 5;
key.ts = 1;
char tmp3[100] = "abcdefg3";
if (streamStatePut(pState, &key, &tmp3, strlen(tmp3) + 1) < 0) {
ASSERT(0);
}
char* val2 = NULL;
int32_t sz;
if (streamStateGet(pState, &key, (void**)&val2, &sz) < 0) {
ASSERT(0);
}
printf("stream read %s %d\n", val2, sz);
streamFreeVal(val2);
}
#endif
qDebug
(
"stream scan called"
);
if
(
pTaskInfo
->
streamInfo
.
prepareStatus
.
type
==
TMQ_OFFSET__LOG
)
{
while
(
1
)
{
...
...
source/libs/executor/src/timewindowoperator.c
浏览文件 @
e0ac1027
此差异已折叠。
点击以展开。
source/libs/stream/src/streamDispatch.c
浏览文件 @
e0ac1027
...
...
@@ -358,7 +358,7 @@ int32_t streamDispatchAllBlocks(SStreamTask* pTask, const SStreamDataBlock* pDat
FAIL_SHUFFLE_DISPATCH:
if
(
pReqs
)
{
for
(
int32_t
i
=
0
;
i
<
vgSz
;
i
++
)
{
taosArrayDestroy
(
pReqs
[
i
].
data
);
taosArrayDestroy
P
(
pReqs
[
i
].
data
,
taosMemoryFree
);
taosArrayDestroy
(
pReqs
[
i
].
dataLen
);
}
taosMemoryFree
(
pReqs
);
...
...
source/libs/stream/src/streamState.c
浏览文件 @
e0ac1027
...
...
@@ -15,6 +15,7 @@
#include "executor.h"
#include "streamInc.h"
#include "tcommon.h"
#include "ttimer.h"
SStreamState
*
streamStateOpen
(
char
*
path
,
SStreamTask
*
pTask
)
{
...
...
@@ -23,14 +24,18 @@ SStreamState* streamStateOpen(char* path, SStreamTask* pTask) {
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
return
NULL
;
}
char
statePath
[
2
00
];
char
statePath
[
3
00
];
sprintf
(
statePath
,
"%s/%d"
,
path
,
pTask
->
taskId
);
if
(
tdbOpen
(
statePath
,
16
*
1024
,
1
,
&
pState
->
db
)
<
0
)
{
if
(
tdbOpen
(
statePath
,
4096
,
256
,
&
pState
->
db
)
<
0
)
{
goto
_err
;
}
// open state storage backend
if
(
tdbTbOpen
(
"state.db"
,
sizeof
(
int32_t
),
-
1
,
NULL
,
pState
->
db
,
&
pState
->
pStateDb
)
<
0
)
{
if
(
tdbTbOpen
(
"state.db"
,
sizeof
(
SWinKey
),
-
1
,
SWinKeyCmpr
,
pState
->
db
,
&
pState
->
pStateDb
)
<
0
)
{
goto
_err
;
}
if
(
streamStateBegin
(
pState
)
<
0
)
{
goto
_err
;
}
...
...
@@ -60,6 +65,7 @@ int32_t streamStateBegin(SStreamState* pState) {
}
if
(
tdbBegin
(
pState
->
db
,
&
pState
->
txn
)
<
0
)
{
tdbTxnClose
(
&
pState
->
txn
);
return
-
1
;
}
return
0
;
...
...
@@ -95,33 +101,39 @@ int32_t streamStateAbort(SStreamState* pState) {
return
0
;
}
int32_t
streamStatePut
(
SStreamState
*
pState
,
const
void
*
key
,
int32_t
kLen
,
const
void
*
value
,
int32_t
vLen
)
{
return
tdbTbUpsert
(
pState
->
pStateDb
,
key
,
kLen
,
value
,
vLen
,
&
pState
->
txn
);
int32_t
streamStatePut
(
SStreamState
*
pState
,
const
SWinKey
*
key
,
const
void
*
value
,
int32_t
vLen
)
{
return
tdbTbUpsert
(
pState
->
pStateDb
,
key
,
sizeof
(
SWinKey
)
,
value
,
vLen
,
&
pState
->
txn
);
}
int32_t
streamStateGet
(
SStreamState
*
pState
,
const
void
*
key
,
int32_t
kLen
,
void
**
pVal
,
int32_t
*
pVLen
)
{
return
tdbTbGet
(
pState
->
pStateDb
,
key
,
kLen
,
pVal
,
pVLen
);
int32_t
streamStateGet
(
SStreamState
*
pState
,
const
SWinKey
*
key
,
void
**
pVal
,
int32_t
*
pVLen
)
{
return
tdbTbGet
(
pState
->
pStateDb
,
key
,
sizeof
(
SWinKey
)
,
pVal
,
pVLen
);
}
int32_t
streamStateDel
(
SStreamState
*
pState
,
const
void
*
key
,
int32_t
kLen
)
{
return
tdbTbDelete
(
pState
->
pStateDb
,
key
,
kLen
,
&
pState
->
txn
);
int32_t
streamStateDel
(
SStreamState
*
pState
,
const
SWinKey
*
key
)
{
return
tdbTbDelete
(
pState
->
pStateDb
,
key
,
sizeof
(
SWinKey
)
,
&
pState
->
txn
);
}
SStreamStateCur
*
streamStateGetCur
(
SStreamState
*
pState
,
const
void
*
key
,
int32_t
kLen
)
{
SStreamStateCur
*
streamStateGetCur
(
SStreamState
*
pState
,
const
SWinKey
*
key
)
{
SStreamStateCur
*
pCur
=
taosMemoryCalloc
(
1
,
sizeof
(
SStreamStateCur
));
if
(
pCur
==
NULL
)
return
NULL
;
tdbTbcOpen
(
pState
->
pStateDb
,
&
pCur
->
pCur
,
NULL
);
int32_t
c
;
tdbTbcMoveTo
(
pCur
->
pCur
,
key
,
kLen
,
&
c
);
tdbTbcMoveTo
(
pCur
->
pCur
,
key
,
sizeof
(
SWinKey
)
,
&
c
);
if
(
c
!=
0
)
{
taosMemoryFree
(
pCur
);
return
NULL
;
}
return
0
;
return
pCur
;
}
int32_t
streamGetKVByCur
(
SStreamStateCur
*
pCur
,
void
**
pKey
,
int32_t
*
pKLen
,
void
**
pVal
,
int32_t
*
pVLen
)
{
return
tdbTbcGet
(
pCur
->
pCur
,
(
const
void
**
)
pKey
,
pKLen
,
(
const
void
**
)
pVal
,
pVLen
);
int32_t
streamStateGetKVByCur
(
SStreamStateCur
*
pCur
,
SWinKey
*
pKey
,
const
void
**
pVal
,
int32_t
*
pVLen
)
{
const
SWinKey
*
pKTmp
=
NULL
;
int32_t
kLen
;
if
(
tdbTbcGet
(
pCur
->
pCur
,
(
const
void
**
)
&
pKTmp
,
&
kLen
,
pVal
,
pVLen
)
<
0
)
{
return
-
1
;
}
*
pKey
=
*
pKTmp
;
return
0
;
}
int32_t
streamStateSeekFirst
(
SStreamState
*
pState
,
SStreamStateCur
*
pCur
)
{
...
...
@@ -134,14 +146,14 @@ int32_t streamStateSeekLast(SStreamState* pState, SStreamStateCur* pCur) {
return
tdbTbcMoveToLast
(
pCur
->
pCur
);
}
SStreamStateCur
*
streamStateSeekKeyNext
(
SStreamState
*
pState
,
const
void
*
key
,
int32_t
kLen
)
{
SStreamStateCur
*
streamStateSeekKeyNext
(
SStreamState
*
pState
,
const
SWinKey
*
key
)
{
SStreamStateCur
*
pCur
=
taosMemoryCalloc
(
1
,
sizeof
(
SStreamStateCur
));
if
(
pCur
==
NULL
)
{
return
NULL
;
}
int32_t
c
;
if
(
tdbTbcMoveTo
(
pCur
->
pCur
,
key
,
kLen
,
&
c
)
<
0
)
{
if
(
tdbTbcMoveTo
(
pCur
->
pCur
,
key
,
sizeof
(
SWinKey
)
,
&
c
)
<
0
)
{
taosMemoryFree
(
pCur
);
return
NULL
;
}
...
...
@@ -155,14 +167,14 @@ SStreamStateCur* streamStateSeekKeyNext(SStreamState* pState, const void* key, i
return
pCur
;
}
SStreamStateCur
*
streamStateSeekKeyPrev
(
SStreamState
*
pState
,
const
void
*
key
,
int32_t
kLen
)
{
SStreamStateCur
*
streamStateSeekKeyPrev
(
SStreamState
*
pState
,
const
SWinKey
*
key
)
{
SStreamStateCur
*
pCur
=
taosMemoryCalloc
(
1
,
sizeof
(
SStreamStateCur
));
if
(
pCur
==
NULL
)
{
return
NULL
;
}
int32_t
c
;
if
(
tdbTbcMoveTo
(
pCur
->
pCur
,
key
,
kLen
,
&
c
)
<
0
)
{
if
(
tdbTbcMoveTo
(
pCur
->
pCur
,
key
,
sizeof
(
SWinKey
)
,
&
c
)
<
0
)
{
taosMemoryFree
(
pCur
);
return
NULL
;
}
...
...
@@ -185,3 +197,9 @@ int32_t streamStateCurPrev(SStreamState* pState, SStreamStateCur* pCur) {
//
return
tdbTbcMoveToPrev
(
pCur
->
pCur
);
}
void
streamStateFreeCur
(
SStreamStateCur
*
pCur
)
{
tdbTbcClose
(
pCur
->
pCur
);
taosMemoryFree
(
pCur
);
}
void
streamFreeVal
(
void
*
val
)
{
tdbFree
(
val
);
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录