Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
7ce98762
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看板
未验证
提交
7ce98762
编写于
9月 13, 2022
作者:
H
Hongze Cheng
提交者:
GitHub
9月 13, 2022
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #16782 from taosdata/fix/TD-19055
fix(tdb): use rbtree with dirty pages' list
上级
2f905064
508c7abb
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
55 addition
and
7 deletion
+55
-7
source/libs/tdb/src/db/tdbPager.c
source/libs/tdb/src/db/tdbPager.c
+50
-5
source/libs/tdb/src/inc/tdbInt.h
source/libs/tdb/src/inc/tdbInt.h
+5
-2
未找到文件。
source/libs/tdb/src/db/tdbPager.c
浏览文件 @
7ce98762
...
...
@@ -34,6 +34,22 @@ static int tdbPagerInitPage(SPager *pPager, SPage *pPage, int (*initPage)(SPage
static
int
tdbPagerWritePageToJournal
(
SPager
*
pPager
,
SPage
*
pPage
);
static
int
tdbPagerWritePageToDB
(
SPager
*
pPager
,
SPage
*
pPage
);
static
FORCE_INLINE
int32_t
pageCmpFn
(
const
void
*
lhs
,
const
void
*
rhs
)
{
SPage
*
pPageL
=
(
SPage
*
)(((
uint8_t
*
)
lhs
)
-
sizeof
(
SRBTreeNode
));
SPage
*
pPageR
=
(
SPage
*
)(((
uint8_t
*
)
rhs
)
-
sizeof
(
SRBTreeNode
));
SPgno
pgnoL
=
TDB_PAGE_PGNO
(
pPageL
);
SPgno
pgnoR
=
TDB_PAGE_PGNO
(
pPageR
);
if
(
pgnoL
<
pgnoR
)
{
return
-
1
;
}
else
if
(
pgnoL
>
pgnoR
)
{
return
1
;
}
else
{
return
0
;
}
}
int
tdbPagerOpen
(
SPCache
*
pCache
,
const
char
*
fileName
,
SPager
**
ppPager
)
{
uint8_t
*
pPtr
;
SPager
*
pPager
;
...
...
@@ -83,6 +99,8 @@ int tdbPagerOpen(SPCache *pCache, const char *fileName, SPager **ppPager) {
ret
=
tdbGetFileSize
(
pPager
->
fd
,
pPager
->
pageSize
,
&
(
pPager
->
dbOrigSize
));
pPager
->
dbFileSize
=
pPager
->
dbOrigSize
;
tRBTreeCreate
(
&
pPager
->
rbt
,
pageCmpFn
);
*
ppPager
=
pPager
;
return
0
;
}
...
...
@@ -167,7 +185,7 @@ int tdbPagerWrite(SPager *pPager, SPage *pPage) {
// ref page one more time so the page will not be release
tdbRefPage
(
pPage
);
tdbDebug
(
"pcache/mdirty page %p/%d/%d"
,
pPage
,
TDB_PAGE_PGNO
(
pPage
),
pPage
->
id
);
/*
// Set page as dirty
pPage->isDirty = 1;
...
...
@@ -185,6 +203,8 @@ int tdbPagerWrite(SPager *pPager, SPage *pPage) {
ASSERT(*ppPage == NULL || TDB_PAGE_PGNO(*ppPage) > TDB_PAGE_PGNO(pPage));
pPage->pDirtyNext = *ppPage;
*ppPage = pPage;
*/
tRBTreePut
(
&
pPager
->
rbt
,
(
SRBTreeNode
*
)
pPage
);
// Write page to journal if neccessary
if
(
TDB_PAGE_PGNO
(
pPage
)
<=
pPager
->
dbOrigSize
)
{
...
...
@@ -228,6 +248,23 @@ int tdbPagerCommit(SPager *pPager, TXN *pTxn) {
return
0
;
}
SRBTreeIter
iter
=
tRBTreeIterCreate
(
&
pPager
->
rbt
,
1
);
SRBTreeNode
*
pNode
=
NULL
;
while
((
pNode
=
tRBTreeIterNext
(
&
iter
))
!=
NULL
)
{
pPage
=
(
SPage
*
)
pNode
;
ret
=
tdbPagerWritePageToDB
(
pPager
,
pPage
);
if
(
ret
<
0
)
{
ASSERT
(
0
);
return
-
1
;
}
pPage
->
isDirty
=
0
;
tdbPCacheRelease
(
pPager
->
pCache
,
pPage
,
pTxn
);
}
tRBTreeCreate
(
&
pPager
->
rbt
,
pageCmpFn
);
/*
// loop to write the dirty pages to file
for (pPage = pPager->pDirty; pPage; pPage = pPage->pDirtyNext) {
// TODO: update the page footer
...
...
@@ -238,9 +275,6 @@ int tdbPagerCommit(SPager *pPager, TXN *pTxn) {
}
}
tdbTrace
(
"tdbttl commit:%p, %d"
,
pPager
,
pPager
->
dbOrigSize
);
pPager
->
dbOrigSize
=
pPager
->
dbFileSize
;
// release the page
for (pPage = pPager->pDirty; pPage; pPage = pPager->pDirty) {
pPager->pDirty = pPage->pDirtyNext;
...
...
@@ -250,6 +284,9 @@ int tdbPagerCommit(SPager *pPager, TXN *pTxn) {
tdbPCacheRelease(pPager->pCache, pPage, pTxn);
}
*/
tdbTrace
(
"tdbttl commit:%p, %d"
,
pPager
,
pPager
->
dbOrigSize
);
pPager
->
dbOrigSize
=
pPager
->
dbFileSize
;
// sync the db file
tdbOsFSync
(
pPager
->
fd
);
...
...
@@ -497,7 +534,14 @@ static int tdbPagerWritePageToJournal(SPager *pPager, SPage *pPage) {
return
0
;
}
/*
struct TdFile {
TdThreadRwlock rwlock;
int refId;
int fd;
FILE *fp;
} TdFile;
*/
static
int
tdbPagerWritePageToDB
(
SPager
*
pPager
,
SPage
*
pPage
)
{
i64
offset
;
int
ret
;
...
...
@@ -514,6 +558,7 @@ static int tdbPagerWritePageToDB(SPager *pPager, SPage *pPage) {
return
-
1
;
}
// pwrite(pPager->fd->fd, pPage->pData, pPage->pageSize, offset);
return
0
;
}
...
...
source/libs/tdb/src/inc/tdbInt.h
浏览文件 @
7ce98762
...
...
@@ -19,6 +19,7 @@
#include "tdb.h"
#include "tlog.h"
#include "trbtree.h"
#ifdef __cplusplus
extern
"C"
{
...
...
@@ -256,6 +257,7 @@ typedef struct {
#pragma pack(pop)
struct
SPage
{
SRBTreeNode
node
;
// must be the first field for pageCmpFn to work
tdb_spinlock_t
lock
;
int
pageSize
;
u8
*
pData
;
...
...
@@ -280,13 +282,13 @@ struct SPage {
static
inline
i32
tdbRefPage
(
SPage
*
pPage
)
{
i32
nRef
=
atomic_add_fetch_32
(
&
((
pPage
)
->
nRef
),
1
);
tdbTrace
(
"ref page %p/%d, nRef %d"
,
pPage
,
pPage
->
id
,
nRef
);
//
tdbTrace("ref page %p/%d, nRef %d", pPage, pPage->id, nRef);
return
nRef
;
}
static
inline
i32
tdbUnrefPage
(
SPage
*
pPage
)
{
i32
nRef
=
atomic_sub_fetch_32
(
&
((
pPage
)
->
nRef
),
1
);
tdbTrace
(
"unref page %p/%d, nRef %d"
,
pPage
,
pPage
->
id
,
nRef
);
//
tdbTrace("unref page %p/%d, nRef %d", pPage, pPage->id, nRef);
return
nRef
;
}
...
...
@@ -389,6 +391,7 @@ struct SPager {
SPgno
dbFileSize
;
SPgno
dbOrigSize
;
SPage
*
pDirty
;
SRBTree
rbt
;
u8
inTran
;
SPager
*
pNext
;
// used by TDB
SPager
*
pHashNext
;
// used by TDB
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录