Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
ffe44230
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
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看板
提交
ffe44230
编写于
3月 08, 2022
作者:
M
Minghao Li
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
sync refactor
上级
f556d981
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
54 addition
and
9 deletion
+54
-9
source/libs/sync/inc/syncInt.h
source/libs/sync/inc/syncInt.h
+3
-1
source/libs/sync/inc/syncReplication.h
source/libs/sync/inc/syncReplication.h
+1
-0
source/libs/sync/src/syncElection.c
source/libs/sync/src/syncElection.c
+6
-2
source/libs/sync/src/syncMain.c
source/libs/sync/src/syncMain.c
+32
-3
source/libs/sync/src/syncReplication.c
source/libs/sync/src/syncReplication.c
+10
-1
source/libs/sync/src/syncTimeout.c
source/libs/sync/src/syncTimeout.c
+1
-1
source/libs/sync/src/syncUtil.c
source/libs/sync/src/syncUtil.c
+1
-1
未找到文件。
source/libs/sync/inc/syncInt.h
浏览文件 @
ffe44230
...
...
@@ -155,7 +155,7 @@ typedef struct SSyncNode {
SSyncLogStore
*
pLogStore
;
SyncIndex
commitIndex
;
// timer
//
ping
timer
tmr_h
pPingTimer
;
int32_t
pingTimerMS
;
uint64_t
pingTimerLogicClock
;
...
...
@@ -163,6 +163,7 @@ typedef struct SSyncNode {
TAOS_TMR_CALLBACK
FpPingTimer
;
// Timer Fp
uint64_t
pingTimerCounter
;
// elect timer
tmr_h
pElectTimer
;
int32_t
electTimerMS
;
uint64_t
electTimerLogicClock
;
...
...
@@ -170,6 +171,7 @@ typedef struct SSyncNode {
TAOS_TMR_CALLBACK
FpElectTimer
;
// Timer Fp
uint64_t
electTimerCounter
;
// heartbeat timer
tmr_h
pHeartbeatTimer
;
int32_t
heartbeatTimerMS
;
uint64_t
heartbeatTimerLogicClock
;
...
...
source/libs/sync/inc/syncReplication.h
浏览文件 @
ffe44230
...
...
@@ -53,6 +53,7 @@ extern "C" {
//
int32_t
syncNodeAppendEntriesPeers
(
SSyncNode
*
pSyncNode
);
int32_t
syncNodeReplicate
(
SSyncNode
*
pSyncNode
);
int32_t
syncNodeAppendEntries
(
SSyncNode
*
pSyncNode
,
const
SRaftId
*
destRaftId
,
const
SyncAppendEntries
*
pMsg
);
#ifdef __cplusplus
...
...
source/libs/sync/src/syncElection.c
浏览文件 @
ffe44230
...
...
@@ -28,11 +28,15 @@
// mdest |-> j])
// /\ UNCHANGED <<serverVars, candidateVars, leaderVars, logVars>>
//
int32_t
syncNodeRequestVotePeers
(
SSyncNode
*
pSyncNode
)
{}
int32_t
syncNodeRequestVotePeers
(
SSyncNode
*
pSyncNode
)
{
int32_t
ret
=
0
;
return
ret
;
}
int32_t
syncNodeElect
(
SSyncNode
*
pSyncNode
)
{
// start election
syncNodeRequestVotePeers
(
pSyncNode
);
int32_t
ret
=
syncNodeRequestVotePeers
(
pSyncNode
);
return
ret
;
}
int32_t
syncNodeRequestVote
(
SSyncNode
*
pSyncNode
,
const
SRaftId
*
destRaftId
,
const
SyncRequestVote
*
pMsg
)
{
...
...
source/libs/sync/src/syncMain.c
浏览文件 @
ffe44230
...
...
@@ -37,7 +37,7 @@ static void syncNodeEqHeartbeatTimer(void* param, void* tmrId);
static
int32_t
syncNodeOnPingCb
(
SSyncNode
*
ths
,
SyncPing
*
pMsg
);
static
int32_t
syncNodeOnPingReplyCb
(
SSyncNode
*
ths
,
SyncPingReply
*
pMsg
);
static
void
UpdateTerm
(
SyncTerm
term
);
static
void
UpdateTerm
(
S
SyncNode
*
pSyncNode
,
S
yncTerm
term
);
static
void
syncNodeBecomeFollower
(
SSyncNode
*
pSyncNode
);
static
void
syncNodeBecomeLeader
(
SSyncNode
*
pSyncNode
);
static
void
syncNodeFollower2Candidate
(
SSyncNode
*
pSyncNode
);
...
...
@@ -452,9 +452,38 @@ static void syncNodeEqElectTimer(void* param, void* tmrId) {
}
}
static
void
syncNodeEqHeartbeatTimer
(
void
*
param
,
void
*
tmrId
)
{}
static
void
syncNodeEqHeartbeatTimer
(
void
*
param
,
void
*
tmrId
)
{
SSyncNode
*
pSyncNode
=
(
SSyncNode
*
)
param
;
if
(
atomic_load_64
(
&
pSyncNode
->
heartbeatTimerLogicClockUser
)
<=
atomic_load_64
(
&
pSyncNode
->
heartbeatTimerLogicClock
))
{
SyncTimeout
*
pSyncMsg
=
syncTimeoutBuild2
(
SYNC_TIMEOUT_HEARTBEAT
,
atomic_load_64
(
&
pSyncNode
->
heartbeatTimerLogicClock
),
pSyncNode
->
heartbeatTimerMS
,
pSyncNode
);
SRpcMsg
rpcMsg
;
syncTimeout2RpcMsg
(
pSyncMsg
,
&
rpcMsg
);
pSyncNode
->
FpEqMsg
(
pSyncNode
->
queue
,
&
rpcMsg
);
syncTimeoutDestroy
(
pSyncMsg
);
// reset timer ms
// pSyncNode->heartbeatTimerMS += 100;
static
void
UpdateTerm
(
SyncTerm
term
)
{}
taosTmrReset
(
syncNodeEqHeartbeatTimer
,
pSyncNode
->
heartbeatTimerMS
,
pSyncNode
,
&
gSyncEnv
->
pTimerManager
,
&
pSyncNode
->
pHeartbeatTimer
);
}
else
{
sTrace
(
"syncNodeEqHeartbeatTimer: heartbeatTimerLogicClock:%lu, heartbeatTimerLogicClockUser:%lu"
,
pSyncNode
->
heartbeatTimerLogicClock
,
pSyncNode
->
heartbeatTimerLogicClockUser
);
}
}
static
void
UpdateTerm
(
SSyncNode
*
pSyncNode
,
SyncTerm
term
)
{
if
(
term
>
pSyncNode
->
pRaftStore
->
currentTerm
)
{
pSyncNode
->
pRaftStore
->
currentTerm
=
term
;
pSyncNode
->
pRaftStore
->
voteFor
=
EMPTY_RAFT_ID
;
raftStorePersist
(
pSyncNode
->
pRaftStore
);
syncNodeBecomeFollower
(
pSyncNode
);
}
}
static
void
syncNodeBecomeFollower
(
SSyncNode
*
pSyncNode
)
{
if
(
pSyncNode
->
state
==
TAOS_SYNC_STATE_LEADER
)
{
...
...
source/libs/sync/src/syncReplication.c
浏览文件 @
ffe44230
...
...
@@ -41,7 +41,16 @@
// mdest |-> j])
// /\ UNCHANGED <<serverVars, candidateVars, leaderVars, logVars>>
//
int32_t
syncNodeAppendEntriesPeers
(
SSyncNode
*
pSyncNode
)
{}
int32_t
syncNodeAppendEntriesPeers
(
SSyncNode
*
pSyncNode
)
{
int32_t
ret
=
0
;
return
ret
;
}
int32_t
syncNodeReplicate
(
SSyncNode
*
pSyncNode
)
{
// start replicate
int32_t
ret
=
syncNodeAppendEntriesPeers
(
pSyncNode
);
return
ret
;
}
int32_t
syncNodeAppendEntries
(
SSyncNode
*
pSyncNode
,
const
SRaftId
*
destRaftId
,
const
SyncAppendEntries
*
pMsg
)
{
sTrace
(
"syncNodeAppendEntries pSyncNode:%p "
,
pSyncNode
);
...
...
source/libs/sync/src/syncTimeout.c
浏览文件 @
ffe44230
...
...
@@ -44,7 +44,7 @@ int32_t syncNodeOnTimeoutCb(SSyncNode* ths, SyncTimeout* pMsg) {
}
else
if
(
pMsg
->
timeoutType
==
SYNC_TIMEOUT_HEARTBEAT
)
{
if
(
atomic_load_64
(
&
ths
->
heartbeatTimerLogicClockUser
)
<=
pMsg
->
logicClock
)
{
++
(
ths
->
heartbeatTimerCounter
);
syncNode
AppendEntriesPeers
(
ths
);
syncNode
Replicate
(
ths
);
}
}
else
{
sTrace
(
"unknown timeoutType:%d"
,
pMsg
->
timeoutType
);
...
...
source/libs/sync/src/syncUtil.c
浏览文件 @
ffe44230
...
...
@@ -127,7 +127,7 @@ cJSON* syncUtilRaftId2Json(const SRaftId* p) {
cJSON_AddNumberToObject
(
pRoot
,
"vgId"
,
p
->
vgId
);
cJSON
*
pJson
=
cJSON_CreateObject
();
cJSON_AddItemToObject
(
pJson
,
"S
NodeInfo
"
,
pRoot
);
cJSON_AddItemToObject
(
pJson
,
"S
RaftId
"
,
pRoot
);
return
pJson
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录