Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
47410b16
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看板
提交
47410b16
编写于
5月 02, 2022
作者:
H
Hongze Cheng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refact TDB
上级
2a042daa
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
87 addition
and
19 deletion
+87
-19
source/dnode/vnode/src/meta/metaTDBImpl.c
source/dnode/vnode/src/meta/metaTDBImpl.c
+8
-8
source/dnode/vnode/src/meta/metaTable.c
source/dnode/vnode/src/meta/metaTable.c
+6
-6
source/dnode/vnode/src/tsdb/tsdbTDBImpl.c
source/dnode/vnode/src/tsdb/tsdbTDBImpl.c
+1
-1
source/libs/tdb/inc/tdb.h
source/libs/tdb/inc/tdb.h
+3
-1
source/libs/tdb/src/db/tdbBtree.c
source/libs/tdb/src/db/tdbBtree.c
+57
-0
source/libs/tdb/src/db/tdbDb.c
source/libs/tdb/src/db/tdbDb.c
+8
-1
source/libs/tdb/src/inc/tdbInt.h
source/libs/tdb/src/inc/tdbInt.h
+2
-0
source/libs/tdb/test/tdbTest.cpp
source/libs/tdb/test/tdbTest.cpp
+2
-2
未找到文件。
source/dnode/vnode/src/meta/metaTDBImpl.c
浏览文件 @
47410b16
...
...
@@ -289,7 +289,7 @@ int metaSaveTableToDB(SMeta *pMeta, STbCfg *pTbCfg, STbDdlH *pHandle) {
pVal
=
pBuf
=
buf
;
metaEncodeTbInfo
(
&
pBuf
,
pTbCfg
);
vLen
=
POINTER_DISTANCE
(
pBuf
,
buf
);
ret
=
tdbDb
Pu
t
(
pMetaDb
->
pTbDB
,
pKey
,
kLen
,
pVal
,
vLen
,
&
pMetaDb
->
txn
);
ret
=
tdbDb
Inser
t
(
pMetaDb
->
pTbDB
,
pKey
,
kLen
,
pVal
,
vLen
,
&
pMetaDb
->
txn
);
if
(
ret
<
0
)
{
return
-
1
;
}
...
...
@@ -311,7 +311,7 @@ int metaSaveTableToDB(SMeta *pMeta, STbCfg *pTbCfg, STbDdlH *pHandle) {
pVal
=
pBuf
=
buf
;
metaEncodeSchemaEx
(
&
pBuf
,
&
schemaWrapper
);
vLen
=
POINTER_DISTANCE
(
pBuf
,
buf
);
ret
=
tdbDb
Pu
t
(
pMetaDb
->
pSchemaDB
,
pKey
,
kLen
,
pVal
,
vLen
,
&
pMeta
->
pDB
->
txn
);
ret
=
tdbDb
Inser
t
(
pMetaDb
->
pSchemaDB
,
pKey
,
kLen
,
pVal
,
vLen
,
&
pMeta
->
pDB
->
txn
);
if
(
ret
<
0
)
{
return
-
1
;
}
...
...
@@ -325,7 +325,7 @@ int metaSaveTableToDB(SMeta *pMeta, STbCfg *pTbCfg, STbDdlH *pHandle) {
kLen
=
nameLen
+
1
+
sizeof
(
uid
);
pVal
=
NULL
;
vLen
=
0
;
ret
=
tdbDb
Pu
t
(
pMetaDb
->
pNameIdx
,
pKey
,
kLen
,
pVal
,
vLen
,
&
pMetaDb
->
txn
);
ret
=
tdbDb
Inser
t
(
pMetaDb
->
pNameIdx
,
pKey
,
kLen
,
pVal
,
vLen
,
&
pMetaDb
->
txn
);
if
(
ret
<
0
)
{
return
-
1
;
}
...
...
@@ -336,7 +336,7 @@ int metaSaveTableToDB(SMeta *pMeta, STbCfg *pTbCfg, STbDdlH *pHandle) {
kLen
=
sizeof
(
uid
);
pVal
=
NULL
;
vLen
=
0
;
ret
=
tdbDb
Pu
t
(
pMetaDb
->
pStbIdx
,
pKey
,
kLen
,
pVal
,
vLen
,
&
pMetaDb
->
txn
);
ret
=
tdbDb
Inser
t
(
pMetaDb
->
pStbIdx
,
pKey
,
kLen
,
pVal
,
vLen
,
&
pMetaDb
->
txn
);
if
(
ret
<
0
)
{
return
-
1
;
}
...
...
@@ -347,7 +347,7 @@ int metaSaveTableToDB(SMeta *pMeta, STbCfg *pTbCfg, STbDdlH *pHandle) {
kLen
=
sizeof
(
ctbIdxKey
);
pVal
=
NULL
;
vLen
=
0
;
ret
=
tdbDb
Pu
t
(
pMetaDb
->
pCtbIdx
,
pKey
,
kLen
,
pVal
,
vLen
,
&
pMetaDb
->
txn
);
ret
=
tdbDb
Inser
t
(
pMetaDb
->
pCtbIdx
,
pKey
,
kLen
,
pVal
,
vLen
,
&
pMetaDb
->
txn
);
if
(
ret
<
0
)
{
return
-
1
;
}
...
...
@@ -362,7 +362,7 @@ int metaSaveTableToDB(SMeta *pMeta, STbCfg *pTbCfg, STbDdlH *pHandle) {
kLen
=
sizeof
(
uid
);
pVal
=
NULL
;
vLen
=
0
;
ret
=
tdbDb
Pu
t
(
pMetaDb
->
pNtbIdx
,
pKey
,
kLen
,
pVal
,
vLen
,
&
pMetaDb
->
txn
);
ret
=
tdbDb
Inser
t
(
pMetaDb
->
pNtbIdx
,
pKey
,
kLen
,
pVal
,
vLen
,
&
pMetaDb
->
txn
);
if
(
ret
<
0
)
{
return
-
1
;
}
...
...
@@ -530,7 +530,7 @@ int metaSaveSmaToDB(SMeta *pMeta, STSma *pSmaCfg) {
int32_t
kLen
=
sizeof
(
pSmaCfg
->
indexUid
);
int32_t
vLen
=
POINTER_DISTANCE
(
qBuf
,
pBuf
);
ret
=
tdbDb
Pu
t
(
pMeta
->
pDB
->
pSmaDB
,
key
,
kLen
,
val
,
vLen
,
&
pMetaDb
->
txn
);
ret
=
tdbDb
Inser
t
(
pMeta
->
pDB
->
pSmaDB
,
key
,
kLen
,
val
,
vLen
,
&
pMetaDb
->
txn
);
if
(
ret
<
0
)
{
taosMemoryFreeClear
(
pBuf
);
return
-
1
;
...
...
@@ -545,7 +545,7 @@ int metaSaveSmaToDB(SMeta *pMeta, STSma *pSmaCfg) {
val
=
NULL
;
vLen
=
0
;
ret
=
tdbDb
Pu
t
(
pMeta
->
pDB
->
pSmaIdx
,
key
,
kLen
,
val
,
vLen
,
&
pMetaDb
->
txn
);
ret
=
tdbDb
Inser
t
(
pMeta
->
pDB
->
pSmaIdx
,
key
,
kLen
,
val
,
vLen
,
&
pMetaDb
->
txn
);
if
(
ret
<
0
)
{
taosMemoryFreeClear
(
pBuf
);
return
-
1
;
...
...
source/dnode/vnode/src/meta/metaTable.c
浏览文件 @
47410b16
...
...
@@ -218,7 +218,7 @@ static int metaSaveToTbDb(SMeta *pMeta, const SMetaEntry *pME) {
tCoderClear
(
&
coder
);
// write to table.db
if
(
tdbDb
Pu
t
(
pMeta
->
pTbDb
,
pKey
,
kLen
,
pVal
,
vLen
,
&
pMeta
->
txn
)
<
0
)
{
if
(
tdbDb
Inser
t
(
pMeta
->
pTbDb
,
pKey
,
kLen
,
pVal
,
vLen
,
&
pMeta
->
txn
)
<
0
)
{
goto
_err
;
}
...
...
@@ -231,11 +231,11 @@ _err:
}
static
int
metaUpdateUidIdx
(
SMeta
*
pMeta
,
const
SMetaEntry
*
pME
)
{
return
tdbDb
Pu
t
(
pMeta
->
pUidIdx
,
&
pME
->
uid
,
sizeof
(
tb_uid_t
),
&
pME
->
version
,
sizeof
(
int64_t
),
&
pMeta
->
txn
);
return
tdbDb
Inser
t
(
pMeta
->
pUidIdx
,
&
pME
->
uid
,
sizeof
(
tb_uid_t
),
&
pME
->
version
,
sizeof
(
int64_t
),
&
pMeta
->
txn
);
}
static
int
metaUpdateNameIdx
(
SMeta
*
pMeta
,
const
SMetaEntry
*
pME
)
{
return
tdbDb
Pu
t
(
pMeta
->
pNameIdx
,
pME
->
name
,
strlen
(
pME
->
name
)
+
1
,
&
pME
->
uid
,
sizeof
(
tb_uid_t
),
&
pMeta
->
txn
);
return
tdbDb
Inser
t
(
pMeta
->
pNameIdx
,
pME
->
name
,
strlen
(
pME
->
name
)
+
1
,
&
pME
->
uid
,
sizeof
(
tb_uid_t
),
&
pMeta
->
txn
);
}
static
int
metaUpdateTtlIdx
(
SMeta
*
pMeta
,
const
SMetaEntry
*
pME
)
{
...
...
@@ -258,12 +258,12 @@ static int metaUpdateTtlIdx(SMeta *pMeta, const SMetaEntry *pME) {
ttlKey
.
dtime
=
ctime
+
ttlDays
*
24
*
60
*
60
;
ttlKey
.
uid
=
pME
->
uid
;
return
tdbDb
Pu
t
(
pMeta
->
pTtlIdx
,
&
ttlKey
,
sizeof
(
ttlKey
),
NULL
,
0
,
&
pMeta
->
txn
);
return
tdbDb
Inser
t
(
pMeta
->
pTtlIdx
,
&
ttlKey
,
sizeof
(
ttlKey
),
NULL
,
0
,
&
pMeta
->
txn
);
}
static
int
metaUpdateCtbIdx
(
SMeta
*
pMeta
,
const
SMetaEntry
*
pME
)
{
SCtbIdxKey
ctbIdxKey
=
{.
suid
=
pME
->
ctbEntry
.
suid
,
.
uid
=
pME
->
uid
};
return
tdbDb
Pu
t
(
pMeta
->
pCtbIdx
,
&
ctbIdxKey
,
sizeof
(
ctbIdxKey
),
NULL
,
0
,
&
pMeta
->
txn
);
return
tdbDb
Inser
t
(
pMeta
->
pCtbIdx
,
&
ctbIdxKey
,
sizeof
(
ctbIdxKey
),
NULL
,
0
,
&
pMeta
->
txn
);
}
static
int
metaUpdateTagIdx
(
SMeta
*
pMeta
,
const
SMetaEntry
*
pME
)
{
...
...
@@ -304,7 +304,7 @@ static int metaSaveToSkmDb(SMeta *pMeta, const SMetaEntry *pME) {
tCoderInit
(
&
coder
,
TD_LITTLE_ENDIAN
,
pVal
,
vLen
,
TD_ENCODER
);
tEncodeSSchemaWrapper
(
&
coder
,
pSW
);
if
(
tdbDb
Pu
t
(
pMeta
->
pSkmDb
,
&
skmDbKey
,
sizeof
(
skmDbKey
),
pVal
,
vLen
,
&
pMeta
->
txn
)
<
0
)
{
if
(
tdbDb
Inser
t
(
pMeta
->
pSkmDb
,
&
skmDbKey
,
sizeof
(
skmDbKey
),
pVal
,
vLen
,
&
pMeta
->
txn
)
<
0
)
{
rcode
=
-
1
;
goto
_exit
;
}
...
...
source/dnode/vnode/src/tsdb/tsdbTDBImpl.c
浏览文件 @
47410b16
...
...
@@ -97,7 +97,7 @@ int32_t tsdbCloseDBF(SDBFile *pDBF) {
int32_t
tsdbSaveSmaToDB
(
SDBFile
*
pDBF
,
void
*
pKey
,
int32_t
keyLen
,
void
*
pVal
,
int32_t
valLen
,
TXN
*
txn
)
{
int32_t
ret
;
ret
=
tdbDb
Pu
t
(
pDBF
->
pDB
,
pKey
,
keyLen
,
pVal
,
valLen
,
txn
);
ret
=
tdbDb
Inser
t
(
pDBF
->
pDB
,
pKey
,
keyLen
,
pVal
,
valLen
,
txn
);
if
(
ret
<
0
)
{
tsdbError
(
"Failed to create insert sma data into db, ret = %d"
,
ret
);
return
-
1
;
...
...
source/libs/tdb/inc/tdb.h
浏览文件 @
47410b16
...
...
@@ -40,7 +40,9 @@ int tdbCommit(TENV *pEnv, TXN *pTxn);
int
tdbDbOpen
(
const
char
*
fname
,
int
keyLen
,
int
valLen
,
tdb_cmpr_fn_t
keyCmprFn
,
TENV
*
pEnv
,
TDB
**
ppDb
);
int
tdbDbClose
(
TDB
*
pDb
);
int
tdbDbDrop
(
TDB
*
pDb
);
int
tdbDbPut
(
TDB
*
pDb
,
const
void
*
pKey
,
int
keyLen
,
const
void
*
pVal
,
int
valLen
,
TXN
*
pTxn
);
int
tdbDbInsert
(
TDB
*
pDb
,
const
void
*
pKey
,
int
keyLen
,
const
void
*
pVal
,
int
valLen
,
TXN
*
pTxn
);
int
tdbDbDelete
(
TDB
*
pDb
,
const
void
*
pKey
,
int
kLen
,
TXN
*
pTxn
);
int
tdbUpsert
(
TDB
*
pTDb
,
const
void
*
pKey
,
int
kLen
,
const
void
*
pVal
,
int
vLen
,
TXN
*
pTxn
);
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
);
...
...
source/libs/tdb/src/db/tdbBtree.c
浏览文件 @
47410b16
...
...
@@ -202,6 +202,36 @@ int tdbBtreeInsert(SBTree *pBt, const void *pKey, int kLen, const void *pVal, in
return
0
;
}
int
tdbBtreeDelete
(
SBTree
*
pBt
,
const
void
*
pKey
,
int
kLen
,
TXN
*
pTxn
)
{
SBTC
btc
;
int
c
;
int
ret
;
tdbBtcOpen
(
&
btc
,
pBt
,
pTxn
);
// move the cursor
ret
=
tdbBtcMoveTo
(
&
btc
,
pKey
,
kLen
,
&
c
);
if
(
ret
<
0
)
{
tdbBtcClose
(
&
btc
);
ASSERT
(
0
);
return
-
1
;
}
if
(
btc
.
idx
<
0
||
c
!=
0
)
{
tdbBtcClose
(
&
btc
);
return
-
1
;
}
// delete the key
if
(
tdbBtcDelete
(
&
btc
)
<
0
)
{
tdbBtcClose
(
&
btc
);
return
-
1
;
}
tdbBtcClose
(
&
btc
);
return
0
;
}
int
tdbBtreeGet
(
SBTree
*
pBt
,
const
void
*
pKey
,
int
kLen
,
void
**
ppVal
,
int
*
vLen
)
{
return
tdbBtreePGet
(
pBt
,
pKey
,
kLen
,
NULL
,
NULL
,
ppVal
,
vLen
);
}
...
...
@@ -1363,6 +1393,33 @@ int tdbBtcGet(SBTC *pBtc, const void **ppKey, int *kLen, const void **ppVal, int
return
0
;
}
int
tdbBtcDelete
(
SBTC
*
pBtc
)
{
#if 0
// check transaction
if (!TDB_TXN_IS_WRITE(pBtc->pTxn)) {
return -1;
}
int idx = pBtc->idx;
int nCells = TDB_PAGE_TOTAL_CELLS(pBtc->pPage);
tdbPagerWrite(pBtc->pBt->pPager, pBtc->pPage);
tdbPageDropCell(pBtc->pPage, idx);
if (idx == nCells - 1) {
// drop cells above
for (;;) {
/* code */
}
// do balance
}
#endif
return
0
;
}
int
tdbBtcMoveTo
(
SBTC
*
pBtc
,
const
void
*
pKey
,
int
kLen
,
int
*
pCRst
)
{
int
ret
;
int
nCells
;
...
...
source/libs/tdb/src/db/tdbDb.c
浏览文件 @
47410b16
...
...
@@ -75,10 +75,17 @@ int tdbDbDrop(TDB *pDb) {
return
0
;
}
int
tdbDb
Pu
t
(
TDB
*
pDb
,
const
void
*
pKey
,
int
keyLen
,
const
void
*
pVal
,
int
valLen
,
TXN
*
pTxn
)
{
int
tdbDb
Inser
t
(
TDB
*
pDb
,
const
void
*
pKey
,
int
keyLen
,
const
void
*
pVal
,
int
valLen
,
TXN
*
pTxn
)
{
return
tdbBtreeInsert
(
pDb
->
pBt
,
pKey
,
keyLen
,
pVal
,
valLen
,
pTxn
);
}
int
tdbDbDelete
(
TDB
*
pDb
,
const
void
*
pKey
,
int
kLen
,
TXN
*
pTxn
)
{
return
tdbBtreeDelete
(
pDb
->
pBt
,
pKey
,
kLen
,
pTxn
);
}
int
tdbUpsert
(
TDB
*
pTDb
,
const
void
*
pKey
,
int
kLen
,
const
void
*
pVal
,
int
vLen
,
TXN
*
pTxn
)
{
// TODO
return
0
;
}
int
tdbDbGet
(
TDB
*
pDb
,
const
void
*
pKey
,
int
kLen
,
void
**
ppVal
,
int
*
vLen
)
{
return
tdbBtreeGet
(
pDb
->
pBt
,
pKey
,
kLen
,
ppVal
,
vLen
);
}
...
...
source/libs/tdb/src/inc/tdbInt.h
浏览文件 @
47410b16
...
...
@@ -128,6 +128,7 @@ struct SBTC {
int
tdbBtreeOpen
(
int
keyLen
,
int
valLen
,
SPager
*
pFile
,
tdb_cmpr_fn_t
kcmpr
,
SBTree
**
ppBt
);
int
tdbBtreeClose
(
SBTree
*
pBt
);
int
tdbBtreeInsert
(
SBTree
*
pBt
,
const
void
*
pKey
,
int
kLen
,
const
void
*
pVal
,
int
vLen
,
TXN
*
pTxn
);
int
tdbBtreeDelete
(
SBTree
*
pBt
,
const
void
*
pKey
,
int
kLen
,
TXN
*
pTxn
);
int
tdbBtreeGet
(
SBTree
*
pBt
,
const
void
*
pKey
,
int
kLen
,
void
**
ppVal
,
int
*
vLen
);
int
tdbBtreePGet
(
SBTree
*
pBt
,
const
void
*
pKey
,
int
kLen
,
void
**
ppKey
,
int
*
pkLen
,
void
**
ppVal
,
int
*
vLen
);
...
...
@@ -141,6 +142,7 @@ int tdbBtcMoveToNext(SBTC *pBtc);
int
tdbBtcMoveToPrev
(
SBTC
*
pBtc
);
int
tdbBtreeNext
(
SBTC
*
pBtc
,
void
**
ppKey
,
int
*
kLen
,
void
**
ppVal
,
int
*
vLen
);
int
tdbBtcGet
(
SBTC
*
pBtc
,
const
void
**
ppKey
,
int
*
kLen
,
const
void
**
ppVal
,
int
*
vLen
);
int
tdbBtcDelete
(
SBTC
*
pBtc
);
// tdbPager.c ====================================
...
...
source/libs/tdb/test/tdbTest.cpp
浏览文件 @
47410b16
...
...
@@ -152,7 +152,7 @@ TEST(tdb_test, simple_test) {
for
(
int
iData
=
1
;
iData
<=
nData
;
iData
++
)
{
sprintf
(
key
,
"key%d"
,
iData
);
sprintf
(
val
,
"value%d"
,
iData
);
ret
=
tdbDb
Pu
t
(
pDb
,
key
,
strlen
(
key
),
val
,
strlen
(
val
),
&
txn
);
ret
=
tdbDb
Inser
t
(
pDb
,
key
,
strlen
(
key
),
val
,
strlen
(
val
),
&
txn
);
GTEST_ASSERT_EQ
(
ret
,
0
);
// if pool is full, commit the transaction and start a new one
...
...
@@ -269,7 +269,7 @@ TEST(tdb_test, simple_test2) {
for
(
int
iData
=
1
;
iData
<=
nData
;
iData
++
)
{
sprintf
(
key
,
"key%d"
,
iData
);
sprintf
(
val
,
"value%d"
,
iData
);
ret
=
tdbDb
Pu
t
(
pDb
,
key
,
strlen
(
key
),
val
,
strlen
(
val
),
&
txn
);
ret
=
tdbDb
Inser
t
(
pDb
,
key
,
strlen
(
key
),
val
,
strlen
(
val
),
&
txn
);
GTEST_ASSERT_EQ
(
ret
,
0
);
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录