Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
40406b6b
T
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1187
Star
22018
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看板
提交
40406b6b
编写于
3月 28, 2022
作者:
H
Hongze Cheng
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'feature/tdb' into feature/meta
上级
47fe8bd9
77957065
变更
10
隐藏空白更改
内联
并排
Showing
10 changed file
with
251 addition
and
71 deletion
+251
-71
source/libs/tdb/CMakeLists.txt
source/libs/tdb/CMakeLists.txt
+1
-0
source/libs/tdb/src/db/tdbBtree.c
source/libs/tdb/src/db/tdbBtree.c
+56
-56
source/libs/tdb/src/db/tdbPager.c
source/libs/tdb/src/db/tdbPager.c
+89
-11
source/libs/tdb/src/db/tdbTxn.c
source/libs/tdb/src/db/tdbTxn.c
+31
-0
source/libs/tdb/src/db/tdbUtil.c
source/libs/tdb/src/db/tdbUtil.c
+5
-0
source/libs/tdb/src/inc/tdbInt.h
source/libs/tdb/src/inc/tdbInt.h
+2
-0
source/libs/tdb/src/inc/tdbTxn.h
source/libs/tdb/src/inc/tdbTxn.h
+39
-0
source/libs/tdb/src/inc/tdbUtil.h
source/libs/tdb/src/inc/tdbUtil.h
+1
-0
source/libs/tdb/src/page/tdbPage.c
source/libs/tdb/src/page/tdbPage.c
+2
-2
source/libs/tdb/test/tdbTest.cpp
source/libs/tdb/test/tdbTest.cpp
+25
-2
未找到文件。
source/libs/tdb/CMakeLists.txt
浏览文件 @
40406b6b
...
...
@@ -8,6 +8,7 @@ target_sources(tdb
"src/db/tdbBtree.c"
"src/db/tdbDb.c"
"src/db/tdbEnv.c"
"src/db/tdbTxn.c"
"src/page/tdbPage.c"
"src/page/tdbPageL.c"
)
...
...
source/libs/tdb/src/db/tdbBtree.c
浏览文件 @
40406b6b
...
...
@@ -67,7 +67,7 @@ typedef struct {
u8
*
pTmpSpace
;
}
SCellDecoder
;
static
int
tdbBtCursorMoveTo
(
SBTC
*
p
Cur
,
const
void
*
pKey
,
int
kLen
,
int
*
pCRst
);
static
int
tdbBtCursorMoveTo
(
SBTC
*
p
Btc
,
const
void
*
pKey
,
int
kLen
,
int
*
pCRst
);
static
int
tdbDefaultKeyCmprFn
(
const
void
*
pKey1
,
int
keyLen1
,
const
void
*
pKey2
,
int
keyLen2
);
static
int
tdbBtreeOpenImpl
(
SBTree
*
pBt
);
static
int
tdbBtreeZeroPage
(
SPage
*
pPage
,
void
*
arg
);
...
...
@@ -75,10 +75,10 @@ static int tdbBtreeInitPage(SPage *pPage, void *arg);
static
int
tdbBtreeEncodeCell
(
SPage
*
pPage
,
const
void
*
pKey
,
int
kLen
,
const
void
*
pVal
,
int
vLen
,
SCell
*
pCell
,
int
*
szCell
);
static
int
tdbBtreeDecodeCell
(
SPage
*
pPage
,
const
SCell
*
pCell
,
SCellDecoder
*
pDecoder
);
static
int
tdbBtreeBalance
(
SBTC
*
p
Cur
);
static
int
tdbBtreeBalance
(
SBTC
*
p
Btc
);
static
int
tdbBtreeCellSize
(
const
SPage
*
pPage
,
SCell
*
pCell
);
static
int
tdbBtcMoveToNext
(
SBTC
*
pBtc
);
static
int
tdbBtcMoveDownward
(
SBTC
*
p
Cur
,
SPgno
pgno
);
static
int
tdbBtcMoveDownward
(
SBTC
*
p
Btc
,
SPgno
pgno
);
static
int
tdbBtcMoveUpward
(
SBTC
*
pBtc
);
int
tdbBtreeOpen
(
int
keyLen
,
int
valLen
,
SPager
*
pPager
,
FKeyComparator
kcmpr
,
SBTree
**
ppBt
)
{
...
...
@@ -134,7 +134,7 @@ int tdbBtreeClose(SBTree *pBt) {
return
0
;
}
int
tdbBtCursorInsert
(
SBTC
*
p
Cur
,
const
void
*
pKey
,
int
kLen
,
const
void
*
pVal
,
int
vLen
)
{
int
tdbBtCursorInsert
(
SBTC
*
p
Btc
,
const
void
*
pKey
,
int
kLen
,
const
void
*
pVal
,
int
vLen
)
{
int
ret
;
int
idx
;
SPager
*
pPager
;
...
...
@@ -143,20 +143,20 @@ int tdbBtCursorInsert(SBTC *pCur, const void *pKey, int kLen, const void *pVal,
int
cret
;
SBTree
*
pBt
;
ret
=
tdbBtCursorMoveTo
(
p
Cur
,
pKey
,
kLen
,
&
cret
);
ret
=
tdbBtCursorMoveTo
(
p
Btc
,
pKey
,
kLen
,
&
cret
);
if
(
ret
<
0
)
{
// TODO: handle error
return
-
1
;
}
if
(
p
Cur
->
idx
==
-
1
)
{
ASSERT
(
TDB_PAGE_TOTAL_CELLS
(
p
Cur
->
pPage
)
==
0
);
if
(
p
Btc
->
idx
==
-
1
)
{
ASSERT
(
TDB_PAGE_TOTAL_CELLS
(
p
Btc
->
pPage
)
==
0
);
idx
=
0
;
}
else
{
if
(
cret
>
0
)
{
idx
=
p
Cur
->
idx
+
1
;
idx
=
p
Btc
->
idx
+
1
;
}
else
if
(
cret
<
0
)
{
idx
=
p
Cur
->
idx
;
idx
=
p
Btc
->
idx
;
}
else
{
/* TODO */
ASSERT
(
0
);
...
...
@@ -164,7 +164,7 @@ int tdbBtCursorInsert(SBTC *pCur, const void *pKey, int kLen, const void *pVal,
}
// TODO: refact code here
pBt
=
p
Cur
->
pBt
;
pBt
=
p
Btc
->
pBt
;
if
(
!
pBt
->
pTmp
)
{
pBt
->
pTmp
=
(
u8
*
)
malloc
(
pBt
->
pageSize
);
if
(
pBt
->
pTmp
==
NULL
)
{
...
...
@@ -175,20 +175,20 @@ int tdbBtCursorInsert(SBTC *pCur, const void *pKey, int kLen, const void *pVal,
pCell
=
pBt
->
pTmp
;
// Encode the cell
ret
=
tdbBtreeEncodeCell
(
p
Cur
->
pPage
,
pKey
,
kLen
,
pVal
,
vLen
,
pCell
,
&
szCell
);
ret
=
tdbBtreeEncodeCell
(
p
Btc
->
pPage
,
pKey
,
kLen
,
pVal
,
vLen
,
pCell
,
&
szCell
);
if
(
ret
<
0
)
{
return
-
1
;
}
// Insert the cell to the index
ret
=
tdbPageInsertCell
(
p
Cur
->
pPage
,
idx
,
pCell
,
szCell
,
0
);
ret
=
tdbPageInsertCell
(
p
Btc
->
pPage
,
idx
,
pCell
,
szCell
,
0
);
if
(
ret
<
0
)
{
return
-
1
;
}
// If page is overflow, balance the tree
if
(
p
Cur
->
pPage
->
nOverflow
>
0
)
{
ret
=
tdbBtreeBalance
(
p
Cur
);
if
(
p
Btc
->
pPage
->
nOverflow
>
0
)
{
ret
=
tdbBtreeBalance
(
p
Btc
);
if
(
ret
<
0
)
{
return
-
1
;
}
...
...
@@ -226,30 +226,30 @@ int tdbBtreeGet(SBTree *pBt, const void *pKey, int kLen, void **ppVal, int *vLen
return
0
;
}
static
int
tdbBtCursorMoveTo
(
SBTC
*
p
Cur
,
const
void
*
pKey
,
int
kLen
,
int
*
pCRst
)
{
static
int
tdbBtCursorMoveTo
(
SBTC
*
p
Btc
,
const
void
*
pKey
,
int
kLen
,
int
*
pCRst
)
{
int
ret
;
SBTree
*
pBt
;
SPager
*
pPager
;
pBt
=
p
Cur
->
pBt
;
pBt
=
p
Btc
->
pBt
;
pPager
=
pBt
->
pPager
;
if
(
p
Cur
->
iPage
<
0
)
{
ASSERT
(
p
Cur
->
iPage
==
-
1
);
ASSERT
(
p
Cur
->
idx
==
-
1
);
if
(
p
Btc
->
iPage
<
0
)
{
ASSERT
(
p
Btc
->
iPage
==
-
1
);
ASSERT
(
p
Btc
->
idx
==
-
1
);
// Move from the root
ret
=
tdbPagerFetchPage
(
pPager
,
pBt
->
root
,
&
(
p
Cur
->
pPage
),
tdbBtreeInitPage
,
pBt
);
ret
=
tdbPagerFetchPage
(
pPager
,
pBt
->
root
,
&
(
p
Btc
->
pPage
),
tdbBtreeInitPage
,
pBt
);
if
(
ret
<
0
)
{
ASSERT
(
0
);
return
-
1
;
}
p
Cur
->
iPage
=
0
;
p
Btc
->
iPage
=
0
;
if
(
TDB_PAGE_TOTAL_CELLS
(
p
Cur
->
pPage
)
==
0
)
{
if
(
TDB_PAGE_TOTAL_CELLS
(
p
Btc
->
pPage
)
==
0
)
{
// Current page is empty
// ASSERT(TDB_FLAG_IS(TDB_PAGE_FLAGS(p
Cur
->pPage), TDB_BTREE_ROOT | TDB_BTREE_LEAF));
// ASSERT(TDB_FLAG_IS(TDB_PAGE_FLAGS(p
Btc
->pPage), TDB_BTREE_ROOT | TDB_BTREE_LEAF));
return
0
;
}
...
...
@@ -259,7 +259,7 @@ static int tdbBtCursorMoveTo(SBTC *pCur, const void *pKey, int kLen, int *pCRst)
SPage
*
pPage
;
SCellDecoder
cd
=
{
0
};
pPage
=
p
Cur
->
pPage
;
pPage
=
p
Btc
->
pPage
;
nCells
=
TDB_PAGE_TOTAL_CELLS
(
pPage
);
lidx
=
0
;
ridx
=
nCells
-
1
;
...
...
@@ -297,22 +297,22 @@ static int tdbBtCursorMoveTo(SBTC *pCur, const void *pKey, int kLen, int *pCRst)
u8
flags
=
TDB_BTREE_PAGE_GET_FLAGS
(
pPage
);
u8
leaf
=
TDB_BTREE_PAGE_IS_LEAF
(
flags
);
if
(
leaf
)
{
p
Cur
->
idx
=
midx
;
p
Btc
->
idx
=
midx
;
*
pCRst
=
c
;
break
;
}
else
{
if
(
c
<=
0
)
{
p
Cur
->
idx
=
midx
;
tdbBtcMoveDownward
(
p
Cur
,
cd
.
pgno
);
p
Btc
->
idx
=
midx
;
tdbBtcMoveDownward
(
p
Btc
,
cd
.
pgno
);
}
else
{
p
Cur
->
idx
=
midx
+
1
;
p
Btc
->
idx
=
midx
+
1
;
if
(
midx
==
nCells
-
1
)
{
/* Move to right-most child */
tdbBtcMoveDownward
(
p
Cur
,
((
SIntHdr
*
)
pCur
->
pPage
->
pData
)
->
pgno
);
tdbBtcMoveDownward
(
p
Btc
,
((
SIntHdr
*
)
pBtc
->
pPage
->
pData
)
->
pgno
);
}
else
{
pCell
=
tdbPageGetCell
(
pPage
,
p
Cur
->
idx
);
pCell
=
tdbPageGetCell
(
pPage
,
p
Btc
->
idx
);
tdbBtreeDecodeCell
(
pPage
,
pCell
,
&
cd
);
tdbBtcMoveDownward
(
p
Cur
,
cd
.
pgno
);
tdbBtcMoveDownward
(
p
Btc
,
cd
.
pgno
);
}
}
}
...
...
@@ -805,7 +805,7 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx) {
return
0
;
}
static
int
tdbBtreeBalance
(
SBTC
*
p
Cur
)
{
static
int
tdbBtreeBalance
(
SBTC
*
p
Btc
)
{
int
iPage
;
SPage
*
pParent
;
SPage
*
pPage
;
...
...
@@ -816,8 +816,8 @@ static int tdbBtreeBalance(SBTC *pCur) {
// Main loop to balance the BTree
for
(;;)
{
iPage
=
p
Cur
->
iPage
;
pPage
=
p
Cur
->
pPage
;
iPage
=
p
Btc
->
iPage
;
pPage
=
p
Btc
->
pPage
;
flags
=
TDB_BTREE_PAGE_GET_FLAGS
(
pPage
);
leaf
=
TDB_BTREE_PAGE_IS_LEAF
(
flags
);
root
=
TDB_BTREE_PAGE_IS_ROOT
(
flags
);
...
...
@@ -833,27 +833,27 @@ static int tdbBtreeBalance(SBTC *pCur) {
// ignore the case of empty
if
(
pPage
->
nOverflow
==
0
)
break
;
ret
=
tdbBtreeBalanceDeeper
(
p
Cur
->
pBt
,
pPage
,
&
(
pCur
->
pgStack
[
1
]));
ret
=
tdbBtreeBalanceDeeper
(
p
Btc
->
pBt
,
pPage
,
&
(
pBtc
->
pgStack
[
1
]));
if
(
ret
<
0
)
{
return
-
1
;
}
p
Cur
->
idx
=
0
;
p
Cur
->
idxStack
[
0
]
=
0
;
p
Cur
->
pgStack
[
0
]
=
pCur
->
pPage
;
p
Cur
->
iPage
=
1
;
p
Cur
->
pPage
=
pCur
->
pgStack
[
1
];
p
Btc
->
idx
=
0
;
p
Btc
->
idxStack
[
0
]
=
0
;
p
Btc
->
pgStack
[
0
]
=
pBtc
->
pPage
;
p
Btc
->
iPage
=
1
;
p
Btc
->
pPage
=
pBtc
->
pgStack
[
1
];
}
else
{
// Generalized balance step
pParent
=
p
Cur
->
pgStack
[
iPage
-
1
];
pParent
=
p
Btc
->
pgStack
[
iPage
-
1
];
ret
=
tdbBtreeBalanceNonRoot
(
p
Cur
->
pBt
,
pParent
,
pCur
->
idxStack
[
pCur
->
iPage
-
1
]);
ret
=
tdbBtreeBalanceNonRoot
(
p
Btc
->
pBt
,
pParent
,
pBtc
->
idxStack
[
pBtc
->
iPage
-
1
]);
if
(
ret
<
0
)
{
return
-
1
;
}
p
Cur
->
iPage
--
;
p
Cur
->
pPage
=
pCur
->
pgStack
[
pCur
->
iPage
];
p
Btc
->
iPage
--
;
p
Btc
->
pPage
=
pBtc
->
pgStack
[
pBtc
->
iPage
];
}
}
...
...
@@ -1050,11 +1050,11 @@ static int tdbBtreeCellSize(const SPage *pPage, SCell *pCell) {
#endif
int
tdbBtcOpen
(
SBTC
*
p
Cur
,
SBTree
*
pBt
)
{
p
Cur
->
pBt
=
pBt
;
p
Cur
->
iPage
=
-
1
;
p
Cur
->
pPage
=
NULL
;
p
Cur
->
idx
=
-
1
;
int
tdbBtcOpen
(
SBTC
*
p
Btc
,
SBTree
*
pBt
)
{
p
Btc
->
pBt
=
pBt
;
p
Btc
->
iPage
=
-
1
;
p
Btc
->
pPage
=
NULL
;
p
Btc
->
idx
=
-
1
;
return
0
;
}
...
...
@@ -1262,16 +1262,16 @@ int tdbBtcClose(SBTC *pBtc) {
return
0
;
}
static
int
tdbBtcMoveDownward
(
SBTC
*
p
Cur
,
SPgno
pgno
)
{
static
int
tdbBtcMoveDownward
(
SBTC
*
p
Btc
,
SPgno
pgno
)
{
int
ret
;
p
Cur
->
pgStack
[
pCur
->
iPage
]
=
pCur
->
pPage
;
p
Cur
->
idxStack
[
pCur
->
iPage
]
=
pCur
->
idx
;
p
Cur
->
iPage
++
;
p
Cur
->
pPage
=
NULL
;
p
Cur
->
idx
=
-
1
;
p
Btc
->
pgStack
[
pBtc
->
iPage
]
=
pBtc
->
pPage
;
p
Btc
->
idxStack
[
pBtc
->
iPage
]
=
pBtc
->
idx
;
p
Btc
->
iPage
++
;
p
Btc
->
pPage
=
NULL
;
p
Btc
->
idx
=
-
1
;
ret
=
tdbPagerFetchPage
(
p
Cur
->
pBt
->
pPager
,
pgno
,
&
pCur
->
pPage
,
tdbBtreeInitPage
,
pCur
->
pBt
);
ret
=
tdbPagerFetchPage
(
p
Btc
->
pBt
->
pPager
,
pgno
,
&
pBtc
->
pPage
,
tdbBtreeInitPage
,
pBtc
->
pBt
);
if
(
ret
<
0
)
{
ASSERT
(
0
);
}
...
...
source/libs/tdb/src/db/tdbPager.c
浏览文件 @
40406b6b
...
...
@@ -25,9 +25,7 @@ struct SPager {
SPCache
*
pCache
;
SPgno
dbFileSize
;
SPgno
dbOrigSize
;
int
nDirty
;
SPage
*
pDirty
;
SPage
*
pDirtyTail
;
u8
inTran
;
};
...
...
@@ -46,6 +44,8 @@ TDB_STATIC_ASSERT(sizeof(SFileHdr) == 128, "Size of file header is not correct")
static
int
tdbPagerReadPage
(
SPager
*
pPager
,
SPage
*
pPage
);
static
int
tdbPagerAllocPage
(
SPager
*
pPager
,
SPgno
*
ppgno
);
static
int
tdbPagerInitPage
(
SPager
*
pPager
,
SPage
*
pPage
,
int
(
*
initPage
)(
SPage
*
,
void
*
),
void
*
arg
);
static
int
tdbPagerWritePageToJournal
(
SPager
*
pPager
,
SPage
*
pPage
);
static
int
tdbPagerWritePageToDB
(
SPager
*
pPager
,
SPage
*
pPage
);
int
tdbPagerOpen
(
SPCache
*
pCache
,
const
char
*
fileName
,
SPager
**
ppPager
)
{
uint8_t
*
pPtr
;
...
...
@@ -140,14 +140,25 @@ int tdbPagerWrite(SPager *pPager, SPage *pPage) {
}
}
if
(
pPage
->
isDirty
==
0
)
{
pPage
->
isDirty
=
1
;
// TODO: add the page to the dirty list
if
(
pPage
->
isDirty
)
return
0
;
// TODO: write the page to the journal
if
(
1
/*actually load from the file*/
)
{
// Set page as dirty
pPage
->
isDirty
=
1
;
// Add page to dirty list
// TODO: sort the list according to the page number
pPage
->
pDirtyNext
=
pPager
->
pDirty
;
pPager
->
pDirty
=
pPage
;
// Write page to journal
if
(
TDB_PAGE_PGNO
(
pPage
)
<=
pPager
->
dbOrigSize
)
{
ret
=
tdbPagerWritePageToJournal
(
pPager
,
pPage
);
if
(
ret
<
0
)
{
ASSERT
(
0
);
return
-
1
;
}
}
return
0
;
}
...
...
@@ -170,7 +181,37 @@ int tdbPagerBegin(SPager *pPager) {
}
int
tdbPagerCommit
(
SPager
*
pPager
)
{
// TODO
SPage
*
pPage
;
int
ret
;
// Begin commit
{
// TODO: Sync the journal file (Here or when write ?)
}
for
(;;)
{
pPage
=
pPager
->
pDirty
;
if
(
pPage
==
NULL
)
break
;
ret
=
tdbPagerWritePageToDB
(
pPager
,
pPage
);
if
(
ret
<
0
)
{
ASSERT
(
0
);
return
-
1
;
}
pPager
->
pDirty
=
pPage
->
pDirtyNext
;
pPage
->
pDirtyNext
=
NULL
;
// TODO: release the page
}
fsync
(
pPager
->
fd
);
close
(
pPager
->
jfd
);
remove
(
pPager
->
jFileName
);
pPager
->
jfd
=
-
1
;
return
0
;
}
...
...
@@ -255,9 +296,7 @@ int tdbPagerNewPage(SPager *pPager, SPgno *ppgno, SPage **ppPage, int (*initPage
return
0
;
}
void
tdbPagerReturnPage
(
SPager
*
pPager
,
SPage
*
pPage
)
{
tdbPCacheRelease
(
pPager
->
pCache
,
pPage
);
}
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
...
...
@@ -328,5 +367,44 @@ static int tdbPagerInitPage(SPager *pPager, SPage *pPage, int (*initPage)(SPage
return
-
1
;
}
return
0
;
}
// ---------------------------- Journal manipulation
static
int
tdbPagerWritePageToJournal
(
SPager
*
pPager
,
SPage
*
pPage
)
{
int
ret
;
SPgno
pgno
;
pgno
=
TDB_PAGE_PGNO
(
pPage
);
ret
=
tdbWrite
(
pPager
->
jfd
,
&
pgno
,
sizeof
(
pgno
));
if
(
ret
<
0
)
{
return
-
1
;
}
ret
=
tdbWrite
(
pPager
->
jfd
,
pPage
->
pData
,
pPage
->
pageSize
);
if
(
ret
<
0
)
{
return
-
1
;
}
return
0
;
}
static
int
tdbPagerWritePageToDB
(
SPager
*
pPager
,
SPage
*
pPage
)
{
i64
offset
;
int
ret
;
offset
=
pPage
->
pageSize
*
TDB_PAGE_PGNO
(
pPage
);
if
(
lseek
(
pPager
->
fd
,
offset
,
SEEK_SET
)
<
0
)
{
ASSERT
(
0
);
return
-
1
;
}
ret
=
tdbWrite
(
pPager
->
fd
,
pPage
->
pData
,
pPage
->
pageSize
);
if
(
ret
<
0
)
{
ASSERT
(
0
);
return
-
1
;
}
return
0
;
}
\ No newline at end of file
source/libs/tdb/src/db/tdbTxn.c
0 → 100644
浏览文件 @
40406b6b
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "tdbInt.h"
int
tdbTxnBegin
(
STEnv
*
pEnv
)
{
// TODO
return
0
;
}
int
tdbTxnCommit
(
STEnv
*
pEnv
)
{
// TODO
return
0
;
}
int
tdbTxnRollback
(
STEnv
*
pEnv
)
{
// TODO
return
0
;
}
\ No newline at end of file
source/libs/tdb/src/db/tdbUtil.c
浏览文件 @
40406b6b
...
...
@@ -89,4 +89,9 @@ int tdbPRead(int fd, void *pData, int count, i64 offset) {
}
return
count
;
}
int
tdbWrite
(
int
fd
,
void
*
pData
,
int
count
)
{
// TODO
return
write
(
fd
,
pData
,
count
);
}
\ No newline at end of file
source/libs/tdb/src/inc/tdbInt.h
浏览文件 @
40406b6b
...
...
@@ -162,6 +162,8 @@ typedef struct SPage SPage;
#include "tdbPage.h"
#include "tdbTxn.h"
#ifdef __cplusplus
}
#endif
...
...
source/libs/tdb/src/inc/tdbTxn.h
0 → 100644
浏览文件 @
40406b6b
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _TDB_TXN_H_
#define _TDB_TXN_H_
#ifdef __cplusplus
extern
"C"
{
#endif
typedef
struct
STxn
STXN
;
struct
STxn
{
u64
txnId
;
void
*
(
*
xMalloc
)(
void
*
,
int
);
void
*
xArg
;
};
int
tdbTxnBegin
(
STEnv
*
pEnv
);
int
tdbTxnCommit
(
STEnv
*
pEnv
);
int
tdbTxnRollback
(
STEnv
*
pEnv
);
#ifdef __cplusplus
}
#endif
#endif
/*_TDB_TXN_H_*/
\ No newline at end of file
source/libs/tdb/src/inc/tdbUtil.h
浏览文件 @
40406b6b
...
...
@@ -38,6 +38,7 @@ int tdbGnrtFileID(const char *fname, uint8_t *fileid, bool unique);
int
tdbGetFileSize
(
const
char
*
fname
,
int
pgSize
,
SPgno
*
pSize
);
int
tdbPRead
(
int
fd
,
void
*
pData
,
int
count
,
i64
offset
);
int
tdbWrite
(
int
fd
,
void
*
pData
,
int
count
);
#define TDB_REALLOC(PTR, SIZE) \
({ \
...
...
source/libs/tdb/src/page/tdbPage.c
浏览文件 @
40406b6b
...
...
@@ -372,11 +372,11 @@ static int tdbPageDefragment(SPage *pPage) {
int
idx
;
int
iCell
;
ASSERT
(
pPage
->
pFreeEnd
-
pPage
->
pFreeStart
<
nFree
);
nFree
=
TDB_PAGE_NFREE
(
pPage
);
nCells
=
TDB_PAGE_NCELLS
(
pPage
);
ASSERT
(
pPage
->
pFreeEnd
-
pPage
->
pFreeStart
<
nFree
);
// Loop to compact the page content
// Here we use an O(n^2) algorithm to do the job since
// this is a low frequency job.
...
...
source/libs/tdb/test/tdbTest.cpp
浏览文件 @
40406b6b
...
...
@@ -39,6 +39,8 @@ static void closePool(SPoolMem *pPool) {
free
(
pPool
);
}
#define clearPool closePool
static
void
*
poolMalloc
(
void
*
arg
,
int
size
)
{
void
*
ptr
=
NULL
;
SPoolMem
*
pPool
=
(
SPoolMem
*
)
arg
;
...
...
@@ -116,7 +118,7 @@ TEST(tdb_test, simple_test) {
STEnv
*
pEnv
;
STDB
*
pDb
;
FKeyComparator
compFunc
;
int
nData
=
1000000
0
;
int
nData
=
1000000
;
// Open Env
ret
=
tdbEnvOpen
(
"tdb"
,
4096
,
256000
,
&
pEnv
);
...
...
@@ -132,13 +134,34 @@ TEST(tdb_test, simple_test) {
char
val
[
64
];
{
// Insert some data
int
i
=
1
;
SPoolMem
*
pPool
;
int
memPoolCapacity
=
16
*
1024
;
pPool
=
openPool
();
tdbTxnBegin
(
pEnv
);
for
(;;)
{
if
(
i
>
nData
)
break
;
for
(
int
i
=
1
;
i
<=
nData
;
i
++
)
{
sprintf
(
key
,
"key%d"
,
i
);
sprintf
(
val
,
"value%d"
,
i
);
ret
=
tdbDbInsert
(
pDb
,
key
,
strlen
(
key
),
val
,
strlen
(
val
));
GTEST_ASSERT_EQ
(
ret
,
0
);
if
(
pPool
->
size
>=
memPoolCapacity
)
{
tdbTxnCommit
(
pEnv
);
clearPool
(
pPool
);
tdbTxnBegin
(
pEnv
);
}
i
++
;
}
closePool
(
pPool
);
}
{
// Query the data
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录