Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
8550a99c
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看板
提交
8550a99c
编写于
3月 17, 2022
作者:
H
Hongze Cheng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
more TDB
上级
1489f166
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
53 addition
and
46 deletion
+53
-46
source/libs/tdb/src/db/tdbBtree.c
source/libs/tdb/src/db/tdbBtree.c
+52
-45
source/libs/tdb/test/tdbTest.cpp
source/libs/tdb/test/tdbTest.cpp
+1
-1
未找到文件。
source/libs/tdb/src/db/tdbBtree.c
浏览文件 @
8550a99c
...
...
@@ -415,6 +415,7 @@ static int tdbBtreeInitPage(SPage *pPage, void *arg) {
// TODO: need to update the SPage.nFree
pPage
->
nFree
=
pPage
->
pFreeEnd
-
pPage
->
pFreeStart
;
pPage
->
nOverflow
=
0
;
return
0
;
}
...
...
@@ -445,7 +446,7 @@ typedef struct {
SBTree
*
pBt
;
SPage
*
pParent
;
int
idx
;
i8
nOld
Pages
;
i8
nOld
;
SPage
*
pOldPages
[
3
];
i8
nNewPages
;
SPage
*
pNewPages
[
5
];
...
...
@@ -514,68 +515,71 @@ static int tdbBtreeBalanceDeeper(SBTree *pBt, SPage *pRoot, SPage **ppChild) {
}
static
int
tdbBtreeBalanceStep1
(
SBtreeBalanceHelper
*
pBlh
)
{
#if 0
int i;
SPage *pParent;
int nDiv;
SPgno pgno;
SPage *pPage;
int ret;
int
nCells
;
int
i
;
int
idxStart
;
int
nChild
;
int
ret
;
SPage
*
pParent
;
SPgno
pgno
;
SCell
*
pCell
;
SCellDecoder
cd
;
SBTree
*
pBt
;
pParent
=
pBlh
->
pParent
;
i = pParent->pPageHdr->nCells + pParent->nOverflow;
nCells
=
TDB_PAGE_NCELLS
(
pParent
);
nChild
=
nCells
+
1
;
pBt
=
pBlh
->
pBt
;
if (i < 1) {
nDiv = 0;
// TODO: ASSERT below needs to be removed
ASSERT
(
pParent
->
nOverflow
==
0
);
ASSERT
(
pBlh
->
idx
<=
nCells
);
if
(
nChild
<
3
)
{
idxStart
=
0
;
pBlh
->
nOld
=
nChild
;
}
else
{
if
(
pBlh
->
idx
==
0
)
{
nDiv
= 0;
} else if (pBlh->idx ==
i
) {
nDiv = i
- 2;
idxStart
=
0
;
}
else
if
(
pBlh
->
idx
==
nCells
)
{
idxStart
=
pBlh
->
idx
-
2
;
}
else
{
nDiv
= pBlh->idx - 1;
idxStart
=
pBlh
->
idx
-
1
;
}
i = 2
;
pBlh
->
nOld
=
3
;
}
pBlh->nOldPages = i + 1;
if (i + nDiv - pParent->nOverflow == pParent->pPageHdr->nCells) {
// pgno = pParent->pPageHdr->rChild;
i
=
pBlh
->
nOld
-
1
;
if
(
idxStart
+
i
==
nCells
)
{
pgno
=
((
SBtPageHdr
*
)(
pParent
->
pAmHdr
))[
0
].
rChild
;
}
else
{
ASSERT(0);
// TODO
pgno = 0;
pCell
=
TDB_PAGE_CELL_AT
(
pParent
,
idxStart
+
i
);
// TODO: no need to decode the payload part, and even the kLen, vLen part
// we only need the pgno part
ret
=
tdbBtreeDecodeCell
(
pParent
,
pCell
,
&
cd
);
if
(
ret
<
0
)
{
ASSERT
(
0
);
return
-
1
;
}
pgno
=
cd
.
pgno
;
}
for
(;;)
{
ret = tdbPagerFetchPage(pB
lh->pBt->pPager, pgno, &pPage, tdbBtreeInitPage, pBlh->
pBt);
ret
=
tdbPagerFetchPage
(
pB
t
->
pPager
,
pgno
,
&
(
pBlh
->
pOldPages
[
i
]),
tdbBtreeInitPage
,
pBt
);
if
(
ret
<
0
)
{
ASSERT
(
0
);
return
-
1
;
}
pBlh->pOldPages[i] = pPage;
// Loop over
if
((
i
--
)
==
0
)
break
;
if (pParent->nOverflow && i + nDiv == pParent->aiOvfl[0]) {
// pCellDiv[i] = pParent->apOvfl[0];
// pgno = 0;
// szNew[i] = tdbPageCellSize(pPage, pCell);
pParent->nOverflow = 0;
} else {
// pCellDiv[i] = TDB_PAGE_CELL_AT(pPage, i + nDiv - pParent->nOverflow);
// pgno = 0;
// szNew[i] = tdbPageCellSize(pPage, pCell);
// Drop the cell from the page
// ret = tdbPageDropCell(pPage, i + nDiv - pParent->nOverflow, szNew[i]);
// if (ret < 0) {
// return -1;
// }
{
// TODO
// ASSERT(0);
}
}
#endif
return
0
;
}
...
...
@@ -587,7 +591,7 @@ static int tdbBtreeBalanceStep2(SBtreeBalanceHelper *pBlh) {
int limit;
SCell *pCell;
for (int i = 0; i < pBlh->nOld
Pages
; i++) {
for (int i = 0; i < pBlh->nOld; i++) {
pPage = pBlh->pOldPages[i];
oidx = 0;
cidx = 0;
...
...
@@ -631,7 +635,7 @@ static int tdbBtreeBalanceStep2(SBtreeBalanceHelper *pBlh) {
}
static
int
tdbBtreeBalanceStep3
(
SBtreeBalanceHelper
*
pBlh
)
{
for
(
int
i
=
0
;
i
<
pBlh
->
nOld
Pages
;
i
++
)
{
for
(
int
i
=
0
;
i
<
pBlh
->
nOld
;
i
++
)
{
/* code */
}
...
...
@@ -657,6 +661,8 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx) {
int
ret
;
SBtreeBalanceHelper
blh
;
ASSERT
(
!
TDB_BTREE_PAGE_IS_LEAF
(
TDB_PAGE_FLAGS
(
pParent
)));
blh
.
pBt
=
pBt
;
blh
.
pParent
=
pParent
;
blh
.
idx
=
idx
;
...
...
@@ -738,7 +744,8 @@ static int tdbBtreeBalance(SBtCursor *pCur) {
// }
// }
// If balance over, break the loop
// 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 <= */
)
{
break
;
}
...
...
@@ -760,7 +767,7 @@ static int tdbBtreeBalance(SBtCursor *pCur) {
pCur
->
pPage
=
pCur
->
pgStack
[
1
];
}
else
{
// Generalized balance step
pParent
=
pCur
->
pgStack
[
pCur
->
iPage
-
1
];
pParent
=
pCur
->
pgStack
[
iPage
-
1
];
ret
=
tdbBtreeBalanceNonRoot
(
pCur
->
pBt
,
pParent
,
pCur
->
idxStack
[
pCur
->
iPage
-
1
]);
if
(
ret
<
0
)
{
...
...
source/libs/tdb/test/tdbTest.cpp
浏览文件 @
8550a99c
...
...
@@ -19,7 +19,7 @@ TEST(tdb_test, simple_test) {
char
key
[
64
];
char
val
[
64
];
for
(
int
i
=
1
;
i
<=
65
;
i
++
)
{
for
(
int
i
=
1
;
i
<=
1000
;
i
++
)
{
sprintf
(
key
,
"key%d"
,
i
);
sprintf
(
val
,
"value%d"
,
i
);
ret
=
tdbDbInsert
(
pDb
,
key
,
strlen
(
key
),
val
,
strlen
(
val
));
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录