Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
2f8f2e09
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看板
未验证
提交
2f8f2e09
编写于
8月 17, 2022
作者:
H
Hui Li
提交者:
GitHub
8月 17, 2022
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #16183 from taosdata/feature/tq
refactor(mnode): check drop and alter stb for stream and topic
上级
ebc79f90
e7377e41
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
160 addition
and
7 deletion
+160
-7
source/dnode/mnode/impl/src/mndStb.c
source/dnode/mnode/impl/src/mndStb.c
+160
-7
未找到文件。
source/dnode/mnode/impl/src/mndStb.c
浏览文件 @
2f8f2e09
...
...
@@ -1145,7 +1145,7 @@ static int32_t mndAddSuperTableTag(const SStbObj *pOld, SStbObj *pNew, SArray *p
return
0
;
}
int32_t
mndCheckColAndTagModifiable
(
SMnode
*
pMnode
,
const
char
*
stbn
ame
,
int64_t
suid
,
col_id_t
colId
)
{
static
int32_t
mndCheckAlterColForTopic
(
SMnode
*
pMnode
,
const
char
*
stbFullN
ame
,
int64_t
suid
,
col_id_t
colId
)
{
SSdb
*
pSdb
=
pMnode
->
pSdb
;
void
*
pIter
=
NULL
;
while
(
1
)
{
...
...
@@ -1154,7 +1154,7 @@ int32_t mndCheckColAndTagModifiable(SMnode *pMnode, const char *stbname, int64_t
if
(
pIter
==
NULL
)
break
;
mDebug
(
"topic:%s, check tag and column modifiable, stb:%s suid:%"
PRId64
" colId:%d, subType:%d sql:%s"
,
pTopic
->
name
,
stb
n
ame
,
suid
,
colId
,
pTopic
->
subType
,
pTopic
->
sql
);
pTopic
->
name
,
stb
FullN
ame
,
suid
,
colId
,
pTopic
->
subType
,
pTopic
->
sql
);
if
(
pTopic
->
subType
!=
TOPIC_SUB_TYPE__COLUMN
)
{
sdbRelease
(
pSdb
,
pTopic
);
continue
;
...
...
@@ -1192,20 +1192,66 @@ int32_t mndCheckColAndTagModifiable(SMnode *pMnode, const char *stbname, int64_t
sdbRelease
(
pSdb
,
pTopic
);
nodesDestroyNode
(
pAst
);
}
return
0
;
}
static
int32_t
mndCheckAlterColForStream
(
SMnode
*
pMnode
,
const
char
*
stbFullName
,
int64_t
suid
,
col_id_t
colId
)
{
SSdb
*
pSdb
=
pMnode
->
pSdb
;
void
*
pIter
=
NULL
;
while
(
1
)
{
SStreamObj
*
pStream
=
NULL
;
pIter
=
sdbFetch
(
pSdb
,
SDB_STREAM
,
pIter
,
(
void
**
)
&
pStream
);
if
(
pIter
==
NULL
)
break
;
SNode
*
pAst
=
NULL
;
if
(
nodesStringToNode
(
pStream
->
ast
,
&
pAst
)
!=
0
)
{
ASSERT
(
0
);
return
-
1
;
}
SNodeList
*
pNodeList
=
NULL
;
nodesCollectColumns
((
SSelectStmt
*
)
pAst
,
SQL_CLAUSE_FROM
,
NULL
,
COLLECT_COL_TYPE_ALL
,
&
pNodeList
);
SNode
*
pNode
=
NULL
;
FOREACH
(
pNode
,
pNodeList
)
{
SColumnNode
*
pCol
=
(
SColumnNode
*
)
pNode
;
if
(
pCol
->
tableId
!=
suid
)
{
mDebug
(
"stream:%s, check colId:%d passed"
,
pStream
->
name
,
pCol
->
colId
);
goto
NEXT
;
}
if
(
pCol
->
colId
>
0
&&
pCol
->
colId
==
colId
)
{
sdbRelease
(
pSdb
,
pStream
);
nodesDestroyNode
(
pAst
);
terrno
=
TSDB_CODE_MND_STREAM_MUST_BE_DELETED
;
mError
(
"stream:%s, check colId:%d conflicted"
,
pStream
->
name
,
pCol
->
colId
);
return
-
1
;
}
mDebug
(
"stream:%s, check colId:%d passed"
,
pStream
->
name
,
pCol
->
colId
);
}
NEXT:
sdbRelease
(
pSdb
,
pStream
);
nodesDestroyNode
(
pAst
);
}
return
0
;
}
static
int32_t
mndCheckAlterColForTSma
(
SMnode
*
pMnode
,
const
char
*
stbFullName
,
int64_t
suid
,
col_id_t
colId
)
{
SSdb
*
pSdb
=
pMnode
->
pSdb
;
void
*
pIter
=
NULL
;
while
(
1
)
{
SSmaObj
*
pSma
=
NULL
;
pIter
=
sdbFetch
(
pSdb
,
SDB_SMA
,
pIter
,
(
void
**
)
&
pSma
);
if
(
pIter
==
NULL
)
break
;
mDebug
(
"tsma:%s, check tag and column modifiable, stb:%s suid:%"
PRId64
" colId:%d, sql:%s"
,
pSma
->
name
,
stbname
,
suid
,
colId
,
pSma
->
sql
);
mDebug
(
"tsma:%s, check tag and column modifiable, stb:%s suid:%"
PRId64
" colId:%d, sql:%s"
,
pSma
->
name
,
s
tbFullName
,
s
uid
,
colId
,
pSma
->
sql
);
SNode
*
pAst
=
NULL
;
if
(
nodesStringToNode
(
pSma
->
ast
,
&
pAst
)
!=
0
)
{
terrno
=
TSDB_CODE_SDB_INVALID_DATA_CONTENT
;
mError
(
"tsma:%s, check tag and column modifiable, stb:%s suid:%"
PRId64
" colId:%d failed since parse AST err"
,
pSma
->
name
,
stb
n
ame
,
suid
,
colId
);
pSma
->
name
,
stb
FullN
ame
,
suid
,
colId
);
return
-
1
;
}
...
...
@@ -1218,7 +1264,7 @@ int32_t mndCheckColAndTagModifiable(SMnode *pMnode, const char *stbname, int64_t
if
((
pCol
->
tableId
!=
suid
)
&&
(
pSma
->
stbUid
!=
suid
))
{
mDebug
(
"tsma:%s, check colId:%d passed"
,
pSma
->
name
,
pCol
->
colId
);
goto
NEXT
2
;
goto
NEXT
;
}
if
((
pCol
->
colId
)
>
0
&&
(
pCol
->
colId
==
colId
))
{
sdbRelease
(
pSdb
,
pSma
);
...
...
@@ -1230,11 +1276,24 @@ int32_t mndCheckColAndTagModifiable(SMnode *pMnode, const char *stbname, int64_t
mDebug
(
"tsma:%s, check colId:%d passed"
,
pSma
->
name
,
pCol
->
colId
);
}
NEXT
2
:
NEXT:
sdbRelease
(
pSdb
,
pSma
);
nodesDestroyNode
(
pAst
);
}
return
0
;
}
int32_t
mndCheckColAndTagModifiable
(
SMnode
*
pMnode
,
const
char
*
stbFullName
,
int64_t
suid
,
col_id_t
colId
)
{
if
(
mndCheckAlterColForTopic
(
pMnode
,
stbFullName
,
suid
,
colId
)
<
0
)
{
return
-
1
;
}
if
(
mndCheckAlterColForStream
(
pMnode
,
stbFullName
,
suid
,
colId
)
<
0
)
{
return
-
1
;
}
if
(
mndCheckAlterColForTSma
(
pMnode
,
stbFullName
,
suid
,
colId
)
<
0
)
{
return
-
1
;
}
return
0
;
}
...
...
@@ -1930,6 +1989,90 @@ _OVER:
return
code
;
}
static
int32_t
mndCheckDropStbForTopic
(
SMnode
*
pMnode
,
const
char
*
stbFullName
,
int64_t
suid
)
{
SSdb
*
pSdb
=
pMnode
->
pSdb
;
void
*
pIter
=
NULL
;
while
(
1
)
{
SMqTopicObj
*
pTopic
=
NULL
;
pIter
=
sdbFetch
(
pSdb
,
SDB_TOPIC
,
pIter
,
(
void
**
)
&
pTopic
);
if
(
pIter
==
NULL
)
break
;
if
(
pTopic
->
subType
==
TOPIC_SUB_TYPE__TABLE
)
{
if
(
pTopic
->
stbUid
==
suid
)
{
sdbRelease
(
pSdb
,
pTopic
);
return
-
1
;
}
}
if
(
pTopic
->
subType
!=
TOPIC_SUB_TYPE__COLUMN
)
{
sdbRelease
(
pSdb
,
pTopic
);
continue
;
}
SNode
*
pAst
=
NULL
;
if
(
nodesStringToNode
(
pTopic
->
ast
,
&
pAst
)
!=
0
)
{
ASSERT
(
0
);
return
-
1
;
}
SNodeList
*
pNodeList
=
NULL
;
nodesCollectColumns
((
SSelectStmt
*
)
pAst
,
SQL_CLAUSE_FROM
,
NULL
,
COLLECT_COL_TYPE_ALL
,
&
pNodeList
);
SNode
*
pNode
=
NULL
;
FOREACH
(
pNode
,
pNodeList
)
{
SColumnNode
*
pCol
=
(
SColumnNode
*
)
pNode
;
if
(
pCol
->
tableId
!=
suid
)
{
mDebug
(
"topic:%s, check colId:%d passed"
,
pTopic
->
name
,
pCol
->
colId
);
sdbRelease
(
pSdb
,
pTopic
);
nodesDestroyNode
(
pAst
);
return
-
1
;
}
else
{
goto
NEXT
;
}
}
NEXT:
sdbRelease
(
pSdb
,
pTopic
);
nodesDestroyNode
(
pAst
);
}
return
0
;
}
static
int32_t
mndCheckDropStbForStream
(
SMnode
*
pMnode
,
const
char
*
stbFullName
,
int64_t
suid
)
{
SSdb
*
pSdb
=
pMnode
->
pSdb
;
void
*
pIter
=
NULL
;
while
(
1
)
{
SStreamObj
*
pStream
=
NULL
;
pIter
=
sdbFetch
(
pSdb
,
SDB_STREAM
,
pIter
,
(
void
**
)
&
pStream
);
if
(
pIter
==
NULL
)
break
;
SNode
*
pAst
=
NULL
;
if
(
nodesStringToNode
(
pStream
->
ast
,
&
pAst
)
!=
0
)
{
ASSERT
(
0
);
return
-
1
;
}
SNodeList
*
pNodeList
=
NULL
;
nodesCollectColumns
((
SSelectStmt
*
)
pAst
,
SQL_CLAUSE_FROM
,
NULL
,
COLLECT_COL_TYPE_ALL
,
&
pNodeList
);
SNode
*
pNode
=
NULL
;
FOREACH
(
pNode
,
pNodeList
)
{
SColumnNode
*
pCol
=
(
SColumnNode
*
)
pNode
;
if
(
pCol
->
tableId
!=
suid
)
{
mDebug
(
"stream:%s, check colId:%d passed"
,
pStream
->
name
,
pCol
->
colId
);
sdbRelease
(
pSdb
,
pStream
);
nodesDestroyNode
(
pAst
);
return
-
1
;
}
else
{
goto
NEXT
;
}
}
NEXT:
sdbRelease
(
pSdb
,
pStream
);
nodesDestroyNode
(
pAst
);
}
return
0
;
}
static
int32_t
mndProcessDropStbReq
(
SRpcMsg
*
pReq
)
{
SMnode
*
pMnode
=
pReq
->
info
.
node
;
int32_t
code
=
-
1
;
...
...
@@ -1971,6 +2114,16 @@ static int32_t mndProcessDropStbReq(SRpcMsg *pReq) {
goto
_OVER
;
}
if
(
mndCheckDropStbForTopic
(
pMnode
,
dropReq
.
name
,
pStb
->
uid
)
<
0
)
{
terrno
=
TSDB_CODE_MND_TOPIC_MUST_BE_DELETED
;
goto
_OVER
;
}
if
(
mndCheckDropStbForStream
(
pMnode
,
dropReq
.
name
,
pStb
->
uid
)
<
0
)
{
terrno
=
TSDB_CODE_MND_STREAM_MUST_BE_DELETED
;
goto
_OVER
;
}
code
=
mndDropStb
(
pMnode
,
pReq
,
pDb
,
pStb
);
if
(
code
==
0
)
code
=
TSDB_CODE_ACTION_IN_PROGRESS
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录