Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
2ea3a427
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看板
提交
2ea3a427
编写于
3月 24, 2022
作者:
S
Shengliang Guan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
sma
上级
8323cad2
变更
5
显示空白变更内容
内联
并排
Showing
5 changed file
with
201 addition
and
63 deletion
+201
-63
include/common/tmsg.h
include/common/tmsg.h
+5
-2
source/common/src/tmsg.c
source/common/src/tmsg.c
+30
-3
source/dnode/mnode/impl/inc/mndDef.h
source/dnode/mnode/impl/inc/mndDef.h
+3
-0
source/dnode/mnode/impl/src/mndStb.c
source/dnode/mnode/impl/src/mndStb.c
+69
-22
source/dnode/mnode/impl/test/sma/sma.cpp
source/dnode/mnode/impl/test/sma/sma.cpp
+94
-36
未找到文件。
include/common/tmsg.h
浏览文件 @
2ea3a427
...
...
@@ -272,11 +272,14 @@ typedef struct {
float
xFilesFactor
;
int32_t
aggregationMethod
;
int32_t
delay
;
int32_t
ttl
;
int32_t
numOfColumns
;
int32_t
numOfTags
;
int32_t
numOfSmas
;
int32_t
commentLen
;
SArray
*
pColumns
;
SArray
*
pTags
;
SArray
*
pColumns
;
// array of SField
SArray
*
pTags
;
// array of SField
SArray
*
pSmas
;
// array of SField
char
*
comment
;
}
SMCreateStbReq
;
...
...
source/common/src/tmsg.c
浏览文件 @
2ea3a427
...
...
@@ -511,8 +511,10 @@ int32_t tSerializeSMCreateStbReq(void *buf, int32_t bufLen, SMCreateStbReq *pReq
if
(
tEncodeFloat
(
&
encoder
,
pReq
->
xFilesFactor
)
<
0
)
return
-
1
;
if
(
tEncodeI32
(
&
encoder
,
pReq
->
aggregationMethod
)
<
0
)
return
-
1
;
if
(
tEncodeI32
(
&
encoder
,
pReq
->
delay
)
<
0
)
return
-
1
;
if
(
tEncodeI32
(
&
encoder
,
pReq
->
ttl
)
<
0
)
return
-
1
;
if
(
tEncodeI32
(
&
encoder
,
pReq
->
numOfColumns
)
<
0
)
return
-
1
;
if
(
tEncodeI32
(
&
encoder
,
pReq
->
numOfTags
)
<
0
)
return
-
1
;
if
(
tEncodeI32
(
&
encoder
,
pReq
->
numOfSmas
)
<
0
)
return
-
1
;
if
(
tEncodeI32
(
&
encoder
,
pReq
->
commentLen
)
<
0
)
return
-
1
;
for
(
int32_t
i
=
0
;
i
<
pReq
->
numOfColumns
;
++
i
)
{
...
...
@@ -529,7 +531,16 @@ int32_t tSerializeSMCreateStbReq(void *buf, int32_t bufLen, SMCreateStbReq *pReq
if
(
tEncodeCStr
(
&
encoder
,
pField
->
name
)
<
0
)
return
-
1
;
}
for
(
int32_t
i
=
0
;
i
<
pReq
->
numOfSmas
;
++
i
)
{
SField
*
pField
=
taosArrayGet
(
pReq
->
pSmas
,
i
);
if
(
tEncodeI8
(
&
encoder
,
pField
->
type
)
<
0
)
return
-
1
;
if
(
tEncodeI32
(
&
encoder
,
pField
->
bytes
)
<
0
)
return
-
1
;
if
(
tEncodeCStr
(
&
encoder
,
pField
->
name
)
<
0
)
return
-
1
;
}
if
(
pReq
->
commentLen
>
0
)
{
if
(
tEncodeBinary
(
&
encoder
,
pReq
->
comment
,
pReq
->
commentLen
)
<
0
)
return
-
1
;
}
tEndEncode
(
&
encoder
);
int32_t
tlen
=
encoder
.
pos
;
...
...
@@ -547,13 +558,16 @@ int32_t tDeserializeSMCreateStbReq(void *buf, int32_t bufLen, SMCreateStbReq *pR
if
(
tDecodeFloat
(
&
decoder
,
&
pReq
->
xFilesFactor
)
<
0
)
return
-
1
;
if
(
tDecodeI32
(
&
decoder
,
&
pReq
->
aggregationMethod
)
<
0
)
return
-
1
;
if
(
tDecodeI32
(
&
decoder
,
&
pReq
->
delay
)
<
0
)
return
-
1
;
if
(
tDecodeI32
(
&
decoder
,
&
pReq
->
ttl
)
<
0
)
return
-
1
;
if
(
tDecodeI32
(
&
decoder
,
&
pReq
->
numOfColumns
)
<
0
)
return
-
1
;
if
(
tDecodeI32
(
&
decoder
,
&
pReq
->
numOfTags
)
<
0
)
return
-
1
;
if
(
tDecodeI32
(
&
decoder
,
&
pReq
->
numOfSmas
)
<
0
)
return
-
1
;
if
(
tDecodeI32
(
&
decoder
,
&
pReq
->
commentLen
)
<
0
)
return
-
1
;
pReq
->
pColumns
=
taosArrayInit
(
pReq
->
numOfColumns
,
sizeof
(
SField
));
pReq
->
pTags
=
taosArrayInit
(
pReq
->
numOfTags
,
sizeof
(
SField
));
if
(
pReq
->
pColumns
==
NULL
||
pReq
->
pTags
==
NULL
)
{
pReq
->
pSmas
=
taosArrayInit
(
pReq
->
numOfSmas
,
sizeof
(
SField
));
if
(
pReq
->
pColumns
==
NULL
||
pReq
->
pTags
==
NULL
||
pReq
->
pSmas
==
NULL
)
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
return
-
1
;
}
...
...
@@ -580,13 +594,23 @@ int32_t tDeserializeSMCreateStbReq(void *buf, int32_t bufLen, SMCreateStbReq *pR
}
}
for
(
int32_t
i
=
0
;
i
<
pReq
->
numOfSmas
;
++
i
)
{
SField
field
=
{
0
};
if
(
tDecodeI8
(
&
decoder
,
&
field
.
type
)
<
0
)
return
-
1
;
if
(
tDecodeI32
(
&
decoder
,
&
field
.
bytes
)
<
0
)
return
-
1
;
if
(
tDecodeCStrTo
(
&
decoder
,
field
.
name
)
<
0
)
return
-
1
;
if
(
taosArrayPush
(
pReq
->
pSmas
,
&
field
)
==
NULL
)
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
return
-
1
;
}
}
if
(
pReq
->
commentLen
>
0
)
{
pReq
->
comment
=
malloc
(
pReq
->
commentLen
);
if
(
pReq
->
comment
==
NULL
)
return
-
1
;
if
(
tDecodeCStrTo
(
&
decoder
,
pReq
->
comment
)
<
0
)
return
-
1
;
}
if
(
tDecodeCStrTo
(
&
decoder
,
pReq
->
comment
)
<
0
)
return
-
1
;
tEndDecode
(
&
decoder
);
tCoderClear
(
&
decoder
);
...
...
@@ -596,8 +620,11 @@ int32_t tDeserializeSMCreateStbReq(void *buf, int32_t bufLen, SMCreateStbReq *pR
void
tFreeSMCreateStbReq
(
SMCreateStbReq
*
pReq
)
{
taosArrayDestroy
(
pReq
->
pColumns
);
taosArrayDestroy
(
pReq
->
pTags
);
taosArrayDestroy
(
pReq
->
pSmas
);
tfree
(
pReq
->
comment
);
pReq
->
pColumns
=
NULL
;
pReq
->
pTags
=
NULL
;
pReq
->
pSmas
=
NULL
;
}
int32_t
tSerializeSMDropStbReq
(
void
*
buf
,
int32_t
bufLen
,
SMDropStbReq
*
pReq
)
{
...
...
source/dnode/mnode/impl/inc/mndDef.h
浏览文件 @
2ea3a427
...
...
@@ -344,11 +344,14 @@ typedef struct {
float
xFilesFactor
;
int32_t
aggregationMethod
;
int32_t
delay
;
int32_t
ttl
;
int32_t
numOfColumns
;
int32_t
numOfTags
;
int32_t
numOfSmas
;
int32_t
commentLen
;
SSchema
*
pColumns
;
SSchema
*
pTags
;
SSchema
*
pSmas
;
char
*
comment
;
SRWLatch
lock
;
}
SStbObj
;
...
...
source/dnode/mnode/impl/src/mndStb.c
浏览文件 @
2ea3a427
...
...
@@ -72,7 +72,8 @@ void mndCleanupStb(SMnode *pMnode) {}
SSdbRaw
*
mndStbActionEncode
(
SStbObj
*
pStb
)
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
int32_t
size
=
sizeof
(
SStbObj
)
+
(
pStb
->
numOfColumns
+
pStb
->
numOfTags
)
*
sizeof
(
SSchema
)
+
TSDB_STB_RESERVE_SIZE
;
int32_t
size
=
sizeof
(
SStbObj
)
+
(
pStb
->
numOfColumns
+
pStb
->
numOfTags
+
pStb
->
numOfSmas
)
*
sizeof
(
SSchema
)
+
TSDB_STB_RESERVE_SIZE
;
SSdbRaw
*
pRaw
=
sdbAllocRaw
(
SDB_STB
,
TSDB_STB_VER_NUMBER
,
size
);
if
(
pRaw
==
NULL
)
goto
STB_ENCODE_OVER
;
...
...
@@ -88,8 +89,10 @@ SSdbRaw *mndStbActionEncode(SStbObj *pStb) {
SDB_SET_INT32
(
pRaw
,
dataPos
,
(
int32_t
)(
pStb
->
xFilesFactor
*
10000
),
STB_ENCODE_OVER
)
SDB_SET_INT32
(
pRaw
,
dataPos
,
pStb
->
aggregationMethod
,
STB_ENCODE_OVER
)
SDB_SET_INT32
(
pRaw
,
dataPos
,
pStb
->
delay
,
STB_ENCODE_OVER
)
SDB_SET_INT32
(
pRaw
,
dataPos
,
pStb
->
ttl
,
STB_ENCODE_OVER
)
SDB_SET_INT32
(
pRaw
,
dataPos
,
pStb
->
numOfColumns
,
STB_ENCODE_OVER
)
SDB_SET_INT32
(
pRaw
,
dataPos
,
pStb
->
numOfTags
,
STB_ENCODE_OVER
)
SDB_SET_INT32
(
pRaw
,
dataPos
,
pStb
->
numOfSmas
,
STB_ENCODE_OVER
)
SDB_SET_INT32
(
pRaw
,
dataPos
,
pStb
->
commentLen
,
STB_ENCODE_OVER
)
for
(
int32_t
i
=
0
;
i
<
pStb
->
numOfColumns
;
++
i
)
{
...
...
@@ -108,7 +111,17 @@ SSdbRaw *mndStbActionEncode(SStbObj *pStb) {
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
->
pSmas
[
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
)
}
if
(
pStb
->
commentLen
>
0
)
{
SDB_SET_BINARY
(
pRaw
,
dataPos
,
pStb
->
comment
,
pStb
->
commentLen
,
STB_ENCODE_OVER
)
}
SDB_SET_RESERVE
(
pRaw
,
dataPos
,
TSDB_STB_RESERVE_SIZE
,
STB_ENCODE_OVER
)
SDB_SET_DATALEN
(
pRaw
,
dataPos
,
STB_ENCODE_OVER
)
...
...
@@ -156,13 +169,16 @@ static SSdbRow *mndStbActionDecode(SSdbRaw *pRaw) {
pStb
->
xFilesFactor
=
xFilesFactor
/
10000
.
0
f
;
SDB_GET_INT32
(
pRaw
,
dataPos
,
&
pStb
->
aggregationMethod
,
STB_DECODE_OVER
)
SDB_GET_INT32
(
pRaw
,
dataPos
,
&
pStb
->
delay
,
STB_DECODE_OVER
)
SDB_GET_INT32
(
pRaw
,
dataPos
,
&
pStb
->
ttl
,
STB_DECODE_OVER
)
SDB_GET_INT32
(
pRaw
,
dataPos
,
&
pStb
->
numOfColumns
,
STB_DECODE_OVER
)
SDB_GET_INT32
(
pRaw
,
dataPos
,
&
pStb
->
numOfTags
,
STB_DECODE_OVER
)
SDB_GET_INT32
(
pRaw
,
dataPos
,
&
pStb
->
numOfSmas
,
STB_DECODE_OVER
)
SDB_GET_INT32
(
pRaw
,
dataPos
,
&
pStb
->
commentLen
,
STB_DECODE_OVER
)
pStb
->
pColumns
=
calloc
(
pStb
->
numOfColumns
,
sizeof
(
SSchema
));
pStb
->
pTags
=
calloc
(
pStb
->
numOfTags
,
sizeof
(
SSchema
));
if
(
pStb
->
pColumns
==
NULL
||
pStb
->
pTags
==
NULL
)
{
pStb
->
pSmas
=
calloc
(
pStb
->
numOfSmas
,
sizeof
(
SSchema
));
if
(
pStb
->
pColumns
==
NULL
||
pStb
->
pTags
==
NULL
||
pStb
->
pSmas
==
NULL
)
{
goto
STB_DECODE_OVER
;
}
...
...
@@ -182,6 +198,14 @@ static SSdbRow *mndStbActionDecode(SSdbRaw *pRaw) {
SDB_GET_BINARY
(
pRaw
,
dataPos
,
pSchema
->
name
,
TSDB_COL_NAME_LEN
,
STB_DECODE_OVER
)
}
for
(
int32_t
i
=
0
;
i
<
pStb
->
numOfSmas
;
++
i
)
{
SSchema
*
pSchema
=
&
pStb
->
pSmas
[
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
)
}
if
(
pStb
->
commentLen
>
0
)
{
pStb
->
comment
=
calloc
(
pStb
->
commentLen
,
1
);
if
(
pStb
->
comment
==
NULL
)
goto
STB_DECODE_OVER
;
...
...
@@ -505,6 +529,16 @@ static int32_t mndSetCreateStbUndoActions(SMnode *pMnode, STrans *pTrans, SDbObj
return
0
;
}
static
SSchema
*
mndFindStbColumns
(
const
SStbObj
*
pStb
,
const
char
*
colName
)
{
for
(
int32_t
col
=
0
;
col
<
pStb
->
numOfColumns
;
col
++
)
{
SSchema
*
pSchema
=
&
pStb
->
pColumns
[
col
];
if
(
strcasecmp
(
pStb
->
pColumns
[
col
].
name
,
colName
)
==
0
)
{
return
pSchema
;
}
}
return
NULL
;
}
static
int32_t
mndCreateStb
(
SMnode
*
pMnode
,
SNodeMsg
*
pReq
,
SMCreateStbReq
*
pCreate
,
SDbObj
*
pDb
)
{
SStbObj
stbObj
=
{
0
};
memcpy
(
stbObj
.
name
,
pCreate
->
name
,
TSDB_TABLE_FNAME_LEN
);
...
...
@@ -515,19 +549,24 @@ static int32_t mndCreateStb(SMnode *pMnode, SNodeMsg *pReq, SMCreateStbReq *pCre
stbObj
.
dbUid
=
pDb
->
uid
;
stbObj
.
version
=
1
;
stbObj
.
nextColId
=
1
;
stbObj
.
ttl
=
pCreate
->
ttl
;
stbObj
.
numOfColumns
=
pCreate
->
numOfColumns
;
stbObj
.
numOfTags
=
pCreate
->
numOfTags
;
stbObj
.
numOfSmas
=
pCreate
->
numOfSmas
;
stbObj
.
commentLen
=
pCreate
->
commentLen
;
if
(
stbObj
.
commentLen
>
0
)
{
stbObj
.
comment
=
calloc
(
stbObj
.
commentLen
,
1
);
if
(
stbObj
.
comment
==
NULL
)
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
return
-
1
;
}
memcpy
(
stbObj
.
comment
,
pCreate
->
comment
,
stbObj
.
commentLen
);
}
stbObj
.
pColumns
=
malloc
(
stbObj
.
numOfColumns
*
sizeof
(
SSchema
));
stbObj
.
pTags
=
malloc
(
stbObj
.
numOfTags
*
sizeof
(
SSchema
));
if
(
stbObj
.
pColumns
==
NULL
||
stbObj
.
pTags
==
NULL
)
{
stbObj
.
pSmas
=
malloc
(
stbObj
.
numOfSmas
*
sizeof
(
SSchema
));
if
(
stbObj
.
pColumns
==
NULL
||
stbObj
.
pTags
==
NULL
||
stbObj
.
pSmas
==
NULL
)
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
return
-
1
;
}
...
...
@@ -552,6 +591,18 @@ static int32_t mndCreateStb(SMnode *pMnode, SNodeMsg *pReq, SMCreateStbReq *pCre
stbObj
.
nextColId
++
;
}
for
(
int32_t
i
=
0
;
i
<
stbObj
.
numOfSmas
;
++
i
)
{
SField
*
pField
=
taosArrayGet
(
pCreate
->
pSmas
,
i
);
SSchema
*
pSchema
=
&
stbObj
.
pSmas
[
i
];
SSchema
*
pColSchema
=
mndFindStbColumns
(
&
stbObj
,
pField
->
name
);
if
(
pColSchema
==
NULL
)
{
mError
(
"stb:%s, sma:%s not found in columns"
,
stbObj
.
name
,
pSchema
->
name
);
terrno
=
TSDB_CODE_MND_INVALID_STB_OPTION
;
return
-
1
;
}
memcpy
(
pSchema
,
pColSchema
,
sizeof
(
SSchema
));
}
int32_t
code
=
-
1
;
STrans
*
pTrans
=
mndTransCreate
(
pMnode
,
TRN_POLICY_ROLLBACK
,
TRN_TYPE_CREATE_STB
,
&
pReq
->
rpcMsg
);
if
(
pTrans
==
NULL
)
goto
CREATE_STB_OVER
;
...
...
@@ -1544,11 +1595,7 @@ static int32_t mndRetrieveStb(SNodeMsg *pReq, SShowObj *pShow, char *data, int32
pShow
->
pIter
=
sdbFetch
(
pSdb
,
SDB_STB
,
pShow
->
pIter
,
(
void
**
)
&
pStb
);
if
(
pShow
->
pIter
==
NULL
)
break
;
if
(
pDb
!=
NULL
&&
pStb
->
dbUid
!=
pDb
->
uid
)
{
if
(
strncmp
(
pStb
->
db
,
pDb
->
name
,
prefixLen
)
==
0
)
{
mError
(
"Inconsistent table data, name:%s, db:%s, dbUid:%"
PRIu64
,
pStb
->
name
,
pDb
->
name
,
pDb
->
uid
);
}
if
(
pStb
->
dbUid
!=
pDb
->
uid
)
{
sdbRelease
(
pSdb
,
pStb
);
continue
;
}
...
...
@@ -1562,12 +1609,12 @@ static int32_t mndRetrieveStb(SNodeMsg *pReq, SShowObj *pShow, char *data, int32
STR_TO_VARSTR
(
pWrite
,
stbName
);
cols
++
;
char
db
[
TSDB_DB_NAME_LEN
]
=
{
0
};
tNameFromString
(
&
name
,
pStb
->
db
,
T_NAME_ACCT
|
T_NAME_DB
);
tNameGetDbName
(
&
name
,
db
);
pWrite
=
data
+
pShow
->
offset
[
cols
]
*
rows
+
pShow
->
bytes
[
cols
]
*
numOfRows
;
STR_TO_VARSTR
(
pWrite
,
db
);
cols
++
;
//
char db[TSDB_DB_NAME_LEN] = {0};
//
tNameFromString(&name, pStb->db, T_NAME_ACCT|T_NAME_DB);
//
tNameGetDbName(&name, db);
//
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
//
STR_TO_VARSTR(pWrite, db);
//
cols++;
pWrite
=
data
+
pShow
->
offset
[
cols
]
*
rows
+
pShow
->
bytes
[
cols
]
*
numOfRows
;
*
(
int64_t
*
)
pWrite
=
pStb
->
createdTime
;
...
...
@@ -1580,7 +1627,7 @@ static int32_t mndRetrieveStb(SNodeMsg *pReq, SShowObj *pShow, char *data, int32
pWrite
=
data
+
pShow
->
offset
[
cols
]
*
rows
+
pShow
->
bytes
[
cols
]
*
numOfRows
;
*
(
int32_t
*
)
pWrite
=
pStb
->
numOfTags
;
cols
++
;
#if 0
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
*(int32_t *)pWrite = 0; // number of tables
cols++;
...
...
@@ -1596,7 +1643,7 @@ static int32_t mndRetrieveStb(SNodeMsg *pReq, SShowObj *pShow, char *data, int32
STR_TO_VARSTR(pWrite, "");
}
cols++;
#endif
numOfRows
++
;
sdbRelease
(
pSdb
,
pStb
);
}
...
...
source/dnode/mnode/impl/test/sma/sma.cpp
浏览文件 @
2ea3a427
...
...
@@ -26,9 +26,12 @@ class MndTestSma : public ::testing::Test {
void
*
BuildDropDbReq
(
const
char
*
dbname
,
int32_t
*
pContLen
);
void
*
BuildCreateStbReq
(
const
char
*
stbname
,
int32_t
*
pContLen
);
void
*
BuildDropStbReq
(
const
char
*
stbname
,
int32_t
*
pContLen
);
void
*
BuildCreateSmaReq
(
const
char
*
smaname
,
const
char
*
stbname
,
int8_t
igExists
,
const
char
*
expr
,
void
*
BuildCreateBSmaStbReq
(
const
char
*
stbname
,
int32_t
*
pContLen
);
void
*
BuildCreateTSmaReq
(
const
char
*
smaname
,
const
char
*
stbname
,
int8_t
igExists
,
const
char
*
expr
,
const
char
*
tagsFilter
,
const
char
*
sql
,
const
char
*
ast
,
int32_t
*
pContLen
);
void
*
BuildDropSmaReq
(
const
char
*
smaname
,
int8_t
igNotExists
,
int32_t
*
pContLen
);
void
*
BuildDropTSmaReq
(
const
char
*
smaname
,
int8_t
igNotExists
,
int32_t
*
pContLen
);
void
PushField
(
SArray
*
pArray
,
int32_t
bytes
,
int8_t
type
,
const
char
*
name
);
};
Testbase
MndTestSma
::
test
;
...
...
@@ -76,6 +79,14 @@ void* MndTestSma::BuildDropDbReq(const char* dbname, int32_t* pContLen) {
return
pReq
;
}
void
MndTestSma
::
PushField
(
SArray
*
pArray
,
int32_t
bytes
,
int8_t
type
,
const
char
*
name
)
{
SField
field
=
{
0
};
field
.
bytes
=
bytes
;
field
.
type
=
type
;
strcpy
(
field
.
name
,
name
);
taosArrayPush
(
pArray
,
&
field
);
}
void
*
MndTestSma
::
BuildCreateStbReq
(
const
char
*
stbname
,
int32_t
*
pContLen
)
{
SMCreateStbReq
createReq
=
{
0
};
createReq
.
numOfColumns
=
3
;
...
...
@@ -85,37 +96,35 @@ void* MndTestSma::BuildCreateStbReq(const char* stbname, int32_t* pContLen) {
createReq
.
pTags
=
taosArrayInit
(
createReq
.
numOfTags
,
sizeof
(
SField
));
strcpy
(
createReq
.
name
,
stbname
);
{
SField
field
=
{
0
};
field
.
bytes
=
8
;
field
.
type
=
TSDB_DATA_TYPE_TIMESTAMP
;
strcpy
(
field
.
name
,
"ts"
);
taosArrayPush
(
createReq
.
pColumns
,
&
field
);
}
PushField
(
createReq
.
pColumns
,
8
,
TSDB_DATA_TYPE_TIMESTAMP
,
"ts"
);
PushField
(
createReq
.
pColumns
,
2
,
TSDB_DATA_TYPE_TINYINT
,
"col1"
);
PushField
(
createReq
.
pColumns
,
8
,
TSDB_DATA_TYPE_BIGINT
,
"col2"
);
PushField
(
createReq
.
pTags
,
2
,
TSDB_DATA_TYPE_TINYINT
,
"tag1"
);
{
SField
field
=
{
0
}
;
field
.
bytes
=
2
;
field
.
type
=
TSDB_DATA_TYPE_TINYINT
;
strcpy
(
field
.
name
,
"col1"
)
;
taosArrayPush
(
createReq
.
pColumns
,
&
field
)
;
}
int32_t
tlen
=
tSerializeSMCreateStbReq
(
NULL
,
0
,
&
createReq
);
void
*
pHead
=
rpcMallocCont
(
tlen
)
;
tSerializeSMCreateStbReq
(
pHead
,
tlen
,
&
createReq
)
;
tFreeSMCreateStbReq
(
&
createReq
)
;
*
pContLen
=
tlen
;
return
pHead
;
}
{
SField
field
=
{
0
};
field
.
bytes
=
8
;
field
.
type
=
TSDB_DATA_TYPE_BIGINT
;
strcpy
(
field
.
name
,
"col2"
);
taosArrayPush
(
createReq
.
pColumns
,
&
field
);
}
void
*
MndTestSma
::
BuildCreateBSmaStbReq
(
const
char
*
stbname
,
int32_t
*
pContLen
)
{
SMCreateStbReq
createReq
=
{
0
};
createReq
.
numOfColumns
=
3
;
createReq
.
numOfTags
=
1
;
createReq
.
numOfSmas
=
1
;
createReq
.
igExists
=
0
;
createReq
.
pColumns
=
taosArrayInit
(
createReq
.
numOfColumns
,
sizeof
(
SField
));
createReq
.
pTags
=
taosArrayInit
(
createReq
.
numOfTags
,
sizeof
(
SField
));
createReq
.
pSmas
=
taosArrayInit
(
createReq
.
numOfSmas
,
sizeof
(
SField
));
strcpy
(
createReq
.
name
,
stbname
);
{
SField
field
=
{
0
};
field
.
bytes
=
2
;
field
.
type
=
TSDB_DATA_TYPE_TINYINT
;
strcpy
(
field
.
name
,
"tag1"
);
taosArrayPush
(
createReq
.
pTags
,
&
field
);
}
PushField
(
createReq
.
pColumns
,
8
,
TSDB_DATA_TYPE_TIMESTAMP
,
"ts"
);
PushField
(
createReq
.
pColumns
,
2
,
TSDB_DATA_TYPE_TINYINT
,
"col1"
);
PushField
(
createReq
.
pColumns
,
8
,
TSDB_DATA_TYPE_BIGINT
,
"col2"
);
PushField
(
createReq
.
pTags
,
2
,
TSDB_DATA_TYPE_TINYINT
,
"tag1"
);
PushField
(
createReq
.
pSmas
,
2
,
TSDB_DATA_TYPE_TINYINT
,
"col1"
);
int32_t
tlen
=
tSerializeSMCreateStbReq
(
NULL
,
0
,
&
createReq
);
void
*
pHead
=
rpcMallocCont
(
tlen
);
...
...
@@ -137,7 +146,7 @@ void* MndTestSma::BuildDropStbReq(const char* stbname, int32_t* pContLen) {
return
pReq
;
}
void
*
MndTestSma
::
BuildCreateSmaReq
(
const
char
*
smaname
,
const
char
*
stbname
,
int8_t
igExists
,
const
char
*
expr
,
void
*
MndTestSma
::
BuildCreate
T
SmaReq
(
const
char
*
smaname
,
const
char
*
stbname
,
int8_t
igExists
,
const
char
*
expr
,
const
char
*
tagsFilter
,
const
char
*
sql
,
const
char
*
ast
,
int32_t
*
pContLen
)
{
SMCreateSmaReq
createReq
=
{
0
};
strcpy
(
createReq
.
name
,
smaname
);
...
...
@@ -166,7 +175,7 @@ void* MndTestSma::BuildCreateSmaReq(const char* smaname, const char* stbname, in
return
pHead
;
}
void
*
MndTestSma
::
BuildDropSmaReq
(
const
char
*
smaname
,
int8_t
igNotExists
,
int32_t
*
pContLen
)
{
void
*
MndTestSma
::
BuildDrop
T
SmaReq
(
const
char
*
smaname
,
int8_t
igNotExists
,
int32_t
*
pContLen
)
{
SMDropSmaReq
dropsmaReq
=
{
0
};
dropsmaReq
.
igNotExists
=
igNotExists
;
strcpy
(
dropsmaReq
.
name
,
smaname
);
...
...
@@ -179,6 +188,7 @@ void* MndTestSma::BuildDropSmaReq(const char* smaname, int8_t igNotExists, int32
return
pReq
;
}
#if 0
TEST_F(MndTestSma, 01_Create_Show_Meta_Drop_Restart_Stb) {
const char* dbname = "1.d1";
const char* stbname = "1.d1.stb";
...
...
@@ -203,7 +213,7 @@ TEST_F(MndTestSma, 01_Create_Show_Meta_Drop_Restart_Stb) {
}
#if 0
{
pReq = BuildCreateSmaReq(smaname, stbname, 0, "expr", "tagsFilter", "sql", "ast", &contLen);
pReq = BuildCreate
T
SmaReq(smaname, stbname, 0, "expr", "tagsFilter", "sql", "ast", &contLen);
pRsp = test.SendReq(TDMT_MND_CREATE_SMA, pReq, contLen);
ASSERT_EQ(pRsp->code, 0);
test.SendShowMetaReq(TSDB_MGMT_TABLE_INDEX, dbname);
...
...
@@ -226,7 +236,7 @@ TEST_F(MndTestSma, 01_Create_Show_Meta_Drop_Restart_Stb) {
}
{
pReq = BuildDropSmaReq(smaname, 0, &contLen);
pReq = BuildDrop
T
SmaReq(smaname, 0, &contLen);
pRsp = test.SendReq(TDMT_MND_DROP_SMA, pReq, contLen);
ASSERT_EQ(pRsp->code, 0);
test.SendShowMetaReq(TSDB_MGMT_TABLE_INDEX, dbname);
...
...
@@ -235,3 +245,51 @@ TEST_F(MndTestSma, 01_Create_Show_Meta_Drop_Restart_Stb) {
}
#endif
}
#endif
TEST_F
(
MndTestSma
,
02
_Create_Show_Meta_Drop_Restart_BSma
)
{
const
char
*
dbname
=
"1.d1"
;
const
char
*
stbname
=
"1.d1.bsmastb"
;
int32_t
contLen
=
0
;
void
*
pReq
;
SRpcMsg
*
pRsp
;
{
pReq
=
BuildCreateDbReq
(
dbname
,
&
contLen
);
pRsp
=
test
.
SendReq
(
TDMT_MND_CREATE_DB
,
pReq
,
contLen
);
ASSERT_EQ
(
pRsp
->
code
,
0
);
}
{
pReq
=
BuildCreateBSmaStbReq
(
stbname
,
&
contLen
);
pRsp
=
test
.
SendReq
(
TDMT_MND_CREATE_STB
,
pReq
,
contLen
);
ASSERT_EQ
(
pRsp
->
code
,
0
);
test
.
SendShowMetaReq
(
TSDB_MGMT_TABLE_STB
,
dbname
);
test
.
SendShowRetrieveReq
();
EXPECT_EQ
(
test
.
GetShowRows
(),
1
);
CheckBinary
(
"bsmastb"
,
TSDB_TABLE_NAME_LEN
);
}
test
.
Restart
();
{
pReq
=
BuildCreateBSmaStbReq
(
stbname
,
&
contLen
);
pRsp
=
test
.
SendReq
(
TDMT_MND_CREATE_STB
,
pReq
,
contLen
);
ASSERT_EQ
(
pRsp
->
code
,
TSDB_CODE_MND_STB_ALREADY_EXIST
);
}
{
pReq
=
BuildDropStbReq
(
stbname
,
&
contLen
);
pRsp
=
test
.
SendReq
(
TDMT_MND_DROP_STB
,
pReq
,
contLen
);
ASSERT_EQ
(
pRsp
->
code
,
0
);
test
.
SendShowMetaReq
(
TSDB_MGMT_TABLE_STB
,
dbname
);
test
.
SendShowRetrieveReq
();
EXPECT_EQ
(
test
.
GetShowRows
(),
0
);
}
{
pReq
=
BuildDropStbReq
(
stbname
,
&
contLen
);
pRsp
=
test
.
SendReq
(
TDMT_MND_DROP_STB
,
pReq
,
contLen
);
ASSERT_EQ
(
pRsp
->
code
,
TSDB_CODE_MND_STB_NOT_EXIST
);
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录