Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
XKZJ_WCL
TDengine
提交
84313b70
T
TDengine
项目概览
XKZJ_WCL
/
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看板
体验新版 GitCode,发现更多精彩内容 >>
提交
84313b70
编写于
1月 19, 2021
作者:
H
Haojun Liao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[TD-2490]<fix>: add check for full table name.
上级
6d91f152
变更
20
展开全部
隐藏空白更改
内联
并排
Showing
20 changed file
with
517 addition
and
334 deletion
+517
-334
src/client/inc/tscUtil.h
src/client/inc/tscUtil.h
+4
-9
src/client/inc/tsclient.h
src/client/inc/tsclient.h
+5
-5
src/client/src/tscLocal.c
src/client/src/tscLocal.c
+9
-5
src/client/src/tscParseInsert.c
src/client/src/tscParseInsert.c
+10
-10
src/client/src/tscPrepare.c
src/client/src/tscPrepare.c
+2
-2
src/client/src/tscSQLParser.c
src/client/src/tscSQLParser.c
+51
-47
src/client/src/tscSchemaUtil.c
src/client/src/tscSchemaUtil.c
+1
-0
src/client/src/tscServer.c
src/client/src/tscServer.c
+111
-111
src/client/src/tscSql.c
src/client/src/tscSql.c
+5
-2
src/client/src/tscStream.c
src/client/src/tscStream.c
+8
-7
src/client/src/tscSubquery.c
src/client/src/tscSubquery.c
+7
-6
src/client/src/tscUtil.c
src/client/src/tscUtil.c
+18
-36
src/common/inc/tname.h
src/common/inc/tname.h
+39
-3
src/common/src/tname.c
src/common/src/tname.c
+181
-24
src/inc/taosmsg.h
src/inc/taosmsg.h
+2
-3
src/mnode/inc/mnodeDb.h
src/mnode/inc/mnodeDb.h
+1
-1
src/mnode/src/mnodeDb.c
src/mnode/src/mnodeDb.c
+7
-12
src/mnode/src/mnodeTable.c
src/mnode/src/mnodeTable.c
+54
-49
src/query/src/qAst.c
src/query/src/qAst.c
+1
-1
src/query/src/qExecutor.c
src/query/src/qExecutor.c
+1
-1
未找到文件。
src/client/inc/tscUtil.h
浏览文件 @
84313b70
...
...
@@ -98,8 +98,7 @@ static FORCE_INLINE SQueryInfo* tscGetQueryInfoDetail(SSqlCmd* pCmd, int32_t sub
return
pCmd
->
pQueryInfo
[
subClauseIndex
];
}
int32_t
tscCreateDataBlock
(
size_t
initialSize
,
int32_t
rowSize
,
int32_t
startOffset
,
const
char
*
name
,
STableMeta
*
pTableMeta
,
STableDataBlocks
**
dataBlocks
);
int32_t
tscCreateDataBlock
(
size_t
initialSize
,
int32_t
rowSize
,
int32_t
startOffset
,
SName
*
name
,
STableMeta
*
pTableMeta
,
STableDataBlocks
**
dataBlocks
);
void
tscDestroyDataBlock
(
STableDataBlocks
*
pDataBlock
);
void
tscSortRemoveDataBlockDupRows
(
STableDataBlocks
*
dataBuf
);
...
...
@@ -111,7 +110,7 @@ void* tscDestroyBlockHashTable(SHashObj* pBlockHashTable);
int32_t
tscCopyDataBlockToPayload
(
SSqlObj
*
pSql
,
STableDataBlocks
*
pDataBlock
);
int32_t
tscMergeTableDataBlocks
(
SSqlObj
*
pSql
,
bool
freeBlockMap
);
int32_t
tscGetDataBlockFromList
(
SHashObj
*
pHashList
,
int64_t
id
,
int32_t
size
,
int32_t
startOffset
,
int32_t
rowSize
,
const
char
*
tableId
,
STableMeta
*
pTableMeta
,
int32_t
tscGetDataBlockFromList
(
SHashObj
*
pHashList
,
int64_t
id
,
int32_t
size
,
int32_t
startOffset
,
int32_t
rowSize
,
SName
*
pName
,
STableMeta
*
pTableMeta
,
STableDataBlocks
**
dataBlocks
,
SArray
*
pBlockList
);
/**
...
...
@@ -142,10 +141,6 @@ void tscClearInterpInfo(SQueryInfo* pQueryInfo);
bool
tscIsInsertData
(
char
*
sqlstr
);
/* use for keep current db info temporarily, for handle table with db prefix */
// todo remove it
void
tscGetDBInfoFromTableFullName
(
char
*
tableId
,
char
*
db
);
int
tscAllocPayload
(
SSqlCmd
*
pCmd
,
int
size
);
TAOS_FIELD
tscCreateField
(
int8_t
type
,
const
char
*
name
,
int16_t
bytes
);
...
...
@@ -215,8 +210,8 @@ SQueryInfo *tscGetQueryInfoDetailSafely(SSqlCmd *pCmd, int32_t subClauseIndex);
void
tscClearTableMetaInfo
(
STableMetaInfo
*
pTableMetaInfo
);
STableMetaInfo
*
tscAddTableMetaInfo
(
SQueryInfo
*
pQueryInfo
,
const
char
*
name
,
STableMeta
*
pTableMeta
,
SVgroupsInfo
*
vgroupList
,
SArray
*
pTagCols
,
SArray
*
pVgroupTables
);
STableMetaInfo
*
tscAddTableMetaInfo
(
SQueryInfo
*
pQueryInfo
,
SName
*
name
,
STableMeta
*
pTableMeta
,
SVgroupsInfo
*
vgroupList
,
SArray
*
pTagCols
,
SArray
*
pVgroupTables
);
STableMetaInfo
*
tscAddEmptyMetaInfo
(
SQueryInfo
*
pQueryInfo
);
int32_t
tscAddSubqueryInfo
(
SSqlCmd
*
pCmd
);
...
...
src/client/inc/tsclient.h
浏览文件 @
84313b70
...
...
@@ -67,7 +67,7 @@ typedef struct CChildTableMeta {
int32_t
vgId
;
STableId
id
;
uint8_t
tableType
;
char
sTableName
[
TSDB_TABLE_FNAME_LEN
];
char
sTableName
[
TSDB_TABLE_FNAME_LEN
];
//super table name, not full name
}
CChildTableMeta
;
typedef
struct
STableMeta
{
...
...
@@ -91,7 +91,7 @@ typedef struct STableMetaInfo {
* 2. keep the vgroup index for multi-vnode insertion
*/
int32_t
vgroupIndex
;
char
name
[
TSDB_TABLE_FNAME_LEN
];
// (super) table name
SName
name
;
char
aliasName
[
TSDB_TABLE_NAME_LEN
];
// alias name of table specified in query sql
SArray
*
tagColList
;
// SArray<SColumn*>, involved tag columns
}
STableMetaInfo
;
...
...
@@ -142,7 +142,7 @@ typedef struct SCond {
}
SCond
;
typedef
struct
SJoinNode
{
char
table
Id
[
TSDB_TABLE_FNAME_LEN
];
char
table
Name
[
TSDB_TABLE_FNAME_LEN
];
uint64_t
uid
;
int16_t
tagColId
;
}
SJoinNode
;
...
...
@@ -176,7 +176,7 @@ typedef struct SParamInfo {
}
SParamInfo
;
typedef
struct
STableDataBlocks
{
char
tableName
[
TSDB_TABLE_FNAME_LEN
]
;
SName
tableName
;
int8_t
tsSource
;
// where does the UNIX timestamp come from, server or client
bool
ordered
;
// if current rows are ordered or not
int64_t
vgId
;
// virtual group id
...
...
@@ -254,7 +254,7 @@ typedef struct {
int8_t
submitSchema
;
// submit block is built with table schema
STagData
tagData
;
// NOTE: pTagData->data is used as a variant length array
char
**
pTableNameList
;
// all involved tableMeta list of current insert sql statement.
SName
**
pTableNameList
;
// all involved tableMeta list of current insert sql statement.
int32_t
numOfTables
;
SHashObj
*
pTableBlockHashList
;
// data block for each table
...
...
src/client/src/tscLocal.c
浏览文件 @
84313b70
...
...
@@ -569,10 +569,12 @@ static int32_t tscRebuildDDLForSubTable(SSqlObj *pSql, const char *tableName, ch
}
char
fullName
[
TSDB_TABLE_FNAME_LEN
*
2
]
=
{
0
};
extractDBName
(
pTableMetaInfo
->
name
,
fullName
);
tNameGetDbName
(
&
pTableMetaInfo
->
name
,
fullName
);
extractTableName
(
pMeta
->
sTableName
,
param
->
sTableName
);
snprintf
(
fullName
+
strlen
(
fullName
),
TSDB_TABLE_FNAME_LEN
-
strlen
(
fullName
),
".%s"
,
param
->
sTableName
);
extractTableName
(
pTableMetaInfo
->
name
,
param
->
buf
);
strncpy
(
param
->
buf
,
tNameGetTableName
(
&
pTableMetaInfo
->
name
),
TSDB_TABLE_NAME_LEN
);
param
->
pParentSql
=
pSql
;
param
->
pInterSql
=
pInterSql
;
...
...
@@ -602,6 +604,7 @@ static int32_t tscRebuildDDLForSubTable(SSqlObj *pSql, const char *tableName, ch
return
TSDB_CODE_TSC_ACTION_IN_PROGRESS
;
}
static
int32_t
tscRebuildDDLForNormalTable
(
SSqlObj
*
pSql
,
const
char
*
tableName
,
char
*
ddl
)
{
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
&
pSql
->
cmd
,
0
);
STableMetaInfo
*
pTableMetaInfo
=
tscGetMetaInfo
(
pQueryInfo
,
0
);
...
...
@@ -675,8 +678,7 @@ static int32_t tscProcessShowCreateTable(SSqlObj *pSql) {
STableMetaInfo
*
pTableMetaInfo
=
tscGetMetaInfo
(
pQueryInfo
,
0
);
assert
(
pTableMetaInfo
->
pTableMeta
!=
NULL
);
char
tableName
[
TSDB_TABLE_NAME_LEN
]
=
{
0
};
extractTableName
(
pTableMetaInfo
->
name
,
tableName
);
const
char
*
tableName
=
tNameGetTableName
(
&
pTableMetaInfo
->
name
);
char
*
result
=
(
char
*
)
calloc
(
1
,
TSDB_MAX_BINARY_LEN
);
int32_t
code
=
TSDB_CODE_SUCCESS
;
...
...
@@ -712,7 +714,9 @@ static int32_t tscProcessShowCreateDatabase(SSqlObj *pSql) {
free
(
pInterSql
);
return
TSDB_CODE_TSC_OUT_OF_MEMORY
;
}
extractTableName
(
pTableMetaInfo
->
name
,
param
->
buf
);
strncpy
(
param
->
buf
,
tNameGetTableName
(
&
pTableMetaInfo
->
name
),
TSDB_TABLE_NAME_LEN
);
param
->
pParentSql
=
pSql
;
param
->
pInterSql
=
pInterSql
;
param
->
fp
=
tscRebuildCreateDBStatement
;
...
...
src/client/src/tscParseInsert.c
浏览文件 @
84313b70
...
...
@@ -703,7 +703,7 @@ static int32_t doParseInsertStatement(SSqlCmd* pCmd, char **str, SParsedDataColI
STableDataBlocks
*
dataBuf
=
NULL
;
int32_t
ret
=
tscGetDataBlockFromList
(
pCmd
->
pTableBlockHashList
,
pTableMeta
->
id
.
uid
,
TSDB_DEFAULT_PAYLOAD_SIZE
,
sizeof
(
SSubmitBlk
),
tinfo
.
rowSize
,
pTableMetaInfo
->
name
,
pTableMeta
,
&
dataBuf
,
NULL
);
sizeof
(
SSubmitBlk
),
tinfo
.
rowSize
,
&
pTableMetaInfo
->
name
,
pTableMeta
,
&
dataBuf
,
NULL
);
if
(
ret
!=
TSDB_CODE_SUCCESS
)
{
return
ret
;
}
...
...
@@ -813,26 +813,26 @@ static int32_t tscCheckIfCreateTable(char **sqlstr, SSqlObj *pSql) {
tscAddEmptyMetaInfo
(
pQueryInfo
);
}
STableMetaInfo
*
pSTableMet
erMet
aInfo
=
tscGetMetaInfo
(
pQueryInfo
,
STABLE_INDEX
);
code
=
tscSetTableFullName
(
pSTableMet
erMet
aInfo
,
&
sToken
,
pSql
);
STableMetaInfo
*
pSTableMetaInfo
=
tscGetMetaInfo
(
pQueryInfo
,
STABLE_INDEX
);
code
=
tscSetTableFullName
(
pSTableMetaInfo
,
&
sToken
,
pSql
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
return
code
;
}
t
strncpy
(
pCmd
->
tagData
.
name
,
pSTableMeterMetaInfo
->
name
,
sizeof
(
pCmd
->
tagData
.
name
)
);
t
NameExtractFullName
(
&
pSTableMetaInfo
->
name
,
pCmd
->
tagData
.
name
);
pCmd
->
tagData
.
dataLen
=
0
;
code
=
tscGetTableMeta
(
pSql
,
pSTableMet
erMet
aInfo
);
code
=
tscGetTableMeta
(
pSql
,
pSTableMetaInfo
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
return
code
;
}
if
(
!
UTIL_TABLE_IS_SUPER_TABLE
(
pSTableMet
erMet
aInfo
))
{
if
(
!
UTIL_TABLE_IS_SUPER_TABLE
(
pSTableMetaInfo
))
{
return
tscInvalidSQLErrMsg
(
pCmd
->
payload
,
"create table only from super table is allowed"
,
sToken
.
z
);
}
SSchema
*
pTagSchema
=
tscGetTableTagSchema
(
pSTableMet
erMet
aInfo
->
pTableMeta
);
STableComInfo
tinfo
=
tscGetTableInfo
(
pSTableMet
erMet
aInfo
->
pTableMeta
);
SSchema
*
pTagSchema
=
tscGetTableTagSchema
(
pSTableMetaInfo
->
pTableMeta
);
STableComInfo
tinfo
=
tscGetTableInfo
(
pSTableMetaInfo
->
pTableMeta
);
index
=
0
;
sToken
=
tStrGetToken
(
sql
,
&
index
,
false
,
0
,
NULL
);
...
...
@@ -840,7 +840,7 @@ static int32_t tscCheckIfCreateTable(char **sqlstr, SSqlObj *pSql) {
SParsedDataColInfo
spd
=
{
0
};
uint8_t
numOfTags
=
tscGetNumOfTags
(
pSTableMet
erMet
aInfo
->
pTableMeta
);
uint8_t
numOfTags
=
tscGetNumOfTags
(
pSTableMetaInfo
->
pTableMeta
);
spd
.
numOfCols
=
numOfTags
;
// if specify some tags column
...
...
@@ -1465,7 +1465,7 @@ static void parseFileSendDataBlock(void *param, TAOS_RES *tres, int32_t numOfRow
STableDataBlocks
*
pTableDataBlock
=
NULL
;
int32_t
ret
=
tscGetDataBlockFromList
(
pCmd
->
pTableBlockHashList
,
pTableMeta
->
id
.
uid
,
TSDB_PAYLOAD_SIZE
,
sizeof
(
SSubmitBlk
),
tinfo
.
rowSize
,
pTableMetaInfo
->
name
,
pTableMeta
,
&
pTableDataBlock
,
NULL
);
tinfo
.
rowSize
,
&
pTableMetaInfo
->
name
,
pTableMeta
,
&
pTableDataBlock
,
NULL
);
if
(
ret
!=
TSDB_CODE_SUCCESS
)
{
pParentSql
->
res
.
code
=
TSDB_CODE_TSC_OUT_OF_MEMORY
;
goto
_error
;
...
...
src/client/src/tscPrepare.c
浏览文件 @
84313b70
...
...
@@ -707,7 +707,7 @@ static int insertStmtBindParam(STscStmt* stmt, TAOS_BIND* bind) {
int32_t
ret
=
tscGetDataBlockFromList
(
pCmd
->
pTableBlockHashList
,
pTableMeta
->
id
.
uid
,
TSDB_PAYLOAD_SIZE
,
sizeof
(
SSubmitBlk
),
pTableMeta
->
tableInfo
.
rowSize
,
pTableMetaInfo
->
name
,
pTableMeta
,
&
pBlock
,
NULL
);
pTableMeta
->
tableInfo
.
rowSize
,
&
pTableMetaInfo
->
name
,
pTableMeta
,
&
pBlock
,
NULL
);
if
(
ret
!=
0
)
{
// todo handle error
}
...
...
@@ -790,7 +790,7 @@ static int insertStmtExecute(STscStmt* stmt) {
int32_t
ret
=
tscGetDataBlockFromList
(
pCmd
->
pTableBlockHashList
,
pTableMeta
->
id
.
uid
,
TSDB_PAYLOAD_SIZE
,
sizeof
(
SSubmitBlk
),
pTableMeta
->
tableInfo
.
rowSize
,
pTableMetaInfo
->
name
,
pTableMeta
,
&
pBlock
,
NULL
);
pTableMeta
->
tableInfo
.
rowSize
,
&
pTableMetaInfo
->
name
,
pTableMeta
,
&
pBlock
,
NULL
);
assert
(
ret
==
0
);
pBlock
->
size
=
sizeof
(
SSubmitBlk
)
+
pCmd
->
batchSize
*
pBlock
->
rowSize
;
SSubmitBlk
*
pBlk
=
(
SSubmitBlk
*
)
pBlock
->
pData
;
...
...
src/client/src/tscSQLParser.c
浏览文件 @
84313b70
...
...
@@ -60,7 +60,7 @@ static int32_t setShowInfo(SSqlObj* pSql, SSqlInfo* pInfo);
static
char
*
getAccountId
(
SSqlObj
*
pSql
);
static
bool
has
(
SArray
*
pFieldList
,
int32_t
startIdx
,
const
char
*
name
);
static
void
getCurrentDBName
(
SSqlObj
*
pSql
,
SStrToken
*
pDBToken
);
static
char
*
getCurrentDBName
(
SSqlObj
*
pSql
);
static
bool
hasSpecifyDB
(
SStrToken
*
pTableName
);
static
bool
validateTableColumnInfo
(
SArray
*
pFieldList
,
SSqlCmd
*
pCmd
);
static
bool
validateTagParams
(
SArray
*
pTagsList
,
SArray
*
pFieldList
,
SSqlCmd
*
pCmd
);
...
...
@@ -272,8 +272,7 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) {
if
(
pInfo
->
type
==
TSDB_SQL_DROP_DB
)
{
assert
(
pInfo
->
pDCLInfo
->
nTokens
==
1
);
code
=
setObjFullName
(
pTableMetaInfo
->
name
,
getAccountId
(
pSql
),
pzName
,
NULL
,
NULL
);
code
=
tNameSetDbName
(
&
pTableMetaInfo
->
name
,
getAccountId
(
pSql
),
pzName
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
return
invalidSqlErrMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg2
);
}
...
...
@@ -287,13 +286,13 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) {
}
}
else
if
(
pInfo
->
type
==
TSDB_SQL_DROP_DNODE
)
{
pzName
->
n
=
strdequote
(
pzName
->
z
);
strncpy
(
p
TableMetaInfo
->
name
,
pzName
->
z
,
pzName
->
n
);
}
else
{
// drop user
strncpy
(
p
Cmd
->
payload
,
pzName
->
z
,
pzName
->
n
);
}
else
{
// drop user
/account
if
(
pzName
->
n
>=
TSDB_USER_LEN
)
{
return
invalidSqlErrMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg3
);
}
strncpy
(
p
TableMetaInfo
->
name
,
pzName
->
z
,
pzName
->
n
);
strncpy
(
p
Cmd
->
payload
,
pzName
->
z
,
pzName
->
n
);
}
break
;
...
...
@@ -307,7 +306,7 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) {
return
invalidSqlErrMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg
);
}
int32_t
ret
=
setObjFullName
(
pTableMetaInfo
->
name
,
getAccountId
(
pSql
),
pToken
,
NULL
,
NULL
);
int32_t
ret
=
tNameSetDbName
(
&
pTableMetaInfo
->
name
,
getAccountId
(
pSql
),
pToken
);
if
(
ret
!=
TSDB_CODE_SUCCESS
)
{
return
invalidSqlErrMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg
);
}
...
...
@@ -337,7 +336,7 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) {
return
invalidSqlErrMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg1
);
}
int32_t
ret
=
setObjFullName
(
pTableMetaInfo
->
name
,
getAccountId
(
pSql
),
&
(
pCreateDB
->
dbname
),
NULL
,
NULL
);
int32_t
ret
=
tNameSetDbName
(
&
pTableMetaInfo
->
name
,
getAccountId
(
pSql
),
&
(
pCreateDB
->
dbname
)
);
if
(
ret
!=
TSDB_CODE_SUCCESS
)
{
return
invalidSqlErrMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg2
);
}
...
...
@@ -878,47 +877,41 @@ int32_t parseSlidingClause(SSqlObj* pSql, SQueryInfo* pQueryInfo, SQuerySQL* pQu
return
TSDB_CODE_SUCCESS
;
}
int32_t
tscSetTableFullName
(
STableMetaInfo
*
pTableMetaInfo
,
SStrToken
*
p
z
TableName
,
SSqlObj
*
pSql
)
{
int32_t
tscSetTableFullName
(
STableMetaInfo
*
pTableMetaInfo
,
SStrToken
*
pTableName
,
SSqlObj
*
pSql
)
{
const
char
*
msg1
=
"name too long"
;
SSqlCmd
*
pCmd
=
&
pSql
->
cmd
;
int32_t
code
=
TSDB_CODE_SUCCESS
;
// backup the old name in pTableMetaInfo
char
oldName
[
TSDB_TABLE_FNAME_LEN
]
=
{
0
};
tstrncpy
(
oldName
,
pTableMetaInfo
->
name
,
tListLen
(
oldName
));
if
(
hasSpecifyDB
(
pTableName
))
{
// db has been specified in sql string so we ignore current db path
tNameSetAcctId
(
&
pTableMetaInfo
->
name
,
getAccountId
(
pSql
));
char
name
[
TSDB_TABLE_FNAME_LEN
]
=
{
0
};
strncpy
(
name
,
pTableName
->
z
,
pTableName
->
n
);
if
(
hasSpecifyDB
(
pzTableName
))
{
// db has been specified in sql string so we ignore current db path
code
=
setObjFullName
(
pTableMetaInfo
->
name
,
getAccountId
(
pSql
),
NULL
,
pzTableName
,
NULL
);
code
=
tNameFromString
(
&
pTableMetaInfo
->
name
,
name
,
T_NAME_DB
|
T_NAME_TABLE
);
if
(
code
!=
0
)
{
invalidSqlErrMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg1
);
return
invalidSqlErrMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg1
);
}
}
else
{
// get current DB name first, and then set it into path
SStrToken
t
=
{
0
};
getCurrentDBName
(
pSql
,
&
t
);
if
(
t
.
n
==
0
)
{
// current database not available or not specified
char
*
t
=
getCurrentDBName
(
pSql
);
assert
(
strlen
(
t
)
>
0
);
code
=
tNameFromString
(
&
pTableMetaInfo
->
name
,
t
,
T_NAME_ACCT
|
T_NAME_DB
);
if
(
code
!=
0
)
{
code
=
TSDB_CODE_TSC_DB_NOT_SELECTED
;
}
else
{
code
=
setObjFullName
(
pTableMetaInfo
->
name
,
NULL
,
&
t
,
pzTableName
,
NULL
);
char
name
[
TSDB_TABLE_FNAME_LEN
]
=
{
0
};
strncpy
(
name
,
pTableName
->
z
,
pTableName
->
n
);
code
=
tNameFromString
(
&
pTableMetaInfo
->
name
,
name
,
T_NAME_TABLE
);
if
(
code
!=
0
)
{
invalidSqlErrMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg1
);
code
=
invalidSqlErrMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg1
);
}
}
}
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
return
code
;
}
/*
* the old name exists and is not equalled to the new name. Release the table meta
* that are corresponding to the old name for the new table name.
*/
if
(
strlen
(
oldName
)
>
0
&&
strncasecmp
(
oldName
,
pTableMetaInfo
->
name
,
tListLen
(
pTableMetaInfo
->
name
))
!=
0
)
{
tscClearTableMetaInfo
(
pTableMetaInfo
);
}
return
TSDB_CODE_SUCCESS
;
return
code
;
}
static
bool
validateTableColumnInfo
(
SArray
*
pFieldList
,
SSqlCmd
*
pCmd
)
{
...
...
@@ -1218,9 +1211,8 @@ static bool has(SArray* pFieldList, int32_t startIdx, const char* name) {
static
char
*
getAccountId
(
SSqlObj
*
pSql
)
{
return
pSql
->
pTscObj
->
acctId
;
}
static
void
getCurrentDBName
(
SSqlObj
*
pSql
,
SStrToken
*
pDBToken
)
{
pDBToken
->
z
=
pSql
->
pTscObj
->
db
;
pDBToken
->
n
=
(
uint32_t
)
strlen
(
pSql
->
pTscObj
->
db
);
static
char
*
getCurrentDBName
(
SSqlObj
*
pSql
)
{
return
pSql
->
pTscObj
->
db
;
}
/* length limitation, strstr cannot be applied */
...
...
@@ -2617,7 +2609,7 @@ int32_t setShowInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) {
return
invalidSqlErrMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg1
);
}
int32_t
ret
=
setObjFullName
(
pTableMetaInfo
->
name
,
getAccountId
(
pSql
),
pDbPrefixToken
,
NULL
,
NULL
);
int32_t
ret
=
tNameSetDbName
(
&
pTableMetaInfo
->
name
,
getAccountId
(
pSql
),
pDbPrefixToken
);
if
(
ret
!=
TSDB_CODE_SUCCESS
)
{
return
invalidSqlErrMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg1
);
}
...
...
@@ -2898,7 +2890,7 @@ int32_t parseGroupbyClause(SQueryInfo* pQueryInfo, SArray* pList, SSqlCmd* pCmd)
STableMeta
*
pTableMeta
=
NULL
;
SSchema
*
pSchema
=
NULL
;
SSchema
s
=
t
sc
GetTbnameColumnSchema
();
SSchema
s
=
tGetTbnameColumnSchema
();
int32_t
tableIndex
=
COLUMN_INDEX_INITIAL_VAL
;
...
...
@@ -3421,6 +3413,7 @@ static int32_t getColumnQueryCondInfo(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSQ
static
int32_t
getJoinCondInfo
(
SSqlCmd
*
pCmd
,
SQueryInfo
*
pQueryInfo
,
tSQLExpr
*
pExpr
)
{
const
char
*
msg1
=
"invalid join query condition"
;
const
char
*
msg2
=
"invalid table name in join query"
;
const
char
*
msg3
=
"type of join columns must be identical"
;
const
char
*
msg4
=
"invalid column name in join condition"
;
...
...
@@ -3446,7 +3439,11 @@ static int32_t getJoinCondInfo(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSQLExpr*
pLeft
->
uid
=
pTableMetaInfo
->
pTableMeta
->
id
.
uid
;
pLeft
->
tagColId
=
pTagSchema1
->
colId
;
strcpy
(
pLeft
->
tableId
,
pTableMetaInfo
->
name
);
int32_t
code
=
tNameExtractFullName
(
&
pTableMetaInfo
->
name
,
pLeft
->
tableName
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
return
invalidSqlErrMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg2
);
}
index
=
(
SColumnIndex
)
COLUMN_INDEX_INITIALIZER
;
if
(
getColumnIndexByName
(
pCmd
,
&
pExpr
->
pRight
->
colInfo
,
pQueryInfo
,
&
index
)
!=
TSDB_CODE_SUCCESS
)
{
...
...
@@ -3458,7 +3455,11 @@ static int32_t getJoinCondInfo(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSQLExpr*
pRight
->
uid
=
pTableMetaInfo
->
pTableMeta
->
id
.
uid
;
pRight
->
tagColId
=
pTagSchema2
->
colId
;
strcpy
(
pRight
->
tableId
,
pTableMetaInfo
->
name
);
code
=
tNameExtractFullName
(
&
pTableMetaInfo
->
name
,
pRight
->
tableName
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
return
invalidSqlErrMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg2
);
}
if
(
pTagSchema1
->
type
!=
pTagSchema2
->
type
)
{
return
invalidSqlErrMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg3
);
...
...
@@ -4035,8 +4036,6 @@ static int32_t setTableCondForSTableQuery(SSqlCmd* pCmd, SQueryInfo* pQueryInfo,
SStringBuilder
sb1
;
memset
(
&
sb1
,
0
,
sizeof
(
sb1
));
taosStringBuilderAppendStringLen
(
&
sb1
,
QUERY_COND_REL_PREFIX_IN
,
QUERY_COND_REL_PREFIX_IN_LEN
);
char
db
[
TSDB_TABLE_FNAME_LEN
]
=
{
0
};
// remove the duplicated input table names
int32_t
num
=
0
;
char
*
tableNameString
=
taosStringBuilderGetResult
(
sb
,
NULL
);
...
...
@@ -4052,7 +4051,8 @@ static int32_t setTableCondForSTableQuery(SSqlCmd* pCmd, SQueryInfo* pQueryInfo,
}
num
=
j
;
char
*
name
=
extractDBName
(
pTableMetaInfo
->
name
,
db
);
char
name
[
TSDB_DB_NAME_LEN
]
=
{
0
};
tNameGetDbName
(
&
pTableMetaInfo
->
name
,
name
);
SStrToken
dbToken
=
{
.
type
=
TK_STRING
,
.
z
=
name
,
.
n
=
(
uint32_t
)
strlen
(
name
)
};
for
(
int32_t
i
=
0
;
i
<
num
;
++
i
)
{
...
...
@@ -6212,9 +6212,9 @@ int32_t doCheckForCreateFromStable(SSqlObj* pSql, SSqlInfo* pInfo) {
}
// get table meta from mnode
tstrncpy
(
pCreateTableInfo
->
tagdata
.
name
,
pStableMetaInfo
->
name
,
tListLen
(
pCreateTableInfo
->
tagdata
.
name
));
SArray
*
pList
=
pCreateTableInfo
->
pTagVals
;
code
=
tNameExtractFullName
(
&
pStableMetaInfo
->
name
,
pCreateTableInfo
->
tagdata
.
name
);
SArray
*
pList
=
pCreateTableInfo
->
pTagVals
;
code
=
tscGetTableMeta
(
pSql
,
pStableMetaInfo
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
return
code
;
...
...
@@ -6292,7 +6292,11 @@ int32_t doCheckForCreateFromStable(SSqlObj* pSql, SSqlInfo* pInfo) {
return
ret
;
}
pCreateTableInfo
->
fullname
=
strndup
(
pTableMetaInfo
->
name
,
TSDB_TABLE_FNAME_LEN
);
pCreateTableInfo
->
fullname
=
calloc
(
1
,
tNameLen
(
&
pTableMetaInfo
->
name
)
+
1
);
ret
=
tNameExtractFullName
(
&
pTableMetaInfo
->
name
,
pCreateTableInfo
->
fullname
);
if
(
ret
!=
TSDB_CODE_SUCCESS
)
{
return
invalidSqlErrMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg1
);
}
}
return
TSDB_CODE_SUCCESS
;
...
...
@@ -6539,7 +6543,7 @@ int32_t doCheckForQuery(SSqlObj* pSql, SQuerySQL* pQuerySql, int32_t index) {
// has no table alias name
if
(
memcmp
(
pTableItem
->
pz
,
p1
->
pVar
.
pz
,
p1
->
pVar
.
nLen
)
==
0
)
{
extractTableName
(
pTableMetaInfo1
->
name
,
pTableMetaInfo1
->
aliasName
);
strncpy
(
pTableMetaInfo1
->
aliasName
,
tNameGetTableName
(
&
pTableMetaInfo1
->
name
),
tListLen
(
pTableMetaInfo
->
aliasName
)
);
}
else
{
tstrncpy
(
pTableMetaInfo1
->
aliasName
,
p1
->
pVar
.
pz
,
sizeof
(
pTableMetaInfo1
->
aliasName
));
}
...
...
src/client/src/tscSchemaUtil.c
浏览文件 @
84313b70
...
...
@@ -106,6 +106,7 @@ STableMeta* tscCreateTableMetaFromMsg(STableMetaMsg* pTableMetaMsg) {
pTableMeta
->
sversion
=
pTableMetaMsg
->
sversion
;
pTableMeta
->
tversion
=
pTableMetaMsg
->
tversion
;
tstrncpy
(
pTableMeta
->
sTableName
,
pTableMetaMsg
->
sTableName
,
TSDB_TABLE_FNAME_LEN
);
memcpy
(
pTableMeta
->
schema
,
pTableMetaMsg
->
schema
,
schemaSize
);
...
...
src/client/src/tscServer.c
浏览文件 @
84313b70
此差异已折叠。
点击以展开。
src/client/src/tscSql.c
浏览文件 @
84313b70
...
...
@@ -995,7 +995,8 @@ static int tscParseTblNameList(SSqlObj *pSql, const char *tblNameList, int32_t t
return
code
;
}
if
(
payloadLen
+
strlen
(
pTableMetaInfo
->
name
)
+
128
>=
pCmd
->
allocSize
)
{
int32_t
xlen
=
tNameLen
(
&
pTableMetaInfo
->
name
);
if
(
payloadLen
+
xlen
+
128
>=
pCmd
->
allocSize
)
{
char
*
pNewMem
=
realloc
(
pCmd
->
payload
,
pCmd
->
allocSize
+
tblListLen
);
if
(
pNewMem
==
NULL
)
{
code
=
TSDB_CODE_TSC_OUT_OF_MEMORY
;
...
...
@@ -1008,7 +1009,9 @@ static int tscParseTblNameList(SSqlObj *pSql, const char *tblNameList, int32_t t
pMsg
=
pCmd
->
payload
;
}
payloadLen
+=
sprintf
(
pMsg
+
payloadLen
,
"%s,"
,
pTableMetaInfo
->
name
);
char
n
[
TSDB_TABLE_FNAME_LEN
]
=
{
0
};
tNameExtractFullName
(
&
pTableMetaInfo
->
name
,
n
);
payloadLen
+=
sprintf
(
pMsg
+
payloadLen
,
"%s,"
,
n
);
}
*
(
pMsg
+
payloadLen
)
=
'\0'
;
...
...
src/client/src/tscStream.c
浏览文件 @
84313b70
...
...
@@ -104,7 +104,7 @@ static void doLaunchQuery(void* param, TAOS_RES* tres, int32_t code) {
// failed to get table Meta or vgroup list, retry in 10sec.
if
(
code
==
TSDB_CODE_SUCCESS
)
{
tscTansformSQLFuncForSTableQuery
(
pQueryInfo
);
tscDebug
(
"%p stream:%p, start stream query on:%s"
,
pSql
,
pStream
,
pTableMetaInfo
->
name
);
tscDebug
(
"%p stream:%p, start stream query on:%s"
,
pSql
,
pStream
,
tNameGetTableName
(
&
pTableMetaInfo
->
name
)
);
pSql
->
fp
=
tscProcessStreamQueryCallback
;
pSql
->
fetchFp
=
tscProcessStreamQueryCallback
;
...
...
@@ -191,8 +191,9 @@ static void tscProcessStreamQueryCallback(void *param, TAOS_RES *tres, int numOf
STableMetaInfo
*
pTableMetaInfo
=
tscGetTableMetaInfoFromCmd
(
&
pStream
->
pSql
->
cmd
,
0
,
0
);
char
*
name
=
pTableMetaInfo
->
name
;
taosHashRemove
(
tscTableMetaInfo
,
name
,
strnlen
(
name
,
TSDB_TABLE_FNAME_LEN
));
assert
(
0
);
// char* name = pTableMetaInfo->name;
// taosHashRemove(tscTableMetaInfo, name, strnlen(name, TSDB_TABLE_FNAME_LEN));
pTableMetaInfo
->
vgroupList
=
tscVgroupInfoClear
(
pTableMetaInfo
->
vgroupList
);
tscSetRetryTimer
(
pStream
,
pStream
->
pSql
,
retryDelay
);
...
...
@@ -291,8 +292,8 @@ static void tscProcessStreamRetrieveResult(void *param, TAOS_RES *res, int numOf
pStream
->
stime
+=
1
;
}
tscDebug
(
"%p stream:%p, query on:%s, fetch result completed, fetched rows:%"
PRId64
,
pSql
,
pStream
,
pTableMetaInfo
->
name
,
pStream
->
numOfRes
);
//
tscDebug("%p stream:%p, query on:%s, fetch result completed, fetched rows:%" PRId64, pSql, pStream, pTableMetaInfo->name,
//
pStream->numOfRes);
tfree
(
pTableMetaInfo
->
pTableMeta
);
...
...
@@ -555,8 +556,8 @@ static void tscCreateStream(void *param, TAOS_RES *res, int code) {
taosTmrReset
(
tscProcessStreamTimer
,
(
int32_t
)
starttime
,
pStream
,
tscTmr
,
&
pStream
->
pTimer
);
tscDebug
(
"%p stream:%p is opened, query on:%s, interval:%"
PRId64
", sliding:%"
PRId64
", first launched in:%"
PRId64
", sql:%s"
,
pSql
,
pStream
,
pTableMetaInfo
->
name
,
pStream
->
interval
.
interval
,
pStream
->
interval
.
sliding
,
starttime
,
pSql
->
sqlstr
);
//
tscDebug("%p stream:%p is opened, query on:%s, interval:%" PRId64 ", sliding:%" PRId64 ", first launched in:%" PRId64 ", sql:%s", pSql,
//
pStream, pTableMetaInfo->name, pStream->interval.interval, pStream->interval.sliding, starttime, pSql->sqlstr);
}
void
tscSetStreamDestTable
(
SSqlStream
*
pStream
,
const
char
*
dstTable
)
{
...
...
src/client/src/tscSubquery.c
浏览文件 @
84313b70
...
...
@@ -483,7 +483,7 @@ static int32_t tscLaunchRealSubqueries(SSqlObj* pSql) {
size_t
numOfCols
=
taosArrayGetSize
(
pQueryInfo
->
colList
);
tscDebug
(
"%p subquery:%p tableIndex:%d, vgroupIndex:%d, type:%d, exprInfo:%"
PRIzu
", colList:%"
PRIzu
", fieldsInfo:%d, name:%s"
,
pSql
,
pNew
,
0
,
pTableMetaInfo
->
vgroupIndex
,
pQueryInfo
->
type
,
taosArrayGetSize
(
pQueryInfo
->
exprList
),
numOfCols
,
pQueryInfo
->
fieldsInfo
.
numOfOutput
,
pTableMetaInfo
->
name
);
numOfCols
,
pQueryInfo
->
fieldsInfo
.
numOfOutput
,
tNameGetTableName
(
&
pTableMetaInfo
->
name
)
);
}
//prepare the subqueries object failed, abort
...
...
@@ -674,7 +674,7 @@ static void issueTSCompQuery(SSqlObj* pSql, SJoinSupporter* pSupporter, SSqlObj*
"%p subquery:%p tableIndex:%d, vgroupIndex:%d, numOfVgroups:%d, type:%d, ts_comp query to retrieve timestamps, "
"numOfExpr:%"
PRIzu
", colList:%"
PRIzu
", numOfOutputFields:%d, name:%s"
,
pParent
,
pSql
,
0
,
pTableMetaInfo
->
vgroupIndex
,
pTableMetaInfo
->
vgroupList
->
numOfVgroups
,
pQueryInfo
->
type
,
tscSqlExprNumOfExprs
(
pQueryInfo
),
numOfCols
,
pQueryInfo
->
fieldsInfo
.
numOfOutput
,
pTableMetaInfo
->
name
);
tscSqlExprNumOfExprs
(
pQueryInfo
),
numOfCols
,
pQueryInfo
->
fieldsInfo
.
numOfOutput
,
tNameGetTableName
(
&
pTableMetaInfo
->
name
)
);
tscProcessSql
(
pSql
);
}
...
...
@@ -1534,7 +1534,7 @@ int32_t tscCreateJoinSubquery(SSqlObj *pSql, int16_t tableIndex, SJoinSupporter
"%p subquery:%p tableIndex:%d, vgroupIndex:%d, type:%d, transfer to tid_tag query to retrieve (tableId, tags), "
"exprInfo:%"
PRIzu
", colList:%"
PRIzu
", fieldsInfo:%d, tagIndex:%d, name:%s"
,
pSql
,
pNew
,
tableIndex
,
pTableMetaInfo
->
vgroupIndex
,
pNewQueryInfo
->
type
,
tscSqlExprNumOfExprs
(
pNewQueryInfo
),
numOfCols
,
pNewQueryInfo
->
fieldsInfo
.
numOfOutput
,
colIndex
.
columnIndex
,
pNewQueryInfo
->
pTableMetaInfo
[
0
]
->
name
);
numOfCols
,
pNewQueryInfo
->
fieldsInfo
.
numOfOutput
,
colIndex
.
columnIndex
,
tNameGetTableName
(
&
pNewQueryInfo
->
pTableMetaInfo
[
0
]
->
name
)
);
}
else
{
SSchema
colSchema
=
{.
type
=
TSDB_DATA_TYPE_BINARY
,
.
bytes
=
1
};
SColumnIndex
colIndex
=
{
0
,
PRIMARYKEY_TIMESTAMP_COL_INDEX
};
...
...
@@ -1569,7 +1569,7 @@ int32_t tscCreateJoinSubquery(SSqlObj *pSql, int16_t tableIndex, SJoinSupporter
"%p subquery:%p tableIndex:%d, vgroupIndex:%d, type:%u, transfer to ts_comp query to retrieve timestamps, "
"exprInfo:%"
PRIzu
", colList:%"
PRIzu
", fieldsInfo:%d, name:%s"
,
pSql
,
pNew
,
tableIndex
,
pTableMetaInfo
->
vgroupIndex
,
pNewQueryInfo
->
type
,
tscSqlExprNumOfExprs
(
pNewQueryInfo
),
numOfCols
,
pNewQueryInfo
->
fieldsInfo
.
numOfOutput
,
pNewQueryInfo
->
pTableMetaInfo
[
0
]
->
name
);
numOfCols
,
pNewQueryInfo
->
fieldsInfo
.
numOfOutput
,
tNameGetTableName
(
&
pNewQueryInfo
->
pTableMetaInfo
[
0
]
->
name
)
);
}
}
else
{
assert
(
0
);
...
...
@@ -2286,7 +2286,7 @@ static void multiVnodeInsertFinalize(void* param, TAOS_RES* tres, int numOfRows)
tscFreeQueryInfo
(
&
pSql
->
cmd
);
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetailSafely
(
&
pSql
->
cmd
,
0
);
STableMetaInfo
*
pMasterTableMetaInfo
=
tscGetTableMetaInfoFromCmd
(
&
pParentObj
->
cmd
,
pSql
->
cmd
.
clauseIndex
,
0
);
tscAddTableMetaInfo
(
pQueryInfo
,
pMasterTableMetaInfo
->
name
,
NULL
,
NULL
,
NULL
,
NULL
);
tscAddTableMetaInfo
(
pQueryInfo
,
&
pMasterTableMetaInfo
->
name
,
NULL
,
NULL
,
NULL
,
NULL
);
tscDebug
(
"%p, failed sub:%d, %p"
,
pParentObj
,
i
,
pSql
);
}
...
...
@@ -2297,7 +2297,8 @@ static void multiVnodeInsertFinalize(void* param, TAOS_RES* tres, int numOfRows)
tscDebug
(
"%p cleanup %d tableMeta in hashTable"
,
pParentObj
,
pParentObj
->
cmd
.
numOfTables
);
for
(
int32_t
i
=
0
;
i
<
pParentObj
->
cmd
.
numOfTables
;
++
i
)
{
char
*
name
=
pParentObj
->
cmd
.
pTableNameList
[
i
];
char
name
[
TSDB_TABLE_FNAME_LEN
]
=
{
0
};
tNameExtractFullName
(
pParentObj
->
cmd
.
pTableNameList
[
i
],
name
);
taosHashRemove
(
tscTableMetaInfo
,
name
,
strnlen
(
name
,
TSDB_TABLE_FNAME_LEN
));
}
...
...
src/client/src/tscUtil.c
浏览文件 @
84313b70
...
...
@@ -89,21 +89,6 @@ bool tscQueryTags(SQueryInfo* pQueryInfo) {
return
true
;
}
// todo refactor, extract methods and move the common module
void
tscGetDBInfoFromTableFullName
(
char
*
tableId
,
char
*
db
)
{
char
*
st
=
strstr
(
tableId
,
TS_PATH_DELIMITER
);
if
(
st
!=
NULL
)
{
char
*
end
=
strstr
(
st
+
1
,
TS_PATH_DELIMITER
);
if
(
end
!=
NULL
)
{
memcpy
(
db
,
tableId
,
(
end
-
tableId
));
db
[
end
-
tableId
]
=
0
;
return
;
}
}
db
[
0
]
=
0
;
}
bool
tscIsTwoStageSTableQuery
(
SQueryInfo
*
pQueryInfo
,
int32_t
tableIndex
)
{
if
(
pQueryInfo
==
NULL
)
{
return
false
;
...
...
@@ -606,15 +591,13 @@ int32_t tscCopyDataBlockToPayload(SSqlObj* pSql, STableDataBlocks* pDataBlock) {
// todo refactor
// set the correct table meta object, the table meta has been locked in pDataBlocks, so it must be in the cache
if
(
pTableMetaInfo
->
pTableMeta
!=
pDataBlock
->
pTableMeta
)
{
t
strncpy
(
pTableMetaInfo
->
name
,
pDataBlock
->
tableName
,
sizeof
(
pTableMetaInfo
->
name
)
);
t
NameAssign
(
&
pTableMetaInfo
->
name
,
&
pDataBlock
->
tableName
);
if
(
pTableMetaInfo
->
pTableMeta
!=
NULL
)
{
tfree
(
pTableMetaInfo
->
pTableMeta
);
}
pTableMetaInfo
->
pTableMeta
=
tscTableMetaDup
(
pDataBlock
->
pTableMeta
);
}
else
{
assert
(
strncmp
(
pTableMetaInfo
->
name
,
pDataBlock
->
tableName
,
tListLen
(
pDataBlock
->
tableName
))
==
0
);
}
/*
...
...
@@ -649,7 +632,7 @@ int32_t tscCopyDataBlockToPayload(SSqlObj* pSql, STableDataBlocks* pDataBlock) {
* @param dataBlocks
* @return
*/
int32_t
tscCreateDataBlock
(
size_t
initialSize
,
int32_t
rowSize
,
int32_t
startOffset
,
const
char
*
name
,
int32_t
tscCreateDataBlock
(
size_t
initialSize
,
int32_t
rowSize
,
int32_t
startOffset
,
SName
*
name
,
STableMeta
*
pTableMeta
,
STableDataBlocks
**
dataBlocks
)
{
STableDataBlocks
*
dataBuf
=
(
STableDataBlocks
*
)
calloc
(
1
,
sizeof
(
STableDataBlocks
));
if
(
dataBuf
==
NULL
)
{
...
...
@@ -677,7 +660,7 @@ int32_t tscCreateDataBlock(size_t initialSize, int32_t rowSize, int32_t startOff
dataBuf
->
size
=
startOffset
;
dataBuf
->
tsSource
=
-
1
;
t
strncpy
(
dataBuf
->
tableName
,
name
,
sizeof
(
dataBuf
->
tableName
)
);
t
NameAssign
(
&
dataBuf
->
tableName
,
name
);
//Here we keep the tableMeta to avoid it to be remove by other threads.
dataBuf
->
pTableMeta
=
tscTableMetaDup
(
pTableMeta
);
...
...
@@ -687,8 +670,8 @@ int32_t tscCreateDataBlock(size_t initialSize, int32_t rowSize, int32_t startOff
return
TSDB_CODE_SUCCESS
;
}
int32_t
tscGetDataBlockFromList
(
SHashObj
*
pHashList
,
int64_t
id
,
int32_t
size
,
int32_t
startOffset
,
int32_t
rowSize
,
const
char
*
tableId
,
STableMeta
*
pTableMeta
,
STableDataBlocks
**
dataBlocks
,
SArray
*
pBlockList
)
{
int32_t
tscGetDataBlockFromList
(
SHashObj
*
pHashList
,
int64_t
id
,
int32_t
size
,
int32_t
startOffset
,
int32_t
rowSize
,
SName
*
name
,
STableMeta
*
pTableMeta
,
STableDataBlocks
**
dataBlocks
,
SArray
*
pBlockList
)
{
*
dataBlocks
=
NULL
;
STableDataBlocks
**
t1
=
(
STableDataBlocks
**
)
taosHashGet
(
pHashList
,
(
const
char
*
)
&
id
,
sizeof
(
id
));
if
(
t1
!=
NULL
)
{
...
...
@@ -696,7 +679,7 @@ int32_t tscGetDataBlockFromList(SHashObj* pHashList, int64_t id, int32_t size, i
}
if
(
*
dataBlocks
==
NULL
)
{
int32_t
ret
=
tscCreateDataBlock
((
size_t
)
size
,
rowSize
,
startOffset
,
tableId
,
pTableMeta
,
dataBlocks
);
int32_t
ret
=
tscCreateDataBlock
((
size_t
)
size
,
rowSize
,
startOffset
,
name
,
pTableMeta
,
dataBlocks
);
if
(
ret
!=
TSDB_CODE_SUCCESS
)
{
return
ret
;
}
...
...
@@ -797,7 +780,7 @@ static void extractTableNameList(SSqlCmd* pCmd, bool freeBlockMap) {
int32_t
i
=
0
;
while
(
p1
)
{
STableDataBlocks
*
pBlocks
=
*
p1
;
pCmd
->
pTableNameList
[
i
++
]
=
strndup
(
pBlocks
->
tableName
,
TSDB_TABLE_FNAME_LEN
);
pCmd
->
pTableNameList
[
i
++
]
=
tNameDup
(
&
pBlocks
->
tableName
);
p1
=
taosHashIterate
(
pCmd
->
pTableBlockHashList
,
p1
);
}
...
...
@@ -822,7 +805,7 @@ int32_t tscMergeTableDataBlocks(SSqlObj* pSql, bool freeBlockMap) {
STableDataBlocks
*
dataBuf
=
NULL
;
int32_t
ret
=
tscGetDataBlockFromList
(
pVnodeDataBlockHashList
,
pOneTableBlock
->
vgId
,
TSDB_PAYLOAD_SIZE
,
INSERT_HEAD_SIZE
,
0
,
pOneTableBlock
->
tableName
,
pOneTableBlock
->
pTableMeta
,
&
dataBuf
,
pVnodeDataBlockList
);
INSERT_HEAD_SIZE
,
0
,
&
pOneTableBlock
->
tableName
,
pOneTableBlock
->
pTableMeta
,
&
dataBuf
,
pVnodeDataBlockList
);
if
(
ret
!=
TSDB_CODE_SUCCESS
)
{
tscError
(
"%p failed to prepare the data block buffer for merging table data, code:%d"
,
pSql
,
ret
);
taosHashCleanup
(
pVnodeDataBlockHashList
);
...
...
@@ -855,8 +838,8 @@ int32_t tscMergeTableDataBlocks(SSqlObj* pSql, bool freeBlockMap) {
tscSortRemoveDataBlockDupRows
(
pOneTableBlock
);
char
*
ekey
=
(
char
*
)
pBlocks
->
data
+
pOneTableBlock
->
rowSize
*
(
pBlocks
->
numOfRows
-
1
);
tscDebug
(
"%p name:%s,
sid:%d rows:%d sversion:%d skey:%"
PRId64
", ekey:%"
PRId64
,
pSql
,
pOneTableBlock
->
tableName
,
tscDebug
(
"%p name:%s,
name:%d rows:%d sversion:%d skey:%"
PRId64
", ekey:%"
PRId64
,
pSql
,
tNameGetTableName
(
&
pOneTableBlock
->
tableName
)
,
pBlocks
->
tid
,
pBlocks
->
numOfRows
,
pBlocks
->
sversion
,
GET_INT64_VAL
(
pBlocks
->
data
),
GET_INT64_VAL
(
ekey
));
int32_t
len
=
pBlocks
->
numOfRows
*
(
pOneTableBlock
->
rowSize
+
expandSize
)
+
sizeof
(
STColumn
)
*
tscGetNumOfColumns
(
pOneTableBlock
->
pTableMeta
);
...
...
@@ -1304,7 +1287,7 @@ SColumn* tscColumnClone(const SColumn* src) {
dst
->
colIndex
=
src
->
colIndex
;
dst
->
numOfFilters
=
src
->
numOfFilters
;
dst
->
filterInfo
=
t
scFilterInfoClone
(
src
->
filterInfo
,
src
->
numOfFilters
);
dst
->
filterInfo
=
t
FilterInfoDup
(
src
->
filterInfo
,
src
->
numOfFilters
);
return
dst
;
}
...
...
@@ -1844,7 +1827,7 @@ void clearAllTableMetaInfo(SQueryInfo* pQueryInfo) {
tfree
(
pQueryInfo
->
pTableMetaInfo
);
}
STableMetaInfo
*
tscAddTableMetaInfo
(
SQueryInfo
*
pQueryInfo
,
const
char
*
name
,
STableMeta
*
pTableMeta
,
STableMetaInfo
*
tscAddTableMetaInfo
(
SQueryInfo
*
pQueryInfo
,
SName
*
name
,
STableMeta
*
pTableMeta
,
SVgroupsInfo
*
vgroupList
,
SArray
*
pTagCols
,
SArray
*
pVgroupTables
)
{
void
*
pAlloc
=
realloc
(
pQueryInfo
->
pTableMetaInfo
,
(
pQueryInfo
->
numOfTables
+
1
)
*
POINTER_BYTES
);
if
(
pAlloc
==
NULL
)
{
...
...
@@ -1862,7 +1845,7 @@ STableMetaInfo* tscAddTableMetaInfo(SQueryInfo* pQueryInfo, const char* name, ST
pQueryInfo
->
pTableMetaInfo
[
pQueryInfo
->
numOfTables
]
=
pTableMetaInfo
;
if
(
name
!=
NULL
)
{
t
strncpy
(
pTableMetaInfo
->
name
,
name
,
sizeof
(
pTableMetaInfo
->
name
)
);
t
NameAssign
(
&
pTableMetaInfo
->
name
,
name
);
}
pTableMetaInfo
->
pTableMeta
=
pTableMeta
;
...
...
@@ -1959,7 +1942,7 @@ SSqlObj* createSimpleSubObj(SSqlObj* pSql, __async_cb_func_t fp, void* param, in
assert
(
pSql
->
cmd
.
clauseIndex
==
0
);
STableMetaInfo
*
pMasterTableMetaInfo
=
tscGetTableMetaInfoFromCmd
(
&
pSql
->
cmd
,
pSql
->
cmd
.
clauseIndex
,
0
);
tscAddTableMetaInfo
(
pQueryInfo
,
pMasterTableMetaInfo
->
name
,
NULL
,
NULL
,
NULL
,
NULL
);
tscAddTableMetaInfo
(
pQueryInfo
,
&
pMasterTableMetaInfo
->
name
,
NULL
,
NULL
,
NULL
,
NULL
);
registerSqlObj
(
pNew
);
return
pNew
;
...
...
@@ -2115,27 +2098,26 @@ SSqlObj* createSubqueryObj(SSqlObj* pSql, int16_t tableIndex, __async_cb_func_t
pNew
->
param
=
param
;
pNew
->
maxRetry
=
TSDB_MAX_REPLICA
;
char
*
name
=
pTableMetaInfo
->
name
;
STableMetaInfo
*
pFinalInfo
=
NULL
;
if
(
pPrevSql
==
NULL
)
{
STableMeta
*
pTableMeta
=
tscTableMetaDup
(
pTableMetaInfo
->
pTableMeta
);
assert
(
pTableMeta
!=
NULL
);
pFinalInfo
=
tscAddTableMetaInfo
(
pNewQueryInfo
,
name
,
pTableMeta
,
pTableMetaInfo
->
vgroupList
,
pFinalInfo
=
tscAddTableMetaInfo
(
pNewQueryInfo
,
&
pTableMetaInfo
->
name
,
pTableMeta
,
pTableMetaInfo
->
vgroupList
,
pTableMetaInfo
->
tagColList
,
pTableMetaInfo
->
pVgroupTables
);
}
else
{
// transfer the ownership of pTableMeta to the newly create sql object.
STableMetaInfo
*
pPrevInfo
=
tscGetTableMetaInfoFromCmd
(
&
pPrevSql
->
cmd
,
pPrevSql
->
cmd
.
clauseIndex
,
0
);
STableMeta
*
pPrevTableMeta
=
tscTableMetaDup
(
pPrevInfo
->
pTableMeta
);
SVgroupsInfo
*
pVgroupsInfo
=
pPrevInfo
->
vgroupList
;
pFinalInfo
=
tscAddTableMetaInfo
(
pNewQueryInfo
,
name
,
pPrevTableMeta
,
pVgroupsInfo
,
pTableMetaInfo
->
tagColList
,
pFinalInfo
=
tscAddTableMetaInfo
(
pNewQueryInfo
,
&
pTableMetaInfo
->
name
,
pPrevTableMeta
,
pVgroupsInfo
,
pTableMetaInfo
->
tagColList
,
pTableMetaInfo
->
pVgroupTables
);
}
// this case cannot be happened
if
(
pFinalInfo
->
pTableMeta
==
NULL
)
{
tscError
(
"%p new subquery failed since no tableMeta, name:%s"
,
pSql
,
name
);
tscError
(
"%p new subquery failed since no tableMeta, name:%s"
,
pSql
,
tNameGetTableName
(
&
pTableMetaInfo
->
name
)
);
if
(
pPrevSql
!=
NULL
)
{
// pass the previous error to client
assert
(
pPrevSql
->
res
.
code
!=
TSDB_CODE_SUCCESS
);
...
...
@@ -2160,7 +2142,7 @@ SSqlObj* createSubqueryObj(SSqlObj* pSql, int16_t tableIndex, __async_cb_func_t
"%p new subquery:%p, tableIndex:%d, vgroupIndex:%d, type:%d, exprInfo:%"
PRIzu
", colList:%"
PRIzu
","
"fieldInfo:%d, name:%s, qrang:%"
PRId64
" - %"
PRId64
" order:%d, limit:%"
PRId64
,
pSql
,
pNew
,
tableIndex
,
pTableMetaInfo
->
vgroupIndex
,
pNewQueryInfo
->
type
,
tscSqlExprNumOfExprs
(
pNewQueryInfo
),
size
,
pNewQueryInfo
->
fieldsInfo
.
numOfOutput
,
pFinalInfo
->
name
,
pNewQueryInfo
->
window
.
skey
,
size
,
pNewQueryInfo
->
fieldsInfo
.
numOfOutput
,
tNameGetTableName
(
&
pFinalInfo
->
name
)
,
pNewQueryInfo
->
window
.
skey
,
pNewQueryInfo
->
window
.
ekey
,
pNewQueryInfo
->
order
.
order
,
pNewQueryInfo
->
limit
.
limit
);
tscPrintSelectClause
(
pNew
,
0
);
...
...
src/common/inc/tname.h
浏览文件 @
84313b70
...
...
@@ -21,6 +21,20 @@ typedef struct SColumnInfoData {
void
*
pData
;
// the corresponding block data in memory
}
SColumnInfoData
;
#define TSDB_DB_NAME_T 1
#define TSDB_TABLE_NAME_T 2
#define T_NAME_ACCT 0x1u
#define T_NAME_DB 0x2u
#define T_NAME_TABLE 0x4u
typedef
struct
SName
{
uint8_t
type
;
//db_name_t, table_name_t
char
acctId
[
TSDB_ACCT_ID_LEN
];
char
dbname
[
TSDB_DB_NAME_LEN
];
char
tname
[
TSDB_TABLE_NAME_LEN
];
}
SName
;
void
extractTableName
(
const
char
*
tableId
,
char
*
name
);
char
*
extractDBName
(
const
char
*
tableId
,
char
*
name
);
...
...
@@ -35,9 +49,9 @@ SSchema tGetUserSpecifiedColumnSchema(tVariant* pVal, SStrToken* exprStr, const
bool
tscValidateTableNameLength
(
size_t
len
);
SColumnFilterInfo
*
t
scFilterInfoClone
(
const
SColumnFilterInfo
*
src
,
int32_t
numOfFilters
);
SColumnFilterInfo
*
t
FilterInfoDup
(
const
SColumnFilterInfo
*
src
,
int32_t
numOfFilters
);
SSchema
t
sc
GetTbnameColumnSchema
();
SSchema
tGetTbnameColumnSchema
();
/**
* check if the schema is valid or not, including following aspects:
...
...
@@ -51,6 +65,28 @@ SSchema tscGetTbnameColumnSchema();
* @param numOfCols
* @return
*/
bool
isValidSchema
(
struct
SSchema
*
pSchema
,
int32_t
numOfCols
,
int32_t
numOfTags
);
bool
tIsValidSchema
(
struct
SSchema
*
pSchema
,
int32_t
numOfCols
,
int32_t
numOfTags
);
int32_t
tNameExtractFullName
(
const
SName
*
name
,
char
*
dst
);
int32_t
tNameLen
(
const
SName
*
name
);
SName
*
tNameDup
(
const
SName
*
name
);
bool
tIsValidName
(
const
SName
*
name
);
const
char
*
tNameGetTableName
(
const
SName
*
name
);
int32_t
tNameGetDbName
(
const
SName
*
name
,
char
*
dst
);
int32_t
tNameGetFullDbName
(
const
SName
*
name
,
char
*
dst
);
bool
tNameIsEmpty
(
const
SName
*
name
);
void
tNameAssign
(
SName
*
dst
,
const
SName
*
src
);
int32_t
tNameFromString
(
SName
*
dst
,
const
char
*
str
,
uint32_t
type
);
int32_t
tNameSetAcctId
(
SName
*
dst
,
const
char
*
acct
);
int32_t
tNameSetDbName
(
SName
*
dst
,
const
char
*
acct
,
SStrToken
*
dbToken
);
#endif // TDENGINE_NAME_H
src/common/src/tname.c
浏览文件 @
84313b70
...
...
@@ -3,31 +3,12 @@
#include "tname.h"
#include "tstoken.h"
#include "ttokendef.h"
#include "tvariant.h"
#define VALIDNUMOFCOLS(x) ((x) >= TSDB_MIN_COLUMNS && (x) <= TSDB_MAX_COLUMNS)
#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
)
{
while
(
*
input
!=
0
&&
*
input
++
!=
delim
)
{
};
}
return
input
;
}
UNUSED_FUNC
static
FORCE_INLINE
size_t
copy
(
char
*
dst
,
const
char
*
src
,
char
delimiter
)
{
size_t
len
=
0
;
while
(
*
src
!=
delimiter
&&
*
src
!=
0
)
{
*
dst
++
=
*
src
++
;
len
++
;
}
return
len
;
}
#define VALID_NAME_TYPE(x) ((x) == TSDB_DB_NAME_T || (x) == TSDB_TABLE_NAME_T)
void
extractTableName
(
const
char
*
tableId
,
char
*
name
)
{
size_t
s1
=
strcspn
(
tableId
,
&
TS_PATH_DELIMITER
[
0
]);
...
...
@@ -85,7 +66,7 @@ bool tscValidateTableNameLength(size_t len) {
return
len
<
TSDB_TABLE_NAME_LEN
;
}
SColumnFilterInfo
*
t
scFilterInfoClone
(
const
SColumnFilterInfo
*
src
,
int32_t
numOfFilters
)
{
SColumnFilterInfo
*
t
FilterInfoDup
(
const
SColumnFilterInfo
*
src
,
int32_t
numOfFilters
)
{
if
(
numOfFilters
==
0
)
{
assert
(
src
==
NULL
);
return
NULL
;
...
...
@@ -200,7 +181,7 @@ void extractTableNameFromToken(SStrToken* pToken, SStrToken* pTable) {
}
}
SSchema
t
sc
GetTbnameColumnSchema
()
{
SSchema
tGetTbnameColumnSchema
()
{
struct
SSchema
s
=
{
.
colId
=
TSDB_TBNAME_COLUMN_INDEX
,
.
type
=
TSDB_DATA_TYPE_BINARY
,
...
...
@@ -248,7 +229,7 @@ static bool doValidateSchema(SSchema* pSchema, int32_t numOfCols, int32_t maxLen
return
rowLen
<=
maxLen
;
}
bool
i
sValidSchema
(
struct
SSchema
*
pSchema
,
int32_t
numOfCols
,
int32_t
numOfTags
)
{
bool
tI
sValidSchema
(
struct
SSchema
*
pSchema
,
int32_t
numOfCols
,
int32_t
numOfTags
)
{
if
(
!
VALIDNUMOFCOLS
(
numOfCols
))
{
return
false
;
}
...
...
@@ -272,3 +253,179 @@ bool isValidSchema(struct SSchema* pSchema, int32_t numOfCols, int32_t numOfTags
return
true
;
}
int32_t
tNameExtractFullName
(
const
SName
*
name
,
char
*
dst
)
{
assert
(
name
!=
NULL
&&
dst
!=
NULL
);
// invalid full name format, abort
if
(
!
tIsValidName
(
name
))
{
return
-
1
;
}
int32_t
len
=
snprintf
(
dst
,
TSDB_ACCT_ID_LEN
+
1
+
TSDB_DB_NAME_LEN
,
"%s.%s"
,
name
->
acctId
,
name
->
dbname
);
size_t
tnameLen
=
strlen
(
name
->
tname
);
if
(
tnameLen
>
0
)
{
assert
(
name
->
type
==
TSDB_TABLE_NAME_T
);
dst
[
len
]
=
TS_PATH_DELIMITER
[
0
];
memcpy
(
dst
+
len
+
1
,
name
->
tname
,
tnameLen
);
dst
[
len
+
tnameLen
+
1
]
=
0
;
}
return
0
;
}
int32_t
tNameLen
(
const
SName
*
name
)
{
assert
(
name
!=
NULL
);
int32_t
len
=
(
int32_t
)
strlen
(
name
->
acctId
);
int32_t
len1
=
(
int32_t
)
strlen
(
name
->
dbname
);
int32_t
len2
=
(
int32_t
)
strlen
(
name
->
tname
);
if
(
name
->
type
==
TSDB_DB_NAME_T
)
{
assert
(
len2
==
0
);
return
len
+
len1
+
TS_PATH_DELIMITER_LEN
;
}
else
{
assert
(
len2
>
0
);
return
len
+
len1
+
len2
+
TS_PATH_DELIMITER_LEN
*
2
;
}
}
bool
tIsValidName
(
const
SName
*
name
)
{
assert
(
name
!=
NULL
);
if
(
!
VALID_NAME_TYPE
(
name
->
type
))
{
return
false
;
}
if
(
strlen
(
name
->
acctId
)
<=
0
)
{
return
false
;
}
if
(
name
->
type
==
TSDB_DB_NAME_T
)
{
return
strlen
(
name
->
dbname
)
>
0
;
}
else
{
return
strlen
(
name
->
dbname
)
>
0
&&
strlen
(
name
->
tname
)
>
0
;
}
}
SName
*
tNameDup
(
const
SName
*
name
)
{
assert
(
name
!=
NULL
);
SName
*
p
=
calloc
(
1
,
sizeof
(
SName
));
memcpy
(
p
,
name
,
sizeof
(
SName
));
return
p
;
}
int32_t
tNameGetDbName
(
const
SName
*
name
,
char
*
dst
)
{
assert
(
name
!=
NULL
&&
dst
!=
NULL
);
strncpy
(
dst
,
name
->
dbname
,
tListLen
(
name
->
dbname
));
return
0
;
}
int32_t
tNameGetFullDbName
(
const
SName
*
name
,
char
*
dst
)
{
assert
(
name
!=
NULL
&&
dst
!=
NULL
);
snprintf
(
dst
,
TSDB_ACCT_ID_LEN
+
TS_PATH_DELIMITER_LEN
+
TSDB_DB_NAME_LEN
,
"%s.%s"
,
name
->
acctId
,
name
->
dbname
);
return
0
;
}
bool
tNameIsEmpty
(
const
SName
*
name
)
{
assert
(
name
!=
NULL
);
return
name
->
type
==
0
||
strlen
(
name
->
acctId
)
<=
0
;
}
const
char
*
tNameGetTableName
(
const
SName
*
name
)
{
assert
(
name
!=
NULL
&&
name
->
type
==
TSDB_TABLE_NAME_T
);
return
&
name
->
tname
[
0
];
}
void
tNameAssign
(
SName
*
dst
,
const
SName
*
src
)
{
memcpy
(
dst
,
src
,
sizeof
(
SName
));
}
int32_t
tNameSetDbName
(
SName
*
dst
,
const
char
*
acct
,
SStrToken
*
dbToken
)
{
assert
(
dst
!=
NULL
&&
dbToken
!=
NULL
&&
acct
!=
NULL
);
// too long account id or too long db name
if
(
strlen
(
acct
)
>=
tListLen
(
dst
->
acctId
)
||
dbToken
->
n
>=
tListLen
(
dst
->
dbname
))
{
return
-
1
;
}
dst
->
type
=
TSDB_DB_NAME_T
;
tstrncpy
(
dst
->
acctId
,
acct
,
tListLen
(
dst
->
acctId
));
tstrncpy
(
dst
->
dbname
,
dbToken
->
z
,
dbToken
->
n
+
1
);
return
0
;
}
int32_t
tNameSetAcctId
(
SName
*
dst
,
const
char
*
acct
)
{
assert
(
dst
!=
NULL
&&
acct
!=
NULL
);
// too long account id or too long db name
if
(
strlen
(
acct
)
>=
tListLen
(
dst
->
acctId
))
{
return
-
1
;
}
tstrncpy
(
dst
->
acctId
,
acct
,
tListLen
(
dst
->
acctId
));
return
0
;
}
int32_t
tNameFromString
(
SName
*
dst
,
const
char
*
str
,
uint32_t
type
)
{
assert
(
dst
!=
NULL
&&
str
!=
NULL
&&
strlen
(
str
)
>
0
);
char
*
p
=
NULL
;
if
((
type
&
T_NAME_ACCT
)
==
T_NAME_ACCT
)
{
p
=
strstr
(
str
,
TS_PATH_DELIMITER
);
if
(
p
==
NULL
)
{
return
-
1
;
}
int32_t
len
=
p
-
str
;
// too long account id or too long db name
if
(
len
>=
tListLen
(
dst
->
acctId
)
||
len
==
0
)
{
return
-
1
;
}
memcpy
(
dst
->
acctId
,
str
,
len
);
dst
->
acctId
[
len
]
=
0
;
}
if
((
type
&
T_NAME_DB
)
==
T_NAME_DB
)
{
dst
->
type
=
TSDB_DB_NAME_T
;
char
*
start
=
(
char
*
)((
p
==
NULL
)
?
str
:
(
p
+
1
));
int32_t
len
=
0
;
p
=
strstr
(
start
,
TS_PATH_DELIMITER
);
if
(
p
==
NULL
)
{
len
=
strlen
(
start
);
}
else
{
len
=
p
-
start
;
}
// too long account id or too long db name
if
(
len
>=
tListLen
(
dst
->
dbname
)
||
len
==
0
)
{
return
-
1
;
}
memcpy
(
dst
->
dbname
,
start
,
len
);
dst
->
dbname
[
len
]
=
0
;
}
if
((
type
&
T_NAME_TABLE
)
==
T_NAME_TABLE
)
{
dst
->
type
=
TSDB_TABLE_NAME_T
;
char
*
start
=
(
char
*
)
((
p
==
NULL
)
?
str
:
(
p
+
1
));
int32_t
len
=
strlen
(
start
);
// too long account id or too long db name
if
(
len
>=
tListLen
(
dst
->
tname
)
||
len
==
0
)
{
return
-
1
;
}
memcpy
(
dst
->
tname
,
start
,
len
);
dst
->
tname
[
len
]
=
0
;
}
return
0
;
}
src/inc/taosmsg.h
浏览文件 @
84313b70
...
...
@@ -268,8 +268,7 @@ typedef struct {
typedef
struct
{
int32_t
len
;
// one create table message
char
tableFname
[
TSDB_TABLE_FNAME_LEN
];
char
db
[
TSDB_ACCT_ID_LEN
+
TSDB_DB_NAME_LEN
];
char
tableName
[
TSDB_TABLE_FNAME_LEN
];
int8_t
igExists
;
int8_t
getMeta
;
int16_t
numOfTags
;
...
...
@@ -285,7 +284,7 @@ typedef struct {
}
SCMCreateTableMsg
;
typedef
struct
{
char
tableF
name
[
TSDB_TABLE_FNAME_LEN
];
char
name
[
TSDB_TABLE_FNAME_LEN
];
int8_t
igNotExists
;
}
SCMDropTableMsg
;
...
...
src/mnode/inc/mnodeDb.h
浏览文件 @
84313b70
...
...
@@ -32,7 +32,7 @@ int32_t mnodeInitDbs();
void
mnodeCleanupDbs
();
int64_t
mnodeGetDbNum
();
SDbObj
*
mnodeGetDb
(
char
*
db
);
SDbObj
*
mnodeGetDbByTable
Id
(
char
*
db
);
SDbObj
*
mnodeGetDbByTable
Name
(
char
*
db
);
void
*
mnodeGetNextDb
(
void
*
pIter
,
SDbObj
**
pDb
);
void
mnodeCancelGetNextDb
(
void
*
pIter
);
void
mnodeIncDbRef
(
SDbObj
*
pDb
);
...
...
src/mnode/src/mnodeDb.c
浏览文件 @
84313b70
...
...
@@ -199,18 +199,13 @@ void mnodeDecDbRef(SDbObj *pDb) {
return
sdbDecRef
(
tsDbSdb
,
pDb
);
}
SDbObj
*
mnodeGetDbByTableId
(
char
*
tableId
)
{
char
db
[
TSDB_TABLE_FNAME_LEN
],
*
pos
;
// tableId format should be : acct.db.table
pos
=
strstr
(
tableId
,
TS_PATH_DELIMITER
);
assert
(
NULL
!=
pos
);
pos
=
strstr
(
pos
+
1
,
TS_PATH_DELIMITER
);
assert
(
NULL
!=
pos
);
memset
(
db
,
0
,
sizeof
(
db
));
strncpy
(
db
,
tableId
,
pos
-
tableId
);
SDbObj
*
mnodeGetDbByTableName
(
char
*
tableName
)
{
SName
name
=
{
0
};
tNameFromString
(
&
name
,
tableName
,
T_NAME_ACCT
|
T_NAME_DB
|
T_NAME_TABLE
);
// validate the tableName?
char
db
[
TSDB_TABLE_FNAME_LEN
]
=
{
0
};
tNameGetFullDbName
(
&
name
,
db
);
return
mnodeGetDb
(
db
);
}
...
...
src/mnode/src/mnodeTable.c
浏览文件 @
84313b70
...
...
@@ -297,7 +297,7 @@ static int32_t mnodeChildTableActionRestored() {
pIter = mnodeGetNextChildTable(pIter, &pTable);
if (pTable == NULL) break;
SDbObj *pDb = mnodeGetDbByTable
Id
(pTable->info.tableId);
SDbObj *pDb = mnodeGetDbByTable
Name
(pTable->info.tableId);
if (pDb == NULL || pDb->status != TSDB_DB_STATUS_READY) {
mError("ctable:%s, failed to get db or db in dropping, discard it", pTable->info.tableId);
SSdbRow desc = {.type = SDB_OPER_LOCAL, .pObj = pTable, .pTable = tsChildTableSdb};
...
...
@@ -443,7 +443,7 @@ static int32_t mnodeSuperTableActionDestroy(SSdbRow *pRow) {
static
int32_t
mnodeSuperTableActionInsert
(
SSdbRow
*
pRow
)
{
SSTableObj
*
pStable
=
pRow
->
pObj
;
SDbObj
*
pDb
=
mnodeGetDbByTable
Id
(
pStable
->
info
.
tableId
);
SDbObj
*
pDb
=
mnodeGetDbByTable
Name
(
pStable
->
info
.
tableId
);
if
(
pDb
!=
NULL
&&
pDb
->
status
==
TSDB_DB_STATUS_READY
)
{
mnodeAddSuperTableIntoDb
(
pDb
);
}
...
...
@@ -455,7 +455,7 @@ static int32_t mnodeSuperTableActionInsert(SSdbRow *pRow) {
static
int32_t
mnodeSuperTableActionDelete
(
SSdbRow
*
pRow
)
{
SSTableObj
*
pStable
=
pRow
->
pObj
;
SDbObj
*
pDb
=
mnodeGetDbByTable
Id
(
pStable
->
info
.
tableId
);
SDbObj
*
pDb
=
mnodeGetDbByTable
Name
(
pStable
->
info
.
tableId
);
if
(
pDb
!=
NULL
)
{
mnodeRemoveSuperTableFromDb
(
pDb
);
mnodeDropAllChildTablesInStable
((
SSTableObj
*
)
pStable
);
...
...
@@ -748,9 +748,12 @@ 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
->
tableFname
);
pMsg
->
pDb
=
mnodeGetDbByTableName
(
pCreateTable
->
tableName
);
}
if
(
pMsg
->
pDb
==
NULL
)
{
mError
(
"msg:%p, app:%p table:%s, failed to create, db not selected"
,
pMsg
,
pMsg
->
rpcMsg
.
ahandle
,
pCreateTable
->
tableName
);
return
TSDB_CODE_MND_DB_NOT_SELECTED
;
}
...
...
@@ -759,28 +762,28 @@ static int32_t mnodeValidateCreateTableMsg(SCreateTableMsg *pCreateTable, SMnode
return
TSDB_CODE_MND_DB_IN_DROPPING
;
}
if
(
pMsg
->
pTable
==
NULL
)
pMsg
->
pTable
=
mnodeGetTable
(
pCreateTable
->
table
Fn
ame
);
if
(
pMsg
->
pTable
==
NULL
)
pMsg
->
pTable
=
mnodeGetTable
(
pCreateTable
->
table
N
ame
);
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
Fn
ame
);
mDebug
(
"msg:%p, app:%p table:%s, continue to get meta"
,
pMsg
,
pMsg
->
rpcMsg
.
ahandle
,
pCreateTable
->
table
N
ame
);
return
mnodeGetChildTableMeta
(
pMsg
);
}
else
if
(
pCreateTable
->
igExists
)
{
mDebug
(
"msg:%p, app:%p table:%s, is already exist"
,
pMsg
,
pMsg
->
rpcMsg
.
ahandle
,
pCreateTable
->
table
Fn
ame
);
mDebug
(
"msg:%p, app:%p table:%s, is already exist"
,
pMsg
,
pMsg
->
rpcMsg
.
ahandle
,
pCreateTable
->
table
N
ame
);
return
TSDB_CODE_SUCCESS
;
}
else
{
mError
(
"msg:%p, app:%p table:%s, failed to create, table already exist"
,
pMsg
,
pMsg
->
rpcMsg
.
ahandle
,
pCreateTable
->
table
Fn
ame
);
pCreateTable
->
table
N
ame
);
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
Fn
ame
,
pMsg
->
rpcMsg
.
handle
);
pCreateTable
->
table
N
ame
,
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
Fn
ame
,
pMsg
->
rpcMsg
.
handle
);
pCreateTable
->
table
N
ame
,
pMsg
->
rpcMsg
.
handle
);
return
mnodeProcessCreateChildTableMsg
(
pMsg
);
}
}
...
...
@@ -860,9 +863,12 @@ 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
->
tableFname
);
pMsg
->
pDb
=
mnodeGetDbByTableName
(
p
->
tableName
);
}
if
(
pMsg
->
pDb
==
NULL
)
{
mError
(
"msg:%p, app:%p table:%s, failed to create, db not selected"
,
pMsg
,
pMsg
->
rpcMsg
.
ahandle
,
p
->
tableName
);
return
TSDB_CODE_MND_DB_NOT_SELECTED
;
}
...
...
@@ -871,37 +877,37 @@ static int32_t mnodeProcessCreateTableMsg(SMnodeMsg *pMsg) {
return
TSDB_CODE_MND_DB_IN_DROPPING
;
}
if
(
pMsg
->
pTable
==
NULL
)
pMsg
->
pTable
=
mnodeGetTable
(
p
->
table
Fn
ame
);
if
(
pMsg
->
pTable
==
NULL
)
pMsg
->
pTable
=
mnodeGetTable
(
p
->
table
N
ame
);
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
Fn
ame
);
mDebug
(
"msg:%p, app:%p table:%s, continue to get meta"
,
pMsg
,
pMsg
->
rpcMsg
.
ahandle
,
p
->
table
N
ame
);
return
mnodeGetChildTableMeta
(
pMsg
);
}
else
if
(
p
->
igExists
)
{
mDebug
(
"msg:%p, app:%p table:%s, is already exist"
,
pMsg
,
pMsg
->
rpcMsg
.
ahandle
,
p
->
table
Fn
ame
);
mDebug
(
"msg:%p, app:%p table:%s, is already exist"
,
pMsg
,
pMsg
->
rpcMsg
.
ahandle
,
p
->
table
N
ame
);
return
TSDB_CODE_SUCCESS
;
}
else
{
mError
(
"msg:%p, app:%p table:%s, failed to create, table already exist"
,
pMsg
,
pMsg
->
rpcMsg
.
ahandle
,
p
->
table
Fn
ame
);
mError
(
"msg:%p, app:%p table:%s, failed to create, table already exist"
,
pMsg
,
pMsg
->
rpcMsg
.
ahandle
,
p
->
table
N
ame
);
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
Fn
ame
,
pMsg
->
rpcMsg
.
handle
);
p
->
table
N
ame
,
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
Fn
ame
,
pMsg
->
rpcMsg
.
handle
);
p
->
table
N
ame
,
pMsg
->
rpcMsg
.
handle
);
return
mnodeProcessCreateChildTableMsg
(
pMsg
);
}
}
static
int32_t
mnodeProcessDropTableMsg
(
SMnodeMsg
*
pMsg
)
{
SCMDropTableMsg
*
pDrop
=
pMsg
->
rpcMsg
.
pCont
;
if
(
pMsg
->
pDb
==
NULL
)
pMsg
->
pDb
=
mnodeGetDbByTable
Id
(
pDrop
->
tableF
name
);
if
(
pMsg
->
pDb
==
NULL
)
pMsg
->
pDb
=
mnodeGetDbByTable
Name
(
pDrop
->
name
);
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
->
tableF
name
);
pMsg
->
rpcMsg
.
ahandle
,
pDrop
->
name
);
return
TSDB_CODE_MND_DB_NOT_SELECTED
;
}
...
...
@@ -912,17 +918,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
->
tableF
name
);
pDrop
->
name
);
return
TSDB_CODE_MND_MONITOR_DB_FORBIDDEN
;
}
if
(
pMsg
->
pTable
==
NULL
)
pMsg
->
pTable
=
mnodeGetTable
(
pDrop
->
tableF
name
);
if
(
pMsg
->
pTable
==
NULL
)
pMsg
->
pTable
=
mnodeGetTable
(
pDrop
->
name
);
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
->
tableF
name
);
mDebug
(
"msg:%p, app:%p table:%s is not exist, treat as success"
,
pMsg
,
pMsg
->
rpcMsg
.
ahandle
,
pDrop
->
name
);
return
TSDB_CODE_SUCCESS
;
}
else
{
mError
(
"msg:%p, app:%p table:%s, failed to drop, table not exist"
,
pMsg
,
pMsg
->
rpcMsg
.
ahandle
,
pDrop
->
tableF
name
);
mError
(
"msg:%p, app:%p table:%s, failed to drop, table not exist"
,
pMsg
,
pMsg
->
rpcMsg
.
ahandle
,
pDrop
->
name
);
return
TSDB_CODE_MND_INVALID_TABLE_NAME
;
}
}
...
...
@@ -930,12 +936,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
->
tableF
name
,
pSTable
->
uid
,
pSTable
->
numOfTables
,
taosHashGetSize
(
pSTable
->
vgHash
));
pMsg
->
rpcMsg
.
ahandle
,
pDrop
->
name
,
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
->
tableF
name
,
pCTable
->
vgId
,
pCTable
->
tid
,
pCTable
->
uid
);
pDrop
->
name
,
pCTable
->
vgId
,
pCTable
->
tid
,
pCTable
->
uid
);
return
mnodeProcessDropChildTableMsg
(
pMsg
);
}
}
...
...
@@ -946,7 +952,7 @@ static int32_t mnodeProcessTableMetaMsg(SMnodeMsg *pMsg) {
mDebug
(
"msg:%p, app:%p table:%s, table meta msg is received from thandle:%p, createFlag:%d"
,
pMsg
,
pMsg
->
rpcMsg
.
ahandle
,
pInfo
->
tableFname
,
pMsg
->
rpcMsg
.
handle
,
pInfo
->
createFlag
);
if
(
pMsg
->
pDb
==
NULL
)
pMsg
->
pDb
=
mnodeGetDbByTable
Id
(
pInfo
->
tableFname
);
if
(
pMsg
->
pDb
==
NULL
)
pMsg
->
pDb
=
mnodeGetDbByTable
Name
(
pInfo
->
tableFname
);
if
(
pMsg
->
pDb
==
NULL
)
{
mError
(
"msg:%p, app:%p table:%s, failed to get table meta, db not selected"
,
pMsg
,
pMsg
->
rpcMsg
.
ahandle
,
pInfo
->
tableFname
);
...
...
@@ -1006,12 +1012,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
Fn
ame
);
mError
(
"msg:%p, app:%p table:%s, failed to create, no enough memory"
,
pMsg
,
pMsg
->
rpcMsg
.
ahandle
,
pCreate
->
table
N
ame
);
return
TSDB_CODE_MND_OUT_OF_MEMORY
;
}
int64_t
us
=
taosGetTimestampUs
();
pStable
->
info
.
tableId
=
strdup
(
pCreate
->
table
Fn
ame
);
pStable
->
info
.
tableId
=
strdup
(
pCreate
->
table
N
ame
);
pStable
->
info
.
type
=
TSDB_SUPER_TABLE
;
pStable
->
createdTime
=
taosGetTimestampMs
();
pStable
->
uid
=
(
us
<<
24
)
+
((
sdbGetVersion
()
&
((
1ul
<<
16
)
-
1ul
))
<<
8
)
+
(
taosRand
()
&
((
1ul
<<
8
)
-
1ul
));
...
...
@@ -1025,14 +1031,14 @@ 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
Fn
ame
);
mError
(
"msg:%p, app:%p table:%s, failed to create, no schema input"
,
pMsg
,
pMsg
->
rpcMsg
.
ahandle
,
pCreate
->
table
N
ame
);
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
Fn
ame
);
mError
(
"msg:%p, app:%p table:%s, failed to create, too many columns"
,
pMsg
,
pMsg
->
rpcMsg
.
ahandle
,
pCreate
->
table
N
ame
);
return
TSDB_CODE_MND_INVALID_TABLE_NAME
;
}
...
...
@@ -1044,8 +1050,8 @@ static int32_t mnodeProcessCreateSuperTableMsg(SMnodeMsg *pMsg) {
tschema
[
col
].
bytes
=
htons
(
tschema
[
col
].
bytes
);
}
if
(
!
i
sValidSchema
(
pStable
->
schema
,
pStable
->
numOfColumns
,
pStable
->
numOfTags
))
{
mError
(
"msg:%p, app:%p table:%s, failed to create table, invalid schema"
,
pMsg
,
pMsg
->
rpcMsg
.
ahandle
,
pCreate
->
table
Fn
ame
);
if
(
!
tI
sValidSchema
(
pStable
->
schema
,
pStable
->
numOfColumns
,
pStable
->
numOfTags
))
{
mError
(
"msg:%p, app:%p table:%s, failed to create table, invalid schema"
,
pMsg
,
pMsg
->
rpcMsg
.
ahandle
,
pCreate
->
table
N
ame
);
return
TSDB_CODE_MND_INVALID_CREATE_TABLE_MSG
;
}
...
...
@@ -1065,7 +1071,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
Fn
ame
);
mError
(
"msg:%p, app:%p table:%s, failed to create, sdb error"
,
pMsg
,
pMsg
->
rpcMsg
.
ahandle
,
pCreate
->
table
N
ame
);
}
return
code
;
...
...
@@ -1907,12 +1913,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
Fn
ame
);
mError
(
"msg:%p, app:%p table:%s, failed to alloc memory"
,
pMsg
,
pMsg
->
rpcMsg
.
ahandle
,
pCreate
->
table
N
ame
);
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
Fn
ame
);
pTable
->
info
.
tableId
=
strdup
(
pCreate
->
table
N
ame
);
pTable
->
createdTime
=
taosGetTimestampMs
();
pTable
->
tid
=
tid
;
pTable
->
vgId
=
pVgroup
->
vgId
;
...
...
@@ -1928,7 +1934,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
Fn
ame
,
stableName
);
pCreate
->
table
N
ame
,
stableName
);
mnodeDestroyChildTable
(
pTable
);
return
TSDB_CODE_TDB_INVALID_CREATE_TB_MSG
;
}
...
...
@@ -1936,7 +1942,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
Fn
ame
,
stableName
);
pCreate
->
table
N
ame
,
stableName
);
mnodeDestroyChildTable
(
pTable
);
return
TSDB_CODE_MND_INVALID_TABLE_NAME
;
}
...
...
@@ -2003,7 +2009,7 @@ static int32_t mnodeDoCreateChildTable(SMnodeMsg *pMsg, int32_t tid) {
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
Fn
ame
,
mError
(
"msg:%p, app:%p table:%s, failed to create, reason:%s"
,
pMsg
,
pMsg
->
rpcMsg
.
ahandle
,
pCreate
->
table
N
ame
,
tstrerror
(
code
));
}
else
{
mDebug
(
"msg:%p, app:%p table:%s, allocated in vgroup, vgId:%d sid:%d uid:%"
PRIu64
,
pMsg
,
pMsg
->
rpcMsg
.
ahandle
,
...
...
@@ -2020,7 +2026,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
Fn
ame
);
pCreate
->
table
N
ame
);
return
code
;
}
...
...
@@ -2031,7 +2037,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
Fn
ame
,
tstrerror
(
code
));
pCreate
->
table
N
ame
,
tstrerror
(
code
));
return
code
;
}
...
...
@@ -2045,15 +2051,15 @@ static int32_t mnodeProcessCreateChildTableMsg(SMnodeMsg *pMsg) {
return
mnodeDoCreateChildTable
(
pMsg
,
tid
);
}
}
else
{
if
(
pMsg
->
pTable
==
NULL
)
pMsg
->
pTable
=
mnodeGetTable
(
pCreate
->
table
Fn
ame
);
if
(
pMsg
->
pTable
==
NULL
)
pMsg
->
pTable
=
mnodeGetTable
(
pCreate
->
table
N
ame
);
}
if
(
pMsg
->
pTable
==
NULL
)
{
mError
(
"msg:%p, app:%p table:%s, object not found, retry:%d reason:%s"
,
pMsg
,
pMsg
->
rpcMsg
.
ahandle
,
pCreate
->
table
Fn
ame
,
pMsg
->
retry
,
mError
(
"msg:%p, app:%p table:%s, object not found, retry:%d reason:%s"
,
pMsg
,
pMsg
->
rpcMsg
.
ahandle
,
pCreate
->
table
N
ame
,
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
Fn
ame
);
mDebug
(
"msg:%p, app:%p table:%s, send create msg to vnode again"
,
pMsg
,
pMsg
->
rpcMsg
.
ahandle
,
pCreate
->
table
N
ame
);
return
mnodeDoCreateChildTableFp
(
pMsg
);
}
}
...
...
@@ -2398,8 +2404,7 @@ static int32_t mnodeAutoCreateChildTable(SMnodeMsg *pMsg) {
SCreateTableMsg
*
pCreate
=
(
SCreateTableMsg
*
)
((
char
*
)
pCreateMsg
+
sizeof
(
SCMCreateTableMsg
));
size_t
size
=
tListLen
(
pInfo
->
tableFname
);
tstrncpy
(
pCreate
->
tableFname
,
pInfo
->
tableFname
,
size
);
tstrncpy
(
pCreate
->
db
,
pMsg
->
pDb
->
name
,
sizeof
(
pCreate
->
db
));
tstrncpy
(
pCreate
->
tableName
,
pInfo
->
tableFname
,
size
);
pCreate
->
igExists
=
1
;
pCreate
->
getMeta
=
1
;
...
...
@@ -2767,7 +2772,7 @@ static int32_t mnodeProcessMultiTableMetaMsg(SMnodeMsg *pMsg) {
SCTableObj
*
pTable
=
mnodeGetChildTable
(
tableId
);
if
(
pTable
==
NULL
)
continue
;
if
(
pMsg
->
pDb
==
NULL
)
pMsg
->
pDb
=
mnodeGetDbByTable
Id
(
tableId
);
if
(
pMsg
->
pDb
==
NULL
)
pMsg
->
pDb
=
mnodeGetDbByTable
Name
(
tableId
);
if
(
pMsg
->
pDb
==
NULL
||
pMsg
->
pDb
->
status
!=
TSDB_DB_STATUS_READY
)
{
mnodeDecTableRef
(
pTable
);
continue
;
...
...
@@ -2988,7 +2993,7 @@ static int32_t mnodeProcessAlterTableMsg(SMnodeMsg *pMsg) {
mDebug
(
"msg:%p, app:%p table:%s, alter table msg is received from thandle:%p"
,
pMsg
,
pMsg
->
rpcMsg
.
ahandle
,
pAlter
->
tableFname
,
pMsg
->
rpcMsg
.
handle
);
if
(
pMsg
->
pDb
==
NULL
)
pMsg
->
pDb
=
mnodeGetDbByTable
Id
(
pAlter
->
tableFname
);
if
(
pMsg
->
pDb
==
NULL
)
pMsg
->
pDb
=
mnodeGetDbByTable
Name
(
pAlter
->
tableFname
);
if
(
pMsg
->
pDb
==
NULL
)
{
mError
(
"msg:%p, app:%p table:%s, failed to alter table, db not selected"
,
pMsg
,
pMsg
->
rpcMsg
.
ahandle
,
pAlter
->
tableFname
);
return
TSDB_CODE_MND_DB_NOT_SELECTED
;
...
...
src/query/src/qAst.c
浏览文件 @
84313b70
...
...
@@ -407,7 +407,7 @@ tExprNode* exprTreeFromTableName(const char* tbnameCond) {
SSchema
*
pSchema
=
exception_calloc
(
1
,
sizeof
(
SSchema
));
left
->
pSchema
=
pSchema
;
*
pSchema
=
t
sc
GetTbnameColumnSchema
();
*
pSchema
=
tGetTbnameColumnSchema
();
tExprNode
*
right
=
exception_calloc
(
1
,
sizeof
(
tExprNode
));
expr
->
_node
.
pRight
=
right
;
...
...
src/query/src/qExecutor.c
浏览文件 @
84313b70
...
...
@@ -6572,7 +6572,7 @@ static SQInfo *createQInfoImpl(SQueryTableMsg *pQueryMsg, SSqlGroupbyExpr *pGrou
int32_t
srcSize
=
0
;
for
(
int16_t
i
=
0
;
i
<
numOfCols
;
++
i
)
{
pQuery
->
colList
[
i
]
=
pQueryMsg
->
colList
[
i
];
pQuery
->
colList
[
i
].
filters
=
t
scFilterInfoClone
(
pQueryMsg
->
colList
[
i
].
filters
,
pQuery
->
colList
[
i
].
numOfFilters
);
pQuery
->
colList
[
i
].
filters
=
t
FilterInfoDup
(
pQueryMsg
->
colList
[
i
].
filters
,
pQuery
->
colList
[
i
].
numOfFilters
);
srcSize
+=
pQuery
->
colList
[
i
].
bytes
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录