Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
ef2b5958
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看板
提交
ef2b5958
编写于
4月 28, 2022
作者:
S
Shengliang Guan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
test: add unitest for sdb
上级
0faaa477
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
198 addition
and
35 deletion
+198
-35
source/dnode/mnode/impl/test/sdb/sdbTest.cpp
source/dnode/mnode/impl/test/sdb/sdbTest.cpp
+192
-32
source/dnode/mnode/sdb/src/sdb.c
source/dnode/mnode/sdb/src/sdb.c
+1
-1
source/dnode/mnode/sdb/src/sdbFile.c
source/dnode/mnode/sdb/src/sdbFile.c
+5
-1
source/dnode/mnode/sdb/src/sdbHash.c
source/dnode/mnode/sdb/src/sdbHash.c
+0
-1
未找到文件。
source/dnode/mnode/impl/test/sdb/sdbTest.cpp
浏览文件 @
ef2b5958
...
...
@@ -15,8 +15,31 @@
class
MndTestSdb
:
public
::
testing
::
Test
{
protected:
static
void
SetUpTestSuite
()
{}
static
void
TearDownTestSuite
()
{}
static
void
SetUpTestSuite
()
{
dDebugFlag
=
143
;
vDebugFlag
=
0
;
mDebugFlag
=
143
;
cDebugFlag
=
0
;
jniDebugFlag
=
0
;
tmrDebugFlag
=
135
;
uDebugFlag
=
135
;
rpcDebugFlag
=
143
;
qDebugFlag
=
0
;
wDebugFlag
=
0
;
sDebugFlag
=
0
;
tsdbDebugFlag
=
0
;
tsLogEmbedded
=
1
;
tsAsyncLog
=
0
;
const
char
*
path
=
"/tmp/td"
;
taosRemoveDir
(
path
);
taosMkDir
(
path
);
tstrncpy
(
tsLogDir
,
path
,
PATH_MAX
);
if
(
taosInitLog
(
"taosdlog"
,
1
)
!=
0
)
{
printf
(
"failed to init log file
\n
"
);
}
}
static
void
TearDownTestSuite
()
{
taosCloseLog
();
}
public:
void
SetUp
()
override
{}
...
...
@@ -26,6 +49,8 @@ class MndTestSdb : public ::testing::Test {
typedef
struct
SMnode
{
int32_t
v100
;
int32_t
v200
;
int32_t
insertTimes
;
int32_t
deleteTimes
;
SSdb
*
pSdb
;
}
SMnode
;
...
...
@@ -108,9 +133,19 @@ SSdbRow *strDecode(SSdbRaw *pRaw) {
return
pRow
;
}
int32_t
strInsert
(
SSdb
*
pSdb
,
SStrObj
*
pObj
)
{
return
0
;
}
int32_t
strInsert
(
SSdb
*
pSdb
,
SStrObj
*
pObj
)
{
SMnode
*
pMnode
=
pSdb
->
pMnode
;
pMnode
->
insertTimes
++
;
return
0
;
}
int32_t
strDelete
(
SSdb
*
pSdb
,
SStrObj
*
pObj
,
bool
callFunc
)
{
return
0
;
}
int32_t
strDelete
(
SSdb
*
pSdb
,
SStrObj
*
pObj
,
bool
callFunc
)
{
if
(
callFunc
)
{
SMnode
*
pMnode
=
pSdb
->
pMnode
;
pMnode
->
deleteTimes
++
;
}
return
0
;
}
int32_t
strUpdate
(
SSdb
*
pSdb
,
SStrObj
*
pOld
,
SStrObj
*
pNew
)
{
pOld
->
v8
=
pNew
->
v8
;
...
...
@@ -151,28 +186,30 @@ int32_t strDefault(SMnode *pMnode) {
bool
sdbTraverseSucc1
(
SMnode
*
pMnode
,
SStrObj
*
pObj
,
int32_t
*
p1
,
int32_t
*
p2
,
int32_t
*
p3
)
{
if
(
pObj
->
v8
==
1
)
{
*
p1
=
*
p2
+
*
p3
+
pObj
->
v8
;
*
p1
+
=
*
p2
+
*
p3
+
pObj
->
v8
;
}
return
true
;
}
bool
sdbTraverseSucc2
(
SMnode
*
pMnode
,
SStrObj
*
pObj
,
int32_t
*
p1
,
int32_t
*
p2
,
int32_t
*
p3
)
{
*
p1
=
*
p2
+
*
p3
+
pObj
->
v8
;
*
p1
+
=
*
p2
+
*
p3
+
pObj
->
v8
;
return
true
;
}
bool
sdbTraverseFail
(
SMnode
*
pMnode
,
SStrObj
*
pObj
,
int32_t
*
p1
,
int32_t
*
p2
,
int32_t
*
p3
)
{
*
p1
=
*
p2
+
*
p3
;
*
p1
+
=
*
p2
+
*
p3
;
return
false
;
}
TEST_F
(
MndTestSdb
,
01
_Write
)
{
void
*
pIter
;
int32_t
num
;
SStrObj
*
pObj
;
SMnode
mnode
;
SSdb
*
pSdb
;
void
*
pIter
=
NULL
;
int32_t
num
=
0
;
SStrObj
*
pObj
=
NULL
;
SMnode
mnode
=
{
0
}
;
SSdb
*
pSdb
=
NULL
;
SSdbOpt
opt
=
{
0
};
SStrObj
strObj
=
{
0
};
SSdbRaw
*
pRaw
=
NULL
;
int32_t
p1
=
0
;
int32_t
p2
=
111
;
int32_t
p3
=
222
;
...
...
@@ -200,7 +237,7 @@ TEST_F(MndTestSdb, 01_Write) {
ASSERT_NE
(
pSdb
,
nullptr
);
ASSERT_EQ
(
sdbSetTable
(
pSdb
,
strTable
),
0
);
ASSERT_EQ
(
sdbDeploy
(
pSdb
),
0
);
#if 0
pObj
=
(
SStrObj
*
)
sdbAcquire
(
pSdb
,
SDB_USER
,
"k1000"
);
ASSERT_NE
(
pObj
,
nullptr
);
EXPECT_STREQ
(
pObj
->
key
,
"k1000"
);
...
...
@@ -248,7 +285,7 @@ TEST_F(MndTestSdb, 01_Write) {
p1
=
0
;
p2
=
111
;
p3
=
222
;
sdbTraverse(pSdb, SDB_USER, (sdbTraverseFp)sdbTraverseSucc
2
, &p1, &p2, &p3);
sdbTraverse
(
pSdb
,
SDB_USER
,
(
sdbTraverseFp
)
sdbTraverseSucc
1
,
&
p1
,
&
p2
,
&
p3
);
EXPECT_EQ
(
p1
,
334
);
p1
=
0
;
...
...
@@ -265,34 +302,85 @@ TEST_F(MndTestSdb, 01_Write) {
EXPECT_EQ
(
sdbGetSize
(
pSdb
,
SDB_USER
),
2
);
EXPECT_EQ
(
sdbGetMaxId
(
pSdb
,
SDB_USER
),
-
1
);
EXPECT_EQ(sdbGetTableVer(pSdb, SDB_USER), 2);
EXPECT_EQ(sdbUpdateVer(pSdb, 0), 2);
EXPECT_EQ(sdbUpdateVer(pSdb, 1), 3);
EXPECT_EQ(sdbUpdateVer(pSdb, -1), 2);
EXPECT_EQ
(
sdbGetTableVer
(
pSdb
,
SDB_USER
),
1
);
EXPECT_EQ
(
sdbUpdateVer
(
pSdb
,
0
),
-
1
);
EXPECT_EQ
(
sdbUpdateVer
(
pSdb
,
1
),
0
);
EXPECT_EQ
(
sdbUpdateVer
(
pSdb
,
-
1
),
-
1
);
EXPECT_EQ
(
mnode
.
insertTimes
,
2
);
EXPECT_EQ
(
mnode
.
deleteTimes
,
0
);
// insert, call func
strSetDefault
(
&
strObj
,
3
);
pRaw
=
strEncode
(
&
strObj
);
sdbSetRawStatus
(
pRaw
,
SDB_STATUS_READY
);
ASSERT_EQ
(
sdbWrite
(
pSdb
,
pRaw
),
0
);
pObj
=
(
SStrObj
*
)
sdbAcquire
(
pSdb
,
SDB_USER
,
"k3000"
);
ASSERT_NE
(
pObj
,
nullptr
);
EXPECT_STREQ
(
pObj
->
key
,
"k3000"
);
EXPECT_STREQ
(
pObj
->
vstr
,
"v3000"
);
EXPECT_EQ
(
pObj
->
v8
,
3
);
EXPECT_EQ
(
pObj
->
v16
,
3
);
EXPECT_EQ
(
pObj
->
v32
,
3000
);
EXPECT_EQ
(
pObj
->
v64
,
3000
);
sdbRelease
(
pSdb
,
pObj
);
// update, call func
strSetDefault
(
&
strObj
,
3
);
strObj
.
v8
=
4
;
pRaw
=
strEncode
(
&
strObj
);
sdbSetRawStatus
(
pRaw
,
SDB_STATUS_READY
);
ASSERT_EQ
(
sdbWrite
(
pSdb
,
pRaw
),
0
);
pObj
=
(
SStrObj
*
)
sdbAcquire
(
pSdb
,
SDB_USER
,
"k3000"
);
ASSERT_NE
(
pObj
,
nullptr
);
EXPECT_STREQ
(
pObj
->
key
,
"k3000"
);
EXPECT_STREQ
(
pObj
->
vstr
,
"v3000"
);
EXPECT_EQ
(
pObj
->
v8
,
4
);
EXPECT_EQ
(
pObj
->
v16
,
3
);
EXPECT_EQ
(
pObj
->
v32
,
3000
);
EXPECT_EQ
(
pObj
->
v64
,
3000
);
sdbRelease
(
pSdb
,
pObj
);
EXPECT_EQ
(
sdbGetSize
(
pSdb
,
SDB_USER
),
3
);
EXPECT_EQ
(
sdbGetTableVer
(
pSdb
,
SDB_USER
),
3
);
EXPECT_EQ
(
sdbUpdateVer
(
pSdb
,
0
),
-
1
);
EXPECT_EQ
(
sdbUpdateVer
(
pSdb
,
1
),
0
);
EXPECT_EQ
(
sdbUpdateVer
(
pSdb
,
-
1
),
-
1
);
EXPECT_EQ
(
mnode
.
insertTimes
,
3
);
EXPECT_EQ
(
mnode
.
deleteTimes
,
0
);
// delete, call func 2
strSetDefault
(
&
strObj
,
3
);
strObj
.
v16
=
4
;
pRaw
=
strEncode
(
&
strObj
);
sdbSetRawStatus
(
pRaw
,
SDB_STATUS_DROPPED
);
ASSERT_EQ
(
sdbWrite
(
pSdb
,
pRaw
),
0
);
pObj
=
(
SStrObj
*
)
sdbAcquire
(
pSdb
,
SDB_USER
,
"k3000"
);
ASSERT_EQ
(
pObj
,
nullptr
);
EXPECT_EQ
(
sdbGetSize
(
pSdb
,
SDB_USER
),
2
);
EXPECT_EQ
(
sdbGetTableVer
(
pSdb
,
SDB_USER
),
4
);
EXPECT_EQ
(
mnode
.
insertTimes
,
3
);
EXPECT_EQ
(
mnode
.
deleteTimes
,
1
);
// write version
// sdb Write ver
// sdbRead
#endif
EXPECT_EQ
(
sdbUpdateVer
(
pSdb
,
1
),
0
);
EXPECT_EQ
(
sdbUpdateVer
(
pSdb
,
1
),
1
);
ASSERT_EQ
(
sdbWriteFile
(
pSdb
),
0
);
ASSERT_EQ
(
sdbWriteFile
(
pSdb
),
0
);
sdbCleanup
(
pSdb
);
EXPECT_EQ
(
mnode
.
insertTimes
,
3
);
EXPECT_EQ
(
mnode
.
deleteTimes
,
3
);
}
TEST_F
(
MndTestSdb
,
01
_Read
)
{
void
*
pIter
;
int32_t
num
;
SStrObj
*
pObj
;
SMnode
mnode
;
SSdb
*
pSdb
;
void
*
pIter
=
NULL
;
int32_t
num
=
0
;
SStrObj
*
pObj
=
NULL
;
SMnode
mnode
=
{
0
}
;
SSdb
*
pSdb
=
NULL
;
SSdbOpt
opt
=
{
0
};
SStrObj
strObj
=
{
0
};
SSdbRaw
*
pRaw
=
NULL
;
int32_t
p1
=
0
;
int32_t
p2
=
111
;
int32_t
p3
=
222
;
...
...
@@ -301,7 +389,6 @@ TEST_F(MndTestSdb, 01_Read) {
mnode
.
v200
=
200
;
opt
.
pMnode
=
&
mnode
;
opt
.
path
=
"/tmp/mnode_test_sdb"
;
taosRemoveDir
(
opt
.
path
);
SSdbTable
strTable
=
{
.
sdbType
=
SDB_USER
,
...
...
@@ -310,13 +397,86 @@ TEST_F(MndTestSdb, 01_Read) {
.
encodeFp
=
(
SdbEncodeFp
)
strEncode
,
.
decodeFp
=
(
SdbDecodeFp
)
strDecode
,
.
insertFp
=
(
SdbInsertFp
)
strInsert
,
.
updateFp
=
(
SdbUpdateFp
)
str
Dele
te
,
.
deleteFp
=
(
SdbDeleteFp
)
str
Upda
te
,
.
updateFp
=
(
SdbUpdateFp
)
str
Upda
te
,
.
deleteFp
=
(
SdbDeleteFp
)
str
Dele
te
,
};
pSdb
=
sdbInit
(
&
opt
);
mnode
.
pSdb
=
pSdb
;
ASSERT_NE
(
pSdb
,
nullptr
);
ASSERT_EQ
(
sdbSetTable
(
pSdb
,
strTable
),
0
);
ASSERT_EQ
(
sdbReadFile
(
pSdb
),
0
);
EXPECT_EQ
(
sdbGetSize
(
pSdb
,
SDB_USER
),
2
);
EXPECT_EQ
(
sdbGetMaxId
(
pSdb
,
SDB_USER
),
-
1
);
EXPECT_EQ
(
sdbGetTableVer
(
pSdb
,
SDB_USER
),
4
);
EXPECT_EQ
(
sdbUpdateVer
(
pSdb
,
0
),
1
);
EXPECT_EQ
(
mnode
.
insertTimes
,
2
);
EXPECT_EQ
(
mnode
.
deleteTimes
,
0
);
pObj
=
(
SStrObj
*
)
sdbAcquire
(
pSdb
,
SDB_USER
,
"k1000"
);
ASSERT_NE
(
pObj
,
nullptr
);
EXPECT_STREQ
(
pObj
->
key
,
"k1000"
);
EXPECT_STREQ
(
pObj
->
vstr
,
"v1000"
);
EXPECT_EQ
(
pObj
->
v8
,
1
);
EXPECT_EQ
(
pObj
->
v16
,
1
);
EXPECT_EQ
(
pObj
->
v32
,
1000
);
EXPECT_EQ
(
pObj
->
v64
,
1000
);
sdbRelease
(
pSdb
,
pObj
);
pObj
=
(
SStrObj
*
)
sdbAcquire
(
pSdb
,
SDB_USER
,
"k2000"
);
ASSERT_NE
(
pObj
,
nullptr
);
EXPECT_STREQ
(
pObj
->
key
,
"k2000"
);
EXPECT_STREQ
(
pObj
->
vstr
,
"v2000"
);
EXPECT_EQ
(
pObj
->
v8
,
2
);
EXPECT_EQ
(
pObj
->
v16
,
2
);
EXPECT_EQ
(
pObj
->
v32
,
2000
);
EXPECT_EQ
(
pObj
->
v64
,
2000
);
sdbRelease
(
pSdb
,
pObj
);
pObj
=
(
SStrObj
*
)
sdbAcquire
(
pSdb
,
SDB_USER
,
"k200"
);
ASSERT_EQ
(
pObj
,
nullptr
);
pIter
=
NULL
;
num
=
0
;
do
{
pIter
=
sdbFetch
(
pSdb
,
SDB_USER
,
pIter
,
(
void
**
)
&
pObj
);
if
(
pIter
==
NULL
)
break
;
ASSERT_NE
(
pObj
,
nullptr
);
num
++
;
sdbRelease
(
pSdb
,
pObj
);
}
while
(
1
);
EXPECT_EQ
(
num
,
2
);
do
{
pIter
=
sdbFetch
(
pSdb
,
SDB_USER
,
pIter
,
(
void
**
)
&
pObj
);
if
(
pIter
==
NULL
)
break
;
if
(
strcmp
(
pObj
->
key
,
"k1000"
)
==
0
)
{
sdbCancelFetch
(
pSdb
,
pIter
);
break
;
}
}
while
(
1
);
EXPECT_STREQ
(
pObj
->
key
,
"k1000"
);
p1
=
0
;
p2
=
111
;
p3
=
222
;
sdbTraverse
(
pSdb
,
SDB_USER
,
(
sdbTraverseFp
)
sdbTraverseSucc1
,
&
p1
,
&
p2
,
&
p3
);
EXPECT_EQ
(
p1
,
334
);
p1
=
0
;
p2
=
111
;
p3
=
222
;
sdbTraverse
(
pSdb
,
SDB_USER
,
(
sdbTraverseFp
)
sdbTraverseSucc2
,
&
p1
,
&
p2
,
&
p3
);
EXPECT_EQ
(
p1
,
669
);
p1
=
0
;
p2
=
111
;
p3
=
222
;
sdbTraverse
(
pSdb
,
SDB_USER
,
(
sdbTraverseFp
)
sdbTraverseFail
,
&
p1
,
&
p2
,
&
p3
);
EXPECT_EQ
(
p1
,
333
);
sdbCleanup
(
pSdb
);
EXPECT_EQ
(
mnode
.
insertTimes
,
2
);
EXPECT_EQ
(
mnode
.
deleteTimes
,
2
);
}
\ No newline at end of file
source/dnode/mnode/sdb/src/sdb.c
浏览文件 @
ef2b5958
...
...
@@ -99,7 +99,7 @@ void sdbCleanup(SSdb *pSdb) {
taosHashClear
(
hash
);
taosHashCleanup
(
hash
);
pSdb
->
hashObjs
[
i
]
=
NULL
;
mDebug
(
"sdb table:%
d is cleaned up"
,
i
);
mDebug
(
"sdb table:%
s is cleaned up"
,
sdbTableName
(
i
)
);
}
taosMemoryFree
(
pSdb
);
...
...
source/dnode/mnode/sdb/src/sdbFile.c
浏览文件 @
ef2b5958
...
...
@@ -18,7 +18,7 @@
#include "tchecksum.h"
#include "wal.h"
#define SDB_TABLE_SIZE 24
#define SDB_TABLE_SIZE
24
#define SDB_RESERVE_SIZE 512
static
int32_t
sdbRunDeployFp
(
SSdb
*
pSdb
)
{
...
...
@@ -165,6 +165,9 @@ int32_t sdbReadFile(SSdb *pSdb) {
return
-
1
;
}
int64_t
tableVer
[
SDB_MAX
]
=
{
0
};
memcpy
(
tableVer
,
pSdb
->
tableVer
,
sizeof
(
tableVer
));
while
(
1
)
{
readLen
=
sizeof
(
SSdbRaw
);
ret
=
taosReadFile
(
pFile
,
pRaw
,
readLen
);
...
...
@@ -212,6 +215,7 @@ int32_t sdbReadFile(SSdb *pSdb) {
code
=
0
;
pSdb
->
lastCommitVer
=
pSdb
->
curVer
;
memcpy
(
pSdb
->
tableVer
,
tableVer
,
sizeof
(
tableVer
));
mDebug
(
"read file:%s successfully, ver:%"
PRId64
,
file
,
pSdb
->
lastCommitVer
);
PARSE_SDB_DATA_ERROR:
...
...
source/dnode/mnode/sdb/src/sdbHash.c
浏览文件 @
ef2b5958
...
...
@@ -231,7 +231,6 @@ static int32_t sdbDeleteRow(SSdb *pSdb, SHashObj *hash, SSdbRaw *pRaw, SSdbRow *
sdbFreeRow
(
pSdb
,
pRow
,
false
);
sdbCheck
(
pSdb
,
pOldRow
);
// sdbRelease(pSdb, pOldRow->pObj);
return
0
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录