Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
9e2062f5
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看板
提交
9e2062f5
编写于
6月 26, 2023
作者:
B
Benguang Zhao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix: resolve memory leak on exceptions in mndCreateTopic
上级
14e2e1e5
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
26 addition
and
46 deletion
+26
-46
source/dnode/mnode/impl/src/mndTopic.c
source/dnode/mnode/impl/src/mndTopic.c
+26
-46
未找到文件。
source/dnode/mnode/impl/src/mndTopic.c
浏览文件 @
9e2062f5
...
...
@@ -377,6 +377,10 @@ static int32_t extractTopicTbInfo(SNode *pAst, SMqTopicObj *pTopic) {
static
int32_t
mndCreateTopic
(
SMnode
*
pMnode
,
SRpcMsg
*
pReq
,
SCMCreateTopicReq
*
pCreate
,
SDbObj
*
pDb
,
const
char
*
userName
)
{
mInfo
(
"start to create topic:%s"
,
pCreate
->
name
);
STrans
*
pTrans
=
NULL
;
int32_t
code
=
-
1
;
SNode
*
pAst
=
NULL
;
SQueryPlan
*
pPlan
=
NULL
;
SMqTopicObj
topicObj
=
{
0
};
tstrncpy
(
topicObj
.
name
,
pCreate
->
name
,
TSDB_TOPIC_FNAME_LEN
);
...
...
@@ -401,7 +405,7 @@ static int32_t mndCreateTopic(SMnode *pMnode, SRpcMsg *pReq, SCMCreateTopicReq *
if
(
pCreate
->
withMeta
)
{
terrno
=
TSDB_CODE_MND_INVALID_TOPIC_OPTION
;
mError
(
"topic:%s, failed to create since %s"
,
pCreate
->
name
,
terrstr
());
return
-
1
;
goto
_OUT
;
}
topicObj
.
ast
=
taosStrdup
(
pCreate
->
ast
);
...
...
@@ -409,32 +413,21 @@ static int32_t mndCreateTopic(SMnode *pMnode, SRpcMsg *pReq, SCMCreateTopicReq *
qDebugL
(
"topic:%s ast %s"
,
topicObj
.
name
,
topicObj
.
ast
);
SNode
*
pAst
=
NULL
;
if
(
nodesStringToNode
(
pCreate
->
ast
,
&
pAst
)
!=
0
)
{
taosMemoryFree
(
topicObj
.
ast
);
taosMemoryFree
(
topicObj
.
sql
);
mError
(
"topic:%s, failed to create since %s"
,
pCreate
->
name
,
terrstr
());
return
-
1
;
goto
_OUT
;
}
SQueryPlan
*
pPlan
=
NULL
;
SPlanContext
cxt
=
{.
pAstRoot
=
pAst
,
.
topicQuery
=
true
};
if
(
qCreateQueryPlan
(
&
cxt
,
&
pPlan
,
NULL
)
!=
0
)
{
mError
(
"failed to create topic:%s since %s"
,
pCreate
->
name
,
terrstr
());
taosMemoryFree
(
topicObj
.
ast
);
taosMemoryFree
(
topicObj
.
sql
);
nodesDestroyNode
(
pAst
);
return
-
1
;
goto
_OUT
;
}
topicObj
.
ntbColIds
=
taosArrayInit
(
0
,
sizeof
(
int16_t
));
if
(
topicObj
.
ntbColIds
==
NULL
)
{
taosMemoryFree
(
topicObj
.
ast
);
taosMemoryFree
(
topicObj
.
sql
);
nodesDestroyNode
(
pAst
);
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
return
-
1
;
goto
_OUT
;
}
extractTopicTbInfo
(
pAst
,
&
topicObj
);
...
...
@@ -446,25 +439,18 @@ static int32_t mndCreateTopic(SMnode *pMnode, SRpcMsg *pReq, SCMCreateTopicReq *
if
(
qExtractResultSchema
(
pAst
,
&
topicObj
.
schema
.
nCols
,
&
topicObj
.
schema
.
pSchema
)
!=
0
)
{
mError
(
"topic:%s, failed to create since %s"
,
pCreate
->
name
,
terrstr
());
taosMemoryFree
(
topicObj
.
ast
);
taosMemoryFree
(
topicObj
.
sql
);
nodesDestroyNode
(
pAst
);
return
-
1
;
goto
_OUT
;
}
if
(
nodesNodeToString
((
SNode
*
)
pPlan
,
false
,
&
topicObj
.
physicalPlan
,
NULL
)
!=
0
)
{
mError
(
"topic:%s, failed to create since %s"
,
pCreate
->
name
,
terrstr
());
taosMemoryFree
(
topicObj
.
ast
);
taosMemoryFree
(
topicObj
.
sql
);
return
-
1
;
goto
_OUT
;
}
nodesDestroyNode
(
pAst
);
nodesDestroyNode
((
SNode
*
)
pPlan
);
}
else
if
(
pCreate
->
subType
==
TOPIC_SUB_TYPE__TABLE
)
{
SStbObj
*
pStb
=
mndAcquireStb
(
pMnode
,
pCreate
->
subStbName
);
if
(
pStb
==
NULL
)
{
terrno
=
TSDB_CODE_MND_STB_NOT_EXIST
;
return
-
1
;
goto
_OUT
;
}
strcpy
(
topicObj
.
stbName
,
pCreate
->
subStbName
);
...
...
@@ -483,13 +469,10 @@ static int32_t mndCreateTopic(SMnode *pMnode, SRpcMsg *pReq, SCMCreateTopicReq *
/*topicObj.withTbName = 1;*/
/*topicObj.withSchema = 1;*/
STrans
*
pTrans
=
mndTransCreate
(
pMnode
,
TRN_POLICY_ROLLBACK
,
TRN_CONFLICT_DB_INSIDE
,
pReq
,
"create-topic"
);
pTrans
=
mndTransCreate
(
pMnode
,
TRN_POLICY_ROLLBACK
,
TRN_CONFLICT_DB_INSIDE
,
pReq
,
"create-topic"
);
if
(
pTrans
==
NULL
)
{
mError
(
"topic:%s, failed to create since %s"
,
pCreate
->
name
,
terrstr
());
taosMemoryFreeClear
(
topicObj
.
ast
);
taosMemoryFreeClear
(
topicObj
.
sql
);
taosMemoryFreeClear
(
topicObj
.
physicalPlan
);
return
-
1
;
goto
_OUT
;
}
mndTransSetDbName
(
pTrans
,
pDb
->
name
,
NULL
);
...
...
@@ -499,9 +482,7 @@ static int32_t mndCreateTopic(SMnode *pMnode, SRpcMsg *pReq, SCMCreateTopicReq *
SSdbRaw
*
pCommitRaw
=
mndTopicActionEncode
(
&
topicObj
);
if
(
pCommitRaw
==
NULL
||
mndTransAppendCommitlog
(
pTrans
,
pCommitRaw
)
!=
0
)
{
mError
(
"trans:%d, failed to append commit log since %s"
,
pTrans
->
id
,
terrstr
());
taosMemoryFreeClear
(
topicObj
.
physicalPlan
);
mndTransDrop
(
pTrans
);
return
-
1
;
goto
_OUT
;
}
(
void
)
sdbSetRawStatus
(
pCommitRaw
,
SDB_STATUS_READY
);
...
...
@@ -530,17 +511,16 @@ static int32_t mndCreateTopic(SMnode *pMnode, SRpcMsg *pReq, SCMCreateTopicReq *
tEncodeSize
(
tEncodeSTqCheckInfo
,
&
info
,
len
,
code
);
if
(
code
<
0
)
{
sdbRelease
(
pSdb
,
pVgroup
);
mndTransDrop
(
pTrans
);
return
-
1
;
goto
_OUT
;
}
void
*
buf
=
taosMemoryCalloc
(
1
,
sizeof
(
SMsgHead
)
+
len
);
void
*
abuf
=
POINTER_SHIFT
(
buf
,
sizeof
(
SMsgHead
));
SEncoder
encoder
;
tEncoderInit
(
&
encoder
,
abuf
,
len
);
if
(
tEncodeSTqCheckInfo
(
&
encoder
,
&
info
)
<
0
)
{
taosMemoryFree
(
buf
);
sdbRelease
(
pSdb
,
pVgroup
);
mndTransDrop
(
pTrans
);
return
-
1
;
goto
_OUT
;
}
tEncoderClear
(
&
encoder
);
((
SMsgHead
*
)
buf
)
->
vgId
=
htonl
(
pVgroup
->
vgId
);
...
...
@@ -553,32 +533,32 @@ static int32_t mndCreateTopic(SMnode *pMnode, SRpcMsg *pReq, SCMCreateTopicReq *
if
(
mndTransAppendRedoAction
(
pTrans
,
&
action
)
!=
0
)
{
taosMemoryFree
(
buf
);
sdbRelease
(
pSdb
,
pVgroup
);
mndTransDrop
(
pTrans
);
return
-
1
;
goto
_OUT
;
}
buf
=
NULL
;
sdbRelease
(
pSdb
,
pVgroup
);
}
}
if
(
mndTransPrepare
(
pMnode
,
pTrans
)
!=
0
)
{
mError
(
"trans:%d, failed to prepare since %s"
,
pTrans
->
id
,
terrstr
());
taosMemoryFreeClear
(
topicObj
.
physicalPlan
);
mndTransDrop
(
pTrans
);
return
-
1
;
goto
_OUT
;
}
code
=
TSDB_CODE_ACTION_IN_PROGRESS
;
_OUT:
taosMemoryFreeClear
(
topicObj
.
physicalPlan
);
taosMemoryFreeClear
(
topicObj
.
sql
);
taosMemoryFreeClear
(
topicObj
.
ast
);
taosArrayDestroy
(
topicObj
.
ntbColIds
);
if
(
topicObj
.
schema
.
nCols
)
{
taosMemoryFreeClear
(
topicObj
.
schema
.
pSchema
);
}
nodesDestroyNode
(
pAst
);
nodesDestroyNode
((
SNode
*
)
pPlan
);
mndTransDrop
(
pTrans
);
return
TSDB_CODE_ACTION_IN_PROGRESS
;
return
code
;
}
static
int32_t
mndProcessCreateTopicReq
(
SRpcMsg
*
pReq
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录