Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
21a4b868
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看板
提交
21a4b868
编写于
3月 24, 2022
作者:
S
Shengliang Guan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
sma
上级
b7c31e9c
变更
4
显示空白变更内容
内联
并排
Showing
4 changed file
with
54 addition
and
20 deletion
+54
-20
source/dnode/mnode/impl/inc/mndStream.h
source/dnode/mnode/impl/inc/mndStream.h
+2
-0
source/dnode/mnode/impl/src/mndSma.c
source/dnode/mnode/impl/src/mndSma.c
+22
-0
source/dnode/mnode/impl/src/mndStream.c
source/dnode/mnode/impl/src/mndStream.c
+27
-18
source/dnode/mnode/impl/test/sma/sma.cpp
source/dnode/mnode/impl/test/sma/sma.cpp
+3
-2
未找到文件。
source/dnode/mnode/impl/inc/mndStream.h
浏览文件 @
21a4b868
...
...
@@ -31,6 +31,8 @@ void mndReleaseStream(SMnode *pMnode, SStreamObj *pStream);
SSdbRaw
*
mndStreamActionEncode
(
SStreamObj
*
pStream
);
SSdbRow
*
mndStreamActionDecode
(
SSdbRaw
*
pRaw
);
int32_t
mndAddStreamToTrans
(
SMnode
*
pMnode
,
SStreamObj
*
pStream
,
const
char
*
ast
,
STrans
*
pTrans
);
#ifdef __cplusplus
}
#endif
...
...
source/dnode/mnode/impl/src/mndSma.c
浏览文件 @
21a4b868
...
...
@@ -22,6 +22,7 @@
#include "mndMnode.h"
#include "mndShow.h"
#include "mndStb.c"
#include "mndStream.h"
#include "mndTrans.h"
#include "mndUser.h"
#include "mndVgroup.h"
...
...
@@ -404,6 +405,18 @@ static int32_t mndCreateSma(SMnode *pMnode, SNodeMsg *pReq, SMCreateSmaReq *pCre
memcpy
(
smaObj
.
ast
,
pCreate
->
ast
,
smaObj
.
astLen
);
}
SStreamObj
streamObj
=
{
0
};
tstrncpy
(
streamObj
.
name
,
pCreate
->
name
,
TSDB_STREAM_FNAME_LEN
);
tstrncpy
(
streamObj
.
db
,
pDb
->
name
,
TSDB_DB_FNAME_LEN
);
streamObj
.
createTime
=
taosGetTimestampMs
();
streamObj
.
updateTime
=
streamObj
.
createTime
;
streamObj
.
uid
=
mndGenerateUid
(
pCreate
->
name
,
strlen
(
pCreate
->
name
));
streamObj
.
dbUid
=
pDb
->
uid
;
streamObj
.
version
=
1
;
streamObj
.
sql
=
pCreate
->
sql
;
/*streamObj.physicalPlan = "";*/
streamObj
.
logicalPlan
=
"not implemented"
;
int32_t
code
=
-
1
;
STrans
*
pTrans
=
mndTransCreate
(
pMnode
,
TRN_POLICY_RETRY
,
TRN_TYPE_CREATE_SMA
,
&
pReq
->
rpcMsg
);
if
(
pTrans
==
NULL
)
goto
_OVER
;
...
...
@@ -414,6 +427,7 @@ static int32_t mndCreateSma(SMnode *pMnode, SNodeMsg *pReq, SMCreateSmaReq *pCre
if
(
mndSetCreateSmaRedoLogs
(
pMnode
,
pTrans
,
&
smaObj
)
!=
0
)
goto
_OVER
;
if
(
mndSetCreateSmaCommitLogs
(
pMnode
,
pTrans
,
&
smaObj
)
!=
0
)
goto
_OVER
;
if
(
mndSetCreateSmaRedoActions
(
pMnode
,
pTrans
,
pDb
,
&
smaObj
)
!=
0
)
goto
_OVER
;
if
(
mndAddStreamToTrans
(
pMnode
,
&
streamObj
,
pCreate
->
ast
,
pTrans
)
!=
0
)
goto
_OVER
;
if
(
mndTransPrepare
(
pMnode
,
pTrans
)
!=
0
)
goto
_OVER
;
code
=
0
;
...
...
@@ -457,6 +471,7 @@ static int32_t mndProcessMCreateSmaReq(SNodeMsg *pReq) {
int32_t
code
=
-
1
;
SStbObj
*
pStb
=
NULL
;
SSmaObj
*
pSma
=
NULL
;
SStreamObj
*
pStream
=
NULL
;
SDbObj
*
pDb
=
NULL
;
SUserObj
*
pUser
=
NULL
;
SMCreateSmaReq
createReq
=
{
0
};
...
...
@@ -477,6 +492,12 @@ static int32_t mndProcessMCreateSmaReq(SNodeMsg *pReq) {
goto
_OVER
;
}
pStream
=
mndAcquireStream
(
pMnode
,
createReq
.
name
);
if
(
pStream
!=
NULL
)
{
mError
(
"sma:%s, failed to create since stream:%s already exist"
,
createReq
.
name
,
createReq
.
name
);
goto
_OVER
;
}
pSma
=
mndAcquireSma
(
pMnode
,
createReq
.
name
);
if
(
pSma
!=
NULL
)
{
if
(
createReq
.
igExists
)
{
...
...
@@ -514,6 +535,7 @@ _OVER:
mndReleaseStb
(
pMnode
,
pStb
);
mndReleaseSma
(
pMnode
,
pSma
);
mndReleaseStream
(
pMnode
,
pStream
);
mndReleaseDb
(
pMnode
,
pDb
);
mndReleaseUser
(
pMnode
,
pUser
);
tFreeSMCreateSmaReq
(
&
createReq
);
...
...
source/dnode/mnode/impl/src/mndStream.c
浏览文件 @
21a4b868
...
...
@@ -218,13 +218,13 @@ static int32_t mndCheckCreateStreamReq(SCMCreateStreamReq *pCreate) {
return
0
;
}
static
int32_t
mndStreamGetPlanString
(
const
SCMCreateStreamReq
*
pCreate
,
char
**
pStr
)
{
if
(
NULL
==
pCreate
->
ast
)
{
static
int32_t
mndStreamGetPlanString
(
const
char
*
ast
,
char
**
pStr
)
{
if
(
NULL
==
ast
)
{
return
TSDB_CODE_SUCCESS
;
}
SNode
*
pAst
=
NULL
;
int32_t
code
=
nodesStringToNode
(
pCreate
->
ast
,
&
pAst
);
int32_t
code
=
nodesStringToNode
(
ast
,
&
pAst
);
SQueryPlan
*
pPlan
=
NULL
;
if
(
TSDB_CODE_SUCCESS
==
code
)
{
...
...
@@ -245,6 +245,28 @@ static int32_t mndStreamGetPlanString(const SCMCreateStreamReq *pCreate, char **
return
code
;
}
int32_t
mndAddStreamToTrans
(
SMnode
*
pMnode
,
SStreamObj
*
pStream
,
const
char
*
ast
,
STrans
*
pTrans
)
{
if
(
TSDB_CODE_SUCCESS
!=
mndStreamGetPlanString
(
ast
,
&
pStream
->
physicalPlan
))
{
mError
(
"topic:%s, failed to get plan since %s"
,
pStream
->
name
,
terrstr
());
return
-
1
;
}
if
(
mndScheduleStream
(
pMnode
,
pTrans
,
pStream
)
<
0
)
{
mError
(
"stream:%ld, schedule stream since %s"
,
pStream
->
uid
,
terrstr
());
return
-
1
;
}
SSdbRaw
*
pRedoRaw
=
mndStreamActionEncode
(
pStream
);
if
(
pRedoRaw
==
NULL
||
mndTransAppendRedolog
(
pTrans
,
pRedoRaw
)
!=
0
)
{
mError
(
"trans:%d, failed to append redo log since %s"
,
pTrans
->
id
,
terrstr
());
mndTransDrop
(
pTrans
);
return
-
1
;
}
sdbSetRawStatus
(
pRedoRaw
,
SDB_STATUS_READY
);
return
0
;
}
static
int32_t
mndCreateStream
(
SMnode
*
pMnode
,
SNodeMsg
*
pReq
,
SCMCreateStreamReq
*
pCreate
,
SDbObj
*
pDb
)
{
mDebug
(
"stream:%s to create"
,
pCreate
->
name
);
SStreamObj
streamObj
=
{
0
};
...
...
@@ -259,11 +281,6 @@ static int32_t mndCreateStream(SMnode *pMnode, SNodeMsg *pReq, SCMCreateStreamRe
/*streamObj.physicalPlan = "";*/
streamObj
.
logicalPlan
=
"not implemented"
;
if
(
TSDB_CODE_SUCCESS
!=
mndStreamGetPlanString
(
pCreate
,
&
streamObj
.
physicalPlan
))
{
mError
(
"topic:%s, failed to get plan since %s"
,
pCreate
->
name
,
terrstr
());
return
-
1
;
}
STrans
*
pTrans
=
mndTransCreate
(
pMnode
,
TRN_POLICY_RETRY
,
TRN_TYPE_CREATE_STREAM
,
&
pReq
->
rpcMsg
);
if
(
pTrans
==
NULL
)
{
mError
(
"stream:%s, failed to create since %s"
,
pCreate
->
name
,
terrstr
());
...
...
@@ -271,20 +288,12 @@ static int32_t mndCreateStream(SMnode *pMnode, SNodeMsg *pReq, SCMCreateStreamRe
}
mDebug
(
"trans:%d, used to create stream:%s"
,
pTrans
->
id
,
pCreate
->
name
);
if
(
mnd
ScheduleStream
(
pMnode
,
pTrans
,
&
streamObj
)
<
0
)
{
mError
(
"
stream:%ld, schedule stream since %s"
,
streamObj
.
u
id
,
terrstr
());
if
(
mnd
AddStreamToTrans
(
pMnode
,
&
streamObj
,
pCreate
->
ast
,
pTrans
)
!=
0
)
{
mError
(
"
trans:%d, failed to add stream since %s"
,
pTrans
->
id
,
terrstr
());
mndTransDrop
(
pTrans
);
return
-
1
;
}
SSdbRaw
*
pRedoRaw
=
mndStreamActionEncode
(
&
streamObj
);
if
(
pRedoRaw
==
NULL
||
mndTransAppendRedolog
(
pTrans
,
pRedoRaw
)
!=
0
)
{
mError
(
"trans:%d, failed to append redo log since %s"
,
pTrans
->
id
,
terrstr
());
mndTransDrop
(
pTrans
);
return
-
1
;
}
sdbSetRawStatus
(
pRedoRaw
,
SDB_STATUS_READY
);
if
(
mndTransPrepare
(
pMnode
,
pTrans
)
!=
0
)
{
mError
(
"trans:%d, failed to prepare since %s"
,
pTrans
->
id
,
terrstr
());
mndTransDrop
(
pTrans
);
...
...
source/dnode/mnode/impl/test/sma/sma.cpp
浏览文件 @
21a4b868
...
...
@@ -156,7 +156,7 @@ void* MndTestSma::BuildCreateSmaReq(const char* smaname, const char* stbname, in
createReq
.
tagsFilterLen
=
strlen
(
createReq
.
tagsFilter
)
+
1
;
createReq
.
sql
=
(
char
*
)
sql
;
createReq
.
sqlLen
=
strlen
(
createReq
.
sql
)
+
1
;
createReq
.
ast
=
(
char
*
)
expr
;
createReq
.
ast
=
(
char
*
)
ast
;
createReq
.
astLen
=
strlen
(
createReq
.
ast
)
+
1
;
int32_t
tlen
=
tSerializeSMCreateSmaReq
(
NULL
,
0
,
&
createReq
);
...
...
@@ -201,7 +201,7 @@ TEST_F(MndTestSma, 01_Create_Show_Meta_Drop_Restart_Stb) {
test
.
SendShowRetrieveReq
();
EXPECT_EQ
(
test
.
GetShowRows
(),
1
);
}
#if 0
{
pReq = BuildCreateSmaReq(smaname, stbname, 0, "expr", "tagsFilter", "sql", "ast", &contLen);
pRsp = test.SendReq(TDMT_MND_CREATE_SMA, pReq, contLen);
...
...
@@ -233,4 +233,5 @@ TEST_F(MndTestSma, 01_Create_Show_Meta_Drop_Restart_Stb) {
test.SendShowRetrieveReq();
EXPECT_EQ(test.GetShowRows(), 0);
}
#endif
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录