Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
e58812aa
TDengine
项目概览
taosdata
/
TDengine
大约 1 年 前同步成功
通知
1184
Star
22015
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看板
体验新版 GitCode,发现更多精彩内容 >>
提交
e58812aa
编写于
3月 24, 2022
作者:
M
Minghao Li
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
sync refactor
上级
b05706f9
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
44 addition
and
12 deletion
+44
-12
source/libs/sync/inc/syncRaftEntry.h
source/libs/sync/inc/syncRaftEntry.h
+2
-1
source/libs/sync/src/syncAppendEntries.c
source/libs/sync/src/syncAppendEntries.c
+4
-3
source/libs/sync/src/syncCommit.c
source/libs/sync/src/syncCommit.c
+1
-1
source/libs/sync/src/syncMain.c
source/libs/sync/src/syncMain.c
+23
-3
source/libs/sync/src/syncRaftEntry.c
source/libs/sync/src/syncRaftEntry.c
+10
-0
source/libs/sync/src/syncRaftLog.c
source/libs/sync/src/syncRaftLog.c
+3
-3
source/libs/sync/test/syncEntryTest.cpp
source/libs/sync/test/syncEntryTest.cpp
+1
-1
未找到文件。
source/libs/sync/inc/syncRaftEntry.h
浏览文件 @
e58812aa
...
@@ -28,7 +28,7 @@ extern "C" {
...
@@ -28,7 +28,7 @@ extern "C" {
#include "taosdef.h"
#include "taosdef.h"
typedef
enum
EntryType
{
typedef
enum
EntryType
{
SYNC_RAFT_ENTRY_N
ULL
=
0
,
SYNC_RAFT_ENTRY_N
OOP
=
0
,
SYNC_RAFT_ENTRY_DATA
=
1
,
SYNC_RAFT_ENTRY_DATA
=
1
,
SYNC_RAFT_ENTRY_CONFIG
=
2
,
SYNC_RAFT_ENTRY_CONFIG
=
2
,
}
EntryType
;
}
EntryType
;
...
@@ -49,6 +49,7 @@ typedef struct SSyncRaftEntry {
...
@@ -49,6 +49,7 @@ typedef struct SSyncRaftEntry {
SSyncRaftEntry
*
syncEntryBuild
(
uint32_t
dataLen
);
SSyncRaftEntry
*
syncEntryBuild
(
uint32_t
dataLen
);
SSyncRaftEntry
*
syncEntryBuild2
(
SyncClientRequest
*
pMsg
,
SyncTerm
term
,
SyncIndex
index
);
// step 4
SSyncRaftEntry
*
syncEntryBuild2
(
SyncClientRequest
*
pMsg
,
SyncTerm
term
,
SyncIndex
index
);
// step 4
SSyncRaftEntry
*
syncEntryBuild3
(
SyncClientRequest
*
pMsg
,
SyncTerm
term
,
SyncIndex
index
,
EntryType
entryType
);
SSyncRaftEntry
*
syncEntryBuild3
(
SyncClientRequest
*
pMsg
,
SyncTerm
term
,
SyncIndex
index
,
EntryType
entryType
);
SSyncRaftEntry
*
syncEntryBuildNoop
(
SyncTerm
term
,
SyncIndex
index
);
void
syncEntryDestory
(
SSyncRaftEntry
*
pEntry
);
void
syncEntryDestory
(
SSyncRaftEntry
*
pEntry
);
char
*
syncEntrySerialize
(
const
SSyncRaftEntry
*
pEntry
,
uint32_t
*
len
);
// step 5
char
*
syncEntrySerialize
(
const
SSyncRaftEntry
*
pEntry
,
uint32_t
*
len
);
// step 5
SSyncRaftEntry
*
syncEntryDeserialize
(
const
char
*
buf
,
uint32_t
len
);
// step 6
SSyncRaftEntry
*
syncEntryDeserialize
(
const
char
*
buf
,
uint32_t
len
);
// step 6
...
...
source/libs/sync/src/syncAppendEntries.c
浏览文件 @
e58812aa
...
@@ -198,6 +198,7 @@ int32_t syncNodeOnAppendEntriesCb(SSyncNode* ths, SyncAppendEntries* pMsg) {
...
@@ -198,6 +198,7 @@ int32_t syncNodeOnAppendEntriesCb(SSyncNode* ths, SyncAppendEntries* pMsg) {
if
(
ths
->
pFsm
->
FpRollBackCb
!=
NULL
)
{
if
(
ths
->
pFsm
->
FpRollBackCb
!=
NULL
)
{
SSyncRaftEntry
*
pRollBackEntry
=
logStoreGetEntry
(
ths
->
pLogStore
,
index
);
SSyncRaftEntry
*
pRollBackEntry
=
logStoreGetEntry
(
ths
->
pLogStore
,
index
);
assert
(
pRollBackEntry
!=
NULL
);
assert
(
pRollBackEntry
!=
NULL
);
assert
(
pRollBackEntry
->
entryType
==
SYNC_RAFT_ENTRY_DATA
);
SRpcMsg
rpcMsg
;
SRpcMsg
rpcMsg
;
syncEntry2OriginalRpc
(
pRollBackEntry
,
&
rpcMsg
);
syncEntry2OriginalRpc
(
pRollBackEntry
,
&
rpcMsg
);
...
@@ -217,7 +218,7 @@ int32_t syncNodeOnAppendEntriesCb(SSyncNode* ths, SyncAppendEntries* pMsg) {
...
@@ -217,7 +218,7 @@ int32_t syncNodeOnAppendEntriesCb(SSyncNode* ths, SyncAppendEntries* pMsg) {
SRpcMsg
rpcMsg
;
SRpcMsg
rpcMsg
;
syncEntry2OriginalRpc
(
pAppendEntry
,
&
rpcMsg
);
syncEntry2OriginalRpc
(
pAppendEntry
,
&
rpcMsg
);
if
(
ths
->
pFsm
!=
NULL
)
{
if
(
ths
->
pFsm
!=
NULL
)
{
if
(
ths
->
pFsm
->
FpPreCommitCb
!=
NULL
)
{
if
(
ths
->
pFsm
->
FpPreCommitCb
!=
NULL
&&
pAppendEntry
->
entryType
==
SYNC_RAFT_ENTRY_DATA
)
{
ths
->
pFsm
->
FpPreCommitCb
(
ths
->
pFsm
,
&
rpcMsg
,
pAppendEntry
->
index
,
pAppendEntry
->
isWeak
,
2
,
ths
->
state
);
ths
->
pFsm
->
FpPreCommitCb
(
ths
->
pFsm
,
&
rpcMsg
,
pAppendEntry
->
index
,
pAppendEntry
->
isWeak
,
2
,
ths
->
state
);
}
}
}
}
...
@@ -242,7 +243,7 @@ int32_t syncNodeOnAppendEntriesCb(SSyncNode* ths, SyncAppendEntries* pMsg) {
...
@@ -242,7 +243,7 @@ int32_t syncNodeOnAppendEntriesCb(SSyncNode* ths, SyncAppendEntries* pMsg) {
SRpcMsg
rpcMsg
;
SRpcMsg
rpcMsg
;
syncEntry2OriginalRpc
(
pAppendEntry
,
&
rpcMsg
);
syncEntry2OriginalRpc
(
pAppendEntry
,
&
rpcMsg
);
if
(
ths
->
pFsm
!=
NULL
)
{
if
(
ths
->
pFsm
!=
NULL
)
{
if
(
ths
->
pFsm
->
FpPreCommitCb
!=
NULL
)
{
if
(
ths
->
pFsm
->
FpPreCommitCb
!=
NULL
&&
pAppendEntry
->
entryType
==
SYNC_RAFT_ENTRY_DATA
)
{
ths
->
pFsm
->
FpPreCommitCb
(
ths
->
pFsm
,
&
rpcMsg
,
pAppendEntry
->
index
,
pAppendEntry
->
isWeak
,
3
,
ths
->
state
);
ths
->
pFsm
->
FpPreCommitCb
(
ths
->
pFsm
,
&
rpcMsg
,
pAppendEntry
->
index
,
pAppendEntry
->
isWeak
,
3
,
ths
->
state
);
}
}
}
}
...
@@ -298,7 +299,7 @@ int32_t syncNodeOnAppendEntriesCb(SSyncNode* ths, SyncAppendEntries* pMsg) {
...
@@ -298,7 +299,7 @@ int32_t syncNodeOnAppendEntriesCb(SSyncNode* ths, SyncAppendEntries* pMsg) {
SRpcMsg
rpcMsg
;
SRpcMsg
rpcMsg
;
syncEntry2OriginalRpc
(
pEntry
,
&
rpcMsg
);
syncEntry2OriginalRpc
(
pEntry
,
&
rpcMsg
);
if
(
ths
->
pFsm
->
FpCommitCb
!=
NULL
)
{
if
(
ths
->
pFsm
->
FpCommitCb
!=
NULL
&&
pEntry
->
entryType
==
SYNC_RAFT_ENTRY_DATA
)
{
ths
->
pFsm
->
FpCommitCb
(
ths
->
pFsm
,
&
rpcMsg
,
pEntry
->
index
,
pEntry
->
isWeak
,
0
,
ths
->
state
);
ths
->
pFsm
->
FpCommitCb
(
ths
->
pFsm
,
&
rpcMsg
,
pEntry
->
index
,
pEntry
->
isWeak
,
0
,
ths
->
state
);
}
}
...
...
source/libs/sync/src/syncCommit.c
浏览文件 @
e58812aa
...
@@ -97,7 +97,7 @@ void syncMaybeAdvanceCommitIndex(SSyncNode* pSyncNode) {
...
@@ -97,7 +97,7 @@ void syncMaybeAdvanceCommitIndex(SSyncNode* pSyncNode) {
SRpcMsg
rpcMsg
;
SRpcMsg
rpcMsg
;
syncEntry2OriginalRpc
(
pEntry
,
&
rpcMsg
);
syncEntry2OriginalRpc
(
pEntry
,
&
rpcMsg
);
if
(
pSyncNode
->
pFsm
->
FpCommitCb
!=
NULL
)
{
if
(
pSyncNode
->
pFsm
->
FpCommitCb
!=
NULL
&&
pEntry
->
entryType
==
SYNC_RAFT_ENTRY_DATA
)
{
pSyncNode
->
pFsm
->
FpCommitCb
(
pSyncNode
->
pFsm
,
&
rpcMsg
,
pEntry
->
index
,
pEntry
->
isWeak
,
0
,
pSyncNode
->
state
);
pSyncNode
->
pFsm
->
FpCommitCb
(
pSyncNode
->
pFsm
,
&
rpcMsg
,
pEntry
->
index
,
pEntry
->
isWeak
,
0
,
pSyncNode
->
state
);
}
}
...
...
source/libs/sync/src/syncMain.c
浏览文件 @
e58812aa
...
@@ -41,10 +41,11 @@ static void syncNodeEqPingTimer(void* param, void* tmrId);
...
@@ -41,10 +41,11 @@ static void syncNodeEqPingTimer(void* param, void* tmrId);
static
void
syncNodeEqElectTimer
(
void
*
param
,
void
*
tmrId
);
static
void
syncNodeEqElectTimer
(
void
*
param
,
void
*
tmrId
);
static
void
syncNodeEqHeartbeatTimer
(
void
*
param
,
void
*
tmrId
);
static
void
syncNodeEqHeartbeatTimer
(
void
*
param
,
void
*
tmrId
);
//
on
message ----
//
process
message ----
static
int32_t
syncNodeOnPingCb
(
SSyncNode
*
ths
,
SyncPing
*
pMsg
);
static
int32_t
syncNodeOnPingCb
(
SSyncNode
*
ths
,
SyncPing
*
pMsg
);
static
int32_t
syncNodeOnPingReplyCb
(
SSyncNode
*
ths
,
SyncPingReply
*
pMsg
);
static
int32_t
syncNodeOnPingReplyCb
(
SSyncNode
*
ths
,
SyncPingReply
*
pMsg
);
static
int32_t
syncNodeOnClientRequestCb
(
SSyncNode
*
ths
,
SyncClientRequest
*
pMsg
);
static
int32_t
syncNodeOnClientRequestCb
(
SSyncNode
*
ths
,
SyncClientRequest
*
pMsg
);
static
int32_t
syncNodeAppendNoop
(
SSyncNode
*
ths
);
// life cycle
// life cycle
static
void
syncFreeNode
(
void
*
param
);
static
void
syncFreeNode
(
void
*
param
);
...
@@ -669,6 +670,9 @@ void syncNodeCandidate2Leader(SSyncNode* pSyncNode) {
...
@@ -669,6 +670,9 @@ void syncNodeCandidate2Leader(SSyncNode* pSyncNode) {
assert
(
pSyncNode
->
state
==
TAOS_SYNC_STATE_CANDIDATE
);
assert
(
pSyncNode
->
state
==
TAOS_SYNC_STATE_CANDIDATE
);
assert
(
voteGrantedMajority
(
pSyncNode
->
pVotesGranted
));
assert
(
voteGrantedMajority
(
pSyncNode
->
pVotesGranted
));
syncNodeBecomeLeader
(
pSyncNode
);
syncNodeBecomeLeader
(
pSyncNode
);
// Raft 3.6.2 Committing entries from previous terms
syncNodeAppendNoop
(
pSyncNode
);
}
}
void
syncNodeFollower2Candidate
(
SSyncNode
*
pSyncNode
)
{
void
syncNodeFollower2Candidate
(
SSyncNode
*
pSyncNode
)
{
...
@@ -851,7 +855,7 @@ static int32_t syncNodeOnClientRequestCb(SSyncNode* ths, SyncClientRequest* pMsg
...
@@ -851,7 +855,7 @@ static int32_t syncNodeOnClientRequestCb(SSyncNode* ths, SyncClientRequest* pMsg
syncEntry2OriginalRpc
(
pEntry
,
&
rpcMsg
);
syncEntry2OriginalRpc
(
pEntry
,
&
rpcMsg
);
if
(
ths
->
pFsm
!=
NULL
)
{
if
(
ths
->
pFsm
!=
NULL
)
{
if
(
ths
->
pFsm
->
FpPreCommitCb
!=
NULL
)
{
if
(
ths
->
pFsm
->
FpPreCommitCb
!=
NULL
&&
pEntry
->
entryType
==
SYNC_RAFT_ENTRY_DATA
)
{
ths
->
pFsm
->
FpPreCommitCb
(
ths
->
pFsm
,
&
rpcMsg
,
pEntry
->
index
,
pEntry
->
isWeak
,
0
,
ths
->
state
);
ths
->
pFsm
->
FpPreCommitCb
(
ths
->
pFsm
,
&
rpcMsg
,
pEntry
->
index
,
pEntry
->
isWeak
,
0
,
ths
->
state
);
}
}
}
}
...
@@ -866,7 +870,7 @@ static int32_t syncNodeOnClientRequestCb(SSyncNode* ths, SyncClientRequest* pMsg
...
@@ -866,7 +870,7 @@ static int32_t syncNodeOnClientRequestCb(SSyncNode* ths, SyncClientRequest* pMsg
syncEntry2OriginalRpc
(
pEntry
,
&
rpcMsg
);
syncEntry2OriginalRpc
(
pEntry
,
&
rpcMsg
);
if
(
ths
->
pFsm
!=
NULL
)
{
if
(
ths
->
pFsm
!=
NULL
)
{
if
(
ths
->
pFsm
->
FpPreCommitCb
!=
NULL
)
{
if
(
ths
->
pFsm
->
FpPreCommitCb
!=
NULL
&&
pEntry
->
entryType
==
SYNC_RAFT_ENTRY_DATA
)
{
ths
->
pFsm
->
FpPreCommitCb
(
ths
->
pFsm
,
&
rpcMsg
,
pEntry
->
index
,
pEntry
->
isWeak
,
1
,
ths
->
state
);
ths
->
pFsm
->
FpPreCommitCb
(
ths
->
pFsm
,
&
rpcMsg
,
pEntry
->
index
,
pEntry
->
isWeak
,
1
,
ths
->
state
);
}
}
}
}
...
@@ -877,6 +881,22 @@ static int32_t syncNodeOnClientRequestCb(SSyncNode* ths, SyncClientRequest* pMsg
...
@@ -877,6 +881,22 @@ static int32_t syncNodeOnClientRequestCb(SSyncNode* ths, SyncClientRequest* pMsg
return
ret
;
return
ret
;
}
}
static
int32_t
syncNodeAppendNoop
(
SSyncNode
*
ths
)
{
int32_t
ret
=
0
;
SyncIndex
index
=
ths
->
pLogStore
->
getLastIndex
(
ths
->
pLogStore
)
+
1
;
SyncTerm
term
=
ths
->
pRaftStore
->
currentTerm
;
SSyncRaftEntry
*
pEntry
=
syncEntryBuildNoop
(
term
,
index
);
assert
(
pEntry
!=
NULL
);
if
(
ths
->
state
==
TAOS_SYNC_STATE_LEADER
)
{
ths
->
pLogStore
->
appendEntry
(
ths
->
pLogStore
,
pEntry
);
syncNodeReplicate
(
ths
);
}
return
ret
;
}
static
void
syncFreeNode
(
void
*
param
)
{
static
void
syncFreeNode
(
void
*
param
)
{
SSyncNode
*
pNode
=
param
;
SSyncNode
*
pNode
=
param
;
syncNodePrint2
((
char
*
)
"==syncFreeNode=="
,
pNode
);
syncNodePrint2
((
char
*
)
"==syncFreeNode=="
,
pNode
);
...
...
source/libs/sync/src/syncRaftEntry.c
浏览文件 @
e58812aa
...
@@ -51,6 +51,16 @@ SSyncRaftEntry* syncEntryBuild3(SyncClientRequest* pMsg, SyncTerm term, SyncInde
...
@@ -51,6 +51,16 @@ SSyncRaftEntry* syncEntryBuild3(SyncClientRequest* pMsg, SyncTerm term, SyncInde
return
pEntry
;
return
pEntry
;
}
}
SSyncRaftEntry
*
syncEntryBuildNoop
(
SyncTerm
term
,
SyncIndex
index
)
{
SSyncRaftEntry
*
pEntry
=
syncEntryBuild
(
0
);
assert
(
pEntry
!=
NULL
);
pEntry
->
term
=
term
;
pEntry
->
index
=
index
;
pEntry
->
entryType
=
SYNC_RAFT_ENTRY_NOOP
;
return
pEntry
;
}
void
syncEntryDestory
(
SSyncRaftEntry
*
pEntry
)
{
void
syncEntryDestory
(
SSyncRaftEntry
*
pEntry
)
{
if
(
pEntry
!=
NULL
)
{
if
(
pEntry
!=
NULL
)
{
free
(
pEntry
);
free
(
pEntry
);
...
...
source/libs/sync/src/syncRaftLog.c
浏览文件 @
e58812aa
...
@@ -34,7 +34,7 @@ SSyncLogStore* logStoreCreate(SSyncNode* pSyncNode) {
...
@@ -34,7 +34,7 @@ SSyncLogStore* logStoreCreate(SSyncNode* pSyncNode) {
pLogStore
->
getLastTerm
=
logStoreLastTerm
;
pLogStore
->
getLastTerm
=
logStoreLastTerm
;
pLogStore
->
updateCommitIndex
=
logStoreUpdateCommitIndex
;
pLogStore
->
updateCommitIndex
=
logStoreUpdateCommitIndex
;
pLogStore
->
getCommitIndex
=
logStoreGetCommitIndex
;
pLogStore
->
getCommitIndex
=
logStoreGetCommitIndex
;
return
pLogStore
;
// to avoid compiler error
return
pLogStore
;
}
}
void
logStoreDestory
(
SSyncLogStore
*
pLogStore
)
{
void
logStoreDestory
(
SSyncLogStore
*
pLogStore
)
{
...
@@ -54,12 +54,12 @@ int32_t logStoreAppendEntry(SSyncLogStore* pLogStore, SSyncRaftEntry* pEntry) {
...
@@ -54,12 +54,12 @@ int32_t logStoreAppendEntry(SSyncLogStore* pLogStore, SSyncRaftEntry* pEntry) {
assert
(
serialized
!=
NULL
);
assert
(
serialized
!=
NULL
);
int
code
;
int
code
;
code
=
walWrite
(
pWal
,
pEntry
->
index
,
pEntry
->
msg
Type
,
serialized
,
len
);
code
=
walWrite
(
pWal
,
pEntry
->
index
,
pEntry
->
entry
Type
,
serialized
,
len
);
assert
(
code
==
0
);
assert
(
code
==
0
);
walFsync
(
pWal
,
true
);
walFsync
(
pWal
,
true
);
free
(
serialized
);
free
(
serialized
);
return
code
;
// to avoid compiler error
return
code
;
}
}
SSyncRaftEntry
*
logStoreGetEntry
(
SSyncLogStore
*
pLogStore
,
SyncIndex
index
)
{
SSyncRaftEntry
*
logStoreGetEntry
(
SSyncLogStore
*
pLogStore
,
SyncIndex
index
)
{
...
...
source/libs/sync/test/syncEntryTest.cpp
浏览文件 @
e58812aa
...
@@ -52,7 +52,7 @@ void test3() {
...
@@ -52,7 +52,7 @@ void test3() {
pSyncMsg
->
isWeak
=
1
;
pSyncMsg
->
isWeak
=
1
;
strcpy
(
pSyncMsg
->
data
,
"test3"
);
strcpy
(
pSyncMsg
->
data
,
"test3"
);
SSyncRaftEntry
*
pEntry
=
syncEntryBuild3
(
pSyncMsg
,
100
,
200
,
SYNC_RAFT_ENTRY_N
ULL
);
SSyncRaftEntry
*
pEntry
=
syncEntryBuild3
(
pSyncMsg
,
100
,
200
,
SYNC_RAFT_ENTRY_N
OOP
);
syncEntryPrint
(
pEntry
);
syncEntryPrint
(
pEntry
);
syncClientRequestDestroy
(
pSyncMsg
);
syncClientRequestDestroy
(
pSyncMsg
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录