Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
54c26073
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看板
提交
54c26073
编写于
3月 08, 2022
作者:
M
Minghao Li
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
sync refactor
上级
ffe44230
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
102 addition
and
1 deletion
+102
-1
source/libs/sync/src/syncMain.c
source/libs/sync/src/syncMain.c
+55
-0
source/libs/sync/src/syncUtil.c
source/libs/sync/src/syncUtil.c
+1
-1
source/libs/sync/test/CMakeLists.txt
source/libs/sync/test/CMakeLists.txt
+14
-0
source/libs/sync/test/syncUtilTest.cpp
source/libs/sync/test/syncUtilTest.cpp
+32
-0
未找到文件。
source/libs/sync/src/syncMain.c
浏览文件 @
54c26073
...
@@ -231,6 +231,61 @@ cJSON* syncNode2Json(const SSyncNode* pSyncNode) {
...
@@ -231,6 +231,61 @@ cJSON* syncNode2Json(const SSyncNode* pSyncNode) {
// tla+ log vars
// tla+ log vars
// ping timer
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%p"
,
pSyncNode
->
pPingTimer
);
cJSON_AddStringToObject
(
pRoot
,
"pPingTimer"
,
u64buf
);
cJSON_AddNumberToObject
(
pRoot
,
"pingTimerMS"
,
pSyncNode
->
pingTimerMS
);
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%lu"
,
pSyncNode
->
pingTimerLogicClock
);
cJSON_AddStringToObject
(
pRoot
,
"pingTimerLogicClock"
,
u64buf
);
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%lu"
,
pSyncNode
->
pingTimerLogicClockUser
);
cJSON_AddStringToObject
(
pRoot
,
"pingTimerLogicClockUser"
,
u64buf
);
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%p"
,
pSyncNode
->
FpPingTimer
);
cJSON_AddStringToObject
(
pRoot
,
"FpPingTimer"
,
u64buf
);
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%lu"
,
pSyncNode
->
pingTimerCounter
);
cJSON_AddStringToObject
(
pRoot
,
"pingTimerCounter"
,
u64buf
);
// elect timer
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%p"
,
pSyncNode
->
pElectTimer
);
cJSON_AddStringToObject
(
pRoot
,
"pElectTimer"
,
u64buf
);
cJSON_AddNumberToObject
(
pRoot
,
"electTimerMS"
,
pSyncNode
->
electTimerMS
);
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%lu"
,
pSyncNode
->
electTimerLogicClock
);
cJSON_AddStringToObject
(
pRoot
,
"electTimerLogicClock"
,
u64buf
);
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%lu"
,
pSyncNode
->
electTimerLogicClockUser
);
cJSON_AddStringToObject
(
pRoot
,
"electTimerLogicClockUser"
,
u64buf
);
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%p"
,
pSyncNode
->
FpElectTimer
);
cJSON_AddStringToObject
(
pRoot
,
"FpElectTimer"
,
u64buf
);
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%lu"
,
pSyncNode
->
electTimerCounter
);
cJSON_AddStringToObject
(
pRoot
,
"electTimerCounter"
,
u64buf
);
// heartbeat timer
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%p"
,
pSyncNode
->
pHeartbeatTimer
);
cJSON_AddStringToObject
(
pRoot
,
"pHeartbeatTimer"
,
u64buf
);
cJSON_AddNumberToObject
(
pRoot
,
"heartbeatTimerMS"
,
pSyncNode
->
heartbeatTimerMS
);
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%lu"
,
pSyncNode
->
heartbeatTimerLogicClock
);
cJSON_AddStringToObject
(
pRoot
,
"heartbeatTimerLogicClock"
,
u64buf
);
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%lu"
,
pSyncNode
->
heartbeatTimerLogicClockUser
);
cJSON_AddStringToObject
(
pRoot
,
"heartbeatTimerLogicClockUser"
,
u64buf
);
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%p"
,
pSyncNode
->
FpHeartbeatTimer
);
cJSON_AddStringToObject
(
pRoot
,
"FpHeartbeatTimer"
,
u64buf
);
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%lu"
,
pSyncNode
->
heartbeatTimerCounter
);
cJSON_AddStringToObject
(
pRoot
,
"heartbeatTimerCounter"
,
u64buf
);
// callback
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%p"
,
pSyncNode
->
FpOnPing
);
cJSON_AddStringToObject
(
pRoot
,
"FpOnPing"
,
u64buf
);
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%p"
,
pSyncNode
->
FpOnPingReply
);
cJSON_AddStringToObject
(
pRoot
,
"FpOnPingReply"
,
u64buf
);
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%p"
,
pSyncNode
->
FpOnRequestVote
);
cJSON_AddStringToObject
(
pRoot
,
"FpOnRequestVote"
,
u64buf
);
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%p"
,
pSyncNode
->
FpOnRequestVoteReply
);
cJSON_AddStringToObject
(
pRoot
,
"FpOnRequestVoteReply"
,
u64buf
);
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%p"
,
pSyncNode
->
FpOnAppendEntries
);
cJSON_AddStringToObject
(
pRoot
,
"FpOnAppendEntries"
,
u64buf
);
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%p"
,
pSyncNode
->
FpOnAppendEntriesReply
);
cJSON_AddStringToObject
(
pRoot
,
"FpOnAppendEntriesReply"
,
u64buf
);
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%p"
,
pSyncNode
->
FpOnTimeout
);
cJSON_AddStringToObject
(
pRoot
,
"FpOnTimeout"
,
u64buf
);
cJSON
*
pJson
=
cJSON_CreateObject
();
cJSON
*
pJson
=
cJSON_CreateObject
();
cJSON_AddItemToObject
(
pJson
,
"SSyncNode"
,
pRoot
);
cJSON_AddItemToObject
(
pJson
,
"SSyncNode"
,
pRoot
);
return
pJson
;
return
pJson
;
...
...
source/libs/sync/src/syncUtil.c
浏览文件 @
54c26073
...
@@ -97,7 +97,7 @@ void syncUtilbufCopyDeep(const SSyncBuffer* src, SSyncBuffer* dest) {
...
@@ -97,7 +97,7 @@ void syncUtilbufCopyDeep(const SSyncBuffer* src, SSyncBuffer* dest) {
int32_t
syncUtilRand
(
int32_t
max
)
{
return
rand
()
%
max
;
}
int32_t
syncUtilRand
(
int32_t
max
)
{
return
rand
()
%
max
;
}
int32_t
syncUtilElectRandomMS
()
{
ELECT_TIMER_MS_MIN
+
syncUtilRand
(
ELECT_TIMER_MS_RANGE
);
}
int32_t
syncUtilElectRandomMS
()
{
return
ELECT_TIMER_MS_MIN
+
syncUtilRand
(
ELECT_TIMER_MS_RANGE
);
}
int32_t
syncUtilQuorum
(
int32_t
replicaNum
)
{
return
replicaNum
/
2
+
1
;
}
int32_t
syncUtilQuorum
(
int32_t
replicaNum
)
{
return
replicaNum
/
2
+
1
;
}
...
...
source/libs/sync/test/CMakeLists.txt
浏览文件 @
54c26073
...
@@ -11,6 +11,7 @@ add_executable(syncRaftStoreTest "")
...
@@ -11,6 +11,7 @@ add_executable(syncRaftStoreTest "")
add_executable
(
syncEnqTest
""
)
add_executable
(
syncEnqTest
""
)
add_executable
(
syncIndexTest
""
)
add_executable
(
syncIndexTest
""
)
add_executable
(
syncInitTest
""
)
add_executable
(
syncInitTest
""
)
add_executable
(
syncUtilTest
""
)
target_sources
(
syncTest
target_sources
(
syncTest
...
@@ -65,6 +66,10 @@ target_sources(syncInitTest
...
@@ -65,6 +66,10 @@ target_sources(syncInitTest
PRIVATE
PRIVATE
"syncInitTest.cpp"
"syncInitTest.cpp"
)
)
target_sources
(
syncUtilTest
PRIVATE
"syncUtilTest.cpp"
)
target_include_directories
(
syncTest
target_include_directories
(
syncTest
...
@@ -132,6 +137,11 @@ target_include_directories(syncInitTest
...
@@ -132,6 +137,11 @@ target_include_directories(syncInitTest
"
${
CMAKE_SOURCE_DIR
}
/include/libs/sync"
"
${
CMAKE_SOURCE_DIR
}
/include/libs/sync"
"
${
CMAKE_CURRENT_SOURCE_DIR
}
/../inc"
"
${
CMAKE_CURRENT_SOURCE_DIR
}
/../inc"
)
)
target_include_directories
(
syncUtilTest
PUBLIC
"
${
CMAKE_SOURCE_DIR
}
/include/libs/sync"
"
${
CMAKE_CURRENT_SOURCE_DIR
}
/../inc"
)
target_link_libraries
(
syncTest
target_link_libraries
(
syncTest
...
@@ -186,6 +196,10 @@ target_link_libraries(syncInitTest
...
@@ -186,6 +196,10 @@ target_link_libraries(syncInitTest
sync
sync
gtest_main
gtest_main
)
)
target_link_libraries
(
syncUtilTest
sync
gtest_main
)
enable_testing
()
enable_testing
()
...
...
source/libs/sync/test/syncUtilTest.cpp
0 → 100644
浏览文件 @
54c26073
#include "syncUtil.h"
//#include <gtest/gtest.h>
#include <stdio.h>
#include "syncIO.h"
#include "syncInt.h"
#include "syncRaftStore.h"
void
logTest
()
{
sTrace
(
"--- sync log test: trace"
);
sDebug
(
"--- sync log test: debug"
);
sInfo
(
"--- sync log test: info"
);
sWarn
(
"--- sync log test: warn"
);
sError
(
"--- sync log test: error"
);
sFatal
(
"--- sync log test: fatal"
);
}
void
electRandomMSTest
()
{
for
(
int
i
=
0
;
i
<
10
;
++
i
)
{
int32_t
ms
=
syncUtilElectRandomMS
();
printf
(
"syncUtilElectRandomMS: %d
\n
"
,
ms
);
}
}
int
main
()
{
// taosInitLog((char *)"syncTest.log", 100000, 10);
tsAsyncLog
=
0
;
sDebugFlag
=
143
+
64
;
logTest
();
electRandomMSTest
();
return
0
;
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录