Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
44daa77d
T
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22017
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看板
提交
44daa77d
编写于
3月 23, 2022
作者:
H
Hongze Cheng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
more TDB
上级
3a173f46
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
35 addition
and
28 deletion
+35
-28
source/libs/tdb/src/db/tdbBtree.c
source/libs/tdb/src/db/tdbBtree.c
+20
-13
source/libs/tdb/src/inc/tdbPage.h
source/libs/tdb/src/inc/tdbPage.h
+1
-1
source/libs/tdb/src/page/tdbPage.c
source/libs/tdb/src/page/tdbPage.c
+14
-14
未找到文件。
source/libs/tdb/src/db/tdbBtree.c
浏览文件 @
44daa77d
...
...
@@ -187,7 +187,7 @@ int tdbBtCursorInsert(SBtCursor *pCur, const void *pKey, int kLen, const void *p
}
// Insert the cell to the index
ret
=
tdbPageInsertCell
(
pCur
->
pPage
,
idx
,
pCell
,
szCell
);
ret
=
tdbPageInsertCell
(
pCur
->
pPage
,
idx
,
pCell
,
szCell
,
0
);
if
(
ret
<
0
)
{
return
-
1
;
}
...
...
@@ -490,7 +490,7 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx) {
SCell
*
pDivCell
[
2
]
=
{
0
};
int
szDivCell
[
2
];
int
sIdx
;
u8
childLeaf
;
u8
child
Not
Leaf
;
{
// Find 3 child pages at most to do balance
int
nCells
=
TDB_PAGE_TOTAL_CELLS
(
pParent
);
...
...
@@ -529,14 +529,21 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx) {
}
}
// copy the parent key out if child pages are not leaf page
child
Leaf
=
TDB_BTREE_PAGE_IS_LEAF
(
TDB_BTREE_PAGE_GET_FLAGS
(
pOlds
[
0
]));
if
(
!
child
Leaf
)
{
child
NotLeaf
=
!
TDB_BTREE_PAGE_IS_LEAF
(
TDB_BTREE_PAGE_GET_FLAGS
(
pOlds
[
0
]));
if
(
childNot
Leaf
)
{
for
(
int
i
=
0
;
i
<
nOlds
-
1
;
i
++
)
{
pCell
=
tdbPageGetCell
(
pParent
,
sIdx
+
i
);
szDivCell
[
i
]
=
tdbBtreeCellSize
(
pParent
,
pCell
);
pDivCell
[
i
]
=
malloc
(
szDivCell
[
i
]);
memcpy
(
pDivCell
,
pCell
,
szDivCell
[
i
]);
((
SPgno
*
)
pDivCell
)[
0
]
=
((
SIntHdr
*
)
pOlds
[
i
]
->
pData
)
->
pgno
;
((
SIntHdr
*
)
pOlds
[
i
]
->
pData
)
->
pgno
=
0
;
// here we insert the cell as an overflow cell to avoid
// the slow defragment process
tdbPageInsertCell
(
pOlds
[
i
],
TDB_PAGE_TOTAL_CELLS
(
pOlds
[
i
]),
pDivCell
[
i
],
szDivCell
[
i
],
1
);
}
}
// drop the cells on parent page
...
...
@@ -575,7 +582,7 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx) {
// page is full, use a new page
nNews
++
;
// for an internal leaf case, this cell is used as the new divider cell to parent
if
(
!
child
Leaf
)
continue
;
if
(
childNot
Leaf
)
continue
;
}
infoNews
[
nNews
].
cnt
++
;
infoNews
[
nNews
].
size
+=
cellBytes
;
...
...
@@ -584,7 +591,7 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx) {
}
// For internal pages
if
(
!
child
Leaf
&&
oPage
<
nOlds
-
1
)
{
if
(
childNot
Leaf
&&
oPage
<
nOlds
-
1
)
{
if
(
infoNews
[
nNews
].
size
+
szDivCell
[
oPage
]
+
TDB_PAGE_OFFSET_SIZE
(
pPage
)
>
TDB_PAGE_USABLE_SIZE
(
pPage
))
{
nNews
++
;
}
...
...
@@ -607,7 +614,7 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx) {
pPage
=
pOlds
[
infoNews
[
iNew
-
1
].
oPage
];
nCells
=
TDB_PAGE_TOTAL_CELLS
(
pPage
);
if
(
child
Leaf
)
{
// child leaf
if
(
!
childNot
Leaf
)
{
// child leaf
for
(;;)
{
pCell
=
tdbPageGetCell
(
pPage
,
infoNews
[
iNew
-
1
].
oIdx
);
cellBytes
=
TDB_BYTES_CELL_TAKEN
(
pPage
,
pCell
);
...
...
@@ -729,7 +736,7 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx) {
nCells
=
TDB_PAGE_TOTAL_CELLS
(
pOlds
[
iOld
]);
tdbBtreeZeroPage
(
pTPage
[
tPage
],
&
iarg
);
tdbPageCopy
(
pOlds
[
iOld
],
pTPage
[
tPage
]);
if
(
!
child
Leaf
)
{
if
(
childNot
Leaf
)
{
((
SIntHdr
*
)
pTPage
[
tPage
]
->
pData
)
->
pgno
=
((
SIntHdr
*
)
pOlds
[
iOld
]
->
pData
)
->
pgno
;
}
...
...
@@ -746,7 +753,7 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx) {
tIdx
++
;
break
;
}
else
{
if
(
!
child
Leaf
)
{
if
(
childNot
Leaf
)
{
if
(
iOld
<
nOlds
-
1
)
{
pCell
=
pDivCell
[
iOld
];
szCell
=
szDivCell
[
iOld
];
...
...
@@ -780,18 +787,18 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx) {
}
}
tdbPageInsertCell
(
pNews
[
iNew
],
iCell
,
pCell
,
szCell
);
tdbPageInsertCell
(
pNews
[
iNew
],
iCell
,
pCell
,
szCell
,
0
);
}
// fill right-most child pgno if internal page
if
(
!
child
Leaf
)
{
if
(
childNot
Leaf
)
{
if
(
tIdx
<
nCells
)
{
pCell
=
tdbPageGetCell
(
pTPage
[
tPage
],
tIdx
);
szCell
=
tdbBtreeCellSize
(
pTPage
[
tPage
],
pCell
);
tIdx
++
;
break
;
}
else
{
if
(
!
childLeaf
)
{
if
(
!
child
Not
Leaf
)
{
if
(
iOld
<
nOlds
-
1
)
{
pCell
=
pDivCell
[
iOld
];
szCell
=
szDivCell
[
iOld
];
...
...
@@ -836,7 +843,7 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx) {
tdbBtreeEncodeCell
(
pParent
,
cd
.
pKey
,
cd
.
kLen
,
(
void
*
)
&
TDB_PAGE_PGNO
(
pNews
[
iNew
]),
sizeof
(
SPgno
),
pCell
,
&
szCell
);
// TODO: the cell here may be used by pParent as an overflow cell
tdbPageInsertCell
(
pParent
,
sIdx
++
,
pCell
,
szCell
);
tdbPageInsertCell
(
pParent
,
sIdx
++
,
pCell
,
szCell
,
0
);
}
}
...
...
source/libs/tdb/src/inc/tdbPage.h
浏览文件 @
44daa77d
...
...
@@ -108,7 +108,7 @@ int tdbPageCreate(int pageSize, SPage **ppPage, void *(*xMalloc)(void *, size_t
int
tdbPageDestroy
(
SPage
*
pPage
,
void
(
*
xFree
)(
void
*
arg
,
void
*
ptr
),
void
*
arg
);
void
tdbPageZero
(
SPage
*
pPage
,
u8
szAmHdr
,
int
(
*
xCellSize
)(
const
SPage
*
,
SCell
*
));
void
tdbPageInit
(
SPage
*
pPage
,
u8
szAmHdr
,
int
(
*
xCellSize
)(
const
SPage
*
,
SCell
*
));
int
tdbPageInsertCell
(
SPage
*
pPage
,
int
idx
,
SCell
*
pCell
,
int
szCell
);
int
tdbPageInsertCell
(
SPage
*
pPage
,
int
idx
,
SCell
*
pCell
,
int
szCell
,
u8
asOvfl
);
int
tdbPageDropCell
(
SPage
*
pPage
,
int
idx
);
void
tdbPageCopy
(
SPage
*
pFromPage
,
SPage
*
pToPage
);
...
...
source/libs/tdb/src/page/tdbPage.c
浏览文件 @
44daa77d
...
...
@@ -114,7 +114,7 @@ void tdbPageInit(SPage *pPage, u8 szAmHdr, int (*xCellSize)(const SPage *, SCell
ASSERT
(
pPage
->
pFreeEnd
-
pPage
->
pFreeStart
<=
TDB_PAGE_NFREE
(
pPage
));
}
int
tdbPageInsertCell
(
SPage
*
pPage
,
int
idx
,
SCell
*
pCell
,
int
szCell
)
{
int
tdbPageInsertCell
(
SPage
*
pPage
,
int
idx
,
SCell
*
pCell
,
int
szCell
,
u8
asOvfl
)
{
int
nFree
;
int
nCells
;
int
iOvfl
;
...
...
@@ -135,7 +135,19 @@ int tdbPageInsertCell(SPage *pPage, int idx, SCell *pCell, int szCell) {
lidx
=
idx
-
iOvfl
;
if
(
nFree
>=
szCell
+
TDB_PAGE_OFFSET_SIZE
(
pPage
))
{
if
(
asOvfl
||
nFree
<
szCell
+
TDB_PAGE_OFFSET_SIZE
(
pPage
))
{
// TODO: make it extensible
// add the cell as an overflow cell
for
(
int
i
=
pPage
->
nOverflow
;
i
>
iOvfl
;
i
--
)
{
pPage
->
apOvfl
[
i
]
=
pPage
->
apOvfl
[
i
-
1
];
pPage
->
aiOvfl
[
i
]
=
pPage
->
aiOvfl
[
i
-
1
];
}
pPage
->
apOvfl
[
iOvfl
]
=
pCell
;
pPage
->
aiOvfl
[
iOvfl
]
=
idx
;
pPage
->
nOverflow
++
;
iOvfl
++
;
}
else
{
// page must has enough space to hold the cell locally
tdbPageAllocate
(
pPage
,
szCell
,
&
pNewCell
);
...
...
@@ -149,18 +161,6 @@ int tdbPageInsertCell(SPage *pPage, int idx, SCell *pCell, int szCell) {
TDB_PAGE_NCELLS_SET
(
pPage
,
nCells
+
1
);
ASSERT
(
pPage
->
pFreeStart
==
pPage
->
pCellIdx
+
TDB_PAGE_OFFSET_SIZE
(
pPage
)
*
(
nCells
+
1
));
}
else
{
// TODO: make it extensible
// add the cell as an overflow cell
for
(
int
i
=
pPage
->
nOverflow
;
i
>
iOvfl
;
i
--
)
{
pPage
->
apOvfl
[
i
]
=
pPage
->
apOvfl
[
i
-
1
];
pPage
->
aiOvfl
[
i
]
=
pPage
->
aiOvfl
[
i
-
1
];
}
pPage
->
apOvfl
[
iOvfl
]
=
pCell
;
pPage
->
aiOvfl
[
iOvfl
]
=
idx
;
pPage
->
nOverflow
++
;
iOvfl
++
;
}
for
(;
iOvfl
<
pPage
->
nOverflow
;
iOvfl
++
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录