Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
a751c97f
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看板
提交
a751c97f
编写于
1月 19, 2022
作者:
H
Hongze Cheng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
more tdb
上级
a243752b
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
85 addition
and
19 deletion
+85
-19
source/libs/tdb/src/db/tdb_mpool.c
source/libs/tdb/src/db/tdb_mpool.c
+56
-1
source/libs/tdb/src/inc/tdb_inc.h
source/libs/tdb/src/inc/tdb_inc.h
+7
-1
source/libs/tdb/src/inc/tdb_mp.h
source/libs/tdb/src/inc/tdb_mp.h
+22
-17
未找到文件。
source/libs/tdb/src/db/tdb_mpool.c
浏览文件 @
a751c97f
...
...
@@ -13,4 +13,59 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "tdb_mpool.h"
\ No newline at end of file
#include "tdb_mp.h"
int
tdbOpenMP
(
TDB_MPOOL
**
mpp
,
uint64_t
cachesize
,
pgsize_t
pgsize
)
{
TDB_MPOOL
*
mp
;
size_t
tsize
;
MP_PAGE
*
pagep
;
// check parameters
if
(
!
TDB_IS_PGSIZE_VLD
(
pgsize
))
{
tdbError
(
"invalid page size"
);
return
-
1
;
}
// allocate handle
mp
=
(
TDB_MPOOL
*
)
calloc
(
1
,
sizeof
(
*
mp
));
if
(
mp
==
NULL
)
{
tdbError
(
"failed to malloc memory pool handle"
);
return
-
1
;
}
// initialize the handle
mp
->
cachesize
=
cachesize
;
mp
->
pgsize
=
pgsize
;
mp
->
npages
=
cachesize
/
pgsize
;
mp
->
pages
=
(
MP_PAGE
*
)
calloc
(
mp
->
npages
,
MP_PAGE_SIZE
(
pgsize
));
if
(
mp
->
pages
==
NULL
)
{
tdbError
(
"failed to malloc memory pool pages"
);
free
(
mp
);
return
-
1
;
}
TD_DLIST_INIT
(
&
(
mp
->
freeList
));
mp
->
nbucket
=
mp
->
npages
;
mp
->
hashtab
=
(
MP_PAGE_LIST
*
)
calloc
(
mp
->
nbucket
,
sizeof
(
MP_PAGE_LIST
));
if
(
mp
->
hashtab
==
NULL
)
{
tdbError
(
"failed to malloc memory pool hash table"
);
free
(
mp
->
pages
);
free
(
mp
);
return
-
1
;
}
for
(
int
i
=
0
;
i
<
mp
->
npages
;
i
++
)
{
pagep
=
(
MP_PAGE
*
)
MP_PAGE_AT
(
mp
,
i
);
TD_DLIST_APPEND
(
&
mp
->
freeList
,
pagep
);
}
// return
*
mpp
=
mp
;
return
0
;
}
int
tdbCloseMP
(
TDB_MPOOL
*
mp
)
{
// TODO
return
0
;
}
source/libs/tdb/src/inc/tdb_inc.h
浏览文件 @
a751c97f
...
...
@@ -35,7 +35,13 @@ typedef int32_t pgsize_t;
#define TDB_MIN_PGSIZE 512
#define TDB_MAX_PGSIZE 16384
#define TDB_DEFAULT_PGSIZE 4096
#define TDB_IS_PGSIZE_VLD(s) (((s) >= TKV_MIN_PGSIZE) && (TKV_MAX_PGSIZE <= TKV_MAX_PGSIZE))
#define TDB_IS_PGSIZE_VLD(s) (((s) >= TDB_MIN_PGSIZE) && ((s) <= TDB_MAX_PGSIZE))
// fileid
#define TDB_FILE_UID_LEN 20
// tdb_log
#define tdbError(var)
#ifdef __cplusplus
}
...
...
source/libs/tdb/src/inc/tdb_mp
ool
.h
→
source/libs/tdb/src/inc/tdb_mp.h
浏览文件 @
a751c97f
...
...
@@ -25,39 +25,44 @@ extern "C" {
// Exposed handle
typedef
struct
TDB_MPOOL
TDB_MPOOL
;
#define TDB_FILE_UID_LEN 20
typedef
struct
{
uint8_t
fuid
[
TDB_FILE_UID_LEN
];
pgid_t
pgid
;
}
mp_pgid_t
;
// Exposed apis
int
tdbOpenMP
(
TDB_MPOOL
**
mpp
,
uint64_t
cachesize
,
pgsize_t
pgsize
);
int
tdbCloseMP
(
TDB_MPOOL
*
mp
);
int
tdbMPFetchPage
(
TDB_MPOOL
*
mp
,
mp_pgid_t
mpgid
,
void
*
p
);
int
tdbMpUnfetchPage
(
TDB_MPOOL
*
mp
,
mp_pgid_t
mpgid
,
void
*
p
);
// Hidden impls
typedef
struct
MP_PAGE
{
// SRWLatch rwLatch;
mp_pgid_t
mpgid
;
uint8_t
dirty
;
int32_t
pinRef
;
// TD_DLIST_NODE(MP_PAGE); // The free list handle
TD_DLIST_NODE
(
MP_PAGE
);
char
*
page
[];
}
MP_PAGE
;
#define MP_PAGE_SIZE(pgsize) (sizeof(MP_PAGE) + (pgsize))
typedef
TD_DLIST
(
MP_PAGE
)
MP_PAGE_LIST
;
struct
TDB_MPOOL
{
pthread_mutex_t
mutex
;
int64_t
cachesize
;
pgsize_t
pgsize
;
MP_PAGE
*
pages
;
// TD_DBLIST(MP_PAGE) freeList;
// TD_DLIST(TD_MPFILE) mpfList; // MPFILE registered on this memory pool
// Hash<mp_pgid_t, frameid> hash;
int64_t
cachesize
;
pgsize_t
pgsize
;
int32_t
npages
;
MP_PAGE
*
pages
;
MP_PAGE_LIST
freeList
;
// Hash<mp_pgid_t, frame_id_t>
int32_t
nbucket
;
MP_PAGE_LIST
*
hashtab
;
// TODO: TD_DLIST(TD_MPFILE) mpfList; // MPFILE registered on this memory pool
};
#define MP_PAGE_AT(mp, idx) ((char *)((mp)->pages) + MP_PAGE_SIZE((mp)->pgsize) * (idx))
// Exposed apis =====================================================================================================
int
tdbOpenMP
(
TDB_MPOOL
**
mpp
,
uint64_t
cachesize
,
pgsize_t
pgsize
);
int
tdbCloseMP
(
TDB_MPOOL
*
mp
);
int
tdbMPFetchPage
(
TDB_MPOOL
*
mp
,
mp_pgid_t
mpgid
,
void
*
p
);
int
tdbMpUnfetchPage
(
TDB_MPOOL
*
mp
,
mp_pgid_t
mpgid
,
void
*
p
);
#ifdef __cplusplus
}
#endif
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录