Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
a96de233
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看板
提交
a96de233
编写于
1月 12, 2023
作者:
H
Haojun Liao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix(query): add the check of item when putting in cache.
上级
d36e68bd
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
55 addition
and
41 deletion
+55
-41
source/dnode/vnode/src/meta/metaCache.c
source/dnode/vnode/src/meta/metaCache.c
+55
-41
未找到文件。
source/dnode/vnode/src/meta/metaCache.c
浏览文件 @
a96de233
...
@@ -424,6 +424,50 @@ int32_t metaStatsCacheGet(SMeta* pMeta, int64_t uid, SMetaStbStats* pInfo) {
...
@@ -424,6 +424,50 @@ int32_t metaStatsCacheGet(SMeta* pMeta, int64_t uid, SMetaStbStats* pInfo) {
return
code
;
return
code
;
}
}
static
int
checkAllEntriesInCache
(
const
STagFilterResEntry
*
pEntry
,
SArray
*
pInvalidRes
,
int32_t
keyLen
,
SLRUCache
*
pCache
,
uint64_t
suid
)
{
SListIter
iter
=
{
0
};
tdListInitIter
((
SList
*
)
&
(
pEntry
->
list
),
&
iter
,
TD_LIST_FORWARD
);
SListNode
*
pNode
=
NULL
;
uint64_t
buf
[
3
];
buf
[
0
]
=
suid
;
int32_t
len
=
sizeof
(
uint64_t
)
*
tListLen
(
buf
);
while
((
pNode
=
tdListNext
(
&
iter
))
!=
NULL
)
{
memcpy
(
&
buf
[
1
],
pNode
->
data
,
keyLen
);
// check whether it is existed in LRU cache, and remove it from linked list if not.
LRUHandle
*
pRes
=
taosLRUCacheLookup
(
pCache
,
buf
,
len
);
if
(
pRes
==
NULL
)
{
// remove the item in the linked list
taosArrayPush
(
pInvalidRes
,
&
pNode
);
}
else
{
taosLRUCacheRelease
(
pCache
,
pRes
,
false
);
}
}
return
0
;
}
#define NEED_CHECK_CACHE_ITEM(_size, _acc_times) ((_size) >= 100 || (_acc_times) > 5000)
static
void
removeInvalidCacheItem
(
SArray
*
pInvalidRes
,
struct
STagFilterResEntry
*
pEntry
)
{
if
(
pInvalidRes
==
NULL
)
{
return
;
}
// remove the keys, of which query uid lists have been replaced already.
size_t
s
=
taosArrayGetSize
(
pInvalidRes
);
for
(
int32_t
i
=
0
;
i
<
s
;
++
i
)
{
SListNode
**
p1
=
taosArrayGet
(
pInvalidRes
,
i
);
tdListPopNode
(
&
(
pEntry
->
list
),
*
p1
);
taosMemoryFree
(
*
p1
);
}
atomic_store_32
(
&
(
pEntry
->
qTimes
),
0
);
// reset the query times
taosArrayDestroy
(
pInvalidRes
);
}
int32_t
metaGetCachedTableUidList
(
SMeta
*
pMeta
,
tb_uid_t
suid
,
const
uint8_t
*
pKey
,
int32_t
keyLen
,
SArray
*
pList1
,
int32_t
metaGetCachedTableUidList
(
SMeta
*
pMeta
,
tb_uid_t
suid
,
const
uint8_t
*
pKey
,
int32_t
keyLen
,
SArray
*
pList1
,
bool
*
acquireRes
)
{
bool
*
acquireRes
)
{
// generate the composed key for LRU cache
// generate the composed key for LRU cache
...
@@ -465,38 +509,13 @@ int32_t metaGetCachedTableUidList(SMeta* pMeta, tb_uid_t suid, const uint8_t* pK
...
@@ -465,38 +509,13 @@ int32_t metaGetCachedTableUidList(SMeta* pMeta, tb_uid_t suid, const uint8_t* pK
taosThreadMutexUnlock
(
pLock
);
taosThreadMutexUnlock
(
pLock
);
// check if scanning all items are necessary or not
// check if scanning all items are necessary or not
if
(
times
>=
5000
&&
TD_DLIST_NELES
(
&
(
*
pEntry
)
->
list
)
>
100
)
{
if
(
NEED_CHECK_CACHE_ITEM
(
listNEles
(
&
(
*
pEntry
)
->
list
),
times
)
)
{
taosThreadMutexLock
(
pLock
);
taosThreadMutexLock
(
pLock
);
SArray
*
pInvalidRes
=
taosArrayInit
(
64
,
POINTER_BYTES
);
SArray
*
pInvalidRes
=
taosArrayInit
(
64
,
POINTER_BYTES
);
checkAllEntriesInCache
(
*
pEntry
,
pInvalidRes
,
keyLen
,
pCache
,
suid
);
SListIter
iter
=
{
0
};
removeInvalidCacheItem
(
pInvalidRes
,
*
pEntry
);
// remove the keys, of which query uid lists have been replaced already.
tdListInitIter
(
&
(
*
pEntry
)
->
list
,
&
iter
,
TD_LIST_FORWARD
);
SListNode
*
pNode
=
NULL
;
while
((
pNode
=
tdListNext
(
&
iter
))
!=
NULL
)
{
memcpy
(
&
buf
[
1
],
pNode
->
data
,
keyLen
);
// check whether it is existed in LRU cache, and remove it from linked list if not.
LRUHandle
*
pRes
=
taosLRUCacheLookup
(
pCache
,
buf
,
len
);
if
(
pRes
==
NULL
)
{
// remove the item in the linked list
taosArrayPush
(
pInvalidRes
,
&
pNode
);
}
else
{
taosLRUCacheRelease
(
pCache
,
pRes
,
false
);
}
}
// remove the keys, of which query uid lists have been replaced already.
size_t
s
=
taosArrayGetSize
(
pInvalidRes
);
for
(
int32_t
i
=
0
;
i
<
s
;
++
i
)
{
SListNode
**
p1
=
taosArrayGet
(
pInvalidRes
,
i
);
tdListPopNode
(
&
(
*
pEntry
)
->
list
,
*
p1
);
taosMemoryFree
(
*
p1
);
}
atomic_store_32
(
&
(
*
pEntry
)
->
qTimes
,
0
);
// reset the query times
taosArrayDestroy
(
pInvalidRes
);
taosThreadMutexUnlock
(
pLock
);
taosThreadMutexUnlock
(
pLock
);
}
}
...
@@ -568,8 +587,8 @@ int32_t metaUidFilterCachePut(SMeta* pMeta, uint64_t suid, const void* pKey, int
...
@@ -568,8 +587,8 @@ int32_t metaUidFilterCachePut(SMeta* pMeta, uint64_t suid, const void* pKey, int
SArray
*
pInvalidRes
=
NULL
;
SArray
*
pInvalidRes
=
NULL
;
uint64_t
keyBuf
[
3
];
uint64_t
keyBuf
[
3
];
if
(
size
>=
100
||
times
>
5000
)
{
// if the threshold value is reached, need to check the value.
// if the threshold value is reached, need to check the value.
if
(
NEED_CHECK_CACHE_ITEM
(
size
,
times
))
{
checkCacheEntry
=
true
;
checkCacheEntry
=
true
;
keyBuf
[
0
]
=
suid
;
keyBuf
[
0
]
=
suid
;
pInvalidRes
=
taosArrayInit
(
64
,
POINTER_BYTES
);
pInvalidRes
=
taosArrayInit
(
64
,
POINTER_BYTES
);
...
@@ -585,18 +604,16 @@ int32_t metaUidFilterCachePut(SMeta* pMeta, uint64_t suid, const void* pKey, int
...
@@ -585,18 +604,16 @@ int32_t metaUidFilterCachePut(SMeta* pMeta, uint64_t suid, const void* pKey, int
// key already exists in cache, quit
// key already exists in cache, quit
if
(
p
[
1
]
==
((
uint64_t
*
)
pKey
)[
1
]
&&
p
[
0
]
==
((
uint64_t
*
)
pKey
)[
0
])
{
if
(
p
[
1
]
==
((
uint64_t
*
)
pKey
)[
1
]
&&
p
[
0
]
==
((
uint64_t
*
)
pKey
)[
0
])
{
// do remove invalid entry in hash
// do remove invalid entry in hash
size_t
s
=
taosArrayGetSize
(
pInvalidRes
);
if
(
pInvalidRes
!=
NULL
)
{
for
(
int32_t
i
=
0
;
i
<
s
;
++
i
)
{
removeInvalidCacheItem
(
pInvalidRes
,
*
pEntry
);
SListNode
**
p1
=
taosArrayGet
(
pInvalidRes
,
i
);
tdListPopNode
(
&
(
*
pEntry
)
->
list
,
*
p1
);
taosMemoryFree
(
*
p1
);
}
}
taosThreadMutexUnlock
(
pLock
);
taosThreadMutexUnlock
(
pLock
);
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
// check whether it is existed in LRU cache, and remove it from linked list if not.
// check whether it is existed in LRU cache, and remove it from linked list if not
// we record every invalid items and remove when the loop is over.
if
(
checkCacheEntry
)
{
if
(
checkCacheEntry
)
{
keyBuf
[
1
]
=
p
[
1
];
keyBuf
[
1
]
=
p
[
1
];
keyBuf
[
2
]
=
p
[
2
];
keyBuf
[
2
]
=
p
[
2
];
...
@@ -611,11 +628,8 @@ int32_t metaUidFilterCachePut(SMeta* pMeta, uint64_t suid, const void* pKey, int
...
@@ -611,11 +628,8 @@ int32_t metaUidFilterCachePut(SMeta* pMeta, uint64_t suid, const void* pKey, int
}
}
// do remove invalid entry in hash
// do remove invalid entry in hash
size_t
s
=
taosArrayGetSize
(
pInvalidRes
);
if
(
pInvalidRes
!=
NULL
)
{
for
(
int32_t
i
=
0
;
i
<
s
;
++
i
)
{
removeInvalidCacheItem
(
pInvalidRes
,
*
pEntry
);
SListNode
**
p1
=
taosArrayGet
(
pInvalidRes
,
i
);
tdListPopNode
(
&
(
*
pEntry
)
->
list
,
*
p1
);
taosMemoryFree
(
*
p1
);
}
}
tdListAppend
(
&
(
*
pEntry
)
->
list
,
pKey
);
tdListAppend
(
&
(
*
pEntry
)
->
list
,
pKey
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录