Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
d6db033d
T
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1187
Star
22018
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
d6db033d
编写于
7月 07, 2020
作者:
H
Haojun Liao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[td-225] fix invalid read for qhandle mgmt
上级
402d5863
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
57 addition
and
42 deletion
+57
-42
src/client/src/tscLocal.c
src/client/src/tscLocal.c
+1
-1
src/client/src/tscServer.c
src/client/src/tscServer.c
+2
-2
src/query/src/qExecutor.c
src/query/src/qExecutor.c
+1
-1
src/util/inc/tcache.h
src/util/inc/tcache.h
+12
-14
src/util/src/tcache.c
src/util/src/tcache.c
+41
-24
未找到文件。
src/client/src/tscLocal.c
浏览文件 @
d6db033d
...
...
@@ -406,7 +406,7 @@ int tscProcessLocalCmd(SSqlObj *pSql) {
pSql
->
res
.
qhandle
=
0x1
;
pSql
->
res
.
numOfRows
=
0
;
}
else
if
(
pCmd
->
command
==
TSDB_SQL_RESET_CACHE
)
{
taosCacheEmpty
(
tscCacheHandle
,
false
);
taosCacheEmpty
(
tscCacheHandle
);
}
else
if
(
pCmd
->
command
==
TSDB_SQL_SERV_VERSION
)
{
tscProcessServerVer
(
pSql
);
}
else
if
(
pCmd
->
command
==
TSDB_SQL_CLI_VERSION
)
{
...
...
src/client/src/tscServer.c
浏览文件 @
d6db033d
...
...
@@ -1955,7 +1955,7 @@ int tscProcessUseDbRsp(SSqlObj *pSql) {
}
int
tscProcessDropDbRsp
(
SSqlObj
*
UNUSED_PARAM
(
pSql
))
{
taosCacheEmpty
(
tscCacheHandle
,
false
);
taosCacheEmpty
(
tscCacheHandle
);
return
0
;
}
...
...
@@ -2001,7 +2001,7 @@ int tscProcessAlterTableMsgRsp(SSqlObj *pSql) {
if
(
isSuperTable
)
{
// if it is a super table, reset whole query cache
tscDebug
(
"%p reset query cache since table:%s is stable"
,
pSql
,
pTableMetaInfo
->
name
);
taosCacheEmpty
(
tscCacheHandle
,
false
);
taosCacheEmpty
(
tscCacheHandle
);
}
}
...
...
src/query/src/qExecutor.c
浏览文件 @
d6db033d
...
...
@@ -6497,7 +6497,7 @@ void qSetQueryMgmtClosed(void* pQMgmt) {
pQueryMgmt
->
closed
=
true
;
pthread_mutex_unlock
(
&
pQueryMgmt
->
lock
);
taosCache
Empty
(
pQueryMgmt
->
qinfoPool
,
true
);
taosCache
Refresh
(
pQueryMgmt
->
qinfoPool
,
freeqinfoFn
);
}
void
qCleanupQueryMgmt
(
void
*
pQMgmt
)
{
...
...
src/util/inc/tcache.h
浏览文件 @
d6db033d
...
...
@@ -24,14 +24,13 @@ extern "C" {
#include "tref.h"
#include "hash.h"
typedef
void
(
*
__cache_free
res
_fn_t
)(
void
*
);
typedef
void
(
*
__cache_free_fn_t
)(
void
*
);
typedef
struct
SCacheStatis
{
int64_t
missCount
;
int64_t
hitCount
;
int64_t
totalAccess
;
int64_t
refreshCount
;
int32_t
numOfCollision
;
}
SCacheStatis
;
typedef
struct
SCacheDataNode
{
...
...
@@ -70,7 +69,7 @@ typedef struct {
// void * pTimer;
SCacheStatis
statistics
;
SHashObj
*
pHashTable
;
__cache_free
res
_fn_t
freeFp
;
__cache_free_fn_t
freeFp
;
uint32_t
numOfElemsInTrash
;
// number of element in trash
uint8_t
deleting
;
// set the deleting flag to stop refreshing ASAP.
pthread_t
refreshWorker
;
...
...
@@ -91,15 +90,7 @@ typedef struct {
* @param fn free resource callback function
* @return
*/
SCacheObj
*
taosCacheInit
(
int32_t
keyType
,
int64_t
refreshTimeInSeconds
,
bool
extendLifespan
,
__cache_freeres_fn_t
fn
,
const
char
*
cacheName
);
/**
* initialize the cache object and set the free object callback function
* @param refreshTimeInSeconds
* @param freeCb
* @return
*/
SCacheObj
*
taosCacheInitWithCb
(
int32_t
keyType
,
int64_t
refreshTimeInSeconds
,
bool
extendLifespan
,
__cache_freeres_fn_t
fn
,
const
char
*
cacheName
);
SCacheObj
*
taosCacheInit
(
int32_t
keyType
,
int64_t
refreshTimeInSeconds
,
bool
extendLifespan
,
__cache_free_fn_t
fn
,
const
char
*
cacheName
);
/**
* add data into cache
...
...
@@ -163,9 +154,8 @@ 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
* @param handle
* @param _remove remove the data or not if refcount is greater than 0
*/
void
taosCacheEmpty
(
SCacheObj
*
pCacheObj
,
bool
_remove
);
void
taosCacheEmpty
(
SCacheObj
*
pCacheObj
);
/**
* release all allocated memory and destroy the cache object.
...
...
@@ -180,6 +170,14 @@ void taosCacheEmpty(SCacheObj *pCacheObj, bool _remove);
*/
void
taosCacheCleanup
(
SCacheObj
*
pCacheObj
);
/**
*
* @param pCacheObj
* @param fp
* @return
*/
void
taosCacheRefresh
(
SCacheObj
*
pCacheObj
,
__cache_free_fn_t
fp
);
#ifdef __cplusplus
}
#endif
...
...
src/util/src/tcache.c
浏览文件 @
d6db033d
...
...
@@ -223,9 +223,9 @@ static void doCleanupDataCache(SCacheObj *pCacheObj);
* refresh cache to remove data in both hash list and trash, if any nodes' refcount == 0, every pCacheObj->refreshTime
* @param handle Cache object handle
*/
static
void
*
taosCache
Refresh
(
void
*
handle
);
static
void
*
taosCache
TimedRefresh
(
void
*
pCacheObj
);
SCacheObj
*
taosCacheInit
(
int32_t
keyType
,
int64_t
refreshTimeInSeconds
,
bool
extendLifespan
,
__cache_free
res
_fn_t
fn
,
const
char
*
cacheName
)
{
SCacheObj
*
taosCacheInit
(
int32_t
keyType
,
int64_t
refreshTimeInSeconds
,
bool
extendLifespan
,
__cache_free_fn_t
fn
,
const
char
*
cacheName
)
{
if
(
refreshTimeInSeconds
<=
0
)
{
return
NULL
;
}
...
...
@@ -261,7 +261,7 @@ SCacheObj *taosCacheInit(int32_t keyType, int64_t refreshTimeInSeconds, bool ext
pthread_attr_init
(
&
thattr
);
pthread_attr_setdetachstate
(
&
thattr
,
PTHREAD_CREATE_JOINABLE
);
pthread_create
(
&
pCacheObj
->
refreshWorker
,
&
thattr
,
taosCacheRefresh
,
pCacheObj
);
pthread_create
(
&
pCacheObj
->
refreshWorker
,
&
thattr
,
taosCache
Timed
Refresh
,
pCacheObj
);
pthread_attr_destroy
(
&
thattr
);
return
pCacheObj
;
...
...
@@ -450,7 +450,7 @@ void taosCacheRelease(SCacheObj *pCacheObj, void **data, bool _remove) {
}
}
void
taosCacheEmpty
(
SCacheObj
*
pCacheObj
,
bool
_remove
)
{
void
taosCacheEmpty
(
SCacheObj
*
pCacheObj
)
{
SHashMutableIterator
*
pIter
=
taosHashCreateIter
(
pCacheObj
->
pHashTable
);
__cache_wr_lock
(
pCacheObj
);
...
...
@@ -459,8 +459,8 @@ void taosCacheEmpty(SCacheObj *pCacheObj, bool _remove) {
break
;
}
SCacheDataNode
*
pNode
=
*
(
SCacheDataNode
**
)
taosHashIterGet
(
pIter
);
if
(
T_REF_VAL_GET
(
pNode
)
==
0
||
_remove
)
{
SCacheDataNode
*
pNode
=
*
(
SCacheDataNode
**
)
taosHashIterGet
(
pIter
);
if
(
T_REF_VAL_GET
(
pNode
)
==
0
)
{
taosCacheReleaseNode
(
pCacheObj
,
pNode
);
}
else
{
taosCacheMoveToTrash
(
pCacheObj
,
pNode
);
...
...
@@ -469,7 +469,7 @@ void taosCacheEmpty(SCacheObj *pCacheObj, bool _remove) {
__cache_unlock
(
pCacheObj
);
taosHashDestroyIter
(
pIter
);
taosTrashCanEmpty
(
pCacheObj
,
_remov
e
);
taosTrashCanEmpty
(
pCacheObj
,
fals
e
);
}
void
taosCacheCleanup
(
SCacheObj
*
pCacheObj
)
{
...
...
@@ -623,8 +623,29 @@ void doCleanupDataCache(SCacheObj *pCacheObj) {
free
(
pCacheObj
);
}
void
*
taosCacheRefresh
(
void
*
handle
)
{
SCacheObj
*
pCacheObj
=
(
SCacheObj
*
)
handle
;
static
void
doCacheRefresh
(
SCacheObj
*
pCacheObj
,
int64_t
time
,
__cache_free_fn_t
fp
)
{
SHashMutableIterator
*
pIter
=
taosHashCreateIter
(
pCacheObj
->
pHashTable
);
__cache_wr_lock
(
pCacheObj
);
while
(
taosHashIterNext
(
pIter
))
{
SCacheDataNode
*
pNode
=
*
(
SCacheDataNode
**
)
taosHashIterGet
(
pIter
);
if
((
pNode
->
addedTime
+
pNode
->
lifespan
*
pNode
->
extendFactor
)
<=
time
&&
T_REF_VAL_GET
(
pNode
)
<=
0
)
{
taosCacheReleaseNode
(
pCacheObj
,
pNode
);
continue
;
}
if
(
fp
)
{
fp
(
pNode
->
data
);
}
}
__cache_unlock
(
pCacheObj
);
taosHashDestroyIter
(
pIter
);
}
void
*
taosCacheTimedRefresh
(
void
*
handle
)
{
SCacheObj
*
pCacheObj
=
handle
;
if
(
pCacheObj
==
NULL
)
{
uDebug
(
"object is destroyed. no refresh retry"
);
return
NULL
;
...
...
@@ -657,21 +678,8 @@ void* taosCacheRefresh(void *handle) {
// refresh data in hash table
if
(
elemInHash
>
0
)
{
int64_t
expiredTime
=
taosGetTimestampMs
();
SHashMutableIterator
*
pIter
=
taosHashCreateIter
(
pCacheObj
->
pHashTable
);
__cache_wr_lock
(
pCacheObj
);
while
(
taosHashIterNext
(
pIter
))
{
SCacheDataNode
*
pNode
=
*
(
SCacheDataNode
**
)
taosHashIterGet
(
pIter
);
if
((
pNode
->
addedTime
+
pNode
->
lifespan
*
pNode
->
extendFactor
)
<=
expiredTime
&&
T_REF_VAL_GET
(
pNode
)
<=
0
)
{
taosCacheReleaseNode
(
pCacheObj
,
pNode
);
}
}
__cache_unlock
(
pCacheObj
);
taosHashDestroyIter
(
pIter
);
int64_t
now
=
taosGetTimestampMs
();
doCacheRefresh
(
pCacheObj
,
now
,
NULL
);
}
taosTrashCanEmpty
(
pCacheObj
,
false
);
...
...
@@ -679,3 +687,12 @@ void* taosCacheRefresh(void *handle) {
return
NULL
;
}
void
taosCacheRefresh
(
SCacheObj
*
pCacheObj
,
__cache_free_fn_t
fp
)
{
if
(
pCacheObj
==
NULL
)
{
return
;
}
int64_t
now
=
taosGetTimestampMs
();
doCacheRefresh
(
pCacheObj
,
now
,
fp
);
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录