Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
296d9abe
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看板
提交
296d9abe
编写于
2月 25, 2022
作者:
M
Minghao Li
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add sync code
上级
113618be
变更
35
隐藏空白更改
内联
并排
Showing
35 changed file
with
114 addition
and
76 deletion
+114
-76
include/libs/sync/sync.h
include/libs/sync/sync.h
+0
-4
source/libs/sync/inc/syncAppendEntries.h
source/libs/sync/inc/syncAppendEntries.h
+1
-0
source/libs/sync/inc/syncAppendEntriesReply.h
source/libs/sync/inc/syncAppendEntriesReply.h
+1
-0
source/libs/sync/inc/syncElection.h
source/libs/sync/inc/syncElection.h
+1
-0
source/libs/sync/inc/syncIO.h
source/libs/sync/inc/syncIO.h
+8
-5
source/libs/sync/inc/syncMessage.h
source/libs/sync/inc/syncMessage.h
+1
-1
source/libs/sync/inc/syncRaft.h
source/libs/sync/inc/syncRaft.h
+6
-1
source/libs/sync/inc/syncRaftEntry.h
source/libs/sync/inc/syncRaftEntry.h
+1
-1
source/libs/sync/inc/syncRaftLog.h
source/libs/sync/inc/syncRaftLog.h
+1
-1
source/libs/sync/inc/syncReplication.h
source/libs/sync/inc/syncReplication.h
+1
-0
source/libs/sync/inc/syncRequestVote.h
source/libs/sync/inc/syncRequestVote.h
+1
-0
source/libs/sync/inc/syncRequestVoteReply.h
source/libs/sync/inc/syncRequestVoteReply.h
+1
-0
source/libs/sync/inc/syncSnapshot.h
source/libs/sync/inc/syncSnapshot.h
+1
-1
source/libs/sync/inc/syncTimeout.h
source/libs/sync/inc/syncTimeout.h
+1
-0
source/libs/sync/inc/syncVoteMgr.h
source/libs/sync/inc/syncVoteMgr.h
+34
-0
source/libs/sync/src/syncAppendEntries.c
source/libs/sync/src/syncAppendEntries.c
+0
-1
source/libs/sync/src/syncAppendEntriesReply.c
source/libs/sync/src/syncAppendEntriesReply.c
+0
-1
source/libs/sync/src/syncElection.c
source/libs/sync/src/syncElection.c
+1
-1
source/libs/sync/src/syncEnv.c
source/libs/sync/src/syncEnv.c
+0
-2
source/libs/sync/src/syncIO.c
source/libs/sync/src/syncIO.c
+14
-10
source/libs/sync/src/syncMain.c
source/libs/sync/src/syncMain.c
+0
-1
source/libs/sync/src/syncMessage.c
source/libs/sync/src/syncMessage.c
+0
-1
source/libs/sync/src/syncOnMessage.c
source/libs/sync/src/syncOnMessage.c
+1
-1
source/libs/sync/src/syncRaft.c
source/libs/sync/src/syncRaft.c
+0
-1
source/libs/sync/src/syncRaftEntry.c
source/libs/sync/src/syncRaftEntry.c
+1
-1
source/libs/sync/src/syncRaftLog.c
source/libs/sync/src/syncRaftLog.c
+0
-1
source/libs/sync/src/syncRaftStore.c
source/libs/sync/src/syncRaftStore.c
+0
-1
source/libs/sync/src/syncReplication.c
source/libs/sync/src/syncReplication.c
+1
-1
source/libs/sync/src/syncRequestVote.c
source/libs/sync/src/syncRequestVote.c
+0
-1
source/libs/sync/src/syncRequestVoteReply.c
source/libs/sync/src/syncRequestVoteReply.c
+0
-1
source/libs/sync/src/syncSnapshot.c
source/libs/sync/src/syncSnapshot.c
+0
-1
source/libs/sync/src/syncTimeout.c
source/libs/sync/src/syncTimeout.c
+0
-1
source/libs/sync/src/syncVoteMgr.c
source/libs/sync/src/syncVoteMgr.c
+16
-0
source/libs/sync/test/syncEnvTest.cpp
source/libs/sync/test/syncEnvTest.cpp
+21
-33
source/libs/sync/test/syncTest.cpp
source/libs/sync/test/syncTest.cpp
+0
-2
未找到文件。
include/libs/sync/sync.h
浏览文件 @
296d9abe
...
...
@@ -131,10 +131,6 @@ typedef struct SStateMgr {
typedef
struct
{
SyncGroupId
vgId
;
SSyncCfg
syncCfg
;
SSyncLogStore
logStore
;
SStateMgr
stateManager
;
SSyncFSM
syncFsm
;
}
SSyncInfo
;
struct
SSyncNode
;
...
...
source/libs/sync/inc/syncAppendEntries.h
浏览文件 @
296d9abe
...
...
@@ -23,6 +23,7 @@ extern "C" {
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include "syncInt.h"
#include "syncMessage.h"
#include "syncRaft.h"
#include "taosdef.h"
...
...
source/libs/sync/inc/syncAppendEntriesReply.h
浏览文件 @
296d9abe
...
...
@@ -23,6 +23,7 @@ extern "C" {
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include "syncInt.h"
#include "syncMessage.h"
#include "syncRaft.h"
#include "taosdef.h"
...
...
source/libs/sync/inc/syncElection.h
浏览文件 @
296d9abe
...
...
@@ -24,6 +24,7 @@ extern "C" {
#include <stdio.h>
#include <stdlib.h>
#include "taosdef.h"
#include "syncInt.h"
#ifdef __cplusplus
}
...
...
source/libs/sync/inc/syncIO.h
浏览文件 @
296d9abe
...
...
@@ -50,13 +50,16 @@ typedef struct SSyncIO {
}
SSyncIO
;
int32_t
syncIOStart
();
int32_t
syncIOStop
();
SSyncIO
*
syncIOCreate
();
static
int32_t
s
yncIOStart
(
SSyncIO
*
io
);
static
int32_t
s
yncIOStop
(
SSyncIO
*
io
);
static
int32_t
s
yncIOPing
(
SSyncIO
*
io
);
static
int32_t
s
yncIOOnMessage
(
struct
SSyncIO
*
io
,
void
*
pParent
,
SRpcMsg
*
pMsg
,
SEpSet
*
pEpSet
);
static
int32_t
s
yncIODestroy
(
SSyncIO
*
io
);
static
int32_t
doS
yncIOStart
(
SSyncIO
*
io
);
static
int32_t
doS
yncIOStop
(
SSyncIO
*
io
);
static
int32_t
doS
yncIOPing
(
SSyncIO
*
io
);
static
int32_t
doS
yncIOOnMessage
(
struct
SSyncIO
*
io
,
void
*
pParent
,
SRpcMsg
*
pMsg
,
SEpSet
*
pEpSet
);
static
int32_t
doS
yncIODestroy
(
SSyncIO
*
io
);
#ifdef __cplusplus
}
...
...
source/libs/sync/inc/syncMessage.h
浏览文件 @
296d9abe
...
...
@@ -23,7 +23,7 @@ extern "C" {
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include "sync.h"
#include "sync
Int
.h"
#include "syncRaftEntry.h"
#include "taosdef.h"
...
...
source/libs/sync/inc/syncRaft.h
浏览文件 @
296d9abe
...
...
@@ -23,7 +23,7 @@ extern "C" {
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include "sync.h"
#include "sync
Int
.h"
#include "syncMessage.h"
#include "taosdef.h"
...
...
@@ -34,6 +34,11 @@ typedef struct SRaftId {
typedef
struct
SRaft
{
SRaftId
id
;
SSyncLogStore
*
logStore
;
SStateMgr
*
stateManager
;
SSyncFSM
*
syncFsm
;
}
SRaft
;
int32_t
raftPropose
(
SRaft
*
pRaft
,
const
SSyncBuffer
*
pBuf
,
bool
isWeak
);
...
...
source/libs/sync/inc/syncRaftEntry.h
浏览文件 @
296d9abe
...
...
@@ -23,7 +23,7 @@ extern "C" {
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include "sync.h"
#include "sync
Int
.h"
#include "taosdef.h"
typedef
struct
SSyncRaftEntry
{
...
...
source/libs/sync/inc/syncRaftLog.h
浏览文件 @
296d9abe
...
...
@@ -23,7 +23,7 @@ extern "C" {
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include "sync.h"
#include "sync
Int
.h"
#include "taosdef.h"
int32_t
raftLogAppendEntry
(
struct
SSyncLogStore
*
pLogStore
,
SSyncBuffer
*
pBuf
);
...
...
source/libs/sync/inc/syncReplication.h
浏览文件 @
296d9abe
...
...
@@ -24,6 +24,7 @@ extern "C" {
#include <stdio.h>
#include <stdlib.h>
#include "taosdef.h"
#include "syncInt.h"
#ifdef __cplusplus
}
...
...
source/libs/sync/inc/syncRequestVote.h
浏览文件 @
296d9abe
...
...
@@ -23,6 +23,7 @@ extern "C" {
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include "syncInt.h"
#include "syncMessage.h"
#include "syncRaft.h"
#include "taosdef.h"
...
...
source/libs/sync/inc/syncRequestVoteReply.h
浏览文件 @
296d9abe
...
...
@@ -23,6 +23,7 @@ extern "C" {
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include "syncInt.h"
#include "syncMessage.h"
#include "syncRaft.h"
#include "taosdef.h"
...
...
source/libs/sync/inc/syncSnapshot.h
浏览文件 @
296d9abe
...
...
@@ -23,7 +23,7 @@ extern "C" {
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include "sync.h"
#include "sync
Int
.h"
#include "syncRaft.h"
#include "taosdef.h"
...
...
source/libs/sync/inc/syncTimeout.h
浏览文件 @
296d9abe
...
...
@@ -26,6 +26,7 @@ extern "C" {
#include "syncMessage.h"
#include "syncRaft.h"
#include "taosdef.h"
#include "syncInt.h"
void
onTimeout
(
SRaft
*
pRaft
,
void
*
pMsg
);
...
...
source/libs/sync/inc/syncVoteMgr.h
0 → 100644
浏览文件 @
296d9abe
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _TD_LIBS_SYNC_VOTG_MGR_H
#define _TD_LIBS_SYNC_VOTG_MGR_H
#ifdef __cplusplus
extern
"C"
{
#endif
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include "taosdef.h"
#include "syncInt.h"
#ifdef __cplusplus
}
#endif
#endif
/*_TD_LIBS_SYNC_VOTG_MGR_H*/
source/libs/sync/src/syncAppendEntries.c
浏览文件 @
296d9abe
...
...
@@ -14,7 +14,6 @@
*/
#include "syncAppendEntries.h"
#include "sync.h"
void
appendEntries
(
SRaft
*
pRaft
,
const
SyncAppendEntries
*
pMsg
)
{
// TLA+ Spec
...
...
source/libs/sync/src/syncAppendEntriesReply.c
浏览文件 @
296d9abe
...
...
@@ -14,7 +14,6 @@
*/
#include "syncAppendEntriesReply.h"
#include "sync.h"
void
onAppendEntriesReply
(
SRaft
*
pRaft
,
const
SyncAppendEntriesReply
*
pMsg
)
{
// TLA+ Spec
...
...
source/libs/sync/src/syncElection.c
浏览文件 @
296d9abe
...
...
@@ -13,4 +13,4 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "sync.h"
#include "sync
Election
.h"
source/libs/sync/src/syncEnv.c
浏览文件 @
296d9abe
...
...
@@ -15,8 +15,6 @@
#include "syncEnv.h"
#include <assert.h>
#include "sync.h"
#include "syncInt.h"
SSyncEnv
*
gSyncEnv
=
NULL
;
...
...
source/libs/sync/src/syncIO.c
浏览文件 @
296d9abe
...
...
@@ -20,6 +20,10 @@
#include "ttimer.h"
#include "tutil.h"
int32_t
syncIOStart
()
{
return
0
;
}
int32_t
syncIOStop
()
{
return
0
;
}
static
void
syncTick
(
void
*
param
,
void
*
tmrId
)
{
SSyncIO
*
io
=
(
SSyncIO
*
)
param
;
sDebug
(
"syncTick ... "
);
...
...
@@ -114,16 +118,16 @@ SSyncIO *syncIOCreate() {
io
->
pQset
=
taosOpenQset
();
taosAddIntoQset
(
io
->
pQset
,
io
->
pMsgQ
,
NULL
);
io
->
start
=
s
yncIOStart
;
io
->
stop
=
s
yncIOStop
;
io
->
ping
=
s
yncIOPing
;
io
->
onMessage
=
s
yncIOOnMessage
;
io
->
destroy
=
s
yncIODestroy
;
io
->
start
=
doS
yncIOStart
;
io
->
stop
=
doS
yncIOStop
;
io
->
ping
=
doS
yncIOPing
;
io
->
onMessage
=
doS
yncIOOnMessage
;
io
->
destroy
=
doS
yncIODestroy
;
return
io
;
}
static
int32_t
s
yncIOStart
(
SSyncIO
*
io
)
{
static
int32_t
doS
yncIOStart
(
SSyncIO
*
io
)
{
taosBlockSIGPIPE
();
tsRpcForceTcp
=
1
;
...
...
@@ -191,13 +195,13 @@ static int32_t syncIOStart(SSyncIO *io) {
return
0
;
}
static
int32_t
s
yncIOStop
(
SSyncIO
*
io
)
{
static
int32_t
doS
yncIOStop
(
SSyncIO
*
io
)
{
atomic_store_8
(
&
io
->
isStart
,
0
);
pthread_join
(
io
->
tid
,
NULL
);
return
0
;
}
static
int32_t
s
yncIOPing
(
SSyncIO
*
io
)
{
static
int32_t
doS
yncIOPing
(
SSyncIO
*
io
)
{
SRpcMsg
rpcMsg
,
rspMsg
;
rpcMsg
.
pCont
=
rpcMallocCont
(
10
);
...
...
@@ -211,9 +215,9 @@ static int32_t syncIOPing(SSyncIO *io) {
return
0
;
}
static
int32_t
s
yncIOOnMessage
(
struct
SSyncIO
*
io
,
void
*
pParent
,
SRpcMsg
*
pMsg
,
SEpSet
*
pEpSet
)
{
return
0
;
}
static
int32_t
doS
yncIOOnMessage
(
struct
SSyncIO
*
io
,
void
*
pParent
,
SRpcMsg
*
pMsg
,
SEpSet
*
pEpSet
)
{
return
0
;
}
static
int32_t
s
yncIODestroy
(
SSyncIO
*
io
)
{
static
int32_t
doS
yncIODestroy
(
SSyncIO
*
io
)
{
int8_t
start
=
atomic_load_8
(
&
io
->
isStart
);
assert
(
start
==
0
);
...
...
source/libs/sync/src/syncMain.c
浏览文件 @
296d9abe
...
...
@@ -14,7 +14,6 @@
*/
#include <stdint.h>
#include "sync.h"
#include "syncEnv.h"
#include "syncInt.h"
...
...
source/libs/sync/src/syncMessage.c
浏览文件 @
296d9abe
...
...
@@ -14,7 +14,6 @@
*/
#include "syncMessage.h"
#include "sync.h"
#include "syncRaft.h"
void
onMessage
(
SRaft
*
pRaft
,
void
*
pMsg
)
{}
\ No newline at end of file
source/libs/sync/src/syncOnMessage.c
浏览文件 @
296d9abe
...
...
@@ -13,4 +13,4 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "sync.h"
#include "sync
OnMessage
.h"
source/libs/sync/src/syncRaft.c
浏览文件 @
296d9abe
...
...
@@ -14,7 +14,6 @@
*/
#include "syncRaft.h"
#include "sync.h"
int32_t
raftPropose
(
SRaft
*
pRaft
,
const
SSyncBuffer
*
pBuf
,
bool
isWeak
)
{
return
0
;
}
...
...
source/libs/sync/src/syncRaftEntry.c
浏览文件 @
296d9abe
...
...
@@ -13,4 +13,4 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "sync.h"
#include "sync
RaftEntry
.h"
source/libs/sync/src/syncRaftLog.c
浏览文件 @
296d9abe
...
...
@@ -14,7 +14,6 @@
*/
#include "syncRaftLog.h"
#include "sync.h"
int32_t
raftLogAppendEntry
(
struct
SSyncLogStore
*
pLogStore
,
SSyncBuffer
*
pBuf
)
{
return
0
;
}
...
...
source/libs/sync/src/syncRaftStore.c
浏览文件 @
296d9abe
...
...
@@ -15,7 +15,6 @@
#include "syncRaftStore.h"
#include "cJSON.h"
#include "sync.h"
SRaftStore
*
raftStoreOpen
(
const
char
*
path
)
{
int32_t
ret
;
...
...
source/libs/sync/src/syncReplication.c
浏览文件 @
296d9abe
...
...
@@ -13,4 +13,4 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "sync.h"
#include "sync
Replication
.h"
source/libs/sync/src/syncRequestVote.c
浏览文件 @
296d9abe
...
...
@@ -14,7 +14,6 @@
*/
#include "syncRequestVote.h"
#include "sync.h"
void
requestVote
(
SRaft
*
pRaft
,
const
SyncRequestVote
*
pMsg
)
{
// TLA+ Spec
...
...
source/libs/sync/src/syncRequestVoteReply.c
浏览文件 @
296d9abe
...
...
@@ -14,7 +14,6 @@
*/
#include "syncRequestVoteReply.h"
#include "sync.h"
void
onRequestVoteReply
(
SRaft
*
pRaft
,
const
SyncRequestVoteReply
*
pMsg
)
{
// TLA+ Spec
...
...
source/libs/sync/src/syncSnapshot.c
浏览文件 @
296d9abe
...
...
@@ -14,7 +14,6 @@
*/
#include "syncSnapshot.h"
#include "sync.h"
#include "syncRaft.h"
int32_t
takeSnapshot
(
SSyncFSM
*
pFsm
,
SSnapshot
*
pSnapshot
)
{
return
0
;
}
...
...
source/libs/sync/src/syncTimeout.c
浏览文件 @
296d9abe
...
...
@@ -14,6 +14,5 @@
*/
#include "syncTimeout.h"
#include "sync.h"
void
onTimeout
(
SRaft
*
pRaft
,
void
*
pMsg
)
{}
\ No newline at end of file
source/libs/sync/src/syncVoteMgr.c
0 → 100644
浏览文件 @
296d9abe
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "syncVoteMgr.h"
source/libs/sync/test/syncEnvTest.cpp
浏览文件 @
296d9abe
#include "syncEnv.h"
#include <stdio.h>
#include "syncIO.h"
#include "syncInt.h"
#include "syncRaftStore.h"
void
*
pingFunc
(
void
*
param
)
{
SSyncIO
*
io
=
(
SSyncIO
*
)
param
;
while
(
1
)
{
sDebug
(
"io->ping"
);
io
->
ping
(
io
);
sleep
(
1
);
}
return
NULL
;
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"
);
}
int
main
()
{
taosInitLog
((
char
*
)
"syncEnvTest.log"
,
100000
,
10
);
tsAsyncLog
=
0
;
taosInitLog
((
char
*
)
"syncTest.log"
,
100000
,
10
);
SRaftStore
*
pRaftStore
=
raftStoreOpen
(
"./raft_store.json"
);
assert
(
pRaftStore
!=
NULL
);
raftStorePrint
(
pRaftStore
);
pRaftStore
->
currentTerm
=
100
;
pRaftStore
->
voteFor
.
addr
=
200
;
pRaftStore
->
voteFor
.
vgId
=
300
;
raftStorePrint
(
pRaftStore
);
raftStorePersist
(
pRaftStore
);
tsAsyncLog
=
0
;
taosInitLog
((
char
*
)
"syncTest.log"
,
100000
,
10
);
sDebugFlag
=
143
+
64
;
sDebug
(
"sync test"
);
logTest
(
);
SSyncIO
*
syncIO
=
syncIOCreate
();
assert
(
syncIO
!=
NULL
);
int32_t
ret
=
syncEnvStart
();
assert
(
ret
==
0
);
syncIO
->
start
(
syncIO
);
ret
=
syncIOStart
();
assert
(
ret
==
0
);
sleep
(
2
);
SSyncInfo
syncInfo
;
syncInfo
.
vgId
=
1
;
pthread_t
tid
;
pthread_create
(
&
tid
,
NULL
,
pingFunc
,
syncIO
);
SSyncNode
*
pSyncNode
=
syncNodeStart
(
&
syncInfo
)
;
assert
(
pSyncNode
!=
NULL
);
while
(
1
)
{
sleep
(
1
);
taosMsleep
(
1000
);
}
return
0
;
}
source/libs/sync/test/syncTest.cpp
浏览文件 @
296d9abe
...
...
@@ -25,8 +25,6 @@ int main() {
sError
(
"sync log test: error"
);
sFatal
(
"sync log test: fatal"
);
SRaftStore
*
pRaftStore
=
raftStoreOpen
(
"./raft_store.json"
);
assert
(
pRaftStore
!=
NULL
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录