Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
c66524d8
TDengine
项目概览
taosdata
/
TDengine
大约 1 年 前同步成功
通知
1184
Star
22015
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看板
体验新版 GitCode,发现更多精彩内容 >>
提交
c66524d8
编写于
7月 05, 2023
作者:
M
Minglei Jin
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
tdb/ofp: recycle ofp cell on parent page
上级
f89b43b6
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
129 addition
and
13 deletion
+129
-13
source/libs/tdb/src/db/tdbBtree.c
source/libs/tdb/src/db/tdbBtree.c
+62
-13
source/libs/tdb/test/tdbPageRecycleTest.cpp
source/libs/tdb/test/tdbPageRecycleTest.cpp
+67
-0
未找到文件。
source/libs/tdb/src/db/tdbBtree.c
浏览文件 @
c66524d8
...
...
@@ -608,7 +608,30 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx, TXN *pTx
for
(
int
i
=
0
;
i
<
nOlds
;
i
++
)
{
nCells
=
TDB_PAGE_TOTAL_CELLS
(
pParent
);
if
(
sIdx
<
nCells
)
{
bool
destroyOfps
=
false
;
if
(
!
childNotLeaf
)
{
if
(
!
pParent
->
pPager
->
ofps
)
{
pParent
->
pPager
->
ofps
=
taosArrayInit
(
8
,
sizeof
(
SPage
*
));
destroyOfps
=
true
;
}
}
tdbPageDropCell
(
pParent
,
sIdx
,
pTxn
,
pBt
);
if
(
!
childNotLeaf
)
{
SArray
*
ofps
=
pParent
->
pPager
->
ofps
;
if
(
ofps
)
{
for
(
int
i
=
0
;
i
<
TARRAY_SIZE
(
ofps
);
++
i
)
{
SPage
*
ofp
=
*
(
SPage
**
)
taosArrayGet
(
ofps
,
i
);
tdbPagerInsertFreePage
(
pParent
->
pPager
,
ofp
,
pTxn
);
}
if
(
destroyOfps
)
{
taosArrayDestroy
(
ofps
);
pParent
->
pPager
->
ofps
=
NULL
;
}
}
}
}
else
{
((
SIntHdr
*
)
pParent
->
pData
)
->
pgno
=
0
;
}
...
...
@@ -1372,6 +1395,7 @@ static int tdbBtreeDecodePayload(SPage *pPage, const SCell *pCell, int nHeader,
// load left key & val to ovpages
while
(
pgno
!=
0
)
{
tdbTrace
(
"tdb decode-ofp, pTxn: %p, pgno:%u by cell:%p"
,
pTxn
,
pgno
,
pCell
);
// printf("tdb decode-ofp, pTxn: %p, pgno:%u by cell:%p\n", pTxn, pgno, pCell);
ret
=
tdbLoadOvflPage
(
&
pgno
,
&
ofp
,
pTxn
,
pBt
);
if
(
ret
<
0
)
{
return
-
1
;
...
...
@@ -2122,10 +2146,27 @@ int tdbBtcDelete(SBTC *pBtc) {
return
-
1
;
}
pBtc
->
pPage
->
pPager
->
ofps
=
taosArrayInit
(
8
,
sizeof
(
SPage
*
));
bool
destroyOfps
=
false
;
if
(
!
pBtc
->
pPage
->
pPager
->
ofps
)
{
pBtc
->
pPage
->
pPager
->
ofps
=
taosArrayInit
(
8
,
sizeof
(
SPage
*
));
destroyOfps
=
true
;
}
tdbPageDropCell
(
pBtc
->
pPage
,
idx
,
pBtc
->
pTxn
,
pBtc
->
pBt
);
SArray
*
ofps
=
pBtc
->
pPage
->
pPager
->
ofps
;
if
(
ofps
)
{
for
(
int
i
=
0
;
i
<
TARRAY_SIZE
(
ofps
);
++
i
)
{
SPage
*
ofp
=
*
(
SPage
**
)
taosArrayGet
(
ofps
,
i
);
tdbPagerInsertFreePage
(
pBtc
->
pPage
->
pPager
,
ofp
,
pBtc
->
pTxn
);
}
if
(
destroyOfps
)
{
taosArrayDestroy
(
ofps
);
pBtc
->
pPage
->
pPager
->
ofps
=
NULL
;
}
}
// update interior page or do balance
if
(
idx
==
nCells
-
1
)
{
if
(
idx
)
{
...
...
@@ -2179,17 +2220,6 @@ int tdbBtcDelete(SBTC *pBtc) {
}
}
SArray
*
ofps
=
pBtc
->
pPage
->
pPager
->
ofps
;
if
(
ofps
)
{
for
(
int
i
=
0
;
i
<
TARRAY_SIZE
(
ofps
);
++
i
)
{
SPage
*
ofp
=
*
(
SPage
**
)
taosArrayGet
(
ofps
,
i
);
tdbPagerInsertFreePage
(
pBtc
->
pPage
->
pPager
,
ofp
,
pBtc
->
pTxn
);
}
taosArrayDestroy
(
ofps
);
pBtc
->
pPage
->
pPager
->
ofps
=
NULL
;
}
return
0
;
}
...
...
@@ -2250,7 +2280,13 @@ int tdbBtcUpsert(SBTC *pBtc, const void *pKey, int kLen, const void *pData, int
tdbError
(
"tdb/btc-upsert: page insert/update cell failed with ret: %d."
,
ret
);
return
-
1
;
}
/*
bool destroyOfps = false;
if (!pBtc->pPage->pPager->ofps) {
pBtc->pPage->pPager->ofps = taosArrayInit(8, sizeof(SPage *));
destroyOfps = true;
}
*/
// check balance
if
(
pBtc
->
pPage
->
nOverflow
>
0
)
{
ret
=
tdbBtreeBalance
(
pBtc
);
...
...
@@ -2259,7 +2295,20 @@ int tdbBtcUpsert(SBTC *pBtc, const void *pKey, int kLen, const void *pData, int
return
-
1
;
}
}
/*
SArray *ofps = pBtc->pPage->pPager->ofps;
if (ofps) {
for (int i = 0; i < TARRAY_SIZE(ofps); ++i) {
SPage *ofp = *(SPage **)taosArrayGet(ofps, i);
tdbPagerInsertFreePage(pBtc->pPage->pPager, ofp, pBtc->pTxn);
}
if (destroyOfps) {
taosArrayDestroy(ofps);
pBtc->pPage->pPager->ofps = NULL;
}
}
*/
return
0
;
}
...
...
source/libs/tdb/test/tdbPageRecycleTest.cpp
浏览文件 @
c66524d8
...
...
@@ -766,3 +766,70 @@ TEST(TdbPageRecycleTest, recycly_seq_insert_ofp_nocommit) {
system
(
"ls -l ./tdb"
);
}
// TEST(TdbPageRecycleTest, DISABLED_recycly_delete_interior_ofp_nocommit) {
TEST
(
TdbPageRecycleTest
,
recycly_delete_interior_ofp_nocommit
)
{
clearDb
(
"tdb"
);
// open Env
int
ret
=
0
;
int
const
pageSize
=
4096
;
int
const
pageNum
=
64
;
TDB
*
pEnv
=
openEnv
(
"tdb"
,
pageSize
,
pageNum
);
GTEST_ASSERT_NE
(
pEnv
,
nullptr
);
// open db
TTB
*
pDb
=
NULL
;
tdb_cmpr_fn_t
compFunc
=
NULL
;
// tKeyCmpr;
ret
=
tdbTbOpen
(
"ofp_insert.db"
,
-
1
,
-
1
,
compFunc
,
pEnv
,
&
pDb
,
0
);
GTEST_ASSERT_EQ
(
ret
,
0
);
// open the pool
SPoolMem
*
pPool
=
openPool
();
// start a transaction
TXN
*
txn
;
tdbBegin
(
pEnv
,
&
txn
,
poolMalloc
,
poolFree
,
pPool
,
TDB_TXN_WRITE
|
TDB_TXN_READ_UNCOMMITTED
);
char
key
[
1024
]
=
{
0
};
int
count
=
sizeof
(
key
)
/
sizeof
(
key
[
0
]);
for
(
int
i
=
0
;
i
<
count
-
1
;
++
i
)
{
key
[
i
]
=
'a'
;
}
// insert n ofp keys to form 2-layer btree
{
for
(
int
i
=
0
;
i
<
7
;
++
i
)
{
// sprintf(&key[count - 2], "%c", i);
key
[
count
-
2
]
=
'0'
+
i
;
ret
=
tdbTbInsert
(
pDb
,
key
,
count
,
NULL
,
NULL
,
txn
);
GTEST_ASSERT_EQ
(
ret
,
0
);
}
}
/*
// delete one interior key
{
sprintf(&key[count - 2], "%c", 2);
key[count - 2] = '0' + 2;
ret = tdbTbDelete(pDb, key, strlen(key) + 1, txn);
GTEST_ASSERT_EQ(ret, 0);
}
*/
// commit current transaction
tdbCommit
(
pEnv
,
txn
);
tdbPostCommit
(
pEnv
,
txn
);
closePool
(
pPool
);
// Close a database
tdbTbClose
(
pDb
);
// Close Env
ret
=
tdbClose
(
pEnv
);
GTEST_ASSERT_EQ
(
ret
,
0
);
system
(
"ls -l ./tdb"
);
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录