Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
0c8f62f7
T
TDengine
项目概览
taosdata
/
TDengine
大约 1 年 前同步成功
通知
1184
Star
22015
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看板
体验新版 GitCode,发现更多精彩内容 >>
提交
0c8f62f7
编写于
3月 09, 2022
作者:
M
Minghao Li
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
sync refactor
上级
57b4e7ce
变更
11
隐藏空白更改
内联
并排
Showing
11 changed file
with
108 addition
and
70 deletion
+108
-70
source/libs/sync/inc/syncInt.h
source/libs/sync/inc/syncInt.h
+1
-1
source/libs/sync/inc/syncRaftEntry.h
source/libs/sync/inc/syncRaftEntry.h
+8
-4
source/libs/sync/inc/syncRaftLog.h
source/libs/sync/inc/syncRaftLog.h
+26
-11
source/libs/sync/inc/syncVoteMgr.h
source/libs/sync/inc/syncVoteMgr.h
+4
-4
source/libs/sync/src/syncMain.c
source/libs/sync/src/syncMain.c
+17
-8
source/libs/sync/src/syncRaftLog.c
source/libs/sync/src/syncRaftLog.c
+52
-37
source/libs/sync/test/syncIndexMgrTest.cpp
source/libs/sync/test/syncIndexMgrTest.cpp
+0
-1
source/libs/sync/test/syncInitTest.cpp
source/libs/sync/test/syncInitTest.cpp
+0
-1
source/libs/sync/test/syncPingTest.cpp
source/libs/sync/test/syncPingTest.cpp
+0
-1
source/libs/sync/test/syncVotesGrantedTest.cpp
source/libs/sync/test/syncVotesGrantedTest.cpp
+0
-1
source/libs/sync/test/syncVotesRespondTest.cpp
source/libs/sync/test/syncVotesRespondTest.cpp
+0
-1
未找到文件。
source/libs/sync/inc/syncInt.h
浏览文件 @
0c8f62f7
...
...
@@ -116,7 +116,7 @@ typedef struct SSyncNode {
SyncGroupId
vgId
;
SSyncCfg
syncCfg
;
char
path
[
TSDB_FILENAME_LEN
];
char
walPath
[
TSDB_FILENAME_LEN
]
;
SWal
*
pWal
;
void
*
rpcClient
;
int32_t
(
*
FpSendMsg
)(
void
*
rpcClient
,
const
SEpSet
*
pEpSet
,
SRpcMsg
*
pMsg
);
void
*
queue
;
...
...
source/libs/sync/inc/syncRaftEntry.h
浏览文件 @
0c8f62f7
...
...
@@ -27,10 +27,14 @@ extern "C" {
#include "taosdef.h"
typedef
struct
SSyncRaftEntry
{
SyncTerm
term
;
SyncIndex
index
;
SSyncBuffer
data
;
int8_t
flag
;
uint32_t
bytes
;
uint32_t
msgType
;
SyncTerm
term
;
SyncIndex
index
;
int8_t
flag
;
uint32_t
dataLen
;
char
data
[];
}
SSyncRaftEntry
;
#ifdef __cplusplus
...
...
source/libs/sync/inc/syncRaftLog.h
浏览文件 @
0c8f62f7
...
...
@@ -24,27 +24,42 @@ extern "C" {
#include <stdio.h>
#include <stdlib.h>
#include "syncInt.h"
#include "syncRaftEntry.h"
#include "taosdef.h"
int32_t
raftLogAppendEntry
(
struct
SSyncLogStore
*
pLogStore
,
SSyncBuffer
*
pBuf
);
typedef
struct
SSyncLogStoreData
{
SSyncNode
*
pSyncNode
;
SWal
*
pWal
;
}
SSyncLogStoreData
;
// get one log entry, user need to free pBuf->data
int32_t
raftLogGetEntry
(
struct
SSyncLogStore
*
pLogStore
,
SyncIndex
index
,
SSyncBuffer
*
pBuf
);
SSyncLogStore
*
logStoreCreate
(
SSyncNode
*
pSyncNode
);
// update log store commit index with "index"
int32_t
raftLogUpdateCommitIndex
(
struct
SSyncLogStore
*
pLogStore
,
SyncIndex
index
);
void
logStoreDestory
(
SSyncLogStore
*
pLogStore
);
//
truncate log with index, entries after the given index (>index) will be deleted
int32_t
raftLogTruncate
(
struct
SSyncLogStore
*
pLogStore
,
SyncIndex
index
);
//
append one log entry
int32_t
logStoreAppendEntry
(
SSyncLogStore
*
pLogStore
,
SRpcMsg
*
pEntry
);
// return commit index of log
SyncIndex
raftLogGetCommitIndex
(
struct
SSyncLogStore
*
pLogStore
);
// get one log entry, user need to free pEntry->pCont
int32_t
logStoreGetEntry
(
SSyncLogStore
*
pLogStore
,
SyncIndex
index
,
SRpcMsg
*
pEntry
);
// truncate log with index, entries after the given index (>=index) will be deleted
int32_t
logStoreTruncate
(
SSyncLogStore
*
pLogStore
,
SyncIndex
fromIndex
);
// return index of last entry
SyncIndex
raftLogGetLastIndex
(
struct
SSyncLogStore
*
pLogStore
);
SyncIndex
logStoreLastIndex
(
SSyncLogStore
*
pLogStore
);
// return term of last entry
SyncTerm
raftLogGetLastTerm
(
struct
SSyncLogStore
*
pLogStore
);
SyncTerm
logStoreLastTerm
(
SSyncLogStore
*
pLogStore
);
// update log store commit index with "index"
int32_t
logStoreUpdateCommitIndex
(
SSyncLogStore
*
pLogStore
,
SyncIndex
index
);
// return commit index of log
SyncIndex
logStoreGetCommitIndex
(
SSyncLogStore
*
pLogStore
);
cJSON
*
logStore2Json
(
SSyncLogStore
*
pLogStore
);
char
*
logStore2Str
(
SSyncLogStore
*
pLogStore
);
#ifdef __cplusplus
}
...
...
source/libs/sync/inc/syncVoteMgr.h
浏览文件 @
0c8f62f7
...
...
@@ -45,8 +45,8 @@ void voteGrantedDestroy(SVotesGranted *pVotesGranted);
bool
voteGrantedMajority
(
SVotesGranted
*
pVotesGranted
);
void
voteGrantedVote
(
SVotesGranted
*
pVotesGranted
,
SyncRequestVoteReply
*
pMsg
);
void
voteGrantedReset
(
SVotesGranted
*
pVotesGranted
,
SyncTerm
term
);
cJSON
*
voteGranted2Json
(
SVotesGranted
*
pVotesGranted
);
char
*
voteGranted2Str
(
SVotesGranted
*
pVotesGranted
);
cJSON
*
voteGranted2Json
(
SVotesGranted
*
pVotesGranted
);
char
*
voteGranted2Str
(
SVotesGranted
*
pVotesGranted
);
// SVotesRespond -----------------------------
typedef
struct
SVotesRespond
{
...
...
@@ -62,8 +62,8 @@ void votesRespondDestory(SVotesRespond *pVotesRespond);
bool
votesResponded
(
SVotesRespond
*
pVotesRespond
,
const
SRaftId
*
pRaftId
);
void
votesRespondAdd
(
SVotesRespond
*
pVotesRespond
,
const
SyncRequestVoteReply
*
pMsg
);
void
votesRespondReset
(
SVotesRespond
*
pVotesRespond
,
SyncTerm
term
);
cJSON
*
votesRespond2Json
(
SVotesRespond
*
pVotesRespond
);
char
*
votesRespond2Str
(
SVotesRespond
*
pVotesRespond
);
cJSON
*
votesRespond2Json
(
SVotesRespond
*
pVotesRespond
);
char
*
votesRespond2Str
(
SVotesRespond
*
pVotesRespond
);
#ifdef __cplusplus
}
...
...
source/libs/sync/src/syncMain.c
浏览文件 @
0c8f62f7
...
...
@@ -18,8 +18,10 @@
#include "syncAppendEntries.h"
#include "syncAppendEntriesReply.h"
#include "syncEnv.h"
#include "syncIndexMgr.h"
#include "syncInt.h"
#include "syncRaft.h"
#include "syncRaftLog.h"
#include "syncRaftStore.h"
#include "syncRequestVote.h"
#include "syncRequestVoteReply.h"
...
...
@@ -78,7 +80,7 @@ SSyncNode* syncNodeOpen(const SSyncInfo* pSyncInfo) {
pSyncNode
->
vgId
=
pSyncInfo
->
vgId
;
pSyncNode
->
syncCfg
=
pSyncInfo
->
syncCfg
;
memcpy
(
pSyncNode
->
path
,
pSyncInfo
->
path
,
sizeof
(
pSyncNode
->
path
));
memcpy
(
pSyncNode
->
walPath
,
pSyncInfo
->
walPath
,
sizeof
(
pSyncNode
->
walPath
))
;
pSyncNode
->
pWal
=
pSyncInfo
->
pWal
;
pSyncNode
->
rpcClient
=
pSyncInfo
->
rpcClient
;
pSyncNode
->
FpSendMsg
=
pSyncInfo
->
FpSendMsg
;
pSyncNode
->
queue
=
pSyncInfo
->
queue
;
...
...
@@ -114,20 +116,26 @@ SSyncNode* syncNodeOpen(const SSyncInfo* pSyncInfo) {
// init life cycle
// init server vars
// init
TLA+
server vars
pSyncNode
->
state
=
TAOS_SYNC_STATE_FOLLOWER
;
pSyncNode
->
pRaftStore
=
raftStoreOpen
(
pSyncInfo
->
walPath
);
assert
(
pSyncNode
->
pRaftStore
!=
NULL
);
// init candidate vars
// init
TLA+
candidate vars
pSyncNode
->
pVotesGranted
=
voteGrantedCreate
(
pSyncNode
);
assert
(
pSyncNode
->
pVotesGranted
!=
NULL
);
pSyncNode
->
pVotesRespond
=
votesRespondCreate
(
pSyncNode
);
assert
(
pSyncNode
->
pVotesRespond
!=
NULL
);
// init leader vars
pSyncNode
->
pNextIndex
=
NULL
;
pSyncNode
->
pMatchIndex
=
NULL
;
// init TLA+ leader vars
pSyncNode
->
pNextIndex
=
syncIndexMgrCreate
(
pSyncNode
);
assert
(
pSyncNode
->
pNextIndex
!=
NULL
);
pSyncNode
->
pMatchIndex
=
syncIndexMgrCreate
(
pSyncNode
);
assert
(
pSyncNode
->
pMatchIndex
!=
NULL
);
// init TLA+ log vars
pSyncNode
->
pLogStore
=
logStoreCreate
(
pSyncNode
);
assert
(
pSyncNode
->
pLogStore
!=
NULL
);
pSyncNode
->
commitIndex
=
0
;
// init ping timer
pSyncNode
->
pPingTimer
=
NULL
;
...
...
@@ -177,7 +185,8 @@ cJSON* syncNode2Json(const SSyncNode* pSyncNode) {
// init by SSyncInfo
cJSON_AddNumberToObject
(
pRoot
,
"vgId"
,
pSyncNode
->
vgId
);
cJSON_AddStringToObject
(
pRoot
,
"path"
,
pSyncNode
->
path
);
cJSON_AddStringToObject
(
pRoot
,
"walPath"
,
pSyncNode
->
walPath
);
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%p"
,
pSyncNode
->
pWal
);
cJSON_AddStringToObject
(
pRoot
,
"pWal"
,
u64buf
);
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%p"
,
pSyncNode
->
rpcClient
);
cJSON_AddStringToObject
(
pRoot
,
"rpcClient"
,
u64buf
);
...
...
source/libs/sync/src/syncRaftLog.c
浏览文件 @
0c8f62f7
...
...
@@ -14,46 +14,61 @@
*/
#include "syncRaftLog.h"
#include "wal.h"
int32_t
raftLogAppendEntry
(
struct
SSyncLogStore
*
pLogStore
,
SSyncBuffer
*
pBuf
)
{
return
0
;
}
// get one log entry, user need to free pBuf->data
int32_t
raftLogGetEntry
(
struct
SSyncLogStore
*
pLogStore
,
SyncIndex
index
,
SSyncBuffer
*
pBuf
)
{
return
0
;
}
// TLA+ Spec
// \* Leader i advances its commitIndex.
// \* This is done as a separate step from handling AppendEntries responses,
// \* in part to minimize atomic regions, and in part so that leaders of
// \* single-server clusters are able to mark entries committed.
// AdvanceCommitIndex(i) ==
// /\ state[i] = Leader
// /\ LET \* The set of servers that agree up through index.
// Agree(index) == {i} \cup {k \in Server :
// matchIndex[i][k] >= index}
// \* The maximum indexes for which a quorum agrees
// agreeIndexes == {index \in 1..Len(log[i]) :
// Agree(index) \in Quorum}
// \* New value for commitIndex'[i]
// newCommitIndex ==
// IF /\ agreeIndexes /= {}
// /\ log[i][Max(agreeIndexes)].term = currentTerm[i]
// THEN
// Max(agreeIndexes)
// ELSE
// commitIndex[i]
// IN commitIndex' = [commitIndex EXCEPT ![i] = newCommitIndex]
// /\ UNCHANGED <<messages, serverVars, candidateVars, leaderVars, log>>
//
int32_t
raftLogupdateCommitIndex
(
struct
SSyncLogStore
*
pLogStore
,
SyncIndex
index
)
{
return
0
;
}
// truncate log with index, entries after the given index (>index) will be deleted
int32_t
raftLogTruncate
(
struct
SSyncLogStore
*
pLogStore
,
SyncIndex
index
)
{
return
0
;
}
SSyncLogStore
*
logStoreCreate
(
SSyncNode
*
pSyncNode
)
{
SSyncLogStore
*
pLogStore
=
malloc
(
sizeof
(
SSyncLogStore
));
assert
(
pLogStore
!=
NULL
);
// return commit index of log
SyncIndex
raftLogGetCommitIndex
(
struct
SSyncLogStore
*
pLogStore
)
{
return
0
;
}
pLogStore
->
data
=
malloc
(
sizeof
(
SSyncLogStoreData
));
assert
(
pLogStore
->
data
!=
NULL
);
SSyncLogStoreData
*
pData
=
pLogStore
->
data
;
pData
->
pSyncNode
=
pSyncNode
;
pData
->
pWal
=
pSyncNode
->
pWal
;
pLogStore
->
appendEntry
=
logStoreAppendEntry
;
pLogStore
->
getEntry
=
logStoreGetEntry
;
pLogStore
->
truncate
=
logStoreTruncate
;
pLogStore
->
getLastIndex
=
logStoreLastIndex
;
pLogStore
->
getLastTerm
=
logStoreLastTerm
;
pLogStore
->
updateCommitIndex
=
logStoreUpdateCommitIndex
;
pLogStore
->
getCommitIndex
=
logStoreGetCommitIndex
;
}
void
logStoreDestory
(
SSyncLogStore
*
pLogStore
)
{
if
(
pLogStore
!=
NULL
)
{
free
(
pLogStore
->
data
);
free
(
pLogStore
);
}
}
// append one log entry
int32_t
logStoreAppendEntry
(
SSyncLogStore
*
pLogStore
,
SRpcMsg
*
pEntry
)
{}
// get one log entry, user need to free pEntry->pCont
int32_t
logStoreGetEntry
(
SSyncLogStore
*
pLogStore
,
SyncIndex
index
,
SRpcMsg
*
pEntry
)
{}
// truncate log with index, entries after the given index (>=index) will be deleted
int32_t
logStoreTruncate
(
SSyncLogStore
*
pLogStore
,
SyncIndex
fromIndex
)
{}
// return index of last entry
SyncIndex
raftLogGetLastIndex
(
struct
SSyncLogStore
*
pLogStore
)
{
return
0
;
}
SyncIndex
logStoreLastIndex
(
SSyncLogStore
*
pLogStore
)
{
}
// return term of last entry
SyncTerm
raftLogGetLastTerm
(
struct
SSyncLogStore
*
pLogStore
)
{
return
0
;
}
\ No newline at end of file
SyncTerm
logStoreLastTerm
(
SSyncLogStore
*
pLogStore
)
{}
// update log store commit index with "index"
int32_t
logStoreUpdateCommitIndex
(
SSyncLogStore
*
pLogStore
,
SyncIndex
index
)
{}
// return commit index of log
SyncIndex
logStoreGetCommitIndex
(
SSyncLogStore
*
pLogStore
)
{}
cJSON
*
logStore2Json
(
SSyncLogStore
*
pLogStore
)
{}
char
*
logStore2Str
(
SSyncLogStore
*
pLogStore
)
{
cJSON
*
pJson
=
logStore2Json
(
pLogStore
);
char
*
serialized
=
cJSON_Print
(
pJson
);
cJSON_Delete
(
pJson
);
return
serialized
;
}
\ No newline at end of file
source/libs/sync/test/syncIndexMgrTest.cpp
浏览文件 @
0c8f62f7
...
...
@@ -34,7 +34,6 @@ SSyncNode* syncNodeInit() {
syncInfo
.
FpEqMsg
=
syncIOEqMsg
;
syncInfo
.
pFsm
=
pFsm
;
snprintf
(
syncInfo
.
path
,
sizeof
(
syncInfo
.
path
),
"%s"
,
"./test_path"
);
snprintf
(
syncInfo
.
walPath
,
sizeof
(
syncInfo
.
walPath
),
"%s"
,
"./test_wal_path"
);
SSyncCfg
*
pCfg
=
&
syncInfo
.
syncCfg
;
pCfg
->
myIndex
=
myIndex
;
...
...
source/libs/sync/test/syncInitTest.cpp
浏览文件 @
0c8f62f7
...
...
@@ -31,7 +31,6 @@ SSyncNode* syncNodeInit() {
syncInfo
.
FpEqMsg
=
syncIOEqMsg
;
syncInfo
.
pFsm
=
pFsm
;
snprintf
(
syncInfo
.
path
,
sizeof
(
syncInfo
.
path
),
"%s"
,
"./test_path"
);
snprintf
(
syncInfo
.
walPath
,
sizeof
(
syncInfo
.
walPath
),
"%s"
,
"./test_wal_path"
);
SSyncCfg
*
pCfg
=
&
syncInfo
.
syncCfg
;
pCfg
->
myIndex
=
myIndex
;
...
...
source/libs/sync/test/syncPingTest.cpp
浏览文件 @
0c8f62f7
...
...
@@ -26,7 +26,6 @@ SSyncNode* doSync(int myIndex) {
syncInfo
.
FpEqMsg
=
syncIOEqMsg
;
syncInfo
.
pFsm
=
pFsm
;
snprintf
(
syncInfo
.
path
,
sizeof
(
syncInfo
.
path
),
"%s"
,
"./path"
);
snprintf
(
syncInfo
.
walPath
,
sizeof
(
syncInfo
.
walPath
),
"%s"
,
"./wal_path"
);
SSyncCfg
*
pCfg
=
&
syncInfo
.
syncCfg
;
pCfg
->
myIndex
=
myIndex
;
...
...
source/libs/sync/test/syncVotesGrantedTest.cpp
浏览文件 @
0c8f62f7
...
...
@@ -33,7 +33,6 @@ SSyncNode* syncNodeInit() {
syncInfo
.
FpEqMsg
=
syncIOEqMsg
;
syncInfo
.
pFsm
=
pFsm
;
snprintf
(
syncInfo
.
path
,
sizeof
(
syncInfo
.
path
),
"%s"
,
"./test_path"
);
snprintf
(
syncInfo
.
walPath
,
sizeof
(
syncInfo
.
walPath
),
"%s"
,
"./test_wal_path"
);
SSyncCfg
*
pCfg
=
&
syncInfo
.
syncCfg
;
pCfg
->
myIndex
=
myIndex
;
...
...
source/libs/sync/test/syncVotesRespondTest.cpp
浏览文件 @
0c8f62f7
...
...
@@ -33,7 +33,6 @@ SSyncNode* syncNodeInit() {
syncInfo
.
FpEqMsg
=
syncIOEqMsg
;
syncInfo
.
pFsm
=
pFsm
;
snprintf
(
syncInfo
.
path
,
sizeof
(
syncInfo
.
path
),
"%s"
,
"./test_path"
);
snprintf
(
syncInfo
.
walPath
,
sizeof
(
syncInfo
.
walPath
),
"%s"
,
"./test_wal_path"
);
SSyncCfg
*
pCfg
=
&
syncInfo
.
syncCfg
;
pCfg
->
myIndex
=
myIndex
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录