Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
39d0b652
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1187
Star
22018
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看板
提交
39d0b652
编写于
6月 08, 2022
作者:
M
Minghao Li
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactor(sync): add raft log test
上级
687caac2
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
67 addition
and
16 deletion
+67
-16
source/libs/sync/src/syncRaftLog.c
source/libs/sync/src/syncRaftLog.c
+1
-1
source/libs/sync/test/syncRaftLogTest2.cpp
source/libs/sync/test/syncRaftLogTest2.cpp
+15
-15
source/libs/sync/test/syncRaftLogTest3.cpp
source/libs/sync/test/syncRaftLogTest3.cpp
+51
-0
未找到文件。
source/libs/sync/src/syncRaftLog.c
浏览文件 @
39d0b652
...
...
@@ -67,7 +67,7 @@ static SyncIndex raftLogEndIndex(struct SSyncLogStore* pLogStore) { return raftL
static
bool
raftLogIsEmpty
(
struct
SSyncLogStore
*
pLogStore
)
{
SyncIndex
beginIndex
=
raftLogBeginIndex
(
pLogStore
);
SyncIndex
endIndex
=
raftLogEndIndex
(
pLogStore
);
return
(
endIndex
>=
beginIndex
);
return
(
endIndex
<
beginIndex
);
}
static
int32_t
raftLogEntryCount
(
struct
SSyncLogStore
*
pLogStore
)
{
...
...
source/libs/sync/test/syncRaftLogTest2.cpp
浏览文件 @
39d0b652
...
...
@@ -76,7 +76,7 @@ void test1() {
assert
(
pLogStore
->
syncLogEndIndex
(
pLogStore
)
==
-
1
);
assert
(
pLogStore
->
syncLogEntryCount
(
pLogStore
)
==
0
);
assert
(
pLogStore
->
syncLogWriteIndex
(
pLogStore
)
==
0
);
assert
(
pLogStore
->
syncLogIsEmpty
(
pLogStore
)
==
0
);
assert
(
pLogStore
->
syncLogIsEmpty
(
pLogStore
)
==
1
);
assert
(
pLogStore
->
syncLogLastIndex
(
pLogStore
)
==
-
1
);
assert
(
pLogStore
->
syncLogLastTerm
(
pLogStore
)
==
0
);
}
...
...
@@ -95,7 +95,7 @@ void test1() {
assert
(
pLogStore
->
syncLogEndIndex
(
pLogStore
)
==
-
1
);
assert
(
pLogStore
->
syncLogEntryCount
(
pLogStore
)
==
0
);
assert
(
pLogStore
->
syncLogWriteIndex
(
pLogStore
)
==
0
);
assert
(
pLogStore
->
syncLogIsEmpty
(
pLogStore
)
==
0
);
assert
(
pLogStore
->
syncLogIsEmpty
(
pLogStore
)
==
1
);
assert
(
pLogStore
->
syncLogLastIndex
(
pLogStore
)
==
-
1
);
assert
(
pLogStore
->
syncLogLastTerm
(
pLogStore
)
==
0
);
}
...
...
@@ -118,7 +118,7 @@ void test2() {
assert
(
pLogStore
->
syncLogEndIndex
(
pLogStore
)
==
-
1
);
assert
(
pLogStore
->
syncLogEntryCount
(
pLogStore
)
==
0
);
assert
(
pLogStore
->
syncLogWriteIndex
(
pLogStore
)
==
5
);
assert
(
pLogStore
->
syncLogIsEmpty
(
pLogStore
)
==
0
);
assert
(
pLogStore
->
syncLogIsEmpty
(
pLogStore
)
==
1
);
assert
(
pLogStore
->
syncLogLastIndex
(
pLogStore
)
==
-
1
);
assert
(
pLogStore
->
syncLogLastTerm
(
pLogStore
)
==
0
);
}
...
...
@@ -137,7 +137,7 @@ void test2() {
assert
(
pLogStore
->
syncLogEndIndex
(
pLogStore
)
==
-
1
);
assert
(
pLogStore
->
syncLogEntryCount
(
pLogStore
)
==
0
);
assert
(
pLogStore
->
syncLogWriteIndex
(
pLogStore
)
==
5
);
assert
(
pLogStore
->
syncLogIsEmpty
(
pLogStore
)
==
0
);
assert
(
pLogStore
->
syncLogIsEmpty
(
pLogStore
)
==
1
);
assert
(
pLogStore
->
syncLogLastIndex
(
pLogStore
)
==
-
1
);
assert
(
pLogStore
->
syncLogLastTerm
(
pLogStore
)
==
0
);
}
...
...
@@ -159,7 +159,7 @@ void test3() {
assert
(
pLogStore
->
syncLogEndIndex
(
pLogStore
)
==
-
1
);
assert
(
pLogStore
->
syncLogEntryCount
(
pLogStore
)
==
0
);
assert
(
pLogStore
->
syncLogWriteIndex
(
pLogStore
)
==
0
);
assert
(
pLogStore
->
syncLogIsEmpty
(
pLogStore
)
==
0
);
assert
(
pLogStore
->
syncLogIsEmpty
(
pLogStore
)
==
1
);
assert
(
pLogStore
->
syncLogLastIndex
(
pLogStore
)
==
-
1
);
assert
(
pLogStore
->
syncLogLastTerm
(
pLogStore
)
==
0
);
}
...
...
@@ -186,7 +186,7 @@ void test3() {
assert
(
pLogStore
->
syncLogEndIndex
(
pLogStore
)
==
4
);
assert
(
pLogStore
->
syncLogEntryCount
(
pLogStore
)
==
5
);
assert
(
pLogStore
->
syncLogWriteIndex
(
pLogStore
)
==
5
);
assert
(
pLogStore
->
syncLogIsEmpty
(
pLogStore
)
==
1
);
assert
(
pLogStore
->
syncLogIsEmpty
(
pLogStore
)
==
0
);
assert
(
pLogStore
->
syncLogLastIndex
(
pLogStore
)
==
4
);
assert
(
pLogStore
->
syncLogLastTerm
(
pLogStore
)
==
104
);
}
...
...
@@ -205,7 +205,7 @@ void test3() {
assert
(
pLogStore
->
syncLogEndIndex
(
pLogStore
)
==
4
);
assert
(
pLogStore
->
syncLogEntryCount
(
pLogStore
)
==
5
);
assert
(
pLogStore
->
syncLogWriteIndex
(
pLogStore
)
==
5
);
assert
(
pLogStore
->
syncLogIsEmpty
(
pLogStore
)
==
1
);
assert
(
pLogStore
->
syncLogIsEmpty
(
pLogStore
)
==
0
);
assert
(
pLogStore
->
syncLogLastIndex
(
pLogStore
)
==
4
);
assert
(
pLogStore
->
syncLogLastTerm
(
pLogStore
)
==
104
);
}
...
...
@@ -245,7 +245,7 @@ void test4() {
assert
(
pLogStore
->
syncLogEndIndex
(
pLogStore
)
==
9
);
assert
(
pLogStore
->
syncLogEntryCount
(
pLogStore
)
==
5
);
assert
(
pLogStore
->
syncLogWriteIndex
(
pLogStore
)
==
10
);
assert
(
pLogStore
->
syncLogIsEmpty
(
pLogStore
)
==
1
);
assert
(
pLogStore
->
syncLogIsEmpty
(
pLogStore
)
==
0
);
assert
(
pLogStore
->
syncLogLastIndex
(
pLogStore
)
==
9
);
assert
(
pLogStore
->
syncLogLastTerm
(
pLogStore
)
==
109
);
}
...
...
@@ -264,7 +264,7 @@ void test4() {
assert
(
pLogStore
->
syncLogEndIndex
(
pLogStore
)
==
9
);
assert
(
pLogStore
->
syncLogEntryCount
(
pLogStore
)
==
5
);
assert
(
pLogStore
->
syncLogWriteIndex
(
pLogStore
)
==
10
);
assert
(
pLogStore
->
syncLogIsEmpty
(
pLogStore
)
==
1
);
assert
(
pLogStore
->
syncLogIsEmpty
(
pLogStore
)
==
0
);
assert
(
pLogStore
->
syncLogLastIndex
(
pLogStore
)
==
9
);
assert
(
pLogStore
->
syncLogLastTerm
(
pLogStore
)
==
109
);
}
...
...
@@ -304,7 +304,7 @@ void test5() {
assert
(
pLogStore
->
syncLogEndIndex
(
pLogStore
)
==
9
);
assert
(
pLogStore
->
syncLogEntryCount
(
pLogStore
)
==
5
);
assert
(
pLogStore
->
syncLogWriteIndex
(
pLogStore
)
==
10
);
assert
(
pLogStore
->
syncLogIsEmpty
(
pLogStore
)
==
1
);
assert
(
pLogStore
->
syncLogIsEmpty
(
pLogStore
)
==
0
);
assert
(
pLogStore
->
syncLogLastIndex
(
pLogStore
)
==
9
);
assert
(
pLogStore
->
syncLogLastTerm
(
pLogStore
)
==
109
);
}
...
...
@@ -317,7 +317,7 @@ void test5() {
assert
(
pLogStore
->
syncLogEndIndex
(
pLogStore
)
==
6
);
assert
(
pLogStore
->
syncLogEntryCount
(
pLogStore
)
==
2
);
assert
(
pLogStore
->
syncLogWriteIndex
(
pLogStore
)
==
7
);
assert
(
pLogStore
->
syncLogIsEmpty
(
pLogStore
)
==
1
);
assert
(
pLogStore
->
syncLogIsEmpty
(
pLogStore
)
==
0
);
assert
(
pLogStore
->
syncLogLastIndex
(
pLogStore
)
==
6
);
assert
(
pLogStore
->
syncLogLastTerm
(
pLogStore
)
==
106
);
}
...
...
@@ -336,7 +336,7 @@ void test5() {
assert
(
pLogStore
->
syncLogEndIndex
(
pLogStore
)
==
6
);
assert
(
pLogStore
->
syncLogEntryCount
(
pLogStore
)
==
2
);
assert
(
pLogStore
->
syncLogWriteIndex
(
pLogStore
)
==
7
);
assert
(
pLogStore
->
syncLogIsEmpty
(
pLogStore
)
==
1
);
assert
(
pLogStore
->
syncLogIsEmpty
(
pLogStore
)
==
0
);
assert
(
pLogStore
->
syncLogLastIndex
(
pLogStore
)
==
6
);
assert
(
pLogStore
->
syncLogLastTerm
(
pLogStore
)
==
106
);
}
...
...
@@ -376,7 +376,7 @@ void test6() {
assert
(
pLogStore
->
syncLogEndIndex
(
pLogStore
)
==
9
);
assert
(
pLogStore
->
syncLogEntryCount
(
pLogStore
)
==
5
);
assert
(
pLogStore
->
syncLogWriteIndex
(
pLogStore
)
==
10
);
assert
(
pLogStore
->
syncLogIsEmpty
(
pLogStore
)
==
1
);
assert
(
pLogStore
->
syncLogIsEmpty
(
pLogStore
)
==
0
);
assert
(
pLogStore
->
syncLogLastIndex
(
pLogStore
)
==
9
);
assert
(
pLogStore
->
syncLogLastTerm
(
pLogStore
)
==
109
);
}
...
...
@@ -389,7 +389,7 @@ void test6() {
assert
(
pLogStore
->
syncLogEndIndex
(
pLogStore
)
==
-
1
);
assert
(
pLogStore
->
syncLogEntryCount
(
pLogStore
)
==
0
);
assert
(
pLogStore
->
syncLogWriteIndex
(
pLogStore
)
==
5
);
assert
(
pLogStore
->
syncLogIsEmpty
(
pLogStore
)
==
0
);
assert
(
pLogStore
->
syncLogIsEmpty
(
pLogStore
)
==
1
);
assert
(
pLogStore
->
syncLogLastIndex
(
pLogStore
)
==
-
1
);
assert
(
pLogStore
->
syncLogLastTerm
(
pLogStore
)
==
0
);
}
...
...
@@ -408,7 +408,7 @@ void test6() {
assert
(
pLogStore
->
syncLogEndIndex
(
pLogStore
)
==
-
1
);
assert
(
pLogStore
->
syncLogEntryCount
(
pLogStore
)
==
0
);
assert
(
pLogStore
->
syncLogWriteIndex
(
pLogStore
)
==
5
);
assert
(
pLogStore
->
syncLogIsEmpty
(
pLogStore
)
==
0
);
assert
(
pLogStore
->
syncLogIsEmpty
(
pLogStore
)
==
1
);
assert
(
pLogStore
->
syncLogLastIndex
(
pLogStore
)
==
-
1
);
assert
(
pLogStore
->
syncLogLastTerm
(
pLogStore
)
==
0
);
}
...
...
source/libs/sync/test/syncRaftLogTest3.cpp
浏览文件 @
39d0b652
...
...
@@ -17,6 +17,8 @@ void logTest() {
sFatal
(
"--- sync log test: fatal"
);
}
bool
gAssert
=
true
;
SSyncNode
*
pSyncNode
;
SWal
*
pWal
;
SSyncLogStore
*
pLogStore
;
...
...
@@ -98,6 +100,14 @@ void test1() {
sTrace
(
"%ld's preIndex: %ld"
,
testIndex
,
preIndex
);
sTrace
(
"%ld's preTerm: %lu"
,
testIndex
,
preTerm
);
if
(
gAssert
)
{
assert
(
lastIndex
==
-
1
);
assert
(
lastTerm
==
0
);
assert
(
syncStartIndex
==
0
);
assert
(
preIndex
==
-
1
);
assert
(
preTerm
==
0
);
}
logStoreDestory
(
pLogStore
);
cleanup
();
}
...
...
@@ -150,12 +160,26 @@ void test2() {
sTrace
(
"lastTerm: %lu"
,
lastTerm
);
sTrace
(
"syncStartIndex: %ld"
,
syncStartIndex
);
if
(
gAssert
)
{
assert
(
lastIndex
==
10
);
assert
(
lastTerm
==
110
);
assert
(
syncStartIndex
==
11
);
}
for
(
SyncIndex
i
=
11
;
i
>=
0
;
--
i
)
{
SyncIndex
preIndex
=
syncNodeGetPreIndex
(
pSyncNode
,
i
);
SyncTerm
preTerm
=
syncNodeGetPreTerm
(
pSyncNode
,
i
);
sTrace
(
"%ld's preIndex: %ld"
,
i
,
preIndex
);
sTrace
(
"%ld's preTerm: %lu"
,
i
,
preTerm
);
if
(
gAssert
)
{
SyncIndex
preIndexArr
[
12
]
=
{
-
1
,
0
,
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
,
10
};
SyncTerm
preTermArr
[
12
]
=
{
0
,
100
,
101
,
102
,
103
,
104
,
105
,
106
,
107
,
108
,
109
,
110
};
assert
(
preIndex
==
preIndexArr
[
i
]);
assert
(
preTerm
==
preTermArr
[
i
]);
}
}
logStoreDestory
(
pLogStore
);
...
...
@@ -198,6 +222,14 @@ void test3() {
sTrace
(
"%d's preIndex: %ld"
,
6
,
preIndex
);
sTrace
(
"%d's preTerm: %lu"
,
6
,
preTerm
);
if
(
gAssert
)
{
assert
(
lastIndex
==
5
);
assert
(
lastTerm
==
100
);
assert
(
syncStartIndex
==
6
);
assert
(
preIndex
==
5
);
assert
(
preTerm
==
100
);
}
logStoreDestory
(
pLogStore
);
cleanup
();
}
...
...
@@ -250,6 +282,12 @@ void test4() {
sTrace
(
"lastTerm: %lu"
,
lastTerm
);
sTrace
(
"syncStartIndex: %ld"
,
syncStartIndex
);
if
(
gAssert
)
{
assert
(
lastIndex
==
10
);
assert
(
lastTerm
==
110
);
assert
(
syncStartIndex
==
11
);
}
for
(
SyncIndex
i
=
11
;
i
>=
6
;
--
i
)
{
SyncIndex
preIndex
=
syncNodeGetPreIndex
(
pSyncNode
,
i
);
SyncTerm
preTerm
=
syncNodeGetPreTerm
(
pSyncNode
,
i
);
...
...
@@ -317,6 +355,14 @@ void test5() {
sTrace
(
"%ld's preIndex: %ld"
,
i
,
preIndex
);
sTrace
(
"%ld's preTerm: %lu"
,
i
,
preTerm
);
if
(
gAssert
)
{
SyncIndex
preIndexArr
[
12
]
=
{
9999
,
9999
,
9999
,
9999
,
9999
,
9999
,
5
,
6
,
7
,
8
,
9
,
10
};
SyncTerm
preTermArr
[
12
]
=
{
9999
,
9999
,
9999
,
9999
,
9999
,
9999
,
100
,
106
,
107
,
108
,
109
,
110
};
assert
(
preIndex
==
preIndexArr
[
i
]);
assert
(
preTerm
==
preTermArr
[
i
]);
}
}
logStoreDestory
(
pLogStore
);
...
...
@@ -327,6 +373,11 @@ int main(int argc, char** argv) {
tsAsyncLog
=
0
;
sDebugFlag
=
DEBUG_TRACE
+
DEBUG_INFO
+
DEBUG_SCREEN
+
DEBUG_FILE
;
if
(
argc
==
2
)
{
gAssert
=
atoi
(
argv
[
1
]);
}
sTrace
(
"gAssert : %d"
,
gAssert
);
test1
();
test2
();
test3
();
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录