Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
2668def4
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看板
未验证
提交
2668def4
编写于
12月 22, 2022
作者:
S
Shengliang Guan
提交者:
GitHub
12月 22, 2022
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #19076 from taosdata/feature/3_liaohj
fix(query): add lock for cache.
上级
053f48e3
8210c49a
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
86 addition
and
51 deletion
+86
-51
source/dnode/vnode/src/meta/metaCache.c
source/dnode/vnode/src/meta/metaCache.c
+81
-50
source/dnode/vnode/src/tsdb/tsdbRead.c
source/dnode/vnode/src/tsdb/tsdbRead.c
+2
-0
source/util/src/tpagedbuf.c
source/util/src/tpagedbuf.c
+3
-1
未找到文件。
source/dnode/vnode/src/meta/metaCache.c
浏览文件 @
2668def4
...
...
@@ -54,6 +54,7 @@ struct SMetaCache {
// query cache
struct
STagFilterResCache
{
TdThreadMutex
lock
;
SHashObj
*
pTableEntry
;
SLRUCache
*
pUidResCache
;
uint64_t
keyBuf
[
3
];
...
...
@@ -140,6 +141,8 @@ int32_t metaCacheOpen(SMeta* pMeta) {
}
taosHashSetFreeFp
(
pCache
->
sTagFilterResCache
.
pTableEntry
,
freeCacheEntryFp
);
taosThreadMutexInit
(
&
pCache
->
sTagFilterResCache
.
lock
,
NULL
);
pMeta
->
pCache
=
pCache
;
return
code
;
...
...
@@ -159,6 +162,8 @@ void metaCacheClose(SMeta* pMeta) {
taosHashCleanup
(
pMeta
->
pCache
->
sTagFilterResCache
.
pTableEntry
);
taosLRUCacheCleanup
(
pMeta
->
pCache
->
sTagFilterResCache
.
pUidResCache
);
taosThreadMutexDestroy
(
&
pMeta
->
pCache
->
sTagFilterResCache
.
lock
);
taosMemoryFree
(
pMeta
->
pCache
);
pMeta
->
pCache
=
NULL
;
}
...
...
@@ -422,63 +427,78 @@ int32_t metaStatsCacheGet(SMeta* pMeta, int64_t uid, SMetaStbStats* pInfo) {
int32_t
metaGetCachedTableUidList
(
SMeta
*
pMeta
,
tb_uid_t
suid
,
const
uint8_t
*
pKey
,
int32_t
keyLen
,
SArray
*
pList1
,
bool
*
acquireRes
)
{
uint64_t
*
pBuf
=
pMeta
->
pCache
->
sTagFilterResCache
.
keyBuf
;
// generate the composed key for LRU cache
SLRUCache
*
pCache
=
pMeta
->
pCache
->
sTagFilterResCache
.
pUidResCache
;
SLRUCache
*
pCache
=
pMeta
->
pCache
->
sTagFilterResCache
.
pUidResCache
;
uint64_t
*
pBuf
=
pMeta
->
pCache
->
sTagFilterResCache
.
keyBuf
;
SHashObj
*
pTableMap
=
pMeta
->
pCache
->
sTagFilterResCache
.
pTableEntry
;
TdThreadMutex
*
pLock
=
&
pMeta
->
pCache
->
sTagFilterResCache
.
lock
;
uint32_t
times
=
0
;
*
acquireRes
=
0
;
pBuf
[
0
]
=
suid
;
memcpy
(
&
pBuf
[
1
],
pKey
,
keyLen
);
taosThreadMutexLock
(
pLock
);
int32_t
len
=
keyLen
+
sizeof
(
uint64_t
);
LRUHandle
*
pHandle
=
taosLRUCacheLookup
(
pCache
,
pBuf
,
len
);
if
(
pHandle
==
NULL
)
{
*
acquireRes
=
0
;
taosThreadMutexUnlock
(
pLock
)
;
return
TSDB_CODE_SUCCESS
;
}
else
{
// do some book mark work after acquiring the filter result from cache
STagFilterResEntry
**
pEntry
=
taosHashGet
(
pMeta
->
pCache
->
sTagFilterResCache
.
pTableEntry
,
&
suid
,
sizeof
(
uint64_t
));
ASSERT
(
pEntry
!=
NULL
);
*
acquireRes
=
1
;
const
char
*
p
=
taosLRUCacheValue
(
pMeta
->
pCache
->
sTagFilterResCache
.
pUidResCache
,
pHandle
);
int32_t
size
=
*
(
int32_t
*
)
p
;
taosArrayAddBatch
(
pList1
,
p
+
sizeof
(
int32_t
),
size
);
(
*
pEntry
)
->
qTimes
+=
1
;
taosLRUCacheRelease
(
pCache
,
pHandle
,
false
);
// check if scanning all items are necessary or not
if
((
*
pEntry
)
->
qTimes
>=
5000
&&
TD_DLIST_NELES
(
&
(
*
pEntry
)
->
list
)
>
10
)
{
SArray
*
pList
=
taosArrayInit
(
64
,
POINTER_BYTES
);
SListIter
iter
=
{
0
};
tdListInitIter
(
&
(
*
pEntry
)
->
list
,
&
iter
,
TD_LIST_FORWARD
);
SListNode
*
pNode
=
NULL
;
while
((
pNode
=
tdListNext
(
&
iter
))
!=
NULL
)
{
memcpy
(
&
pBuf
[
1
],
pNode
->
data
,
keyLen
);
// check whether it is existed in LRU cache, and remove it from linked list if not.
LRUHandle
*
pRes
=
taosLRUCacheLookup
(
pCache
,
pBuf
,
len
);
if
(
pRes
==
NULL
)
{
// remove the item in the linked list
taosArrayPush
(
pList
,
&
pNode
);
}
else
{
taosLRUCacheRelease
(
pCache
,
pRes
,
false
);
}
}
}
// remove the keys, of which query uid lists have been replaced already.
size_t
s
=
taosArrayGetSize
(
pList
);
for
(
int32_t
i
=
0
;
i
<
s
;
++
i
)
{
SListNode
**
p1
=
taosArrayGet
(
pList
,
i
);
tdListPopNode
(
&
(
*
pEntry
)
->
list
,
*
p1
);
taosMemoryFree
(
*
p1
);
}
// do some book mark work after acquiring the filter result from cache
STagFilterResEntry
**
pEntry
=
taosHashGet
(
pTableMap
,
&
suid
,
sizeof
(
uint64_t
));
ASSERT
(
pEntry
!=
NULL
);
*
acquireRes
=
1
;
(
*
pEntry
)
->
qTimes
=
0
;
// reset the query times
const
char
*
p
=
taosLRUCacheValue
(
pCache
,
pHandle
);
int32_t
size
=
*
(
int32_t
*
)
p
;
taosArrayDestroy
(
pList
);
// set the result into the buffer
taosArrayAddBatch
(
pList1
,
p
+
sizeof
(
int32_t
),
size
);
times
=
atomic_add_fetch_32
(
&
(
*
pEntry
)
->
qTimes
,
1
);
taosLRUCacheRelease
(
pCache
,
pHandle
,
false
);
// unlock meta
taosThreadMutexUnlock
(
pLock
);
// check if scanning all items are necessary or not
if
(
times
>=
5000
&&
TD_DLIST_NELES
(
&
(
*
pEntry
)
->
list
)
>
10
)
{
taosThreadMutexLock
(
pLock
);
SArray
*
pInvalidRes
=
taosArrayInit
(
64
,
POINTER_BYTES
);
SListIter
iter
=
{
0
};
tdListInitIter
(
&
(
*
pEntry
)
->
list
,
&
iter
,
TD_LIST_FORWARD
);
SListNode
*
pNode
=
NULL
;
while
((
pNode
=
tdListNext
(
&
iter
))
!=
NULL
)
{
memcpy
(
&
pBuf
[
1
],
pNode
->
data
,
keyLen
);
// check whether it is existed in LRU cache, and remove it from linked list if not.
LRUHandle
*
pRes
=
taosLRUCacheLookup
(
pCache
,
pBuf
,
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
);
}
return
TSDB_CODE_SUCCESS
;
...
...
@@ -510,8 +530,11 @@ int32_t metaUidFilterCachePut(SMeta* pMeta, uint64_t suid, const void* pKey, int
return
TSDB_CODE_SUCCESS
;
}
SLRUCache
*
pCache
=
pMeta
->
pCache
->
sTagFilterResCache
.
pUidResCache
;
SHashObj
*
pTableEntry
=
pMeta
->
pCache
->
sTagFilterResCache
.
pTableEntry
;
SLRUCache
*
pCache
=
pMeta
->
pCache
->
sTagFilterResCache
.
pUidResCache
;
SHashObj
*
pTableEntry
=
pMeta
->
pCache
->
sTagFilterResCache
.
pTableEntry
;
TdThreadMutex
*
pLock
=
&
pMeta
->
pCache
->
sTagFilterResCache
.
lock
;
taosThreadMutexLock
(
pLock
);
STagFilterResEntry
**
pEntry
=
taosHashGet
(
pTableEntry
,
&
suid
,
sizeof
(
uint64_t
));
if
(
pEntry
==
NULL
)
{
...
...
@@ -533,6 +556,9 @@ int32_t metaUidFilterCachePut(SMeta* pMeta, uint64_t suid, const void* pKey, int
// add to cache.
taosLRUCacheInsert
(
pCache
,
pBuf
,
sizeof
(
uint64_t
)
+
keyLen
,
pPayload
,
payloadLen
,
freePayload
,
NULL
,
TAOS_LRU_PRIORITY_LOW
);
taosThreadMutexUnlock
(
pLock
);
metaDebug
(
"vgId:%d, suid:%"
PRIu64
" list cache added into cache, total:%d, tables:%d"
,
TD_VID
(
pMeta
->
pVnode
),
suid
,
(
int32_t
)
taosLRUCacheGetUsage
(
pCache
),
taosHashGetSize
(
pTableEntry
));
...
...
@@ -541,15 +567,19 @@ int32_t metaUidFilterCachePut(SMeta* pMeta, uint64_t suid, const void* pKey, int
// remove the lru cache that are expired due to the tags value update, or creating, or dropping, of child tables
int32_t
metaUidCacheClear
(
SMeta
*
pMeta
,
uint64_t
suid
)
{
int32_t
keyLen
=
sizeof
(
uint64_t
)
*
3
;
uint64_t
p
[
3
]
=
{
0
};
p
[
0
]
=
suid
;
TdThreadMutex
*
pLock
=
&
pMeta
->
pCache
->
sTagFilterResCache
.
lock
;
taosThreadMutexLock
(
pLock
);
STagFilterResEntry
**
pEntry
=
taosHashGet
(
pMeta
->
pCache
->
sTagFilterResCache
.
pTableEntry
,
&
suid
,
sizeof
(
uint64_t
));
if
(
pEntry
==
NULL
||
listNEles
(
&
(
*
pEntry
)
->
list
)
==
0
)
{
taosThreadMutexUnlock
(
pLock
);
return
TSDB_CODE_SUCCESS
;
}
int32_t
keyLen
=
sizeof
(
uint64_t
)
*
3
;
uint64_t
p
[
3
]
=
{
0
};
p
[
0
]
=
suid
;
SListIter
iter
=
{
0
};
tdListInitIter
(
&
(
*
pEntry
)
->
list
,
&
iter
,
TD_LIST_FORWARD
);
...
...
@@ -562,5 +592,6 @@ int32_t metaUidCacheClear(SMeta* pMeta, uint64_t suid) {
(
*
pEntry
)
->
qTimes
=
0
;
tdListEmpty
(
&
(
*
pEntry
)
->
list
);
taosThreadMutexUnlock
(
pLock
);
return
TSDB_CODE_SUCCESS
;
}
source/dnode/vnode/src/tsdb/tsdbRead.c
浏览文件 @
2668def4
...
...
@@ -3522,6 +3522,8 @@ int32_t doMergeMemIMemRows(TSDBROW* pRow, TSDBROW* piRow, STableBlockScanInfo* p
}
int32_t
code
=
tRowMergerGetRow
(
&
merge
,
pTSRow
);
tRowMergerClear
(
&
merge
);
return
code
;
}
...
...
source/util/src/tpagedbuf.c
浏览文件 @
2668def4
...
...
@@ -621,11 +621,13 @@ void dBufPrintStatis(const SDiskbasedBuf* pBuf) {
const
SDiskbasedBufStatis
*
ps
=
&
pBuf
->
statis
;
#if 0
printf(
"Paged buffer closed, total:%.2f Kb (%d Pages), inmem size:%.2f Kb (%d Pages), file size:%.2f Kb, page size:%.2f "
"Kb, %s\n",
pBuf->totalBufSize / 1024.0, pBuf->numOfPages, listNEles(pBuf->lruList) * pBuf->pageSize / 1024.0,
listNEles(pBuf->lruList), pBuf->fileSize / 1024.0, pBuf->pageSize / 1024.0f, pBuf->id);
#endif
if
(
ps
->
loadPages
>
0
)
{
printf
(
...
...
@@ -634,7 +636,7 @@ void dBufPrintStatis(const SDiskbasedBuf* pBuf) {
ps
->
getPages
,
ps
->
releasePages
,
ps
->
flushBytes
/
1024
.
0
f
,
ps
->
flushPages
,
ps
->
loadBytes
/
1024
.
0
f
,
ps
->
loadPages
,
ps
->
loadBytes
/
(
1024
.
0
*
ps
->
loadPages
));
}
else
{
printf
(
"no page loaded
\n
"
);
//
printf("no page loaded\n");
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录