Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
21cec7b6
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看板
提交
21cec7b6
编写于
4月 29, 2022
作者:
H
Hongze Cheng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
more
上级
fd6b2ad6
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
86 addition
and
63 deletion
+86
-63
source/libs/tdb/inc/tdb.h
source/libs/tdb/inc/tdb.h
+4
-5
source/libs/tdb/src/db/tdbBtree.c
source/libs/tdb/src/db/tdbBtree.c
+78
-53
source/libs/tdb/src/db/tdbDb.c
source/libs/tdb/src/db/tdbDb.c
+3
-4
source/libs/tdb/src/inc/tdbInt.h
source/libs/tdb/src/inc/tdbInt.h
+1
-1
未找到文件。
source/libs/tdb/inc/tdb.h
浏览文件 @
21cec7b6
...
...
@@ -45,13 +45,12 @@ int tdbDbGet(TDB *pDb, const void *pKey, int kLen, void **ppVal, int *vLen);
int
tdbDbPGet
(
TDB
*
pDb
,
const
void
*
pKey
,
int
kLen
,
void
**
ppKey
,
int
*
pkLen
,
void
**
ppVal
,
int
*
vLen
);
// TDBC
#define TDB_FLG_BACKWD 0x1 // backward search
#define TDB_FLG_CMP_LT 0x2 // less than
#define TDB_FLG_CMP_EQ 0x4 // equal
#define TDB_FLG_CMP_GT 0x8 // greater than
#define TDB_FLG_CMP_LT 0x1 // less than
#define TDB_FLG_CMP_EQ 0x2 // equal
#define TDB_FLG_CMP_GT 0x4 // greater than
int
tdbDbcOpen
(
TDB
*
pDb
,
TDBC
**
ppDbc
,
TXN
*
pTxn
);
int
tdbDbcMoveTo
(
TDBC
*
pDbc
,
const
void
*
pKey
,
int
kLen
,
tdb_cmpr_fn_t
cmprFn
,
int
flags
);
int
tdbDbcMoveTo
(
TDBC
*
pDbc
,
const
void
*
pKey
,
int
kLen
,
int
flags
);
int
tdbDbcPut
(
TDBC
*
pDbc
,
const
void
*
pKey
,
int
keyLen
,
const
void
*
pVal
,
int
valLen
);
int
tdbDbcUpdate
(
TDBC
*
pDbc
,
const
void
*
pKey
,
int
kLen
,
const
void
*
pVal
,
int
vLen
);
int
tdbDbcDrop
(
TDBC
*
pDbc
);
...
...
source/libs/tdb/src/db/tdbBtree.c
浏览文件 @
21cec7b6
...
...
@@ -1506,20 +1506,45 @@ void tdbBtPageInfo(SPage *pPage, int idx) {
#endif
// TDB_BTREE_DEBUG
int
tdbBtcMoveTo2
(
SBTC
*
pBtc
,
const
void
*
pKey
,
int
kLen
,
tdb_cmpr_fn_t
cmprFn
,
int
flags
)
{
SBTree
*
pBt
=
pBtc
->
pBt
;
SPager
*
pPager
=
pBt
->
pPager
;
SPgno
root
=
pBt
->
root
;
SCellDecoder
cd
=
{
0
};
int
nCells
=
0
;
SCell
*
pCell
=
NULL
;
int
ret
=
0
;
int
c
;
int
backward
=
flags
&
TDB_FLG_BACKWD
;
if
(
cmprFn
==
NULL
)
{
cmprFn
=
pBt
->
kcmpr
;
static
void
tdbBSearch
(
int
*
lidx
,
int
*
ridx
,
int
midx
,
int
c
,
int
flags
)
{
if
(
flags
&
TDB_FLG_CMP_EQ
)
{
if
(
c
<
0
)
{
*
lidx
=
midx
+
1
;
}
else
if
(
c
==
0
)
{
*
lidx
=
*
ridx
+
1
;
}
else
{
*
ridx
=
midx
-
1
;
}
}
else
if
(
flags
&
TDB_FLG_CMP_GT
)
{
if
(
c
<=
0
)
{
*
lidx
=
midx
+
1
;
}
else
{
*
ridx
=
midx
-
1
;
}
}
else
if
(
flags
&
TDB_FLG_CMP_LT
)
{
if
(
c
<
0
)
{
*
lidx
=
midx
+
1
;
}
else
{
*
ridx
=
midx
-
1
;
}
}
else
{
ASSERT
(
0
);
}
}
int
tdbBtcMoveTo2
(
SBTC
*
pBtc
,
const
void
*
pKey
,
int
kLen
,
int
flags
)
{
SBTree
*
pBt
=
pBtc
->
pBt
;
SPager
*
pPager
=
pBt
->
pPager
;
SPgno
root
=
pBt
->
root
;
SCellDecoder
cd
=
{
0
};
int
nCells
=
0
;
SCell
*
pCell
=
NULL
;
int
ret
=
0
;
int
c
;
u8
leaf
;
tdb_cmpr_fn_t
cmprFn
;
cmprFn
=
pBt
->
kcmpr
;
// move cursor to a level
if
(
pBtc
->
iPage
<
0
)
{
...
...
@@ -1538,6 +1563,7 @@ int tdbBtcMoveTo2(SBTC *pBtc, const void *pKey, int kLen, tdb_cmpr_fn_t cmprFn,
if
(
TDB_PAGE_TOTAL_CELLS
(
pBtc
->
pPage
)
==
0
)
return
0
;
}
else
{
// move from a position (TODO)
ASSERT
(
0
);
}
// search downward
...
...
@@ -1553,28 +1579,21 @@ int tdbBtcMoveTo2(SBTC *pBtc, const void *pKey, int kLen, tdb_cmpr_fn_t cmprFn,
ASSERT
(
nCells
>
0
);
ASSERT
(
pBtc
->
idx
==
-
1
);
// search two ends
// compare first cell
midx
=
lidx
;
pCell
=
tdbPageGetCell
(
pPage
,
midx
);
tdbBtreeDecodeCell
(
pPage
,
pCell
,
&
cd
);
c
=
cmprFn
(
pKey
,
kLen
,
cd
.
pKey
,
cd
.
kLen
);
if
(
c
<=
0
)
{
ridx
=
lidx
-
1
;
}
else
{
lidx
=
lidx
+
1
;
}
c
=
cmprFn
(
cd
.
pKey
,
cd
.
kLen
,
pKey
,
kLen
);
tdbBSearch
(
&
lidx
,
&
ridx
,
midx
,
c
,
flags
);
// compare last cell
if
(
lidx
<=
ridx
)
{
midx
=
ridx
;
pCell
=
tdbPageGetCell
(
pPage
,
midx
);
tdbBtreeDecodeCell
(
pPage
,
pCell
,
&
cd
);
c
=
cmprFn
(
pKey
,
kLen
,
cd
.
pKey
,
cd
.
kLen
);
if
(
c
>=
0
)
{
lidx
=
ridx
+
1
;
}
else
{
ridx
=
ridx
-
1
;
}
c
=
cmprFn
(
cd
.
pKey
,
cd
.
kLen
,
pKey
,
kLen
);
tdbBSearch
(
&
lidx
,
&
ridx
,
midx
,
c
,
flags
);
}
// binary search
...
...
@@ -1582,41 +1601,47 @@ int tdbBtcMoveTo2(SBTC *pBtc, const void *pKey, int kLen, tdb_cmpr_fn_t cmprFn,
if
(
lidx
>
ridx
)
break
;
midx
=
(
lidx
+
ridx
)
>>
1
;
pCell
=
tdbPageGetCell
(
pPage
,
midx
);
ret
=
tdbBtreeDecodeCell
(
pPage
,
pCell
,
&
cd
);
if
(
ret
<
0
)
{
// TODO: handle error
ASSERT
(
0
);
return
-
1
;
}
// Compare the key values
tdbBtreeDecodeCell
(
pPage
,
pCell
,
&
cd
);
c
=
cmprFn
(
pKey
,
kLen
,
cd
.
pKey
,
cd
.
kLen
);
if
(
c
<
0
)
{
// pKey < cd.pKey
ridx
=
midx
-
1
;
}
else
if
(
c
>
0
)
{
// pKey > cd.pKey
lidx
=
midx
+
1
;
}
else
{
// pKey == cd.pKey
break
;
}
tdbBSearch
(
&
lidx
,
&
ridx
,
midx
,
c
,
flags
);
}
// keep search downward or break
if
(
TDB_BTREE_PAGE_IS_LEAF
(
pPage
))
{
pBtc
->
idx
=
midx
;
// *pCRst = c;
break
;
}
else
{
if
(
c
<=
0
)
{
pBtc
->
idx
=
midx
;
}
else
{
pBtc
->
idx
=
midx
+
1
;
leaf
=
TDB_BTREE_PAGE_IS_LEAF
(
pPage
);
if
(
!
leaf
)
{
if
(
flags
&
0x7
==
TDB_FLG_CMP_EQ
)
{
if
(
c
<
0
)
{
pBtc
->
idx
=
midx
+
1
;
}
else
{
pBtc
->
idx
=
midx
;
}
}
else
if
(
flags
&
0x7
==
TDB_FLG_CMP_LT
)
{
if
(
c
<
0
)
{
pBtc
->
idx
=
midx
;
}
else
if
(
c
==
0
)
{
}
else
{
}
}
else
if
(
flags
&
0x7
==
TDB_FLG_CMP_GT
)
{
if
(
c
<
0
)
{
}
else
if
(
c
==
0
)
{
}
else
{
}
}
else
if
(
flags
&
0x7
==
TDB_FLG_CMP_LT
|
TDB_FLG_CMP_EQ
)
{
if
(
c
<
0
)
{
}
else
if
(
c
==
0
)
{
}
else
{
}
}
else
if
(
flags
&
0x7
==
TDB_FLG_CMP_GT
|
TDB_FLG_CMP_EQ
)
{
if
(
c
<
0
)
{
}
else
if
(
c
==
0
)
{
}
else
{
}
}
tdbBtcMoveDownward
(
pBtc
);
}
else
{
// non-leaf (TODO)
}
}
...
...
source/libs/tdb/src/db/tdbDb.c
浏览文件 @
21cec7b6
...
...
@@ -111,18 +111,17 @@ int tdbDbcOpen(TDB *pDb, TDBC **ppDbc, TXN *pTxn) {
return
0
;
}
int
tdbDbcMoveTo
(
TDBC
*
pDbc
,
const
void
*
pKey
,
int
kLen
,
tdb_cmpr_fn_t
cmprFn
,
int
flags
)
{
int
tdbDbcMoveTo
(
TDBC
*
pDbc
,
const
void
*
pKey
,
int
kLen
,
int
flags
)
{
int
tflags
;
// set/check flags
if
(
flags
==
0
)
{
flags
|=
TDB_FLG_CMP_EQ
;
}
else
{
tflags
=
flags
&
(
TDB_FLG_CMP_LT
|
TDB_FLG_CMP_EQ
|
TDB_FLG_CMP_GT
);
if
(
tflags
!=
TDB_FLG_CMP_LT
&&
tflags
!=
TDB_FLG_CMP_EQ
&&
tflags
!=
TDB_FLG_CMP_GT
)
return
-
1
;
if
(
flags
&
TDB_FLG_CMP_LT
&&
flags
&
TDB_FLG_CMP_GT
)
return
-
1
;
}
return
tdbBtcMoveTo2
(
&
pDbc
->
btc
,
pKey
,
kLen
,
cmprFn
,
flags
);
return
tdbBtcMoveTo2
(
&
pDbc
->
btc
,
pKey
,
kLen
,
flags
);
}
int
tdbDbcPut
(
TDBC
*
pDbc
,
const
void
*
pKey
,
int
keyLen
,
const
void
*
pVal
,
int
valLen
)
{
...
...
source/libs/tdb/src/inc/tdbInt.h
浏览文件 @
21cec7b6
...
...
@@ -123,7 +123,7 @@ int tdbBtreePGet(SBTree *pBt, const void *pKey, int kLen, void **ppKey, int *pkL
// SBTC
int
tdbBtcOpen
(
SBTC
*
pBtc
,
SBTree
*
pBt
,
TXN
*
pTxn
);
int
tdbBtcMoveTo2
(
SBTC
*
pBtc
,
const
void
*
pKey
,
int
kLen
,
tdb_cmpr_fn_t
cmprFn
,
int
flags
);
int
tdbBtcMoveTo2
(
SBTC
*
pBtc
,
const
void
*
pKey
,
int
kLen
,
int
flags
);
int
tdbBtcMoveToFirst
(
SBTC
*
pBtc
);
int
tdbBtcMoveToLast
(
SBTC
*
pBtc
);
int
tdbBtreeNext
(
SBTC
*
pBtc
,
void
**
ppKey
,
int
*
kLen
,
void
**
ppVal
,
int
*
vLen
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录