Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
a9eeafe3
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
a9eeafe3
编写于
1月 20, 2022
作者:
H
Hongze Cheng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
more tdb
上级
c50b787f
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
126 addition
and
50 deletion
+126
-50
include/util/tlist.h
include/util/tlist.h
+26
-26
source/libs/tdb/src/db/tdb_mpool.c
source/libs/tdb/src/db/tdb_mpool.c
+78
-7
source/libs/tdb/src/inc/tdb_mpool.h
source/libs/tdb/src/inc/tdb_mpool.h
+22
-17
未找到文件。
include/util/tlist.h
浏览文件 @
a9eeafe3
...
@@ -34,7 +34,7 @@ extern "C" {
...
@@ -34,7 +34,7 @@ extern "C" {
#define TD_SLIST_HEAD(sl) ((sl)->sl_head_)
#define TD_SLIST_HEAD(sl) ((sl)->sl_head_)
#define TD_SLIST_NELES(sl) ((sl)->sl_neles_)
#define TD_SLIST_NELES(sl) ((sl)->sl_neles_)
#define TD_SLIST_NODE_NEXT(sln) ((sln)->sl_next_)
#define TD_SLIST_NODE_NEXT(sln) ((sln)->sl_next_)
#define TD_SLIST_NODE_NEXT_WITH_FIELD(sln, f
eild) ((sln)->fei
ld.sl_next_)
#define TD_SLIST_NODE_NEXT_WITH_FIELD(sln, f
ield) ((sln)->fie
ld.sl_next_)
#define TD_SLIST_INIT(sl) \
#define TD_SLIST_INIT(sl) \
do { \
do { \
...
@@ -49,9 +49,9 @@ extern "C" {
...
@@ -49,9 +49,9 @@ extern "C" {
TD_SLIST_NELES(sl) += 1; \
TD_SLIST_NELES(sl) += 1; \
} while (0)
} while (0)
#define TD_SLIST_PUSH_WITH_FIELD(sl, sln, f
ei
ld) \
#define TD_SLIST_PUSH_WITH_FIELD(sl, sln, f
ie
ld) \
do { \
do { \
TD_SLIST_NODE_NEXT_WITH_FIELD(sln, f
ei
ld) = TD_SLIST_HEAD(sl); \
TD_SLIST_NODE_NEXT_WITH_FIELD(sln, f
ie
ld) = TD_SLIST_HEAD(sl); \
TD_SLIST_HEAD(sl) = (sln); \
TD_SLIST_HEAD(sl) = (sln); \
TD_SLIST_NELES(sl) += 1; \
TD_SLIST_NELES(sl) += 1; \
} while (0)
} while (0)
...
@@ -62,9 +62,9 @@ extern "C" {
...
@@ -62,9 +62,9 @@ extern "C" {
TD_SLIST_NELES(sl) -= 1; \
TD_SLIST_NELES(sl) -= 1; \
} while (0)
} while (0)
#define TD_SLIST_POP_WITH_FIELD(sl, f
ei
ld) \
#define TD_SLIST_POP_WITH_FIELD(sl, f
ie
ld) \
do { \
do { \
TD_SLIST_HEAD(sl) = TD_SLIST_NODE_NEXT_WITH_FIELD(TD_SLIST_HEAD(sl), f
ei
ld); \
TD_SLIST_HEAD(sl) = TD_SLIST_NODE_NEXT_WITH_FIELD(TD_SLIST_HEAD(sl), f
ie
ld); \
TD_SLIST_NELES(sl) -= 1; \
TD_SLIST_NELES(sl) -= 1; \
} while (0)
} while (0)
...
@@ -84,8 +84,8 @@ extern "C" {
...
@@ -84,8 +84,8 @@ extern "C" {
#define TD_DLIST_NODE_PREV(dln) ((dln)->dl_prev_)
#define TD_DLIST_NODE_PREV(dln) ((dln)->dl_prev_)
#define TD_DLIST_NODE_NEXT(dln) ((dln)->dl_next_)
#define TD_DLIST_NODE_NEXT(dln) ((dln)->dl_next_)
#define TD_DLIST_NODE_PREV_WITH_FIELD(dln, f
eild) ((dln)->fei
ld.dl_prev_)
#define TD_DLIST_NODE_PREV_WITH_FIELD(dln, f
ield) ((dln)->fie
ld.dl_prev_)
#define TD_DLIST_NODE_NEXT_WITH_FIELD(dln, f
eild) ((dln)->fei
ld.dl_next_)
#define TD_DLIST_NODE_NEXT_WITH_FIELD(dln, f
ield) ((dln)->fie
ld.dl_next_)
#define TD_DLIST_HEAD(dl) ((dl)->dl_head_)
#define TD_DLIST_HEAD(dl) ((dl)->dl_head_)
#define TD_DLIST_TAIL(dl) ((dl)->dl_tail_)
#define TD_DLIST_TAIL(dl) ((dl)->dl_tail_)
#define TD_DLIST_NELES(dl) ((dl)->dl_neles_)
#define TD_DLIST_NELES(dl) ((dl)->dl_neles_)
...
@@ -110,15 +110,15 @@ extern "C" {
...
@@ -110,15 +110,15 @@ extern "C" {
TD_DLIST_NELES(dl) += 1; \
TD_DLIST_NELES(dl) += 1; \
} while (0)
} while (0)
#define TD_DLIST_APPEND_WITH_F
EILD(dl, dln, fei
ld) \
#define TD_DLIST_APPEND_WITH_F
IELD(dl, dln, fie
ld) \
do { \
do { \
if (TD_DLIST_HEAD(dl) == NULL) { \
if (TD_DLIST_HEAD(dl) == NULL) { \
TD_DLIST_NODE_PREV_WITH_FIELD(dln, f
eild) = TD_DLIST_NODE_NEXT_WITH_FIELD(dln, fei
ld) = NULL; \
TD_DLIST_NODE_PREV_WITH_FIELD(dln, f
ield) = TD_DLIST_NODE_NEXT_WITH_FIELD(dln, fie
ld) = NULL; \
TD_DLIST_HEAD(dl) = TD_DLIST_TAIL(dl) = (dln); \
TD_DLIST_HEAD(dl) = TD_DLIST_TAIL(dl) = (dln); \
} else { \
} else { \
TD_DLIST_NODE_PREV_WITH_FIELD(dln, f
ei
ld) = TD_DLIST_TAIL(dl); \
TD_DLIST_NODE_PREV_WITH_FIELD(dln, f
ie
ld) = TD_DLIST_TAIL(dl); \
TD_DLIST_NODE_NEXT_WITH_FIELD(dln, f
ei
ld) = NULL; \
TD_DLIST_NODE_NEXT_WITH_FIELD(dln, f
ie
ld) = NULL; \
TD_DLIST_NODE_NEXT_WITH_FIELD(TD_DLIST_TAIL(dl), f
ei
ld) = (dln); \
TD_DLIST_NODE_NEXT_WITH_FIELD(TD_DLIST_TAIL(dl), f
ie
ld) = (dln); \
TD_DLIST_TAIL(dl) = (dln); \
TD_DLIST_TAIL(dl) = (dln); \
} \
} \
TD_DLIST_NELES(dl) += 1; \
TD_DLIST_NELES(dl) += 1; \
...
@@ -138,15 +138,15 @@ extern "C" {
...
@@ -138,15 +138,15 @@ extern "C" {
TD_DLIST_NELES(dl) += 1; \
TD_DLIST_NELES(dl) += 1; \
} while (0)
} while (0)
#define TD_DLIST_PREPEND_WITH_FIELD(dl, dln, f
ei
ld) \
#define TD_DLIST_PREPEND_WITH_FIELD(dl, dln, f
ie
ld) \
do { \
do { \
if (TD_DLIST_HEAD(dl) == NULL) { \
if (TD_DLIST_HEAD(dl) == NULL) { \
TD_DLIST_NODE_PREV_WITH_FIELD(dln, f
eild) = TD_DLIST_NODE_NEXT_WITH_FIELD(dln, fei
ld) = NULL; \
TD_DLIST_NODE_PREV_WITH_FIELD(dln, f
ield) = TD_DLIST_NODE_NEXT_WITH_FIELD(dln, fie
ld) = NULL; \
TD_DLIST_HEAD(dl) = TD_DLIST_TAIL(dl) = (dln); \
TD_DLIST_HEAD(dl) = TD_DLIST_TAIL(dl) = (dln); \
} else { \
} else { \
TD_DLIST_NODE_PREV_WITH_FIELD(dln, f
ei
ld) = NULL; \
TD_DLIST_NODE_PREV_WITH_FIELD(dln, f
ie
ld) = NULL; \
TD_DLIST_NODE_NEXT_WITH_FIELD(dln, f
ei
ld) = TD_DLIST_HEAD(dl); \
TD_DLIST_NODE_NEXT_WITH_FIELD(dln, f
ie
ld) = TD_DLIST_HEAD(dl); \
TD_DLIST_NODE_PREV_WITH_FIELD(TD_DLIST_HEAD(dl), f
ei
ld) = (dln); \
TD_DLIST_NODE_PREV_WITH_FIELD(TD_DLIST_HEAD(dl), f
ie
ld) = (dln); \
TD_DLIST_HEAD(dl) = (dln); \
TD_DLIST_HEAD(dl) = (dln); \
} \
} \
TD_DLIST_NELES(dl) += 1; \
TD_DLIST_NELES(dl) += 1; \
...
@@ -173,21 +173,21 @@ extern "C" {
...
@@ -173,21 +173,21 @@ extern "C" {
#define TD_DLIST_POP_WITH_FIELD(dl, dln, field) \
#define TD_DLIST_POP_WITH_FIELD(dl, dln, field) \
do { \
do { \
if (TD_DLIST_HEAD(dl) == (dln)) { \
if (TD_DLIST_HEAD(dl) == (dln)) { \
TD_DLIST_HEAD(dl) = TD_DLIST_NODE_NEXT_WITH_FIELD(dln, f
ei
ld); \
TD_DLIST_HEAD(dl) = TD_DLIST_NODE_NEXT_WITH_FIELD(dln, f
ie
ld); \
} \
} \
if (TD_DLIST_TAIL(dl) == (dln)) { \
if (TD_DLIST_TAIL(dl) == (dln)) { \
TD_DLIST_TAIL(dl) = TD_DLIST_NODE_PREV_WITH_FIELD(dln, f
ei
ld); \
TD_DLIST_TAIL(dl) = TD_DLIST_NODE_PREV_WITH_FIELD(dln, f
ie
ld); \
} \
} \
if (TD_DLIST_NODE_PREV_WITH_FIELD(dln, f
ei
ld) != NULL) { \
if (TD_DLIST_NODE_PREV_WITH_FIELD(dln, f
ie
ld) != NULL) { \
TD_DLIST_NODE_NEXT_WITH_FIELD(TD_DLIST_NODE_PREV_WITH_FIELD(dln, f
eild), fei
ld) = \
TD_DLIST_NODE_NEXT_WITH_FIELD(TD_DLIST_NODE_PREV_WITH_FIELD(dln, f
ield), fie
ld) = \
TD_DLIST_NODE_NEXT_WITH_FIELD(dln, f
ei
ld); \
TD_DLIST_NODE_NEXT_WITH_FIELD(dln, f
ie
ld); \
} \
} \
if (TD_DLIST_NODE_NEXT_WITH_FIELD(dln, f
ei
ld) != NULL) { \
if (TD_DLIST_NODE_NEXT_WITH_FIELD(dln, f
ie
ld) != NULL) { \
TD_DLIST_NODE_PREV_WITH_FIELD(TD_DLIST_NODE_NEXT_WITH_FIELD(dln, f
eild), fei
ld) = \
TD_DLIST_NODE_PREV_WITH_FIELD(TD_DLIST_NODE_NEXT_WITH_FIELD(dln, f
ield), fie
ld) = \
TD_DLIST_NODE_PREV_WITH_FIELD(dln, f
ei
ld); \
TD_DLIST_NODE_PREV_WITH_FIELD(dln, f
ie
ld); \
} \
} \
TD_DLIST_NELES(dl) -= 1; \
TD_DLIST_NELES(dl) -= 1; \
TD_DLIST_NODE_PREV_WITH_FIELD(dln, f
eild) = TD_DLIST_NODE_NEXT_WITH_FIELD(dln, fei
ld) = NULL; \
TD_DLIST_NODE_PREV_WITH_FIELD(dln, f
ield) = TD_DLIST_NODE_NEXT_WITH_FIELD(dln, fie
ld) = NULL; \
} while (0)
} while (0)
// General double linked list
// General double linked list
...
...
source/libs/tdb/src/db/tdb_mpool.c
浏览文件 @
a9eeafe3
...
@@ -15,8 +15,10 @@
...
@@ -15,8 +15,10 @@
#include "tdb_mpool.h"
#include "tdb_mpool.h"
static
int
tdbGnrtFileID
(
const
char
*
fname
,
uint8_t
*
fileid
);
static
int
tdbGnrtFileID
(
const
char
*
fname
,
uint8_t
*
fileid
);
static
void
tdbMpoolRegFile
(
TDB_MPOOL
*
mp
,
TDB_MPFILE
*
mpf
);
static
void
tdbMPoolRegFile
(
TDB_MPOOL
*
mp
,
TDB_MPFILE
*
mpf
);
static
void
tdbMPoolUnregFile
(
TDB_MPOOL
*
mp
,
TDB_MPFILE
*
mpf
);
static
TDB_MPFILE
*
tdbMPoolGetFile
(
TDB_MPOOL
*
mp
,
uint8_t
*
fileid
);
int
tdbMPoolOpen
(
TDB_MPOOL
**
mpp
,
uint64_t
cachesize
,
pgsize_t
pgsize
)
{
int
tdbMPoolOpen
(
TDB_MPOOL
**
mpp
,
uint64_t
cachesize
,
pgsize_t
pgsize
)
{
TDB_MPOOL
*
mp
=
NULL
;
TDB_MPOOL
*
mp
=
NULL
;
...
@@ -60,7 +62,7 @@ int tdbMPoolOpen(TDB_MPOOL **mpp, uint64_t cachesize, pgsize_t pgsize) {
...
@@ -60,7 +62,7 @@ int tdbMPoolOpen(TDB_MPOOL **mpp, uint64_t cachesize, pgsize_t pgsize) {
mp
->
pages
[
i
]
->
pgid
=
TDB_IVLD_PGID
;
mp
->
pages
[
i
]
->
pgid
=
TDB_IVLD_PGID
;
// add new page to the free list
// add new page to the free list
TD_DLIST_APPEND_WITH_F
EI
LD
(
&
(
mp
->
freeList
),
mp
->
pages
[
i
],
free
);
TD_DLIST_APPEND_WITH_F
IE
LD
(
&
(
mp
->
freeList
),
mp
->
pages
[
i
],
free
);
}
}
#define PGTAB_FACTOR 1.0
#define PGTAB_FACTOR 1.0
...
@@ -105,7 +107,6 @@ int tdbMPoolFileOpen(TDB_MPFILE **mpfp, const char *fname, TDB_MPOOL *mp) {
...
@@ -105,7 +107,6 @@ int tdbMPoolFileOpen(TDB_MPFILE **mpfp, const char *fname, TDB_MPOOL *mp) {
}
}
mpf
->
fd
=
-
1
;
mpf
->
fd
=
-
1
;
mpf
->
mp
=
mp
;
if
((
mpf
->
fname
=
strdup
(
fname
))
==
NULL
)
{
if
((
mpf
->
fname
=
strdup
(
fname
))
==
NULL
)
{
goto
_err
;
goto
_err
;
...
@@ -120,7 +121,7 @@ int tdbMPoolFileOpen(TDB_MPFILE **mpfp, const char *fname, TDB_MPOOL *mp) {
...
@@ -120,7 +121,7 @@ int tdbMPoolFileOpen(TDB_MPFILE **mpfp, const char *fname, TDB_MPOOL *mp) {
}
}
// Register current MPF to MP
// Register current MPF to MP
tdbM
p
oolRegFile
(
mp
,
mpf
);
tdbM
P
oolRegFile
(
mp
,
mpf
);
*
mpfp
=
mpf
;
*
mpfp
=
mpf
;
return
0
;
return
0
;
...
@@ -193,6 +194,76 @@ static int tdbGnrtFileID(const char *fname, uint8_t *fileid) {
...
@@ -193,6 +194,76 @@ static int tdbGnrtFileID(const char *fname, uint8_t *fileid) {
return
0
;
return
0
;
}
}
static
void
tdbMpoolRegFile
(
TDB_MPOOL
*
mp
,
TDB_MPFILE
*
mpf
)
{
#define MPF_GET_BUCKETID(fileid) \
// TODO
({ \
uint64_t *tmp = fileid; \
(tmp[0] + tmp[1] + tmp[2]) % MPF_HASH_BUCKETS; \
})
static
void
tdbMPoolRegFile
(
TDB_MPOOL
*
mp
,
TDB_MPFILE
*
mpf
)
{
int
bucketid
;
mpf_bucket_t
*
bktp
;
bucketid
=
MPF_GET_BUCKETID
(
mpf
->
fileid
);
bktp
=
mp
->
mpfht
.
buckets
+
bucketid
;
taosWLockLatch
(
&
(
bktp
->
latch
));
TD_DLIST_APPEND_WITH_FIELD
(
bktp
,
mpf
,
node
);
taosWUnLockLatch
(
&
(
bktp
->
latch
));
mpf
->
mp
=
mp
;
}
static
TDB_MPFILE
*
tdbMPoolGetFile
(
TDB_MPOOL
*
mp
,
uint8_t
*
fileid
)
{
int
bucketid
;
TDB_MPFILE
*
mpf
=
NULL
;
mpf_bucket_t
*
bktp
;
bucketid
=
MPF_GET_BUCKETID
(
fileid
);
bktp
=
mp
->
mpfht
.
buckets
+
bucketid
;
taosRLockLatch
(
&
(
bktp
->
latch
));
mpf
=
TD_DLIST_HEAD
(
bktp
);
while
(
mpf
)
{
if
(
memcmp
(
fileid
,
mpf
->
fileid
,
TDB_FILE_ID_LEN
)
==
0
)
{
break
;
}
mpf
=
TD_DLIST_NODE_NEXT_WITH_FIELD
(
mpf
,
node
);
}
taosRUnLockLatch
(
&
(
bktp
->
latch
));
return
mpf
;
}
static
void
tdbMPoolUnregFile
(
TDB_MPOOL
*
mp
,
TDB_MPFILE
*
mpf
)
{
mpf_bucket_t
*
bktp
;
TDB_MPFILE
*
tmpf
;
if
(
mpf
->
mp
==
NULL
)
return
;
ASSERT
(
mpf
->
mp
==
mp
);
bktp
=
mp
->
mpfht
.
buckets
+
MPF_GET_BUCKETID
(
mpf
->
fileid
);
taosWLockLatch
(
&
(
bktp
->
latch
));
tmpf
=
TD_DLIST_HEAD
(
bktp
);
while
(
tmpf
)
{
if
(
memcmp
(
mpf
->
fileid
,
tmpf
->
fileid
,
TDB_FILE_ID_LEN
)
==
0
)
{
TD_DLIST_POP_WITH_FIELD
(
bktp
,
tmpf
,
node
);
break
;
}
tmpf
=
TD_DLIST_NODE_NEXT_WITH_FIELD
(
tmpf
,
node
);
}
taosWUnLockLatch
(
&
(
bktp
->
latch
));
ASSERT
(
tmpf
==
mpf
);
}
}
\ No newline at end of file
source/libs/tdb/src/inc/tdb_mpool.h
浏览文件 @
a9eeafe3
...
@@ -26,21 +26,25 @@ extern "C" {
...
@@ -26,21 +26,25 @@ extern "C" {
typedef
struct
TDB_MPOOL
TDB_MPOOL
;
typedef
struct
TDB_MPOOL
TDB_MPOOL
;
typedef
struct
TDB_MPFILE
TDB_MPFILE
;
typedef
struct
TDB_MPFILE
TDB_MPFILE
;
typedef
TD_DLIST_NODE
(
pg_t
)
pg_free_
list_node_t
,
pg_hash_
list_node_t
;
typedef
TD_DLIST_NODE
(
pg_t
)
pg_free_
dlist_node_t
,
pg_hash_d
list_node_t
;
typedef
struct
pg_t
{
typedef
struct
pg_t
{
SRWLatch
rwLatch
;
SRWLatch
rwLatch
;
frame_id_t
frameid
;
frame_id_t
frameid
;
pgid_t
pgid
;
pgid_t
pgid
;
uint8_t
dirty
;
uint8_t
dirty
;
int32_t
pinRef
;
int32_t
pinRef
;
pg_free_list_node_t
free
;
pg_free_
d
list_node_t
free
;
pg_hash_list_node_t
hash
;
pg_hash_
d
list_node_t
hash
;
uint8_t
data
[];
uint8_t
data
[];
}
pg_t
;
}
pg_t
;
#define MP_PAGE_SIZE(pgsize) (sizeof(pg_t) + (pgsize))
#define MP_PAGE_SIZE(pgsize) (sizeof(pg_t) + (pgsize))
typedef
TD_DLIST
(
pg_t
)
pg_list_t
;
typedef
TD_DLIST
(
pg_t
)
pg_list_t
;
typedef
struct
{
SRWLatch
latch
;
TD_DLIST
(
TDB_MPFILE
);
}
mpf_bucket_t
;
struct
TDB_MPOOL
{
struct
TDB_MPOOL
{
int64_t
cachesize
;
int64_t
cachesize
;
pgsize_t
pgsize
;
pgsize_t
pgsize
;
...
@@ -52,19 +56,20 @@ struct TDB_MPOOL {
...
@@ -52,19 +56,20 @@ struct TDB_MPOOL {
pg_list_t
*
hashtab
;
pg_list_t
*
hashtab
;
}
pgtab
;
// page table, hash<pgid_t, pg_t>
}
pgtab
;
// page table, hash<pgid_t, pg_t>
struct
{
struct
{
int32_t
nbucket
;
#define MPF_HASH_BUCKETS 16
TD_DLIST
(
TDB_MPFILE
)
hashtab
[
8
];
mpf_bucket_t
buckets
[
MPF_HASH_BUCKETS
];
}
mpf
tab
;
}
mpf
ht
;
// MPF hash table. MPFs using this MP will be put in this hash table
};
};
#define MP_PAGE_AT(mp, idx) (mp)->pages[idx]
#define MP_PAGE_AT(mp, idx) (mp)->pages[idx]
typedef
TD_DLIST_NODE
(
TDB_MPFILE
)
td_mpf_dlist_node_t
;
struct
TDB_MPFILE
{
struct
TDB_MPFILE
{
char
*
fname
;
// file name
char
*
fname
;
// file name
int
fd
;
// fd
int
fd
;
// fd
uint8_t
fileid
[
TDB_FILE_ID_LEN
];
// file ID
uint8_t
fileid
[
TDB_FILE_ID_LEN
];
// file ID
TDB_MPOOL
*
mp
;
// underlying memory pool
TDB_MPOOL
*
mp
;
// underlying memory pool
TD_DLIST_NODE
(
TDB_MPFILE
)
;
td_mpf_dlist_node_t
node
;
};
};
/*=================================================== Exposed apis ==================================================*/
/*=================================================== Exposed apis ==================================================*/
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录