Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
0c02e112
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看板
提交
0c02e112
编写于
3月 16, 2022
作者:
H
Hongze Cheng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
more TDB
上级
16e7fa2e
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
33 addition
and
8 deletion
+33
-8
source/libs/tdb/src/db/tdbBtree.c
source/libs/tdb/src/db/tdbBtree.c
+33
-8
未找到文件。
source/libs/tdb/src/db/tdbBtree.c
浏览文件 @
0c02e112
...
...
@@ -380,11 +380,13 @@ static int tdbBtreeOpenImpl(SBTree *pBt) {
static
int
tdbBtreeInitPage
(
SPage
*
pPage
,
void
*
arg
)
{
SBTree
*
pBt
;
u16
flags
;
u8
isLeaf
;
pBt
=
(
SBTree
*
)
arg
;
flags
=
TDB_PAGE_FLAGS
(
pPage
);
if
(
TDB_BTREE_PAGE_IS_LEAF
(
flags
))
{
isLeaf
=
TDB_BTREE_PAGE_IS_LEAF
(
flags
);
if
(
isLeaf
)
{
pPage
->
szAmHdr
=
0
;
}
else
{
pPage
->
szAmHdr
=
sizeof
(
SBtPageHdr
);
...
...
@@ -399,7 +401,7 @@ static int tdbBtreeInitPage(SPage *pPage, void *arg) {
TDB_BTREE_ASSERT_FLAG
(
flags
);
// Init other fields
if
(
TDB_BTREE_PAGE_IS_LEAF
(
flags
)
)
{
if
(
isLeaf
)
{
pPage
->
kLen
=
pBt
->
keyLen
;
pPage
->
vLen
=
pBt
->
valLen
;
pPage
->
maxLocal
=
pBt
->
maxLeaf
;
...
...
@@ -450,7 +452,22 @@ typedef struct {
}
SBtreeBalanceHelper
;
static
int
tdbBtreeCopyPageContent
(
SPage
*
pFrom
,
SPage
*
pTo
)
{
/* TODO */
int
nCells
=
TDB_PAGE_NCELLS
(
pFrom
);
int
cCells
=
TDB_PAGE_CCELLS
(
pFrom
);
int
fCell
=
TDB_PAGE_FCELL
(
pFrom
);
int
nFree
=
TDB_PAGE_NFREE
(
pFrom
);
pTo
->
pFreeStart
=
pTo
->
pCellIdx
+
nCells
*
pFrom
->
szOffset
;
memcpy
(
pTo
->
pCellIdx
,
pFrom
->
pCellIdx
,
nCells
*
pFrom
->
szOffset
);
pTo
->
pFreeEnd
=
(
u8
*
)
pTo
->
pPageFtr
-
(
pFrom
->
pFreeEnd
-
(
u8
*
)(
pFrom
->
pPageFtr
));
memcpy
(
pTo
->
pFreeEnd
,
pFrom
->
pFreeEnd
,
(
pFrom
->
pFreeEnd
-
(
u8
*
)
pFrom
->
pPageFtr
));
TDB_PAGE_NCELLS_SET
(
pTo
,
nCells
);
TDB_PAGE_CCELLS_SET
(
pTo
,
cCells
);
TDB_PAGE_FCELL_SET
(
pTo
,
fCell
);
TDB_PAGE_NFREE_SET
(
pTo
,
nFree
);
// TODO: update other fields
return
0
;
}
...
...
@@ -698,11 +715,19 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx) {
static
int
tdbBtreeBalance
(
SBtCursor
*
pCur
)
{
int
iPage
;
SPage
*
pParent
;
SPage
*
pPage
;
int
ret
;
u16
flags
;
u8
leaf
;
u8
root
;
// Main loop to balance the BTree
for
(;;)
{
iPage
=
pCur
->
iPage
;
pPage
=
pCur
->
pPage
;
flags
=
TDB_PAGE_FLAGS
(
pPage
);
leaf
=
TDB_BTREE_PAGE_IS_LEAF
(
flags
);
root
=
TDB_BTREE_PAGE_IS_ROOT
(
flags
);
// TODO: Get the page free space if not get yet
// if (pPage->nFree < 0) {
...
...
@@ -711,14 +736,15 @@ static int tdbBtreeBalance(SBtCursor *pCur) {
// }
// }
if
(
0
/*TODO: balance is over*/
)
{
// If balance over, break the loop
if
(
pPage
->
nOverflow
==
0
/* TODO: && pPage->nFree <= */
)
{
break
;
}
if
(
iPage
==
0
)
{
//
Balance the root page by copy the root page content to
//
a child page and set the root page as empty first
// ASSERT(TDB_BTREE_PAGE_IS_ROOT(pCur->pPage->pPageHdr->flags))
;
//
For the root page, only balance when the page is overfull,
//
ignore the case of empty
if
(
pPage
->
nOverflow
==
0
)
break
;
ret
=
tdbBtreeBalanceDeeper
(
pCur
->
pBt
,
pCur
->
pPage
,
&
(
pCur
->
pgStack
[
1
]));
if
(
ret
<
0
)
{
...
...
@@ -730,7 +756,6 @@ static int tdbBtreeBalance(SBtCursor *pCur) {
pCur
->
pgStack
[
0
]
=
pCur
->
pPage
;
pCur
->
iPage
=
1
;
pCur
->
pPage
=
pCur
->
pgStack
[
1
];
}
else
{
// Generalized balance step
pParent
=
pCur
->
pgStack
[
pCur
->
iPage
-
1
];
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录