Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
9df1fed6
T
TDengine
项目概览
taosdata
/
TDengine
大约 2 年 前同步成功
通知
1192
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看板
提交
9df1fed6
编写于
2月 28, 2022
作者:
S
Shengliang Guan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
cache
上级
1360f6b2
变更
2
展开全部
隐藏空白更改
内联
并排
Showing
2 changed file
with
168 addition
and
162 deletion
+168
-162
include/util/tcache.h
include/util/tcache.h
+39
-38
source/util/src/tcache.c
source/util/src/tcache.c
+129
-124
未找到文件。
include/util/tcache.h
浏览文件 @
9df1fed6
...
...
@@ -13,27 +13,26 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _TD_UTIL_CACHE_H
#define _TD_UTIL_CACHE_H
#ifndef _TD_UTIL_CACHE_H_
#define _TD_UTIL_CACHE_H_
#include "thash.h"
#include "tlockfree.h"
#ifdef __cplusplus
extern
"C"
{
#endif
#include "os.h"
#include "tlockfree.h"
#include "thash.h"
#if defined(_TD_ARM_32)
#define TSDB_CACHE_PTR_KEY TSDB_DATA_TYPE_INT
#define TSDB_CACHE_PTR_TYPE int32_t
#if defined(_TD_ARM_32)
#define TSDB_CACHE_PTR_KEY TSDB_DATA_TYPE_INT
#define TSDB_CACHE_PTR_TYPE int32_t
#else
#define TSDB_CACHE_PTR_KEY TSDB_DATA_TYPE_BIGINT
#define TSDB_CACHE_PTR_TYPE int64_t
#define TSDB_CACHE_PTR_KEY TSDB_DATA_TYPE_BIGINT
#define TSDB_CACHE_PTR_TYPE int64_t
#endif
typedef
void
(
*
__cache_free_fn_t
)(
void
*
);
typedef
void
(
*
__cache_trav_fn_t
)(
void
*
,
void
*
);
typedef
void
(
*
__cache_free_fn_t
)(
void
*
);
typedef
void
(
*
__cache_trav_fn_t
)(
void
*
,
void
*
);
typedef
struct
SCacheStatis
{
int64_t
missCount
;
...
...
@@ -45,17 +44,17 @@ typedef struct SCacheStatis {
struct
STrashElem
;
typedef
struct
SCacheDataNode
{
uint64_t
addedTime
;
// the added time when this element is added or updated into cache
uint64_t
lifespan
;
// life duration when this element should be remove from cache
uint64_t
expireTime
;
// expire time
uint64_t
addedTime
;
// the added time when this element is added or updated into cache
uint64_t
lifespan
;
// life duration when this element should be remove from cache
uint64_t
expireTime
;
// expire time
uint64_t
signature
;
struct
STrashElem
*
pTNodeHeader
;
// point to trash node head
uint16_t
keySize
:
15
;
// max key size: 32kb
bool
inTrashcan
:
1
;
// denote if it is in trash or not
uint32_t
size
;
// allocated size for current SCacheDataNode
struct
STrashElem
*
pTNodeHeader
;
// point to trash node head
uint16_t
keySize
:
15
;
// max key size: 32kb
bool
inTrashcan
:
1
;
// denote if it is in trash or not
uint32_t
size
;
// allocated size for current SCacheDataNode
T_REF_DECLARE
()
char
*
key
;
char
data
[];
char
*
key
;
char
data
[];
}
SCacheDataNode
;
typedef
struct
STrashElem
{
...
...
@@ -73,22 +72,22 @@ typedef struct STrashElem {
* when the node in pTrash does not be referenced, it will be release at the expired expiredTime
*/
typedef
struct
{
int64_t
totalSize
;
// total allocated buffer in this hash table, SCacheObj is not included.
int64_t
refreshTime
;
STrashElem
*
pTrash
;
char
*
name
;
SCacheStatis
statistics
;
SHashObj
*
pHashTable
;
int64_t
totalSize
;
// total allocated buffer in this hash table, SCacheObj is not included.
int64_t
refreshTime
;
STrashElem
*
pTrash
;
char
*
name
;
SCacheStatis
statistics
;
SHashObj
*
pHashTable
;
__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
;
bool
extendLifespan
;
// auto extend life span when one item is accessed.
int64_t
checkTick
;
// tick used to record the check times of the refresh threads
uint32_t
numOfElemsInTrash
;
// number of element in trash
uint8_t
deleting
;
// set the deleting flag to stop refreshing ASAP.
pthread_t
refreshWorker
;
bool
extendLifespan
;
// auto extend life span when one item is accessed.
int64_t
checkTick
;
// tick used to record the check times of the refresh threads
#if defined(LINUX)
pthread_rwlock_t
lock
;
#else
pthread_mutex_t
lock
;
pthread_mutex_t
lock
;
#endif
}
SCacheObj
;
...
...
@@ -101,7 +100,8 @@ typedef struct {
* @param fn free resource callback function
* @return
*/
SCacheObj
*
taosCacheInit
(
int32_t
keyType
,
int64_t
refreshTimeInSeconds
,
bool
extendLifespan
,
__cache_free_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
...
...
@@ -113,7 +113,8 @@ SCacheObj *taosCacheInit(int32_t keyType, int64_t refreshTimeInSeconds, bool ext
* @param keepTime survival time in second
* @return cached element
*/
void
*
taosCachePut
(
SCacheObj
*
pCacheObj
,
const
void
*
key
,
size_t
keyLen
,
const
void
*
pData
,
size_t
dataSize
,
int
durationMS
);
void
*
taosCachePut
(
SCacheObj
*
pCacheObj
,
const
void
*
key
,
size_t
keyLen
,
const
void
*
pData
,
size_t
dataSize
,
int32_t
durationMS
);
/**
* get data from cache
...
...
@@ -177,7 +178,7 @@ void taosCacheCleanup(SCacheObj *pCacheObj);
* @param fp
* @return
*/
void
taosCacheRefresh
(
SCacheObj
*
pCacheObj
,
__cache_trav_fn_t
fp
,
void
*
param1
);
void
taosCacheRefresh
(
SCacheObj
*
pCacheObj
,
__cache_trav_fn_t
fp
,
void
*
param1
);
/**
* stop background refresh worker thread
...
...
@@ -188,4 +189,4 @@ void taosStopCacheRefreshWorker();
}
#endif
#endif
/*_TD_UTIL_CACHE_H
*/
#endif
/*_TD_UTIL_CACHE_H_
*/
source/util/src/tcache.c
浏览文件 @
9df1fed6
此差异已折叠。
点击以展开。
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录