Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
e2f1434b
T
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1187
Star
22018
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看板
提交
e2f1434b
编写于
3月 22, 2022
作者:
H
Hongze Cheng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
more TDB
上级
92500477
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
34 addition
and
74 deletion
+34
-74
source/libs/tdb/src/db/tdbBtree.c
source/libs/tdb/src/db/tdbBtree.c
+34
-74
未找到文件。
source/libs/tdb/src/db/tdbBtree.c
浏览文件 @
e2f1434b
...
...
@@ -688,26 +688,33 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx) {
}
int
nNews
=
0
;
int
cntNews
[
5
]
=
{
0
};
// TODO: maybe 5 is not enough
int
szNews
[
5
]
=
{
0
};
struct
{
int
cnt
;
int
size
;
int
oPage
;
int
oIdx
;
}
infoNews
[
5
]
=
{
0
};
{
// Get how many new pages are needed and the new distribution
//
loop to find
number of pages needed
for
(
int
i
=
0
;
i
<
nOlds
;
i
++
)
{
SPage
*
pPage
=
pOlds
[
i
];
//
first loop to find minimum
number of pages needed
for
(
int
oPage
=
0
;
oPage
<
nOlds
;
oPage
++
)
{
SPage
*
pPage
=
pOlds
[
oPage
];
SCell
*
pCell
;
int
cellBytes
;
for
(
int
cIdx
=
0
;
cIdx
<
TDB_PAGE_TOTAL_CELLS
(
pPage
);
c
Idx
++
)
{
pCell
=
tdbPageGetCell
(
pPage
,
c
Idx
);
for
(
int
oIdx
=
0
;
oIdx
<
TDB_PAGE_TOTAL_CELLS
(
pPage
);
o
Idx
++
)
{
pCell
=
tdbPageGetCell
(
pPage
,
o
Idx
);
cellBytes
=
TDB_BYTES_CELL_TAKEN
(
pPage
,
pCell
);
if
(
szNews
[
nNews
]
+
cellBytes
>
TDB_PAGE_USABLE_SIZE
(
pPage
))
{
if
(
infoNews
[
nNews
].
size
+
cellBytes
>
TDB_PAGE_USABLE_SIZE
(
pPage
))
{
// page is full, use a new page
nNews
++
;
}
cntNews
[
nNews
]
++
;
szNews
[
nNews
]
=
szNews
[
nNews
]
+
cellBytes
;
infoNews
[
nNews
].
cnt
++
;
infoNews
[
nNews
].
size
+=
cellBytes
;
infoNews
[
nNews
].
oPage
=
oPage
;
infoNews
[
nNews
].
oIdx
=
oIdx
;
}
}
...
...
@@ -715,84 +722,37 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx) {
// back loop to make the distribution even
for
(
int
iNew
=
nNews
-
1
;
iNew
>
0
;
iNew
--
)
{
// TODO: find the last cell of page (iNew-1)
int
cIdx
;
int
iPage
;
int
cellBytes
;
SPage
*
pPage
;
SCell
*
pCell
;
SPage
*
pPage
;
int
cellBytes
;
for
(;;)
{
pCell
=
tdbPageGetCell
(
pPage
,
cIdx
);
pPage
=
pOlds
[
infoNews
[
iNew
-
1
].
oPage
];
pCell
=
tdbPageGetCell
(
pPage
,
infoNews
[
iNew
-
1
].
oIdx
);
cellBytes
=
TDB_BYTES_CELL_TAKEN
(
pPage
,
pCell
);
if
(
szNews
[
iNew
]
+
cellBytes
>=
szNews
[
iNew
-
1
]
+
cellBytes
)
{
break
;
infoNews
[
iNew
].
cnt
++
;
infoNews
[
iNew
].
size
+=
cellBytes
;
infoNews
[
iNew
-
1
].
cnt
--
;
infoNews
[
iNew
-
1
].
size
-=
cellBytes
;
if
((
infoNews
[
iNew
-
1
].
oIdx
--
)
==
0
)
{
infoNews
[
iNew
-
1
].
oPage
--
;
infoNews
[
iNew
-
1
].
oIdx
=
TDB_PAGE_TOTAL_CELLS
(
pOlds
[
infoNews
[
iNew
-
1
].
oPage
]);
}
// Move the cell right
szNews
[
iNew
]
+=
cellBytes
;
cntNews
[
iNew
]
++
;
szNews
[
iNew
-
1
]
-=
cellBytes
;
cntNews
[
iNew
-
1
]
++
;
cIdx
--
;
if
(
cIdx
<
0
)
{
pPage
=
pOlds
[
--
iPage
];
cIdx
=
TDB_PAGE_TOTAL_CELLS
(
pPage
)
-
1
;
if
(
infoNews
[
iNew
].
size
>
infoNews
[
iNew
-
1
].
size
)
{
break
;
}
}
}
}
SPage
*
pNews
[
5
];
{
// Allocate the new pages
}
#if 0
// Step 1: find two sibling pages and get engough info about the old pages
ret = tdbBtreeBalanceStep1(&blh);
if (ret < 0) {
ASSERT(0);
return -1;
}
// Step 2: Load all cells on the old page and the divider cells
ret = tdbBtreeBalanceStep2(&blh);
if (ret < 0) {
ASSERT(0);
return -1;
}
// Step 3: Get the number of pages needed to hold all cells
ret = tdbBtreeBalanceStep3(&blh);
if (ret < 0) {
ASSERT(0);
return -1;
int
k
=
0
;
}
// Step 4: Allocate enough new pages. Reuse old pages as much as possible
ret = tdbBtreeBalanceStep4(&blh);
if (ret < 0) {
ASSERT(0);
return -1;
}
// Step 5: Insert new divider cells into pParent
ret = tdbBtreeBalanceStep5(&blh);
if (ret < 0) {
ASSERT(0);
return -1;
}
// Step 6: Update the sibling pages
ret = tdbBtreeBalanceStep6(&blh);
if (ret < 0) {
ASSERT(0);
return -1;
SPage
*
pNews
[
5
];
{
// Allocate the new pages
}
#endif
{
// TODO: Reset states
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录