Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
冷面1992
TDengine
提交
5d4f826b
TDengine
项目概览
冷面1992
/
TDengine
与 Fork 源项目一致
Fork自
taosdata / TDengine
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
5d4f826b
编写于
3月 19, 2020
作者:
H
hjxilinx
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[TD-32] fix bugs in get table meta (parsing query sql)
上级
d1828544
变更
22
隐藏空白更改
内联
并排
Showing
22 changed file
with
242 addition
and
231 deletion
+242
-231
src/client/inc/tscUtil.h
src/client/inc/tscUtil.h
+1
-1
src/client/inc/tsclient.h
src/client/inc/tsclient.h
+7
-6
src/client/src/tscAsync.c
src/client/src/tscAsync.c
+3
-3
src/client/src/tscJoinProcess.c
src/client/src/tscJoinProcess.c
+2
-2
src/client/src/tscLocal.c
src/client/src/tscLocal.c
+1
-1
src/client/src/tscParseInsert.c
src/client/src/tscParseInsert.c
+6
-6
src/client/src/tscPrepare.c
src/client/src/tscPrepare.c
+2
-2
src/client/src/tscSQLParser.c
src/client/src/tscSQLParser.c
+3
-3
src/client/src/tscSchemaUtil.c
src/client/src/tscSchemaUtil.c
+16
-0
src/client/src/tscSecondaryMerge.c
src/client/src/tscSecondaryMerge.c
+3
-3
src/client/src/tscServer.c
src/client/src/tscServer.c
+50
-50
src/client/src/tscStream.c
src/client/src/tscStream.c
+2
-2
src/client/src/tscSub.c
src/client/src/tscSub.c
+2
-2
src/client/src/tscUtil.c
src/client/src/tscUtil.c
+4
-4
src/inc/mnode.h
src/inc/mnode.h
+2
-2
src/inc/taosmsg.h
src/inc/taosmsg.h
+7
-8
src/mnode/src/mgmtChildTable.c
src/mnode/src/mgmtChildTable.c
+1
-2
src/mnode/src/mgmtNormalTable.c
src/mnode/src/mgmtNormalTable.c
+3
-1
src/mnode/src/mgmtTable.c
src/mnode/src/mgmtTable.c
+2
-1
src/mnode/src/mgmtVgroup.c
src/mnode/src/mgmtVgroup.c
+0
-1
src/util/inc/tcache.h
src/util/inc/tcache.h
+6
-6
src/util/src/tcache.c
src/util/src/tcache.c
+119
-125
未找到文件。
src/client/inc/tscUtil.h
浏览文件 @
5d4f826b
...
@@ -190,7 +190,7 @@ void tscCleanSqlCmd(SSqlCmd* pCmd);
...
@@ -190,7 +190,7 @@ void tscCleanSqlCmd(SSqlCmd* pCmd);
bool
tscShouldFreeAsyncSqlObj
(
SSqlObj
*
pSql
);
bool
tscShouldFreeAsyncSqlObj
(
SSqlObj
*
pSql
);
void
tscRemoveAllMeterMetaInfo
(
SQueryInfo
*
pQueryInfo
,
const
char
*
address
,
bool
removeFromCache
);
void
tscRemoveAllMeterMetaInfo
(
SQueryInfo
*
pQueryInfo
,
const
char
*
address
,
bool
removeFromCache
);
STableMetaInfo
*
tscGet
MeterMetaInfo
(
SSqlCmd
*
pCmd
,
int32_t
subClauseIndex
,
int32_t
tableIndex
);
STableMetaInfo
*
tscGet
TableMetaInfoFromCmd
(
SSqlCmd
*
pCmd
,
int32_t
subClauseIndex
,
int32_t
tableIndex
);
STableMetaInfo
*
tscGetMetaInfo
(
SQueryInfo
*
pQueryInfo
,
int32_t
tableIndex
);
STableMetaInfo
*
tscGetMetaInfo
(
SQueryInfo
*
pQueryInfo
,
int32_t
tableIndex
);
SQueryInfo
*
tscGetQueryInfoDetail
(
SSqlCmd
*
pCmd
,
int32_t
subClauseIndex
);
SQueryInfo
*
tscGetQueryInfoDetail
(
SSqlCmd
*
pCmd
,
int32_t
subClauseIndex
);
...
...
src/client/inc/tsclient.h
浏览文件 @
5d4f826b
...
@@ -20,18 +20,19 @@
...
@@ -20,18 +20,19 @@
extern
"C"
{
extern
"C"
{
#endif
#endif
#include <tarray.h>
#include "os.h"
#include "os.h"
#include "qsqlparser.h"
#include "qsqltype.h"
#include "qtsbuf.h"
#include "taos.h"
#include "taos.h"
#include "taosdef.h"
#include "taosmsg.h"
#include "taosmsg.h"
#include "tglobalcfg.h"
#include "tglobalcfg.h"
#include "tlog.h"
#include "tlog.h"
#include "t
aosdef
.h"
#include "t
rpc
.h"
#include "tsqlfunction.h"
#include "tsqlfunction.h"
#include "tutil.h"
#include "tutil.h"
#include "trpc.h"
#include "qsqltype.h"
#include "qsqlparser.h"
#include "qtsbuf.h"
#define TSC_GET_RESPTR_BASE(res, _queryinfo, col) (res->data + ((_queryinfo)->fieldsInfo.pSqlExpr[col]->offset) * res->numOfRows)
#define TSC_GET_RESPTR_BASE(res, _queryinfo, col) (res->data + ((_queryinfo)->fieldsInfo.pSqlExpr[col]->offset) * res->numOfRows)
...
@@ -68,8 +69,8 @@ typedef struct STableMeta {
...
@@ -68,8 +69,8 @@ typedef struct STableMeta {
int16_t
sversion
;
int16_t
sversion
;
int8_t
numOfVpeers
;
int8_t
numOfVpeers
;
SVnodeDesc
vpeerDesc
[
TSDB_VNODES_SUPPORT
];
SVnodeDesc
vpeerDesc
[
TSDB_VNODES_SUPPORT
];
int32_t
sid
;
int32_t
vgid
;
int32_t
vgid
;
int32_t
sid
;
uint64_t
uid
;
uint64_t
uid
;
// if the table is TSDB_CHILD_TABLE, schema is acquired by super table meta info
// if the table is TSDB_CHILD_TABLE, schema is acquired by super table meta info
...
...
src/client/src/tscAsync.c
浏览文件 @
5d4f826b
...
@@ -465,7 +465,7 @@ void tscTableMetaCallBack(void *param, TAOS_RES *res, int code) {
...
@@ -465,7 +465,7 @@ void tscTableMetaCallBack(void *param, TAOS_RES *res, int code) {
tscTrace
(
"%p renew tableMeta successfully, command:%d, code:%d, retry:%d"
,
tscTrace
(
"%p renew tableMeta successfully, command:%d, code:%d, retry:%d"
,
pSql
,
pSql
->
cmd
.
command
,
pSql
->
res
.
code
,
pSql
->
retry
);
pSql
,
pSql
->
cmd
.
command
,
pSql
->
res
.
code
,
pSql
->
retry
);
STableMetaInfo
*
pTableMetaInfo
=
tscGet
MeterMetaInfo
(
&
pSql
->
cmd
,
0
,
0
);
STableMetaInfo
*
pTableMetaInfo
=
tscGet
TableMetaInfoFromCmd
(
&
pSql
->
cmd
,
0
,
0
);
assert
(
pTableMetaInfo
->
pTableMeta
==
NULL
);
assert
(
pTableMetaInfo
->
pTableMeta
==
NULL
);
tscGetTableMeta
(
pSql
,
pTableMetaInfo
);
tscGetTableMeta
(
pSql
,
pTableMetaInfo
);
...
@@ -514,7 +514,7 @@ void tscTableMetaCallBack(void *param, TAOS_RES *res, int code) {
...
@@ -514,7 +514,7 @@ void tscTableMetaCallBack(void *param, TAOS_RES *res, int code) {
if
(
pCmd
->
isParseFinish
)
{
if
(
pCmd
->
isParseFinish
)
{
tscTrace
(
"%p resend data to vnode in metermeta callback since sql has been parsed completed"
,
pSql
);
tscTrace
(
"%p resend data to vnode in metermeta callback since sql has been parsed completed"
,
pSql
);
STableMetaInfo
*
pTableMetaInfo
=
tscGet
MeterMetaInfo
(
pCmd
,
pCmd
->
clauseIndex
,
0
);
STableMetaInfo
*
pTableMetaInfo
=
tscGet
TableMetaInfoFromCmd
(
pCmd
,
pCmd
->
clauseIndex
,
0
);
code
=
tscGetTableMeta
(
pSql
,
pTableMetaInfo
);
code
=
tscGetTableMeta
(
pSql
,
pTableMetaInfo
);
assert
(
code
==
TSDB_CODE_SUCCESS
);
assert
(
code
==
TSDB_CODE_SUCCESS
);
...
@@ -529,7 +529,7 @@ void tscTableMetaCallBack(void *param, TAOS_RES *res, int code) {
...
@@ -529,7 +529,7 @@ void tscTableMetaCallBack(void *param, TAOS_RES *res, int code) {
}
}
}
else
{
// stream computing
}
else
{
// stream computing
STableMetaInfo
*
pTableMetaInfo
=
tscGet
MeterMetaInfo
(
pCmd
,
pCmd
->
clauseIndex
,
0
);
STableMetaInfo
*
pTableMetaInfo
=
tscGet
TableMetaInfoFromCmd
(
pCmd
,
pCmd
->
clauseIndex
,
0
);
code
=
tscGetTableMeta
(
pSql
,
pTableMetaInfo
);
code
=
tscGetTableMeta
(
pSql
,
pTableMetaInfo
);
pRes
->
code
=
code
;
pRes
->
code
=
code
;
...
...
src/client/src/tscJoinProcess.c
浏览文件 @
5d4f826b
...
@@ -164,7 +164,7 @@ SJoinSubquerySupporter* tscCreateJoinSupporter(SSqlObj* pSql, SSubqueryState* pS
...
@@ -164,7 +164,7 @@ SJoinSubquerySupporter* tscCreateJoinSupporter(SSqlObj* pSql, SSubqueryState* pS
pSupporter
->
interval
=
pQueryInfo
->
intervalTime
;
pSupporter
->
interval
=
pQueryInfo
->
intervalTime
;
pSupporter
->
limit
=
pQueryInfo
->
limit
;
pSupporter
->
limit
=
pQueryInfo
->
limit
;
STableMetaInfo
*
pTableMetaInfo
=
tscGet
MeterMetaInfo
(
&
pSql
->
cmd
,
pSql
->
cmd
.
clauseIndex
,
index
);
STableMetaInfo
*
pTableMetaInfo
=
tscGet
TableMetaInfoFromCmd
(
&
pSql
->
cmd
,
pSql
->
cmd
.
clauseIndex
,
index
);
pSupporter
->
uid
=
pTableMetaInfo
->
pTableMeta
->
uid
;
pSupporter
->
uid
=
pTableMetaInfo
->
pTableMeta
->
uid
;
assert
(
pSupporter
->
uid
!=
0
);
assert
(
pSupporter
->
uid
!=
0
);
...
@@ -712,7 +712,7 @@ void tscSetupOutputColumnIndex(SSqlObj* pSql) {
...
@@ -712,7 +712,7 @@ void tscSetupOutputColumnIndex(SSqlObj* pSql) {
void
tscJoinQueryCallback
(
void
*
param
,
TAOS_RES
*
tres
,
int
code
)
{
void
tscJoinQueryCallback
(
void
*
param
,
TAOS_RES
*
tres
,
int
code
)
{
SSqlObj
*
pSql
=
(
SSqlObj
*
)
tres
;
SSqlObj
*
pSql
=
(
SSqlObj
*
)
tres
;
// STableMetaInfo *pTableMetaInfo = tscGet
MeterMetaInfo
(&pSql->cmd, 0, 0);
// STableMetaInfo *pTableMetaInfo = tscGet
TableMetaInfoFromCmd
(&pSql->cmd, 0, 0);
// int32_t idx = pSql->cmd.vnodeIdx;
// int32_t idx = pSql->cmd.vnodeIdx;
...
...
src/client/src/tscLocal.c
浏览文件 @
5d4f826b
...
@@ -77,7 +77,7 @@ static int32_t getToStringLength(const char *pData, int32_t length, int32_t type
...
@@ -77,7 +77,7 @@ static int32_t getToStringLength(const char *pData, int32_t length, int32_t type
* length((uint64_t) 123456789011) > 12, greater than sizsof(uint64_t)
* length((uint64_t) 123456789011) > 12, greater than sizsof(uint64_t)
*/
*/
static
int32_t
tscMaxLengthOfTagsFields
(
SSqlObj
*
pSql
)
{
static
int32_t
tscMaxLengthOfTagsFields
(
SSqlObj
*
pSql
)
{
STableMeta
*
pMeta
=
tscGet
MeterMetaInfo
(
&
pSql
->
cmd
,
0
,
0
)
->
pTableMeta
;
STableMeta
*
pMeta
=
tscGet
TableMetaInfoFromCmd
(
&
pSql
->
cmd
,
0
,
0
)
->
pTableMeta
;
if
(
pMeta
->
tableType
==
TSDB_SUPER_TABLE
||
pMeta
->
tableType
==
TSDB_NORMAL_TABLE
||
if
(
pMeta
->
tableType
==
TSDB_SUPER_TABLE
||
pMeta
->
tableType
==
TSDB_NORMAL_TABLE
||
pMeta
->
tableType
==
TSDB_STREAM_TABLE
)
{
pMeta
->
tableType
==
TSDB_STREAM_TABLE
)
{
...
...
src/client/src/tscParseInsert.c
浏览文件 @
5d4f826b
...
@@ -656,7 +656,7 @@ void sortRemoveDuplicates(STableDataBlocks *dataBuf) {
...
@@ -656,7 +656,7 @@ void sortRemoveDuplicates(STableDataBlocks *dataBuf) {
static
int32_t
doParseInsertStatement
(
SSqlObj
*
pSql
,
void
*
pTableHashList
,
char
**
str
,
SParsedDataColInfo
*
spd
,
static
int32_t
doParseInsertStatement
(
SSqlObj
*
pSql
,
void
*
pTableHashList
,
char
**
str
,
SParsedDataColInfo
*
spd
,
int32_t
*
totalNum
)
{
int32_t
*
totalNum
)
{
SSqlCmd
*
pCmd
=
&
pSql
->
cmd
;
SSqlCmd
*
pCmd
=
&
pSql
->
cmd
;
STableMetaInfo
*
pTableMetaInfo
=
tscGet
MeterMetaInfo
(
pCmd
,
pCmd
->
clauseIndex
,
0
);
STableMetaInfo
*
pTableMetaInfo
=
tscGet
TableMetaInfoFromCmd
(
pCmd
,
pCmd
->
clauseIndex
,
0
);
STableMeta
*
pTableMeta
=
pTableMetaInfo
->
pTableMeta
;
STableMeta
*
pTableMeta
=
pTableMetaInfo
->
pTableMeta
;
STableInfo
tinfo
=
tscGetTableInfo
(
pTableMeta
);
STableInfo
tinfo
=
tscGetTableInfo
(
pTableMeta
);
...
@@ -1155,7 +1155,7 @@ int doParseInsertSql(SSqlObj *pSql, char *str) {
...
@@ -1155,7 +1155,7 @@ int doParseInsertSql(SSqlObj *pSql, char *str) {
strcpy
(
pDataBlock
->
filename
,
fname
);
strcpy
(
pDataBlock
->
filename
,
fname
);
}
else
if
(
sToken
.
type
==
TK_LP
)
{
}
else
if
(
sToken
.
type
==
TK_LP
)
{
/* insert into tablename(col1, col2,..., coln) values(v1, v2,... vn); */
/* insert into tablename(col1, col2,..., coln) values(v1, v2,... vn); */
STableMeta
*
pTableMeta
=
tscGet
MeterMetaInfo
(
pCmd
,
pCmd
->
clauseIndex
,
0
)
->
pTableMeta
;
STableMeta
*
pTableMeta
=
tscGet
TableMetaInfoFromCmd
(
pCmd
,
pCmd
->
clauseIndex
,
0
)
->
pTableMeta
;
SSchema
*
pSchema
=
tscGetTableSchema
(
pTableMeta
);
SSchema
*
pSchema
=
tscGetTableSchema
(
pTableMeta
);
if
(
validateDataSource
(
pCmd
,
DATA_FROM_SQL_STRING
,
sToken
.
z
)
!=
TSDB_CODE_SUCCESS
)
{
if
(
validateDataSource
(
pCmd
,
DATA_FROM_SQL_STRING
,
sToken
.
z
)
!=
TSDB_CODE_SUCCESS
)
{
...
@@ -1252,7 +1252,7 @@ int doParseInsertSql(SSqlObj *pSql, char *str) {
...
@@ -1252,7 +1252,7 @@ int doParseInsertSql(SSqlObj *pSql, char *str) {
goto
_error_clean
;
goto
_error_clean
;
}
}
pTableMetaInfo
=
tscGet
MeterMetaInfo
(
&
pSql
->
cmd
,
0
,
0
);
pTableMetaInfo
=
tscGet
TableMetaInfoFromCmd
(
&
pSql
->
cmd
,
0
,
0
);
// set the next sent data vnode index in data block arraylist
// set the next sent data vnode index in data block arraylist
pTableMetaInfo
->
vnodeIndex
=
1
;
pTableMetaInfo
->
vnodeIndex
=
1
;
...
@@ -1355,7 +1355,7 @@ static int doPackSendDataBlock(SSqlObj *pSql, int32_t numOfRows, STableDataBlock
...
@@ -1355,7 +1355,7 @@ static int doPackSendDataBlock(SSqlObj *pSql, int32_t numOfRows, STableDataBlock
SSqlCmd
*
pCmd
=
&
pSql
->
cmd
;
SSqlCmd
*
pCmd
=
&
pSql
->
cmd
;
assert
(
pCmd
->
numOfClause
==
1
);
assert
(
pCmd
->
numOfClause
==
1
);
STableMeta
*
pTableMeta
=
tscGet
MeterMetaInfo
(
pCmd
,
pCmd
->
clauseIndex
,
0
)
->
pTableMeta
;
STableMeta
*
pTableMeta
=
tscGet
TableMetaInfoFromCmd
(
pCmd
,
pCmd
->
clauseIndex
,
0
)
->
pTableMeta
;
SShellSubmitBlock
*
pBlocks
=
(
SShellSubmitBlock
*
)(
pTableDataBlocks
->
pData
);
SShellSubmitBlock
*
pBlocks
=
(
SShellSubmitBlock
*
)(
pTableDataBlocks
->
pData
);
tsSetBlockInfo
(
pBlocks
,
pTableMeta
,
numOfRows
);
tsSetBlockInfo
(
pBlocks
,
pTableMeta
,
numOfRows
);
...
@@ -1388,7 +1388,7 @@ static int tscInsertDataFromFile(SSqlObj *pSql, FILE *fp, char *tmpTokenBuf) {
...
@@ -1388,7 +1388,7 @@ static int tscInsertDataFromFile(SSqlObj *pSql, FILE *fp, char *tmpTokenBuf) {
int32_t
code
=
0
;
int32_t
code
=
0
;
int
nrows
=
0
;
int
nrows
=
0
;
STableMetaInfo
*
pTableMetaInfo
=
tscGet
MeterMetaInfo
(
pCmd
,
pCmd
->
clauseIndex
,
0
);
STableMetaInfo
*
pTableMetaInfo
=
tscGet
TableMetaInfoFromCmd
(
pCmd
,
pCmd
->
clauseIndex
,
0
);
STableMeta
*
pTableMeta
=
pTableMetaInfo
->
pTableMeta
;
STableMeta
*
pTableMeta
=
pTableMetaInfo
->
pTableMeta
;
STableInfo
tinfo
=
tscGetTableInfo
(
pTableMeta
);
STableInfo
tinfo
=
tscGetTableInfo
(
pTableMeta
);
...
@@ -1482,7 +1482,7 @@ void tscProcessMultiVnodesInsert(SSqlObj *pSql) {
...
@@ -1482,7 +1482,7 @@ void tscProcessMultiVnodesInsert(SSqlObj *pSql) {
}
}
STableDataBlocks
*
pDataBlock
=
NULL
;
STableDataBlocks
*
pDataBlock
=
NULL
;
STableMetaInfo
*
pTableMetaInfo
=
tscGet
MeterMetaInfo
(
pCmd
,
pCmd
->
clauseIndex
,
0
);
STableMetaInfo
*
pTableMetaInfo
=
tscGet
TableMetaInfoFromCmd
(
pCmd
,
pCmd
->
clauseIndex
,
0
);
assert
(
pCmd
->
numOfClause
==
1
);
assert
(
pCmd
->
numOfClause
==
1
);
int32_t
code
=
TSDB_CODE_SUCCESS
;
int32_t
code
=
TSDB_CODE_SUCCESS
;
...
...
src/client/src/tscPrepare.c
浏览文件 @
5d4f826b
...
@@ -407,7 +407,7 @@ static int insertStmtReset(STscStmt* pStmt) {
...
@@ -407,7 +407,7 @@ static int insertStmtReset(STscStmt* pStmt) {
}
}
pCmd
->
batchSize
=
0
;
pCmd
->
batchSize
=
0
;
STableMetaInfo
*
pTableMetaInfo
=
tscGet
MeterMetaInfo
(
pCmd
,
pCmd
->
clauseIndex
,
0
);
STableMetaInfo
*
pTableMetaInfo
=
tscGet
TableMetaInfoFromCmd
(
pCmd
,
pCmd
->
clauseIndex
,
0
);
pTableMetaInfo
->
vnodeIndex
=
0
;
pTableMetaInfo
->
vnodeIndex
=
0
;
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
...
@@ -421,7 +421,7 @@ static int insertStmtExecute(STscStmt* stmt) {
...
@@ -421,7 +421,7 @@ static int insertStmtExecute(STscStmt* stmt) {
++
pCmd
->
batchSize
;
++
pCmd
->
batchSize
;
}
}
STableMetaInfo
*
pTableMetaInfo
=
tscGet
MeterMetaInfo
(
pCmd
,
pCmd
->
clauseIndex
,
0
);
STableMetaInfo
*
pTableMetaInfo
=
tscGet
TableMetaInfoFromCmd
(
pCmd
,
pCmd
->
clauseIndex
,
0
);
assert
(
pCmd
->
numOfClause
==
1
);
assert
(
pCmd
->
numOfClause
==
1
);
if
(
pCmd
->
pDataBlocks
->
nSize
>
0
)
{
if
(
pCmd
->
pDataBlocks
->
nSize
>
0
)
{
...
...
src/client/src/tscSQLParser.c
浏览文件 @
5d4f826b
...
@@ -896,7 +896,7 @@ bool validateOneTags(SSqlCmd* pCmd, TAOS_FIELD* pTagField) {
...
@@ -896,7 +896,7 @@ bool validateOneTags(SSqlCmd* pCmd, TAOS_FIELD* pTagField) {
assert
(
pCmd
->
numOfClause
==
1
);
assert
(
pCmd
->
numOfClause
==
1
);
STableMetaInfo
*
pTableMetaInfo
=
tscGet
MeterMetaInfo
(
pCmd
,
pCmd
->
clauseIndex
,
0
);
STableMetaInfo
*
pTableMetaInfo
=
tscGet
TableMetaInfoFromCmd
(
pCmd
,
pCmd
->
clauseIndex
,
0
);
STableMeta
*
pTableMeta
=
pTableMetaInfo
->
pTableMeta
;
STableMeta
*
pTableMeta
=
pTableMetaInfo
->
pTableMeta
;
int32_t
numOfTags
=
tscGetNumOfTags
(
pTableMeta
);
int32_t
numOfTags
=
tscGetNumOfTags
(
pTableMeta
);
...
@@ -969,7 +969,7 @@ bool validateOneColumn(SSqlCmd* pCmd, TAOS_FIELD* pColField) {
...
@@ -969,7 +969,7 @@ bool validateOneColumn(SSqlCmd* pCmd, TAOS_FIELD* pColField) {
const
char
*
msg6
=
"invalid column length"
;
const
char
*
msg6
=
"invalid column length"
;
assert
(
pCmd
->
numOfClause
==
1
);
assert
(
pCmd
->
numOfClause
==
1
);
STableMetaInfo
*
pTableMetaInfo
=
tscGet
MeterMetaInfo
(
pCmd
,
pCmd
->
clauseIndex
,
0
);
STableMetaInfo
*
pTableMetaInfo
=
tscGet
TableMetaInfoFromCmd
(
pCmd
,
pCmd
->
clauseIndex
,
0
);
STableMeta
*
pTableMeta
=
pTableMetaInfo
->
pTableMeta
;
STableMeta
*
pTableMeta
=
pTableMetaInfo
->
pTableMeta
;
int32_t
numOfTags
=
tscGetNumOfTags
(
pTableMeta
);
int32_t
numOfTags
=
tscGetNumOfTags
(
pTableMeta
);
...
@@ -2129,7 +2129,7 @@ int32_t changeFunctionID(int32_t optr, int16_t* functionId) {
...
@@ -2129,7 +2129,7 @@ int32_t changeFunctionID(int32_t optr, int16_t* functionId) {
int32_t
setShowInfo
(
SSqlObj
*
pSql
,
struct
SSqlInfo
*
pInfo
)
{
int32_t
setShowInfo
(
SSqlObj
*
pSql
,
struct
SSqlInfo
*
pInfo
)
{
SSqlCmd
*
pCmd
=
&
pSql
->
cmd
;
SSqlCmd
*
pCmd
=
&
pSql
->
cmd
;
STableMetaInfo
*
pTableMetaInfo
=
tscGet
MeterMetaInfo
(
pCmd
,
pCmd
->
clauseIndex
,
0
);
STableMetaInfo
*
pTableMetaInfo
=
tscGet
TableMetaInfoFromCmd
(
pCmd
,
pCmd
->
clauseIndex
,
0
);
assert
(
pCmd
->
numOfClause
==
1
);
assert
(
pCmd
->
numOfClause
==
1
);
pCmd
->
command
=
TSDB_SQL_SHOW
;
pCmd
->
command
=
TSDB_SQL_SHOW
;
...
...
src/client/src/tscSchemaUtil.c
浏览文件 @
5d4f826b
...
@@ -155,9 +155,25 @@ STableMeta* tscCreateTableMetaFromMsg(STableMetaMsg* pTableMetaMsg, size_t* size
...
@@ -155,9 +155,25 @@ STableMeta* tscCreateTableMetaFromMsg(STableMetaMsg* pTableMetaMsg, size_t* size
int32_t
schemaSize
=
(
pTableMetaMsg
->
numOfColumns
+
pTableMetaMsg
->
numOfTags
)
*
sizeof
(
SSchema
);
int32_t
schemaSize
=
(
pTableMetaMsg
->
numOfColumns
+
pTableMetaMsg
->
numOfTags
)
*
sizeof
(
SSchema
);
STableMeta
*
pTableMeta
=
calloc
(
1
,
sizeof
(
STableMeta
)
+
schemaSize
);
STableMeta
*
pTableMeta
=
calloc
(
1
,
sizeof
(
STableMeta
)
+
schemaSize
);
pTableMeta
->
tableType
=
pTableMetaMsg
->
tableType
;
pTableMeta
->
tableInfo
=
(
STableInfo
){.
numOfTags
=
pTableMetaMsg
->
numOfTags
,
.
numOfColumns
=
pTableMetaMsg
->
numOfColumns
,
.
precision
=
pTableMetaMsg
->
precision
};
pTableMeta
->
sid
=
pTableMetaMsg
->
sid
;
pTableMeta
->
uid
=
pTableMetaMsg
->
uid
;
pTableMeta
->
vgid
=
pTableMetaMsg
->
vgid
;
pTableMeta
->
numOfVpeers
=
pTableMetaMsg
->
numOfVpeers
;
memcpy
(
pTableMeta
->
vpeerDesc
,
pTableMetaMsg
->
vpeerDesc
,
sizeof
(
SVnodeDesc
)
*
pTableMeta
->
numOfVpeers
);
// pTableMeta->tableId = pTableMetaMsg->tableId;
memcpy
(
pTableMeta
->
schema
,
pTableMetaMsg
->
schema
,
schemaSize
);
memcpy
(
pTableMeta
->
schema
,
pTableMetaMsg
->
schema
,
schemaSize
);
int32_t
numOfTotalCols
=
pTableMeta
->
tableInfo
.
numOfColumns
+
pTableMeta
->
tableInfo
.
numOfTags
;
for
(
int32_t
i
=
0
;
i
<
numOfTotalCols
;
++
i
)
{
pTableMeta
->
tableInfo
.
rowSize
+=
pTableMeta
->
schema
[
i
].
bytes
;
}
if
(
size
!=
NULL
)
{
if
(
size
!=
NULL
)
{
*
size
=
sizeof
(
STableMeta
)
+
schemaSize
;
*
size
=
sizeof
(
STableMeta
)
+
schemaSize
;
}
}
...
...
src/client/src/tscSecondaryMerge.c
浏览文件 @
5d4f826b
...
@@ -319,7 +319,7 @@ void tscCreateLocalReducer(tExtMemBuffer **pMemBuffer, int32_t numOfBuffer, tOrd
...
@@ -319,7 +319,7 @@ void tscCreateLocalReducer(tExtMemBuffer **pMemBuffer, int32_t numOfBuffer, tOrd
pRes
->
pLocalReducer
=
pReducer
;
pRes
->
pLocalReducer
=
pReducer
;
pRes
->
numOfGroups
=
0
;
pRes
->
numOfGroups
=
0
;
STableMetaInfo
*
pTableMetaInfo
=
tscGet
MeterMetaInfo
(
pCmd
,
pCmd
->
clauseIndex
,
0
);
STableMetaInfo
*
pTableMetaInfo
=
tscGet
TableMetaInfoFromCmd
(
pCmd
,
pCmd
->
clauseIndex
,
0
);
STableInfo
tinfo
=
tscGetTableInfo
(
pTableMetaInfo
->
pTableMeta
);
STableInfo
tinfo
=
tscGetTableInfo
(
pTableMetaInfo
->
pTableMeta
);
int16_t
prec
=
tinfo
.
precision
;
int16_t
prec
=
tinfo
.
precision
;
...
@@ -920,7 +920,7 @@ static void doInterpolateResult(SSqlObj *pSql, SLocalReducer *pLocalReducer, boo
...
@@ -920,7 +920,7 @@ static void doInterpolateResult(SSqlObj *pSql, SLocalReducer *pLocalReducer, boo
functions
[
i
]
=
tscSqlExprGet
(
pQueryInfo
,
i
)
->
functionId
;
functions
[
i
]
=
tscSqlExprGet
(
pQueryInfo
,
i
)
->
functionId
;
}
}
STableMetaInfo
*
pTableMetaInfo
=
tscGet
MeterMetaInfo
(
pCmd
,
pCmd
->
clauseIndex
,
0
);
STableMetaInfo
*
pTableMetaInfo
=
tscGet
TableMetaInfoFromCmd
(
pCmd
,
pCmd
->
clauseIndex
,
0
);
STableInfo
tinfo
=
tscGetTableInfo
(
pTableMetaInfo
->
pTableMeta
);
STableInfo
tinfo
=
tscGetTableInfo
(
pTableMetaInfo
->
pTableMeta
);
int8_t
precision
=
tinfo
.
precision
;
int8_t
precision
=
tinfo
.
precision
;
...
@@ -1273,7 +1273,7 @@ static void resetEnvForNewResultset(SSqlRes *pRes, SSqlCmd *pCmd, SLocalReducer
...
@@ -1273,7 +1273,7 @@ static void resetEnvForNewResultset(SSqlRes *pRes, SSqlCmd *pCmd, SLocalReducer
pQueryInfo
->
limit
.
offset
=
pLocalReducer
->
offset
;
pQueryInfo
->
limit
.
offset
=
pLocalReducer
->
offset
;
STableMetaInfo
*
pTableMetaInfo
=
tscGet
MeterMetaInfo
(
pCmd
,
pCmd
->
clauseIndex
,
0
);
STableMetaInfo
*
pTableMetaInfo
=
tscGet
TableMetaInfoFromCmd
(
pCmd
,
pCmd
->
clauseIndex
,
0
);
STableInfo
tinfo
=
tscGetTableInfo
(
pTableMetaInfo
->
pTableMeta
);
STableInfo
tinfo
=
tscGetTableInfo
(
pTableMetaInfo
->
pTableMeta
);
int8_t
precision
=
tinfo
.
precision
;
int8_t
precision
=
tinfo
.
precision
;
...
...
src/client/src/tscServer.c
浏览文件 @
5d4f826b
...
@@ -236,7 +236,7 @@ void tscProcessMsgFromServer(SRpcMsg *rpcMsg) {
...
@@ -236,7 +236,7 @@ void tscProcessMsgFromServer(SRpcMsg *rpcMsg) {
if
(
rpcMsg
->
pCont
==
NULL
)
{
if
(
rpcMsg
->
pCont
==
NULL
)
{
rpcMsg
->
code
=
TSDB_CODE_NETWORK_UNAVAIL
;
rpcMsg
->
code
=
TSDB_CODE_NETWORK_UNAVAIL
;
}
else
{
}
else
{
STableMetaInfo
*
pTableMetaInfo
=
tscGet
MeterMetaInfo
(
pCmd
,
pCmd
->
clauseIndex
,
0
);
STableMetaInfo
*
pTableMetaInfo
=
tscGet
TableMetaInfoFromCmd
(
pCmd
,
pCmd
->
clauseIndex
,
0
);
if
(
rpcMsg
->
code
==
TSDB_CODE_NOT_ACTIVE_TABLE
||
rpcMsg
->
code
==
TSDB_CODE_INVALID_TABLE_ID
||
if
(
rpcMsg
->
code
==
TSDB_CODE_NOT_ACTIVE_TABLE
||
rpcMsg
->
code
==
TSDB_CODE_INVALID_TABLE_ID
||
rpcMsg
->
code
==
TSDB_CODE_INVALID_VNODE_ID
||
rpcMsg
->
code
==
TSDB_CODE_NOT_ACTIVE_VNODE
||
rpcMsg
->
code
==
TSDB_CODE_INVALID_VNODE_ID
||
rpcMsg
->
code
==
TSDB_CODE_NOT_ACTIVE_VNODE
||
rpcMsg
->
code
==
TSDB_CODE_NETWORK_UNAVAIL
||
rpcMsg
->
code
==
TSDB_CODE_NOT_ACTIVE_SESSION
||
rpcMsg
->
code
==
TSDB_CODE_NETWORK_UNAVAIL
||
rpcMsg
->
code
==
TSDB_CODE_NOT_ACTIVE_SESSION
||
...
@@ -1125,7 +1125,7 @@ void tscRetrieveDataRes(void *param, TAOS_RES *tres, int code) {
...
@@ -1125,7 +1125,7 @@ void tscRetrieveDataRes(void *param, TAOS_RES *tres, int code) {
SSqlObj
*
pParentSql
=
trsupport
->
pParentSqlObj
;
SSqlObj
*
pParentSql
=
trsupport
->
pParentSqlObj
;
SSqlObj
*
pSql
=
(
SSqlObj
*
)
tres
;
SSqlObj
*
pSql
=
(
SSqlObj
*
)
tres
;
STableMetaInfo
*
pTableMetaInfo
=
tscGet
MeterMetaInfo
(
&
pSql
->
cmd
,
0
,
0
);
STableMetaInfo
*
pTableMetaInfo
=
tscGet
TableMetaInfoFromCmd
(
&
pSql
->
cmd
,
0
,
0
);
assert
(
pSql
->
cmd
.
numOfClause
==
1
&&
pSql
->
cmd
.
pQueryInfo
[
0
]
->
numOfTables
==
1
);
assert
(
pSql
->
cmd
.
numOfClause
==
1
&&
pSql
->
cmd
.
pQueryInfo
[
0
]
->
numOfTables
==
1
);
int32_t
idx
=
pTableMetaInfo
->
vnodeIndex
;
int32_t
idx
=
pTableMetaInfo
->
vnodeIndex
;
...
@@ -1231,7 +1231,7 @@ int tscBuildRetrieveMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
...
@@ -1231,7 +1231,7 @@ int tscBuildRetrieveMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
void
tscUpdateVnodeInSubmitMsg
(
SSqlObj
*
pSql
,
char
*
buf
)
{
void
tscUpdateVnodeInSubmitMsg
(
SSqlObj
*
pSql
,
char
*
buf
)
{
//SShellSubmitMsg *pShellMsg;
//SShellSubmitMsg *pShellMsg;
//char * pMsg;
//char * pMsg;
//STableMetaInfo * pTableMetaInfo = tscGet
MeterMetaInfo
(&pSql->cmd, pSql->cmd.clauseIndex, 0);
//STableMetaInfo * pTableMetaInfo = tscGet
TableMetaInfoFromCmd
(&pSql->cmd, pSql->cmd.clauseIndex, 0);
//STableMeta *pTableMeta = pTableMetaInfo->pTableMeta;
//STableMeta *pTableMeta = pTableMetaInfo->pTableMeta;
...
@@ -1272,7 +1272,7 @@ int tscBuildSubmitMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
...
@@ -1272,7 +1272,7 @@ int tscBuildSubmitMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
void
tscUpdateVnodeInQueryMsg
(
SSqlObj
*
pSql
,
char
*
buf
)
{
void
tscUpdateVnodeInQueryMsg
(
SSqlObj
*
pSql
,
char
*
buf
)
{
//TODO
//TODO
// SSqlCmd * pCmd = &pSql->cmd;
// SSqlCmd * pCmd = &pSql->cmd;
// STableMetaInfo *pTableMetaInfo = tscGet
MeterMetaInfo
(pCmd, pCmd->clauseIndex, 0);
// STableMetaInfo *pTableMetaInfo = tscGet
TableMetaInfoFromCmd
(pCmd, pCmd->clauseIndex, 0);
//
//
// char * pStart = buf + tsRpcHeadSize;
// char * pStart = buf + tsRpcHeadSize;
// SQueryTableMsg *pQueryMsg = (SQueryTableMsg *)pStart;
// SQueryTableMsg *pQueryMsg = (SQueryTableMsg *)pStart;
...
@@ -1320,7 +1320,7 @@ static int32_t tscEstimateQueryMsgSize(SSqlCmd *pCmd, int32_t clauseIndex) {
...
@@ -1320,7 +1320,7 @@ static int32_t tscEstimateQueryMsgSize(SSqlCmd *pCmd, int32_t clauseIndex) {
}
}
static
char
*
doSerializeTableInfo
(
SSqlObj
*
pSql
,
int32_t
numOfTables
,
int32_t
vnodeId
,
char
*
pMsg
)
{
static
char
*
doSerializeTableInfo
(
SSqlObj
*
pSql
,
int32_t
numOfTables
,
int32_t
vnodeId
,
char
*
pMsg
)
{
STableMetaInfo
*
pTableMetaInfo
=
tscGet
MeterMetaInfo
(
&
pSql
->
cmd
,
pSql
->
cmd
.
clauseIndex
,
0
);
STableMetaInfo
*
pTableMetaInfo
=
tscGet
TableMetaInfoFromCmd
(
&
pSql
->
cmd
,
pSql
->
cmd
.
clauseIndex
,
0
);
STableMeta
*
pTableMeta
=
pTableMetaInfo
->
pTableMeta
;
STableMeta
*
pTableMeta
=
pTableMetaInfo
->
pTableMeta
;
SSuperTableMeta
*
pMetricMeta
=
pTableMetaInfo
->
pMetricMeta
;
SSuperTableMeta
*
pMetricMeta
=
pTableMetaInfo
->
pMetricMeta
;
...
@@ -1677,7 +1677,7 @@ int32_t tscBuildCreateDbMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
...
@@ -1677,7 +1677,7 @@ int32_t tscBuildCreateDbMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
SCMCreateDbMsg
*
pCreateDbMsg
=
(
SCMCreateDbMsg
*
)
pCmd
->
payload
;
SCMCreateDbMsg
*
pCreateDbMsg
=
(
SCMCreateDbMsg
*
)
pCmd
->
payload
;
assert
(
pCmd
->
numOfClause
==
1
);
assert
(
pCmd
->
numOfClause
==
1
);
STableMetaInfo
*
pTableMetaInfo
=
tscGet
MeterMetaInfo
(
pCmd
,
pCmd
->
clauseIndex
,
0
);
STableMetaInfo
*
pTableMetaInfo
=
tscGet
TableMetaInfoFromCmd
(
pCmd
,
pCmd
->
clauseIndex
,
0
);
strncpy
(
pCreateDbMsg
->
db
,
pTableMetaInfo
->
name
,
tListLen
(
pCreateDbMsg
->
db
));
strncpy
(
pCreateDbMsg
->
db
,
pTableMetaInfo
->
name
,
tListLen
(
pCreateDbMsg
->
db
));
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
...
@@ -1799,7 +1799,7 @@ int32_t tscBuildDropDbMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
...
@@ -1799,7 +1799,7 @@ int32_t tscBuildDropDbMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
SCMDropDbMsg
*
pDropDbMsg
=
(
SCMDropDbMsg
*
)
pCmd
->
payload
;
SCMDropDbMsg
*
pDropDbMsg
=
(
SCMDropDbMsg
*
)
pCmd
->
payload
;
STableMetaInfo
*
pTableMetaInfo
=
tscGet
MeterMetaInfo
(
pCmd
,
pCmd
->
clauseIndex
,
0
);
STableMetaInfo
*
pTableMetaInfo
=
tscGet
TableMetaInfoFromCmd
(
pCmd
,
pCmd
->
clauseIndex
,
0
);
strncpy
(
pDropDbMsg
->
db
,
pTableMetaInfo
->
name
,
tListLen
(
pDropDbMsg
->
db
));
strncpy
(
pDropDbMsg
->
db
,
pTableMetaInfo
->
name
,
tListLen
(
pDropDbMsg
->
db
));
pDropDbMsg
->
ignoreNotExists
=
pInfo
->
pDCLInfo
->
existsCheck
?
1
:
0
;
pDropDbMsg
->
ignoreNotExists
=
pInfo
->
pDCLInfo
->
existsCheck
?
1
:
0
;
...
@@ -1817,7 +1817,7 @@ int32_t tscBuildDropTableMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
...
@@ -1817,7 +1817,7 @@ int32_t tscBuildDropTableMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
}
}
SCMDropTableMsg
*
pDropTableMsg
=
(
SCMDropTableMsg
*
)
pCmd
->
payload
;
SCMDropTableMsg
*
pDropTableMsg
=
(
SCMDropTableMsg
*
)
pCmd
->
payload
;
STableMetaInfo
*
pTableMetaInfo
=
tscGet
MeterMetaInfo
(
pCmd
,
pCmd
->
clauseIndex
,
0
);
STableMetaInfo
*
pTableMetaInfo
=
tscGet
TableMetaInfoFromCmd
(
pCmd
,
pCmd
->
clauseIndex
,
0
);
strcpy
(
pDropTableMsg
->
tableId
,
pTableMetaInfo
->
name
);
strcpy
(
pDropTableMsg
->
tableId
,
pTableMetaInfo
->
name
);
pDropTableMsg
->
igNotExists
=
pInfo
->
pDCLInfo
->
existsCheck
?
1
:
0
;
pDropTableMsg
->
igNotExists
=
pInfo
->
pDCLInfo
->
existsCheck
?
1
:
0
;
...
@@ -1834,7 +1834,7 @@ int32_t tscBuildDropDnodeMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
...
@@ -1834,7 +1834,7 @@ int32_t tscBuildDropDnodeMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
}
}
SCMDropDnodeMsg
*
pDrop
=
(
SCMDropDnodeMsg
*
)
pCmd
->
payload
;
SCMDropDnodeMsg
*
pDrop
=
(
SCMDropDnodeMsg
*
)
pCmd
->
payload
;
STableMetaInfo
*
pTableMetaInfo
=
tscGet
MeterMetaInfo
(
pCmd
,
pCmd
->
clauseIndex
,
0
);
STableMetaInfo
*
pTableMetaInfo
=
tscGet
TableMetaInfoFromCmd
(
pCmd
,
pCmd
->
clauseIndex
,
0
);
strcpy
(
pDrop
->
ip
,
pTableMetaInfo
->
name
);
strcpy
(
pDrop
->
ip
,
pTableMetaInfo
->
name
);
pCmd
->
msgType
=
TSDB_MSG_TYPE_CM_DROP_DNODE
;
pCmd
->
msgType
=
TSDB_MSG_TYPE_CM_DROP_DNODE
;
...
@@ -1852,7 +1852,7 @@ int32_t tscBuildDropAcctMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
...
@@ -1852,7 +1852,7 @@ int32_t tscBuildDropAcctMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
}
}
SCMDropUserMsg
*
pDropMsg
=
(
SCMDropUserMsg
*
)
pCmd
->
payload
;
SCMDropUserMsg
*
pDropMsg
=
(
SCMDropUserMsg
*
)
pCmd
->
payload
;
STableMetaInfo
*
pTableMetaInfo
=
tscGet
MeterMetaInfo
(
pCmd
,
pCmd
->
clauseIndex
,
0
);
STableMetaInfo
*
pTableMetaInfo
=
tscGet
TableMetaInfoFromCmd
(
pCmd
,
pCmd
->
clauseIndex
,
0
);
strcpy
(
pDropMsg
->
user
,
pTableMetaInfo
->
name
);
strcpy
(
pDropMsg
->
user
,
pTableMetaInfo
->
name
);
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
...
@@ -1868,7 +1868,7 @@ int32_t tscBuildUseDbMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
...
@@ -1868,7 +1868,7 @@ int32_t tscBuildUseDbMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
}
}
SCMUseDbMsg
*
pUseDbMsg
=
(
SCMUseDbMsg
*
)
pCmd
->
payload
;
SCMUseDbMsg
*
pUseDbMsg
=
(
SCMUseDbMsg
*
)
pCmd
->
payload
;
STableMetaInfo
*
pTableMetaInfo
=
tscGet
MeterMetaInfo
(
pCmd
,
pCmd
->
clauseIndex
,
0
);
STableMetaInfo
*
pTableMetaInfo
=
tscGet
TableMetaInfoFromCmd
(
pCmd
,
pCmd
->
clauseIndex
,
0
);
strcpy
(
pUseDbMsg
->
db
,
pTableMetaInfo
->
name
);
strcpy
(
pUseDbMsg
->
db
,
pTableMetaInfo
->
name
);
pCmd
->
msgType
=
TSDB_MSG_TYPE_CM_USE_DB
;
pCmd
->
msgType
=
TSDB_MSG_TYPE_CM_USE_DB
;
...
@@ -1888,7 +1888,7 @@ int32_t tscBuildShowMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
...
@@ -1888,7 +1888,7 @@ int32_t tscBuildShowMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
SCMShowMsg
*
pShowMsg
=
(
SCMShowMsg
*
)
pCmd
->
payload
;
SCMShowMsg
*
pShowMsg
=
(
SCMShowMsg
*
)
pCmd
->
payload
;
STableMetaInfo
*
pTableMetaInfo
=
tscGet
MeterMetaInfo
(
pCmd
,
pCmd
->
clauseIndex
,
0
);
STableMetaInfo
*
pTableMetaInfo
=
tscGet
TableMetaInfoFromCmd
(
pCmd
,
pCmd
->
clauseIndex
,
0
);
size_t
nameLen
=
strlen
(
pTableMetaInfo
->
name
);
size_t
nameLen
=
strlen
(
pTableMetaInfo
->
name
);
if
(
nameLen
>
0
)
{
if
(
nameLen
>
0
)
{
strcpy
(
pShowMsg
->
db
,
pTableMetaInfo
->
name
);
// prefix is set here
strcpy
(
pShowMsg
->
db
,
pTableMetaInfo
->
name
);
// prefix is set here
...
@@ -2099,7 +2099,7 @@ int tscAlterDbMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
...
@@ -2099,7 +2099,7 @@ int tscAlterDbMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
}
}
SCMAlterDbMsg
*
pAlterDbMsg
=
(
SCMAlterDbMsg
*
)
pCmd
->
payload
;
SCMAlterDbMsg
*
pAlterDbMsg
=
(
SCMAlterDbMsg
*
)
pCmd
->
payload
;
STableMetaInfo
*
pTableMetaInfo
=
tscGet
MeterMetaInfo
(
pCmd
,
pCmd
->
clauseIndex
,
0
);
STableMetaInfo
*
pTableMetaInfo
=
tscGet
TableMetaInfoFromCmd
(
pCmd
,
pCmd
->
clauseIndex
,
0
);
strcpy
(
pAlterDbMsg
->
db
,
pTableMetaInfo
->
name
);
strcpy
(
pAlterDbMsg
->
db
,
pTableMetaInfo
->
name
);
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
...
@@ -2174,7 +2174,7 @@ static int tscLocalResultCommonBuilder(SSqlObj *pSql, int32_t numOfRes) {
...
@@ -2174,7 +2174,7 @@ static int tscLocalResultCommonBuilder(SSqlObj *pSql, int32_t numOfRes) {
int
tscProcessDescribeTableRsp
(
SSqlObj
*
pSql
)
{
int
tscProcessDescribeTableRsp
(
SSqlObj
*
pSql
)
{
SSqlCmd
*
pCmd
=
&
pSql
->
cmd
;
SSqlCmd
*
pCmd
=
&
pSql
->
cmd
;
STableMetaInfo
*
pTableMetaInfo
=
tscGet
MeterMetaInfo
(
pCmd
,
pCmd
->
clauseIndex
,
0
);
STableMetaInfo
*
pTableMetaInfo
=
tscGet
TableMetaInfoFromCmd
(
pCmd
,
pCmd
->
clauseIndex
,
0
);
STableInfo
tinfo
=
tscGetTableInfo
(
pTableMetaInfo
->
pTableMeta
);
STableInfo
tinfo
=
tscGetTableInfo
(
pTableMetaInfo
->
pTableMeta
);
...
@@ -2405,7 +2405,7 @@ int tscBuildMetricMetaMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
...
@@ -2405,7 +2405,7 @@ int tscBuildMetricMetaMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
pMsg
+=
sizeof
(
int16_t
);
pMsg
+=
sizeof
(
int16_t
);
for
(
int32_t
i
=
0
;
i
<
pQueryInfo
->
numOfTables
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
pQueryInfo
->
numOfTables
;
++
i
)
{
pTableMetaInfo
=
tscGet
MeterMetaInfo
(
pCmd
,
pCmd
->
clauseIndex
,
i
);
pTableMetaInfo
=
tscGet
TableMetaInfoFromCmd
(
pCmd
,
pCmd
->
clauseIndex
,
i
);
uint64_t
uid
=
pTableMetaInfo
->
pTableMeta
->
uid
;
uint64_t
uid
=
pTableMetaInfo
->
pTableMeta
->
uid
;
offset
=
pMsg
-
(
char
*
)
pMetaMsg
;
offset
=
pMsg
-
(
char
*
)
pMetaMsg
;
...
@@ -2556,49 +2556,46 @@ int tscBuildHeartBeatMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
...
@@ -2556,49 +2556,46 @@ int tscBuildHeartBeatMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
return
msgLen
;
return
msgLen
;
}
}
int
tscProcessMeterMetaRsp
(
SSqlObj
*
pSql
)
{
int
tscProcessTableMetaRsp
(
SSqlObj
*
pSql
)
{
STableMetaMsg
*
pMeta
;
STableMetaMsg
*
pMetaMsg
=
(
STableMetaMsg
*
)
pSql
->
res
.
pRsp
;
SSchema
*
pSchema
;
pMeta
=
(
STableMetaMsg
*
)
pSql
->
res
.
pRsp
;
pMetaMsg
->
sid
=
htonl
(
pMetaMsg
->
sid
);
pMetaMsg
->
sversion
=
htons
(
pMetaMsg
->
sversion
);
pMetaMsg
->
vgid
=
htonl
(
pMetaMsg
->
vgid
);
pMetaMsg
->
uid
=
htobe64
(
pMetaMsg
->
uid
);
pMetaMsg
->
contLen
=
htons
(
pMetaMsg
->
contLen
);
pMeta
->
sid
=
htonl
(
pMeta
->
sid
);
if
(
pMetaMsg
->
sid
<
0
||
pMetaMsg
->
vgid
<
0
)
{
pMeta
->
sversion
=
htons
(
pMeta
->
sversion
);
tscError
(
"invalid meter vgid:%d, sid%d"
,
pMetaMsg
->
vgid
,
pMetaMsg
->
sid
);
pMeta
->
vgid
=
htonl
(
pMeta
->
vgid
);
pMeta
->
uid
=
htobe64
(
pMeta
->
uid
);
pMeta
->
contLen
=
htons
(
pMeta
->
contLen
);
if
(
pMeta
->
sid
<
0
||
pMeta
->
vgid
<
0
)
{
tscError
(
"invalid meter vgid:%d, sid%d"
,
pMeta
->
vgid
,
pMeta
->
sid
);
return
TSDB_CODE_INVALID_VALUE
;
return
TSDB_CODE_INVALID_VALUE
;
}
}
pMeta
->
numOfColumns
=
htons
(
pMeta
->
numOfColumns
);
pMeta
Msg
->
numOfColumns
=
htons
(
pMetaMsg
->
numOfColumns
);
if
(
pMeta
->
numOfTags
>
TSDB_MAX_TAGS
||
pMeta
->
numOfTags
<
0
)
{
if
(
pMeta
Msg
->
numOfTags
>
TSDB_MAX_TAGS
||
pMetaMsg
->
numOfTags
<
0
)
{
tscError
(
"invalid numOfTags:%d"
,
pMeta
->
numOfTags
);
tscError
(
"invalid numOfTags:%d"
,
pMeta
Msg
->
numOfTags
);
return
TSDB_CODE_INVALID_VALUE
;
return
TSDB_CODE_INVALID_VALUE
;
}
}
if
(
pMeta
->
numOfColumns
>
TSDB_MAX_COLUMNS
||
pMeta
->
numOfColumns
<=
0
)
{
if
(
pMeta
Msg
->
numOfColumns
>
TSDB_MAX_COLUMNS
||
pMetaMsg
->
numOfColumns
<=
0
)
{
tscError
(
"invalid numOfColumns:%d"
,
pMeta
->
numOfColumns
);
tscError
(
"invalid numOfColumns:%d"
,
pMeta
Msg
->
numOfColumns
);
return
TSDB_CODE_INVALID_VALUE
;
return
TSDB_CODE_INVALID_VALUE
;
}
}
for
(
int
i
=
0
;
i
<
TSDB_VNODES_SUPPORT
;
++
i
)
{
for
(
int
i
=
0
;
i
<
TSDB_VNODES_SUPPORT
;
++
i
)
{
pMeta
->
vpeerDesc
[
i
].
vnode
=
htonl
(
pMeta
->
vpeerDesc
[
i
].
vnode
);
pMeta
Msg
->
vpeerDesc
[
i
].
vnode
=
htonl
(
pMetaMsg
->
vpeerDesc
[
i
].
vnode
);
}
}
int32_t
rowSize
=
0
;
int32_t
rowSize
=
0
;
pSchema
=
(
SSchema
*
)(
pSql
->
res
.
pRsp
+
sizeof
(
STableMeta
))
;
SSchema
*
pSchema
=
pMetaMsg
->
schema
;
int32_t
numOfTotalCols
=
pMeta
->
numOfColumns
+
pMeta
->
numOfTags
;
int32_t
numOfTotalCols
=
pMeta
Msg
->
numOfColumns
+
pMetaMsg
->
numOfTags
;
for
(
int
i
=
0
;
i
<
numOfTotalCols
;
++
i
)
{
for
(
int
i
=
0
;
i
<
numOfTotalCols
;
++
i
)
{
pSchema
->
bytes
=
htons
(
pSchema
->
bytes
);
pSchema
->
bytes
=
htons
(
pSchema
->
bytes
);
pSchema
->
colId
=
htons
(
pSchema
->
colId
);
pSchema
->
colId
=
htons
(
pSchema
->
colId
);
// ignore the tags length
// ignore the tags length
if
(
i
<
pMeta
->
numOfColumns
)
{
if
(
i
<
pMeta
Msg
->
numOfColumns
)
{
rowSize
+=
pSchema
->
bytes
;
rowSize
+=
pSchema
->
bytes
;
}
}
pSchema
++
;
pSchema
++
;
...
@@ -2607,29 +2604,32 @@ int tscProcessMeterMetaRsp(SSqlObj *pSql) {
...
@@ -2607,29 +2604,32 @@ int tscProcessMeterMetaRsp(SSqlObj *pSql) {
// rsp += numOfTotalCols * sizeof(SSchema);
// rsp += numOfTotalCols * sizeof(SSchema);
//
//
// int32_t tagLen = 0;
// int32_t tagLen = 0;
// SSchema *pTagsSchema = tscGetTableTagSchema(pMeta);
// SSchema *pTagsSchema = tscGetTableTagSchema(pMeta
Msg
);
//
//
// if (pMeta->tableType == TSDB_CHILD_TABLE) {
// if (pMeta
Msg
->tableType == TSDB_CHILD_TABLE) {
// for (int32_t i = 0; i < pMeta->numOfTags; ++i) {
// for (int32_t i = 0; i < pMeta
Msg
->numOfTags; ++i) {
// tagLen += pTagsSchema[i].bytes;
// tagLen += pTagsSchema[i].bytes;
// }
// }
// }
// }
//
//
// rsp += tagLen;
// rsp += tagLen;
// int32_t size = (int32_t)(rsp - (char *)pMeta);
// int32_t size = (int32_t)(rsp - (char *)pMeta
Msg
);
// pMeta->index = rand() % TSDB_VNODES_SUPPORT
;
size_t
size
=
0
;
// pMeta->index = 0
;
STableMeta
*
pTableMeta
=
tscCreateTableMetaFromMsg
(
pMetaMsg
,
&
size
)
;
// todo add one more function: taosAddDataIfNotExists();
// todo add one more function: taosAddDataIfNotExists();
STableMetaInfo
*
pTableMetaInfo
=
tscGet
MeterMetaInfo
(
&
pSql
->
cmd
,
0
,
0
);
STableMetaInfo
*
pTableMetaInfo
=
tscGet
TableMetaInfoFromCmd
(
&
pSql
->
cmd
,
0
,
0
);
assert
(
pTableMetaInfo
->
pTableMeta
==
NULL
);
assert
(
pTableMetaInfo
->
pTableMeta
==
NULL
);
pTableMetaInfo
->
pTableMeta
=
(
STableMeta
*
)
taosCachePut
(
tscCacheHandle
,
pTableMetaInfo
->
name
,
(
char
*
)
p
Meta
,
pTableMetaInfo
->
pTableMeta
=
(
STableMeta
*
)
taosCachePut
(
tscCacheHandle
,
pTableMetaInfo
->
name
,
pTable
Meta
,
pMeta
->
contLen
,
tsMeterMetaKeepTimer
);
size
,
tsMeterMetaKeepTimer
);
// todo handle out of memory case
// todo handle out of memory case
if
(
pTableMetaInfo
->
pTableMeta
==
NULL
)
return
0
;
if
(
pTableMetaInfo
->
pTableMeta
==
NULL
)
{
return
0
;
}
free
(
pTableMeta
);
return
TSDB_CODE_OTHERS
;
return
TSDB_CODE_OTHERS
;
}
}
...
@@ -2956,7 +2956,7 @@ int tscProcessConnectRsp(SSqlObj *pSql) {
...
@@ -2956,7 +2956,7 @@ int tscProcessConnectRsp(SSqlObj *pSql) {
int
tscProcessUseDbRsp
(
SSqlObj
*
pSql
)
{
int
tscProcessUseDbRsp
(
SSqlObj
*
pSql
)
{
STscObj
*
pObj
=
pSql
->
pTscObj
;
STscObj
*
pObj
=
pSql
->
pTscObj
;
STableMetaInfo
*
pTableMetaInfo
=
tscGet
MeterMetaInfo
(
&
pSql
->
cmd
,
0
,
0
);
STableMetaInfo
*
pTableMetaInfo
=
tscGet
TableMetaInfoFromCmd
(
&
pSql
->
cmd
,
0
,
0
);
strcpy
(
pObj
->
db
,
pTableMetaInfo
->
name
);
strcpy
(
pObj
->
db
,
pTableMetaInfo
->
name
);
return
0
;
return
0
;
...
@@ -2968,7 +2968,7 @@ int tscProcessDropDbRsp(SSqlObj *UNUSED_PARAM(pSql)) {
...
@@ -2968,7 +2968,7 @@ int tscProcessDropDbRsp(SSqlObj *UNUSED_PARAM(pSql)) {
}
}
int
tscProcessDropTableRsp
(
SSqlObj
*
pSql
)
{
int
tscProcessDropTableRsp
(
SSqlObj
*
pSql
)
{
STableMetaInfo
*
pTableMetaInfo
=
tscGet
MeterMetaInfo
(
&
pSql
->
cmd
,
0
,
0
);
STableMetaInfo
*
pTableMetaInfo
=
tscGet
TableMetaInfoFromCmd
(
&
pSql
->
cmd
,
0
,
0
);
STableMeta
*
pTableMeta
=
taosCacheAcquireByName
(
tscCacheHandle
,
pTableMetaInfo
->
name
);
STableMeta
*
pTableMeta
=
taosCacheAcquireByName
(
tscCacheHandle
,
pTableMetaInfo
->
name
);
if
(
pTableMeta
==
NULL
)
{
if
(
pTableMeta
==
NULL
)
{
...
@@ -2995,7 +2995,7 @@ int tscProcessDropTableRsp(SSqlObj *pSql) {
...
@@ -2995,7 +2995,7 @@ int tscProcessDropTableRsp(SSqlObj *pSql) {
}
}
int
tscProcessAlterTableMsgRsp
(
SSqlObj
*
pSql
)
{
int
tscProcessAlterTableMsgRsp
(
SSqlObj
*
pSql
)
{
STableMetaInfo
*
pTableMetaInfo
=
tscGet
MeterMetaInfo
(
&
pSql
->
cmd
,
0
,
0
);
STableMetaInfo
*
pTableMetaInfo
=
tscGet
TableMetaInfoFromCmd
(
&
pSql
->
cmd
,
0
,
0
);
STableMeta
*
pTableMeta
=
taosCacheAcquireByName
(
tscCacheHandle
,
pTableMetaInfo
->
name
);
STableMeta
*
pTableMeta
=
taosCacheAcquireByName
(
tscCacheHandle
,
pTableMetaInfo
->
name
);
if
(
pTableMeta
==
NULL
)
{
/* not in cache, abort */
if
(
pTableMeta
==
NULL
)
{
/* not in cache, abort */
...
@@ -3378,7 +3378,7 @@ void tscInitMsgs() {
...
@@ -3378,7 +3378,7 @@ void tscInitMsgs() {
tscProcessMsgRsp
[
TSDB_SQL_DROP_TABLE
]
=
tscProcessDropTableRsp
;
tscProcessMsgRsp
[
TSDB_SQL_DROP_TABLE
]
=
tscProcessDropTableRsp
;
tscProcessMsgRsp
[
TSDB_SQL_CONNECT
]
=
tscProcessConnectRsp
;
tscProcessMsgRsp
[
TSDB_SQL_CONNECT
]
=
tscProcessConnectRsp
;
tscProcessMsgRsp
[
TSDB_SQL_USE_DB
]
=
tscProcessUseDbRsp
;
tscProcessMsgRsp
[
TSDB_SQL_USE_DB
]
=
tscProcessUseDbRsp
;
tscProcessMsgRsp
[
TSDB_SQL_META
]
=
tscProcess
Meter
MetaRsp
;
tscProcessMsgRsp
[
TSDB_SQL_META
]
=
tscProcess
Table
MetaRsp
;
tscProcessMsgRsp
[
TSDB_SQL_METRIC
]
=
tscProcessMetricMetaRsp
;
tscProcessMsgRsp
[
TSDB_SQL_METRIC
]
=
tscProcessMetricMetaRsp
;
tscProcessMsgRsp
[
TSDB_SQL_MULTI_META
]
=
tscProcessMultiMeterMetaRsp
;
tscProcessMsgRsp
[
TSDB_SQL_MULTI_META
]
=
tscProcessMultiMeterMetaRsp
;
...
...
src/client/src/tscStream.c
浏览文件 @
5d4f826b
...
@@ -146,7 +146,7 @@ static void tscProcessStreamQueryCallback(void *param, TAOS_RES *tres, int numOf
...
@@ -146,7 +146,7 @@ static void tscProcessStreamQueryCallback(void *param, TAOS_RES *tres, int numOf
tscError
(
"%p stream:%p, query data failed, code:%d, retry in %"
PRId64
"ms"
,
pStream
->
pSql
,
pStream
,
numOfRows
,
tscError
(
"%p stream:%p, query data failed, code:%d, retry in %"
PRId64
"ms"
,
pStream
->
pSql
,
pStream
,
numOfRows
,
retryDelay
);
retryDelay
);
STableMetaInfo
*
pTableMetaInfo
=
tscGet
MeterMetaInfo
(
&
pStream
->
pSql
->
cmd
,
0
,
0
);
STableMetaInfo
*
pTableMetaInfo
=
tscGet
TableMetaInfoFromCmd
(
&
pStream
->
pSql
->
cmd
,
0
,
0
);
tscClearMeterMetaInfo
(
pTableMetaInfo
,
true
);
tscClearMeterMetaInfo
(
pTableMetaInfo
,
true
);
tscSetRetryTimer
(
pStream
,
pStream
->
pSql
,
retryDelay
);
tscSetRetryTimer
(
pStream
,
pStream
->
pSql
,
retryDelay
);
...
@@ -172,7 +172,7 @@ static void tscSetTimestampForRes(SSqlStream *pStream, SSqlObj *pSql) {
...
@@ -172,7 +172,7 @@ static void tscSetTimestampForRes(SSqlStream *pStream, SSqlObj *pSql) {
static
void
tscProcessStreamRetrieveResult
(
void
*
param
,
TAOS_RES
*
res
,
int
numOfRows
)
{
static
void
tscProcessStreamRetrieveResult
(
void
*
param
,
TAOS_RES
*
res
,
int
numOfRows
)
{
SSqlStream
*
pStream
=
(
SSqlStream
*
)
param
;
SSqlStream
*
pStream
=
(
SSqlStream
*
)
param
;
SSqlObj
*
pSql
=
(
SSqlObj
*
)
res
;
SSqlObj
*
pSql
=
(
SSqlObj
*
)
res
;
STableMetaInfo
*
pTableMetaInfo
=
tscGet
MeterMetaInfo
(
&
pSql
->
cmd
,
0
,
0
);
STableMetaInfo
*
pTableMetaInfo
=
tscGet
TableMetaInfoFromCmd
(
&
pSql
->
cmd
,
0
,
0
);
if
(
pSql
==
NULL
||
numOfRows
<
0
)
{
if
(
pSql
==
NULL
||
numOfRows
<
0
)
{
int64_t
retryDelayTime
=
tscGetRetryDelayTime
(
pStream
->
slidingTime
,
pStream
->
precision
);
int64_t
retryDelayTime
=
tscGetRetryDelayTime
(
pStream
->
slidingTime
,
pStream
->
precision
);
...
...
src/client/src/tscSub.c
浏览文件 @
5d4f826b
...
@@ -175,7 +175,7 @@ int tscUpdateSubscription(STscObj* pObj, SSub* pSub) {
...
@@ -175,7 +175,7 @@ int tscUpdateSubscription(STscObj* pObj, SSub* pSub) {
return
0
;
return
0
;
}
}
STableMetaInfo
*
pTableMetaInfo
=
tscGet
MeterMetaInfo
(
pCmd
,
0
,
0
);
STableMetaInfo
*
pTableMetaInfo
=
tscGet
TableMetaInfoFromCmd
(
pCmd
,
0
,
0
);
int
numOfTables
=
0
;
int
numOfTables
=
0
;
if
(
!
UTIL_METER_IS_NOMRAL_METER
(
pTableMetaInfo
))
{
if
(
!
UTIL_METER_IS_NOMRAL_METER
(
pTableMetaInfo
))
{
SSuperTableMeta
*
pMetricMeta
=
pTableMetaInfo
->
pMetricMeta
;
SSuperTableMeta
*
pMetricMeta
=
pTableMetaInfo
->
pMetricMeta
;
...
@@ -385,7 +385,7 @@ TAOS_RES *taos_consume(TAOS_SUB *tsub) {
...
@@ -385,7 +385,7 @@ TAOS_RES *taos_consume(TAOS_SUB *tsub) {
pSql
->
cmd
.
command
=
TSDB_SQL_SELECT
;
pSql
->
cmd
.
command
=
TSDB_SQL_SELECT
;
pQueryInfo
->
type
=
type
;
pQueryInfo
->
type
=
type
;
tscGet
MeterMetaInfo
(
&
pSql
->
cmd
,
0
,
0
)
->
vnodeIndex
=
0
;
tscGet
TableMetaInfoFromCmd
(
&
pSql
->
cmd
,
0
,
0
)
->
vnodeIndex
=
0
;
}
}
tscDoQuery
(
pSql
);
tscDoQuery
(
pSql
);
...
...
src/client/src/tscUtil.c
浏览文件 @
5d4f826b
...
@@ -584,7 +584,7 @@ int32_t tscCopyDataBlockToPayload(SSqlObj* pSql, STableDataBlocks* pDataBlock) {
...
@@ -584,7 +584,7 @@ int32_t tscCopyDataBlockToPayload(SSqlObj* pSql, STableDataBlocks* pDataBlock) {
pCmd
->
numOfTablesInSubmit
=
pDataBlock
->
numOfTables
;
pCmd
->
numOfTablesInSubmit
=
pDataBlock
->
numOfTables
;
assert
(
pCmd
->
numOfClause
==
1
);
assert
(
pCmd
->
numOfClause
==
1
);
STableMetaInfo
*
pTableMetaInfo
=
tscGet
MeterMetaInfo
(
pCmd
,
pCmd
->
clauseIndex
,
0
);
STableMetaInfo
*
pTableMetaInfo
=
tscGet
TableMetaInfoFromCmd
(
pCmd
,
pCmd
->
clauseIndex
,
0
);
// set the correct metermeta object, the metermeta has been locked in pDataBlocks, so it must be in the cache
// set the correct metermeta object, the metermeta has been locked in pDataBlocks, so it must be in the cache
if
(
pTableMetaInfo
->
pTableMeta
!=
pDataBlock
->
pTableMeta
)
{
if
(
pTableMetaInfo
->
pTableMeta
!=
pDataBlock
->
pTableMeta
)
{
...
@@ -1747,7 +1747,7 @@ bool tscShouldFreeAsyncSqlObj(SSqlObj* pSql) {
...
@@ -1747,7 +1747,7 @@ bool tscShouldFreeAsyncSqlObj(SSqlObj* pSql) {
* @param tableIndex denote the table index for join query, where more than one table exists
* @param tableIndex denote the table index for join query, where more than one table exists
* @return
* @return
*/
*/
STableMetaInfo
*
tscGet
MeterMetaInfo
(
SSqlCmd
*
pCmd
,
int32_t
clauseIndex
,
int32_t
tableIndex
)
{
STableMetaInfo
*
tscGet
TableMetaInfoFromCmd
(
SSqlCmd
*
pCmd
,
int32_t
clauseIndex
,
int32_t
tableIndex
)
{
if
(
pCmd
==
NULL
||
pCmd
->
numOfClause
==
0
)
{
if
(
pCmd
==
NULL
||
pCmd
->
numOfClause
==
0
)
{
return
NULL
;
return
NULL
;
}
}
...
@@ -1957,7 +1957,7 @@ void tscResetForNextRetrieve(SSqlRes* pRes) {
...
@@ -1957,7 +1957,7 @@ void tscResetForNextRetrieve(SSqlRes* pRes) {
SSqlObj
*
createSubqueryObj
(
SSqlObj
*
pSql
,
int16_t
tableIndex
,
void
(
*
fp
)(),
void
*
param
,
SSqlObj
*
pPrevSql
)
{
SSqlObj
*
createSubqueryObj
(
SSqlObj
*
pSql
,
int16_t
tableIndex
,
void
(
*
fp
)(),
void
*
param
,
SSqlObj
*
pPrevSql
)
{
SSqlCmd
*
pCmd
=
&
pSql
->
cmd
;
SSqlCmd
*
pCmd
=
&
pSql
->
cmd
;
STableMetaInfo
*
pTableMetaInfo
=
tscGet
MeterMetaInfo
(
pCmd
,
pCmd
->
clauseIndex
,
tableIndex
);
STableMetaInfo
*
pTableMetaInfo
=
tscGet
TableMetaInfoFromCmd
(
pCmd
,
pCmd
->
clauseIndex
,
tableIndex
);
SSqlObj
*
pNew
=
(
SSqlObj
*
)
calloc
(
1
,
sizeof
(
SSqlObj
));
SSqlObj
*
pNew
=
(
SSqlObj
*
)
calloc
(
1
,
sizeof
(
SSqlObj
));
if
(
pNew
==
NULL
)
{
if
(
pNew
==
NULL
)
{
...
@@ -2079,7 +2079,7 @@ SSqlObj* createSubqueryObj(SSqlObj* pSql, int16_t tableIndex, void (*fp)(), void
...
@@ -2079,7 +2079,7 @@ SSqlObj* createSubqueryObj(SSqlObj* pSql, int16_t tableIndex, void (*fp)(), void
pFinalInfo
=
tscAddMeterMetaInfo
(
pNewQueryInfo
,
name
,
pTableMeta
,
pMetricMeta
,
pTableMetaInfo
->
numOfTags
,
pFinalInfo
=
tscAddMeterMetaInfo
(
pNewQueryInfo
,
name
,
pTableMeta
,
pMetricMeta
,
pTableMetaInfo
->
numOfTags
,
pTableMetaInfo
->
tagColumnIndex
);
pTableMetaInfo
->
tagColumnIndex
);
}
else
{
// transfer the ownership of pTableMeta/pMetricMeta to the newly create sql object.
}
else
{
// transfer the ownership of pTableMeta/pMetricMeta to the newly create sql object.
STableMetaInfo
*
pPrevInfo
=
tscGet
MeterMetaInfo
(
&
pPrevSql
->
cmd
,
pPrevSql
->
cmd
.
clauseIndex
,
0
);
STableMetaInfo
*
pPrevInfo
=
tscGet
TableMetaInfoFromCmd
(
&
pPrevSql
->
cmd
,
pPrevSql
->
cmd
.
clauseIndex
,
0
);
STableMeta
*
pPrevMeterMeta
=
taosCacheTransfer
(
tscCacheHandle
,
(
void
**
)
&
pPrevInfo
->
pTableMeta
);
STableMeta
*
pPrevMeterMeta
=
taosCacheTransfer
(
tscCacheHandle
,
(
void
**
)
&
pPrevInfo
->
pTableMeta
);
SSuperTableMeta
*
pPrevMetricMeta
=
taosCacheTransfer
(
tscCacheHandle
,
(
void
**
)
&
pPrevInfo
->
pMetricMeta
);
SSuperTableMeta
*
pPrevMetricMeta
=
taosCacheTransfer
(
tscCacheHandle
,
(
void
**
)
&
pPrevInfo
->
pMetricMeta
);
...
...
src/inc/mnode.h
浏览文件 @
5d4f826b
...
@@ -84,7 +84,7 @@ typedef struct {
...
@@ -84,7 +84,7 @@ typedef struct {
}
SVnodeGid
;
}
SVnodeGid
;
typedef
struct
{
typedef
struct
{
char
tableId
[
TSDB_TABLE_ID_LEN
+
1
];
char
tableId
[
TSDB_TABLE_ID_LEN
];
int8_t
type
;
int8_t
type
;
int8_t
dirty
;
int8_t
dirty
;
uint64_t
uid
;
uint64_t
uid
;
...
@@ -128,7 +128,7 @@ typedef struct {
...
@@ -128,7 +128,7 @@ typedef struct {
}
SChildTableObj
;
}
SChildTableObj
;
typedef
struct
{
typedef
struct
{
char
tableId
[
TSDB_TABLE_ID_LEN
+
1
];
char
tableId
[
TSDB_TABLE_ID_LEN
];
int8_t
type
;
int8_t
type
;
int8_t
dirty
;
int8_t
dirty
;
uint64_t
uid
;
uint64_t
uid
;
...
...
src/inc/taosmsg.h
浏览文件 @
5d4f826b
...
@@ -229,7 +229,6 @@ typedef struct SSchema {
...
@@ -229,7 +229,6 @@ typedef struct SSchema {
}
SSchema
;
}
SSchema
;
typedef
struct
{
typedef
struct
{
int32_t
vgId
;
int32_t
vnode
;
//the index of vnode
int32_t
vnode
;
//the index of vnode
uint32_t
ip
;
uint32_t
ip
;
}
SVnodeDesc
;
}
SVnodeDesc
;
...
@@ -256,14 +255,14 @@ typedef struct {
...
@@ -256,14 +255,14 @@ typedef struct {
uint64_t
uid
;
uint64_t
uid
;
uint64_t
superTableUid
;
uint64_t
superTableUid
;
uint64_t
createdTime
;
uint64_t
createdTime
;
char
tableId
[
TSDB_TABLE_ID_LEN
+
1
];
char
tableId
[
TSDB_TABLE_ID_LEN
];
char
superTableId
[
TSDB_TABLE_ID_LEN
+
1
];
char
superTableId
[
TSDB_TABLE_ID_LEN
];
char
data
[];
char
data
[];
}
SMDCreateTableMsg
;
}
SMDCreateTableMsg
;
typedef
struct
{
typedef
struct
{
char
tableId
[
TSDB_TABLE_ID_LEN
+
1
];
char
tableId
[
TSDB_TABLE_ID_LEN
];
char
db
[
TSDB_DB_NAME_LEN
+
1
];
char
db
[
TSDB_DB_NAME_LEN
];
int8_t
igExists
;
int8_t
igExists
;
int16_t
numOfTags
;
int16_t
numOfTags
;
int16_t
numOfColumns
;
int16_t
numOfColumns
;
...
@@ -274,13 +273,13 @@ typedef struct {
...
@@ -274,13 +273,13 @@ typedef struct {
}
SCMCreateTableMsg
;
}
SCMCreateTableMsg
;
typedef
struct
{
typedef
struct
{
char
tableId
[
TSDB_TABLE_ID_LEN
+
1
];
char
tableId
[
TSDB_TABLE_ID_LEN
];
int8_t
igNotExists
;
int8_t
igNotExists
;
}
SCMDropTableMsg
;
}
SCMDropTableMsg
;
typedef
struct
{
typedef
struct
{
char
tableId
[
TSDB_TABLE_ID_LEN
+
1
];
char
tableId
[
TSDB_TABLE_ID_LEN
];
char
db
[
TSDB_DB_NAME_LEN
+
1
];
char
db
[
TSDB_DB_NAME_LEN
];
int16_t
type
;
/* operation type */
int16_t
type
;
/* operation type */
char
tagVal
[
TSDB_MAX_BYTES_PER_ROW
];
char
tagVal
[
TSDB_MAX_BYTES_PER_ROW
];
int8_t
numOfCols
;
/* number of schema */
int8_t
numOfCols
;
/* number of schema */
...
...
src/mnode/src/mgmtChildTable.c
浏览文件 @
5d4f826b
...
@@ -451,7 +451,7 @@ int32_t mgmtGetChildTableMeta(SDbObj *pDb, SChildTableObj *pTable, STableMetaMsg
...
@@ -451,7 +451,7 @@ int32_t mgmtGetChildTableMeta(SDbObj *pDb, SChildTableObj *pTable, STableMetaMsg
pMeta
->
numOfColumns
=
htons
(
pTable
->
superTable
->
numOfColumns
);
pMeta
->
numOfColumns
=
htons
(
pTable
->
superTable
->
numOfColumns
);
pMeta
->
tableType
=
pTable
->
type
;
pMeta
->
tableType
=
pTable
->
type
;
pMeta
->
contLen
=
sizeof
(
STableMetaMsg
)
+
mgmtSetSchemaFromSuperTable
(
pMeta
->
schema
,
pTable
->
superTable
);
pMeta
->
contLen
=
sizeof
(
STableMetaMsg
)
+
mgmtSetSchemaFromSuperTable
(
pMeta
->
schema
,
pTable
->
superTable
);
str
cpy
(
pMeta
->
tableId
,
pTable
->
tableId
);
str
ncpy
(
pMeta
->
tableId
,
pTable
->
tableId
,
tListLen
(
pTable
->
tableId
)
);
SVgObj
*
pVgroup
=
mgmtGetVgroup
(
pTable
->
vgId
);
SVgObj
*
pVgroup
=
mgmtGetVgroup
(
pTable
->
vgId
);
if
(
pVgroup
==
NULL
)
{
if
(
pVgroup
==
NULL
)
{
...
@@ -464,7 +464,6 @@ int32_t mgmtGetChildTableMeta(SDbObj *pDb, SChildTableObj *pTable, STableMetaMsg
...
@@ -464,7 +464,6 @@ int32_t mgmtGetChildTableMeta(SDbObj *pDb, SChildTableObj *pTable, STableMetaMsg
pMeta
->
vpeerDesc
[
i
].
ip
=
pVgroup
->
vnodeGid
[
i
].
ip
;
pMeta
->
vpeerDesc
[
i
].
ip
=
pVgroup
->
vnodeGid
[
i
].
ip
;
}
}
pMeta
->
vpeerDesc
[
i
].
vnode
=
htonl
(
pVgroup
->
vnodeGid
[
i
].
vnode
);
pMeta
->
vpeerDesc
[
i
].
vnode
=
htonl
(
pVgroup
->
vnodeGid
[
i
].
vnode
);
pMeta
->
vpeerDesc
[
i
].
vgId
=
htonl
(
pVgroup
->
vgId
);
}
}
pMeta
->
numOfVpeers
=
pVgroup
->
numOfVnodes
;
pMeta
->
numOfVpeers
=
pVgroup
->
numOfVnodes
;
...
...
src/mnode/src/mgmtNormalTable.c
浏览文件 @
5d4f826b
...
@@ -531,6 +531,8 @@ int32_t mgmtGetNormalTableMeta(SDbObj *pDb, SNormalTableObj *pTable, STableMetaM
...
@@ -531,6 +531,8 @@ int32_t mgmtGetNormalTableMeta(SDbObj *pDb, SNormalTableObj *pTable, STableMetaM
pMeta
->
numOfColumns
=
htons
(
pTable
->
numOfColumns
);
pMeta
->
numOfColumns
=
htons
(
pTable
->
numOfColumns
);
pMeta
->
tableType
=
pTable
->
type
;
pMeta
->
tableType
=
pTable
->
type
;
pMeta
->
contLen
=
sizeof
(
STableMetaMsg
)
+
mgmtSetSchemaFromNormalTable
(
pMeta
->
schema
,
pTable
);
pMeta
->
contLen
=
sizeof
(
STableMetaMsg
)
+
mgmtSetSchemaFromNormalTable
(
pMeta
->
schema
,
pTable
);
strncpy
(
pMeta
->
tableId
,
pTable
->
tableId
,
tListLen
(
pTable
->
tableId
));
SVgObj
*
pVgroup
=
mgmtGetVgroup
(
pTable
->
vgId
);
SVgObj
*
pVgroup
=
mgmtGetVgroup
(
pTable
->
vgId
);
if
(
pVgroup
==
NULL
)
{
if
(
pVgroup
==
NULL
)
{
...
@@ -542,8 +544,8 @@ int32_t mgmtGetNormalTableMeta(SDbObj *pDb, SNormalTableObj *pTable, STableMetaM
...
@@ -542,8 +544,8 @@ int32_t mgmtGetNormalTableMeta(SDbObj *pDb, SNormalTableObj *pTable, STableMetaM
}
else
{
}
else
{
pMeta
->
vpeerDesc
[
i
].
ip
=
pVgroup
->
vnodeGid
[
i
].
ip
;
pMeta
->
vpeerDesc
[
i
].
ip
=
pVgroup
->
vnodeGid
[
i
].
ip
;
}
}
pMeta
->
vpeerDesc
[
i
].
vnode
=
htonl
(
pVgroup
->
vnodeGid
[
i
].
vnode
);
pMeta
->
vpeerDesc
[
i
].
vnode
=
htonl
(
pVgroup
->
vnodeGid
[
i
].
vnode
);
pMeta
->
vpeerDesc
[
i
].
vgId
=
htonl
(
pVgroup
->
vgId
);
}
}
pMeta
->
numOfVpeers
=
pVgroup
->
numOfVnodes
;
pMeta
->
numOfVpeers
=
pVgroup
->
numOfVnodes
;
...
...
src/mnode/src/mgmtTable.c
浏览文件 @
5d4f826b
...
@@ -610,9 +610,10 @@ void mgmtProcessGetTableMeta(STableInfo *pTable, void *thandle) {
...
@@ -610,9 +610,10 @@ void mgmtProcessGetTableMeta(STableInfo *pTable, void *thandle) {
if
(
rpcRsp
.
code
!=
TSDB_CODE_SUCCESS
)
{
if
(
rpcRsp
.
code
!=
TSDB_CODE_SUCCESS
)
{
rpcFreeCont
(
pMeta
);
rpcFreeCont
(
pMeta
);
}
else
{
}
else
{
pMeta
->
contLen
=
htons
(
pMeta
->
contLen
);
rpcRsp
.
pCont
=
pMeta
;
rpcRsp
.
pCont
=
pMeta
;
rpcRsp
.
contLen
=
pMeta
->
contLen
;
rpcRsp
.
contLen
=
pMeta
->
contLen
;
pMeta
->
contLen
=
htons
(
pMeta
->
contLen
);
}
}
rpcSendResponse
(
&
rpcRsp
);
rpcSendResponse
(
&
rpcRsp
);
...
...
src/mnode/src/mgmtVgroup.c
浏览文件 @
5d4f826b
...
@@ -514,7 +514,6 @@ SMDCreateVnodeMsg *mgmtBuildCreateVnodeMsg(SVgObj *pVgroup, int32_t vnode) {
...
@@ -514,7 +514,6 @@ SMDCreateVnodeMsg *mgmtBuildCreateVnodeMsg(SVgObj *pVgroup, int32_t vnode) {
SVnodeDesc
*
vpeerDesc
=
pVnode
->
vpeerDesc
;
SVnodeDesc
*
vpeerDesc
=
pVnode
->
vpeerDesc
;
for
(
int32_t
j
=
0
;
j
<
pVgroup
->
numOfVnodes
;
++
j
)
{
for
(
int32_t
j
=
0
;
j
<
pVgroup
->
numOfVnodes
;
++
j
)
{
vpeerDesc
[
j
].
vgId
=
htonl
(
pVgroup
->
vgId
);
vpeerDesc
[
j
].
ip
=
htonl
(
pVgroup
->
vnodeGid
[
j
].
ip
);
vpeerDesc
[
j
].
ip
=
htonl
(
pVgroup
->
vnodeGid
[
j
].
ip
);
vpeerDesc
[
j
].
vnode
=
htonl
(
pVgroup
->
vnodeGid
[
j
].
vnode
);
vpeerDesc
[
j
].
vnode
=
htonl
(
pVgroup
->
vnodeGid
[
j
].
vnode
);
}
}
...
...
src/util/inc/tcache.h
浏览文件 @
5d4f826b
...
@@ -98,15 +98,15 @@ SCacheObj *taosCacheInit(void *tmrCtrl, int64_t refreshTimeInSeconds);
...
@@ -98,15 +98,15 @@ SCacheObj *taosCacheInit(void *tmrCtrl, int64_t refreshTimeInSeconds);
* @param keepTime survival time in second
* @param keepTime survival time in second
* @return cached element
* @return cached element
*/
*/
void
*
taosCachePut
(
void
*
handle
,
char
*
key
,
char
*
pData
,
in
t
dataSize
,
int
keepTimeInSeconds
);
void
*
taosCachePut
(
SCacheObj
*
pCacheObj
,
char
*
key
,
void
*
pData
,
size_
t
dataSize
,
int
keepTimeInSeconds
);
/**
/**
* get data from cache
* get data from cache
* @param
handle
cache object
* @param
pCacheObj
cache object
* @param key key
* @param key key
* @return cached data or NULL
* @return cached data or NULL
*/
*/
void
*
taosCacheAcquireByName
(
void
*
handle
,
char
*
key
);
void
*
taosCacheAcquireByName
(
SCacheObj
*
pCacheObj
,
const
char
*
key
);
/**
/**
* Add one reference count for the exist data, and assign this data for a new owner.
* Add one reference count for the exist data, and assign this data for a new owner.
...
@@ -118,7 +118,7 @@ void *taosCacheAcquireByName(void *handle, char *key);
...
@@ -118,7 +118,7 @@ void *taosCacheAcquireByName(void *handle, char *key);
* @param data
* @param data
* @return
* @return
*/
*/
void
*
taosCacheAcquireByData
(
void
*
handle
,
void
*
data
);
void
*
taosCacheAcquireByData
(
SCacheObj
*
pCacheObj
,
void
*
data
);
/**
/**
* transfer the ownership of data in cache to another object without increasing reference count.
* transfer the ownership of data in cache to another object without increasing reference count.
...
@@ -126,7 +126,7 @@ void *taosCacheAcquireByData(void *handle, void *data);
...
@@ -126,7 +126,7 @@ void *taosCacheAcquireByData(void *handle, void *data);
* @param data
* @param data
* @return
* @return
*/
*/
void
*
taosCacheTransfer
(
void
*
handle
,
void
**
data
);
void
*
taosCacheTransfer
(
SCacheObj
*
pCacheObj
,
void
**
data
);
/**
/**
* remove data in cache, the data will not be removed immediately.
* remove data in cache, the data will not be removed immediately.
...
@@ -136,7 +136,7 @@ void *taosCacheTransfer(void *handle, void **data);
...
@@ -136,7 +136,7 @@ void *taosCacheTransfer(void *handle, void **data);
* @param _remove force model, reduce the ref count and move the data into
* @param _remove force model, reduce the ref count and move the data into
* pTrash
* pTrash
*/
*/
void
taosCacheRelease
(
void
*
handle
,
void
**
data
,
bool
_remove
);
void
taosCacheRelease
(
SCacheObj
*
pCacheObj
,
void
**
data
,
bool
_remove
);
/**
/**
* move all data node into trash, clear node in trash can if it is not referenced by any clients
* move all data node into trash, clear node in trash can if it is not referenced by any clients
...
...
src/util/src/tcache.c
浏览文件 @
5d4f826b
...
@@ -22,43 +22,43 @@
...
@@ -22,43 +22,43 @@
#include "ttimer.h"
#include "ttimer.h"
#include "tutil.h"
#include "tutil.h"
static
FORCE_INLINE
void
__cache_wr_lock
(
SCacheObj
*
pObj
)
{
static
FORCE_INLINE
void
__cache_wr_lock
(
SCacheObj
*
p
Cache
Obj
)
{
#if defined(LINUX)
#if defined(LINUX)
pthread_rwlock_wrlock
(
&
pObj
->
lock
);
pthread_rwlock_wrlock
(
&
p
Cache
Obj
->
lock
);
#else
#else
pthread_mutex_lock
(
&
pObj
->
lock
);
pthread_mutex_lock
(
&
p
Cache
Obj
->
lock
);
#endif
#endif
}
}
static
FORCE_INLINE
void
__cache_rd_lock
(
SCacheObj
*
pObj
)
{
static
FORCE_INLINE
void
__cache_rd_lock
(
SCacheObj
*
p
Cache
Obj
)
{
#if defined(LINUX)
#if defined(LINUX)
pthread_rwlock_rdlock
(
&
pObj
->
lock
);
pthread_rwlock_rdlock
(
&
p
Cache
Obj
->
lock
);
#else
#else
pthread_mutex_lock
(
&
pObj
->
lock
);
pthread_mutex_lock
(
&
p
Cache
Obj
->
lock
);
#endif
#endif
}
}
static
FORCE_INLINE
void
__cache_unlock
(
SCacheObj
*
pObj
)
{
static
FORCE_INLINE
void
__cache_unlock
(
SCacheObj
*
p
Cache
Obj
)
{
#if defined(LINUX)
#if defined(LINUX)
pthread_rwlock_unlock
(
&
pObj
->
lock
);
pthread_rwlock_unlock
(
&
p
Cache
Obj
->
lock
);
#else
#else
pthread_mutex_unlock
(
&
pObj
->
lock
);
pthread_mutex_unlock
(
&
p
Cache
Obj
->
lock
);
#endif
#endif
}
}
static
FORCE_INLINE
int32_t
__cache_lock_init
(
SCacheObj
*
pObj
)
{
static
FORCE_INLINE
int32_t
__cache_lock_init
(
SCacheObj
*
p
Cache
Obj
)
{
#if defined(LINUX)
#if defined(LINUX)
return
pthread_rwlock_init
(
&
pObj
->
lock
,
NULL
);
return
pthread_rwlock_init
(
&
p
Cache
Obj
->
lock
,
NULL
);
#else
#else
return
pthread_mutex_init
(
&
pObj
->
lock
,
NULL
);
return
pthread_mutex_init
(
&
p
Cache
Obj
->
lock
,
NULL
);
#endif
#endif
}
}
static
FORCE_INLINE
void
__cache_lock_destroy
(
SCacheObj
*
pObj
)
{
static
FORCE_INLINE
void
__cache_lock_destroy
(
SCacheObj
*
p
Cache
Obj
)
{
#if defined(LINUX)
#if defined(LINUX)
pthread_rwlock_destroy
(
&
pObj
->
lock
);
pthread_rwlock_destroy
(
&
p
Cache
Obj
->
lock
);
#else
#else
pthread_mutex_destroy
(
&
pObj
->
lock
);
pthread_mutex_destroy
(
&
p
Cache
Obj
->
lock
);
#endif
#endif
}
}
...
@@ -105,10 +105,10 @@ static SCacheDataNode *taosCreateHashNode(const char *key, size_t keyLen, const
...
@@ -105,10 +105,10 @@ static SCacheDataNode *taosCreateHashNode(const char *key, size_t keyLen, const
/**
/**
* addedTime object node into trash, and this object is closed for referencing if it is addedTime to trash
* addedTime object node into trash, and this object is closed for referencing if it is addedTime to trash
* It will be removed until the pNode->refCount == 0
* It will be removed until the pNode->refCount == 0
* @param pObj Cache object
* @param p
Cache
Obj Cache object
* @param pNode Cache slot object
* @param pNode Cache slot object
*/
*/
static
void
taosAddToTrash
(
SCacheObj
*
pObj
,
SCacheDataNode
*
pNode
)
{
static
void
taosAddToTrash
(
SCacheObj
*
p
Cache
Obj
,
SCacheDataNode
*
pNode
)
{
if
(
pNode
->
inTrash
)
{
/* node is already in trash */
if
(
pNode
->
inTrash
)
{
/* node is already in trash */
return
;
return
;
}
}
...
@@ -116,31 +116,31 @@ static void taosAddToTrash(SCacheObj *pObj, SCacheDataNode *pNode) {
...
@@ -116,31 +116,31 @@ static void taosAddToTrash(SCacheObj *pObj, SCacheDataNode *pNode) {
STrashElem
*
pElem
=
calloc
(
1
,
sizeof
(
STrashElem
));
STrashElem
*
pElem
=
calloc
(
1
,
sizeof
(
STrashElem
));
pElem
->
pData
=
pNode
;
pElem
->
pData
=
pNode
;
pElem
->
next
=
pObj
->
pTrash
;
pElem
->
next
=
p
Cache
Obj
->
pTrash
;
if
(
pObj
->
pTrash
)
{
if
(
p
Cache
Obj
->
pTrash
)
{
pObj
->
pTrash
->
prev
=
pElem
;
p
Cache
Obj
->
pTrash
->
prev
=
pElem
;
}
}
pElem
->
prev
=
NULL
;
pElem
->
prev
=
NULL
;
pObj
->
pTrash
=
pElem
;
p
Cache
Obj
->
pTrash
=
pElem
;
pNode
->
inTrash
=
true
;
pNode
->
inTrash
=
true
;
pObj
->
numOfElemsInTrash
++
;
p
Cache
Obj
->
numOfElemsInTrash
++
;
pTrace
(
"key:%s %p move to trash, numOfElem in trash:%d"
,
pNode
->
key
,
pNode
,
pObj
->
numOfElemsInTrash
);
pTrace
(
"key:%s %p move to trash, numOfElem in trash:%d"
,
pNode
->
key
,
pNode
,
p
Cache
Obj
->
numOfElemsInTrash
);
}
}
static
void
taosRemoveFromTrash
(
SCacheObj
*
pObj
,
STrashElem
*
pElem
)
{
static
void
taosRemoveFromTrash
(
SCacheObj
*
p
Cache
Obj
,
STrashElem
*
pElem
)
{
if
(
pElem
->
pData
->
signature
!=
(
uint64_t
)
pElem
->
pData
)
{
if
(
pElem
->
pData
->
signature
!=
(
uint64_t
)
pElem
->
pData
)
{
pError
(
"key:sig:%d %p data has been released, ignore"
,
pElem
->
pData
->
signature
,
pElem
->
pData
);
pError
(
"key:sig:%d %p data has been released, ignore"
,
pElem
->
pData
->
signature
,
pElem
->
pData
);
return
;
return
;
}
}
pObj
->
numOfElemsInTrash
--
;
p
Cache
Obj
->
numOfElemsInTrash
--
;
if
(
pElem
->
prev
)
{
if
(
pElem
->
prev
)
{
pElem
->
prev
->
next
=
pElem
->
next
;
pElem
->
prev
->
next
=
pElem
->
next
;
}
else
{
/* pnode is the header, update header */
}
else
{
/* pnode is the header, update header */
pObj
->
pTrash
=
pElem
->
next
;
p
Cache
Obj
->
pTrash
=
pElem
->
next
;
}
}
if
(
pElem
->
next
)
{
if
(
pElem
->
next
)
{
...
@@ -154,24 +154,24 @@ static void taosRemoveFromTrash(SCacheObj *pObj, STrashElem *pElem) {
...
@@ -154,24 +154,24 @@ static void taosRemoveFromTrash(SCacheObj *pObj, STrashElem *pElem) {
/**
/**
* remove nodes in trash with refCount == 0 in cache
* remove nodes in trash with refCount == 0 in cache
* @param pNode
* @param pNode
* @param pObj
* @param p
Cache
Obj
* @param force force model, if true, remove data in trash without check refcount.
* @param force force model, if true, remove data in trash without check refcount.
* may cause corruption. So, forece model only applys before cache is closed
* may cause corruption. So, forece model only applys before cache is closed
*/
*/
static
void
taosTrashEmpty
(
SCacheObj
*
pObj
,
bool
force
)
{
static
void
taosTrashEmpty
(
SCacheObj
*
p
Cache
Obj
,
bool
force
)
{
__cache_wr_lock
(
pObj
);
__cache_wr_lock
(
p
Cache
Obj
);
if
(
pObj
->
numOfElemsInTrash
==
0
)
{
if
(
p
Cache
Obj
->
numOfElemsInTrash
==
0
)
{
if
(
pObj
->
pTrash
!=
NULL
)
{
if
(
p
Cache
Obj
->
pTrash
!=
NULL
)
{
pError
(
"key:inconsistency data in cache, numOfElem in trash:%d"
,
pObj
->
numOfElemsInTrash
);
pError
(
"key:inconsistency data in cache, numOfElem in trash:%d"
,
p
Cache
Obj
->
numOfElemsInTrash
);
}
}
pObj
->
pTrash
=
NULL
;
p
Cache
Obj
->
pTrash
=
NULL
;
__cache_unlock
(
pObj
);
__cache_unlock
(
p
Cache
Obj
);
return
;
return
;
}
}
STrashElem
*
pElem
=
pObj
->
pTrash
;
STrashElem
*
pElem
=
p
Cache
Obj
->
pTrash
;
while
(
pElem
)
{
while
(
pElem
)
{
T_REF_VAL_CHECK
(
pElem
->
pData
);
T_REF_VAL_CHECK
(
pElem
->
pData
);
...
@@ -181,51 +181,51 @@ static void taosTrashEmpty(SCacheObj *pObj, bool force) {
...
@@ -181,51 +181,51 @@ static void taosTrashEmpty(SCacheObj *pObj, bool force) {
if
(
force
||
(
T_REF_VAL_GET
(
pElem
->
pData
)
==
0
))
{
if
(
force
||
(
T_REF_VAL_GET
(
pElem
->
pData
)
==
0
))
{
pTrace
(
"key:%s %p removed from trash. numOfElem in trash:%d"
,
pElem
->
pData
->
key
,
pElem
->
pData
,
pTrace
(
"key:%s %p removed from trash. numOfElem in trash:%d"
,
pElem
->
pData
->
key
,
pElem
->
pData
,
pObj
->
numOfElemsInTrash
-
1
);
p
Cache
Obj
->
numOfElemsInTrash
-
1
);
STrashElem
*
p
=
pElem
;
STrashElem
*
p
=
pElem
;
pElem
=
pElem
->
next
;
pElem
=
pElem
->
next
;
taosRemoveFromTrash
(
pObj
,
p
);
taosRemoveFromTrash
(
p
Cache
Obj
,
p
);
}
else
{
}
else
{
pElem
=
pElem
->
next
;
pElem
=
pElem
->
next
;
}
}
}
}
assert
(
pObj
->
numOfElemsInTrash
>=
0
);
assert
(
p
Cache
Obj
->
numOfElemsInTrash
>=
0
);
__cache_unlock
(
pObj
);
__cache_unlock
(
p
Cache
Obj
);
}
}
/**
/**
* release node
* release node
* @param pObj cache object
* @param p
Cache
Obj cache object
* @param pNode data node
* @param pNode data node
*/
*/
static
FORCE_INLINE
void
taosCacheReleaseNode
(
SCacheObj
*
pObj
,
SCacheDataNode
*
pNode
)
{
static
FORCE_INLINE
void
taosCacheReleaseNode
(
SCacheObj
*
p
Cache
Obj
,
SCacheDataNode
*
pNode
)
{
if
(
pNode
->
signature
!=
(
uint64_t
)
pNode
)
{
if
(
pNode
->
signature
!=
(
uint64_t
)
pNode
)
{
pError
(
"key:%s, %p data is invalid, or has been released"
,
pNode
->
key
,
pNode
);
pError
(
"key:%s, %p data is invalid, or has been released"
,
pNode
->
key
,
pNode
);
return
;
return
;
}
}
int32_t
size
=
pNode
->
size
;
int32_t
size
=
pNode
->
size
;
taosHashRemove
(
pObj
->
pHashTable
,
pNode
->
key
,
pNode
->
keySize
);
taosHashRemove
(
p
Cache
Obj
->
pHashTable
,
pNode
->
key
,
pNode
->
keySize
);
pTrace
(
"key:%s is removed from cache,total:%d,size:%ldbytes"
,
pNode
->
key
,
pObj
->
totalSize
,
size
);
pTrace
(
"key:%s is removed from cache,total:%d,size:%ldbytes"
,
pNode
->
key
,
p
Cache
Obj
->
totalSize
,
size
);
free
(
pNode
);
free
(
pNode
);
}
}
/**
/**
* move the old node into trash
* move the old node into trash
* @param pObj
* @param p
Cache
Obj
* @param pNode
* @param pNode
*/
*/
static
FORCE_INLINE
void
taosCacheMoveToTrash
(
SCacheObj
*
pObj
,
SCacheDataNode
*
pNode
)
{
static
FORCE_INLINE
void
taosCacheMoveToTrash
(
SCacheObj
*
p
Cache
Obj
,
SCacheDataNode
*
pNode
)
{
taosHashRemove
(
pObj
->
pHashTable
,
pNode
->
key
,
pNode
->
keySize
);
taosHashRemove
(
p
Cache
Obj
->
pHashTable
,
pNode
->
key
,
pNode
->
keySize
);
taosAddToTrash
(
pObj
,
pNode
);
taosAddToTrash
(
p
Cache
Obj
,
pNode
);
}
}
/**
/**
* update data in cache
* update data in cache
* @param pObj
* @param p
Cache
Obj
* @param pNode
* @param pNode
* @param key
* @param key
* @param keyLen
* @param keyLen
...
@@ -233,7 +233,7 @@ static FORCE_INLINE void taosCacheMoveToTrash(SCacheObj *pObj, SCacheDataNode *p
...
@@ -233,7 +233,7 @@ static FORCE_INLINE void taosCacheMoveToTrash(SCacheObj *pObj, SCacheDataNode *p
* @param dataSize
* @param dataSize
* @return
* @return
*/
*/
static
SCacheDataNode
*
taosUpdateCacheImpl
(
SCacheObj
*
pObj
,
SCacheDataNode
*
pNode
,
char
*
key
,
int32_t
keyLen
,
static
SCacheDataNode
*
taosUpdateCacheImpl
(
SCacheObj
*
p
Cache
Obj
,
SCacheDataNode
*
pNode
,
char
*
key
,
int32_t
keyLen
,
void
*
pData
,
uint32_t
dataSize
,
uint64_t
duration
)
{
void
*
pData
,
uint32_t
dataSize
,
uint64_t
duration
)
{
SCacheDataNode
*
pNewNode
=
NULL
;
SCacheDataNode
*
pNewNode
=
NULL
;
...
@@ -260,9 +260,9 @@ static SCacheDataNode *taosUpdateCacheImpl(SCacheObj *pObj, SCacheDataNode *pNod
...
@@ -260,9 +260,9 @@ static SCacheDataNode *taosUpdateCacheImpl(SCacheObj *pObj, SCacheDataNode *pNod
T_REF_INC
(
pNewNode
);
T_REF_INC
(
pNewNode
);
// the address of this node may be changed, so the prev and next element should update the corresponding pointer
// the address of this node may be changed, so the prev and next element should update the corresponding pointer
taosHashPut
(
pObj
->
pHashTable
,
key
,
keyLen
,
&
pNewNode
,
sizeof
(
void
*
));
taosHashPut
(
p
Cache
Obj
->
pHashTable
,
key
,
keyLen
,
&
pNewNode
,
sizeof
(
void
*
));
}
else
{
}
else
{
taosCacheMoveToTrash
(
pObj
,
pNode
);
taosCacheMoveToTrash
(
p
Cache
Obj
,
pNode
);
pNewNode
=
taosCreateHashNode
(
key
,
keyLen
,
pData
,
dataSize
,
duration
);
pNewNode
=
taosCreateHashNode
(
key
,
keyLen
,
pData
,
dataSize
,
duration
);
if
(
pNewNode
==
NULL
)
{
if
(
pNewNode
==
NULL
)
{
...
@@ -272,7 +272,7 @@ static SCacheDataNode *taosUpdateCacheImpl(SCacheObj *pObj, SCacheDataNode *pNod
...
@@ -272,7 +272,7 @@ static SCacheDataNode *taosUpdateCacheImpl(SCacheObj *pObj, SCacheDataNode *pNod
T_REF_INC
(
pNewNode
);
T_REF_INC
(
pNewNode
);
// addedTime new element to hashtable
// addedTime new element to hashtable
taosHashPut
(
pObj
->
pHashTable
,
key
,
keyLen
,
&
pNewNode
,
sizeof
(
void
*
));
taosHashPut
(
p
Cache
Obj
->
pHashTable
,
key
,
keyLen
,
&
pNewNode
,
sizeof
(
void
*
));
}
}
return
pNewNode
;
return
pNewNode
;
...
@@ -283,12 +283,12 @@ static SCacheDataNode *taosUpdateCacheImpl(SCacheObj *pObj, SCacheDataNode *pNod
...
@@ -283,12 +283,12 @@ static SCacheDataNode *taosUpdateCacheImpl(SCacheObj *pObj, SCacheDataNode *pNod
* @param key
* @param key
* @param pData
* @param pData
* @param size
* @param size
* @param pObj
* @param p
Cache
Obj
* @param keyLen
* @param keyLen
* @param pNode
* @param pNode
* @return
* @return
*/
*/
static
FORCE_INLINE
SCacheDataNode
*
taosAddToCacheImpl
(
SCacheObj
*
pObj
,
char
*
key
,
size_t
keyLen
,
const
void
*
pData
,
static
FORCE_INLINE
SCacheDataNode
*
taosAddToCacheImpl
(
SCacheObj
*
p
Cache
Obj
,
char
*
key
,
size_t
keyLen
,
const
void
*
pData
,
size_t
dataSize
,
uint64_t
duration
)
{
size_t
dataSize
,
uint64_t
duration
)
{
SCacheDataNode
*
pNode
=
taosCreateHashNode
(
key
,
keyLen
,
pData
,
dataSize
,
duration
);
SCacheDataNode
*
pNode
=
taosCreateHashNode
(
key
,
keyLen
,
pData
,
dataSize
,
duration
);
if
(
pNode
==
NULL
)
{
if
(
pNode
==
NULL
)
{
...
@@ -296,70 +296,70 @@ static FORCE_INLINE SCacheDataNode *taosAddToCacheImpl(SCacheObj *pObj, char *ke
...
@@ -296,70 +296,70 @@ static FORCE_INLINE SCacheDataNode *taosAddToCacheImpl(SCacheObj *pObj, char *ke
}
}
T_REF_INC
(
pNode
);
T_REF_INC
(
pNode
);
taosHashPut
(
pObj
->
pHashTable
,
key
,
keyLen
,
&
pNode
,
sizeof
(
void
*
));
taosHashPut
(
p
Cache
Obj
->
pHashTable
,
key
,
keyLen
,
&
pNode
,
sizeof
(
void
*
));
return
pNode
;
return
pNode
;
}
}
static
void
doCleanupDataCache
(
SCacheObj
*
pObj
)
{
static
void
doCleanupDataCache
(
SCacheObj
*
p
Cache
Obj
)
{
__cache_wr_lock
(
pObj
);
__cache_wr_lock
(
p
Cache
Obj
);
if
(
taosHashGetSize
(
pObj
->
pHashTable
)
>
0
)
{
if
(
taosHashGetSize
(
p
Cache
Obj
->
pHashTable
)
>
0
)
{
taosHashCleanup
(
pObj
->
pHashTable
);
taosHashCleanup
(
p
Cache
Obj
->
pHashTable
);
}
}
__cache_unlock
(
pObj
);
__cache_unlock
(
p
Cache
Obj
);
taosTrashEmpty
(
pObj
,
true
);
taosTrashEmpty
(
p
Cache
Obj
,
true
);
__cache_lock_destroy
(
pObj
);
__cache_lock_destroy
(
p
Cache
Obj
);
memset
(
pObj
,
0
,
sizeof
(
SCacheObj
));
memset
(
p
Cache
Obj
,
0
,
sizeof
(
SCacheObj
));
free
(
pObj
);
free
(
p
Cache
Obj
);
}
}
/**
/**
* refresh cache to remove data in both hash list and trash, if any nodes' refcount == 0, every pObj->refreshTime
* refresh cache to remove data in both hash list and trash, if any nodes' refcount == 0, every p
Cache
Obj->refreshTime
* @param handle Cache object handle
* @param handle Cache object handle
*/
*/
static
void
taosCacheRefresh
(
void
*
handle
,
void
*
tmrId
)
{
static
void
taosCacheRefresh
(
void
*
handle
,
void
*
tmrId
)
{
SCacheObj
*
pObj
=
(
SCacheObj
*
)
handle
;
SCacheObj
*
p
Cache
Obj
=
(
SCacheObj
*
)
handle
;
if
(
p
Obj
==
NULL
||
taosHashGetSize
(
p
Obj
->
pHashTable
)
==
0
)
{
if
(
p
CacheObj
==
NULL
||
taosHashGetSize
(
pCache
Obj
->
pHashTable
)
==
0
)
{
pTrace
(
"object is destroyed. no refresh retry"
);
pTrace
(
"object is destroyed. no refresh retry"
);
return
;
return
;
}
}
if
(
pObj
->
deleting
==
1
)
{
if
(
p
Cache
Obj
->
deleting
==
1
)
{
doCleanupDataCache
(
pObj
);
doCleanupDataCache
(
p
Cache
Obj
);
return
;
return
;
}
}
uint64_t
expiredTime
=
taosGetTimestampMs
();
uint64_t
expiredTime
=
taosGetTimestampMs
();
pObj
->
statistics
.
refreshCount
++
;
p
Cache
Obj
->
statistics
.
refreshCount
++
;
SHashMutableIterator
*
pIter
=
taosHashCreateIter
(
pObj
->
pHashTable
);
SHashMutableIterator
*
pIter
=
taosHashCreateIter
(
p
Cache
Obj
->
pHashTable
);
__cache_wr_lock
(
pObj
);
__cache_wr_lock
(
p
Cache
Obj
);
while
(
taosHashIterNext
(
pIter
))
{
while
(
taosHashIterNext
(
pIter
))
{
if
(
pObj
->
deleting
==
1
)
{
if
(
p
Cache
Obj
->
deleting
==
1
)
{
taosHashDestroyIter
(
pIter
);
taosHashDestroyIter
(
pIter
);
break
;
break
;
}
}
SCacheDataNode
*
pNode
=
*
(
SCacheDataNode
**
)
taosHashIterGet
(
pIter
);
SCacheDataNode
*
pNode
=
*
(
SCacheDataNode
**
)
taosHashIterGet
(
pIter
);
if
(
pNode
->
expiredTime
<=
expiredTime
&&
T_REF_VAL_GET
(
pNode
)
<=
0
)
{
if
(
pNode
->
expiredTime
<=
expiredTime
&&
T_REF_VAL_GET
(
pNode
)
<=
0
)
{
taosCacheReleaseNode
(
pObj
,
pNode
);
taosCacheReleaseNode
(
p
Cache
Obj
,
pNode
);
}
}
}
}
__cache_unlock
(
pObj
);
__cache_unlock
(
p
Cache
Obj
);
taosHashDestroyIter
(
pIter
);
taosHashDestroyIter
(
pIter
);
if
(
pObj
->
deleting
==
1
)
{
// clean up resources and abort
if
(
p
Cache
Obj
->
deleting
==
1
)
{
// clean up resources and abort
doCleanupDataCache
(
pObj
);
doCleanupDataCache
(
p
Cache
Obj
);
}
else
{
}
else
{
taosTrashEmpty
(
pObj
,
false
);
taosTrashEmpty
(
p
Cache
Obj
,
false
);
taosTmrReset
(
taosCacheRefresh
,
p
Obj
->
refreshTime
,
pObj
,
pObj
->
tmrCtrl
,
&
p
Obj
->
pTimer
);
taosTmrReset
(
taosCacheRefresh
,
p
CacheObj
->
refreshTime
,
pCacheObj
,
pCacheObj
->
tmrCtrl
,
&
pCache
Obj
->
pTimer
);
}
}
}
}
...
@@ -368,104 +368,100 @@ SCacheObj *taosCacheInit(void *tmrCtrl, int64_t refreshTime) {
...
@@ -368,104 +368,100 @@ SCacheObj *taosCacheInit(void *tmrCtrl, int64_t refreshTime) {
return
NULL
;
return
NULL
;
}
}
SCacheObj
*
pObj
=
(
SCacheObj
*
)
calloc
(
1
,
sizeof
(
SCacheObj
));
SCacheObj
*
p
Cache
Obj
=
(
SCacheObj
*
)
calloc
(
1
,
sizeof
(
SCacheObj
));
if
(
pObj
==
NULL
)
{
if
(
p
Cache
Obj
==
NULL
)
{
pError
(
"failed to allocate memory, reason:%s"
,
strerror
(
errno
));
pError
(
"failed to allocate memory, reason:%s"
,
strerror
(
errno
));
return
NULL
;
return
NULL
;
}
}
pObj
->
pHashTable
=
taosHashInit
(
1024
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_BINARY
),
false
);
p
Cache
Obj
->
pHashTable
=
taosHashInit
(
1024
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_BINARY
),
false
);
if
(
pObj
->
pHashTable
==
NULL
)
{
if
(
p
Cache
Obj
->
pHashTable
==
NULL
)
{
free
(
pObj
);
free
(
p
Cache
Obj
);
pError
(
"failed to allocate memory, reason:%s"
,
strerror
(
errno
));
pError
(
"failed to allocate memory, reason:%s"
,
strerror
(
errno
));
return
NULL
;
return
NULL
;
}
}
// set free cache node callback function for hash table
// set free cache node callback function for hash table
taosHashSetFreecb
(
pObj
->
pHashTable
,
taosFreeNode
);
taosHashSetFreecb
(
p
Cache
Obj
->
pHashTable
,
taosFreeNode
);
pObj
->
refreshTime
=
refreshTime
*
1000
;
p
Cache
Obj
->
refreshTime
=
refreshTime
*
1000
;
pObj
->
tmrCtrl
=
tmrCtrl
;
p
Cache
Obj
->
tmrCtrl
=
tmrCtrl
;
taosTmrReset
(
taosCacheRefresh
,
p
Obj
->
refreshTime
,
pObj
,
pObj
->
tmrCtrl
,
&
p
Obj
->
pTimer
);
taosTmrReset
(
taosCacheRefresh
,
p
CacheObj
->
refreshTime
,
pCacheObj
,
pCacheObj
->
tmrCtrl
,
&
pCache
Obj
->
pTimer
);
if
(
__cache_lock_init
(
pObj
)
!=
0
)
{
if
(
__cache_lock_init
(
p
Cache
Obj
)
!=
0
)
{
taosTmrStopA
(
&
pObj
->
pTimer
);
taosTmrStopA
(
&
p
Cache
Obj
->
pTimer
);
taosHashCleanup
(
pObj
->
pHashTable
);
taosHashCleanup
(
p
Cache
Obj
->
pHashTable
);
free
(
pObj
);
free
(
p
Cache
Obj
);
pError
(
"failed to init lock, reason:%s"
,
strerror
(
errno
));
pError
(
"failed to init lock, reason:%s"
,
strerror
(
errno
));
return
NULL
;
return
NULL
;
}
}
return
pObj
;
return
p
Cache
Obj
;
}
}
void
*
taosCachePut
(
void
*
handle
,
char
*
key
,
char
*
pData
,
in
t
dataSize
,
int
duration
)
{
void
*
taosCachePut
(
SCacheObj
*
pCacheObj
,
char
*
key
,
void
*
pData
,
size_
t
dataSize
,
int
duration
)
{
SCacheDataNode
*
pNode
;
SCacheDataNode
*
pNode
;
SCacheObj
*
pObj
;
pObj
=
(
SCacheObj
*
)
handle
;
if
(
pCacheObj
==
NULL
||
pCacheObj
->
pHashTable
==
NULL
)
{
if
(
pObj
==
NULL
||
pObj
->
pHashTable
==
NULL
)
{
return
NULL
;
return
NULL
;
}
}
size_t
keyLen
=
strlen
(
key
);
size_t
keyLen
=
strlen
(
key
);
__cache_wr_lock
(
pObj
);
__cache_wr_lock
(
p
Cache
Obj
);
SCacheDataNode
**
pt
=
(
SCacheDataNode
**
)
taosHashGet
(
pObj
->
pHashTable
,
key
,
keyLen
);
SCacheDataNode
**
pt
=
(
SCacheDataNode
**
)
taosHashGet
(
p
Cache
Obj
->
pHashTable
,
key
,
keyLen
);
SCacheDataNode
*
pOld
=
(
pt
!=
NULL
)
?
(
*
pt
)
:
NULL
;
SCacheDataNode
*
pOld
=
(
pt
!=
NULL
)
?
(
*
pt
)
:
NULL
;
if
(
pOld
==
NULL
)
{
// do addedTime to cache
if
(
pOld
==
NULL
)
{
// do addedTime to cache
pNode
=
taosAddToCacheImpl
(
pObj
,
key
,
keyLen
,
pData
,
dataSize
,
duration
*
1000L
);
pNode
=
taosAddToCacheImpl
(
p
Cache
Obj
,
key
,
keyLen
,
pData
,
dataSize
,
duration
*
1000L
);
if
(
NULL
!=
pNode
)
{
if
(
NULL
!=
pNode
)
{
pObj
->
totalSize
+=
pNode
->
size
;
p
Cache
Obj
->
totalSize
+=
pNode
->
size
;
pTrace
(
"key:%s %p added into cache, added:%"
PRIu64
", expire:%"
PRIu64
", total:%d, size:%"
PRId64
" bytes"
,
pTrace
(
"key:%s %p added into cache, added:%"
PRIu64
", expire:%"
PRIu64
", total:%d, size:%"
PRId64
" bytes"
,
key
,
pNode
,
pNode
->
addedTime
,
pNode
->
expiredTime
,
pObj
->
totalSize
,
dataSize
);
key
,
pNode
,
pNode
->
addedTime
,
pNode
->
expiredTime
,
p
Cache
Obj
->
totalSize
,
dataSize
);
}
}
}
else
{
// old data exists, update the node
}
else
{
// old data exists, update the node
pNode
=
taosUpdateCacheImpl
(
pObj
,
pOld
,
key
,
keyLen
,
pData
,
dataSize
,
duration
*
1000L
);
pNode
=
taosUpdateCacheImpl
(
p
Cache
Obj
,
pOld
,
key
,
keyLen
,
pData
,
dataSize
,
duration
*
1000L
);
pTrace
(
"key:%s %p exist in cache, updated"
,
key
,
pNode
);
pTrace
(
"key:%s %p exist in cache, updated"
,
key
,
pNode
);
}
}
__cache_unlock
(
pObj
);
__cache_unlock
(
p
Cache
Obj
);
return
(
pNode
!=
NULL
)
?
pNode
->
data
:
NULL
;
return
(
pNode
!=
NULL
)
?
pNode
->
data
:
NULL
;
}
}
void
*
taosCacheAcquireByName
(
void
*
handle
,
char
*
key
)
{
void
*
taosCacheAcquireByName
(
SCacheObj
*
pCacheObj
,
const
char
*
key
)
{
SCacheObj
*
pObj
=
(
SCacheObj
*
)
handle
;
if
(
pCacheObj
==
NULL
||
taosHashGetSize
(
pCacheObj
->
pHashTable
)
==
0
)
{
if
(
pObj
==
NULL
||
taosHashGetSize
(
pObj
->
pHashTable
)
==
0
)
{
return
NULL
;
return
NULL
;
}
}
uint32_t
keyLen
=
(
uint32_t
)
strlen
(
key
);
uint32_t
keyLen
=
(
uint32_t
)
strlen
(
key
);
__cache_rd_lock
(
pObj
);
__cache_rd_lock
(
p
Cache
Obj
);
SCacheDataNode
**
ptNode
=
(
SCacheDataNode
**
)
taosHashGet
(
pObj
->
pHashTable
,
key
,
keyLen
);
SCacheDataNode
**
ptNode
=
(
SCacheDataNode
**
)
taosHashGet
(
p
Cache
Obj
->
pHashTable
,
key
,
keyLen
);
if
(
ptNode
!=
NULL
)
{
if
(
ptNode
!=
NULL
)
{
T_REF_INC
(
*
ptNode
);
T_REF_INC
(
*
ptNode
);
}
}
__cache_unlock
(
pObj
);
__cache_unlock
(
p
Cache
Obj
);
if
(
ptNode
!=
NULL
)
{
if
(
ptNode
!=
NULL
)
{
atomic_add_fetch_32
(
&
pObj
->
statistics
.
hitCount
,
1
);
atomic_add_fetch_32
(
&
p
Cache
Obj
->
statistics
.
hitCount
,
1
);
pTrace
(
"key:%s is retrieved from cache,refcnt:%d"
,
key
,
T_REF_VAL_GET
(
*
ptNode
));
pTrace
(
"key:%s is retrieved from cache,refcnt:%d"
,
key
,
T_REF_VAL_GET
(
*
ptNode
));
}
else
{
}
else
{
atomic_add_fetch_32
(
&
pObj
->
statistics
.
missCount
,
1
);
atomic_add_fetch_32
(
&
p
Cache
Obj
->
statistics
.
missCount
,
1
);
pTrace
(
"key:%s not in cache,retrieved failed"
,
key
);
pTrace
(
"key:%s not in cache,retrieved failed"
,
key
);
}
}
atomic_add_fetch_32
(
&
pObj
->
statistics
.
totalAccess
,
1
);
atomic_add_fetch_32
(
&
p
Cache
Obj
->
statistics
.
totalAccess
,
1
);
return
(
ptNode
!=
NULL
)
?
(
*
ptNode
)
->
data
:
NULL
;
return
(
ptNode
!=
NULL
)
?
(
*
ptNode
)
->
data
:
NULL
;
}
}
void
*
taosCacheAcquireByData
(
void
*
handle
,
void
*
data
)
{
void
*
taosCacheAcquireByData
(
SCacheObj
*
pCacheObj
,
void
*
data
)
{
SCacheObj
*
pObj
=
(
SCacheObj
*
)
handle
;
if
(
pCacheObj
==
NULL
||
data
==
NULL
)
return
NULL
;
if
(
pObj
==
NULL
||
data
==
NULL
)
return
NULL
;
size_t
offset
=
offsetof
(
SCacheDataNode
,
data
);
size_t
offset
=
offsetof
(
SCacheDataNode
,
data
);
SCacheDataNode
*
ptNode
=
(
SCacheDataNode
*
)((
char
*
)
data
-
offset
);
SCacheDataNode
*
ptNode
=
(
SCacheDataNode
*
)((
char
*
)
data
-
offset
);
...
@@ -483,9 +479,8 @@ void *taosCacheAcquireByData(void *handle, void *data) {
...
@@ -483,9 +479,8 @@ void *taosCacheAcquireByData(void *handle, void *data) {
return
data
;
return
data
;
}
}
void
*
taosCacheTransfer
(
void
*
handle
,
void
**
data
)
{
void
*
taosCacheTransfer
(
SCacheObj
*
pCacheObj
,
void
**
data
)
{
SCacheObj
*
pObj
=
(
SCacheObj
*
)
handle
;
if
(
pCacheObj
==
NULL
||
data
==
NULL
)
return
NULL
;
if
(
pObj
==
NULL
||
data
==
NULL
)
return
NULL
;
size_t
offset
=
offsetof
(
SCacheDataNode
,
data
);
size_t
offset
=
offsetof
(
SCacheDataNode
,
data
);
SCacheDataNode
*
ptNode
=
(
SCacheDataNode
*
)((
char
*
)(
*
data
)
-
offset
);
SCacheDataNode
*
ptNode
=
(
SCacheDataNode
*
)((
char
*
)(
*
data
)
-
offset
);
...
@@ -505,9 +500,8 @@ void *taosCacheTransfer(void *handle, void **data) {
...
@@ -505,9 +500,8 @@ void *taosCacheTransfer(void *handle, void **data) {
return
d
;
return
d
;
}
}
void
taosCacheRelease
(
void
*
handle
,
void
**
data
,
bool
_remove
)
{
void
taosCacheRelease
(
SCacheObj
*
pCacheObj
,
void
**
data
,
bool
_remove
)
{
SCacheObj
*
pObj
=
(
SCacheObj
*
)
handle
;
if
(
pCacheObj
==
NULL
||
(
*
data
)
==
NULL
||
(
taosHashGetSize
(
pCacheObj
->
pHashTable
)
+
pCacheObj
->
numOfElemsInTrash
==
0
))
{
if
(
pObj
==
NULL
||
(
*
data
)
==
NULL
||
(
taosHashGetSize
(
pObj
->
pHashTable
)
+
pObj
->
numOfElemsInTrash
==
0
))
{
return
;
return
;
}
}
...
@@ -523,13 +517,13 @@ void taosCacheRelease(void *handle, void **data, bool _remove) {
...
@@ -523,13 +517,13 @@ void taosCacheRelease(void *handle, void **data, bool _remove) {
*
data
=
NULL
;
*
data
=
NULL
;
if
(
_remove
)
{
if
(
_remove
)
{
__cache_wr_lock
(
pObj
);
__cache_wr_lock
(
p
Cache
Obj
);
// pNode may be released immediately by other thread after the reference count of pNode is set to 0,
// pNode may be released immediately by other thread after the reference count of pNode is set to 0,
// So we need to lock it in the first place.
// So we need to lock it in the first place.
T_REF_DEC
(
pNode
);
T_REF_DEC
(
pNode
);
taosCacheMoveToTrash
(
pObj
,
pNode
);
taosCacheMoveToTrash
(
p
Cache
Obj
,
pNode
);
__cache_unlock
(
pObj
);
__cache_unlock
(
p
Cache
Obj
);
}
else
{
}
else
{
T_REF_DEC
(
pNode
);
T_REF_DEC
(
pNode
);
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录