Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
慢慢CG
TDengine
提交
5757003f
T
TDengine
项目概览
慢慢CG
/
TDengine
与 Fork 源项目一致
Fork自
taosdata / TDengine
通知
1
Star
0
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看板
提交
5757003f
编写于
1月 15, 2021
作者:
H
Haojun Liao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[TD-225]refactor codes.
上级
52648e93
变更
12
隐藏空白更改
内联
并排
Showing
12 changed file
with
223 addition
and
242 deletion
+223
-242
src/client/inc/tschemautil.h
src/client/inc/tschemautil.h
+0
-24
src/client/src/tscSchemaUtil.c
src/client/src/tscSchemaUtil.c
+0
-62
src/client/src/tscServer.c
src/client/src/tscServer.c
+12
-10
src/common/inc/tname.h
src/common/inc/tname.h
+14
-0
src/common/src/tname.c
src/common/src/tname.c
+66
-0
src/dnode/src/dnodeShell.c
src/dnode/src/dnodeShell.c
+1
-1
src/inc/taosmsg.h
src/inc/taosmsg.h
+10
-10
src/mnode/src/mnodeCluster.c
src/mnode/src/mnodeCluster.c
+1
-1
src/mnode/src/mnodeTable.c
src/mnode/src/mnodeTable.c
+113
-128
src/mnode/src/mnodeUser.c
src/mnode/src/mnodeUser.c
+1
-1
src/tsdb/src/tsdbMeta.c
src/tsdb/src/tsdbMeta.c
+2
-2
src/vnode/src/vnodeWrite.c
src/vnode/src/vnodeWrite.c
+3
-3
未找到文件。
src/client/inc/tschemautil.h
浏览文件 @
5757003f
...
...
@@ -24,10 +24,6 @@ extern "C" {
#include "tstoken.h"
#include "tsclient.h"
#define VALIDNUMOFCOLS(x) ((x) >= TSDB_MIN_COLUMNS && (x) <= TSDB_MAX_COLUMNS)
#define VALIDNUMOFTAGS(x) ((x) >= 0 && (x) <= TSDB_MAX_TAGS)
/**
* get the number of tags of this table
* @param pTableMeta
...
...
@@ -79,26 +75,6 @@ SSchema *tscGetTableColumnSchema(const STableMeta *pMeta, int32_t colIndex);
*/
SSchema
*
tscGetColumnSchemaById
(
STableMeta
*
pTableMeta
,
int16_t
colId
);
/**
* check if the schema is valid or not, including following aspects:
* 1. number of columns
* 2. column types
* 3. column length
* 4. column names
* 5. total length
*
* @param pSchema
* @param numOfCols
* @return
*/
bool
isValidSchema
(
struct
SSchema
*
pSchema
,
int32_t
numOfCols
,
int32_t
numOfTags
);
/**
* get the schema for the "tbname" column. it is a built column
* @return
*/
SSchema
tscGetTbnameColumnSchema
();
/**
* create the table meta from the msg
* @param pTableMetaMsg
...
...
src/client/src/tscSchemaUtil.c
浏览文件 @
5757003f
...
...
@@ -66,68 +66,6 @@ STableComInfo tscGetTableInfo(const STableMeta* pTableMeta) {
return
pTableMeta
->
tableInfo
;
}
static
bool
doValidateSchema
(
SSchema
*
pSchema
,
int32_t
numOfCols
,
int32_t
maxLen
)
{
int32_t
rowLen
=
0
;
for
(
int32_t
i
=
0
;
i
<
numOfCols
;
++
i
)
{
// 1. valid types
if
(
!
isValidDataType
(
pSchema
[
i
].
type
))
{
return
false
;
}
// 2. valid length for each type
if
(
pSchema
[
i
].
type
==
TSDB_DATA_TYPE_BINARY
)
{
if
(
pSchema
[
i
].
bytes
>
TSDB_MAX_BINARY_LEN
)
{
return
false
;
}
}
else
if
(
pSchema
[
i
].
type
==
TSDB_DATA_TYPE_NCHAR
)
{
if
(
pSchema
[
i
].
bytes
>
TSDB_MAX_NCHAR_LEN
)
{
return
false
;
}
}
else
{
if
(
pSchema
[
i
].
bytes
!=
tDataTypes
[
pSchema
[
i
].
type
].
bytes
)
{
return
false
;
}
}
// 3. valid column names
for
(
int32_t
j
=
i
+
1
;
j
<
numOfCols
;
++
j
)
{
if
(
strncasecmp
(
pSchema
[
i
].
name
,
pSchema
[
j
].
name
,
sizeof
(
pSchema
[
i
].
name
)
-
1
)
==
0
)
{
return
false
;
}
}
rowLen
+=
pSchema
[
i
].
bytes
;
}
return
rowLen
<=
maxLen
;
}
bool
isValidSchema
(
struct
SSchema
*
pSchema
,
int32_t
numOfCols
,
int32_t
numOfTags
)
{
if
(
!
VALIDNUMOFCOLS
(
numOfCols
))
{
return
false
;
}
if
(
!
VALIDNUMOFTAGS
(
numOfTags
))
{
return
false
;
}
/* first column must be the timestamp, which is a primary key */
if
(
pSchema
[
0
].
type
!=
TSDB_DATA_TYPE_TIMESTAMP
)
{
return
false
;
}
if
(
!
doValidateSchema
(
pSchema
,
numOfCols
,
TSDB_MAX_BYTES_PER_ROW
))
{
return
false
;
}
if
(
!
doValidateSchema
(
&
pSchema
[
numOfCols
],
numOfTags
,
TSDB_MAX_TAGS_LEN
))
{
return
false
;
}
return
true
;
}
SSchema
*
tscGetTableColumnSchema
(
const
STableMeta
*
pTableMeta
,
int32_t
colIndex
)
{
assert
(
pTableMeta
!=
NULL
);
...
...
src/client/src/tscServer.c
浏览文件 @
5757003f
...
...
@@ -25,8 +25,6 @@
#include "ttimer.h"
#include "tlockfree.h"
///SRpcCorEpSet tscMgmtEpSet;
int
(
*
tscBuildMsg
[
TSDB_SQL_MAX
])(
SSqlObj
*
pSql
,
SSqlInfo
*
pInfo
)
=
{
0
};
int
(
*
tscProcessMsgRsp
[
TSDB_SQL_MAX
])(
SSqlObj
*
pSql
);
...
...
@@ -1157,7 +1155,7 @@ int32_t tscBuildDropTableMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
SCMDropTableMsg
*
pDropTableMsg
=
(
SCMDropTableMsg
*
)
pCmd
->
payload
;
STableMetaInfo
*
pTableMetaInfo
=
tscGetTableMetaInfoFromCmd
(
pCmd
,
pCmd
->
clauseIndex
,
0
);
strcpy
(
pDropTableMsg
->
table
Id
,
pTableMetaInfo
->
name
);
strcpy
(
pDropTableMsg
->
table
Fname
,
pTableMetaInfo
->
name
);
pDropTableMsg
->
igNotExists
=
pInfo
->
pDCLInfo
->
existsCheck
?
1
:
0
;
pCmd
->
msgType
=
TSDB_MSG_TYPE_CM_DROP_TABLE
;
...
...
@@ -1347,7 +1345,7 @@ int tscBuildCreateTableMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
pMsg
+=
sizeof
(
SCreateTableMsg
);
SCreatedTableInfo
*
p
=
taosArrayGet
(
list
,
i
);
strcpy
(
pCreate
->
table
Id
,
p
->
fullname
);
strcpy
(
pCreate
->
table
Fname
,
p
->
fullname
);
pCreate
->
igExists
=
(
p
->
igExist
)
?
1
:
0
;
// use dbinfo from table id without modifying current db info
...
...
@@ -1360,7 +1358,7 @@ int tscBuildCreateTableMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
}
else
{
// create (super) table
pCreateTableMsg
->
numOfTables
=
htonl
(
1
);
// only one table will be created
strcpy
(
pCreateMsg
->
table
Id
,
pTableMetaInfo
->
name
);
strcpy
(
pCreateMsg
->
table
Fname
,
pTableMetaInfo
->
name
);
// use dbinfo from table id without modifying current db info
tscGetDBInfoFromTableFullName
(
pTableMetaInfo
->
name
,
pCreateMsg
->
db
);
...
...
@@ -1431,7 +1429,7 @@ int tscBuildAlterTableMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
SAlterTableMsg
*
pAlterTableMsg
=
(
SAlterTableMsg
*
)
pCmd
->
payload
;
tscGetDBInfoFromTableFullName
(
pTableMetaInfo
->
name
,
pAlterTableMsg
->
db
);
strcpy
(
pAlterTableMsg
->
table
Id
,
pTableMetaInfo
->
name
);
strcpy
(
pAlterTableMsg
->
table
Fname
,
pTableMetaInfo
->
name
);
pAlterTableMsg
->
type
=
htons
(
pAlterInfo
->
type
);
pAlterTableMsg
->
numOfCols
=
htons
(
tscNumOfFields
(
pQueryInfo
));
...
...
@@ -1630,7 +1628,7 @@ int tscBuildTableMetaMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
STableMetaInfo
*
pTableMetaInfo
=
tscGetMetaInfo
(
pQueryInfo
,
0
);
STableInfoMsg
*
pInfoMsg
=
(
STableInfoMsg
*
)
pCmd
->
payload
;
strcpy
(
pInfoMsg
->
table
Id
,
pTableMetaInfo
->
name
);
strcpy
(
pInfoMsg
->
table
Fname
,
pTableMetaInfo
->
name
);
pInfoMsg
->
createFlag
=
htons
(
pSql
->
cmd
.
autoCreated
?
1
:
0
);
char
*
pMsg
=
(
char
*
)
pInfoMsg
+
sizeof
(
STableInfoMsg
);
...
...
@@ -1799,7 +1797,7 @@ int tscProcessTableMetaRsp(SSqlObj *pSql) {
if
((
pMetaMsg
->
tableType
!=
TSDB_SUPER_TABLE
)
&&
(
pMetaMsg
->
tid
<=
0
||
pMetaMsg
->
vgroup
.
vgId
<
2
||
pMetaMsg
->
vgroup
.
numOfEps
<=
0
))
{
tscError
(
"invalid value in table numOfEps:%d, vgId:%d tid:%d, name:%s"
,
pMetaMsg
->
vgroup
.
numOfEps
,
pMetaMsg
->
vgroup
.
vgId
,
pMetaMsg
->
tid
,
pMetaMsg
->
table
Id
);
pMetaMsg
->
tid
,
pMetaMsg
->
table
Fname
);
return
TSDB_CODE_TSC_INVALID_VALUE
;
}
...
...
@@ -1831,12 +1829,16 @@ int tscProcessTableMetaRsp(SSqlObj *pSql) {
assert
(
isValidDataType
(
pSchema
->
type
));
pSchema
++
;
}
STableMeta
*
pTableMeta
=
tscCreateTableMetaFromMsg
(
pMetaMsg
);
STableMetaInfo
*
pTableMetaInfo
=
tscGetTableMetaInfoFromCmd
(
&
pSql
->
cmd
,
0
,
0
);
assert
(
pTableMetaInfo
->
pTableMeta
==
NULL
);
STableMeta
*
pTableMeta
=
tscCreateTableMetaFromMsg
(
pMetaMsg
);
if
(
!
isValidSchema
(
pTableMeta
->
schema
,
pTableMeta
->
tableInfo
.
numOfColumns
,
pTableMeta
->
tableInfo
.
numOfTags
))
{
tscError
(
"%p invalid table meta from mnode, name:%s"
,
pSql
,
pTableMetaInfo
->
name
);
return
TSDB_CODE_TSC_INVALID_VALUE
;
}
if
(
pTableMeta
->
tableType
==
TSDB_CHILD_TABLE
)
{
// check if super table hashmap or not
int32_t
len
=
(
int32_t
)
strnlen
(
pTableMeta
->
sTableName
,
TSDB_TABLE_FNAME_LEN
);
...
...
src/common/inc/tname.h
浏览文件 @
5757003f
...
...
@@ -39,4 +39,18 @@ SColumnFilterInfo* tscFilterInfoClone(const SColumnFilterInfo* src, int32_t numO
SSchema
tscGetTbnameColumnSchema
();
/**
* check if the schema is valid or not, including following aspects:
* 1. number of columns
* 2. column types
* 3. column length
* 4. column names
* 5. total length
*
* @param pSchema
* @param numOfCols
* @return
*/
bool
isValidSchema
(
struct
SSchema
*
pSchema
,
int32_t
numOfCols
,
int32_t
numOfTags
);
#endif // TDENGINE_NAME_H
src/common/src/tname.c
浏览文件 @
5757003f
...
...
@@ -6,6 +6,10 @@
#include "ttokendef.h"
#include "tvariant.h"
#define VALIDNUMOFCOLS(x) ((x) >= TSDB_MIN_COLUMNS && (x) <= TSDB_MAX_COLUMNS)
#define VALIDNUMOFTAGS(x) ((x) >= 0 && (x) <= TSDB_MAX_TAGS)
// todo refactor
UNUSED_FUNC
static
FORCE_INLINE
const
char
*
skipSegments
(
const
char
*
input
,
char
delim
,
int32_t
num
)
{
for
(
int32_t
i
=
0
;
i
<
num
;
++
i
)
{
...
...
@@ -206,3 +210,65 @@ SSchema tscGetTbnameColumnSchema() {
strcpy
(
s
.
name
,
TSQL_TBNAME_L
);
return
s
;
}
static
bool
doValidateSchema
(
SSchema
*
pSchema
,
int32_t
numOfCols
,
int32_t
maxLen
)
{
int32_t
rowLen
=
0
;
for
(
int32_t
i
=
0
;
i
<
numOfCols
;
++
i
)
{
// 1. valid types
if
(
!
isValidDataType
(
pSchema
[
i
].
type
))
{
return
false
;
}
// 2. valid length for each type
if
(
pSchema
[
i
].
type
==
TSDB_DATA_TYPE_BINARY
)
{
if
(
pSchema
[
i
].
bytes
>
TSDB_MAX_BINARY_LEN
)
{
return
false
;
}
}
else
if
(
pSchema
[
i
].
type
==
TSDB_DATA_TYPE_NCHAR
)
{
if
(
pSchema
[
i
].
bytes
>
TSDB_MAX_NCHAR_LEN
)
{
return
false
;
}
}
else
{
if
(
pSchema
[
i
].
bytes
!=
tDataTypes
[
pSchema
[
i
].
type
].
bytes
)
{
return
false
;
}
}
// 3. valid column names
for
(
int32_t
j
=
i
+
1
;
j
<
numOfCols
;
++
j
)
{
if
(
strncasecmp
(
pSchema
[
i
].
name
,
pSchema
[
j
].
name
,
sizeof
(
pSchema
[
i
].
name
)
-
1
)
==
0
)
{
return
false
;
}
}
rowLen
+=
pSchema
[
i
].
bytes
;
}
return
rowLen
<=
maxLen
;
}
bool
isValidSchema
(
struct
SSchema
*
pSchema
,
int32_t
numOfCols
,
int32_t
numOfTags
)
{
if
(
!
VALIDNUMOFCOLS
(
numOfCols
))
{
return
false
;
}
if
(
!
VALIDNUMOFTAGS
(
numOfTags
))
{
return
false
;
}
/* first column must be the timestamp, which is a primary key */
if
(
pSchema
[
0
].
type
!=
TSDB_DATA_TYPE_TIMESTAMP
)
{
return
false
;
}
if
(
!
doValidateSchema
(
pSchema
,
numOfCols
,
TSDB_MAX_BYTES_PER_ROW
))
{
return
false
;
}
if
(
!
doValidateSchema
(
&
pSchema
[
numOfCols
],
numOfTags
,
TSDB_MAX_TAGS_LEN
))
{
return
false
;
}
return
true
;
}
src/dnode/src/dnodeShell.c
浏览文件 @
5757003f
...
...
@@ -216,7 +216,7 @@ void *dnodeSendCfgTableToRecv(int32_t vgId, int32_t tid) {
int16_t
numOfTags
=
htons
(
pTable
->
numOfTags
);
int32_t
tableId
=
htonl
(
pTable
->
tid
);
uint64_t
uid
=
htobe64
(
pTable
->
uid
);
dInfo
(
"table:%s, numOfColumns:%d numOfTags:%d tid:%d uid:%"
PRIu64
,
pTable
->
table
Id
,
numOfColumns
,
numOfTags
,
tableId
,
uid
);
dInfo
(
"table:%s, numOfColumns:%d numOfTags:%d tid:%d uid:%"
PRIu64
,
pTable
->
table
Fname
,
numOfColumns
,
numOfTags
,
tableId
,
uid
);
return
rpcRsp
.
pCont
;
}
...
...
src/inc/taosmsg.h
浏览文件 @
5757003f
...
...
@@ -260,14 +260,14 @@ typedef struct {
uint64_t
uid
;
uint64_t
superTableUid
;
uint64_t
createdTime
;
char
table
Id
[
TSDB_TABLE_FNAME_LEN
];
char
s
uperTableId
[
TSDB_TABLE_FNAME_LEN
];
char
table
Fname
[
TSDB_TABLE_FNAME_LEN
];
char
s
tableFname
[
TSDB_TABLE_FNAME_LEN
];
char
data
[];
}
SMDCreateTableMsg
;
typedef
struct
{
int32_t
len
;
// one create table message
char
table
Id
[
TSDB_TABLE_FNAME_LEN
];
char
table
Fname
[
TSDB_TABLE_FNAME_LEN
];
char
db
[
TSDB_ACCT_ID_LEN
+
TSDB_DB_NAME_LEN
];
int8_t
igExists
;
int8_t
getMeta
;
...
...
@@ -284,12 +284,12 @@ typedef struct {
}
SCMCreateTableMsg
;
typedef
struct
{
char
table
Id
[
TSDB_TABLE_FNAME_LEN
];
char
table
Fname
[
TSDB_TABLE_FNAME_LEN
];
int8_t
igNotExists
;
}
SCMDropTableMsg
;
typedef
struct
{
char
table
Id
[
TSDB_TABLE_FNAME_LEN
];
char
table
Fname
[
TSDB_TABLE_FNAME_LEN
];
char
db
[
TSDB_ACCT_ID_LEN
+
TSDB_DB_NAME_LEN
];
int16_t
type
;
/* operation type */
int16_t
numOfCols
;
/* number of schema */
...
...
@@ -369,14 +369,14 @@ typedef struct {
int32_t
vgId
;
int32_t
tid
;
uint64_t
uid
;
char
table
Id
[
TSDB_TABLE_FNAME_LEN
];
char
table
Fname
[
TSDB_TABLE_FNAME_LEN
];
}
SMDDropTableMsg
;
typedef
struct
{
int32_t
contLen
;
int32_t
vgId
;
uint64_t
uid
;
char
table
Id
[
TSDB_TABLE_FNAME_LEN
];
char
table
Fname
[
TSDB_TABLE_FNAME_LEN
];
}
SDropSTableMsg
;
typedef
struct
{
...
...
@@ -688,7 +688,7 @@ typedef struct {
}
SCreateVnodeMsg
,
SAlterVnodeMsg
;
typedef
struct
{
char
table
Id
[
TSDB_TABLE_FNAME_LEN
];
char
table
Fname
[
TSDB_TABLE_FNAME_LEN
];
int16_t
createFlag
;
char
tags
[];
}
STableInfoMsg
;
...
...
@@ -726,7 +726,7 @@ typedef struct {
typedef
struct
STableMetaMsg
{
int32_t
contLen
;
char
table
Id
[
TSDB_TABLE_FNAME_LEN
];
// table id
char
table
Fname
[
TSDB_TABLE_FNAME_LEN
];
// table id
uint8_t
numOfTags
;
uint8_t
precision
;
uint8_t
tableType
;
...
...
@@ -847,7 +847,7 @@ typedef struct {
uint64_t
uid
;
uint64_t
stime
;
// stream starting time
int32_t
status
;
char
table
Id
[
TSDB_TABLE_FNAME_LEN
];
char
table
Fname
[
TSDB_TABLE_FNAME_LEN
];
}
SAlterStreamMsg
;
typedef
struct
{
...
...
src/mnode/src/mnodeCluster.c
浏览文件 @
5757003f
...
...
@@ -195,7 +195,7 @@ static int32_t mnodeGetClusterMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *
cols
++
;
pMeta
->
numOfColumns
=
htons
(
cols
);
strcpy
(
pMeta
->
table
Id
,
"show cluster"
);
strcpy
(
pMeta
->
table
Fname
,
"show cluster"
);
pShow
->
numOfColumns
=
cols
;
pShow
->
offset
[
0
]
=
0
;
...
...
src/mnode/src/mnodeTable.c
浏览文件 @
5757003f
...
...
@@ -68,7 +68,7 @@ static int32_t mnodeGetShowSuperTableMeta(STableMetaMsg *pMeta, SShowObj *pShow,
static
int32_t
mnodeRetrieveShowSuperTables
(
SShowObj
*
pShow
,
char
*
data
,
int32_t
rows
,
void
*
pConn
);
static
int32_t
mnodeGetStreamTableMeta
(
STableMetaMsg
*
pMeta
,
SShowObj
*
pShow
,
void
*
pConn
);
static
int32_t
mnodeRetrieveStreamTables
(
SShowObj
*
pShow
,
char
*
data
,
int32_t
rows
,
void
*
pConn
);
static
int32_t
mnodeProcessCreateTableMsg
(
SMnodeMsg
*
pMsg
);
static
int32_t
mnodeProcessCreateSuperTableMsg
(
SMnodeMsg
*
pMsg
);
static
int32_t
mnodeProcessCreateChildTableMsg
(
SMnodeMsg
*
pMsg
);
...
...
@@ -164,7 +164,7 @@ static int32_t mnodeChildTableActionDelete(SSdbRow *pRow) {
SVgObj
*
pVgroup
=
NULL
;
SDbObj
*
pDb
=
NULL
;
SAcctObj
*
pAcct
=
NULL
;
pVgroup
=
mnodeGetVgroup
(
pTable
->
vgId
);
if
(
pVgroup
!=
NULL
)
pDb
=
mnodeGetDb
(
pVgroup
->
dbName
);
if
(
pDb
!=
NULL
)
pAcct
=
mnodeGetAcct
(
pDb
->
acct
);
...
...
@@ -180,14 +180,14 @@ static int32_t mnodeChildTableActionDelete(SSdbRow *pRow) {
grantRestore
(
TSDB_GRANT_TIMESERIES
,
pTable
->
numOfColumns
-
1
);
if
(
pAcct
!=
NULL
)
pAcct
->
acctInfo
.
numOfTimeSeries
-=
(
pTable
->
numOfColumns
-
1
);
}
if
(
pDb
!=
NULL
)
mnodeRemoveTableFromDb
(
pDb
);
if
(
pVgroup
!=
NULL
)
mnodeRemoveTableFromVgroup
(
pVgroup
,
pTable
);
mnodeDecVgroupRef
(
pVgroup
);
mnodeDecDbRef
(
pDb
);
mnodeDecAcctRef
(
pAcct
);
return
TSDB_CODE_SUCCESS
;
}
...
...
@@ -195,19 +195,19 @@ static int32_t mnodeChildTableActionUpdate(SSdbRow *pRow) {
SCTableObj
*
pNew
=
pRow
->
pObj
;
SCTableObj
*
pTable
=
mnodeGetChildTable
(
pNew
->
info
.
tableId
);
if
(
pTable
!=
pNew
)
{
void
*
oldTableId
=
pTable
->
info
.
tableId
;
void
*
oldTableId
=
pTable
->
info
.
tableId
;
void
*
oldSql
=
pTable
->
sql
;
void
*
oldSchema
=
pTable
->
schema
;
void
*
oldSTable
=
pTable
->
superTable
;
int32_t
oldRefCount
=
pTable
->
refCount
;
memcpy
(
pTable
,
pNew
,
sizeof
(
SCTableObj
));
pTable
->
refCount
=
oldRefCount
;
pTable
->
sql
=
pNew
->
sql
;
pTable
->
schema
=
pNew
->
schema
;
pTable
->
superTable
=
oldSTable
;
free
(
pNew
);
free
(
oldSql
);
free
(
oldSchema
);
...
...
@@ -544,7 +544,7 @@ static int32_t mnodeSuperTableActionDecode(SSdbRow *pRow) {
}
memcpy
(
pStable
->
schema
,
pRow
->
rowData
+
len
,
schemaSize
);
pRow
->
pObj
=
pStable
;
return
TSDB_CODE_SUCCESS
;
...
...
@@ -611,7 +611,7 @@ int32_t mnodeInitTables() {
mnodeAddWriteMsgHandle
(
TSDB_MSG_TYPE_CM_ALTER_TABLE
,
mnodeProcessAlterTableMsg
);
mnodeAddReadMsgHandle
(
TSDB_MSG_TYPE_CM_TABLE_META
,
mnodeProcessTableMetaMsg
);
mnodeAddReadMsgHandle
(
TSDB_MSG_TYPE_CM_STABLE_VGROUP
,
mnodeProcessSuperTableVgroupMsg
);
mnodeAddPeerRspHandle
(
TSDB_MSG_TYPE_MD_CREATE_TABLE_RSP
,
mnodeProcessCreateChildTableRsp
);
mnodeAddPeerRspHandle
(
TSDB_MSG_TYPE_MD_DROP_TABLE_RSP
,
mnodeProcessDropChildTableRsp
);
mnodeAddPeerRspHandle
(
TSDB_MSG_TYPE_MD_DROP_STABLE_RSP
,
mnodeProcessDropSuperTableRsp
);
...
...
@@ -750,7 +750,7 @@ void mnodeDestroySubMsg(SMnodeMsg *pSubMsg) {
static
int32_t
mnodeValidateCreateTableMsg
(
SCreateTableMsg
*
pCreateTable
,
SMnodeMsg
*
pMsg
)
{
if
(
pMsg
->
pDb
==
NULL
)
pMsg
->
pDb
=
mnodeGetDb
(
pCreateTable
->
db
);
if
(
pMsg
->
pDb
==
NULL
)
{
mError
(
"msg:%p, app:%p table:%s, failed to create, db not selected"
,
pMsg
,
pMsg
->
rpcMsg
.
ahandle
,
pCreateTable
->
table
Id
);
mError
(
"msg:%p, app:%p table:%s, failed to create, db not selected"
,
pMsg
,
pMsg
->
rpcMsg
.
ahandle
,
pCreateTable
->
table
Fname
);
return
TSDB_CODE_MND_DB_NOT_SELECTED
;
}
...
...
@@ -759,28 +759,28 @@ static int32_t mnodeValidateCreateTableMsg(SCreateTableMsg *pCreateTable, SMnode
return
TSDB_CODE_MND_DB_IN_DROPPING
;
}
if
(
pMsg
->
pTable
==
NULL
)
pMsg
->
pTable
=
mnodeGetTable
(
pCreateTable
->
table
Id
);
if
(
pMsg
->
pTable
==
NULL
)
pMsg
->
pTable
=
mnodeGetTable
(
pCreateTable
->
table
Fname
);
if
(
pMsg
->
pTable
!=
NULL
&&
pMsg
->
retry
==
0
)
{
if
(
pCreateTable
->
getMeta
)
{
mDebug
(
"msg:%p, app:%p table:%s, continue to get meta"
,
pMsg
,
pMsg
->
rpcMsg
.
ahandle
,
pCreateTable
->
table
Id
);
mDebug
(
"msg:%p, app:%p table:%s, continue to get meta"
,
pMsg
,
pMsg
->
rpcMsg
.
ahandle
,
pCreateTable
->
table
Fname
);
return
mnodeGetChildTableMeta
(
pMsg
);
}
else
if
(
pCreateTable
->
igExists
)
{
mDebug
(
"msg:%p, app:%p table:%s, is already exist"
,
pMsg
,
pMsg
->
rpcMsg
.
ahandle
,
pCreateTable
->
table
Id
);
mDebug
(
"msg:%p, app:%p table:%s, is already exist"
,
pMsg
,
pMsg
->
rpcMsg
.
ahandle
,
pCreateTable
->
table
Fname
);
return
TSDB_CODE_SUCCESS
;
}
else
{
mError
(
"msg:%p, app:%p table:%s, failed to create, table already exist"
,
pMsg
,
pMsg
->
rpcMsg
.
ahandle
,
pCreateTable
->
table
Id
);
pCreateTable
->
table
Fname
);
return
TSDB_CODE_MND_TABLE_ALREADY_EXIST
;
}
}
if
(
pCreateTable
->
numOfTags
!=
0
)
{
mDebug
(
"msg:%p, app:%p table:%s, create stable msg is received from thandle:%p"
,
pMsg
,
pMsg
->
rpcMsg
.
ahandle
,
pCreateTable
->
table
Id
,
pMsg
->
rpcMsg
.
handle
);
pCreateTable
->
table
Fname
,
pMsg
->
rpcMsg
.
handle
);
return
mnodeProcessCreateSuperTableMsg
(
pMsg
);
}
else
{
mDebug
(
"msg:%p, app:%p table:%s, create ctable msg is received from thandle:%p"
,
pMsg
,
pMsg
->
rpcMsg
.
ahandle
,
pCreateTable
->
table
Id
,
pMsg
->
rpcMsg
.
handle
);
pCreateTable
->
table
Fname
,
pMsg
->
rpcMsg
.
handle
);
return
mnodeProcessCreateChildTableMsg
(
pMsg
);
}
}
...
...
@@ -862,47 +862,46 @@ static int32_t mnodeProcessCreateTableMsg(SMnodeMsg *pMsg) {
SCreateTableMsg
*
p
=
(
SCreateTableMsg
*
)((
char
*
)
pCreate
+
sizeof
(
SCMCreateTableMsg
));
if
(
pMsg
->
pDb
==
NULL
)
pMsg
->
pDb
=
mnodeGetDb
(
p
->
db
);
if
(
pMsg
->
pDb
==
NULL
)
{
mError
(
"msg:%p, app:%p table:%s, failed to create, db not selected"
,
pMsg
,
pMsg
->
rpcMsg
.
ahandle
,
p
->
table
Id
);
mError
(
"msg:%p, app:%p table:%s, failed to create, db not selected"
,
pMsg
,
pMsg
->
rpcMsg
.
ahandle
,
p
->
table
Fname
);
return
TSDB_CODE_MND_DB_NOT_SELECTED
;
}
if
(
pMsg
->
pDb
->
status
!=
TSDB_DB_STATUS_READY
)
{
mError
(
"db:%s, status:%d, in dropping"
,
pMsg
->
pDb
->
name
,
pMsg
->
pDb
->
status
);
return
TSDB_CODE_MND_DB_IN_DROPPING
;
}
if
(
pMsg
->
pTable
==
NULL
)
pMsg
->
pTable
=
mnodeGetTable
(
p
->
table
Id
);
if
(
pMsg
->
pTable
==
NULL
)
pMsg
->
pTable
=
mnodeGetTable
(
p
->
table
Fname
);
if
(
pMsg
->
pTable
!=
NULL
&&
pMsg
->
retry
==
0
)
{
if
(
p
->
getMeta
)
{
mDebug
(
"msg:%p, app:%p table:%s, continue to get meta"
,
pMsg
,
pMsg
->
rpcMsg
.
ahandle
,
p
->
table
Id
);
mDebug
(
"msg:%p, app:%p table:%s, continue to get meta"
,
pMsg
,
pMsg
->
rpcMsg
.
ahandle
,
p
->
table
Fname
);
return
mnodeGetChildTableMeta
(
pMsg
);
}
else
if
(
p
->
igExists
)
{
mDebug
(
"msg:%p, app:%p table:%s, is already exist"
,
pMsg
,
pMsg
->
rpcMsg
.
ahandle
,
p
->
table
Id
);
mDebug
(
"msg:%p, app:%p table:%s, is already exist"
,
pMsg
,
pMsg
->
rpcMsg
.
ahandle
,
p
->
table
Fname
);
return
TSDB_CODE_SUCCESS
;
}
else
{
mError
(
"msg:%p, app:%p table:%s, failed to create, table already exist"
,
pMsg
,
pMsg
->
rpcMsg
.
ahandle
,
p
->
tableId
);
mError
(
"msg:%p, app:%p table:%s, failed to create, table already exist"
,
pMsg
,
pMsg
->
rpcMsg
.
ahandle
,
p
->
tableFname
);
return
TSDB_CODE_MND_TABLE_ALREADY_EXIST
;
}
}
if
(
p
->
numOfTags
!=
0
)
{
mDebug
(
"msg:%p, app:%p table:%s, create stable msg is received from thandle:%p"
,
pMsg
,
pMsg
->
rpcMsg
.
ahandle
,
p
->
table
Id
,
pMsg
->
rpcMsg
.
handle
);
p
->
table
Fname
,
pMsg
->
rpcMsg
.
handle
);
return
mnodeProcessCreateSuperTableMsg
(
pMsg
);
}
else
{
mDebug
(
"msg:%p, app:%p table:%s, create ctable msg is received from thandle:%p"
,
pMsg
,
pMsg
->
rpcMsg
.
ahandle
,
p
->
table
Id
,
pMsg
->
rpcMsg
.
handle
);
p
->
table
Fname
,
pMsg
->
rpcMsg
.
handle
);
return
mnodeProcessCreateChildTableMsg
(
pMsg
);
}
}
static
int32_t
mnodeProcessDropTableMsg
(
SMnodeMsg
*
pMsg
)
{
SCMDropTableMsg
*
pDrop
=
pMsg
->
rpcMsg
.
pCont
;
if
(
pMsg
->
pDb
==
NULL
)
pMsg
->
pDb
=
mnodeGetDbByTableId
(
pDrop
->
table
Id
);
if
(
pMsg
->
pDb
==
NULL
)
pMsg
->
pDb
=
mnodeGetDbByTableId
(
pDrop
->
table
Fname
);
if
(
pMsg
->
pDb
==
NULL
)
{
mError
(
"msg:%p, app:%p table:%s, failed to drop table, db not selected or db in dropping"
,
pMsg
,
pMsg
->
rpcMsg
.
ahandle
,
pDrop
->
table
Id
);
pMsg
->
rpcMsg
.
ahandle
,
pDrop
->
table
Fname
);
return
TSDB_CODE_MND_DB_NOT_SELECTED
;
}
...
...
@@ -913,17 +912,17 @@ static int32_t mnodeProcessDropTableMsg(SMnodeMsg *pMsg) {
if
(
mnodeCheckIsMonitorDB
(
pMsg
->
pDb
->
name
,
tsMonitorDbName
))
{
mError
(
"msg:%p, app:%p table:%s, failed to drop table, in monitor database"
,
pMsg
,
pMsg
->
rpcMsg
.
ahandle
,
pDrop
->
table
Id
);
pDrop
->
table
Fname
);
return
TSDB_CODE_MND_MONITOR_DB_FORBIDDEN
;
}
if
(
pMsg
->
pTable
==
NULL
)
pMsg
->
pTable
=
mnodeGetTable
(
pDrop
->
table
Id
);
if
(
pMsg
->
pTable
==
NULL
)
pMsg
->
pTable
=
mnodeGetTable
(
pDrop
->
table
Fname
);
if
(
pMsg
->
pTable
==
NULL
)
{
if
(
pDrop
->
igNotExists
)
{
mDebug
(
"msg:%p, app:%p table:%s is not exist, treat as success"
,
pMsg
,
pMsg
->
rpcMsg
.
ahandle
,
pDrop
->
table
Id
);
mDebug
(
"msg:%p, app:%p table:%s is not exist, treat as success"
,
pMsg
,
pMsg
->
rpcMsg
.
ahandle
,
pDrop
->
table
Fname
);
return
TSDB_CODE_SUCCESS
;
}
else
{
mError
(
"msg:%p, app:%p table:%s, failed to drop, table not exist"
,
pMsg
,
pMsg
->
rpcMsg
.
ahandle
,
pDrop
->
table
Id
);
mError
(
"msg:%p, app:%p table:%s, failed to drop, table not exist"
,
pMsg
,
pMsg
->
rpcMsg
.
ahandle
,
pDrop
->
table
Fname
);
return
TSDB_CODE_MND_INVALID_TABLE_NAME
;
}
}
...
...
@@ -931,12 +930,12 @@ static int32_t mnodeProcessDropTableMsg(SMnodeMsg *pMsg) {
if
(
pMsg
->
pTable
->
type
==
TSDB_SUPER_TABLE
)
{
SSTableObj
*
pSTable
=
(
SSTableObj
*
)
pMsg
->
pTable
;
mInfo
(
"msg:%p, app:%p table:%s, start to drop stable, uid:%"
PRIu64
", numOfChildTables:%d, sizeOfVgList:%d"
,
pMsg
,
pMsg
->
rpcMsg
.
ahandle
,
pDrop
->
table
Id
,
pSTable
->
uid
,
pSTable
->
numOfTables
,
taosHashGetSize
(
pSTable
->
vgHash
));
pMsg
->
rpcMsg
.
ahandle
,
pDrop
->
table
Fname
,
pSTable
->
uid
,
pSTable
->
numOfTables
,
taosHashGetSize
(
pSTable
->
vgHash
));
return
mnodeProcessDropSuperTableMsg
(
pMsg
);
}
else
{
SCTableObj
*
pCTable
=
(
SCTableObj
*
)
pMsg
->
pTable
;
mInfo
(
"msg:%p, app:%p table:%s, start to drop ctable, vgId:%d tid:%d uid:%"
PRIu64
,
pMsg
,
pMsg
->
rpcMsg
.
ahandle
,
pDrop
->
table
Id
,
pCTable
->
vgId
,
pCTable
->
tid
,
pCTable
->
uid
);
pDrop
->
table
Fname
,
pCTable
->
vgId
,
pCTable
->
tid
,
pCTable
->
uid
);
return
mnodeProcessDropChildTableMsg
(
pMsg
);
}
}
...
...
@@ -945,29 +944,29 @@ static int32_t mnodeProcessTableMetaMsg(SMnodeMsg *pMsg) {
STableInfoMsg
*
pInfo
=
pMsg
->
rpcMsg
.
pCont
;
pInfo
->
createFlag
=
htons
(
pInfo
->
createFlag
);
mDebug
(
"msg:%p, app:%p table:%s, table meta msg is received from thandle:%p, createFlag:%d"
,
pMsg
,
pMsg
->
rpcMsg
.
ahandle
,
pInfo
->
table
Id
,
pMsg
->
rpcMsg
.
handle
,
pInfo
->
createFlag
);
pInfo
->
table
Fname
,
pMsg
->
rpcMsg
.
handle
,
pInfo
->
createFlag
);
if
(
pMsg
->
pDb
==
NULL
)
pMsg
->
pDb
=
mnodeGetDbByTableId
(
pInfo
->
table
Id
);
if
(
pMsg
->
pDb
==
NULL
)
pMsg
->
pDb
=
mnodeGetDbByTableId
(
pInfo
->
table
Fname
);
if
(
pMsg
->
pDb
==
NULL
)
{
mError
(
"msg:%p, app:%p table:%s, failed to get table meta, db not selected"
,
pMsg
,
pMsg
->
rpcMsg
.
ahandle
,
pInfo
->
table
Id
);
pInfo
->
table
Fname
);
return
TSDB_CODE_MND_DB_NOT_SELECTED
;
}
if
(
pMsg
->
pDb
->
status
!=
TSDB_DB_STATUS_READY
)
{
mError
(
"db:%s, status:%d, in dropping"
,
pMsg
->
pDb
->
name
,
pMsg
->
pDb
->
status
);
return
TSDB_CODE_MND_DB_IN_DROPPING
;
}
if
(
pMsg
->
pTable
==
NULL
)
pMsg
->
pTable
=
mnodeGetTable
(
pInfo
->
table
Id
);
if
(
pMsg
->
pTable
==
NULL
)
pMsg
->
pTable
=
mnodeGetTable
(
pInfo
->
table
Fname
);
if
(
pMsg
->
pTable
==
NULL
)
{
if
(
!
pInfo
->
createFlag
)
{
mError
(
"msg:%p, app:%p table:%s, failed to get table meta, table not exist"
,
pMsg
,
pMsg
->
rpcMsg
.
ahandle
,
pInfo
->
table
Id
);
pInfo
->
table
Fname
);
return
TSDB_CODE_MND_INVALID_TABLE_NAME
;
}
else
{
mDebug
(
"msg:%p, app:%p table:%s, failed to get table meta, start auto create table "
,
pMsg
,
pMsg
->
rpcMsg
.
ahandle
,
pInfo
->
table
Id
);
pInfo
->
table
Fname
);
return
mnodeAutoCreateChildTable
(
pMsg
);
}
}
else
{
...
...
@@ -1007,12 +1006,12 @@ static int32_t mnodeProcessCreateSuperTableMsg(SMnodeMsg *pMsg) {
SSTableObj
*
pStable
=
calloc
(
1
,
sizeof
(
SSTableObj
));
if
(
pStable
==
NULL
)
{
mError
(
"msg:%p, app:%p table:%s, failed to create, no enough memory"
,
pMsg
,
pMsg
->
rpcMsg
.
ahandle
,
pCreate
->
table
Id
);
mError
(
"msg:%p, app:%p table:%s, failed to create, no enough memory"
,
pMsg
,
pMsg
->
rpcMsg
.
ahandle
,
pCreate
->
table
Fname
);
return
TSDB_CODE_MND_OUT_OF_MEMORY
;
}
int64_t
us
=
taosGetTimestampUs
();
pStable
->
info
.
tableId
=
strdup
(
pCreate
->
table
Id
);
pStable
->
info
.
tableId
=
strdup
(
pCreate
->
table
Fname
);
pStable
->
info
.
type
=
TSDB_SUPER_TABLE
;
pStable
->
createdTime
=
taosGetTimestampMs
();
pStable
->
uid
=
(
us
<<
24
)
+
((
sdbGetVersion
()
&
((
1ul
<<
16
)
-
1ul
))
<<
8
)
+
(
taosRand
()
&
((
1ul
<<
8
)
-
1ul
));
...
...
@@ -1026,41 +1025,27 @@ static int32_t mnodeProcessCreateSuperTableMsg(SMnodeMsg *pMsg) {
pStable
->
schema
=
(
SSchema
*
)
calloc
(
1
,
schemaSize
);
if
(
pStable
->
schema
==
NULL
)
{
free
(
pStable
);
mError
(
"msg:%p, app:%p table:%s, failed to create, no schema input"
,
pMsg
,
pMsg
->
rpcMsg
.
ahandle
,
pCreate
->
table
Id
);
mError
(
"msg:%p, app:%p table:%s, failed to create, no schema input"
,
pMsg
,
pMsg
->
rpcMsg
.
ahandle
,
pCreate
->
table
Fname
);
return
TSDB_CODE_MND_INVALID_TABLE_NAME
;
}
memcpy
(
pStable
->
schema
,
pCreate
->
schema
,
numOfCols
*
sizeof
(
SSchema
));
if
(
pStable
->
numOfColumns
>
TSDB_MAX_COLUMNS
||
pStable
->
numOfTags
>
TSDB_MAX_TAGS
)
{
mError
(
"msg:%p, app:%p table:%s, failed to create, too many columns"
,
pMsg
,
pMsg
->
rpcMsg
.
ahandle
,
pCreate
->
table
Id
);
mError
(
"msg:%p, app:%p table:%s, failed to create, too many columns"
,
pMsg
,
pMsg
->
rpcMsg
.
ahandle
,
pCreate
->
table
Fname
);
return
TSDB_CODE_MND_INVALID_TABLE_NAME
;
}
pStable
->
nextColId
=
0
;
// TODO extract method to valid the schema
int32_t
schemaLen
=
0
;
int32_t
tagLen
=
0
;
for
(
int32_t
col
=
0
;
col
<
numOfCols
;
col
++
)
{
SSchema
*
tschema
=
pStable
->
schema
;
tschema
[
col
].
colId
=
pStable
->
nextColId
++
;
tschema
[
col
].
bytes
=
htons
(
tschema
[
col
].
bytes
);
if
(
col
<
pStable
->
numOfTables
)
{
schemaLen
+=
tschema
[
col
].
bytes
;
}
else
{
tagLen
+=
tschema
[
col
].
bytes
;
}
if
(
!
isValidDataType
(
tschema
[
col
].
type
))
{
mError
(
"msg:%p, app:%p table:%s, failed to create, invalid data type in schema"
,
pMsg
,
pMsg
->
rpcMsg
.
ahandle
,
pCreate
->
tableId
);
return
TSDB_CODE_MND_INVALID_CREATE_TABLE_MSG
;
}
}
if
(
schemaLen
>
(
TSDB_MAX_BYTES_PER_ROW
||
tagLen
>
TSDB_MAX_TAGS_LEN
))
{
mError
(
"msg:%p, app:%p table:%s, failed to create
, schema is too long"
,
pMsg
,
pMsg
->
rpcMsg
.
ahandle
,
pCreate
->
tableId
);
if
(
!
isValidSchema
(
pStable
->
schema
,
pStable
->
numOfColumns
,
pStable
->
numOfTags
))
{
mError
(
"msg:%p, app:%p table:%s, failed to create
table, invalid schema"
,
pMsg
,
pMsg
->
rpcMsg
.
ahandle
,
pCreate
->
tableFname
);
return
TSDB_CODE_MND_INVALID_CREATE_TABLE_MSG
;
}
...
...
@@ -1080,7 +1065,7 @@ static int32_t mnodeProcessCreateSuperTableMsg(SMnodeMsg *pMsg) {
if
(
code
!=
TSDB_CODE_SUCCESS
&&
code
!=
TSDB_CODE_MND_ACTION_IN_PROGRESS
)
{
mnodeDestroySuperTable
(
pStable
);
pMsg
->
pTable
=
NULL
;
mError
(
"msg:%p, app:%p table:%s, failed to create, sdb error"
,
pMsg
,
pMsg
->
rpcMsg
.
ahandle
,
pCreate
->
table
Id
);
mError
(
"msg:%p, app:%p table:%s, failed to create, sdb error"
,
pMsg
,
pMsg
->
rpcMsg
.
ahandle
,
pCreate
->
table
Fname
);
}
return
code
;
...
...
@@ -1115,7 +1100,7 @@ static int32_t mnodeProcessDropSuperTableMsg(SMnodeMsg *pMsg) {
pDrop
->
contLen
=
htonl
(
sizeof
(
SDropSTableMsg
));
pDrop
->
vgId
=
htonl
(
pVgroup
->
vgId
);
pDrop
->
uid
=
htobe64
(
pStable
->
uid
);
mnodeExtractTableName
(
pStable
->
info
.
tableId
,
pDrop
->
table
Id
);
mnodeExtractTableName
(
pStable
->
info
.
tableId
,
pDrop
->
table
Fname
);
mInfo
(
"msg:%p, app:%p stable:%s, send drop stable msg to vgId:%d, hash:%p sizeOfVgList:%d"
,
pMsg
,
pMsg
->
rpcMsg
.
ahandle
,
pStable
->
info
.
tableId
,
pVgroup
->
vgId
,
pStable
->
vgHash
,
...
...
@@ -1129,8 +1114,8 @@ static int32_t mnodeProcessDropSuperTableMsg(SMnodeMsg *pMsg) {
taosHashCancelIterate
(
pStable
->
vgHash
,
pVgId
);
mnodeDropAllChildTablesInStable
(
pStable
);
}
}
SSdbRow
row
=
{
.
type
=
SDB_OPER_GLOBAL
,
.
pTable
=
tsSuperTableSdb
,
...
...
@@ -1274,7 +1259,7 @@ static int32_t mnodeModifySuperTableTagName(SMnodeMsg *pMsg, char *oldTagName, c
if
(
mnodeFindSuperTableTagIndex
(
pStable
,
newTagName
)
>=
0
)
{
return
TSDB_CODE_MND_TAG_ALREAY_EXIST
;
}
// update
SSchema
*
schema
=
(
SSchema
*
)
(
pStable
->
schema
+
pStable
->
numOfColumns
+
col
);
tstrncpy
(
schema
->
name
,
newTagName
,
sizeof
(
schema
->
name
));
...
...
@@ -1437,7 +1422,7 @@ static int32_t mnodeChangeSuperTableColumn(SMnodeMsg *pMsg, char *oldName, char
if
(
mnodeFindSuperTableColumnIndex
(
pStable
,
newName
)
>=
0
)
{
return
TSDB_CODE_MND_FIELD_ALREAY_EXIST
;
}
// update
SSchema
*
schema
=
(
SSchema
*
)
(
pStable
->
schema
+
col
);
tstrncpy
(
schema
->
name
,
newName
,
sizeof
(
schema
->
name
));
...
...
@@ -1460,7 +1445,7 @@ static int32_t mnodeChangeSuperTableColumn(SMnodeMsg *pMsg, char *oldName, char
static
int32_t
mnodeGetShowSuperTableMeta
(
STableMetaMsg
*
pMeta
,
SShowObj
*
pShow
,
void
*
pConn
)
{
SDbObj
*
pDb
=
mnodeGetDb
(
pShow
->
db
);
if
(
pDb
==
NULL
)
return
TSDB_CODE_MND_DB_NOT_SELECTED
;
if
(
pDb
->
status
!=
TSDB_DB_STATUS_READY
)
{
mError
(
"db:%s, status:%d, in dropping"
,
pDb
->
name
,
pDb
->
status
);
mnodeDecDbRef
(
pDb
);
...
...
@@ -1525,7 +1510,7 @@ int32_t mnodeRetrieveShowSuperTables(SShowObj *pShow, char *data, int32_t rows,
SDbObj
*
pDb
=
mnodeGetDb
(
pShow
->
db
);
if
(
pDb
==
NULL
)
return
0
;
if
(
pDb
->
status
!=
TSDB_DB_STATUS_READY
)
{
mError
(
"db:%s, status:%d, in dropping"
,
pDb
->
name
,
pDb
->
status
);
mnodeDecDbRef
(
pDb
);
...
...
@@ -1539,7 +1524,7 @@ int32_t mnodeRetrieveShowSuperTables(SShowObj *pShow, char *data, int32_t rows,
SPatternCompareInfo
info
=
PATTERN_COMPARE_INFO_INITIALIZER
;
char
stableName
[
TSDB_TABLE_NAME_LEN
]
=
{
0
};
while
(
numOfRows
<
rows
)
{
while
(
numOfRows
<
rows
)
{
pShow
->
pIter
=
mnodeGetNextSuperTable
(
pShow
->
pIter
,
&
pTable
);
if
(
pTable
==
NULL
)
break
;
if
(
strncmp
(
pTable
->
info
.
tableId
,
prefix
,
prefixLen
))
{
...
...
@@ -1558,11 +1543,11 @@ int32_t mnodeRetrieveShowSuperTables(SShowObj *pShow, char *data, int32_t rows,
cols
=
0
;
pWrite
=
data
+
pShow
->
offset
[
cols
]
*
rows
+
pShow
->
bytes
[
cols
]
*
numOfRows
;
int16_t
len
=
strnlen
(
stableName
,
TSDB_TABLE_NAME_LEN
-
1
);
*
(
int16_t
*
)
pWrite
=
len
;
pWrite
+=
sizeof
(
int16_t
);
// todo refactor
strncpy
(
pWrite
,
stableName
,
len
);
cols
++
;
...
...
@@ -1629,7 +1614,7 @@ void mnodeDropAllSuperTables(SDbObj *pDropDb) {
static
int32_t
mnodeSetSchemaFromSuperTable
(
SSchema
*
pSchema
,
SSTableObj
*
pTable
)
{
int32_t
numOfCols
=
pTable
->
numOfColumns
+
pTable
->
numOfTags
;
assert
(
numOfCols
<=
TSDB_MAX_COLUMNS
);
for
(
int32_t
i
=
0
;
i
<
numOfCols
;
++
i
)
{
tstrncpy
(
pSchema
->
name
,
pTable
->
schema
[
i
].
name
,
sizeof
(
pSchema
->
name
));
pSchema
->
type
=
pTable
->
schema
[
i
].
type
;
...
...
@@ -1655,7 +1640,7 @@ static int32_t mnodeGetSuperTableMeta(SMnodeMsg *pMsg) {
pMeta
->
numOfColumns
=
htons
((
int16_t
)
pTable
->
numOfColumns
);
pMeta
->
tableType
=
pTable
->
info
.
type
;
pMeta
->
contLen
=
sizeof
(
STableMetaMsg
)
+
mnodeSetSchemaFromSuperTable
(
pMeta
->
schema
,
pTable
);
tstrncpy
(
pMeta
->
table
Id
,
pTable
->
info
.
tableId
,
sizeof
(
pMeta
->
tableId
));
tstrncpy
(
pMeta
->
table
Fname
,
pTable
->
info
.
tableId
,
sizeof
(
pMeta
->
tableFname
));
pMsg
->
rpcRsp
.
len
=
pMeta
->
contLen
;
pMeta
->
contLen
=
htons
(
pMeta
->
contLen
);
...
...
@@ -1709,7 +1694,7 @@ static int32_t mnodeProcessSuperTableVgroupMsg(SMnodeMsg *pMsg) {
SVgroupsMsg
*
pVgroupMsg
=
(
SVgroupsMsg
*
)
msg
;
pVgroupMsg
->
numOfVgroups
=
0
;
msg
+=
sizeof
(
SVgroupsMsg
);
}
else
{
SVgroupsMsg
*
pVgroupMsg
=
(
SVgroupsMsg
*
)
msg
;
...
...
@@ -1798,7 +1783,7 @@ static void *mnodeBuildCreateChildTableMsg(SCMCreateTableMsg *pCreateMsg, SCTabl
return
NULL
;
}
mnodeExtractTableName
(
pTable
->
info
.
tableId
,
pCreate
->
table
Id
);
mnodeExtractTableName
(
pTable
->
info
.
tableId
,
pCreate
->
table
Fname
);
pCreate
->
contLen
=
htonl
(
contLen
);
pCreate
->
vgId
=
htonl
(
pTable
->
vgId
);
pCreate
->
tableType
=
pTable
->
info
.
type
;
...
...
@@ -1806,9 +1791,9 @@ static void *mnodeBuildCreateChildTableMsg(SCMCreateTableMsg *pCreateMsg, SCTabl
pCreate
->
tid
=
htonl
(
pTable
->
tid
);
pCreate
->
sqlDataLen
=
htonl
(
pTable
->
sqlLen
);
pCreate
->
uid
=
htobe64
(
pTable
->
uid
);
if
(
pTable
->
info
.
type
==
TSDB_CHILD_TABLE
)
{
mnodeExtractTableName
(
pTable
->
superTable
->
info
.
tableId
,
pCreate
->
s
uperTableId
);
mnodeExtractTableName
(
pTable
->
superTable
->
info
.
tableId
,
pCreate
->
s
tableFname
);
pCreate
->
numOfColumns
=
htons
(
pTable
->
superTable
->
numOfColumns
);
pCreate
->
numOfTags
=
htons
(
pTable
->
superTable
->
numOfTags
);
pCreate
->
sversion
=
htonl
(
pTable
->
superTable
->
sversion
);
...
...
@@ -1823,7 +1808,7 @@ static void *mnodeBuildCreateChildTableMsg(SCMCreateTableMsg *pCreateMsg, SCTabl
pCreate
->
tagDataLen
=
0
;
pCreate
->
superTableUid
=
0
;
}
SSchema
*
pSchema
=
(
SSchema
*
)
pCreate
->
data
;
if
(
pTable
->
info
.
type
==
TSDB_CHILD_TABLE
)
{
memcpy
(
pSchema
,
pTable
->
superTable
->
schema
,
totalCols
*
sizeof
(
SSchema
));
...
...
@@ -1922,12 +1907,12 @@ static int32_t mnodeDoCreateChildTable(SMnodeMsg *pMsg, int32_t tid) {
SCTableObj
*
pTable
=
calloc
(
1
,
sizeof
(
SCTableObj
));
if
(
pTable
==
NULL
)
{
mError
(
"msg:%p, app:%p table:%s, failed to alloc memory"
,
pMsg
,
pMsg
->
rpcMsg
.
ahandle
,
pCreate
->
table
Id
);
mError
(
"msg:%p, app:%p table:%s, failed to alloc memory"
,
pMsg
,
pMsg
->
rpcMsg
.
ahandle
,
pCreate
->
table
Fname
);
return
TSDB_CODE_MND_OUT_OF_MEMORY
;
}
pTable
->
info
.
type
=
(
pCreate
->
numOfColumns
==
0
)
?
TSDB_CHILD_TABLE
:
TSDB_NORMAL_TABLE
;
pTable
->
info
.
tableId
=
strdup
(
pCreate
->
table
Id
);
pTable
->
info
.
tableId
=
strdup
(
pCreate
->
table
Fname
);
pTable
->
createdTime
=
taosGetTimestampMs
();
pTable
->
tid
=
tid
;
pTable
->
vgId
=
pVgroup
->
vgId
;
...
...
@@ -1943,7 +1928,7 @@ static int32_t mnodeDoCreateChildTable(SMnodeMsg *pMsg, int32_t tid) {
size_t
prefixLen
=
tableIdPrefix
(
pMsg
->
pDb
->
name
,
prefix
,
64
);
if
(
0
!=
strncasecmp
(
prefix
,
stableName
,
prefixLen
))
{
mError
(
"msg:%p, app:%p table:%s, corresponding super table:%s not in this db"
,
pMsg
,
pMsg
->
rpcMsg
.
ahandle
,
pCreate
->
table
Id
,
stableName
);
pCreate
->
table
Fname
,
stableName
);
mnodeDestroyChildTable
(
pTable
);
return
TSDB_CODE_TDB_INVALID_CREATE_TB_MSG
;
}
...
...
@@ -1951,7 +1936,7 @@ static int32_t mnodeDoCreateChildTable(SMnodeMsg *pMsg, int32_t tid) {
if
(
pMsg
->
pSTable
==
NULL
)
pMsg
->
pSTable
=
mnodeGetSuperTable
(
stableName
);
if
(
pMsg
->
pSTable
==
NULL
)
{
mError
(
"msg:%p, app:%p table:%s, corresponding super table:%s does not exist"
,
pMsg
,
pMsg
->
rpcMsg
.
ahandle
,
pCreate
->
table
Id
,
stableName
);
pCreate
->
table
Fname
,
stableName
);
mnodeDestroyChildTable
(
pTable
);
return
TSDB_CODE_MND_INVALID_TABLE_NAME
;
}
...
...
@@ -2013,12 +1998,12 @@ static int32_t mnodeDoCreateChildTable(SMnodeMsg *pMsg, int32_t tid) {
.
pMsg
=
pMsg
,
.
fpReq
=
mnodeDoCreateChildTableFp
};
int32_t
code
=
sdbInsertRow
(
&
desc
);
if
(
code
!=
TSDB_CODE_SUCCESS
&&
code
!=
TSDB_CODE_MND_ACTION_IN_PROGRESS
)
{
mnodeDestroyChildTable
(
pTable
);
pMsg
->
pTable
=
NULL
;
mError
(
"msg:%p, app:%p table:%s, failed to create, reason:%s"
,
pMsg
,
pMsg
->
rpcMsg
.
ahandle
,
pCreate
->
table
Id
,
mError
(
"msg:%p, app:%p table:%s, failed to create, reason:%s"
,
pMsg
,
pMsg
->
rpcMsg
.
ahandle
,
pCreate
->
table
Fname
,
tstrerror
(
code
));
}
else
{
mDebug
(
"msg:%p, app:%p table:%s, allocated in vgroup, vgId:%d sid:%d uid:%"
PRIu64
,
pMsg
,
pMsg
->
rpcMsg
.
ahandle
,
...
...
@@ -2035,7 +2020,7 @@ static int32_t mnodeProcessCreateChildTableMsg(SMnodeMsg *pMsg) {
int32_t
code
=
grantCheck
(
TSDB_GRANT_TIMESERIES
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
mError
(
"msg:%p, app:%p table:%s, failed to create, grant timeseries failed"
,
pMsg
,
pMsg
->
rpcMsg
.
ahandle
,
pCreate
->
table
Id
);
pCreate
->
table
Fname
);
return
code
;
}
...
...
@@ -2046,7 +2031,7 @@ static int32_t mnodeProcessCreateChildTableMsg(SMnodeMsg *pMsg) {
code
=
mnodeGetAvailableVgroup
(
pMsg
,
&
pVgroup
,
&
tid
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
mDebug
(
"msg:%p, app:%p table:%s, failed to get available vgroup, reason:%s"
,
pMsg
,
pMsg
->
rpcMsg
.
ahandle
,
pCreate
->
table
Id
,
tstrerror
(
code
));
pCreate
->
table
Fname
,
tstrerror
(
code
));
return
code
;
}
...
...
@@ -2060,15 +2045,15 @@ static int32_t mnodeProcessCreateChildTableMsg(SMnodeMsg *pMsg) {
return
mnodeDoCreateChildTable
(
pMsg
,
tid
);
}
}
else
{
if
(
pMsg
->
pTable
==
NULL
)
pMsg
->
pTable
=
mnodeGetTable
(
pCreate
->
table
Id
);
if
(
pMsg
->
pTable
==
NULL
)
pMsg
->
pTable
=
mnodeGetTable
(
pCreate
->
table
Fname
);
}
if
(
pMsg
->
pTable
==
NULL
)
{
mError
(
"msg:%p, app:%p table:%s, object not found, retry:%d reason:%s"
,
pMsg
,
pMsg
->
rpcMsg
.
ahandle
,
pCreate
->
table
Id
,
pMsg
->
retry
,
mError
(
"msg:%p, app:%p table:%s, object not found, retry:%d reason:%s"
,
pMsg
,
pMsg
->
rpcMsg
.
ahandle
,
pCreate
->
table
Fname
,
pMsg
->
retry
,
tstrerror
(
terrno
));
return
terrno
;
}
else
{
mDebug
(
"msg:%p, app:%p table:%s, send create msg to vnode again"
,
pMsg
,
pMsg
->
rpcMsg
.
ahandle
,
pCreate
->
table
Id
);
mDebug
(
"msg:%p, app:%p table:%s, send create msg to vnode again"
,
pMsg
,
pMsg
->
rpcMsg
.
ahandle
,
pCreate
->
table
Fname
);
return
mnodeDoCreateChildTableFp
(
pMsg
);
}
}
...
...
@@ -2084,7 +2069,7 @@ static int32_t mnodeSendDropChildTableMsg(SMnodeMsg *pMsg, bool needReturn) {
return
TSDB_CODE_MND_OUT_OF_MEMORY
;
}
tstrncpy
(
pDrop
->
table
Id
,
pTable
->
info
.
tableId
,
TSDB_TABLE_FNAME_LEN
);
tstrncpy
(
pDrop
->
table
Fname
,
pTable
->
info
.
tableId
,
TSDB_TABLE_FNAME_LEN
);
pDrop
->
vgId
=
htonl
(
pTable
->
vgId
);
pDrop
->
contLen
=
htonl
(
sizeof
(
SMDDropTableMsg
));
pDrop
->
tid
=
htonl
(
pTable
->
tid
);
...
...
@@ -2093,7 +2078,7 @@ static int32_t mnodeSendDropChildTableMsg(SMnodeMsg *pMsg, bool needReturn) {
SRpcEpSet
epSet
=
mnodeGetEpSetFromVgroup
(
pMsg
->
pVgroup
);
mInfo
(
"msg:%p, app:%p ctable:%s, send drop ctable msg, vgId:%d sid:%d uid:%"
PRIu64
,
pMsg
,
pMsg
->
rpcMsg
.
ahandle
,
pDrop
->
table
Id
,
pTable
->
vgId
,
pTable
->
tid
,
pTable
->
uid
);
pDrop
->
table
Fname
,
pTable
->
vgId
,
pTable
->
tid
,
pTable
->
uid
);
SRpcMsg
rpcMsg
=
{
.
ahandle
=
pMsg
,
...
...
@@ -2115,7 +2100,7 @@ static int32_t mnodeDropChildTableCb(SMnodeMsg *pMsg, int32_t code) {
SCTableObj
*
pTable
=
(
SCTableObj
*
)
pMsg
->
pTable
;
mError
(
"msg:%p, app:%p ctable:%s, failed to drop, sdb error"
,
pMsg
,
pMsg
->
rpcMsg
.
ahandle
,
pTable
->
info
.
tableId
);
return
code
;
}
}
return
mnodeSendDropChildTableMsg
(
pMsg
,
true
);
}
...
...
@@ -2224,7 +2209,7 @@ static int32_t mnodeAddNormalTableColumn(SMnodeMsg *pMsg, SSchema schema[], int3
pTable
->
numOfColumns
+=
ncols
;
pTable
->
sversion
++
;
SAcctObj
*
pAcct
=
mnodeGetAcct
(
pDb
->
acct
);
if
(
pAcct
!=
NULL
)
{
pAcct
->
acctInfo
.
numOfTimeSeries
+=
ncols
;
...
...
@@ -2295,7 +2280,7 @@ static int32_t mnodeChangeNormalTableColumn(SMnodeMsg *pMsg, char *oldName, char
if
(
mnodeFindNormalTableColumnIndex
(
pTable
,
newName
)
>=
0
)
{
return
TSDB_CODE_MND_FIELD_ALREAY_EXIST
;
}
// update
SSchema
*
schema
=
(
SSchema
*
)
(
pTable
->
schema
+
col
);
tstrncpy
(
schema
->
name
,
newName
,
sizeof
(
schema
->
name
));
...
...
@@ -2335,7 +2320,7 @@ static int32_t mnodeDoGetChildTableMeta(SMnodeMsg *pMsg, STableMetaMsg *pMeta) {
pMeta
->
tid
=
htonl
(
pTable
->
tid
);
pMeta
->
precision
=
pDb
->
cfg
.
precision
;
pMeta
->
tableType
=
pTable
->
info
.
type
;
tstrncpy
(
pMeta
->
table
Id
,
pTable
->
info
.
tableId
,
TSDB_TABLE_FNAME_LEN
);
tstrncpy
(
pMeta
->
table
Fname
,
pTable
->
info
.
tableId
,
TSDB_TABLE_FNAME_LEN
);
if
(
pTable
->
info
.
type
==
TSDB_CHILD_TABLE
)
{
assert
(
pTable
->
superTable
!=
NULL
);
...
...
@@ -2352,7 +2337,7 @@ static int32_t mnodeDoGetChildTableMeta(SMnodeMsg *pMsg, STableMetaMsg *pMeta) {
pMeta
->
tversion
=
0
;
pMeta
->
numOfTags
=
0
;
pMeta
->
numOfColumns
=
htons
((
int16_t
)
pTable
->
numOfColumns
);
pMeta
->
contLen
=
sizeof
(
STableMetaMsg
)
+
mnodeSetSchemaFromNormalTable
(
pMeta
->
schema
,
pTable
);
pMeta
->
contLen
=
sizeof
(
STableMetaMsg
)
+
mnodeSetSchemaFromNormalTable
(
pMeta
->
schema
,
pTable
);
}
if
(
pMsg
->
pVgroup
==
NULL
)
pMsg
->
pVgroup
=
mnodeGetVgroup
(
pTable
->
vgId
);
...
...
@@ -2383,7 +2368,7 @@ static int32_t mnodeAutoCreateChildTable(SMnodeMsg *pMsg) {
if
(
pMsg
->
rpcMsg
.
contLen
<=
sizeof
(
*
pInfo
))
{
mError
(
"msg:%p, app:%p table:%s, failed to auto create child table, tags not exist"
,
pMsg
,
pMsg
->
rpcMsg
.
ahandle
,
pInfo
->
table
Id
);
pInfo
->
table
Fname
);
return
TSDB_CODE_MND_TAG_NOT_EXIST
;
}
...
...
@@ -2398,7 +2383,7 @@ static int32_t mnodeAutoCreateChildTable(SMnodeMsg *pMsg) {
int32_t
totalLen
=
nameLen
+
tagLen
+
sizeof
(
int32_t
)
*
2
;
if
(
tagLen
==
0
||
nameLen
==
0
)
{
mError
(
"msg:%p, app:%p table:%s, failed to create table on demand for super table is empty, tagLen:%d"
,
pMsg
,
pMsg
->
rpcMsg
.
ahandle
,
pInfo
->
table
Id
,
tagLen
);
pMsg
->
rpcMsg
.
ahandle
,
pInfo
->
table
Fname
,
tagLen
);
return
TSDB_CODE_MND_INVALID_STABLE_NAME
;
}
...
...
@@ -2406,14 +2391,14 @@ static int32_t mnodeAutoCreateChildTable(SMnodeMsg *pMsg) {
SCMCreateTableMsg
*
pCreateMsg
=
calloc
(
1
,
contLen
);
if
(
pCreateMsg
==
NULL
)
{
mError
(
"msg:%p, app:%p table:%s, failed to create table while get meta info, no enough memory"
,
pMsg
,
pMsg
->
rpcMsg
.
ahandle
,
pInfo
->
table
Id
);
pMsg
->
rpcMsg
.
ahandle
,
pInfo
->
table
Fname
);
return
TSDB_CODE_MND_OUT_OF_MEMORY
;
}
SCreateTableMsg
*
pCreate
=
(
SCreateTableMsg
*
)
((
char
*
)
pCreateMsg
+
sizeof
(
SCMCreateTableMsg
));
size_t
size
=
tListLen
(
pInfo
->
table
Id
);
tstrncpy
(
pCreate
->
table
Id
,
pInfo
->
tableId
,
size
);
size_t
size
=
tListLen
(
pInfo
->
table
Fname
);
tstrncpy
(
pCreate
->
table
Fname
,
pInfo
->
tableFname
,
size
);
tstrncpy
(
pCreate
->
db
,
pMsg
->
pDb
->
name
,
sizeof
(
pCreate
->
db
));
pCreate
->
igExists
=
1
;
pCreate
->
getMeta
=
1
;
...
...
@@ -2427,7 +2412,7 @@ static int32_t mnodeAutoCreateChildTable(SMnodeMsg *pMsg) {
memcpy
(
name
,
pInfo
->
tags
+
sizeof
(
int32_t
),
nameLen
);
mDebug
(
"msg:%p, app:%p table:%s, start to create on demand, tagLen:%d stable:%s"
,
pMsg
,
pMsg
->
rpcMsg
.
ahandle
,
pInfo
->
table
Id
,
tagLen
,
name
);
pInfo
->
table
Fname
,
tagLen
,
name
);
if
(
pMsg
->
rpcMsg
.
pCont
!=
pMsg
->
pCont
)
{
tfree
(
pMsg
->
rpcMsg
.
pCont
);
...
...
@@ -2557,7 +2542,7 @@ static SCTableObj* mnodeGetTableByPos(int32_t vnode, int32_t tid) {
static
int32_t
mnodeProcessTableCfgMsg
(
SMnodeMsg
*
pMsg
)
{
return
TSDB_CODE_COM_OPS_NOT_SUPPORT
;
#if 0
#if 0
SConfigTableMsg *pCfg = pMsg->rpcMsg.pCont;
pCfg->dnodeId = htonl(pCfg->dnodeId);
pCfg->vgId = htonl(pCfg->vgId);
...
...
@@ -2575,13 +2560,13 @@ static int32_t mnodeProcessTableCfgMsg(SMnodeMsg *pMsg) {
SMDCreateTableMsg *pCreate = NULL;
pCreate = mnodeBuildCreateChildTableMsg(NULL, (SCTableObj *)pTable);
mnodeDecTableRef(pTable);
if (pCreate == NULL) return terrno;
pMsg->rpcRsp.rsp = pCreate;
pMsg->rpcRsp.len = htonl(pCreate->contLen);
return TSDB_CODE_SUCCESS;
#endif
#endif
}
// handle drop child response
...
...
@@ -2674,7 +2659,7 @@ static void mnodeProcessCreateChildTableRsp(SRpcMsg *rpcMsg) {
.
pMsg
=
pMsg
,
.
fpRsp
=
mnodeDoCreateChildTableCb
};
int32_t
code
=
sdbInsertRowToQueue
(
&
desc
);
if
(
code
!=
TSDB_CODE_SUCCESS
&&
code
!=
TSDB_CODE_MND_ACTION_IN_PROGRESS
)
{
pMsg
->
pTable
=
NULL
;
...
...
@@ -2821,7 +2806,7 @@ static int32_t mnodeProcessMultiTableMetaMsg(SMnodeMsg *pMsg) {
static
int32_t
mnodeGetShowTableMeta
(
STableMetaMsg
*
pMeta
,
SShowObj
*
pShow
,
void
*
pConn
)
{
SDbObj
*
pDb
=
mnodeGetDb
(
pShow
->
db
);
if
(
pDb
==
NULL
)
return
TSDB_CODE_MND_DB_NOT_SELECTED
;
if
(
pDb
->
status
!=
TSDB_DB_STATUS_READY
)
{
mError
(
"db:%s, status:%d, in dropping"
,
pDb
->
name
,
pDb
->
status
);
mnodeDecDbRef
(
pDb
);
...
...
@@ -2894,7 +2879,7 @@ static int32_t mnodeGetShowTableMeta(STableMetaMsg *pMeta, SShowObj *pShow, void
static
int32_t
mnodeRetrieveShowTables
(
SShowObj
*
pShow
,
char
*
data
,
int32_t
rows
,
void
*
pConn
)
{
SDbObj
*
pDb
=
mnodeGetDb
(
pShow
->
db
);
if
(
pDb
==
NULL
)
return
0
;
if
(
pDb
->
status
!=
TSDB_DB_STATUS_READY
)
{
mError
(
"db:%s, status:%d, in dropping"
,
pDb
->
name
,
pDb
->
status
);
mnodeDecDbRef
(
pDb
);
...
...
@@ -2931,7 +2916,7 @@ static int32_t mnodeRetrieveShowTables(SShowObj *pShow, char *data, int32_t rows
}
char
tableName
[
TSDB_TABLE_NAME_LEN
]
=
{
0
};
// pattern compare for table name
mnodeExtractTableName
(
pTable
->
info
.
tableId
,
tableName
);
...
...
@@ -2960,13 +2945,13 @@ static int32_t mnodeRetrieveShowTables(SShowObj *pShow, char *data, int32_t rows
cols
++
;
pWrite
=
data
+
pShow
->
offset
[
cols
]
*
rows
+
pShow
->
bytes
[
cols
]
*
numOfRows
;
memset
(
tableName
,
0
,
sizeof
(
tableName
));
if
(
pTable
->
info
.
type
==
TSDB_CHILD_TABLE
)
{
mnodeExtractTableName
(
pTable
->
superTable
->
info
.
tableId
,
tableName
);
STR_WITH_MAXSIZE_TO_VARSTR
(
pWrite
,
tableName
,
pShow
->
bytes
[
cols
]);
}
cols
++
;
// uid
...
...
@@ -3001,27 +2986,27 @@ static int32_t mnodeRetrieveShowTables(SShowObj *pShow, char *data, int32_t rows
static
int32_t
mnodeProcessAlterTableMsg
(
SMnodeMsg
*
pMsg
)
{
SAlterTableMsg
*
pAlter
=
pMsg
->
rpcMsg
.
pCont
;
mDebug
(
"msg:%p, app:%p table:%s, alter table msg is received from thandle:%p"
,
pMsg
,
pMsg
->
rpcMsg
.
ahandle
,
pAlter
->
table
Id
,
pMsg
->
rpcMsg
.
handle
);
pAlter
->
table
Fname
,
pMsg
->
rpcMsg
.
handle
);
if
(
pMsg
->
pDb
==
NULL
)
pMsg
->
pDb
=
mnodeGetDbByTableId
(
pAlter
->
table
Id
);
if
(
pMsg
->
pDb
==
NULL
)
pMsg
->
pDb
=
mnodeGetDbByTableId
(
pAlter
->
table
Fname
);
if
(
pMsg
->
pDb
==
NULL
)
{
mError
(
"msg:%p, app:%p table:%s, failed to alter table, db not selected"
,
pMsg
,
pMsg
->
rpcMsg
.
ahandle
,
pAlter
->
table
Id
);
mError
(
"msg:%p, app:%p table:%s, failed to alter table, db not selected"
,
pMsg
,
pMsg
->
rpcMsg
.
ahandle
,
pAlter
->
table
Fname
);
return
TSDB_CODE_MND_DB_NOT_SELECTED
;
}
if
(
pMsg
->
pDb
->
status
!=
TSDB_DB_STATUS_READY
)
{
mError
(
"db:%s, status:%d, in dropping"
,
pMsg
->
pDb
->
name
,
pMsg
->
pDb
->
status
);
return
TSDB_CODE_MND_DB_IN_DROPPING
;
}
if
(
mnodeCheckIsMonitorDB
(
pMsg
->
pDb
->
name
,
tsMonitorDbName
))
{
mError
(
"msg:%p, app:%p table:%s, failed to alter table, its log db"
,
pMsg
,
pMsg
->
rpcMsg
.
ahandle
,
pAlter
->
table
Id
);
mError
(
"msg:%p, app:%p table:%s, failed to alter table, its log db"
,
pMsg
,
pMsg
->
rpcMsg
.
ahandle
,
pAlter
->
table
Fname
);
return
TSDB_CODE_MND_MONITOR_DB_FORBIDDEN
;
}
if
(
pMsg
->
pTable
==
NULL
)
pMsg
->
pTable
=
mnodeGetTable
(
pAlter
->
table
Id
);
if
(
pMsg
->
pTable
==
NULL
)
pMsg
->
pTable
=
mnodeGetTable
(
pAlter
->
table
Fname
);
if
(
pMsg
->
pTable
==
NULL
)
{
mError
(
"msg:%p, app:%p table:%s, failed to alter table, table not exist"
,
pMsg
,
pMsg
->
rpcMsg
.
ahandle
,
pAlter
->
table
Id
);
mError
(
"msg:%p, app:%p table:%s, failed to alter table, table not exist"
,
pMsg
,
pMsg
->
rpcMsg
.
ahandle
,
pAlter
->
table
Fname
);
return
TSDB_CODE_MND_INVALID_TABLE_NAME
;
}
...
...
@@ -3030,7 +3015,7 @@ static int32_t mnodeProcessAlterTableMsg(SMnodeMsg *pMsg) {
pAlter
->
tagValLen
=
htonl
(
pAlter
->
tagValLen
);
if
(
pAlter
->
numOfCols
>
2
)
{
mError
(
"msg:%p, app:%p table:%s, error numOfCols:%d in alter table"
,
pMsg
,
pMsg
->
rpcMsg
.
ahandle
,
pAlter
->
table
Id
,
mError
(
"msg:%p, app:%p table:%s, error numOfCols:%d in alter table"
,
pMsg
,
pMsg
->
rpcMsg
.
ahandle
,
pAlter
->
table
Fname
,
pAlter
->
numOfCols
);
return
TSDB_CODE_MND_APP_ERROR
;
}
...
...
@@ -3041,7 +3026,7 @@ static int32_t mnodeProcessAlterTableMsg(SMnodeMsg *pMsg) {
int32_t
code
=
TSDB_CODE_COM_OPS_NOT_SUPPORT
;
if
(
pMsg
->
pTable
->
type
==
TSDB_SUPER_TABLE
)
{
mDebug
(
"msg:%p, app:%p table:%s, start to alter stable"
,
pMsg
,
pMsg
->
rpcMsg
.
ahandle
,
pAlter
->
table
Id
);
mDebug
(
"msg:%p, app:%p table:%s, start to alter stable"
,
pMsg
,
pMsg
->
rpcMsg
.
ahandle
,
pAlter
->
table
Fname
);
if
(
pAlter
->
type
==
TSDB_ALTER_TABLE_ADD_TAG_COLUMN
)
{
code
=
mnodeAddSuperTableTag
(
pMsg
,
pAlter
->
schema
,
1
);
}
else
if
(
pAlter
->
type
==
TSDB_ALTER_TABLE_DROP_TAG_COLUMN
)
{
...
...
@@ -3057,7 +3042,7 @@ static int32_t mnodeProcessAlterTableMsg(SMnodeMsg *pMsg) {
}
else
{
}
}
else
{
mDebug
(
"msg:%p, app:%p table:%s, start to alter ctable"
,
pMsg
,
pMsg
->
rpcMsg
.
ahandle
,
pAlter
->
table
Id
);
mDebug
(
"msg:%p, app:%p table:%s, start to alter ctable"
,
pMsg
,
pMsg
->
rpcMsg
.
ahandle
,
pAlter
->
table
Fname
);
if
(
pAlter
->
type
==
TSDB_ALTER_TABLE_UPDATE_TAG_VAL
)
{
return
TSDB_CODE_COM_OPS_NOT_SUPPORT
;
}
else
if
(
pAlter
->
type
==
TSDB_ALTER_TABLE_ADD_COLUMN
)
{
...
...
@@ -3076,7 +3061,7 @@ static int32_t mnodeProcessAlterTableMsg(SMnodeMsg *pMsg) {
static
int32_t
mnodeGetStreamTableMeta
(
STableMetaMsg
*
pMeta
,
SShowObj
*
pShow
,
void
*
pConn
)
{
SDbObj
*
pDb
=
mnodeGetDb
(
pShow
->
db
);
if
(
pDb
==
NULL
)
return
TSDB_CODE_MND_DB_NOT_SELECTED
;
if
(
pDb
->
status
!=
TSDB_DB_STATUS_READY
)
{
mError
(
"db:%s, status:%d, in dropping"
,
pDb
->
name
,
pDb
->
status
);
mnodeDecDbRef
(
pDb
);
...
...
@@ -3129,13 +3114,13 @@ static int32_t mnodeGetStreamTableMeta(STableMetaMsg *pMeta, SShowObj *pShow, vo
static
int32_t
mnodeRetrieveStreamTables
(
SShowObj
*
pShow
,
char
*
data
,
int32_t
rows
,
void
*
pConn
)
{
SDbObj
*
pDb
=
mnodeGetDb
(
pShow
->
db
);
if
(
pDb
==
NULL
)
return
0
;
if
(
pDb
->
status
!=
TSDB_DB_STATUS_READY
)
{
mError
(
"db:%s, status:%d, in dropping"
,
pDb
->
name
,
pDb
->
status
);
mnodeDecDbRef
(
pDb
);
return
0
;
}
int32_t
numOfRows
=
0
;
SCTableObj
*
pTable
=
NULL
;
SPatternCompareInfo
info
=
PATTERN_COMPARE_INFO_INITIALIZER
;
...
...
@@ -3148,7 +3133,7 @@ static int32_t mnodeRetrieveStreamTables(SShowObj *pShow, char *data, int32_t ro
while
(
numOfRows
<
rows
)
{
pShow
->
pIter
=
mnodeGetNextChildTable
(
pShow
->
pIter
,
&
pTable
);
if
(
pTable
==
NULL
)
break
;
// not belong to current db
if
(
strncmp
(
pTable
->
info
.
tableId
,
prefix
,
prefixLen
)
||
pTable
->
info
.
type
!=
TSDB_STREAM_TABLE
)
{
mnodeDecTableRef
(
pTable
);
...
...
@@ -3156,7 +3141,7 @@ static int32_t mnodeRetrieveStreamTables(SShowObj *pShow, char *data, int32_t ro
}
char
tableName
[
TSDB_TABLE_NAME_LEN
]
=
{
0
};
// pattern compare for table name
mnodeExtractTableName
(
pTable
->
info
.
tableId
,
tableName
);
...
...
src/mnode/src/mnodeUser.c
浏览文件 @
5757003f
...
...
@@ -337,7 +337,7 @@ static int32_t mnodeGetUserMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pCo
cols
++
;
pMeta
->
numOfColumns
=
htons
(
cols
);
strcpy
(
pMeta
->
table
Id
,
"show users"
);
strcpy
(
pMeta
->
table
Fname
,
"show users"
);
pShow
->
numOfColumns
=
cols
;
pShow
->
offset
[
0
]
=
0
;
...
...
src/tsdb/src/tsdbMeta.c
浏览文件 @
5757003f
...
...
@@ -253,7 +253,7 @@ STableCfg *tsdbCreateTableCfgFromMsg(SMDCreateTableMsg *pMsg) {
}
}
if
(
tsdbTableSetSchema
(
pCfg
,
tdGetSchemaFromBuilder
(
&
schemaBuilder
),
false
)
<
0
)
goto
_err
;
if
(
tsdbTableSetName
(
pCfg
,
pMsg
->
table
Id
,
true
)
<
0
)
goto
_err
;
if
(
tsdbTableSetName
(
pCfg
,
pMsg
->
table
Fname
,
true
)
<
0
)
goto
_err
;
if
(
numOfTags
>
0
)
{
// Decode tag schema
...
...
@@ -265,7 +265,7 @@ STableCfg *tsdbCreateTableCfgFromMsg(SMDCreateTableMsg *pMsg) {
}
}
if
(
tsdbTableSetTagSchema
(
pCfg
,
tdGetSchemaFromBuilder
(
&
schemaBuilder
),
false
)
<
0
)
goto
_err
;
if
(
tsdbTableSetSName
(
pCfg
,
pMsg
->
s
uperTableId
,
true
)
<
0
)
goto
_err
;
if
(
tsdbTableSetSName
(
pCfg
,
pMsg
->
s
tableFname
,
true
)
<
0
)
goto
_err
;
if
(
tsdbTableSetSuperUid
(
pCfg
,
htobe64
(
pMsg
->
superTableUid
))
<
0
)
goto
_err
;
int32_t
tagDataLen
=
htonl
(
pMsg
->
tagDataLen
);
...
...
src/vnode/src/vnodeWrite.c
浏览文件 @
5757003f
...
...
@@ -174,7 +174,7 @@ static int32_t vnodeProcessDropTableMsg(SVnodeObj *pVnode, void *pCont, SRspRet
SMDDropTableMsg
*
pTable
=
pCont
;
int32_t
code
=
TSDB_CODE_SUCCESS
;
vDebug
(
"vgId:%d, table:%s, start to drop"
,
pVnode
->
vgId
,
pTable
->
table
Id
);
vDebug
(
"vgId:%d, table:%s, start to drop"
,
pVnode
->
vgId
,
pTable
->
table
Fname
);
STableId
tableId
=
{.
uid
=
htobe64
(
pTable
->
uid
),
.
tid
=
htonl
(
pTable
->
tid
)};
if
(
tsdbDropTable
(
pVnode
->
tsdb
,
tableId
)
<
0
)
code
=
terrno
;
...
...
@@ -197,13 +197,13 @@ static int32_t vnodeProcessDropStableMsg(SVnodeObj *pVnode, void *pCont, SRspRet
SDropSTableMsg
*
pTable
=
pCont
;
int32_t
code
=
TSDB_CODE_SUCCESS
;
vDebug
(
"vgId:%d, stable:%s, start to drop"
,
pVnode
->
vgId
,
pTable
->
table
Id
);
vDebug
(
"vgId:%d, stable:%s, start to drop"
,
pVnode
->
vgId
,
pTable
->
table
Fname
);
STableId
stableId
=
{.
uid
=
htobe64
(
pTable
->
uid
),
.
tid
=
-
1
};
if
(
tsdbDropTable
(
pVnode
->
tsdb
,
stableId
)
<
0
)
code
=
terrno
;
vDebug
(
"vgId:%d, stable:%s, drop stable result:%s"
,
pVnode
->
vgId
,
pTable
->
table
Id
,
tstrerror
(
code
));
vDebug
(
"vgId:%d, stable:%s, drop stable result:%s"
,
pVnode
->
vgId
,
pTable
->
table
Fname
,
tstrerror
(
code
));
return
code
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录