Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
76a7b98b
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看板
提交
76a7b98b
编写于
12月 21, 2021
作者:
S
Shengliang Guan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
minor changes
上级
546b0f10
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
206 addition
and
78 deletion
+206
-78
include/common/taosmsg.h
include/common/taosmsg.h
+42
-39
source/dnode/mnode/impl/src/mndStb.c
source/dnode/mnode/impl/src/mndStb.c
+164
-39
未找到文件。
include/common/taosmsg.h
浏览文件 @
76a7b98b
...
...
@@ -290,37 +290,6 @@ typedef struct SSchema {
char
name
[
TSDB_COL_NAME_LEN
];
}
SSchema
;
typedef
struct
{
int32_t
contLen
;
int32_t
vgId
;
int8_t
tableType
;
int16_t
numOfColumns
;
int16_t
numOfTags
;
int32_t
tid
;
int32_t
sversion
;
int32_t
tversion
;
int32_t
tagDataLen
;
int32_t
sqlDataLen
;
uint64_t
uid
;
uint64_t
superTableUid
;
uint64_t
createdTime
;
char
tableFname
[
TSDB_TABLE_FNAME_LEN
];
char
stbFname
[
TSDB_TABLE_FNAME_LEN
];
char
data
[];
}
SMDCreateTableMsg
;
typedef
struct
{
int32_t
len
;
// one create table message
char
tableName
[
TSDB_TABLE_FNAME_LEN
];
int8_t
igExists
;
int8_t
getMeta
;
int16_t
numOfTags
;
int16_t
numOfColumns
;
int16_t
sqlLen
;
// the length of SQL, it starts after schema , sql is a null-terminated string
int8_t
reserved
[
16
];
char
schema
[];
}
SCreateTableMsg
;
typedef
struct
{
char
name
[
TSDB_TABLE_FNAME_LEN
];
int8_t
igExists
;
...
...
@@ -341,16 +310,50 @@ typedef struct {
}
SAlterStbMsg
;
typedef
struct
{
char
tableFname
[
TSDB_TABLE_FNAME_LEN
];
char
db
[
TSDB_FULL_DB_NAME_LEN
];
int16_t
type
;
/* operation type */
int16_t
numOfCols
;
/* number of schema */
int32_t
tagValLen
;
SSchema
schema
[];
// tagVal is padded after schema
// char tagVal[];
SMsgHead
head
;
char
name
[
TSDB_TABLE_FNAME_LEN
];
uint64_t
suid
;
int32_t
sverson
;
uint32_t
ttl
;
uint32_t
keep
;
int32_t
numOfTags
;
int32_t
numOfColumns
;
SSchema
pSchema
[];
}
SCreateStbInternalMsg
;
typedef
struct
{
SMsgHead
head
;
char
name
[
TSDB_TABLE_FNAME_LEN
];
uint64_t
suid
;
}
SDropStbInternalMsg
;
typedef
struct
{
SMsgHead
head
;
char
name
[
TSDB_TABLE_FNAME_LEN
];
char
stbFname
[
TSDB_TABLE_FNAME_LEN
];
int8_t
tableType
;
uint64_t
suid
;
int32_t
sversion
;
int32_t
numOfTags
;
int32_t
numOfColumns
;
int32_t
tagDataLen
;
char
data
[];
}
SCreateTableMsg
;
typedef
struct
{
SMsgHead
head
;
char
name
[
TSDB_TABLE_FNAME_LEN
];
int8_t
type
;
/* operation type */
int32_t
numOfCols
;
/* number of schema */
int32_t
numOfTags
;
char
data
[];
}
SAlterTableMsg
;
typedef
struct
{
SMsgHead
head
;
char
name
[
TSDB_TABLE_FNAME_LEN
];
}
SDropTableMsg
;
typedef
struct
{
SMsgHead
head
;
int64_t
uid
;
...
...
source/dnode/mnode/impl/src/mndStb.c
浏览文件 @
76a7b98b
...
...
@@ -248,6 +248,91 @@ static int32_t mndCheckStbMsg(SCreateStbMsg *pCreate) {
return
0
;
}
static
int32_t
mndSetCreateStbRedoLogs
(
SMnode
*
pMnode
,
STrans
*
pTrans
,
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
mndSetCreateStbUndoLogs
(
SMnode
*
pMnode
,
STrans
*
pTrans
,
SStbObj
*
pStb
)
{
SSdbRaw
*
pUndoRaw
=
mndStbActionEncode
(
pStb
);
if
(
pUndoRaw
==
NULL
)
return
-
1
;
if
(
mndTransAppendUndolog
(
pTrans
,
pUndoRaw
)
!=
0
)
return
-
1
;
if
(
sdbSetRawStatus
(
pUndoRaw
,
SDB_STATUS_DROPPED
)
!=
0
)
return
-
1
;
return
0
;
}
static
int32_t
mndSetCreateStbCommitLogs
(
SMnode
*
pMnode
,
STrans
*
pTrans
,
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
mndSetCreateStbRedoActions
(
SMnode
*
pMnode
,
STrans
*
pTrans
,
SStbObj
*
pStb
)
{
// for (int32_t vg = 0; vg < pDb->cfg.numOfVgroups; ++vg) {
// SVgObj *pVgroup = pVgroups + vg;
// for (int32_t vn = 0; vn < pVgroup->replica; ++vn) {
// STransAction action = {0};
// SVnodeGid *pVgid = pVgroup->vnodeGid + vn;
// SDnodeObj *pDnode = mndAcquireDnode(pMnode, pVgid->dnodeId);
// if (pDnode == NULL) return -1;
// action.epSet = mndGetDnodeEpset(pDnode);
// mndReleaseDnode(pMnode, pDnode);
// SCreateVnodeMsg *pMsg = mndBuildCreateVnodeMsg(pMnode, pDnode, pDb, pVgroup);
// if (pMsg == NULL) return -1;
// action.pCont = pMsg;
// action.contLen = sizeof(SCreateVnodeMsg);
// action.msgType = TSDB_MSG_TYPE_CREATE_VNODE_IN;
// if (mndTransAppendRedoAction(pTrans, &action) != 0) {
// free(pMsg);
// return -1;
// }
// }
// }
return
0
;
}
static
int32_t
mndSetCreateStbUndoActions
(
SMnode
*
pMnode
,
STrans
*
pTrans
,
SStbObj
*
pStb
)
{
// for (int32_t vg = 0; vg < pDb->cfg.numOfVgroups; ++vg) {
// SVgObj *pVgroup = pVgroups + vg;
// for (int32_t vn = 0; vn < pVgroup->replica; ++vn) {
// STransAction action = {0};
// SVnodeGid *pVgid = pVgroup->vnodeGid + vn;
// SDnodeObj *pDnode = mndAcquireDnode(pMnode, pVgid->dnodeId);
// if (pDnode == NULL) return -1;
// action.epSet = mndGetDnodeEpset(pDnode);
// mndReleaseDnode(pMnode, pDnode);
// SDropVnodeMsg *pMsg = mndBuildDropVnodeMsg(pMnode, pDnode, pDb, pVgroup);
// if (pMsg == NULL) return -1;
// action.pCont = pMsg;
// action.contLen = sizeof(SDropVnodeMsg);
// action.msgType = TSDB_MSG_TYPE_DROP_VNODE_IN;
// if (mndTransAppendUndoAction(pTrans, &action) != 0) {
// free(pMsg);
// return -1;
// }
// }
// }
return
0
;
}
static
int32_t
mndCreateStb
(
SMnode
*
pMnode
,
SMnodeMsg
*
pMsg
,
SCreateStbMsg
*
pCreate
,
SDbObj
*
pDb
)
{
SStbObj
stbObj
=
{
0
};
tstrncpy
(
stbObj
.
name
,
pCreate
->
name
,
TSDB_TABLE_FNAME_LEN
);
...
...
@@ -269,6 +354,7 @@ static int32_t mndCreateStb(SMnode *pMnode, SMnodeMsg *pMsg, SCreateStbMsg *pCre
}
memcpy
(
stbObj
.
pSchema
,
pCreate
->
pSchema
,
totalSize
);
int32_t
code
=
0
;
STrans
*
pTrans
=
mndTransCreate
(
pMnode
,
TRN_POLICY_ROLLBACK
,
pMsg
->
rpcMsg
.
handle
);
if
(
pTrans
==
NULL
)
{
mError
(
"stb:%s, failed to create since %s"
,
pCreate
->
name
,
terrstr
());
...
...
@@ -276,29 +362,30 @@ static int32_t mndCreateStb(SMnode *pMnode, SMnodeMsg *pMsg, SCreateStbMsg *pCre
}
mDebug
(
"trans:%d, used to create stb:%s"
,
pTrans
->
id
,
pCreate
->
name
);
SSdbRaw
*
pRedoRaw
=
mndStbActionEncode
(
&
stbObj
);
if
(
pRedoRaw
==
NULL
||
mndTransAppendRedolog
(
pTrans
,
pRedoRaw
)
!=
0
)
{
mError
(
"trans:%d, failed to append redo log since %s"
,
pTrans
->
id
,
terrstr
());
mndTransDrop
(
pTrans
);
return
-
1
;
if
(
mndSetCreateStbRedoLogs
(
pMnode
,
pTrans
,
&
stbObj
)
!=
0
)
{
mError
(
"trans:%d, failed to set redo log since %s"
,
pTrans
->
id
,
terrstr
());
goto
CREATE_STB_OVER
;
}
sdbSetRawStatus
(
pRedoRaw
,
SDB_STATUS_CREATING
);
SSdbRaw
*
pUndoRaw
=
mndStbActionEncode
(
&
stbObj
);
if
(
pUndoRaw
==
NULL
||
mndTransAppendUndolog
(
pTrans
,
pUndoRaw
)
!=
0
)
{
mError
(
"trans:%d, failed to append undo log since %s"
,
pTrans
->
id
,
terrstr
());
mndTransDrop
(
pTrans
);
return
-
1
;
if
(
mndSetCreateStbUndoLogs
(
pMnode
,
pTrans
,
&
stbObj
)
!=
0
)
{
mError
(
"trans:%d, failed to set undo log since %s"
,
pTrans
->
id
,
terrstr
());
goto
CREATE_STB_OVER
;
}
sdbSetRawStatus
(
pUndoRaw
,
SDB_STATUS_DROPPED
);
SSdbRaw
*
pCommitRaw
=
mndStbActionEncode
(
&
stbObj
);
if
(
pCommitRaw
==
NULL
||
mndTransAppendCommitlog
(
pTrans
,
pCommitRaw
)
!=
0
)
{
mError
(
"trans:%d, failed to append commit log since %s"
,
pTrans
->
id
,
terrstr
());
mndTransDrop
(
pTrans
);
return
-
1
;
if
(
mndSetCreateStbCommitLogs
(
pMnode
,
pTrans
,
&
stbObj
)
!=
0
)
{
mError
(
"trans:%d, failed to set commit log since %s"
,
pTrans
->
id
,
terrstr
());
goto
CREATE_STB_OVER
;
}
if
(
mndSetCreateStbRedoActions
(
pMnode
,
pTrans
,
&
stbObj
)
!=
0
)
{
mError
(
"trans:%d, failed to set redo actions since %s"
,
pTrans
->
id
,
terrstr
());
goto
CREATE_STB_OVER
;
}
if
(
mndSetCreateStbUndoActions
(
pMnode
,
pTrans
,
&
stbObj
)
!=
0
)
{
mError
(
"trans:%d, failed to set redo actions since %s"
,
pTrans
->
id
,
terrstr
());
goto
CREATE_STB_OVER
;
}
sdbSetRawStatus
(
pCommitRaw
,
SDB_STATUS_READY
);
if
(
mndTransPrepare
(
pMnode
,
pTrans
)
!=
0
)
{
mError
(
"trans:%d, failed to prepare since %s"
,
pTrans
->
id
,
terrstr
());
...
...
@@ -306,8 +393,11 @@ static int32_t mndCreateStb(SMnode *pMnode, SMnodeMsg *pMsg, SCreateStbMsg *pCre
return
-
1
;
}
code
=
0
;
CREATE_STB_OVER:
mndTransDrop
(
pTrans
);
return
0
;
return
code
;
}
static
int32_t
mndProcessCreateStbMsg
(
SMnodeMsg
*
pMsg
)
{
...
...
@@ -416,7 +506,39 @@ static int32_t mndProcessAlterStbMsg(SMnodeMsg *pMsg) {
static
int32_t
mndProcessAlterStbInRsp
(
SMnodeMsg
*
pMsg
)
{
return
0
;
}
static
int32_t
mndSetDropStbRedoLogs
(
SMnode
*
pMnode
,
STrans
*
pTrans
,
SStbObj
*
pStb
)
{
SSdbRaw
*
pRedoRaw
=
mndStbActionEncode
(
pStb
);
if
(
pRedoRaw
==
NULL
)
return
-
1
;
if
(
mndTransAppendRedolog
(
pTrans
,
pRedoRaw
)
!=
0
)
return
-
1
;
if
(
sdbSetRawStatus
(
pRedoRaw
,
SDB_STATUS_DROPPING
)
!=
0
)
return
-
1
;
return
0
;
}
static
int32_t
mndSetDropStbUndoLogs
(
SMnode
*
pMnode
,
STrans
*
pTrans
,
SStbObj
*
pStb
)
{
SSdbRaw
*
pUndoRaw
=
mndStbActionEncode
(
pStb
);
if
(
pUndoRaw
==
NULL
)
return
-
1
;
if
(
mndTransAppendUndolog
(
pTrans
,
pUndoRaw
)
!=
0
)
return
-
1
;
if
(
sdbSetRawStatus
(
pUndoRaw
,
SDB_STATUS_READY
)
!=
0
)
return
-
1
;
return
0
;
}
static
int32_t
mndSetDropStbCommitLogs
(
SMnode
*
pMnode
,
STrans
*
pTrans
,
SStbObj
*
pStb
)
{
SSdbRaw
*
pCommitRaw
=
mndStbActionEncode
(
pStb
);
if
(
pCommitRaw
==
NULL
)
return
-
1
;
if
(
mndTransAppendCommitlog
(
pTrans
,
pCommitRaw
)
!=
0
)
return
-
1
;
if
(
sdbSetRawStatus
(
pCommitRaw
,
SDB_STATUS_DROPPED
)
!=
0
)
return
-
1
;
return
0
;
}
static
int32_t
mndSetDropStbRedoActions
(
SMnode
*
pMnode
,
STrans
*
pTrans
,
SStbObj
*
pStb
)
{
return
0
;
}
static
int32_t
mndSetDropStbUndoActions
(
SMnode
*
pMnode
,
STrans
*
pTrans
,
SStbObj
*
pStb
)
{
return
0
;
}
static
int32_t
mndDropStb
(
SMnode
*
pMnode
,
SMnodeMsg
*
pMsg
,
SStbObj
*
pStb
)
{
int32_t
code
=
-
1
;
STrans
*
pTrans
=
mndTransCreate
(
pMnode
,
TRN_POLICY_ROLLBACK
,
pMsg
->
rpcMsg
.
handle
);
if
(
pTrans
==
NULL
)
{
mError
(
"stb:%s, failed to drop since %s"
,
pStb
->
name
,
terrstr
());
...
...
@@ -424,36 +546,39 @@ static int32_t mndDropStb(SMnode *pMnode, SMnodeMsg *pMsg, SStbObj *pStb) {
}
mDebug
(
"trans:%d, used to drop stb:%s"
,
pTrans
->
id
,
pStb
->
name
);
SSdbRaw
*
pRedoRaw
=
mndStbActionEncode
(
pStb
);
if
(
pRedoRaw
==
NULL
||
mndTransAppendRedolog
(
pTrans
,
pRedoRaw
)
!=
0
)
{
mError
(
"trans:%d, failed to append redo log since %s"
,
pTrans
->
id
,
terrstr
());
mndTransDrop
(
pTrans
);
return
-
1
;
if
(
mndSetDropStbRedoLogs
(
pMnode
,
pTrans
,
pStb
)
!=
0
)
{
mError
(
"trans:%d, failed to set redo log since %s"
,
pTrans
->
id
,
terrstr
());
goto
DROP_STB_OVER
;
}
sdbSetRawStatus
(
pRedoRaw
,
SDB_STATUS_DROPPING
);
SSdbRaw
*
pUndoRaw
=
mndStbActionEncode
(
pStb
);
if
(
pUndoRaw
==
NULL
||
mndTransAppendUndolog
(
pTrans
,
pUndoRaw
)
!=
0
)
{
mError
(
"trans:%d, failed to append undo log since %s"
,
pTrans
->
id
,
terrstr
());
mndTransDrop
(
pTrans
);
return
-
1
;
if
(
mndSetDropStbUndoLogs
(
pMnode
,
pTrans
,
pStb
)
!=
0
)
{
mError
(
"trans:%d, failed to set undo log since %s"
,
pTrans
->
id
,
terrstr
());
goto
DROP_STB_OVER
;
}
sdbSetRawStatus
(
pUndoRaw
,
SDB_STATUS_READY
);
SSdbRaw
*
pCommitRaw
=
mndStbActionEncode
(
pStb
);
if
(
pCommitRaw
==
NULL
||
mndTransAppendCommitlog
(
pTrans
,
pCommitRaw
)
!=
0
)
{
mError
(
"trans:%d, failed to append commit log since %s"
,
pTrans
->
id
,
terrstr
());
mndTransDrop
(
pTrans
);
return
-
1
;
if
(
mndSetDropStbCommitLogs
(
pMnode
,
pTrans
,
pStb
)
!=
0
)
{
mError
(
"trans:%d, failed to set commit log since %s"
,
pTrans
->
id
,
terrstr
());
goto
DROP_STB_OVER
;
}
if
(
mndSetDropStbRedoActions
(
pMnode
,
pTrans
,
pStb
)
!=
0
)
{
mError
(
"trans:%d, failed to set redo actions since %s"
,
pTrans
->
id
,
terrstr
());
goto
DROP_STB_OVER
;
}
if
(
mndSetDropStbUndoActions
(
pMnode
,
pTrans
,
pStb
)
!=
0
)
{
mError
(
"trans:%d, failed to set redo actions since %s"
,
pTrans
->
id
,
terrstr
());
goto
DROP_STB_OVER
;
}
sdbSetRawStatus
(
pCommitRaw
,
SDB_STATUS_DROPPED
);
if
(
mndTransPrepare
(
pMnode
,
pTrans
)
!=
0
)
{
mError
(
"trans:%d, failed to prepare since %s"
,
pTrans
->
id
,
terrstr
());
mndTransDrop
(
pTrans
);
return
-
1
;
goto
DROP_STB_OVER
;
}
code
=
0
;
DROP_STB_OVER:
mndTransDrop
(
pTrans
);
return
0
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录