Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
慢慢CG
TDengine
提交
c62e0360
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看板
提交
c62e0360
编写于
5月 12, 2021
作者:
H
Haojun Liao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[td-4151]
上级
6c4c8e37
变更
4
显示空白变更内容
内联
并排
Showing
4 changed file
with
260 addition
and
196 deletion
+260
-196
src/client/src/tscSQLParser.c
src/client/src/tscSQLParser.c
+12
-6
src/client/src/tscServer.c
src/client/src/tscServer.c
+96
-128
src/inc/taosmsg.h
src/inc/taosmsg.h
+1
-0
src/mnode/src/mnodeTable.c
src/mnode/src/mnodeTable.c
+151
-62
未找到文件。
src/client/src/tscSQLParser.c
浏览文件 @
c62e0360
...
@@ -619,7 +619,10 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) {
...
@@ -619,7 +619,10 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) {
case
TSDB_SQL_SELECT
:
{
case
TSDB_SQL_SELECT
:
{
const
char
*
msg1
=
"columns in select clause not identical"
;
const
char
*
msg1
=
"columns in select clause not identical"
;
loadAllTableMeta
(
pSql
,
pInfo
);
int32_t
code
=
loadAllTableMeta
(
pSql
,
pInfo
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
return
code
;
}
SQueryInfo
*
pCurrent
=
pCmd
->
pQueryInfo
;
SQueryInfo
*
pCurrent
=
pCmd
->
pQueryInfo
;
for
(
int32_t
i
=
0
;
i
<
pCmd
->
clauseIndex
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
pCmd
->
clauseIndex
;
++
i
)
{
...
@@ -7128,7 +7131,7 @@ static int32_t getTableNameFromSubquery(SSqlNode* pSqlNode, SArray* tableNameLis
...
@@ -7128,7 +7131,7 @@ static int32_t getTableNameFromSubquery(SSqlNode* pSqlNode, SArray* tableNameLis
}
}
static
void
freeElem
(
void
*
p
)
{
static
void
freeElem
(
void
*
p
)
{
tfree
(
p
);
tfree
(
*
(
char
**
)
p
);
}
}
int32_t
loadAllTableMeta
(
SSqlObj
*
pSql
,
struct
SSqlInfo
*
pInfo
)
{
int32_t
loadAllTableMeta
(
SSqlObj
*
pSql
,
struct
SSqlInfo
*
pInfo
)
{
...
@@ -7252,7 +7255,10 @@ static int32_t doLoadAllTableMeta(SSqlObj* pSql, SQueryInfo* pQueryInfo, SSqlNod
...
@@ -7252,7 +7255,10 @@ static int32_t doLoadAllTableMeta(SSqlObj* pSql, SQueryInfo* pQueryInfo, SSqlNod
strncpy
(
pTableMetaInfo
->
aliasName
,
tNameGetTableName
(
&
pTableMetaInfo
->
name
),
tListLen
(
pTableMetaInfo
->
aliasName
));
strncpy
(
pTableMetaInfo
->
aliasName
,
tNameGetTableName
(
&
pTableMetaInfo
->
name
),
tListLen
(
pTableMetaInfo
->
aliasName
));
}
}
code
=
tscGetTableMeta
(
pSql
,
pTableMetaInfo
);
const
char
*
name
=
tNameGetTableName
(
&
pTableMetaInfo
->
name
);
pTableMetaInfo
->
pTableMeta
=
taosHashGet
(
pCmd
->
pTableMetaMap
,
name
,
strlen
(
name
));
assert
(
pTableMetaInfo
->
pTableMeta
!=
NULL
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
return
code
;
return
code
;
}
}
...
@@ -7376,13 +7382,13 @@ int32_t validateSqlNode(SSqlObj* pSql, SSqlNode* pSqlNode, SQueryInfo* pQueryInf
...
@@ -7376,13 +7382,13 @@ int32_t validateSqlNode(SSqlObj* pSql, SSqlNode* pSqlNode, SQueryInfo* pQueryInf
}
else
{
}
else
{
pQueryInfo
->
command
=
TSDB_SQL_SELECT
;
pQueryInfo
->
command
=
TSDB_SQL_SELECT
;
size_t
fromSize
=
taosArrayGetSize
(
pSqlNode
->
from
->
list
);
size_t
numOfTables
=
taosArrayGetSize
(
pSqlNode
->
from
->
list
);
if
(
fromSize
>
TSDB_MAX_JOIN_TABLE_NUM
)
{
if
(
numOfTables
>
TSDB_MAX_JOIN_TABLE_NUM
)
{
return
invalidSqlErrMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg2
);
return
invalidSqlErrMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg2
);
}
}
// set all query tables, which are maybe more than one.
// set all query tables, which are maybe more than one.
code
=
doLoadAllTableMeta
(
pSql
,
pQueryInfo
,
pSqlNode
,
(
int32_t
)
fromSize
);
code
=
doLoadAllTableMeta
(
pSql
,
pQueryInfo
,
pSqlNode
,
(
int32_t
)
numOfTables
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
return
code
;
return
code
;
}
}
...
...
src/client/src/tscServer.c
浏览文件 @
c62e0360
...
@@ -1822,9 +1822,7 @@ int tscBuildHeartBeatMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
...
@@ -1822,9 +1822,7 @@ int tscBuildHeartBeatMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
int
tscProcessTableMetaRsp
(
SSqlObj
*
pSql
)
{
static
int32_t
tableMetaMsgConvert
(
STableMetaMsg
*
pMetaMsg
)
{
STableMetaMsg
*
pMetaMsg
=
(
STableMetaMsg
*
)
pSql
->
res
.
pRsp
;
pMetaMsg
->
tid
=
htonl
(
pMetaMsg
->
tid
);
pMetaMsg
->
tid
=
htonl
(
pMetaMsg
->
tid
);
pMetaMsg
->
sversion
=
htons
(
pMetaMsg
->
sversion
);
pMetaMsg
->
sversion
=
htons
(
pMetaMsg
->
sversion
);
pMetaMsg
->
tversion
=
htons
(
pMetaMsg
->
tversion
);
pMetaMsg
->
tversion
=
htons
(
pMetaMsg
->
tversion
);
...
@@ -1869,20 +1867,33 @@ int tscProcessTableMetaRsp(SSqlObj *pSql) {
...
@@ -1869,20 +1867,33 @@ int tscProcessTableMetaRsp(SSqlObj *pSql) {
pSchema
++
;
pSchema
++
;
}
}
STableMetaInfo
*
pTableMetaInfo
=
tscGetTableMetaInfoFromCmd
(
&
pSql
->
cmd
,
0
,
0
)
;
return
TSDB_CODE_SUCCESS
;
assert
(
pTableMetaInfo
->
pTableMeta
==
NULL
);
}
STableMeta
*
pTableMeta
=
tscCreateTableMetaFromMsg
(
pMetaMsg
);
// update the vgroupInfo if needed
if
(
!
tIsValidSchema
(
pTableMeta
->
schema
,
pTableMeta
->
tableInfo
.
numOfColumns
,
pTableMeta
->
tableInfo
.
numOfTags
))
{
static
void
doUpdateVgroupInfo
(
STableMeta
*
pTableMeta
,
SVgroupMsg
*
pVgroupMsg
)
{
tscError
(
"0x%"
PRIx64
" invalid table meta from mnode, name:%s"
,
pSql
->
self
,
tNameGetTableName
(
&
pTableMetaInfo
->
name
));
if
(
pTableMeta
->
vgId
>
0
)
{
return
TSDB_CODE_TSC_INVALID_VALUE
;
int32_t
vgId
=
pTableMeta
->
vgId
;
assert
(
pTableMeta
->
tableType
!=
TSDB_SUPER_TABLE
);
SNewVgroupInfo
vgroupInfo
=
{.
inUse
=
-
1
};
taosHashGetClone
(
tscVgroupMap
,
&
vgId
,
sizeof
(
vgId
),
NULL
,
&
vgroupInfo
,
sizeof
(
SNewVgroupInfo
));
// vgroup info exists, compare with it
if
(((
vgroupInfo
.
inUse
>=
0
)
&&
!
vgroupInfoIdentical
(
&
vgroupInfo
,
pVgroupMsg
))
||
(
vgroupInfo
.
inUse
<
0
))
{
vgroupInfo
=
createNewVgroupInfo
(
pVgroupMsg
);
taosHashPut
(
tscVgroupMap
,
&
vgId
,
sizeof
(
vgId
),
&
vgroupInfo
,
sizeof
(
vgroupInfo
));
tscDebug
(
"add new VgroupInfo, vgId:%d, total cached:%d"
,
vgId
,
(
int32_t
)
taosHashGetSize
(
tscVgroupMap
));
}
}
}
}
static
void
doAddTableMetaLocalBuf
(
STableMeta
*
pTableMeta
,
STableMetaMsg
*
pMetaMsg
,
bool
updateSTable
)
{
if
(
pTableMeta
->
tableType
==
TSDB_CHILD_TABLE
)
{
if
(
pTableMeta
->
tableType
==
TSDB_CHILD_TABLE
)
{
//
check if super table hashmap or not
//
add or update the corresponding super table meta data info
int32_t
len
=
(
int32_t
)
strnlen
(
pTableMeta
->
sTableName
,
TSDB_TABLE_FNAME_LEN
);
int32_t
len
=
(
int32_t
)
strnlen
(
pTableMeta
->
sTableName
,
TSDB_TABLE_FNAME_LEN
);
//
super tableMeta data alrea
y exists, create it according to tableMeta and add it to hash map
//
The super tableMeta alread
y exists, create it according to tableMeta and add it to hash map
STableMeta
*
pSupTableMeta
=
createSuperTableMeta
(
pMetaMsg
);
STableMeta
*
pSupTableMeta
=
createSuperTableMeta
(
pMetaMsg
);
uint32_t
size
=
tscGetTableMetaSize
(
pSupTableMeta
);
uint32_t
size
=
tscGetTableMetaSize
(
pSupTableMeta
);
...
@@ -1892,37 +1903,37 @@ int tscProcessTableMetaRsp(SSqlObj *pSql) {
...
@@ -1892,37 +1903,37 @@ int tscProcessTableMetaRsp(SSqlObj *pSql) {
tfree
(
pSupTableMeta
);
tfree
(
pSupTableMeta
);
CChildTableMeta
*
cMeta
=
tscCreateChildMeta
(
pTableMeta
);
CChildTableMeta
*
cMeta
=
tscCreateChildMeta
(
pTableMeta
);
taosHashPut
(
tscTableMetaInfo
,
pMetaMsg
->
tableFname
,
strlen
(
pMetaMsg
->
tableFname
),
cMeta
,
sizeof
(
CChildTableMeta
));
char
name
[
TSDB_TABLE_FNAME_LEN
]
=
{
0
};
tNameExtractFullName
(
&
pTableMetaInfo
->
name
,
name
);
taosHashPut
(
tscTableMetaInfo
,
name
,
strlen
(
name
),
cMeta
,
sizeof
(
CChildTableMeta
));
tfree
(
cMeta
);
tfree
(
cMeta
);
}
else
{
}
else
{
uint32_t
s
=
tscGetTableMetaSize
(
pTableMeta
);
uint32_t
s
=
tscGetTableMetaSize
(
pTableMeta
);
taosHashPut
(
tscTableMetaInfo
,
pMetaMsg
->
tableFname
,
strlen
(
pMetaMsg
->
tableFname
),
pTableMeta
,
s
);
char
name
[
TSDB_TABLE_FNAME_LEN
]
=
{
0
};
tNameExtractFullName
(
&
pTableMetaInfo
->
name
,
name
);
taosHashPut
(
tscTableMetaInfo
,
name
,
strlen
(
name
),
pTableMeta
,
s
);
}
}
}
// update the vgroupInfo if needed
int
tscProcessTableMetaRsp
(
SSqlObj
*
pSql
)
{
if
(
pTableMeta
->
vgId
>
0
)
{
STableMetaMsg
*
pMetaMsg
=
(
STableMetaMsg
*
)
pSql
->
res
.
pRsp
;
int32_t
vgId
=
pTableMeta
->
vgId
;
int32_t
code
=
tableMetaMsgConvert
(
pMetaMsg
);
assert
(
pTableMeta
->
tableType
!=
TSDB_SUPER_TABLE
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
return
code
;
}
SNewVgroupInfo
vgroupInfo
=
{.
inUse
=
-
1
}
;
STableMetaInfo
*
pTableMetaInfo
=
tscGetTableMetaInfoFromCmd
(
&
pSql
->
cmd
,
0
,
0
)
;
taosHashGetClone
(
tscVgroupMap
,
&
vgId
,
sizeof
(
vgId
),
NULL
,
&
vgroupInfo
,
sizeof
(
SNewVgroupInfo
)
);
assert
(
pTableMetaInfo
->
pTableMeta
==
NULL
);
if
(((
vgroupInfo
.
inUse
>=
0
)
&&
!
vgroupInfoIdentical
(
&
vgroupInfo
,
&
pMetaMsg
->
vgroup
))
||
STableMeta
*
pTableMeta
=
tscCreateTableMetaFromMsg
(
pMetaMsg
);
(
vgroupInfo
.
inUse
<
0
))
{
// vgroup info exists, compare with it
if
(
!
tIsValidSchema
(
pTableMeta
->
schema
,
pTableMeta
->
tableInfo
.
numOfColumns
,
pTableMeta
->
tableInfo
.
numOfTags
))
{
vgroupInfo
=
createNewVgroupInfo
(
&
pMetaMsg
->
vgroup
);
tscError
(
"0x%"
PRIx64
" invalid table meta from mnode, name:%s"
,
pSql
->
self
,
tNameGetTableName
(
&
pTableMetaInfo
->
name
));
taosHashPut
(
tscVgroupMap
,
&
vgId
,
sizeof
(
vgId
),
&
vgroupInfo
,
sizeof
(
vgroupInfo
));
return
TSDB_CODE_TSC_INVALID_VALUE
;
tscDebug
(
"add new VgroupInfo, vgId:%d, total cached:%d"
,
vgId
,
(
int32_t
)
taosHashGetSize
(
tscVgroupMap
));
}
}
}
char
name
[
TSDB_TABLE_FNAME_LEN
]
=
{
0
};
tNameExtractFullName
(
&
pTableMetaInfo
->
name
,
name
);
assert
(
strncmp
(
pMetaMsg
->
tableFname
,
name
,
tListLen
(
pMetaMsg
->
tableFname
))
==
0
);
doAddTableMetaLocalBuf
(
pTableMeta
,
pMetaMsg
,
true
);
doUpdateVgroupInfo
(
pTableMeta
,
&
pMetaMsg
->
vgroup
);
tscDebug
(
"0x%"
PRIx64
" recv table meta, uid:%"
PRIu64
", tid:%d, name:%s"
,
pSql
->
self
,
pTableMeta
->
id
.
uid
,
pTableMeta
->
id
.
tid
,
tscDebug
(
"0x%"
PRIx64
" recv table meta, uid:%"
PRIu64
", tid:%d, name:%s"
,
pSql
->
self
,
pTableMeta
->
id
.
uid
,
pTableMeta
->
id
.
tid
,
tNameGetTableName
(
&
pTableMetaInfo
->
name
));
tNameGetTableName
(
&
pTableMetaInfo
->
name
));
...
@@ -1930,108 +1941,65 @@ int tscProcessTableMetaRsp(SSqlObj *pSql) {
...
@@ -1930,108 +1941,65 @@ int tscProcessTableMetaRsp(SSqlObj *pSql) {
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
/*
*
/*
* multi table meta rsp pkg format:
* multi table meta rsp pkg format:
* | STaosRsp | SMultiTableInfoMsg | SMeterMeta0 | SSchema0 | SMeterMeta1 | SSchema1 | SMeterMeta2 | SSchema2
* | SMultiTableInfoMsg | SMeterMeta0 | SSchema0 | SMeterMeta1 | SSchema1 | SMeterMeta2 | SSchema2
* |...... 1B 4B
* | 4B
**/
*/
int
tscProcessMultiMeterMetaRsp
(
SSqlObj
*
pSql
)
{
int
tscProcessMultiTableMetaRsp
(
SSqlObj
*
pSql
)
{
#if 0
char
*
rsp
=
pSql
->
res
.
pRsp
;
char
*
rsp
=
pSql
->
res
.
pRsp
;
ieType = *rsp;
SMultiTableMeta
*
pMultiMeta
=
(
SMultiTableMeta
*
)
rsp
;
if (ieType != TSDB_IE_TYPE_META) {
pMultiMeta
->
numOfTables
=
htonl
(
pMultiMeta
->
numOfTables
);
tscError("invalid ie type:%d", ieType);
pSql->res.code = TSDB_CODE_TSC_INVALID_IE;
rsp
+=
sizeof
(
SMultiTableMeta
);
pSql->res.numOfTotal = 0;
return TSDB_CODE_TSC_APP_ERROR;
SSqlObj
*
pParentSql
=
(
SSqlObj
*
)
taosAcquireRef
(
tscObjRef
,
(
int64_t
)
pSql
->
param
);
SSqlCmd
*
pParentCmd
=
&
pParentSql
->
cmd
;
SHashObj
*
pSet
=
taosHashInit
(
4
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_BIGINT
),
false
,
HASH_NO_LOCK
);
for
(
int32_t
i
=
0
;
i
<
pMultiMeta
->
numOfTables
;
i
++
)
{
STableMetaMsg
*
pMetaMsg
=
(
STableMetaMsg
*
)
pMultiMeta
->
meta
;
int32_t
code
=
tableMetaMsgConvert
(
pMetaMsg
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
return
code
;
}
}
rsp++;
STableMeta
*
pTableMeta
=
tscCreateTableMetaFromMsg
(
pMetaMsg
);
if
(
!
tIsValidSchema
(
pTableMeta
->
schema
,
pTableMeta
->
tableInfo
.
numOfColumns
,
pTableMeta
->
tableInfo
.
numOfTags
))
{
tscError
(
"0x%"
PRIx64
" invalid table meta from mnode, name:%s"
,
pSql
->
self
,
pMetaMsg
->
tableFname
);
return
TSDB_CODE_TSC_INVALID_VALUE
;
}
SMultiTableInfoMsg *pInfo = (SMultiTableInfoMsg *)rsp;
int32_t
t
=
tscGetTableMetaSize
(
pTableMeta
);
totalNum = htonl(pInfo->numOfTables);
rsp += sizeof(SMultiTableInfoMsg);
for (i = 0; i < totalNum; i++) {
SName
sn
=
{
0
};
SMultiTableMeta *pMultiMeta = (SMultiTableMeta *)rsp;
tNameFromString
(
&
sn
,
pMetaMsg
->
tableFname
,
T_NAME_ACCT
|
T_NAME_DB
|
T_NAME_TABLE
);
STableMeta * pMeta = pMultiMeta->metas;
const
char
*
tableName
=
tNameGetTableName
(
&
sn
);
int32_t
keyLen
=
strlen
(
tableName
);
pMeta->sid = htonl(pMeta->sid);
taosHashPut
(
pParentCmd
->
pTableMetaMap
,
tableName
,
keyLen
,
pTableMeta
,
t
);
pMeta->sversion = htons(pMeta->sversion);
pMeta->vgId = htonl(pMeta->vgId);
bool
addToBuf
=
false
;
pMeta->uid = htobe64(pMeta->uid);
if
(
taosHashGet
(
pSet
,
&
pMetaMsg
->
uid
,
sizeof
(
pMetaMsg
->
uid
))
==
NULL
)
{
addToBuf
=
true
;
if (pMeta->sid <= 0 || pMeta->vgId < 0) {
taosHashPut
(
pSet
,
&
pMetaMsg
->
uid
,
sizeof
(
pMetaMsg
->
uid
),
""
,
0
);
tscError("invalid meter vgId:%d, sid%d", pMeta->vgId, pMeta->sid);
}
pSql->res.code = TSDB_CODE_TSC_INVALID_VALUE;
pSql->res.numOfTotal = i;
// create the tableMeta and add it into the TableMeta map
return TSDB_CODE_TSC_APP_ERROR;
doAddTableMetaLocalBuf
(
pTableMeta
,
pMetaMsg
,
addToBuf
);
}
// if the vgroup is not updated in current process, update it.
// pMeta->numOfColumns = htons(pMeta->numOfColumns);
int64_t
vgId
=
pMetaMsg
->
vgroup
.
vgId
;
//
if
(
taosHashGet
(
pSet
,
&
vgId
,
sizeof
(
vgId
))
==
NULL
)
{
// if (pMeta->numOfTags > TSDB_MAX_TAGS || pMeta->numOfTags < 0) {
doUpdateVgroupInfo
(
pTableMeta
,
&
pMetaMsg
->
vgroup
);
// tscError("invalid tag value count:%d", pMeta->numOfTags);
taosHashPut
(
pSet
,
&
vgId
,
sizeof
(
vgId
),
""
,
0
);
// pSql->res.code = TSDB_CODE_TSC_INVALID_VALUE;
}
// pSql->res.numOfTotal = i;
// return TSDB_CODE_TSC_APP_ERROR;
// }
//
// if (pMeta->numOfTags > TSDB_MAX_TAGS || pMeta->numOfTags < 0) {
// tscError("invalid numOfTags:%d", pMeta->numOfTags);
// pSql->res.code = TSDB_CODE_TSC_INVALID_VALUE;
// pSql->res.numOfTotal = i;
// return TSDB_CODE_TSC_APP_ERROR;
// }
//
// if (pMeta->numOfColumns > TSDB_MAX_COLUMNS || pMeta->numOfColumns < 0) {
// tscError("invalid numOfColumns:%d", pMeta->numOfColumns);
// pSql->res.code = TSDB_CODE_TSC_INVALID_VALUE;
// pSql->res.numOfTotal = i;
// return TSDB_CODE_TSC_APP_ERROR;
// }
//
// for (int j = 0; j < TSDB_REPLICA_MAX_NUM; ++j) {
// pMeta->vpeerDesc[j].vnode = htonl(pMeta->vpeerDesc[j].vnode);
// }
//
// pMeta->rowSize = 0;
// rsp += sizeof(SMultiTableMeta);
// pSchema = (SSchema *)rsp;
//
// int32_t numOfTotalCols = pMeta->numOfColumns + pMeta->numOfTags;
// for (int j = 0; j < numOfTotalCols; ++j) {
// pSchema->bytes = htons(pSchema->bytes);
// pSchema->colId = htons(pSchema->colId);
//
// // ignore the tags length
// if (j < pMeta->numOfColumns) {
// pMeta->rowSize += pSchema->bytes;
// }
// pSchema++;
// }
//
// rsp += numOfTotalCols * sizeof(SSchema);
//
// int32_t tagLen = 0;
// SSchema *pTagsSchema = tscGetTableTagSchema(pMeta);
//
// if (pMeta->tableType == TSDB_CHILD_TABLE) {
// for (int32_t j = 0; j < pMeta->numOfTags; ++j) {
// tagLen += pTagsSchema[j].bytes;
// }
// }
//
// rsp += tagLen;
// int32_t size = (int32_t)(rsp - ((char *)pMeta)); // Consistent with STableMeta in cache
// }
}
}
pSql
->
res
.
code
=
TSDB_CODE_SUCCESS
;
pSql
->
res
.
code
=
TSDB_CODE_SUCCESS
;
pSql->res.numOfTotal = i;
pSql
->
res
.
numOfTotal
=
pMultiMeta
->
numOfTables
;
tscDebug("0x%"PRIx64" load multi-metermeta resp from complete num:%d", pSql->self, pSql->res.numOfTotal);
tscDebug
(
"0x%"
PRIx64
" load multi-tableMeta resp from complete numOfTables:%d"
,
pSql
->
self
,
pMultiMeta
->
numOfTables
);
#endif
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
...
@@ -2670,7 +2638,7 @@ void tscInitMsgsFp() {
...
@@ -2670,7 +2638,7 @@ void tscInitMsgsFp() {
tscProcessMsgRsp
[
TSDB_SQL_USE_DB
]
=
tscProcessUseDbRsp
;
tscProcessMsgRsp
[
TSDB_SQL_USE_DB
]
=
tscProcessUseDbRsp
;
tscProcessMsgRsp
[
TSDB_SQL_META
]
=
tscProcessTableMetaRsp
;
tscProcessMsgRsp
[
TSDB_SQL_META
]
=
tscProcessTableMetaRsp
;
tscProcessMsgRsp
[
TSDB_SQL_STABLEVGROUP
]
=
tscProcessSTableVgroupRsp
;
tscProcessMsgRsp
[
TSDB_SQL_STABLEVGROUP
]
=
tscProcessSTableVgroupRsp
;
tscProcessMsgRsp
[
TSDB_SQL_MULTI_META
]
=
tscProcessMulti
Meter
MetaRsp
;
tscProcessMsgRsp
[
TSDB_SQL_MULTI_META
]
=
tscProcessMulti
Table
MetaRsp
;
tscProcessMsgRsp
[
TSDB_SQL_SHOW
]
=
tscProcessShowRsp
;
tscProcessMsgRsp
[
TSDB_SQL_SHOW
]
=
tscProcessShowRsp
;
tscProcessMsgRsp
[
TSDB_SQL_RETRIEVE
]
=
tscProcessRetrieveRspFromNode
;
// rsp handled by same function.
tscProcessMsgRsp
[
TSDB_SQL_RETRIEVE
]
=
tscProcessRetrieveRspFromNode
;
// rsp handled by same function.
...
...
src/inc/taosmsg.h
浏览文件 @
c62e0360
...
@@ -754,6 +754,7 @@ typedef struct STableMetaMsg {
...
@@ -754,6 +754,7 @@ typedef struct STableMetaMsg {
typedef
struct
SMultiTableMeta
{
typedef
struct
SMultiTableMeta
{
int32_t
numOfTables
;
int32_t
numOfTables
;
int32_t
numOfVgroup
;
int32_t
contLen
;
int32_t
contLen
;
char
meta
[];
char
meta
[];
}
SMultiTableMeta
;
}
SMultiTableMeta
;
...
...
src/mnode/src/mnodeTable.c
浏览文件 @
c62e0360
...
@@ -1709,11 +1709,7 @@ static int32_t mnodeGetSuperTableMeta(SMnodeMsg *pMsg) {
...
@@ -1709,11 +1709,7 @@ static int32_t mnodeGetSuperTableMeta(SMnodeMsg *pMsg) {
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
static
int32_t
mnodeProcessSuperTableVgroupMsg
(
SMnodeMsg
*
pMsg
)
{
static
int32_t
calculateVgroupMsgLength
(
SSTableVgroupMsg
*
pInfo
,
int32_t
numOfTable
)
{
SSTableVgroupMsg
*
pInfo
=
pMsg
->
rpcMsg
.
pCont
;
int32_t
numOfTable
=
htonl
(
pInfo
->
numOfTables
);
// reserve space
int32_t
contLen
=
sizeof
(
SSTableVgroupRspMsg
)
+
32
*
sizeof
(
SVgroupMsg
)
+
sizeof
(
SVgroupsMsg
);
int32_t
contLen
=
sizeof
(
SSTableVgroupRspMsg
)
+
32
*
sizeof
(
SVgroupMsg
)
+
sizeof
(
SVgroupsMsg
);
for
(
int32_t
i
=
0
;
i
<
numOfTable
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
numOfTable
;
++
i
)
{
char
*
stableName
=
(
char
*
)
pInfo
+
sizeof
(
SSTableVgroupMsg
)
+
(
TSDB_TABLE_FNAME_LEN
)
*
i
;
char
*
stableName
=
(
char
*
)
pInfo
+
sizeof
(
SSTableVgroupMsg
)
+
(
TSDB_TABLE_FNAME_LEN
)
*
i
;
...
@@ -1725,37 +1721,26 @@ static int32_t mnodeProcessSuperTableVgroupMsg(SMnodeMsg *pMsg) {
...
@@ -1725,37 +1721,26 @@ static int32_t mnodeProcessSuperTableVgroupMsg(SMnodeMsg *pMsg) {
mnodeDecTableRef
(
pTable
);
mnodeDecTableRef
(
pTable
);
}
}
SSTableVgroupRspMsg
*
pRsp
=
rpcMallocCont
(
contLen
);
return
contLen
;
if
(
pRsp
==
NULL
)
{
}
return
TSDB_CODE_MND_OUT_OF_MEMORY
;
}
pRsp
->
numOfTables
=
0
;
static
char
*
serializeVgroupInfo
(
SSTableObj
*
pTable
,
char
*
msg
,
SMnodeMsg
*
pMsgBody
,
void
*
handle
)
{
char
*
msg
=
(
char
*
)
pRsp
+
sizeof
(
SSTableVgroupRspMsg
);
*
(
uint64_t
*
)
msg
=
htobe64
(
pTable
->
uid
);
msg
+=
sizeof
(
sizeof
(
pTable
->
uid
));
for
(
int32_t
i
=
0
;
i
<
numOfTable
;
++
i
)
{
char
*
stableName
=
(
char
*
)
pInfo
+
sizeof
(
SSTableVgroupMsg
)
+
(
TSDB_TABLE_FNAME_LEN
)
*
i
;
SSTableObj
*
pTable
=
mnodeGetSuperTable
(
stableName
);
if
(
pTable
==
NULL
)
{
mError
(
"msg:%p, app:%p stable:%s, not exist while get stable vgroup info"
,
pMsg
,
pMsg
->
rpcMsg
.
ahandle
,
stableName
);
mnodeDecTableRef
(
pTable
);
continue
;
}
if
(
pTable
->
vgHash
==
NULL
)
{
if
(
pTable
->
vgHash
==
NULL
)
{
mDebug
(
"msg:%p, app:%p stable:%s, no vgroup exist while get stable vgroup info"
,
pMsg
,
pMsg
->
rpcMsg
.
ahandle
,
mDebug
(
"msg:%p, app:%p stable:%s, no vgroup exist while get stable vgroup info"
,
pMsgBody
,
handle
,
stableName
);
stableName
);
mnodeDecTableRef
(
pTable
);
mnodeDecTableRef
(
pTable
);
// even this super table has no corresponding table, still return
// even this super table has no corresponding table, still return
pRsp
->
numOfTables
++
;
int64_t
uid
=
htobe64
(
pTable
->
uid
);
SVgroupsMsg
*
pVgroupMsg
=
(
SVgroupsMsg
*
)
msg
;
SVgroupsMsg
*
pVgroupMsg
=
(
SVgroupsMsg
*
)
msg
;
pVgroupMsg
->
numOfVgroups
=
0
;
pVgroupMsg
->
numOfVgroups
=
0
;
msg
+=
sizeof
(
SVgroupsMsg
);
msg
+=
sizeof
(
SVgroupsMsg
);
}
else
{
}
else
{
SVgroupsMsg
*
pVgroupMsg
=
(
SVgroupsMsg
*
)
msg
;
SVgroupsMsg
*
pVgroupMsg
=
(
SVgroupsMsg
*
)
msg
;
mDebug
(
"msg:%p, app:%p stable:%s, hash:%p sizeOfVgList:%d will be returned"
,
pMsg
,
pMsg
->
rpcMsg
.
a
handle
,
mDebug
(
"msg:%p, app:%p stable:%s, hash:%p sizeOfVgList:%d will be returned"
,
pMsgBody
,
handle
,
pTable
->
info
.
tableId
,
pTable
->
vgHash
,
taosHashGetSize
(
pTable
->
vgHash
));
pTable
->
info
.
tableId
,
pTable
->
vgHash
,
taosHashGetSize
(
pTable
->
vgHash
));
int32_t
*
pVgId
=
taosHashIterate
(
pTable
->
vgHash
,
NULL
);
int32_t
*
pVgId
=
taosHashIterate
(
pTable
->
vgHash
,
NULL
);
...
@@ -1763,7 +1748,9 @@ static int32_t mnodeProcessSuperTableVgroupMsg(SMnodeMsg *pMsg) {
...
@@ -1763,7 +1748,9 @@ static int32_t mnodeProcessSuperTableVgroupMsg(SMnodeMsg *pMsg) {
while
(
pVgId
)
{
while
(
pVgId
)
{
SVgObj
*
pVgroup
=
mnodeGetVgroup
(
*
pVgId
);
SVgObj
*
pVgroup
=
mnodeGetVgroup
(
*
pVgId
);
pVgId
=
taosHashIterate
(
pTable
->
vgHash
,
pVgId
);
pVgId
=
taosHashIterate
(
pTable
->
vgHash
,
pVgId
);
if
(
pVgroup
==
NULL
)
continue
;
if
(
pVgroup
==
NULL
)
{
continue
;
}
pVgroupMsg
->
vgroups
[
vgSize
].
vgId
=
htonl
(
pVgroup
->
vgId
);
pVgroupMsg
->
vgroups
[
vgSize
].
vgId
=
htonl
(
pVgroup
->
vgId
);
pVgroupMsg
->
vgroups
[
vgSize
].
numOfEps
=
0
;
pVgroupMsg
->
vgroups
[
vgSize
].
numOfEps
=
0
;
...
@@ -1789,8 +1776,88 @@ static int32_t mnodeProcessSuperTableVgroupMsg(SMnodeMsg *pMsg) {
...
@@ -1789,8 +1776,88 @@ static int32_t mnodeProcessSuperTableVgroupMsg(SMnodeMsg *pMsg) {
// one table is done, try the next table
// one table is done, try the next table
msg
+=
sizeof
(
SVgroupsMsg
)
+
vgSize
*
sizeof
(
SVgroupMsg
);
msg
+=
sizeof
(
SVgroupsMsg
)
+
vgSize
*
sizeof
(
SVgroupMsg
);
pRsp
->
numOfTables
++
;
}
}
return
msg
;
}
static
int32_t
mnodeProcessSuperTableVgroupMsg
(
SMnodeMsg
*
pMsg
)
{
SSTableVgroupMsg
*
pInfo
=
pMsg
->
rpcMsg
.
pCont
;
int32_t
numOfTable
=
htonl
(
pInfo
->
numOfTables
);
// calculate the required space.
int32_t
contLen
=
calculateVgroupMsgLength
(
pInfo
,
numOfTable
);
SSTableVgroupRspMsg
*
pRsp
=
rpcMallocCont
(
contLen
);
if
(
pRsp
==
NULL
)
{
return
TSDB_CODE_MND_OUT_OF_MEMORY
;
}
pRsp
->
numOfTables
=
0
;
char
*
msg
=
(
char
*
)
pRsp
+
sizeof
(
SSTableVgroupRspMsg
);
for
(
int32_t
i
=
0
;
i
<
numOfTable
;
++
i
)
{
char
*
stableName
=
(
char
*
)
pInfo
+
sizeof
(
SSTableVgroupMsg
)
+
(
TSDB_TABLE_FNAME_LEN
)
*
i
;
SSTableObj
*
pTable
=
mnodeGetSuperTable
(
stableName
);
if
(
pTable
==
NULL
)
{
mError
(
"msg:%p, app:%p stable:%s, not exist while get stable vgroup info"
,
pMsg
,
pMsg
->
rpcMsg
.
ahandle
,
stableName
);
mnodeDecTableRef
(
pTable
);
continue
;
}
msg
=
serializeVgroupInfo
(
pTable
,
msg
,
pMsg
,
pMsg
->
rpcMsg
.
ahandle
);
pRsp
->
numOfTables
++
;
// if (pTable->vgHash == NULL) {
// mDebug("msg:%p, app:%p stable:%s, no vgroup exist while get stable vgroup info", pMsg, pMsg->rpcMsg.ahandle,
// stableName);
// mnodeDecTableRef(pTable);
//
// // even this super table has no corresponding table, still return
// pRsp->numOfTables++;
//
// SVgroupsMsg *pVgroupMsg = (SVgroupsMsg *)msg;
// pVgroupMsg->numOfVgroups = 0;
//
// msg += sizeof(SVgroupsMsg);
// } else {
// SVgroupsMsg *pVgroupMsg = (SVgroupsMsg *)msg;
// mDebug("msg:%p, app:%p stable:%s, hash:%p sizeOfVgList:%d will be returned", pMsg, pMsg->rpcMsg.ahandle,
// pTable->info.tableId, pTable->vgHash, taosHashGetSize(pTable->vgHash));
//
// int32_t *pVgId = taosHashIterate(pTable->vgHash, NULL);
// int32_t vgSize = 0;
// while (pVgId) {
// SVgObj *pVgroup = mnodeGetVgroup(*pVgId);
// pVgId = taosHashIterate(pTable->vgHash, pVgId);
// if (pVgroup == NULL) continue;
//
// pVgroupMsg->vgroups[vgSize].vgId = htonl(pVgroup->vgId);
// pVgroupMsg->vgroups[vgSize].numOfEps = 0;
//
// for (int32_t vn = 0; vn < pVgroup->numOfVnodes; ++vn) {
// SDnodeObj *pDnode = pVgroup->vnodeGid[vn].pDnode;
// if (pDnode == NULL) break;
//
// tstrncpy(pVgroupMsg->vgroups[vgSize].epAddr[vn].fqdn, pDnode->dnodeFqdn, TSDB_FQDN_LEN);
// pVgroupMsg->vgroups[vgSize].epAddr[vn].port = htons(pDnode->dnodePort);
//
// pVgroupMsg->vgroups[vgSize].numOfEps++;
// }
//
// vgSize++;
// mnodeDecVgroupRef(pVgroup);
// }
//
// taosHashCancelIterate(pTable->vgHash, pVgId);
// mnodeDecTableRef(pTable);
//
// pVgroupMsg->numOfVgroups = htonl(vgSize);
//
// // one table is done, try the next table
// msg += sizeof(SVgroupsMsg) + vgSize * sizeof(SVgroupMsg);
// pRsp->numOfTables++;
// }
}
}
if
(
pRsp
->
numOfTables
!=
numOfTable
)
{
if
(
pRsp
->
numOfTables
!=
numOfTable
)
{
...
@@ -2818,14 +2885,13 @@ static void mnodeProcessAlterTableRsp(SRpcMsg *rpcMsg) {
...
@@ -2818,14 +2885,13 @@ static void mnodeProcessAlterTableRsp(SRpcMsg *rpcMsg) {
}
}
}
}
//TODO. set the vgroup info for the super table
static
int32_t
mnodeProcessMultiTableMetaMsg
(
SMnodeMsg
*
pMsg
)
{
static
int32_t
mnodeProcessMultiTableMetaMsg
(
SMnodeMsg
*
pMsg
)
{
SMultiTableInfoMsg
*
pInfo
=
pMsg
->
rpcMsg
.
pCont
;
SMultiTableInfoMsg
*
pInfo
=
pMsg
->
rpcMsg
.
pCont
;
pInfo
->
numOfTables
=
htonl
(
pInfo
->
numOfTables
);
pInfo
->
numOfTables
=
htonl
(
pInfo
->
numOfTables
);
pInfo
->
loadVgroup
=
htonl
(
pInfo
->
loadVgroup
);
pInfo
->
loadVgroup
=
htonl
(
pInfo
->
loadVgroup
);
// first malloc
4
KB, subsequent reallocation will expand the size as twice of the original size
// first malloc
80
KB, subsequent reallocation will expand the size as twice of the original size
int32_t
totalMallocLen
=
4
*
1024
;
int32_t
totalMallocLen
=
sizeof
(
STableMetaMsg
)
+
sizeof
(
SSchema
)
*
(
TSDB_MAX_TAGS
+
TSDB_MAX_COLUMNS
+
16
)
;
SMultiTableMeta
*
pMultiMeta
=
rpcMallocCont
(
totalMallocLen
);
SMultiTableMeta
*
pMultiMeta
=
rpcMallocCont
(
totalMallocLen
);
if
(
pMultiMeta
==
NULL
)
{
if
(
pMultiMeta
==
NULL
)
{
...
@@ -2835,13 +2901,17 @@ static int32_t mnodeProcessMultiTableMetaMsg(SMnodeMsg *pMsg) {
...
@@ -2835,13 +2901,17 @@ static int32_t mnodeProcessMultiTableMetaMsg(SMnodeMsg *pMsg) {
pMultiMeta
->
contLen
=
sizeof
(
SMultiTableMeta
);
pMultiMeta
->
contLen
=
sizeof
(
SMultiTableMeta
);
pMultiMeta
->
numOfTables
=
0
;
pMultiMeta
->
numOfTables
=
0
;
SArray
*
pList
=
taosArrayInit
(
4
,
POINTER_BYTES
);
for
(
int32_t
t
=
0
;
t
<
pInfo
->
numOfTables
;
++
t
)
{
for
(
int32_t
t
=
0
;
t
<
pInfo
->
numOfTables
;
++
t
)
{
char
*
fullName
=
(
char
*
)(
pInfo
->
tableNames
+
t
*
TSDB_TABLE_FNAME_LEN
);
char
*
fullName
=
(
char
*
)(
pInfo
->
tableNames
+
t
*
TSDB_TABLE_FNAME_LEN
);
if
(
pMsg
->
pTable
==
NULL
)
{
if
(
pMsg
->
pTable
==
NULL
)
{
pMsg
->
pTable
=
mnodeGetTable
(
fullName
);
pMsg
->
pTable
=
mnodeGetTable
(
fullName
);
if
(
pMsg
->
pTable
==
NULL
)
{
// TODO: return error to client?
if
(
pMsg
->
pTable
==
NULL
)
{
continue
;
rpcFreeCont
(
pMultiMeta
);
mError
(
"msg:%p, app:%p table:%s, failed to get table meta, table not exist"
,
pMsg
,
pMsg
->
rpcMsg
.
ahandle
,
fullName
);
return
TSDB_CODE_MND_INVALID_TABLE_NAME
;
}
}
}
}
...
@@ -2850,8 +2920,9 @@ static int32_t mnodeProcessMultiTableMetaMsg(SMnodeMsg *pMsg) {
...
@@ -2850,8 +2920,9 @@ static int32_t mnodeProcessMultiTableMetaMsg(SMnodeMsg *pMsg) {
}
}
if
(
pMsg
->
pDb
==
NULL
||
pMsg
->
pDb
->
status
!=
TSDB_DB_STATUS_READY
)
{
if
(
pMsg
->
pDb
==
NULL
||
pMsg
->
pDb
->
status
!=
TSDB_DB_STATUS_READY
)
{
mnodeDecTableRef
(
pMsg
->
pTable
);
// TODO: return error to client?
rpcFreeCont
(
pMultiMeta
);
continue
;
mnodeDecTableRef
(
pMsg
->
pTable
);
return
TSDB_CODE_APP_NOT_READY
;
}
}
int
availLen
=
totalMallocLen
-
pMultiMeta
->
contLen
;
int
availLen
=
totalMallocLen
-
pMultiMeta
->
contLen
;
...
@@ -2864,13 +2935,14 @@ static int32_t mnodeProcessMultiTableMetaMsg(SMnodeMsg *pMsg) {
...
@@ -2864,13 +2935,14 @@ static int32_t mnodeProcessMultiTableMetaMsg(SMnodeMsg *pMsg) {
}
}
}
}
STableMetaMsg
*
pMeta
=
(
STableMetaMsg
*
)(
pMultiMeta
->
m
eta
+
pMultiMeta
->
contLen
);
STableMetaMsg
*
pMeta
=
(
STableMetaMsg
*
)(
(
char
*
)
pMultiM
eta
+
pMultiMeta
->
contLen
);
int32_t
code
=
0
;
int32_t
code
=
0
;
if
(
pMsg
->
pTable
->
type
!=
TSDB_SUPER_TABLE
)
{
if
(
pMsg
->
pTable
->
type
!=
TSDB_SUPER_TABLE
)
{
code
=
mnodeDoGetChildTableMeta
(
pMsg
,
pMeta
);
code
=
mnodeDoGetChildTableMeta
(
pMsg
,
pMeta
);
}
else
{
}
else
{
code
=
mnodeDoGetSuperTableMeta
(
pMsg
,
pMeta
);
code
=
mnodeDoGetSuperTableMeta
(
pMsg
,
pMeta
);
taosArrayPush
(
pList
,
fullName
);
// keep the super table full name
}
}
if
(
code
==
TSDB_CODE_SUCCESS
)
{
if
(
code
==
TSDB_CODE_SUCCESS
)
{
...
@@ -2881,6 +2953,23 @@ static int32_t mnodeProcessMultiTableMetaMsg(SMnodeMsg *pMsg) {
...
@@ -2881,6 +2953,23 @@ static int32_t mnodeProcessMultiTableMetaMsg(SMnodeMsg *pMsg) {
mnodeDecTableRef
(
pMsg
->
pTable
);
mnodeDecTableRef
(
pMsg
->
pTable
);
}
}
char
*
msg
=
(
char
*
)
pMultiMeta
+
pMultiMeta
->
contLen
;
for
(
int32_t
i
=
0
;
i
<
taosArrayGetSize
(
pList
);
++
i
)
{
char
*
name
=
taosArrayGet
(
pList
,
i
);
SSTableObj
*
pTable
=
mnodeGetSuperTable
(
name
);
if
(
pTable
==
NULL
)
{
mError
(
"msg:%p, app:%p stable:%s, not exist while get stable vgroup info"
,
pMsg
,
pMsg
->
rpcMsg
.
ahandle
,
stableName
);
mnodeDecTableRef
(
pTable
);
continue
;
}
msg
=
serializeVgroupInfo
(
pTable
,
msg
,
pMsg
,
pMsg
->
rpcMsg
.
ahandle
);
}
pMultiMeta
->
contLen
=
(
msg
-
(
char
*
)
pMultiMeta
);
pMultiMeta
->
numOfTables
=
htonl
(
pMultiMeta
->
numOfTables
);
pMsg
->
rpcRsp
.
rsp
=
pMultiMeta
;
pMsg
->
rpcRsp
.
rsp
=
pMultiMeta
;
pMsg
->
rpcRsp
.
len
=
pMultiMeta
->
contLen
;
pMsg
->
rpcRsp
.
len
=
pMultiMeta
->
contLen
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录