Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
loser646
TDengine
提交
ab805d41
T
TDengine
项目概览
loser646
/
TDengine
与 Fork 源项目一致
Fork自
taosdata / TDengine
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
ab805d41
编写于
3月 15, 2020
作者:
S
slguan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[TD-10] refact create table
上级
b23c4cd1
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
93 addition
and
111 deletion
+93
-111
src/dnode/src/dnodeWrite.c
src/dnode/src/dnodeWrite.c
+1
-0
src/inc/taosmsg.h
src/inc/taosmsg.h
+1
-2
src/mnode/src/mgmtChildTable.c
src/mnode/src/mgmtChildTable.c
+4
-8
src/mnode/src/mgmtNormalTable.c
src/mnode/src/mgmtNormalTable.c
+0
-6
src/mnode/src/mgmtTable.c
src/mnode/src/mgmtTable.c
+81
-89
src/mnode/src/mgmtVgroup.c
src/mnode/src/mgmtVgroup.c
+6
-6
未找到文件。
src/dnode/src/dnodeWrite.c
浏览文件 @
ab805d41
...
@@ -402,3 +402,4 @@ static void dnodeProcessDropStableMsg(SWriteMsg *pMsg) {
...
@@ -402,3 +402,4 @@ static void dnodeProcessDropStableMsg(SWriteMsg *pMsg) {
SRpcMsg
rpcRsp
=
{.
handle
=
pMsg
->
rpcMsg
.
handle
,
.
pCont
=
NULL
,
.
contLen
=
0
,
.
code
=
0
,
.
msgType
=
0
};
SRpcMsg
rpcRsp
=
{.
handle
=
pMsg
->
rpcMsg
.
handle
,
.
pCont
=
NULL
,
.
contLen
=
0
,
.
code
=
0
,
.
msgType
=
0
};
rpcSendResponse
(
&
rpcRsp
);
rpcSendResponse
(
&
rpcRsp
);
}
}
src/inc/taosmsg.h
浏览文件 @
ab805d41
...
@@ -332,11 +332,10 @@ typedef struct {
...
@@ -332,11 +332,10 @@ typedef struct {
}
SMgmtHead
;
}
SMgmtHead
;
typedef
struct
{
typedef
struct
{
int32_t
contLen
;
int32_t
vgId
;
int32_t
vgId
;
int32_t
sid
;
int32_t
sid
;
int32_t
numOfVPeers
;
uint64_t
uid
;
uint64_t
uid
;
SVnodeDesc
vpeerDesc
[
TSDB_MAX_MPEERS
];
char
tableId
[
TSDB_TABLE_ID_LEN
+
1
];
char
tableId
[
TSDB_TABLE_ID_LEN
+
1
];
}
SMDDropTableMsg
;
}
SMDDropTableMsg
;
...
...
src/mnode/src/mgmtChildTable.c
浏览文件 @
ab805d41
...
@@ -373,14 +373,10 @@ int32_t mgmtDropChildTable(SDbObj *pDb, SChildTableObj *pTable) {
...
@@ -373,14 +373,10 @@ int32_t mgmtDropChildTable(SDbObj *pDb, SChildTableObj *pTable) {
}
}
strcpy
(
pRemove
->
tableId
,
pTable
->
tableId
);
strcpy
(
pRemove
->
tableId
,
pTable
->
tableId
);
pRemove
->
sid
=
htonl
(
pTable
->
sid
);
pRemove
->
vgId
=
htonl
(
pTable
->
vgId
);
pRemove
->
uid
=
htobe64
(
pTable
->
uid
);
pRemove
->
contLen
=
htonl
(
sizeof
(
SMDDropTableMsg
));
pRemove
->
sid
=
htonl
(
pTable
->
sid
);
pRemove
->
numOfVPeers
=
htonl
(
pVgroup
->
numOfVnodes
);
pRemove
->
uid
=
htobe64
(
pTable
->
uid
);
for
(
int
i
=
0
;
i
<
pVgroup
->
numOfVnodes
;
++
i
)
{
pRemove
->
vpeerDesc
[
i
].
ip
=
htonl
(
pVgroup
->
vnodeGid
[
i
].
ip
);
pRemove
->
vpeerDesc
[
i
].
vnode
=
htonl
(
pVgroup
->
vnodeGid
[
i
].
vnode
);
}
SRpcIpSet
ipSet
=
mgmtGetIpSetFromVgroup
(
pVgroup
);
SRpcIpSet
ipSet
=
mgmtGetIpSetFromVgroup
(
pVgroup
);
...
...
src/mnode/src/mgmtNormalTable.c
浏览文件 @
ab805d41
...
@@ -411,12 +411,6 @@ int32_t mgmtDropNormalTable(SDbObj *pDb, SNormalTableObj *pTable) {
...
@@ -411,12 +411,6 @@ int32_t mgmtDropNormalTable(SDbObj *pDb, SNormalTableObj *pTable) {
pRemove
->
sid
=
htonl
(
pTable
->
sid
);
pRemove
->
sid
=
htonl
(
pTable
->
sid
);
pRemove
->
uid
=
htobe64
(
pTable
->
uid
);
pRemove
->
uid
=
htobe64
(
pTable
->
uid
);
pRemove
->
numOfVPeers
=
htonl
(
pVgroup
->
numOfVnodes
);
for
(
int
i
=
0
;
i
<
pVgroup
->
numOfVnodes
;
++
i
)
{
pRemove
->
vpeerDesc
[
i
].
ip
=
htonl
(
pVgroup
->
vnodeGid
[
i
].
ip
);
pRemove
->
vpeerDesc
[
i
].
vnode
=
htonl
(
pVgroup
->
vnodeGid
[
i
].
vnode
);
}
SRpcIpSet
ipSet
=
mgmtGetIpSetFromVgroup
(
pVgroup
);
SRpcIpSet
ipSet
=
mgmtGetIpSetFromVgroup
(
pVgroup
);
mTrace
(
"table:%s, send drop table msg"
,
pRemove
->
tableId
);
mTrace
(
"table:%s, send drop table msg"
,
pRemove
->
tableId
);
SRpcMsg
rpcMsg
=
{
SRpcMsg
rpcMsg
=
{
...
...
src/mnode/src/mgmtTable.c
浏览文件 @
ab805d41
...
@@ -135,80 +135,7 @@ int32_t mgmtGetTableMeta(SDbObj *pDb, STableInfo *pTable, STableMeta *pMeta, boo
...
@@ -135,80 +135,7 @@ int32_t mgmtGetTableMeta(SDbObj *pDb, STableInfo *pTable, STableMeta *pMeta, boo
}
}
static
void
mgmtCreateTable
(
SVgObj
*
pVgroup
,
SQueuedMsg
*
pMsg
)
{
static
void
mgmtCreateTable
(
SVgObj
*
pVgroup
,
SQueuedMsg
*
pMsg
)
{
SCMCreateTableMsg
*
pCreate
=
pMsg
->
pCont
;
int32_t
sid
=
taosAllocateId
(
pVgroup
->
idPool
);
if
(
sid
<
0
)
{
mTrace
(
"tables:%s, no enough sid in vgroup:%d"
,
pVgroup
->
vgId
);
mgmtCreateVgroup
(
pMsg
);
return
;
}
int32_t
code
;
STableInfo
*
pTable
;
SMDCreateTableMsg
*
pMDCreate
=
NULL
;
if
(
pCreate
->
numOfColumns
==
0
)
{
mTrace
(
"table:%s, is a child table, vgroup:%d sid:%d ahandle:%p"
,
pCreate
->
tableId
,
pVgroup
->
vgId
,
sid
,
pMsg
);
code
=
mgmtCreateChildTable
(
pCreate
,
pMsg
->
contLen
,
pVgroup
,
sid
,
&
pMDCreate
,
&
pTable
);
}
else
{
mTrace
(
"table:%s, is a normal table, vgroup:%d sid:%d ahandle:%p"
,
pCreate
->
tableId
,
pVgroup
->
vgId
,
sid
,
pMsg
);
code
=
mgmtCreateNormalTable
(
pCreate
,
pMsg
->
contLen
,
pVgroup
,
sid
,
&
pMDCreate
,
&
pTable
);
}
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
mTrace
(
"table:%s, failed to create in vgroup:%d"
,
pCreate
->
tableId
,
pVgroup
->
vgId
);
mgmtSendSimpleResp
(
pMsg
->
thandle
,
code
);
return
;
}
SRpcIpSet
ipSet
=
mgmtGetIpSetFromVgroup
(
pVgroup
);
SRpcMsg
rpcMsg
=
{
.
handle
=
pMsg
,
.
pCont
=
pMDCreate
,
.
contLen
=
htonl
(
pMDCreate
->
contLen
),
.
code
=
0
,
.
msgType
=
TSDB_MSG_TYPE_MD_CREATE_TABLE
};
pMsg
->
ahandle
=
pTable
;
mgmtSendMsgToDnode
(
&
ipSet
,
&
rpcMsg
);
}
int32_t
mgmtDropTable
(
SDbObj
*
pDb
,
char
*
tableId
,
int32_t
ignore
)
{
STableInfo
*
pTable
=
mgmtGetTable
(
tableId
);
if
(
pTable
==
NULL
)
{
if
(
ignore
)
{
mTrace
(
"table:%s, table is not exist, think it success"
,
tableId
);
return
TSDB_CODE_SUCCESS
;
}
else
{
mError
(
"table:%s, failed to create table, table not exist"
,
tableId
);
return
TSDB_CODE_INVALID_TABLE
;
}
}
if
(
mgmtCheckIsMonitorDB
(
pDb
->
name
,
tsMonitorDbName
))
{
mError
(
"table:%s, failed to create table, in monitor database"
,
tableId
);
return
TSDB_CODE_MONITOR_DB_FORBIDDEN
;
}
switch
(
pTable
->
type
)
{
case
TSDB_SUPER_TABLE
:
mTrace
(
"table:%s, start to drop super table"
,
tableId
);
return
mgmtDropSuperTable
(
pDb
,
(
SSuperTableObj
*
)
pTable
);
case
TSDB_CHILD_TABLE
:
mTrace
(
"table:%s, start to drop child table"
,
tableId
);
return
mgmtDropChildTable
(
pDb
,
(
SChildTableObj
*
)
pTable
);
case
TSDB_NORMAL_TABLE
:
mTrace
(
"table:%s, start to drop normal table"
,
tableId
);
return
mgmtDropNormalTable
(
pDb
,
(
SNormalTableObj
*
)
pTable
);
case
TSDB_STREAM_TABLE
:
mTrace
(
"table:%s, start to drop stream table"
,
tableId
);
return
mgmtDropNormalTable
(
pDb
,
(
SNormalTableObj
*
)
pTable
);
default:
mError
(
"table:%s, invalid table type:%d"
,
tableId
,
pTable
->
type
);
return
TSDB_CODE_INVALID_TABLE
;
}
}
}
int32_t
mgmtAlterTable
(
SDbObj
*
pDb
,
SCMAlterTableMsg
*
pAlter
)
{
int32_t
mgmtAlterTable
(
SDbObj
*
pDb
,
SCMAlterTableMsg
*
pAlter
)
{
...
@@ -494,29 +421,58 @@ void mgmtProcessCreateTableMsg(SQueuedMsg *pMsg) {
...
@@ -494,29 +421,58 @@ void mgmtProcessCreateTableMsg(SQueuedMsg *pMsg) {
if
(
pVgroup
==
NULL
)
{
if
(
pVgroup
==
NULL
)
{
mTrace
(
"table:%s, start to create a new vgroup"
,
pCreate
->
tableId
);
mTrace
(
"table:%s, start to create a new vgroup"
,
pCreate
->
tableId
);
mgmtCreateVgroup
(
newMsg
);
mgmtCreateVgroup
(
newMsg
);
return
;
}
int32_t
sid
=
taosAllocateId
(
pVgroup
->
idPool
);
if
(
sid
<
0
)
{
mTrace
(
"tables:%s, no enough sid in vgroup:%d"
,
pVgroup
->
vgId
);
mgmtCreateVgroup
(
newMsg
);
return
;
}
SMDCreateTableMsg
*
pMDCreate
=
NULL
;
if
(
pCreate
->
numOfColumns
==
0
)
{
mTrace
(
"table:%s, is a child table, vgroup:%d sid:%d ahandle:%p"
,
pCreate
->
tableId
,
pVgroup
->
vgId
,
sid
,
pMsg
);
code
=
mgmtCreateChildTable
(
pCreate
,
pMsg
->
contLen
,
pVgroup
,
sid
,
&
pMDCreate
,
&
pTable
);
}
else
{
}
else
{
mTrace
(
"table:%s,
vgroup:%d is selected"
,
pCreate
->
tableId
,
pVgroup
->
vgId
);
mTrace
(
"table:%s,
is a normal table, vgroup:%d sid:%d ahandle:%p"
,
pCreate
->
tableId
,
pVgroup
->
vgId
,
sid
,
pMsg
);
mgmtCreateTable
(
pVgroup
,
newMsg
);
code
=
mgmtCreateNormalTable
(
pCreate
,
pMsg
->
contLen
,
pVgroup
,
sid
,
&
pMDCreate
,
&
pTable
);
}
}
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
mTrace
(
"table:%s, failed to create in vgroup:%d"
,
pCreate
->
tableId
,
pVgroup
->
vgId
);
mgmtSendSimpleResp
(
pMsg
->
thandle
,
code
);
return
;
}
SRpcIpSet
ipSet
=
mgmtGetIpSetFromVgroup
(
pVgroup
);
SRpcMsg
rpcMsg
=
{
.
handle
=
newMsg
,
.
pCont
=
pMDCreate
,
.
contLen
=
htonl
(
pMDCreate
->
contLen
),
.
code
=
0
,
.
msgType
=
TSDB_MSG_TYPE_MD_CREATE_TABLE
};
newMsg
->
ahandle
=
pTable
;
mgmtSendMsgToDnode
(
&
ipSet
,
&
rpcMsg
);
}
}
void
mgmtProcessDropTableMsg
(
SQueuedMsg
*
pMsg
)
{
void
mgmtProcessDropTableMsg
(
SQueuedMsg
*
pMsg
)
{
SCMDropTableMsg
*
pDrop
=
pMsg
->
pCont
;
if
(
mgmtCheckRedirect
(
pMsg
->
thandle
))
return
;
if
(
mgmtCheckRedirect
(
pMsg
->
thandle
))
{
SCMDropTableMsg
*
pDrop
=
pMsg
->
pCont
;
mError
(
"thandle:%p, failed to drop table:%s, need redirect message"
,
pMsg
->
thandle
,
pDrop
->
tableId
);
mTrace
(
"table:%s, drop msg is received from thandle:%p"
,
pDrop
->
tableId
,
pMsg
->
thandle
);
return
;
}
SUserObj
*
pUser
=
mgmtGetUserFromConn
(
pMsg
->
thandle
);
if
(
mgmtCheckExpired
())
{
if
(
pUser
==
NULL
)
{
mError
(
"table:%s, failed to drop, grant expired"
,
pDrop
->
tableId
);
mError
(
"table:%s, failed to drop table, invalid user"
,
pDrop
->
tableId
);
mgmtSendSimpleResp
(
pMsg
->
thandle
,
TSDB_CODE_GRANT_EXPIRED
);
mgmtSendSimpleResp
(
pMsg
->
thandle
,
TSDB_CODE_INVALID_USER
);
return
;
return
;
}
}
if
(
!
pUser
->
writeAuth
)
{
if
(
!
p
Msg
->
p
User
->
writeAuth
)
{
mError
(
"table:%s, failed to drop
table
, no rights"
,
pDrop
->
tableId
);
mError
(
"table:%s, failed to drop, no rights"
,
pDrop
->
tableId
);
mgmtSendSimpleResp
(
pMsg
->
thandle
,
TSDB_CODE_NO_RIGHTS
);
mgmtSendSimpleResp
(
pMsg
->
thandle
,
TSDB_CODE_NO_RIGHTS
);
return
;
return
;
}
}
...
@@ -528,9 +484,45 @@ void mgmtProcessDropTableMsg(SQueuedMsg *pMsg) {
...
@@ -528,9 +484,45 @@ void mgmtProcessDropTableMsg(SQueuedMsg *pMsg) {
return
;
return
;
}
}
int32_t
code
=
mgmtDropTable
(
pDb
,
pDrop
->
tableId
,
pDrop
->
igNotExists
);
STableInfo
*
pTable
=
mgmtGetTable
(
pDrop
->
tableId
);
if
(
code
!=
TSDB_CODE_ACTION_IN_PROGRESS
)
{
if
(
pTable
==
NULL
)
{
mgmtSendSimpleResp
(
pMsg
->
thandle
,
code
);
if
(
pDrop
->
igNotExists
)
{
mTrace
(
"table:%s, table is not exist, think drop success"
,
pDrop
->
tableId
);
mgmtSendSimpleResp
(
pMsg
->
thandle
,
TSDB_CODE_SUCCESS
);
return
;
}
else
{
mError
(
"table:%s, failed to drop table, table not exist"
,
pDrop
->
tableId
);
mgmtSendSimpleResp
(
pMsg
->
thandle
,
TSDB_CODE_INVALID_TABLE
);
return
;
}
}
if
(
mgmtCheckIsMonitorDB
(
pDb
->
name
,
tsMonitorDbName
))
{
mError
(
"table:%s, failed to create table, in monitor database"
,
pDrop
->
tableId
);
mgmtSendSimpleResp
(
pMsg
->
thandle
,
TSDB_CODE_MONITOR_DB_FORBIDDEN
);
return
;
}
switch
(
pTable
->
type
)
{
case
TSDB_SUPER_TABLE
:
mTrace
(
"table:%s, start to drop super table"
,
pDrop
->
tableId
);
mgmtDropSuperTable
(
pDb
,
(
SSuperTableObj
*
)
pTable
);
break
;
case
TSDB_CHILD_TABLE
:
mTrace
(
"table:%s, start to drop child table"
,
pDrop
->
tableId
);
mgmtDropChildTable
(
pDb
,
(
SChildTableObj
*
)
pTable
);
break
;
case
TSDB_NORMAL_TABLE
:
mTrace
(
"table:%s, start to drop normal table"
,
pDrop
->
tableId
);
mgmtDropNormalTable
(
pDb
,
(
SNormalTableObj
*
)
pTable
);
break
;
case
TSDB_STREAM_TABLE
:
mTrace
(
"table:%s, start to drop stream table"
,
pDrop
->
tableId
);
mgmtDropNormalTable
(
pDb
,
(
SNormalTableObj
*
)
pTable
);
break
;
default:
mError
(
"table:%s, invalid table type:%d"
,
pDrop
->
tableId
,
pTable
->
type
);
mgmtSendSimpleResp
(
pMsg
->
thandle
,
TSDB_CODE_INVALID_TABLE
);
}
}
}
}
...
...
src/mnode/src/mgmtVgroup.c
浏览文件 @
ab805d41
...
@@ -189,12 +189,12 @@ int32_t mgmtDropVgroup(SDbObj *pDb, SVgObj *pVgroup) {
...
@@ -189,12 +189,12 @@ int32_t mgmtDropVgroup(SDbObj *pDb, SVgObj *pVgroup) {
STableInfo
*
pTable
;
STableInfo
*
pTable
;
if
(
pVgroup
->
numOfTables
>
0
)
{
if
(
pVgroup
->
numOfTables
>
0
)
{
for
(
int32_t
i
=
0
;
i
<
pDb
->
cfg
.
maxSessions
;
++
i
)
{
//
for (int32_t i = 0; i < pDb->cfg.maxSessions; ++i) {
if
(
pVgroup
->
tableList
!=
NULL
)
{
//
if (pVgroup->tableList != NULL) {
pTable
=
pVgroup
->
tableList
[
i
];
//
pTable = pVgroup->tableList[i];
if
(
pTable
)
mgmtDropTable
(
pDb
,
pTable
->
tableId
,
0
);
//
if (pTable) mgmtDropTable(pDb, pTable->tableId, 0);
}
//
}
}
//
}
}
}
mTrace
(
"vgroup:%d, db:%s replica:%d is deleted"
,
pVgroup
->
vgId
,
pDb
->
name
,
pVgroup
->
numOfVnodes
);
mTrace
(
"vgroup:%d, db:%s replica:%d is deleted"
,
pVgroup
->
vgId
,
pDb
->
name
,
pVgroup
->
numOfVnodes
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录