Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
6d446e61
T
TDengine
项目概览
taosdata
/
TDengine
12 个月 前同步成功
通知
1180
Star
22014
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看板
体验新版 GitCode,发现更多精彩内容 >>
提交
6d446e61
编写于
2月 07, 2022
作者:
H
Hongze Cheng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
more TDB
上级
a195e51c
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
68 addition
and
9 deletion
+68
-9
source/libs/tdb/src/db/pgcache.c
source/libs/tdb/src/db/pgcache.c
+62
-6
source/libs/tdb/src/inc/pgcache.h
source/libs/tdb/src/inc/pgcache.h
+3
-3
source/libs/tdb/src/inc/tdbInt.h
source/libs/tdb/src/inc/tdbInt.h
+3
-0
未找到文件。
source/libs/tdb/src/db/pgcache.c
浏览文件 @
6d446e61
...
...
@@ -14,9 +14,12 @@
*/
#include "tdbInt.h"
typedef
TD_DLIST_NODE
(
SPage
)
SPgListNode
;
struct
SPage
{
pgid_t
pgid
;
// page id
// TODO
frame_id_t
frameid
;
// frame id
SPgListNode
freeNode
;
// for SPgCache.freeList
uint8_t
*
pData
;
// real data
};
typedef
TD_DLIST
(
SPage
)
SPgList
;
...
...
@@ -24,6 +27,7 @@ typedef TD_DLIST(SPage) SPgList;
struct
SPgCache
{
SRWLatch
mutex
;
pgsize_t
pgsize
;
int32_t
npage
;
SPage
*
pages
;
SPgList
freeList
;
struct
{
...
...
@@ -32,31 +36,83 @@ struct SPgCache {
}
pght
;
// page hash table
};
int
pgCacheCreate
(
SPgCache
**
ppPgCache
,
pgsize_t
pg
siz
e
)
{
int
pgCacheCreate
(
SPgCache
**
ppPgCache
,
pgsize_t
pg
Size
,
int32_t
npag
e
)
{
SPgCache
*
pPgCache
;
SPage
*
pPage
;
*
ppPgCache
=
NULL
;
if
(
!
TDB_IS_PGSIZE_VLD
(
pgSize
))
{
return
-
1
;
}
pPgCache
=
(
SPgCache
*
)
calloc
(
1
,
sizeof
(
*
pPgCache
));
if
(
pPgCache
==
NULL
)
{
return
-
1
;
}
pPgCache
->
pgsize
=
pgsize
;
taosInitRWLatch
(
&
(
pPgCache
->
mutex
));
pPgCache
->
pgsize
=
pgSize
;
pPgCache
->
npage
=
npage
;
pPgCache
->
pages
=
(
SPage
*
)
calloc
(
npage
,
sizeof
(
SPage
));
if
(
pPgCache
->
pages
==
NULL
)
{
pgCacheDestroy
(
pPgCache
);
return
-
1
;
}
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
)
{
pgCacheDestroy
(
pPgCache
);
return
-
1
;
}
pPgCache
->
pght
.
nbucket
=
npage
;
pPgCache
->
pght
.
buckets
=
(
SPgList
*
)
calloc
(
pPgCache
->
pght
.
nbucket
,
sizeof
(
SPgList
));
if
(
pPgCache
->
pght
.
buckets
==
NULL
)
{
pgCacheDestroy
(
pPgCache
);
return
-
1
;
}
TD_DLIST_APPEND_WITH_FIELD
(
&
(
pPgCache
->
freeList
),
pPage
,
freeNode
);
}
*
ppPgCache
=
pPgCache
;
return
0
;
}
int
pgCacheDestroy
(
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
);
}
free
(
pPgCache
);
}
return
0
;
}
int
pgCacheOpen
(
SPgCache
*
pPgCache
)
{
int
pgCacheOpen
(
SPgCache
**
ppPgCache
)
{
if
(
*
ppPgCache
==
NULL
)
{
if
(
pgCacheCreate
(
ppPgCache
,
TDB_DEFAULT_PGSIZE
,
TDB_DEFAULT_CACHE_SIZE
/
TDB_DEFAULT_PGSIZE
)
<
0
)
{
return
-
1
;
}
}
// TODO
return
0
;
}
...
...
source/libs/tdb/src/inc/pgcache.h
浏览文件 @
6d446e61
...
...
@@ -24,9 +24,9 @@ typedef struct SPgCache SPgCache;
typedef
struct
SPage
SPage
;
// SPgCache
int
pgCacheCreate
(
SPgCache
**
ppPgCache
,
pgsize_t
pg
siz
e
);
int
pgCache
Destroy
(
SPgCache
*
pPgCache
);
int
pgCache
Open
(
SPgCache
*
pPgCache
);
int
pgCacheCreate
(
SPgCache
**
ppPgCache
,
pgsize_t
pg
Size
,
int32_t
npag
e
);
int
pgCache
Open
(
SPgCache
**
p
pPgCache
);
int
pgCache
Close
(
SPgCache
*
pPgCache
);
int
pgCacheClose
(
SPgCache
*
pPgCache
);
SPage
*
pgCacheFetch
(
SPgCache
*
pPgCache
);
...
...
source/libs/tdb/src/inc/tdbInt.h
浏览文件 @
6d446e61
...
...
@@ -50,6 +50,9 @@ typedef int32_t pgsize_t;
#define TDB_DEFAULT_PGSIZE 4096
#define TDB_IS_PGSIZE_VLD(s) (((s) >= TDB_MIN_PGSIZE) && ((s) <= TDB_MAX_PGSIZE))
// cache
#define TDB_DEFAULT_CACHE_SIZE (256 * 1024) // 256K
// tdb_log
#define tdbError(var)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录