Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
loser646
TDengine
提交
8504daea
T
TDengine
项目概览
loser646
/
TDengine
与 Fork 源项目一致
Fork自
taosdata / TDengine
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
8504daea
编写于
3月 14, 2020
作者:
H
hjxilinx
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactor cache module based on new hash table and reference count management module
上级
98b4296b
变更
7
展开全部
隐藏空白更改
内联
并排
Showing
7 changed file
with
432 addition
and
767 deletion
+432
-767
src/client/src/tcache.c
src/client/src/tcache.c
+302
-687
src/client/src/tscLocal.c
src/client/src/tscLocal.c
+1
-1
src/client/src/tscServer.c
src/client/src/tscServer.c
+25
-26
src/client/src/tscSub.c
src/client/src/tscSub.c
+1
-1
src/client/src/tscSystem.c
src/client/src/tscSystem.c
+1
-1
src/client/src/tscUtil.c
src/client/src/tscUtil.c
+10
-10
src/query/inc/tcache.h
src/query/inc/tcache.h
+92
-41
未找到文件。
src/client/src/tcache.c
浏览文件 @
8504daea
此差异已折叠。
点击以展开。
src/client/src/tscLocal.c
浏览文件 @
8504daea
...
...
@@ -484,7 +484,7 @@ int tscProcessLocalCmd(SSqlObj *pSql) {
pSql
->
res
.
qhandle
=
0x1
;
pSql
->
res
.
numOfRows
=
0
;
}
else
if
(
pCmd
->
command
==
TSDB_SQL_RESET_CACHE
)
{
taosC
learDataCache
(
tscCacheHandle
);
taosC
acheEmpty
(
tscCacheHandle
);
}
else
if
(
pCmd
->
command
==
TSDB_SQL_SERV_VERSION
)
{
tscProcessServerVer
(
pSql
);
}
else
if
(
pCmd
->
command
==
TSDB_SQL_CLI_VERSION
)
{
...
...
src/client/src/tscServer.c
浏览文件 @
8504daea
...
...
@@ -182,7 +182,6 @@ int tscSendMsgToServer(SSqlObj *pSql) {
}
pSql
->
ipList
->
ip
[
0
]
=
inet_addr
(
"192.168.0.1"
);
SSqlCmd
*
pCmd
=
&
pSql
->
cmd
;
if
(
pSql
->
cmd
.
command
<
TSDB_SQL_MGMT
)
{
pSql
->
ipList
->
port
=
tsDnodeShellPort
;
...
...
@@ -2641,7 +2640,7 @@ int tscProcessMeterMetaRsp(SSqlObj *pSql) {
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfo
(
&
pSql
->
cmd
,
0
,
0
);
assert
(
pMeterMetaInfo
->
pMeterMeta
==
NULL
);
pMeterMetaInfo
->
pMeterMeta
=
(
STableMeta
*
)
taos
AddDataIntoCache
(
tscCacheHandle
,
pMeterMetaInfo
->
name
,
(
char
*
)
pMeta
,
pMeterMetaInfo
->
pMeterMeta
=
(
STableMeta
*
)
taos
CachePut
(
tscCacheHandle
,
pMeterMetaInfo
->
name
,
(
char
*
)
pMeta
,
pMeta
->
contLen
,
tsMeterMetaKeepTimer
);
// todo handle out of memory case
if
(
pMeterMetaInfo
->
pMeterMeta
==
NULL
)
return
0
;
...
...
@@ -2750,7 +2749,7 @@ int tscProcessMultiMeterMetaRsp(SSqlObj *pSql) {
int32_t
size
=
(
int32_t
)(
rsp
-
((
char
*
)
pMeta
));
// Consistent with STableMeta in cache
pMeta
->
index
=
0
;
(
void
)
taos
AddDataIntoCache
(
tscCacheHandle
,
pMeta
->
tableId
,
(
char
*
)
pMeta
,
size
,
tsMeterMetaKeepTimer
);
(
void
)
taos
CachePut
(
tscCacheHandle
,
pMeta
->
tableId
,
(
char
*
)
pMeta
,
size
,
tsMeterMetaKeepTimer
);
}
pSql
->
res
.
code
=
TSDB_CODE_SUCCESS
;
...
...
@@ -2857,9 +2856,9 @@ int tscProcessMetricMetaRsp(SSqlObj *pSql) {
#endif
// release the used metricmeta
taos
RemoveDataFromCach
e
(
tscCacheHandle
,
(
void
**
)
&
(
pMeterMetaInfo
->
pMetricMeta
),
false
);
taos
CacheReleas
e
(
tscCacheHandle
,
(
void
**
)
&
(
pMeterMetaInfo
->
pMetricMeta
),
false
);
pMeterMetaInfo
->
pMetricMeta
=
(
SSuperTableMeta
*
)
taos
AddDataIntoCache
(
tscCacheHandle
,
name
,
(
char
*
)
metricMetaList
[
i
],
pMeterMetaInfo
->
pMetricMeta
=
(
SSuperTableMeta
*
)
taos
CachePut
(
tscCacheHandle
,
name
,
(
char
*
)
metricMetaList
[
i
],
sizes
[
i
],
tsMetricMetaKeepTimer
);
tfree
(
metricMetaList
[
i
]);
...
...
@@ -2917,11 +2916,11 @@ int tscProcessShowRsp(SSqlObj *pSql) {
key
[
0
]
=
pCmd
->
msgType
+
'a'
;
strcpy
(
key
+
1
,
"showlist"
);
taos
RemoveDataFromCach
e
(
tscCacheHandle
,
(
void
*
)
&
(
pMeterMetaInfo
->
pMeterMeta
),
false
);
taos
CacheReleas
e
(
tscCacheHandle
,
(
void
*
)
&
(
pMeterMetaInfo
->
pMeterMeta
),
false
);
int32_t
size
=
pMeta
->
numOfColumns
*
sizeof
(
SSchema
)
+
sizeof
(
STableMeta
);
pMeterMetaInfo
->
pMeterMeta
=
(
STableMeta
*
)
taos
AddDataIntoCache
(
tscCacheHandle
,
key
,
(
char
*
)
pMeta
,
size
,
tsMeterMetaKeepTimer
);
(
STableMeta
*
)
taos
CachePut
(
tscCacheHandle
,
key
,
(
char
*
)
pMeta
,
size
,
tsMeterMetaKeepTimer
);
pCmd
->
numOfCols
=
pQueryInfo
->
fieldsInfo
.
numOfOutputCols
;
SSchema
*
pMeterSchema
=
tsGetSchema
(
pMeterMetaInfo
->
pMeterMeta
);
...
...
@@ -2975,14 +2974,14 @@ int tscProcessUseDbRsp(SSqlObj *pSql) {
}
int
tscProcessDropDbRsp
(
SSqlObj
*
UNUSED_PARAM
(
pSql
))
{
taosC
learDataCache
(
tscCacheHandle
);
taosC
acheEmpty
(
tscCacheHandle
);
return
0
;
}
int
tscProcessDropTableRsp
(
SSqlObj
*
pSql
)
{
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfo
(
&
pSql
->
cmd
,
0
,
0
);
STableMeta
*
pMeterMeta
=
taos
GetDataFromCach
e
(
tscCacheHandle
,
pMeterMetaInfo
->
name
);
STableMeta
*
pMeterMeta
=
taos
CacheAcquireByNam
e
(
tscCacheHandle
,
pMeterMetaInfo
->
name
);
if
(
pMeterMeta
==
NULL
)
{
/* not in cache, abort */
return
0
;
...
...
@@ -2996,11 +2995,11 @@ int tscProcessDropTableRsp(SSqlObj *pSql) {
* instead.
*/
tscTrace
(
"%p force release metermeta after drop table:%s"
,
pSql
,
pMeterMetaInfo
->
name
);
taos
RemoveDataFromCach
e
(
tscCacheHandle
,
(
void
**
)
&
pMeterMeta
,
true
);
taos
CacheReleas
e
(
tscCacheHandle
,
(
void
**
)
&
pMeterMeta
,
true
);
if
(
pMeterMetaInfo
->
pMeterMeta
)
{
taos
RemoveDataFromCach
e
(
tscCacheHandle
,
(
void
**
)
&
(
pMeterMetaInfo
->
pMeterMeta
),
true
);
taos
RemoveDataFromCach
e
(
tscCacheHandle
,
(
void
**
)
&
(
pMeterMetaInfo
->
pMetricMeta
),
true
);
taos
CacheReleas
e
(
tscCacheHandle
,
(
void
**
)
&
(
pMeterMetaInfo
->
pMeterMeta
),
true
);
taos
CacheReleas
e
(
tscCacheHandle
,
(
void
**
)
&
(
pMeterMetaInfo
->
pMetricMeta
),
true
);
}
return
0
;
...
...
@@ -3009,23 +3008,23 @@ int tscProcessDropTableRsp(SSqlObj *pSql) {
int
tscProcessAlterTableMsgRsp
(
SSqlObj
*
pSql
)
{
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfo
(
&
pSql
->
cmd
,
0
,
0
);
STableMeta
*
pMeterMeta
=
taos
GetDataFromCach
e
(
tscCacheHandle
,
pMeterMetaInfo
->
name
);
STableMeta
*
pMeterMeta
=
taos
CacheAcquireByNam
e
(
tscCacheHandle
,
pMeterMetaInfo
->
name
);
if
(
pMeterMeta
==
NULL
)
{
/* not in cache, abort */
return
0
;
}
tscTrace
(
"%p force release metermeta in cache after alter-table: %s"
,
pSql
,
pMeterMetaInfo
->
name
);
taos
RemoveDataFromCach
e
(
tscCacheHandle
,
(
void
**
)
&
pMeterMeta
,
true
);
taos
CacheReleas
e
(
tscCacheHandle
,
(
void
**
)
&
pMeterMeta
,
true
);
if
(
pMeterMetaInfo
->
pMeterMeta
)
{
bool
isSuperTable
=
UTIL_METER_IS_SUPERTABLE
(
pMeterMetaInfo
);
taos
RemoveDataFromCach
e
(
tscCacheHandle
,
(
void
**
)
&
(
pMeterMetaInfo
->
pMeterMeta
),
true
);
taos
RemoveDataFromCach
e
(
tscCacheHandle
,
(
void
**
)
&
(
pMeterMetaInfo
->
pMetricMeta
),
true
);
taos
CacheReleas
e
(
tscCacheHandle
,
(
void
**
)
&
(
pMeterMetaInfo
->
pMeterMeta
),
true
);
taos
CacheReleas
e
(
tscCacheHandle
,
(
void
**
)
&
(
pMeterMetaInfo
->
pMetricMeta
),
true
);
if
(
isSuperTable
)
{
// if it is a super table, reset whole query cache
tscTrace
(
"%p reset query cache since table:%s is stable"
,
pSql
,
pMeterMetaInfo
->
name
);
taosC
learDataCache
(
tscCacheHandle
);
taosC
acheEmpty
(
tscCacheHandle
);
}
}
...
...
@@ -3151,7 +3150,7 @@ static int32_t doGetMeterMetaFromServer(SSqlObj *pSql, SMeterMetaInfo *pMeterMet
* Transfer the ownership of metermeta to the new object, instead of invoking the release/acquire routine
*/
if
(
code
==
TSDB_CODE_SUCCESS
)
{
pMeterMetaInfo
->
pMeterMeta
=
taos
TransferDataInCache
(
tscCacheHandle
,
(
void
**
)
&
pNewMeterMetaInfo
->
pMeterMeta
);
pMeterMetaInfo
->
pMeterMeta
=
taos
CacheTransfer
(
tscCacheHandle
,
(
void
**
)
&
pNewMeterMetaInfo
->
pMeterMeta
);
assert
(
pMeterMetaInfo
->
pMeterMeta
!=
NULL
);
}
...
...
@@ -3177,10 +3176,10 @@ int tscGetMeterMeta(SSqlObj *pSql, SMeterMetaInfo *pMeterMetaInfo) {
// If this SMeterMetaInfo owns a metermeta, release it first
if
(
pMeterMetaInfo
->
pMeterMeta
!=
NULL
)
{
taos
RemoveDataFromCach
e
(
tscCacheHandle
,
(
void
**
)
&
(
pMeterMetaInfo
->
pMeterMeta
),
false
);
taos
CacheReleas
e
(
tscCacheHandle
,
(
void
**
)
&
(
pMeterMetaInfo
->
pMeterMeta
),
false
);
}
pMeterMetaInfo
->
pMeterMeta
=
(
STableMeta
*
)
taos
GetDataFromCach
e
(
tscCacheHandle
,
pMeterMetaInfo
->
name
);
pMeterMetaInfo
->
pMeterMeta
=
(
STableMeta
*
)
taos
CacheAcquireByNam
e
(
tscCacheHandle
,
pMeterMetaInfo
->
name
);
if
(
pMeterMetaInfo
->
pMeterMeta
!=
NULL
)
{
STableMeta
*
pMeterMeta
=
pMeterMetaInfo
->
pMeterMeta
;
...
...
@@ -3244,7 +3243,7 @@ int tscRenewMeterMeta(SSqlObj *pSql, char *tableId) {
}
tscWaitingForCreateTable
(
pCmd
);
taos
RemoveDataFromCach
e
(
tscCacheHandle
,
(
void
**
)
&
(
pMeterMetaInfo
->
pMeterMeta
),
true
);
taos
CacheReleas
e
(
tscCacheHandle
,
(
void
**
)
&
(
pMeterMetaInfo
->
pMeterMeta
),
true
);
code
=
doGetMeterMetaFromServer
(
pSql
,
pMeterMetaInfo
);
// todo ??
}
else
{
...
...
@@ -3278,9 +3277,9 @@ int tscGetMetricMeta(SSqlObj *pSql, int32_t clauseIndex) {
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfoFromQueryInfo
(
pQueryInfo
,
i
);
tscGetMetricMetaCacheKey
(
pQueryInfo
,
tagstr
,
pMeterMetaInfo
->
pMeterMeta
->
uid
);
taos
RemoveDataFromCach
e
(
tscCacheHandle
,
(
void
**
)
&
(
pMeterMetaInfo
->
pMetricMeta
),
false
);
taos
CacheReleas
e
(
tscCacheHandle
,
(
void
**
)
&
(
pMeterMetaInfo
->
pMetricMeta
),
false
);
SSuperTableMeta
*
ppMeta
=
(
SSuperTableMeta
*
)
taos
GetDataFromCach
e
(
tscCacheHandle
,
tagstr
);
SSuperTableMeta
*
ppMeta
=
(
SSuperTableMeta
*
)
taos
CacheAcquireByNam
e
(
tscCacheHandle
,
tagstr
);
if
(
ppMeta
==
NULL
)
{
required
=
true
;
break
;
...
...
@@ -3308,7 +3307,7 @@ int tscGetMetricMeta(SSqlObj *pSql, int32_t clauseIndex) {
for
(
int32_t
i
=
0
;
i
<
pQueryInfo
->
numOfTables
;
++
i
)
{
SMeterMetaInfo
*
pMMInfo
=
tscGetMeterMetaInfoFromQueryInfo
(
pQueryInfo
,
i
);
STableMeta
*
pMeterMeta
=
taos
GetDataFromCach
e
(
tscCacheHandle
,
pMMInfo
->
name
);
STableMeta
*
pMeterMeta
=
taos
CacheAcquireByNam
e
(
tscCacheHandle
,
pMMInfo
->
name
);
tscAddMeterMetaInfo
(
pNewQueryInfo
,
pMMInfo
->
name
,
pMeterMeta
,
NULL
,
pMMInfo
->
numOfTags
,
pMMInfo
->
tagColumnIndex
);
}
...
...
@@ -3353,8 +3352,8 @@ int tscGetMetricMeta(SSqlObj *pSql, int32_t clauseIndex) {
printf
(
"create metric key:%s, index:%d
\n
"
,
tagstr
,
i
);
#endif
taos
RemoveDataFromCach
e
(
tscCacheHandle
,
(
void
**
)
&
(
pMeterMetaInfo
->
pMetricMeta
),
false
);
pMeterMetaInfo
->
pMetricMeta
=
(
SSuperTableMeta
*
)
taosGetDataFromCach
e
(
tscCacheHandle
,
tagstr
);
taos
CacheReleas
e
(
tscCacheHandle
,
(
void
**
)
&
(
pMeterMetaInfo
->
pMetricMeta
),
false
);
pMeterMetaInfo
->
pMetricMeta
=
(
SSuperTableMeta
*
)
taosCacheAcquireByNam
e
(
tscCacheHandle
,
tagstr
);
}
}
...
...
src/client/src/tscSub.c
浏览文件 @
8504daea
...
...
@@ -371,7 +371,7 @@ TAOS_RES *taos_consume(TAOS_SUB *tsub) {
pSql
->
sqlstr
=
NULL
;
taos_free_result_imp
(
pSql
,
0
);
pSql
->
sqlstr
=
sqlstr
;
taosC
learDataCache
(
tscCacheHandle
);
taosC
acheEmpty
(
tscCacheHandle
);
if
(
!
tscUpdateSubscription
(
pSub
->
taos
,
pSub
))
return
NULL
;
tscTrace
(
"meter synchronization completed"
);
}
else
{
...
...
src/client/src/tscSystem.c
浏览文件 @
8504daea
...
...
@@ -186,7 +186,7 @@ void taos_init_imp() {
refreshTime
=
refreshTime
>
2
?
2
:
refreshTime
;
refreshTime
=
refreshTime
<
1
?
1
:
refreshTime
;
if
(
tscCacheHandle
==
NULL
)
tscCacheHandle
=
taos
InitDataCache
(
tsMaxMeterConnections
/
2
,
tscTmr
,
refreshTime
);
if
(
tscCacheHandle
==
NULL
)
tscCacheHandle
=
taos
CacheInit
(
tscTmr
,
refreshTime
);
tscConnCache
=
taosOpenConnCache
(
tsMaxMeterConnections
*
2
,
NULL
/*taosCloseRpcConn*/
,
tscTmr
,
tsShellActivityTimer
*
1000
);
...
...
src/client/src/tscUtil.c
浏览文件 @
8504daea
...
...
@@ -505,7 +505,7 @@ void tscDestroyDataBlock(STableDataBlocks* pDataBlock) {
tfree
(
pDataBlock
->
params
);
// free the refcount for metermeta
taos
RemoveDataFromCach
e
(
tscCacheHandle
,
(
void
**
)
&
(
pDataBlock
->
pMeterMeta
),
false
);
taos
CacheReleas
e
(
tscCacheHandle
,
(
void
**
)
&
(
pDataBlock
->
pMeterMeta
),
false
);
tfree
(
pDataBlock
);
}
...
...
@@ -589,9 +589,9 @@ int32_t tscCopyDataBlockToPayload(SSqlObj* pSql, STableDataBlocks* pDataBlock) {
// set the correct metermeta object, the metermeta has been locked in pDataBlocks, so it must be in the cache
if
(
pMeterMetaInfo
->
pMeterMeta
!=
pDataBlock
->
pMeterMeta
)
{
strcpy
(
pMeterMetaInfo
->
name
,
pDataBlock
->
tableId
);
taos
RemoveDataFromCach
e
(
tscCacheHandle
,
(
void
**
)
&
(
pMeterMetaInfo
->
pMeterMeta
),
false
);
taos
CacheReleas
e
(
tscCacheHandle
,
(
void
**
)
&
(
pMeterMetaInfo
->
pMeterMeta
),
false
);
pMeterMetaInfo
->
pMeterMeta
=
taos
TransferDataInCache
(
tscCacheHandle
,
(
void
**
)
&
pDataBlock
->
pMeterMeta
);
pMeterMetaInfo
->
pMeterMeta
=
taos
CacheTransfer
(
tscCacheHandle
,
(
void
**
)
&
pDataBlock
->
pMeterMeta
);
}
else
{
assert
(
strncmp
(
pMeterMetaInfo
->
name
,
pDataBlock
->
tableId
,
tListLen
(
pDataBlock
->
tableId
))
==
0
);
}
...
...
@@ -665,7 +665,7 @@ int32_t tscCreateDataBlock(size_t initialSize, int32_t rowSize, int32_t startOff
* due to operation such as drop database. So here we add the reference count directly instead of invoke
* taosGetDataFromCache, which may return NULL value.
*/
dataBuf
->
pMeterMeta
=
taos
GetDataFromExists
(
tscCacheHandle
,
pMeterMeta
);
dataBuf
->
pMeterMeta
=
taos
CacheAcquireByData
(
tscCacheHandle
,
pMeterMeta
);
assert
(
initialSize
>
0
&&
pMeterMeta
!=
NULL
&&
dataBuf
->
pMeterMeta
!=
NULL
);
*
dataBlocks
=
dataBuf
;
...
...
@@ -1940,8 +1940,8 @@ void tscClearMeterMetaInfo(SMeterMetaInfo* pMeterMetaInfo, bool removeFromCache)
return
;
}
taos
RemoveDataFromCach
e
(
tscCacheHandle
,
(
void
**
)
&
(
pMeterMetaInfo
->
pMeterMeta
),
removeFromCache
);
taos
RemoveDataFromCach
e
(
tscCacheHandle
,
(
void
**
)
&
(
pMeterMetaInfo
->
pMetricMeta
),
removeFromCache
);
taos
CacheReleas
e
(
tscCacheHandle
,
(
void
**
)
&
(
pMeterMetaInfo
->
pMeterMeta
),
removeFromCache
);
taos
CacheReleas
e
(
tscCacheHandle
,
(
void
**
)
&
(
pMeterMetaInfo
->
pMetricMeta
),
removeFromCache
);
}
void
tscResetForNextRetrieve
(
SSqlRes
*
pRes
)
{
...
...
@@ -2071,16 +2071,16 @@ SSqlObj* createSubqueryObj(SSqlObj* pSql, int16_t tableIndex, void (*fp)(), void
SMeterMetaInfo
*
pFinalInfo
=
NULL
;
if
(
pPrevSql
==
NULL
)
{
STableMeta
*
pMeterMeta
=
taos
GetDataFromCach
e
(
tscCacheHandle
,
name
);
SSuperTableMeta
*
pMetricMeta
=
taos
GetDataFromCach
e
(
tscCacheHandle
,
key
);
STableMeta
*
pMeterMeta
=
taos
CacheAcquireByNam
e
(
tscCacheHandle
,
name
);
SSuperTableMeta
*
pMetricMeta
=
taos
CacheAcquireByNam
e
(
tscCacheHandle
,
key
);
pFinalInfo
=
tscAddMeterMetaInfo
(
pNewQueryInfo
,
name
,
pMeterMeta
,
pMetricMeta
,
pMeterMetaInfo
->
numOfTags
,
pMeterMetaInfo
->
tagColumnIndex
);
}
else
{
// transfer the ownership of pMeterMeta/pMetricMeta to the newly create sql object.
SMeterMetaInfo
*
pPrevInfo
=
tscGetMeterMetaInfo
(
&
pPrevSql
->
cmd
,
pPrevSql
->
cmd
.
clauseIndex
,
0
);
STableMeta
*
pPrevMeterMeta
=
taos
TransferDataInCache
(
tscCacheHandle
,
(
void
**
)
&
pPrevInfo
->
pMeterMeta
);
SSuperTableMeta
*
pPrevMetricMeta
=
taos
TransferDataInCache
(
tscCacheHandle
,
(
void
**
)
&
pPrevInfo
->
pMetricMeta
);
STableMeta
*
pPrevMeterMeta
=
taos
CacheTransfer
(
tscCacheHandle
,
(
void
**
)
&
pPrevInfo
->
pMeterMeta
);
SSuperTableMeta
*
pPrevMetricMeta
=
taos
CacheTransfer
(
tscCacheHandle
,
(
void
**
)
&
pPrevInfo
->
pMetricMeta
);
pFinalInfo
=
tscAddMeterMetaInfo
(
pNewQueryInfo
,
name
,
pPrevMeterMeta
,
pPrevMetricMeta
,
pMeterMetaInfo
->
numOfTags
,
pMeterMetaInfo
->
tagColumnIndex
);
...
...
src/query/inc/tcache.h
浏览文件 @
8504daea
...
...
@@ -20,7 +20,63 @@
extern
"C"
{
#endif
#include <stdbool.h>
#include "os.h"
#include "tref.h"
#include "hash.h"
typedef
struct
SCacheStatis
{
int64_t
missCount
;
int64_t
hitCount
;
int64_t
totalAccess
;
int64_t
refreshCount
;
int32_t
numOfCollision
;
}
SCacheStatis
;
typedef
struct
SCacheDataNode
{
uint64_t
addedTime
;
// the added time when this element is added or updated into cache
uint64_t
expiredTime
;
// expiredTime expiredTime when this element should be remove from cache
uint64_t
signature
;
uint32_t
size
;
// allocated size for current SCacheDataNode
uint16_t
keySize
:
15
;
bool
inTrash
:
1
;
// denote if it is in trash or not
T_REF_DECLARE
()
char
*
key
;
char
data
[];
}
SCacheDataNode
;
typedef
struct
STrashElem
{
struct
STrashElem
*
prev
;
struct
STrashElem
*
next
;
SCacheDataNode
*
pData
;
}
STrashElem
;
typedef
struct
{
int64_t
totalSize
;
// total allocated buffer in this hash table, SCacheObj is not included.
int64_t
refreshTime
;
/*
* to accommodate the old datanode which has the same key value of new one in hashList
* when an new node is put into cache, if an existed one with the same key:
* 1. if the old one does not be referenced, update it.
* 2. otherwise, move the old one to pTrash, addedTime the new one.
*
* when the node in pTrash does not be referenced, it will be release at the expired expiredTime
*/
STrashElem
*
pTrash
;
void
*
tmrCtrl
;
void
*
pTimer
;
SCacheStatis
statistics
;
SHashObj
*
pHashTable
;
int
numOfElemsInTrash
;
// number of element in trash
int16_t
deleting
;
// set the deleting flag to stop refreshing ASAP.
#if defined(LINUX)
pthread_rwlock_t
lock
;
#else
pthread_mutex_t
lock
;
#endif
}
SCacheObj
;
/**
*
...
...
@@ -30,7 +86,7 @@ extern "C" {
* not referenced by other objects
* @return
*/
void
*
taosInitDataCache
(
int
maxSessions
,
void
*
tmrCtrl
,
int64_t
refreshTimeInSeconds
);
SCacheObj
*
taosCacheInit
(
void
*
tmrCtrl
,
int64_t
refreshTimeInSeconds
);
/**
* add data into cache
...
...
@@ -42,28 +98,7 @@ void *taosInitDataCache(int maxSessions, void *tmrCtrl, int64_t refreshTimeInSec
* @param keepTime survival time in second
* @return cached element
*/
void
*
taosAddDataIntoCache
(
void
*
handle
,
char
*
key
,
char
*
pData
,
int
dataSize
,
int
keepTimeInSeconds
);
/**
* remove data in cache, the data will not be removed immediately.
* if it is referenced by other object, it will be remain in cache
* @param handle cache object
* @param data not the key, actually referenced data
* @param _remove force model, reduce the ref count and move the data into
* pTrash
*/
void
taosRemoveDataFromCache
(
void
*
handle
,
void
**
data
,
bool
_remove
);
/**
* update data in cache
* @param handle hash object handle(pointer)
* @param key key for hash
* @param pData actually data
* @param size length of data
* @param duration survival time of this object in cache
* @return new referenced data
*/
void
*
taosUpdateDataFromCache
(
void
*
handle
,
char
*
key
,
char
*
pData
,
int
size
,
int
duration
);
void
*
taosCachePut
(
void
*
handle
,
char
*
key
,
char
*
pData
,
int
dataSize
,
int
keepTimeInSeconds
);
/**
* get data from cache
...
...
@@ -71,40 +106,56 @@ void *taosUpdateDataFromCache(void *handle, char *key, char *pData, int size, in
* @param key key
* @return cached data or NULL
*/
void
*
taos
GetDataFromCach
e
(
void
*
handle
,
char
*
key
);
void
*
taos
CacheAcquireByNam
e
(
void
*
handle
,
char
*
key
);
/**
* release all allocated memory and destroy the cache object
* Add one reference count for the exist data, and assign this data for a new owner.
* The new owner needs to invoke the taosCacheRelease when it does not need this data anymore.
* This procedure is a faster version of taosCacheAcquireByName function, which avoids the sideeffect of the problem of
* the data is moved to trash, and taosCacheAcquireByName will fail to retrieve it again.
*
* @param handle
* @param data
* @return
*/
void
taosCleanUpDataCache
(
void
*
handle
);
void
*
taosCacheAcquireByData
(
void
*
handle
,
void
*
data
);
/**
*
move all data node into trash,clear node in trash can if it is not referenced by client
*
transfer the ownership of data in cache to another object without increasing reference count.
* @param handle
* @param data
* @return
*/
void
taosClearDataCache
(
void
*
handle
);
void
*
taosCacheTransfer
(
void
*
handle
,
void
**
data
);
/**
* Add one reference count for the exist data, and assign this data for a new owner.
* The new owner needs to invoke the taosRemoveDataFromCache when it does not need this data anymore.
* This procedure is a faster version of taosGetDataFromCache function, which avoids the sideeffect of the problem of the
* data is moved to trash, and taosGetDataFromCache will fail to retrieve it again.
*
* remove data in cache, the data will not be removed immediately.
* if it is referenced by other object, it will be remain in cache
* @param handle cache object
* @param data not the key, actually referenced data
* @param _remove force model, reduce the ref count and move the data into
* pTrash
*/
void
taosCacheRelease
(
void
*
handle
,
void
**
data
,
bool
_remove
);
/**
* move all data node into trash, clear node in trash can if it is not referenced by any clients
* @param handle
* @param data
* @return
*/
void
*
taosGetDataFromExists
(
void
*
handle
,
void
*
data
);
void
taosCacheEmpty
(
SCacheObj
*
pCacheObj
);
/**
* transfer the ownership of data in cache to another object without increasing reference count.
* release all allocated memory and destroy the cache object.
*
* This function only set the deleting flag, and the specific work of clean up cache is delegated to
* taosCacheRefresh function, which will executed every SCacheObj->refreshTime sec.
*
* If the value of SCacheObj->refreshTime is too large, the taosCacheRefresh function may not be invoked
* before the main thread terminated, in which case all allocated resources are simply recycled by OS.
*
* @param handle
* @param data
* @return
*/
void
*
taosTransferDataInCache
(
void
*
handle
,
void
**
data
);
void
taosCacheCleanup
(
SCacheObj
*
pCacheObj
);
#ifdef __cplusplus
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录