Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
aa691d13
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看板
未验证
提交
aa691d13
编写于
5月 27, 2022
作者:
L
Li Minghao
提交者:
GitHub
5月 27, 2022
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #13096 from taosdata/feature/3.0_mhli
enh(sync) snapshot sender, receiver
上级
8bf795d8
3a1be0c5
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
89 addition
and
28 deletion
+89
-28
source/libs/sync/inc/syncInt.h
source/libs/sync/inc/syncInt.h
+6
-2
source/libs/sync/inc/syncRaftLog.h
source/libs/sync/inc/syncRaftLog.h
+15
-14
source/libs/sync/inc/syncSnapshot.h
source/libs/sync/inc/syncSnapshot.h
+30
-2
source/libs/sync/src/syncAppendEntries.c
source/libs/sync/src/syncAppendEntries.c
+5
-5
source/libs/sync/src/syncRaftLog.c
source/libs/sync/src/syncRaftLog.c
+12
-1
source/libs/sync/src/syncReplication.c
source/libs/sync/src/syncReplication.c
+1
-1
source/libs/sync/src/syncSnapshot.c
source/libs/sync/src/syncSnapshot.c
+18
-2
source/libs/sync/test/syncConfigChangeTest.cpp
source/libs/sync/test/syncConfigChangeTest.cpp
+2
-1
未找到文件。
source/libs/sync/inc/syncInt.h
浏览文件 @
aa691d13
...
...
@@ -55,6 +55,8 @@ typedef struct SVotesRespond SVotesRespond;
typedef
struct
SSyncIndexMgr
SSyncIndexMgr
;
typedef
struct
SRaftCfg
SRaftCfg
;
typedef
struct
SSyncRespMgr
SSyncRespMgr
;
typedef
struct
SSyncSnapshotSender
SSyncSnapshotSender
;
typedef
struct
SSyncSnapshotReceiver
SSyncSnapshotReceiver
;
typedef
struct
SSyncNode
{
// init by SSyncInfo
...
...
@@ -148,9 +150,11 @@ typedef struct SSyncNode {
SSyncRespMgr
*
pSyncRespMgr
;
// restore state
bool
restoreFinish
;
// sem_t restoreSem;
SSnapshot
*
pSnapshot
;
bool
restoreFinish
;
SSnapshot
*
pSnapshot
;
SSyncSnapshotSender
*
pSender
;
SSyncSnapshotReceiver
*
pReceiver
;
}
SSyncNode
;
...
...
source/libs/sync/inc/syncRaftLog.h
浏览文件 @
aa691d13
...
...
@@ -32,20 +32,21 @@ typedef struct SSyncLogStoreData {
SWal
*
pWal
;
}
SSyncLogStoreData
;
SSyncLogStore
*
logStoreCreate
(
SSyncNode
*
pSyncNode
);
void
logStoreDestory
(
SSyncLogStore
*
pLogStore
);
int32_t
logStoreAppendEntry
(
SSyncLogStore
*
pLogStore
,
SSyncRaftEntry
*
pEntry
);
SSyncRaftEntry
*
logStoreGetEntry
(
SSyncLogStore
*
pLogStore
,
SyncIndex
index
);
int32_t
logStoreTruncate
(
SSyncLogStore
*
pLogStore
,
SyncIndex
fromIndex
);
SyncIndex
logStoreLastIndex
(
SSyncLogStore
*
pLogStore
);
SyncTerm
logStoreLastTerm
(
SSyncLogStore
*
pLogStore
);
int32_t
logStoreUpdateCommitIndex
(
SSyncLogStore
*
pLogStore
,
SyncIndex
index
);
SyncIndex
logStoreGetCommitIndex
(
SSyncLogStore
*
pLogStore
);
SSyncRaftEntry
*
logStoreGetLastEntry
(
SSyncLogStore
*
pLogStore
);
cJSON
*
logStore2Json
(
SSyncLogStore
*
pLogStore
);
char
*
logStore2Str
(
SSyncLogStore
*
pLogStore
);
cJSON
*
logStoreSimple2Json
(
SSyncLogStore
*
pLogStore
);
char
*
logStoreSimple2Str
(
SSyncLogStore
*
pLogStore
);
SSyncLogStore
*
logStoreCreate
(
SSyncNode
*
pSyncNode
);
void
logStoreDestory
(
SSyncLogStore
*
pLogStore
);
cJSON
*
logStore2Json
(
SSyncLogStore
*
pLogStore
);
char
*
logStore2Str
(
SSyncLogStore
*
pLogStore
);
cJSON
*
logStoreSimple2Json
(
SSyncLogStore
*
pLogStore
);
char
*
logStoreSimple2Str
(
SSyncLogStore
*
pLogStore
);
// SSyncRaftEntry* logStoreGetLastEntry(SSyncLogStore* pLogStore);
// SyncIndex logStoreLastIndex(SSyncLogStore* pLogStore);
// SyncTerm logStoreLastTerm(SSyncLogStore* pLogStore);
// SSyncRaftEntry* logStoreGetEntry(SSyncLogStore* pLogStore, SyncIndex index);
// int32_t logStoreAppendEntry(SSyncLogStore* pLogStore, SSyncRaftEntry* pEntry);
// int32_t logStoreTruncate(SSyncLogStore* pLogStore, SyncIndex fromIndex);
// int32_t logStoreUpdateCommitIndex(SSyncLogStore* pLogStore, SyncIndex index);
// SyncIndex logStoreGetCommitIndex(SSyncLogStore* pLogStore);
// for debug
void
logStorePrint
(
SSyncLogStore
*
pLogStore
);
...
...
source/libs/sync/inc/syncSnapshot.h
浏览文件 @
aa691d13
...
...
@@ -23,11 +23,39 @@ extern "C" {
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include "cJSON.h"
#include "syncInt.h"
#include "taosdef.h"
int32_t
takeSnapshot
(
SSyncFSM
*
pFsm
,
SSnapshot
*
pSnapshot
);
int32_t
restoreSnapshot
(
SSyncFSM
*
pFsm
,
SSnapshot
*
pSnapshot
);
typedef
struct
SSyncSnapshotSender
{
bool
isStart
;
int32_t
progressIndex
;
void
*
pCurrentBlock
;
int32_t
len
;
SSnapshot
*
pSnapshot
;
SSyncNode
*
pSyncNode
;
}
SSyncSnapshotSender
;
SSyncSnapshotSender
*
snapshotSenderCreate
(
SSyncNode
*
pSyncNode
);
void
snapshotSenderDestroy
(
SSyncSnapshotSender
*
pSender
);
int32_t
snapshotSend
(
SSyncSnapshotSender
*
pSender
);
cJSON
*
snapshotSender2Json
(
SSyncSnapshotSender
*
pSender
);
char
*
snapshotSender2Str
(
SSyncSnapshotSender
*
pSender
);
typedef
struct
SSyncSnapshotReceiver
{
bool
isStart
;
int32_t
progressIndex
;
void
*
pCurrentBlock
;
int32_t
len
;
SSnapshot
*
pSnapshot
;
SSyncNode
*
pSyncNode
;
}
SSyncSnapshotReceiver
;
SSyncSnapshotReceiver
*
snapshotReceiverCreate
(
SSyncNode
*
pSyncNode
);
void
snapshotReceiverDestroy
(
SSyncSnapshotReceiver
*
pReceiver
);
int32_t
snapshotReceive
(
SSyncSnapshotReceiver
*
pReceiver
);
cJSON
*
snapshotReceiver2Json
(
SSyncSnapshotReceiver
*
pReceiver
);
char
*
snapshotReceiver2Str
(
SSyncSnapshotReceiver
*
pReceiver
);
#ifdef __cplusplus
}
...
...
source/libs/sync/src/syncAppendEntries.c
浏览文件 @
aa691d13
...
...
@@ -107,7 +107,7 @@ int32_t syncNodeOnAppendEntriesCb(SSyncNode* ths, SyncAppendEntries* pMsg) {
SyncTerm
localPreLogTerm
=
0
;
if
(
pMsg
->
prevLogIndex
>=
SYNC_INDEX_BEGIN
&&
pMsg
->
prevLogIndex
<=
ths
->
pLogStore
->
getLastIndex
(
ths
->
pLogStore
))
{
SSyncRaftEntry
*
pEntry
=
logStoreG
etEntry
(
ths
->
pLogStore
,
pMsg
->
prevLogIndex
);
SSyncRaftEntry
*
pEntry
=
ths
->
pLogStore
->
g
etEntry
(
ths
->
pLogStore
,
pMsg
->
prevLogIndex
);
assert
(
pEntry
!=
NULL
);
localPreLogTerm
=
pEntry
->
term
;
syncEntryDestory
(
pEntry
);
...
...
@@ -175,7 +175,7 @@ int32_t syncNodeOnAppendEntriesCb(SSyncNode* ths, SyncAppendEntries* pMsg) {
bool
conflict
=
false
;
SyncIndex
extraIndex
=
pMsg
->
prevLogIndex
+
1
;
SSyncRaftEntry
*
pExtraEntry
=
logStoreG
etEntry
(
ths
->
pLogStore
,
extraIndex
);
SSyncRaftEntry
*
pExtraEntry
=
ths
->
pLogStore
->
g
etEntry
(
ths
->
pLogStore
,
extraIndex
);
assert
(
pExtraEntry
!=
NULL
);
SSyncRaftEntry
*
pAppendEntry
=
syncEntryDeserialize
(
pMsg
->
data
,
pMsg
->
dataLen
);
...
...
@@ -197,7 +197,7 @@ int32_t syncNodeOnAppendEntriesCb(SSyncNode* ths, SyncAppendEntries* pMsg) {
// notice! reverse roll back!
for
(
SyncIndex
index
=
delEnd
;
index
>=
delBegin
;
--
index
)
{
if
(
ths
->
pFsm
->
FpRollBackCb
!=
NULL
)
{
SSyncRaftEntry
*
pRollBackEntry
=
logStoreG
etEntry
(
ths
->
pLogStore
,
index
);
SSyncRaftEntry
*
pRollBackEntry
=
ths
->
pLogStore
->
g
etEntry
(
ths
->
pLogStore
,
index
);
assert
(
pRollBackEntry
!=
NULL
);
// if (pRollBackEntry->msgType != TDMT_VND_SYNC_NOOP) {
...
...
@@ -365,7 +365,7 @@ int32_t syncNodeOnAppendEntriesCb(SSyncNode* ths, SyncAppendEntries* pMsg) {
}
SReConfigCbMeta
cbMeta
=
{
0
};
bool
isDrop
;
bool
isDrop
;
// I am in newConfig
if
(
hit
)
{
...
...
@@ -388,7 +388,7 @@ int32_t syncNodeOnAppendEntriesCb(SSyncNode* ths, SyncAppendEntries* pMsg) {
}
// always call FpReConfigCb
if
(
ths
->
pFsm
->
FpReConfigCb
!=
NULL
)
{
if
(
ths
->
pFsm
->
FpReConfigCb
!=
NULL
)
{
cbMeta
.
code
=
0
;
cbMeta
.
currentTerm
=
ths
->
pRaftStore
->
currentTerm
;
cbMeta
.
index
=
pEntry
->
index
;
...
...
source/libs/sync/src/syncRaftLog.c
浏览文件 @
aa691d13
...
...
@@ -16,6 +16,15 @@
#include "syncRaftLog.h"
#include "wal.h"
static
SSyncRaftEntry
*
logStoreGetLastEntry
(
SSyncLogStore
*
pLogStore
);
static
SyncIndex
logStoreLastIndex
(
SSyncLogStore
*
pLogStore
);
static
SyncTerm
logStoreLastTerm
(
SSyncLogStore
*
pLogStore
);
static
SSyncRaftEntry
*
logStoreGetEntry
(
SSyncLogStore
*
pLogStore
,
SyncIndex
index
);
static
int32_t
logStoreAppendEntry
(
SSyncLogStore
*
pLogStore
,
SSyncRaftEntry
*
pEntry
);
static
int32_t
logStoreTruncate
(
SSyncLogStore
*
pLogStore
,
SyncIndex
fromIndex
);
static
int32_t
logStoreUpdateCommitIndex
(
SSyncLogStore
*
pLogStore
,
SyncIndex
index
);
static
SyncIndex
logStoreGetCommitIndex
(
SSyncLogStore
*
pLogStore
);
SSyncLogStore
*
logStoreCreate
(
SSyncNode
*
pSyncNode
)
{
SSyncLogStore
*
pLogStore
=
taosMemoryMalloc
(
sizeof
(
SSyncLogStore
));
assert
(
pLogStore
!=
NULL
);
...
...
@@ -78,7 +87,9 @@ SSyncRaftEntry* logStoreGetEntry(SSyncLogStore* pLogStore, SyncIndex index) {
if
(
index
>=
SYNC_INDEX_BEGIN
&&
index
<=
logStoreLastIndex
(
pLogStore
))
{
SWalReadHandle
*
pWalHandle
=
walOpenReadHandle
(
pWal
);
int32_t
code
=
walReadWithHandle
(
pWalHandle
,
index
);
ASSERT
(
pWalHandle
!=
NULL
);
int32_t
code
=
walReadWithHandle
(
pWalHandle
,
index
);
if
(
code
!=
0
)
{
int32_t
err
=
terrno
;
const
char
*
errStr
=
tstrerror
(
err
);
...
...
source/libs/sync/src/syncReplication.c
浏览文件 @
aa691d13
...
...
@@ -75,7 +75,7 @@ int32_t syncNodeAppendEntriesPeers(SSyncNode* pSyncNode) {
// SyncIndex lastIndex = syncUtilMinIndex(pSyncNode->pLogStore->getLastIndex(pSyncNode->pLogStore), nextIndex);
SyncAppendEntries
*
pMsg
=
NULL
;
SSyncRaftEntry
*
pEntry
=
logStoreG
etEntry
(
pSyncNode
->
pLogStore
,
nextIndex
);
SSyncRaftEntry
*
pEntry
=
pSyncNode
->
pLogStore
->
g
etEntry
(
pSyncNode
->
pLogStore
,
nextIndex
);
if
(
pEntry
!=
NULL
)
{
pMsg
=
syncAppendEntriesBuild
(
pEntry
->
bytes
,
pSyncNode
->
vgId
);
assert
(
pMsg
!=
NULL
);
...
...
source/libs/sync/src/syncSnapshot.c
浏览文件 @
aa691d13
...
...
@@ -15,6 +15,22 @@
#include "syncSnapshot.h"
int32_t
takeSnapshot
(
SSyncFSM
*
pFsm
,
SSnapshot
*
pSnapshot
)
{
return
0
;
}
SSyncSnapshotSender
*
snapshotSenderCreate
(
SSyncNode
*
pSyncNode
)
{
return
NULL
;
}
int32_t
restoreSnapshot
(
SSyncFSM
*
pFsm
,
SSnapshot
*
pSnapshot
)
{
return
0
;
}
\ No newline at end of file
void
snapshotSenderDestroy
(
SSyncSnapshotSender
*
pSender
)
{}
int32_t
snapshotSend
(
SSyncSnapshotSender
*
pSender
)
{
return
0
;
}
cJSON
*
snapshotSender2Json
(
SSyncSnapshotSender
*
pSender
)
{
return
NULL
;
}
char
*
snapshotSender2Str
(
SSyncSnapshotSender
*
pSender
)
{
return
NULL
;
}
SSyncSnapshotReceiver
*
snapshotReceiverCreate
(
SSyncNode
*
pSyncNode
)
{
return
NULL
;
}
void
snapshotReceiverDestroy
(
SSyncSnapshotReceiver
*
pReceiver
)
{}
int32_t
snapshotReceive
(
SSyncSnapshotReceiver
*
pReceiver
)
{
return
0
;
}
cJSON
*
snapshotReceiver2Json
(
SSyncSnapshotReceiver
*
pReceiver
)
{
return
NULL
;
}
char
*
snapshotReceiver2Str
(
SSyncSnapshotReceiver
*
pReceiver
)
{
return
NULL
;
}
source/libs/sync/test/syncConfigChangeTest.cpp
浏览文件 @
aa691d13
...
...
@@ -78,7 +78,8 @@ int32_t GetSnapshotCb(struct SSyncFSM* pFsm, SSnapshot* pSnapshot) {
void
RestoreFinishCb
(
struct
SSyncFSM
*
pFsm
)
{
sTrace
(
"==callback== ==RestoreFinishCb=="
);
}
void
ReConfigCb
(
struct
SSyncFSM
*
pFsm
,
SSyncCfg
newCfg
,
SReConfigCbMeta
cbMeta
)
{
sTrace
(
"==callback== ==ReConfigCb== flag:0x%lX, isDrop:%d, index:%ld, code:%d, currentTerm:%lu, term:%lu"
,
cbMeta
.
flag
,
cbMeta
.
isDrop
,
cbMeta
.
index
,
cbMeta
.
code
,
cbMeta
.
currentTerm
,
cbMeta
.
term
);
sTrace
(
"==callback== ==ReConfigCb== flag:0x%lX, isDrop:%d, index:%ld, code:%d, currentTerm:%lu, term:%lu"
,
cbMeta
.
flag
,
cbMeta
.
isDrop
,
cbMeta
.
index
,
cbMeta
.
code
,
cbMeta
.
currentTerm
,
cbMeta
.
term
);
}
SSyncFSM
*
createFsm
()
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录