Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
bfd427ae
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看板
提交
bfd427ae
编写于
1月 20, 2022
作者:
H
Hongze Cheng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
more TDB
上级
ed06d822
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
106 addition
and
40 deletion
+106
-40
source/libs/tdb/src/db/tdb_mpool.c
source/libs/tdb/src/db/tdb_mpool.c
+78
-16
source/libs/tdb/src/inc/tdb_inc.h
source/libs/tdb/src/inc/tdb_inc.h
+4
-3
source/libs/tdb/src/inc/tdb_mpool.h
source/libs/tdb/src/inc/tdb_mpool.h
+24
-21
未找到文件。
source/libs/tdb/src/db/tdb_mpool.c
浏览文件 @
bfd427ae
...
...
@@ -15,8 +15,10 @@
#include "tdb_mpool.h"
static
int
tdbGnrtFileID
(
const
char
*
fname
,
uint8_t
*
fileid
);
int
tdbMPoolOpen
(
TDB_MPOOL
**
mpp
,
uint64_t
cachesize
,
pgsize_t
pgsize
)
{
TDB_MPOOL
*
mp
;
TDB_MPOOL
*
mp
=
NULL
;
size_t
tsize
;
pg_t
*
pagep
;
...
...
@@ -30,42 +32,102 @@ int tdbMPoolOpen(TDB_MPOOL **mpp, uint64_t cachesize, pgsize_t pgsize) {
mp
=
(
TDB_MPOOL
*
)
calloc
(
1
,
sizeof
(
*
mp
));
if
(
mp
==
NULL
)
{
tdbError
(
"failed to malloc memory pool handle"
);
return
-
1
;
goto
_err
;
}
// initialize the handle
mp
->
cachesize
=
cachesize
;
mp
->
pgsize
=
pgsize
;
mp
->
npages
=
cachesize
/
pgsize
;
mp
->
pages
=
(
pg_t
*
)
calloc
(
mp
->
npages
,
MP_PAGE_SIZE
(
pgsize
));
TD_DLIST_INIT
(
&
mp
->
freeList
);
mp
->
pages
=
(
pg_t
**
)
calloc
(
mp
->
npages
,
sizeof
(
pg_t
*
));
if
(
mp
->
pages
==
NULL
)
{
tdbError
(
"failed to malloc memory pool pages"
);
free
(
mp
);
return
-
1
;
goto
_err
;
}
TD_DLIST_INIT
(
&
(
mp
->
freeList
));
for
(
frame_id_t
i
=
0
;
i
<
mp
->
npages
;
i
++
)
{
mp
->
pages
[
i
]
=
(
pg_t
*
)
calloc
(
1
,
MP_PAGE_SIZE
(
pgsize
));
if
(
mp
->
pages
[
i
]
==
NULL
)
{
goto
_err
;
}
mp
->
nbucket
=
mp
->
npages
;
mp
->
hashtab
=
(
pg_list_t
*
)
calloc
(
mp
->
nbucket
,
sizeof
(
pg_list_t
));
if
(
mp
->
hashtab
==
NULL
)
{
tdbError
(
"failed to malloc memory pool hash table"
);
free
(
mp
->
pages
);
free
(
mp
);
return
-
1
;
taosInitRWLatch
(
&
mp
->
pages
[
i
]
->
rwLatch
);
mp
->
pages
[
i
]
->
frameid
=
i
;
mp
->
pages
[
i
]
->
pgid
=
TDB_IVLD_PGID
;
// TODO: add the new page to the free list
// TD_DLIST_APPEND(&mp->freeList, mp->pages[i]);
}
for
(
int
i
=
0
;
i
<
mp
->
npages
;
i
++
)
{
pagep
=
(
pg_t
*
)
MP_PAGE_AT
(
mp
,
i
);
TD_DLIST_APPEND
(
&
mp
->
freeList
,
pagep
);
#define PGTAB_FACTOR 1.0
mp
->
pgtab
.
nbucket
=
mp
->
npages
/
PGTAB_FACTOR
;
mp
->
pgtab
.
hashtab
=
(
pg_list_t
*
)
calloc
(
mp
->
pgtab
.
nbucket
,
sizeof
(
pg_list_t
));
if
(
mp
->
pgtab
.
hashtab
==
NULL
)
{
tdbError
(
"failed to malloc memory pool hash table"
);
goto
_err
;
}
// return
*
mpp
=
mp
;
return
0
;
_err:
tdbMPoolClose
(
mp
);
*
mpp
=
NULL
;
return
-
1
;
}
int
tdbMPoolClose
(
TDB_MPOOL
*
mp
)
{
if
(
mp
)
{
tfree
(
mp
->
pgtab
.
hashtab
);
if
(
mp
->
pages
)
{
for
(
int
i
=
0
;
i
<
mp
->
npages
;
i
++
)
{
tfree
(
mp
->
pages
[
i
]);
}
free
(
mp
->
pages
);
}
free
(
mp
);
}
return
0
;
}
int
tdbMPoolFileOpen
(
TDB_MPFILE
**
mpfp
,
const
char
*
fname
,
TDB_MPOOL
*
mp
)
{
TDB_MPFILE
*
mpf
;
if
((
mpf
=
(
TDB_MPFILE
*
)
calloc
(
1
,
sizeof
(
*
mpf
)))
==
NULL
)
{
return
-
1
;
}
mpf
->
fd
=
-
1
;
if
((
mpf
->
fname
=
strdup
(
fname
))
==
NULL
)
{
goto
_err
;
}
if
((
mpf
->
fd
=
open
(
fname
,
O_CREAT
|
O_RDWR
,
0755
))
<
0
)
{
goto
_err
;
}
*
mpfp
=
mpf
;
return
0
;
_err:
tdbMPoolFileClose
(
mpf
);
*
mpfp
=
NULL
;
return
-
1
;
}
int
tdbMPoolFileClose
(
TDB_MPFILE
*
mpf
)
{
// TODO
return
0
;
}
static
int
tdbGnrtFileID
(
const
char
*
fname
,
uint8_t
*
fileid
)
{
// TODO
return
0
;
}
\ No newline at end of file
source/libs/tdb/src/inc/tdb_inc.h
浏览文件 @
bfd427ae
...
...
@@ -26,16 +26,17 @@ extern "C" {
// pgno_t
typedef
int32_t
pgno_t
;
#define TDB_IVLD_PG
ID
((pgno_t)-1)
#define TDB_IVLD_PG
NO
((pgno_t)-1)
// fileid
#define TDB_FILE_
UID_LEN 20
#define TDB_FILE_
ID_LEN 24
// pgid_t
typedef
struct
{
uint8_t
fileid
[
TDB_FILE_
U
ID_LEN
];
uint8_t
fileid
[
TDB_FILE_ID_LEN
];
pgno_t
pgid
;
}
pgid_t
;
#define TDB_IVLD_PGID (pgid_t){0, TDB_IVLD_PGNO};
// framd_id_t
typedef
int32_t
frame_id_t
;
...
...
source/libs/tdb/src/inc/tdb_mpool.h
浏览文件 @
bfd427ae
...
...
@@ -26,13 +26,16 @@ extern "C" {
typedef
struct
TDB_MPOOL
TDB_MPOOL
;
typedef
struct
TDB_MPFILE
TDB_MPFILE
;
typedef
TD_DLIST_NODE
(
pg_t
)
pg_free_list_node_t
,
pg_hash_list_node_t
;
typedef
struct
pg_t
{
SRWLatch
rwLatch
;
pgid_t
mpgid
;
uint8_t
dirty
;
int32_t
pinRef
;
TD_DLIST_NODE
(
pg_t
);
char
*
page
[];
SRWLatch
rwLatch
;
frame_id_t
frameid
;
pgid_t
pgid
;
uint8_t
dirty
;
int32_t
pinRef
;
pg_free_list_node_t
free
;
pg_hash_list_node_t
hash
;
uint8_t
data
[];
}
pg_t
;
#define MP_PAGE_SIZE(pgsize) (sizeof(pg_t) + (pgsize))
...
...
@@ -42,33 +45,33 @@ struct TDB_MPOOL {
int64_t
cachesize
;
pgsize_t
pgsize
;
int32_t
npages
;
pg_t
*
pages
;
pg_t
*
*
pages
;
pg_list_t
freeList
;
// Hash<pgid_t, frame_id_t>
int32_t
nbucket
;
pg_list_t
*
hashtab
;
// TODO: TD_DLIST(TD_MPFILE) mpfList; // MPFILE registered on this memory pool
struct
{
int32_t
nbucket
;
pg_list_t
*
hashtab
;
}
pgtab
;
// page table, hash<pgid_t, pg_t>
};
#define MP_PAGE_AT(mp, idx) (mp)->pages[idx]
struct
TDB_MPFILE
{
uint8_t
f
uid
[
20
];
// file uniqu
e ID
TDB_MPOOL
*
mp
;
// underlying memory pool
char
*
fname
;
// file name
int
fd
;
// fd
uint8_t
f
ileid
[
TDB_FILE_ID_LEN
];
// fil
e ID
TDB_MPOOL
*
mp
;
// underlying memory pool
char
*
fname
;
// file name
int
fd
;
// fd
};
#define MP_PAGE_AT(mp, idx) ((char *)((mp)->pages) + MP_PAGE_SIZE((mp)->pgsize) * (idx))
/*=================================================== Exposed apis ==================================================*/
// TDB_MPOOL
int
tdbMPoolOpen
(
TDB_MPOOL
**
mpp
,
uint64_t
cachesize
,
pgsize_t
pgsize
);
int
tdbMPoolClose
(
TDB_MPOOL
*
mp
);
// TDB_MPFILE
int
tdbMP
F
Open
(
TDB_MPFILE
**
mpfp
,
const
char
*
fname
,
TDB_MPOOL
*
mp
);
int
tdbMP
F
Close
(
TDB_MPFILE
*
mpf
);
int
tdbMP
F
Get
(
TDB_MPFILE
*
mpf
,
pgno_t
pgid
,
void
*
addr
);
int
tdbMP
F
Put
(
TDB_MPOOL
*
mpf
,
pgno_t
pgid
,
void
*
addr
);
int
tdbMP
oolFile
Open
(
TDB_MPFILE
**
mpfp
,
const
char
*
fname
,
TDB_MPOOL
*
mp
);
int
tdbMP
oolFile
Close
(
TDB_MPFILE
*
mpf
);
int
tdbMP
oolFile
Get
(
TDB_MPFILE
*
mpf
,
pgno_t
pgid
,
void
*
addr
);
int
tdbMP
oolFile
Put
(
TDB_MPOOL
*
mpf
,
pgno_t
pgid
,
void
*
addr
);
#ifdef __cplusplus
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录