Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
af98aa40
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
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看板
提交
af98aa40
编写于
3月 25, 2022
作者:
H
Hongze Cheng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
more TDB
上级
f75cb898
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
73 addition
and
73 deletion
+73
-73
source/libs/tdb/src/db/tdbBtree.c
source/libs/tdb/src/db/tdbBtree.c
+29
-22
source/libs/tdb/src/db/tdbPCache.c
source/libs/tdb/src/db/tdbPCache.c
+18
-29
source/libs/tdb/src/db/tdbPager.c
source/libs/tdb/src/db/tdbPager.c
+4
-0
source/libs/tdb/src/inc/tdbPCache.h
source/libs/tdb/src/inc/tdbPCache.h
+12
-13
source/libs/tdb/src/inc/tdbPager.h
source/libs/tdb/src/inc/tdbPager.h
+10
-9
未找到文件。
source/libs/tdb/src/db/tdbBtree.c
浏览文件 @
af98aa40
...
...
@@ -78,6 +78,8 @@ static int tdbBtreeDecodeCell(SPage *pPage, const SCell *pCell, SCellDecoder *pD
static
int
tdbBtreeBalance
(
SBTC
*
pCur
);
static
int
tdbBtreeCellSize
(
const
SPage
*
pPage
,
SCell
*
pCell
);
static
int
tdbBtcMoveToNext
(
SBTC
*
pBtc
);
static
int
tdbBtcMoveDownward
(
SBTC
*
pCur
,
SPgno
pgno
);
static
int
tdbBtcMoveUpward
(
SBTC
*
pBtc
);
int
tdbBtreeOpen
(
int
keyLen
,
int
valLen
,
SPager
*
pPager
,
FKeyComparator
kcmpr
,
SBTree
**
ppBt
)
{
SBTree
*
pBt
;
...
...
@@ -224,23 +226,6 @@ int tdbBtreeGet(SBTree *pBt, const void *pKey, int kLen, void **ppVal, int *vLen
return
0
;
}
static
int
tdbBtCursorMoveToChild
(
SBTC
*
pCur
,
SPgno
pgno
)
{
int
ret
;
pCur
->
pgStack
[
pCur
->
iPage
]
=
pCur
->
pPage
;
pCur
->
idxStack
[
pCur
->
iPage
]
=
pCur
->
idx
;
pCur
->
iPage
++
;
pCur
->
pPage
=
NULL
;
pCur
->
idx
=
-
1
;
ret
=
tdbPagerFetchPage
(
pCur
->
pBt
->
pPager
,
pgno
,
&
pCur
->
pPage
,
tdbBtreeInitPage
,
pCur
->
pBt
);
if
(
ret
<
0
)
{
ASSERT
(
0
);
}
return
0
;
}
static
int
tdbBtCursorMoveTo
(
SBTC
*
pCur
,
const
void
*
pKey
,
int
kLen
,
int
*
pCRst
)
{
int
ret
;
SBTree
*
pBt
;
...
...
@@ -318,16 +303,16 @@ static int tdbBtCursorMoveTo(SBTC *pCur, const void *pKey, int kLen, int *pCRst)
}
else
{
if
(
c
<=
0
)
{
pCur
->
idx
=
midx
;
tdbBt
CursorMoveToChil
d
(
pCur
,
cd
.
pgno
);
tdbBt
cMoveDownwar
d
(
pCur
,
cd
.
pgno
);
}
else
{
pCur
->
idx
=
midx
+
1
;
if
(
midx
==
nCells
-
1
)
{
/* Move to right-most child */
tdbBt
CursorMoveToChil
d
(
pCur
,
((
SIntHdr
*
)
pCur
->
pPage
->
pData
)
->
pgno
);
tdbBt
cMoveDownwar
d
(
pCur
,
((
SIntHdr
*
)
pCur
->
pPage
->
pData
)
->
pgno
);
}
else
{
pCell
=
tdbPageGetCell
(
pPage
,
pCur
->
idx
);
tdbBtreeDecodeCell
(
pPage
,
pCell
,
&
cd
);
tdbBt
CursorMoveToChil
d
(
pCur
,
cd
.
pgno
);
tdbBt
cMoveDownwar
d
(
pCur
,
cd
.
pgno
);
}
}
}
...
...
@@ -1109,7 +1094,7 @@ int tdbBtcMoveToFirst(SBTC *pBtc) {
pCell
=
tdbPageGetCell
(
pBtc
->
pPage
,
0
);
pgno
=
*
(
SPgno
*
)
pCell
;
ret
=
tdbBt
CursorMoveToChil
d
(
pBtc
,
pgno
);
ret
=
tdbBt
cMoveDownwar
d
(
pBtc
,
pgno
);
if
(
ret
<
0
)
{
ASSERT
(
0
);
return
-
1
;
...
...
@@ -1158,7 +1143,7 @@ int tdbBtcMoveToLast(SBTC *pBtc) {
pBtc
->
idx
=
TDB_PAGE_TOTAL_CELLS
(
pBtc
->
pPage
);
pgno
=
((
SIntHdr
*
)
pBtc
->
pPage
->
pData
)
->
pgno
;
ret
=
tdbBt
CursorMoveToChil
d
(
pBtc
,
pgno
);
ret
=
tdbBt
cMoveDownwar
d
(
pBtc
,
pgno
);
if
(
ret
<
0
)
{
ASSERT
(
0
);
return
-
1
;
...
...
@@ -1242,4 +1227,26 @@ static int tdbBtcMoveToNext(SBTC *pBtc) {
int
tdbBtcClose
(
SBTC
*
pBtc
)
{
// TODO
return
0
;
}
static
int
tdbBtcMoveDownward
(
SBTC
*
pCur
,
SPgno
pgno
)
{
int
ret
;
pCur
->
pgStack
[
pCur
->
iPage
]
=
pCur
->
pPage
;
pCur
->
idxStack
[
pCur
->
iPage
]
=
pCur
->
idx
;
pCur
->
iPage
++
;
pCur
->
pPage
=
NULL
;
pCur
->
idx
=
-
1
;
ret
=
tdbPagerFetchPage
(
pCur
->
pBt
->
pPager
,
pgno
,
&
pCur
->
pPage
,
tdbBtreeInitPage
,
pCur
->
pBt
);
if
(
ret
<
0
)
{
ASSERT
(
0
);
}
return
0
;
}
static
int
tdbBtcMoveUpward
(
SBTC
*
pBtc
)
{
// TODO
return
0
;
}
\ No newline at end of file
source/libs/tdb/src/db/tdbPCache.c
浏览文件 @
af98aa40
...
...
@@ -53,10 +53,10 @@ static void tdbPCacheLock(SPCache *pCache);
static
void
tdbPCacheUnlock
(
SPCache
*
pCache
);
static
bool
tdbPCacheLocked
(
SPCache
*
pCache
);
static
SPage
*
tdbPCacheFetchImpl
(
SPCache
*
pCache
,
const
SPgid
*
pPgid
,
bool
alcNewPage
);
static
void
tdbPCachePinPage
(
SPage
*
pPage
);
static
void
tdbPCacheRemovePageFromHash
(
SPage
*
pPage
);
static
void
tdbPCacheAddPageToHash
(
SPage
*
pPage
);
static
void
tdbPCacheUnpinPage
(
SPage
*
pPage
);
static
void
tdbPCachePinPage
(
SP
Cache
*
pCache
,
SP
age
*
pPage
);
static
void
tdbPCacheRemovePageFromHash
(
SP
Cache
*
pCache
,
SP
age
*
pPage
);
static
void
tdbPCacheAddPageToHash
(
SP
Cache
*
pCache
,
SP
age
*
pPage
);
static
void
tdbPCacheUnpinPage
(
SP
Cache
*
pCache
,
SP
age
*
pPage
);
int
tdbPCacheOpen
(
int
pageSize
,
int
cacheSize
,
SPCache
**
ppCache
)
{
SPCache
*
pCache
;
...
...
@@ -100,7 +100,7 @@ SPage *tdbPCacheFetch(SPCache *pCache, const SPgid *pPgid, bool alcNewPage) {
return
pPage
;
}
void
tdbPCacheRelease
(
SPage
*
pPage
)
{
void
tdbPCacheRelease
(
SP
Cache
*
pCache
,
SP
age
*
pPage
)
{
i32
nRef
;
nRef
=
TDB_UNREF_PAGE
(
pPage
);
...
...
@@ -108,7 +108,7 @@ void tdbPCacheRelease(SPage *pPage) {
if
(
nRef
==
0
)
{
if
(
1
/*TODO: page still clean*/
)
{
tdbPCacheUnpinPage
(
pPage
);
tdbPCacheUnpinPage
(
p
Cache
,
p
Page
);
}
else
{
// TODO
ASSERT
(
0
);
...
...
@@ -142,7 +142,7 @@ static SPage *tdbPCacheFetchImpl(SPCache *pCache, const SPgid *pPgid, bool alcNe
if
(
pPage
||
!
alcNewPage
)
{
if
(
pPage
)
{
tdbPCachePinPage
(
pPage
);
tdbPCachePinPage
(
p
Cache
,
p
Page
);
}
return
pPage
;
}
...
...
@@ -158,8 +158,8 @@ static SPage *tdbPCacheFetchImpl(SPCache *pCache, const SPgid *pPgid, bool alcNe
// 3. Try to Recycle a page
if
(
!
pPage
&&
!
pCache
->
lru
.
pLruPrev
->
isAnchor
)
{
pPage
=
pCache
->
lru
.
pLruPrev
;
tdbPCacheRemovePageFromHash
(
pPage
);
tdbPCachePinPage
(
pPage
);
tdbPCacheRemovePageFromHash
(
p
Cache
,
p
Page
);
tdbPCachePinPage
(
p
Cache
,
p
Page
);
}
// 4. Try a stress allocation (TODO)
...
...
@@ -171,16 +171,13 @@ static SPage *tdbPCacheFetchImpl(SPCache *pCache, const SPgid *pPgid, bool alcNe
memcpy
(
&
(
pPage
->
pgid
),
pPgid
,
sizeof
(
*
pPgid
));
pPage
->
pLruNext
=
NULL
;
pPage
->
pPager
=
NULL
;
tdbPCacheAddPageToHash
(
pPage
);
tdbPCacheAddPageToHash
(
p
Cache
,
p
Page
);
}
return
pPage
;
}
static
void
tdbPCachePinPage
(
SPage
*
pPage
)
{
SPCache
*
pCache
;
pCache
=
pPage
->
pCache
;
static
void
tdbPCachePinPage
(
SPCache
*
pCache
,
SPage
*
pPage
)
{
if
(
!
PAGE_IS_PINNED
(
pPage
))
{
pPage
->
pLruPrev
->
pLruNext
=
pPage
->
pLruNext
;
pPage
->
pLruNext
->
pLruPrev
=
pPage
->
pLruPrev
;
...
...
@@ -190,11 +187,8 @@ static void tdbPCachePinPage(SPage *pPage) {
}
}
static
void
tdbPCacheUnpinPage
(
SPage
*
pPage
)
{
SPCache
*
pCache
;
i32
nRef
;
pCache
=
pPage
->
pCache
;
static
void
tdbPCacheUnpinPage
(
SPCache
*
pCache
,
SPage
*
pPage
)
{
i32
nRef
;
tdbPCacheLock
(
pCache
);
...
...
@@ -215,12 +209,10 @@ static void tdbPCacheUnpinPage(SPage *pPage) {
tdbPCacheUnlock
(
pCache
);
}
static
void
tdbPCacheRemovePageFromHash
(
SPage
*
pPage
)
{
SPCache
*
pCache
;
SPage
**
ppPage
;
int
h
;
static
void
tdbPCacheRemovePageFromHash
(
SPCache
*
pCache
,
SPage
*
pPage
)
{
SPage
**
ppPage
;
int
h
;
pCache
=
pPage
->
pCache
;
h
=
PCACHE_PAGE_HASH
(
&
(
pPage
->
pgid
));
for
(
ppPage
=
&
(
pCache
->
pgHash
[
h
%
pCache
->
nHash
]);
*
ppPage
!=
pPage
;
ppPage
=
&
((
*
ppPage
)
->
pHashNext
))
;
...
...
@@ -230,11 +222,9 @@ static void tdbPCacheRemovePageFromHash(SPage *pPage) {
pCache
->
nPage
--
;
}
static
void
tdbPCacheAddPageToHash
(
SPage
*
pPage
)
{
SPCache
*
pCache
;
int
h
;
static
void
tdbPCacheAddPageToHash
(
SPCache
*
pCache
,
SPage
*
pPage
)
{
int
h
;
pCache
=
pPage
->
pCache
;
h
=
PCACHE_PAGE_HASH
(
&
(
pPage
->
pgid
))
%
pCache
->
nHash
;
pPage
->
pHashNext
=
pCache
->
pgHash
[
h
];
...
...
@@ -264,7 +254,6 @@ static int tdbPCacheOpenImpl(SPCache *pCache) {
// pPage->pgid = 0;
pPage
->
isAnchor
=
0
;
pPage
->
isLocalPage
=
1
;
pPage
->
pCache
=
pCache
;
TDB_INIT_PAGE_REF
(
pPage
);
pPage
->
pHashNext
=
NULL
;
pPage
->
pLruNext
=
NULL
;
...
...
source/libs/tdb/src/db/tdbPager.c
浏览文件 @
af98aa40
...
...
@@ -255,6 +255,10 @@ int tdbPagerNewPage(SPager *pPager, SPgno *ppgno, SPage **ppPage, int (*initPage
return
0
;
}
void
tdbPagerReturnPage
(
SPager
*
pPager
,
SPage
*
pPage
)
{
tdbPCacheRelease
(
pPager
->
pCache
,
pPage
);
}
static
int
tdbPagerAllocFreePage
(
SPager
*
pPager
,
SPgno
*
ppgno
)
{
// TODO: Allocate a page from the free list
return
0
;
...
...
source/libs/tdb/src/inc/tdbPCache.h
浏览文件 @
af98aa40
...
...
@@ -21,23 +21,22 @@ extern "C" {
#endif
#define TDB_PCACHE_PAGE \
u8 isAnchor; \
u8 isLocalPage; \
u8 isDirty; \
i32 nRef; \
SPCache *pCache; \
SPage *pFreeNext; \
SPage *pHashNext; \
SPage *pLruNext; \
SPage *pLruPrev; \
SPage *pDirtyNext; \
SPager *pPager; \
SPgid pgid;
u8 isAnchor; \
u8 isLocalPage; \
u8 isDirty; \
i32 nRef; \
SPage *pFreeNext; \
SPage *pHashNext; \
SPage *pLruNext; \
SPage *pLruPrev; \
SPage *pDirtyNext; \
SPager *pPager; \
SPgid pgid;
int
tdbPCacheOpen
(
int
pageSize
,
int
cacheSize
,
SPCache
**
ppCache
);
int
tdbPCacheClose
(
SPCache
*
pCache
);
SPage
*
tdbPCacheFetch
(
SPCache
*
pCache
,
const
SPgid
*
pPgid
,
bool
alcNewPage
);
void
tdbPCacheRelease
(
SPage
*
pPage
);
void
tdbPCacheRelease
(
SP
Cache
*
pCache
,
SP
age
*
pPage
);
int
tdbPCacheGetPageSize
(
SPCache
*
pCache
);
#ifdef __cplusplus
...
...
source/libs/tdb/src/inc/tdbPager.h
浏览文件 @
af98aa40
...
...
@@ -20,15 +20,16 @@
extern
"C"
{
#endif
int
tdbPagerOpen
(
SPCache
*
pCache
,
const
char
*
fileName
,
SPager
**
ppPager
);
int
tdbPagerClose
(
SPager
*
pPager
);
int
tdbPagerOpenDB
(
SPager
*
pPager
,
SPgno
*
ppgno
,
bool
toCreate
);
int
tdbPagerWrite
(
SPager
*
pPager
,
SPage
*
pPage
);
int
tdbPagerBegin
(
SPager
*
pPager
);
int
tdbPagerCommit
(
SPager
*
pPager
);
int
tdbPagerGetPageSize
(
SPager
*
pPager
);
int
tdbPagerFetchPage
(
SPager
*
pPager
,
SPgno
pgno
,
SPage
**
ppPage
,
int
(
*
initPage
)(
SPage
*
,
void
*
),
void
*
arg
);
int
tdbPagerNewPage
(
SPager
*
pPager
,
SPgno
*
ppgno
,
SPage
**
ppPage
,
int
(
*
initPage
)(
SPage
*
,
void
*
),
void
*
arg
);
int
tdbPagerOpen
(
SPCache
*
pCache
,
const
char
*
fileName
,
SPager
**
ppPager
);
int
tdbPagerClose
(
SPager
*
pPager
);
int
tdbPagerOpenDB
(
SPager
*
pPager
,
SPgno
*
ppgno
,
bool
toCreate
);
int
tdbPagerWrite
(
SPager
*
pPager
,
SPage
*
pPage
);
int
tdbPagerBegin
(
SPager
*
pPager
);
int
tdbPagerCommit
(
SPager
*
pPager
);
int
tdbPagerGetPageSize
(
SPager
*
pPager
);
int
tdbPagerFetchPage
(
SPager
*
pPager
,
SPgno
pgno
,
SPage
**
ppPage
,
int
(
*
initPage
)(
SPage
*
,
void
*
),
void
*
arg
);
int
tdbPagerNewPage
(
SPager
*
pPager
,
SPgno
*
ppgno
,
SPage
**
ppPage
,
int
(
*
initPage
)(
SPage
*
,
void
*
),
void
*
arg
);
void
tdbPagerReturnPage
(
SPager
*
pPager
,
SPage
*
pPage
);
#ifdef __cplusplus
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录