Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
a2162892
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看板
提交
a2162892
编写于
2月 08, 2022
作者:
S
Shengliang Guan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update stb
上级
a342af36
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
105 addition
and
46 deletion
+105
-46
include/common/tmsg.h
include/common/tmsg.h
+2
-1
source/dnode/mnode/impl/inc/mndDef.h
source/dnode/mnode/impl/inc/mndDef.h
+3
-1
source/dnode/mnode/impl/src/mndStb.c
source/dnode/mnode/impl/src/mndStb.c
+100
-44
未找到文件。
include/common/tmsg.h
浏览文件 @
a2162892
...
...
@@ -265,7 +265,8 @@ typedef struct {
typedef
struct
{
char
name
[
TSDB_TABLE_FNAME_LEN
];
int8_t
alterType
;
SSchema
schema
;
int32_t
numOfColumns
;
SSchema
pSchema
[];
}
SMAlterStbReq
;
typedef
struct
{
...
...
source/dnode/mnode/impl/inc/mndDef.h
浏览文件 @
a2162892
...
...
@@ -301,10 +301,12 @@ typedef struct {
uint64_t
uid
;
uint64_t
dbUid
;
int32_t
version
;
int32_t
nextColId
;
int32_t
numOfColumns
;
int32_t
numOfTags
;
SSchema
*
pTags
;
SSchema
*
pColumns
;
SRWLatch
lock
;
SSchema
*
pSchema
;
}
SStbObj
;
typedef
struct
{
...
...
source/dnode/mnode/impl/src/mndStb.c
浏览文件 @
a2162892
...
...
@@ -84,12 +84,20 @@ static SSdbRaw *mndStbActionEncode(SStbObj *pStb) {
SDB_SET_INT64
(
pRaw
,
dataPos
,
pStb
->
uid
,
STB_ENCODE_OVER
)
SDB_SET_INT64
(
pRaw
,
dataPos
,
pStb
->
dbUid
,
STB_ENCODE_OVER
)
SDB_SET_INT32
(
pRaw
,
dataPos
,
pStb
->
version
,
STB_ENCODE_OVER
)
SDB_SET_INT32
(
pRaw
,
dataPos
,
pStb
->
nextColId
,
STB_ENCODE_OVER
)
SDB_SET_INT32
(
pRaw
,
dataPos
,
pStb
->
numOfColumns
,
STB_ENCODE_OVER
)
SDB_SET_INT32
(
pRaw
,
dataPos
,
pStb
->
numOfTags
,
STB_ENCODE_OVER
)
int32_t
totalCols
=
pStb
->
numOfColumns
+
pStb
->
numOfTags
;
for
(
int32_t
i
=
0
;
i
<
totalCols
;
++
i
)
{
SSchema
*
pSchema
=
&
pStb
->
pSchema
[
i
];
for
(
int32_t
i
=
0
;
i
<
pStb
->
numOfColumns
;
++
i
)
{
SSchema
*
pSchema
=
&
pStb
->
pColumns
[
i
];
SDB_SET_INT8
(
pRaw
,
dataPos
,
pSchema
->
type
,
STB_ENCODE_OVER
)
SDB_SET_INT32
(
pRaw
,
dataPos
,
pSchema
->
colId
,
STB_ENCODE_OVER
)
SDB_SET_INT32
(
pRaw
,
dataPos
,
pSchema
->
bytes
,
STB_ENCODE_OVER
)
SDB_SET_BINARY
(
pRaw
,
dataPos
,
pSchema
->
name
,
TSDB_COL_NAME_LEN
,
STB_ENCODE_OVER
)
}
for
(
int32_t
i
=
0
;
i
<
pStb
->
numOfTags
;
++
i
)
{
SSchema
*
pSchema
=
&
pStb
->
pTags
[
i
];
SDB_SET_INT8
(
pRaw
,
dataPos
,
pSchema
->
type
,
STB_ENCODE_OVER
)
SDB_SET_INT32
(
pRaw
,
dataPos
,
pSchema
->
colId
,
STB_ENCODE_OVER
)
SDB_SET_INT32
(
pRaw
,
dataPos
,
pSchema
->
bytes
,
STB_ENCODE_OVER
)
...
...
@@ -137,17 +145,26 @@ static SSdbRow *mndStbActionDecode(SSdbRaw *pRaw) {
SDB_GET_INT64
(
pRaw
,
dataPos
,
&
pStb
->
uid
,
STB_DECODE_OVER
)
SDB_GET_INT64
(
pRaw
,
dataPos
,
&
pStb
->
dbUid
,
STB_DECODE_OVER
)
SDB_GET_INT32
(
pRaw
,
dataPos
,
&
pStb
->
version
,
STB_DECODE_OVER
)
SDB_GET_INT32
(
pRaw
,
dataPos
,
&
pStb
->
nextColId
,
STB_DECODE_OVER
)
SDB_GET_INT32
(
pRaw
,
dataPos
,
&
pStb
->
numOfColumns
,
STB_DECODE_OVER
)
SDB_GET_INT32
(
pRaw
,
dataPos
,
&
pStb
->
numOfTags
,
STB_DECODE_OVER
)
int32_t
totalCols
=
pStb
->
numOfColumns
+
pStb
->
numOfTags
;
pStb
->
p
Schema
=
calloc
(
totalCol
s
,
sizeof
(
SSchema
));
if
(
pStb
->
p
Schema
==
NULL
)
{
pStb
->
pColumns
=
calloc
(
pStb
->
numOfColumns
,
sizeof
(
SSchema
))
;
pStb
->
p
Tags
=
calloc
(
pStb
->
numOfTag
s
,
sizeof
(
SSchema
));
if
(
pStb
->
p
Columns
==
NULL
||
pStb
->
pTags
==
NULL
)
{
goto
STB_DECODE_OVER
;
}
for
(
int32_t
i
=
0
;
i
<
totalCols
;
++
i
)
{
SSchema
*
pSchema
=
&
pStb
->
pSchema
[
i
];
for
(
int32_t
i
=
0
;
i
<
pStb
->
numOfColumns
;
++
i
)
{
SSchema
*
pSchema
=
&
pStb
->
pColumns
[
i
];
SDB_GET_INT8
(
pRaw
,
dataPos
,
&
pSchema
->
type
,
STB_DECODE_OVER
)
SDB_GET_INT32
(
pRaw
,
dataPos
,
&
pSchema
->
colId
,
STB_DECODE_OVER
)
SDB_GET_INT32
(
pRaw
,
dataPos
,
&
pSchema
->
bytes
,
STB_DECODE_OVER
)
SDB_GET_BINARY
(
pRaw
,
dataPos
,
pSchema
->
name
,
TSDB_COL_NAME_LEN
,
STB_DECODE_OVER
)
}
for
(
int32_t
i
=
0
;
i
<
pStb
->
numOfTags
;
++
i
)
{
SSchema
*
pSchema
=
&
pStb
->
pTags
[
i
];
SDB_GET_INT8
(
pRaw
,
dataPos
,
&
pSchema
->
type
,
STB_DECODE_OVER
)
SDB_GET_INT32
(
pRaw
,
dataPos
,
&
pSchema
->
colId
,
STB_DECODE_OVER
)
SDB_GET_INT32
(
pRaw
,
dataPos
,
&
pSchema
->
bytes
,
STB_DECODE_OVER
)
...
...
@@ -183,13 +200,24 @@ static int32_t mndStbActionUpdate(SSdb *pSdb, SStbObj *pOld, SStbObj *pNew) {
mTrace
(
"stb:%s, perform update action, old row:%p new row:%p"
,
pOld
->
name
,
pOld
,
pNew
);
taosWLockLatch
(
&
pOld
->
lock
);
int32_t
totalCols
=
pNew
->
numOfTags
+
pNew
->
numOfColumns
;
int32_t
totalSize
=
totalCols
*
sizeof
(
SSchema
);
if
(
pOld
->
numOfTags
+
pOld
->
numOfColumns
<
totalCols
)
{
void
*
pSchema
=
malloc
(
totalSize
);
if
(
pOld
->
numOfColumns
<
pNew
->
numOfColumns
)
{
void
*
pSchema
=
malloc
(
pOld
->
numOfColumns
*
sizeof
(
SSchema
));
if
(
pSchema
!=
NULL
)
{
free
(
pOld
->
pSchema
);
pOld
->
pSchema
=
pSchema
;
free
(
pOld
->
pColumns
);
pOld
->
pColumns
=
pSchema
;
}
else
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
mTrace
(
"stb:%s, failed to perform update action since %s"
,
pOld
->
name
,
terrstr
());
taosWUnLockLatch
(
&
pOld
->
lock
);
}
}
if
(
pOld
->
numOfTags
<
pNew
->
numOfTags
)
{
void
*
pSchema
=
malloc
(
pOld
->
numOfTags
*
sizeof
(
SSchema
));
if
(
pSchema
!=
NULL
)
{
free
(
pOld
->
pTags
);
pOld
->
pTags
=
pSchema
;
}
else
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
mTrace
(
"stb:%s, failed to perform update action since %s"
,
pOld
->
name
,
terrstr
());
...
...
@@ -199,9 +227,11 @@ static int32_t mndStbActionUpdate(SSdb *pSdb, SStbObj *pOld, SStbObj *pNew) {
pOld
->
updateTime
=
pNew
->
updateTime
;
pOld
->
version
=
pNew
->
version
;
pOld
->
nextColId
=
pNew
->
nextColId
;
pOld
->
numOfColumns
=
pNew
->
numOfColumns
;
pOld
->
numOfTags
=
pNew
->
numOfTags
;
memcpy
(
pOld
->
pSchema
,
pNew
->
pSchema
,
totalSize
);
memcpy
(
pOld
->
pColumns
,
pNew
->
pColumns
,
pOld
->
numOfColumns
*
sizeof
(
SSchema
));
memcpy
(
pOld
->
pTags
,
pNew
->
pTags
,
pOld
->
numOfTags
*
sizeof
(
SSchema
));
taosWUnLockLatch
(
&
pOld
->
lock
);
return
0
;
}
...
...
@@ -242,9 +272,9 @@ static void *mndBuildCreateStbReq(SMnode *pMnode, SVgObj *pVgroup, SStbObj *pStb
req
.
type
=
TD_SUPER_TABLE
;
req
.
stbCfg
.
suid
=
pStb
->
uid
;
req
.
stbCfg
.
nCols
=
pStb
->
numOfColumns
;
req
.
stbCfg
.
pSchema
=
pStb
->
p
Schema
;
req
.
stbCfg
.
pSchema
=
pStb
->
p
Columns
;
req
.
stbCfg
.
nTagCols
=
pStb
->
numOfTags
;
req
.
stbCfg
.
pTagSchema
=
pStb
->
p
Schema
+
pStb
->
numOfColumn
s
;
req
.
stbCfg
.
pTagSchema
=
pStb
->
p
Tag
s
;
int32_t
contLen
=
tSerializeSVCreateTbReq
(
NULL
,
&
req
)
+
sizeof
(
SMsgHead
);
SMsgHead
*
pHead
=
malloc
(
contLen
);
...
...
@@ -442,20 +472,32 @@ static int32_t mndCreateStb(SMnode *pMnode, SMnodeMsg *pReq, SMCreateStbReq *pCr
stbObj
.
uid
=
mndGenerateUid
(
pCreate
->
name
,
TSDB_TABLE_FNAME_LEN
);
stbObj
.
dbUid
=
pDb
->
uid
;
stbObj
.
version
=
1
;
stbObj
.
nextColId
=
1
;
stbObj
.
numOfColumns
=
pCreate
->
numOfColumns
;
stbObj
.
numOfTags
=
pCreate
->
numOfTags
;
int32_t
totalCols
=
stbObj
.
numOfColumns
+
stbObj
.
numOfTags
;
int32_t
totalSize
=
totalCols
*
sizeof
(
SSchema
);
stbObj
.
pSchema
=
malloc
(
totalSize
);
if
(
stbObj
.
pSchema
==
NULL
)
{
stbObj
.
pColumns
=
malloc
(
stbObj
.
numOfColumns
*
sizeof
(
SSchema
));
if
(
stbObj
.
pColumns
==
NULL
)
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
return
-
1
;
}
memcpy
(
stbObj
.
p
Schema
,
pCreate
->
pSchema
,
totalSize
);
memcpy
(
stbObj
.
p
Columns
,
pCreate
->
pSchema
,
stbObj
.
numOfColumns
*
sizeof
(
SSchema
)
);
for
(
int32_t
i
=
0
;
i
<
totalCols
;
++
i
)
{
stbObj
.
pSchema
[
i
].
colId
=
i
+
1
;
stbObj
.
pTags
=
malloc
(
stbObj
.
numOfTags
*
sizeof
(
SSchema
));
if
(
stbObj
.
pTags
==
NULL
)
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
return
-
1
;
}
memcpy
(
stbObj
.
pTags
,
pCreate
->
pSchema
+
stbObj
.
numOfColumns
,
stbObj
.
numOfTags
*
sizeof
(
SSchema
));
for
(
int32_t
i
=
0
;
i
<
stbObj
.
numOfColumns
;
++
i
)
{
stbObj
.
pColumns
[
i
].
colId
=
stbObj
.
nextColId
;
stbObj
.
nextColId
++
;
}
for
(
int32_t
i
=
0
;
i
<
stbObj
.
numOfTags
;
++
i
)
{
stbObj
.
pTags
[
i
].
colId
=
stbObj
.
nextColId
;
stbObj
.
nextColId
++
;
}
int32_t
code
=
-
1
;
...
...
@@ -538,25 +580,29 @@ static int32_t mndProcessVCreateStbRsp(SMnodeMsg *pRsp) {
}
static
int32_t
mndCheckAlterStbReq
(
SMAlterStbReq
*
pAlter
)
{
SSchema
*
pSchema
=
&
pAlter
->
schema
;
pSchema
->
colId
=
htonl
(
pSchema
->
colId
);
pSchema
->
bytes
=
htonl
(
pSchema
->
bytes
);
pAlter
->
numOfColumns
=
htonl
(
pAlter
->
numOfColumns
);
if
(
pSchema
->
type
<=
0
)
{
terrno
=
TSDB_CODE_MND_INVALID_STB_OPTION
;
return
-
1
;
}
if
(
pSchema
->
colId
<
0
||
pSchema
->
colId
>=
(
TSDB_MAX_COLUMNS
+
TSDB_MAX_TAGS
))
{
terrno
=
TSDB_CODE_MND_INVALID_STB_OPTION
;
return
-
1
;
}
if
(
pSchema
->
bytes
<=
0
)
{
terrno
=
TSDB_CODE_MND_INVALID_STB_OPTION
;
return
-
1
;
}
if
(
pSchema
->
name
[
0
]
==
0
)
{
terrno
=
TSDB_CODE_MND_INVALID_STB_OPTION
;
return
-
1
;
for
(
int32_t
i
=
0
;
i
<
pAlter
->
numOfColumns
;
++
i
)
{
SSchema
*
pSchema
=
&
pAlter
->
pSchema
[
i
];
pSchema
->
colId
=
htonl
(
pSchema
->
colId
);
pSchema
->
bytes
=
htonl
(
pSchema
->
bytes
);
if
(
pSchema
->
type
<=
0
)
{
terrno
=
TSDB_CODE_MND_INVALID_STB_OPTION
;
return
-
1
;
}
if
(
pSchema
->
colId
<
0
||
pSchema
->
colId
>=
(
TSDB_MAX_COLUMNS
+
TSDB_MAX_TAGS
))
{
terrno
=
TSDB_CODE_MND_INVALID_STB_OPTION
;
return
-
1
;
}
if
(
pSchema
->
bytes
<=
0
)
{
terrno
=
TSDB_CODE_MND_INVALID_STB_OPTION
;
return
-
1
;
}
if
(
pSchema
->
name
[
0
]
==
0
)
{
terrno
=
TSDB_CODE_MND_INVALID_STB_OPTION
;
return
-
1
;
}
}
return
0
;
...
...
@@ -764,14 +810,24 @@ static int32_t mndProcessStbMetaReq(SMnodeMsg *pReq) {
pMeta
->
suid
=
htobe64
(
pStb
->
uid
);
pMeta
->
tuid
=
htobe64
(
pStb
->
uid
);
for
(
int32_t
i
=
0
;
i
<
totalCol
s
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
pStb
->
numOfColumn
s
;
++
i
)
{
SSchema
*
pSchema
=
&
pMeta
->
pSchema
[
i
];
SSchema
*
pSrcSchema
=
&
pStb
->
pSchema
[
i
];
SSchema
*
pSrcSchema
=
&
pStb
->
pColumns
[
i
];
memcpy
(
pSchema
->
name
,
pSrcSchema
->
name
,
TSDB_COL_NAME_LEN
);
pSchema
->
type
=
pSrcSchema
->
type
;
pSchema
->
colId
=
htonl
(
pSrcSchema
->
colId
);
pSchema
->
bytes
=
htonl
(
pSrcSchema
->
bytes
);
}
for
(
int32_t
i
=
0
;
i
<
pStb
->
numOfTags
;
++
i
)
{
SSchema
*
pSchema
=
&
pMeta
->
pSchema
[
i
+
pStb
->
numOfColumns
];
SSchema
*
pSrcSchema
=
&
pStb
->
pTags
[
i
];
memcpy
(
pSchema
->
name
,
pSrcSchema
->
name
,
TSDB_COL_NAME_LEN
);
pSchema
->
type
=
pSrcSchema
->
type
;
pSchema
->
colId
=
htonl
(
pSrcSchema
->
colId
);
pSchema
->
bytes
=
htonl
(
pSrcSchema
->
bytes
);
}
taosRUnLockLatch
(
&
pStb
->
lock
);
mndReleaseDb
(
pMnode
,
pDb
);
mndReleaseStb
(
pMnode
,
pStb
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录