Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
c0b8234f
T
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22017
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看板
提交
c0b8234f
编写于
2月 08, 2022
作者:
S
Shengliang Guan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update stb
上级
f24e04e8
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
104 addition
and
29 deletion
+104
-29
source/dnode/mnode/impl/src/mndStb.c
source/dnode/mnode/impl/src/mndStb.c
+104
-29
未找到文件。
source/dnode/mnode/impl/src/mndStb.c
浏览文件 @
c0b8234f
...
...
@@ -465,8 +465,8 @@ static int32_t mndSetCreateStbUndoActions(SMnode *pMnode, STrans *pTrans, SDbObj
static
int32_t
mndCreateStb
(
SMnode
*
pMnode
,
SMnodeMsg
*
pReq
,
SMCreateStbReq
*
pCreate
,
SDbObj
*
pDb
)
{
SStbObj
stbObj
=
{
0
};
tstrn
cpy
(
stbObj
.
name
,
pCreate
->
name
,
TSDB_TABLE_FNAME_LEN
);
tstrn
cpy
(
stbObj
.
db
,
pDb
->
name
,
TSDB_DB_FNAME_LEN
);
mem
cpy
(
stbObj
.
name
,
pCreate
->
name
,
TSDB_TABLE_FNAME_LEN
);
mem
cpy
(
stbObj
.
db
,
pDb
->
name
,
TSDB_DB_FNAME_LEN
);
stbObj
.
createdTime
=
taosGetTimestampMs
();
stbObj
.
updateTime
=
stbObj
.
createdTime
;
stbObj
.
uid
=
mndGenerateUid
(
pCreate
->
name
,
TSDB_TABLE_FNAME_LEN
);
...
...
@@ -477,17 +477,13 @@ static int32_t mndCreateStb(SMnode *pMnode, SMnodeMsg *pReq, SMCreateStbReq *pCr
stbObj
.
numOfTags
=
pCreate
->
numOfTags
;
stbObj
.
pColumns
=
malloc
(
stbObj
.
numOfColumns
*
sizeof
(
SSchema
));
if
(
stbObj
.
pColumns
==
NULL
)
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
return
-
1
;
}
memcpy
(
stbObj
.
pColumns
,
pCreate
->
pSchema
,
stbObj
.
numOfColumns
*
sizeof
(
SSchema
));
stbObj
.
pTags
=
malloc
(
stbObj
.
numOfTags
*
sizeof
(
SSchema
));
if
(
stbObj
.
pTags
==
NULL
)
{
if
(
stbObj
.
p
Columns
==
NULL
||
stbObj
.
p
Tags
==
NULL
)
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
return
-
1
;
}
memcpy
(
stbObj
.
pColumns
,
pCreate
->
pSchema
,
stbObj
.
numOfColumns
*
sizeof
(
SSchema
));
memcpy
(
stbObj
.
pTags
,
pCreate
->
pSchema
+
stbObj
.
numOfColumns
,
stbObj
.
numOfTags
*
sizeof
(
SSchema
));
for
(
int32_t
i
=
0
;
i
<
stbObj
.
numOfColumns
;
++
i
)
{
...
...
@@ -853,41 +849,119 @@ static int32_t mndChangeSuperTableColumn(const SStbObj *pOld, SStbObj *pNew, con
return
0
;
}
static
int32_t
mndUpdateStb
(
const
SMAlterStbReq
*
pAlter
,
const
SStbObj
*
pOld
,
SStbObj
*
pNew
)
{
int32_t
code
=
0
;
static
int32_t
mndSetUpdateStbRedoLogs
(
SMnode
*
pMnode
,
STrans
*
pTrans
,
SDbObj
*
pDb
,
SStbObj
*
pStb
)
{
SSdbRaw
*
pRedoRaw
=
mndStbActionEncode
(
pStb
);
if
(
pRedoRaw
==
NULL
)
return
-
1
;
if
(
mndTransAppendRedolog
(
pTrans
,
pRedoRaw
)
!=
0
)
return
-
1
;
if
(
sdbSetRawStatus
(
pRedoRaw
,
SDB_STATUS_CREATING
)
!=
0
)
return
-
1
;
return
0
;
}
static
int32_t
mndSetUpdateStbCommitLogs
(
SMnode
*
pMnode
,
STrans
*
pTrans
,
SDbObj
*
pDb
,
SStbObj
*
pStb
)
{
SSdbRaw
*
pCommitRaw
=
mndStbActionEncode
(
pStb
);
if
(
pCommitRaw
==
NULL
)
return
-
1
;
if
(
mndTransAppendCommitlog
(
pTrans
,
pCommitRaw
)
!=
0
)
return
-
1
;
if
(
sdbSetRawStatus
(
pCommitRaw
,
SDB_STATUS_READY
)
!=
0
)
return
-
1
;
return
0
;
}
static
int32_t
mndSetUpdateStbRedoActions
(
SMnode
*
pMnode
,
STrans
*
pTrans
,
SDbObj
*
pDb
,
SStbObj
*
pStb
)
{
SSdb
*
pSdb
=
pMnode
->
pSdb
;
SVgObj
*
pVgroup
=
NULL
;
void
*
pIter
=
NULL
;
int32_t
contLen
;
while
(
1
)
{
pIter
=
sdbFetch
(
pSdb
,
SDB_VGROUP
,
pIter
,
(
void
**
)
&
pVgroup
);
if
(
pIter
==
NULL
)
break
;
if
(
pVgroup
->
dbUid
!=
pDb
->
uid
)
continue
;
void
*
pReq
=
mndBuildCreateStbReq
(
pMnode
,
pVgroup
,
pStb
,
&
contLen
);
if
(
pReq
==
NULL
)
{
sdbCancelFetch
(
pSdb
,
pIter
);
sdbRelease
(
pSdb
,
pVgroup
);
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
return
-
1
;
}
STransAction
action
=
{
0
};
action
.
epSet
=
mndGetVgroupEpset
(
pMnode
,
pVgroup
);
action
.
pCont
=
pReq
;
action
.
contLen
=
contLen
;
action
.
msgType
=
TDMT_VND_CREATE_STB
;
if
(
mndTransAppendRedoAction
(
pTrans
,
&
action
)
!=
0
)
{
free
(
pReq
);
sdbCancelFetch
(
pSdb
,
pIter
);
sdbRelease
(
pSdb
,
pVgroup
);
return
-
1
;
}
sdbRelease
(
pSdb
,
pVgroup
);
}
return
0
;
}
static
int32_t
mndUpdateStb
(
SMnode
*
pMnode
,
SMnodeMsg
*
pReq
,
const
SMAlterStbReq
*
pAlter
,
SDbObj
*
pDb
,
SStbObj
*
pOld
)
{
SStbObj
stbObj
=
{
0
};
taosRLockLatch
(
&
pOld
->
lock
);
memcpy
(
&
stbObj
,
pOld
,
sizeof
(
SStbObj
));
stbObj
.
pColumns
=
NULL
;
stbObj
.
pTags
=
NULL
;
stbObj
.
updateTime
=
taosGetTimestampMs
();
taosRUnLockLatch
(
&
pOld
->
lock
);
int32_t
code
=
-
1
;
switch
(
pAlter
->
alterType
)
{
case
TSDB_ALTER_TABLE_ADD_TAG_COLUMN
:
code
=
mndAddSuperTableTag
(
pOld
,
pNew
,
pAlter
->
pSchema
,
1
);
code
=
mndAddSuperTableTag
(
pOld
,
&
stbObj
,
pAlter
->
pSchema
,
1
);
break
;
case
TSDB_ALTER_TABLE_DROP_TAG_COLUMN
:
code
=
mndDropSuperTableTag
(
pOld
,
pNew
,
pAlter
->
pSchema
[
0
].
name
);
code
=
mndDropSuperTableTag
(
pOld
,
&
stbObj
,
pAlter
->
pSchema
[
0
].
name
);
break
;
case
TSDB_ALTER_TABLE_CHANGE_TAG_COLUMN
:
code
=
mndModifySuperTableTagName
(
pOld
,
pNew
,
pAlter
->
pSchema
[
0
].
name
,
pAlter
->
pSchema
[
1
].
name
);
code
=
mndModifySuperTableTagName
(
pOld
,
&
stbObj
,
pAlter
->
pSchema
[
0
].
name
,
pAlter
->
pSchema
[
1
].
name
);
break
;
case
TSDB_ALTER_TABLE_MODIFY_TAG_COLUMN
:
code
=
mndChangeSuperTableTag
(
pOld
,
pNew
,
&
pAlter
->
pSchema
[
0
]);
code
=
mndChangeSuperTableTag
(
pOld
,
&
stbObj
,
&
pAlter
->
pSchema
[
0
]);
break
;
case
TSDB_ALTER_TABLE_ADD_COLUMN
:
code
=
mndAddSuperTableColumn
(
pOld
,
pNew
,
pAlter
->
pSchema
,
1
);
code
=
mndAddSuperTableColumn
(
pOld
,
&
stbObj
,
pAlter
->
pSchema
,
1
);
break
;
case
TSDB_ALTER_TABLE_DROP_COLUMN
:
code
=
mndDropSuperTableColumn
(
pOld
,
pNew
,
pAlter
->
pSchema
[
0
].
name
);
code
=
mndDropSuperTableColumn
(
pOld
,
&
stbObj
,
pAlter
->
pSchema
[
0
].
name
);
break
;
case
TSDB_ALTER_TABLE_CHANGE_COLUMN
:
code
=
mndChangeSuperTableColumn
(
pOld
,
pNew
,
&
pAlter
->
pSchema
[
0
]);
code
=
mndChangeSuperTableColumn
(
pOld
,
&
stbObj
,
&
pAlter
->
pSchema
[
0
]);
break
;
default:
terrno
=
TSDB_CODE_MND_INVALID_STB_OPTION
;
break
;
}
if
(
code
!=
0
)
{
tfree
(
pNew
->
pTags
);
tfree
(
pNew
->
pColumns
);
}
if
(
code
!=
0
)
goto
UPDATE_STB_OVER
;
code
=
-
1
;
STrans
*
pTrans
=
mndTransCreate
(
pMnode
,
TRN_POLICY_RETRY
,
&
pReq
->
rpcMsg
);
if
(
pTrans
==
NULL
)
goto
UPDATE_STB_OVER
;
mDebug
(
"trans:%d, used to update stb:%s"
,
pTrans
->
id
,
pAlter
->
name
);
if
(
mndSetUpdateStbRedoLogs
(
pMnode
,
pTrans
,
pDb
,
&
stbObj
)
!=
0
)
goto
UPDATE_STB_OVER
;
if
(
mndSetUpdateStbCommitLogs
(
pMnode
,
pTrans
,
pDb
,
&
stbObj
)
!=
0
)
goto
UPDATE_STB_OVER
;
if
(
mndSetUpdateStbRedoActions
(
pMnode
,
pTrans
,
pDb
,
&
stbObj
)
!=
0
)
goto
UPDATE_STB_OVER
;
if
(
mndTransPrepare
(
pMnode
,
pTrans
)
!=
0
)
goto
UPDATE_STB_OVER
;
code
=
0
;
UPDATE_STB_OVER:
mndTransDrop
(
pTrans
);
tfree
(
stbObj
.
pTags
);
tfree
(
stbObj
.
pColumns
);
return
code
;
}
...
...
@@ -909,14 +983,15 @@ static int32_t mndProcessMAlterStbReq(SMnodeMsg *pReq) {
return
-
1
;
}
SStbObj
stbObj
=
{
0
};
taosRLockLatch
(
&
pStb
->
lock
);
memcpy
(
&
stbObj
,
pStb
,
sizeof
(
SStbObj
));
stbObj
.
pColumns
=
NULL
;
stbObj
.
pTags
=
NULL
;
taosRUnLockLatch
(
&
pStb
->
lock
);
SDbObj
*
pDb
=
mndAcquireDbByStb
(
pMnode
,
pAlter
->
name
);
if
(
pDb
==
NULL
)
{
mndReleaseStb
(
pMnode
,
pStb
);
terrno
=
TSDB_CODE_MND_DB_NOT_SELECTED
;
mError
(
"stb:%s, failed to update since %s"
,
pAlter
->
name
,
terrstr
());
return
-
1
;
}
int32_t
code
=
mndUpdateStb
(
p
Alter
,
pStb
,
&
stbObj
);
int32_t
code
=
mndUpdateStb
(
p
Mnode
,
pReq
,
pAlter
,
pDb
,
pStb
);
mndReleaseStb
(
pMnode
,
pStb
);
if
(
code
!=
0
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录