Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
2fcc970d
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看板
提交
2fcc970d
编写于
3月 09, 2022
作者:
M
Minghao Li
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
sync refactor
上级
d3b1d5d8
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
25 addition
and
36 deletion
+25
-36
source/libs/sync/inc/syncInt.h
source/libs/sync/inc/syncInt.h
+5
-2
source/libs/sync/src/syncIndexMgr.c
source/libs/sync/src/syncIndexMgr.c
+3
-2
source/libs/sync/test/syncIndexMgrTest.cpp
source/libs/sync/test/syncIndexMgrTest.cpp
+17
-32
未找到文件。
source/libs/sync/inc/syncInt.h
浏览文件 @
2fcc970d
...
...
@@ -103,6 +103,9 @@ typedef struct SVotesGranted SVotesGranted;
struct
SVotesRespond
;
typedef
struct
SVotesRespond
SVotesRespond
;
struct
SSyncIndexMgr
;
typedef
struct
SSyncIndexMgr
SSyncIndexMgr
;
typedef
struct
SRaftId
{
SyncNodeId
addr
;
// typedef uint64_t SyncNodeId;
SyncGroupId
vgId
;
// typedef int32_t SyncGroupId;
...
...
@@ -148,8 +151,8 @@ typedef struct SSyncNode {
SVotesRespond
*
pVotesRespond
;
// tla+ leader vars
S
HashObj
*
pNextIndex
;
S
HashObj
*
pMatchIndex
;
S
SyncIndexMgr
*
pNextIndex
;
S
SyncIndexMgr
*
pMatchIndex
;
// tla+ log vars
SSyncLogStore
*
pLogStore
;
...
...
source/libs/sync/src/syncIndexMgr.c
浏览文件 @
2fcc970d
...
...
@@ -81,8 +81,9 @@ cJSON *syncIndexMgr2Json(SSyncIndexMgr *pSyncIndexMgr) {
for
(
int
i
=
0
;
i
<
pSyncIndexMgr
->
replicaNum
;
++
i
)
{
arr
[
i
]
=
pSyncIndexMgr
->
index
[
i
];
}
cJSON
*
pI
sRespond
=
cJSON_CreateIntArray
(
arr
,
pSyncIndexMgr
->
replicaNum
);
cJSON
*
pI
ndex
=
cJSON_CreateIntArray
(
arr
,
pSyncIndexMgr
->
replicaNum
);
free
(
arr
);
cJSON_AddItemToObject
(
pRoot
,
"index"
,
pIndex
);
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%p"
,
pSyncIndexMgr
->
pSyncNode
);
cJSON_AddStringToObject
(
pRoot
,
"pSyncNode"
,
u64buf
);
...
...
@@ -93,7 +94,7 @@ cJSON *syncIndexMgr2Json(SSyncIndexMgr *pSyncIndexMgr) {
char
*
syncIndexMgr2Str
(
SSyncIndexMgr
*
pSyncIndexMgr
)
{
cJSON
*
pJson
=
syncIndexMgr2Json
(
pSyncIndexMgr
);
char
*
serialized
=
cJSON_Print
(
pJson
);
char
*
serialized
=
cJSON_Print
(
pJson
);
cJSON_Delete
(
pJson
);
return
serialized
;
}
\ No newline at end of file
source/libs/sync/test/syncIndexMgrTest.cpp
浏览文件 @
2fcc970d
#include <gtest/gtest.h>
#include "syncIndexMgr.h"
//#include <gtest/gtest.h>
#include <stdio.h>
#include "syncEnv.h"
#include "syncIO.h"
...
...
@@ -97,60 +98,44 @@ int main(int argc, char** argv) {
initRaftId
(
pSyncNode
);
S
VotesGranted
*
pVotesGranted
=
voteGranted
Create
(
pSyncNode
);
assert
(
p
VotesGranted
!=
NULL
);
S
SyncIndexMgr
*
pSyncIndexMgr
=
syncIndexMgr
Create
(
pSyncNode
);
assert
(
p
SyncIndexMgr
!=
NULL
);
printf
(
"---------------------------------------
\n
"
);
{
char
*
serialized
=
voteGranted2Str
(
pVotesGranted
);
char
*
serialized
=
syncIndexMgr2Str
(
pSyncIndexMgr
);
assert
(
serialized
!=
NULL
);
printf
(
"%s
\n
"
,
serialized
);
free
(
serialized
);
}
SyncTerm
term
=
1234
;
syncIndexMgrSetIndex
(
pSyncIndexMgr
,
&
ids
[
0
],
100
);
syncIndexMgrSetIndex
(
pSyncIndexMgr
,
&
ids
[
1
],
200
);
syncIndexMgrSetIndex
(
pSyncIndexMgr
,
&
ids
[
2
],
300
);
printf
(
"---------------------------------------
\n
"
);
voteGrantedReset
(
pVotesGranted
,
term
);
{
char
*
serialized
=
voteGranted2Str
(
pVotesGranted
);
char
*
serialized
=
syncIndexMgr2Str
(
pSyncIndexMgr
);
assert
(
serialized
!=
NULL
);
printf
(
"%s
\n
"
,
serialized
);
free
(
serialized
);
}
for
(
int
i
=
0
;
i
<
replicaNum
;
++
i
)
{
SyncRequestVoteReply
*
reply
=
SyncRequestVoteReplyBuild
();
reply
->
destId
=
pSyncNode
->
myRaftId
;
reply
->
srcId
=
ids
[
i
];
reply
->
term
=
term
;
reply
->
voteGranted
=
true
;
voteGrantedVote
(
pVotesGranted
,
reply
);
{
char
*
serialized
=
voteGranted2Str
(
pVotesGranted
);
assert
(
serialized
!=
NULL
);
printf
(
"%s
\n
"
,
serialized
);
free
(
serialized
);
}
voteGrantedVote
(
pVotesGranted
,
reply
);
{
char
*
serialized
=
voteGranted2Str
(
pVotesGranted
);
assert
(
serialized
!=
NULL
);
printf
(
"%s
\n
"
,
serialized
);
free
(
serialized
);
}
printf
(
"---------------------------------------
\n
"
);
for
(
int
i
=
0
;
i
<
pSyncIndexMgr
->
replicaNum
;
++
i
)
{
SyncIndex
idx
=
syncIndexMgrGetIndex
(
pSyncIndexMgr
,
&
ids
[
i
]);
printf
(
"index %d : %lu
\n
"
,
i
,
idx
);
}
syncIndexMgrClear
(
pSyncIndexMgr
);
printf
(
"---------------------------------------
\n
"
);
voteGrantedReset
(
pVotesGranted
,
123456789
);
{
char
*
serialized
=
voteGranted2Str
(
pVotesGranted
);
char
*
serialized
=
syncIndexMgr2Str
(
pSyncIndexMgr
);
assert
(
serialized
!=
NULL
);
printf
(
"%s
\n
"
,
serialized
);
free
(
serialized
);
}
voteGrantedDestroy
(
pVotesGranted
);
syncIndexMgrDestroy
(
pSyncIndexMgr
);
return
0
;
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录