Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
ba4b33e7
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看板
提交
ba4b33e7
编写于
3月 31, 2022
作者:
H
Hongze Cheng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
more progress
上级
59061a6f
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
62 addition
and
33 deletion
+62
-33
source/libs/tdb/src/db/tdbBtree.c
source/libs/tdb/src/db/tdbBtree.c
+35
-14
source/libs/tdb/src/db/tdbPager.c
source/libs/tdb/src/db/tdbPager.c
+24
-18
source/libs/tdb/src/inc/tdbPage.h
source/libs/tdb/src/inc/tdbPage.h
+1
-0
source/libs/tdb/test/tdbTest.cpp
source/libs/tdb/test/tdbTest.cpp
+2
-1
未找到文件。
source/libs/tdb/src/db/tdbBtree.c
浏览文件 @
ba4b33e7
...
...
@@ -383,17 +383,7 @@ static int tdbBtreeZeroPage(SPage *pPage, void *arg) {
return
0
;
}
#ifndef TDB_BTREE_BALANCE
typedef
struct
{
SBTree
*
pBt
;
SPage
*
pParent
;
int
idx
;
i8
nOld
;
SPage
*
pOldPages
[
3
];
i8
nNewPages
;
SPage
*
pNewPages
[
5
];
}
SBtreeBalanceHelper
;
// TDB_BTREE_BALANCE =====================
static
int
tdbBtreeBalanceDeeper
(
SBTree
*
pBt
,
SPage
*
pRoot
,
SPage
**
ppChild
)
{
SPager
*
pPager
;
SPage
*
pChild
;
...
...
@@ -420,6 +410,13 @@ static int tdbBtreeBalanceDeeper(SBTree *pBt, SPage *pRoot, SPage **ppChild) {
((
SIntHdr
*
)
pChild
->
pData
)
->
pgno
=
((
SIntHdr
*
)(
pRoot
->
pData
))
->
pgno
;
}
ret
=
tdbPagerWrite
(
pPager
,
pChild
);
if
(
ret
<
0
)
{
// TODO
ASSERT
(
0
);
return
0
;
}
// Copy the root page content to the child page
tdbPageCopy
(
pRoot
,
pChild
);
...
...
@@ -497,6 +494,13 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx) {
}
if
(
i
<
nOlds
-
1
)
{
ret
=
tdbPagerWrite
(
pBt
->
pPager
,
pOlds
[
i
]);
if
(
ret
<
0
)
{
// TODO
ASSERT
(
0
);
return
-
1
;
}
((
SPgno
*
)
pDivCell
[
i
])[
0
]
=
((
SIntHdr
*
)
pOlds
[
i
]
->
pData
)
->
pgno
;
((
SIntHdr
*
)
pOlds
[
i
]
->
pData
)
->
pgno
=
0
;
tdbPageInsertCell
(
pOlds
[
i
],
TDB_PAGE_TOTAL_CELLS
(
pOlds
[
i
]),
pDivCell
[
i
],
szDivCell
[
i
],
1
);
...
...
@@ -504,6 +508,14 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx) {
}
rPgno
=
((
SIntHdr
*
)
pOlds
[
nOlds
-
1
]
->
pData
)
->
pgno
;
}
ret
=
tdbPagerWrite
(
pBt
->
pPager
,
pParent
);
if
(
ret
<
0
)
{
// TODO
ASSERT
(
0
);
return
-
1
;
}
// drop the cells on parent page
for
(
int
i
=
0
;
i
<
nOlds
;
i
++
)
{
nCells
=
TDB_PAGE_TOTAL_CELLS
(
pParent
);
...
...
@@ -631,6 +643,13 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx) {
if
(
ret
<
0
)
{
ASSERT
(
0
);
}
ret
=
tdbPagerWrite
(
pBt
->
pPager
,
pNews
[
iNew
]);
if
(
ret
<
0
)
{
// TODO
ASSERT
(
0
);
return
-
1
;
}
}
}
...
...
@@ -749,9 +768,10 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx) {
static
int
tdbBtreeBalance
(
SBTC
*
pBtc
)
{
int
iPage
;
int
ret
;
int
nFree
;
SPage
*
pParent
;
SPage
*
pPage
;
int
ret
;
u8
flags
;
u8
leaf
;
u8
root
;
...
...
@@ -762,10 +782,11 @@ static int tdbBtreeBalance(SBTC *pBtc) {
pPage
=
pBtc
->
pPage
;
leaf
=
TDB_BTREE_PAGE_IS_LEAF
(
pPage
);
root
=
TDB_BTREE_PAGE_IS_ROOT
(
pPage
);
nFree
=
TDB_PAGE_FREE_SIZE
(
pPage
);
// when the page is not overflow and not too empty, the balance work
// is finished. Just break out the balance loop.
if
(
pPage
->
nOverflow
==
0
/* TODO: && pPage->nFree <= */
)
{
if
(
pPage
->
nOverflow
==
0
&&
nFree
<
TDB_PAGE_USABLE_SIZE
(
pPage
)
*
2
/
3
)
{
break
;
}
...
...
@@ -800,7 +821,7 @@ static int tdbBtreeBalance(SBTC *pBtc) {
return
0
;
}
#endif
// TDB_BTREE_BALANCE
// TDB_BTREE_CELL =====================
static
int
tdbBtreeEncodePayload
(
SPage
*
pPage
,
SCell
*
pCell
,
int
nHeader
,
const
void
*
pKey
,
int
kLen
,
const
void
*
pVal
,
...
...
source/libs/tdb/src/db/tdbPager.c
浏览文件 @
ba4b33e7
...
...
@@ -117,14 +117,18 @@ int tdbPagerOpenDB(SPager *pPager, SPgno *ppgno, bool toCreate) {
}
int
tdbPagerWrite
(
SPager
*
pPager
,
SPage
*
pPage
)
{
int
ret
;
int
ret
;
SPage
**
ppPage
;
ASSERT
(
pPager
->
inTran
);
#if 0
if (pPager->inTran == 0) {
ret = tdbPagerBegin(pPager);
if (ret < 0) {
return -1;
}
}
#endif
if
(
pPage
->
isDirty
)
return
0
;
...
...
@@ -132,11 +136,14 @@ int tdbPagerWrite(SPager *pPager, SPage *pPage) {
pPage
->
isDirty
=
1
;
// Add page to dirty list
// TODO: sort the list according to the page number
pPage
->
pDirtyNext
=
pPager
->
pDirty
;
pPager
->
pDirty
=
pPage
;
for
(
ppPage
=
&
pPager
->
pDirty
;
(
*
ppPage
)
&&
TDB_PAGE_PGNO
(
*
ppPage
)
<
TDB_PAGE_PGNO
(
pPage
);
ppPage
=
&
((
*
ppPage
)
->
pDirtyNext
))
{
}
ASSERT
(
*
ppPage
==
NULL
||
TDB_PAGE_PGNO
(
*
ppPage
)
>
TDB_PAGE_PGNO
(
pPage
));
pPage
->
pDirtyNext
=
*
ppPage
;
*
ppPage
=
pPage
;
// Write page to journal
// Write page to journal
if neccessary
if
(
TDB_PAGE_PGNO
(
pPage
)
<=
pPager
->
dbOrigSize
)
{
ret
=
tdbPagerWritePageToJournal
(
pPager
,
pPage
);
if
(
ret
<
0
)
{
...
...
@@ -170,30 +177,29 @@ int tdbPagerCommit(SPager *pPager) {
SPage
*
pPage
;
int
ret
;
// Begin commit
{
// TODO: Sync the journal file (Here or when write ?)
// sync the journal file
ret
=
tdbOsFSync
(
pPager
->
jfd
);
if
(
ret
<
0
)
{
// TODO
ASSERT
(
0
);
return
0
;
}
for
(;;)
{
pPage
=
pPager
->
pDirty
;
if
(
pPage
==
NULL
)
break
;
// loop to write the dirty pages to file
for
(
pPage
=
pPager
->
pDirty
;
pPage
;
pPage
=
pPage
->
pDirtyNext
)
{
ret
=
tdbPagerWritePageToDB
(
pPager
,
pPage
);
if
(
ret
<
0
)
{
ASSERT
(
0
);
return
-
1
;
}
pPager
->
pDirty
=
pPage
->
pDirtyNext
;
pPage
->
pDirtyNext
=
NULL
;
// TODO: release the page
}
// TODO: loop to release the dirty pages
// sync the db file
tdbOsFSync
(
pPager
->
fd
);
// remote the journal file
tdbOsClose
(
pPager
->
jfd
);
tdbOsRemove
(
pPager
->
jFileName
);
...
...
source/libs/tdb/src/inc/tdbPage.h
浏览文件 @
ba4b33e7
...
...
@@ -100,6 +100,7 @@ struct SPage {
// APIs
#define TDB_PAGE_TOTAL_CELLS(pPage) ((pPage)->nOverflow + (pPage)->pPageMethods->getCellNum(pPage))
#define TDB_PAGE_USABLE_SIZE(pPage) ((u8 *)(pPage)->pPageFtr - (pPage)->pCellIdx)
#define TDB_PAGE_FREE_SIZE(pPage) (*(pPage)->pPageMethods->getFreeBytes)(pPage)
#define TDB_PAGE_PGNO(pPage) ((pPage)->pgid.pgno)
#define TDB_BYTES_CELL_TAKEN(pPage, pCell) ((*(pPage)->xCellSize)(pPage, pCell) + (pPage)->pPageMethods->szOffset)
#define TDB_PAGE_OFFSET_SIZE(pPage) ((pPage)->pPageMethods->szOffset)
...
...
source/libs/tdb/test/tdbTest.cpp
浏览文件 @
ba4b33e7
...
...
@@ -134,8 +134,9 @@ TEST(tdb_test, simple_test) {
char
val
[
64
];
{
// Insert some data
int
i
=
1
;
tdbBegin
(
pEnv
)
;
int
i
=
1
;
for
(;;)
{
if
(
i
>
nData
)
break
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录