Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
da49669a
T
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
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看板
提交
da49669a
编写于
2月 15, 2022
作者:
H
Hongze Cheng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refact TDB
上级
1bcb1098
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
31 addition
and
36 deletion
+31
-36
source/libs/tdb/src/db/tdbPgCache.c
source/libs/tdb/src/db/tdbPgCache.c
+31
-36
未找到文件。
source/libs/tdb/src/db/tdbPgCache.c
浏览文件 @
da49669a
...
...
@@ -18,10 +18,10 @@ typedef TD_DLIST_NODE(SPage) SPgListNode;
struct
SPage
{
pgid_t
pgid
;
// page id
frame_id_t
frameid
;
// frame id
uint8_t
*
pData
;
// real data
SPgListNode
freeNode
;
// for SPgCache.freeList
SPgListNode
pghtNode
;
// for pght
SPgListNode
lruNode
;
// for LRU
uint8_t
*
pData
;
// real data
};
typedef
TD_DLIST
(
SPage
)
SPgList
;
...
...
@@ -29,7 +29,7 @@ struct SPgCache {
TENV
*
pEnv
;
// TENV containing this page cache
pgsz_t
pgsize
;
int32_t
npage
;
SPage
*
pages
;
SPage
*
*
pages
;
SPgList
freeList
;
SPgList
lru
;
struct
{
...
...
@@ -44,59 +44,58 @@ static void pgCacheUnpinPage(SPage *pPage);
int
pgCacheOpen
(
SPgCache
**
ppPgCache
,
TENV
*
pEnv
)
{
SPgCache
*
pPgCache
;
SPage
*
pPage
;
void
*
pData
;
pgsz_t
pgSize
;
cachesz_t
cacheSize
;
int32_t
npage
;
int32_t
nbucket
;
size_t
msize
;
*
ppPgCache
=
NULL
;
pgSize
=
tdbEnvGetPageSize
(
pEnv
);
cacheSize
=
tdbEnvGetCacheSize
(
pEnv
);
npage
=
cacheSize
/
pgSize
;
nbucket
=
npage
;
msize
=
sizeof
(
*
pPgCache
)
+
sizeof
(
SPage
*
)
*
npage
+
sizeof
(
SPgList
)
*
nbucket
;
// Allocate the handle
pPgCache
=
(
SPgCache
*
)
calloc
(
1
,
sizeof
(
*
pPgCache
)
);
pPgCache
=
(
SPgCache
*
)
calloc
(
1
,
msize
);
if
(
pPgCache
==
NULL
)
{
return
-
1
;
}
// Init the handle
pPgCache
->
pEnv
=
pEnv
;
pPgCache
->
pgsize
=
pgSize
;
pPgCache
->
npage
=
npage
;
for
(
int32_t
i
=
0
;
i
<
npage
;
i
++
)
{
/* code */
}
#if 0
pPgCache->pages = (SPage *)calloc(npage, sizeof(SPage));
if (pPgCache->pages == NULL) {
pgCacheClose(pPgCache);
return -1;
}
pPgCache
->
pages
=
(
SPage
**
)(
&
pPgCache
[
1
]);
pPgCache
->
pght
.
nbucket
=
nbucket
;
pPgCache
->
pght
.
buckets
=
(
SPgList
*
)(
&
(
pPgCache
->
pages
[
npage
]));
TD_DLIST_INIT
(
&
(
pPgCache
->
freeList
));
for
(
int32_t
i
=
0
;
i
<
npage
;
i
++
)
{
pPage = pPgCache->pages + i;
pPage->pgid = TDB_IVLD_PGID;
pPage->frameid = i;
pPage->pData = (uint8_t *)calloc(1, pgSize);
if (pPage->pData == NULL) {
pgCacheClose(pPgCache);
pData
=
malloc
(
pgSize
+
sizeof
(
SPage
));
if
(
pData
==
NULL
)
{
return
-
1
;
// TODO: handle error
}
pPgCache->pght.nbucket = npage;
pPgCache->pght.buckets = (SPgList *)calloc(pPgCache->pght.nbucket, sizeof(SPgList));
if (pPgCache->pght.buckets == NULL) {
pgCacheClose(pPgCache);
return -1;
}
pPage
=
POINTER_SHIFT
(
pData
,
pgSize
);
pPage
->
pgid
=
TDB_IVLD_PGID
;
pPage
->
frameid
=
i
;
pPage
->
pData
=
pData
;
// add current page to the page cache
pPgCache
->
pages
[
i
]
=
pPage
;
TD_DLIST_APPEND_WITH_FIELD
(
&
(
pPgCache
->
freeList
),
pPage
,
freeNode
);
}
#if 0
for (int32_t i = 0; i < nbucket; i++) {
TD_DLIST_INIT(pPgCache->pght.buckets + i);
}
#endif
*
ppPgCache
=
pPgCache
;
...
...
@@ -106,15 +105,11 @@ int pgCacheOpen(SPgCache **ppPgCache, TENV *pEnv) {
int
pgCacheClose
(
SPgCache
*
pPgCache
)
{
SPage
*
pPage
;
if
(
pPgCache
)
{
tfree
(
pPgCache
->
pght
.
buckets
);
if
(
pPgCache
->
pages
)
{
for
(
int32_t
i
=
0
;
i
<
pPgCache
->
npage
;
i
++
)
{
pPage
=
pPgCache
->
pages
+
i
;
tfree
(
pPage
->
pData
);
}
free
(
pPgCache
->
pages
);
for
(
int32_t
i
=
0
;
i
<
pPgCache
->
npage
;
i
++
)
{
pPage
=
pPgCache
->
pages
[
i
];
tfree
(
pPage
->
pData
);
}
free
(
pPgCache
);
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录