Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
2071c5a7
T
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1187
Star
22018
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看板
提交
2071c5a7
编写于
6月 06, 2022
作者:
M
Minghao Li
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix(sync): sending snapshot
上级
0d7272a3
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
41 addition
and
18 deletion
+41
-18
source/libs/sync/src/syncAppendEntries.c
source/libs/sync/src/syncAppendEntries.c
+19
-9
source/libs/sync/src/syncMain.c
source/libs/sync/src/syncMain.c
+1
-1
source/libs/sync/src/syncRaftLog.c
source/libs/sync/src/syncRaftLog.c
+9
-2
source/libs/sync/src/syncSnapshot.c
source/libs/sync/src/syncSnapshot.c
+10
-4
source/libs/sync/test/syncTestTool.cpp
source/libs/sync/test/syncTestTool.cpp
+2
-2
未找到文件。
source/libs/sync/src/syncAppendEntries.c
浏览文件 @
2071c5a7
...
...
@@ -451,9 +451,11 @@ static bool syncNodeOnAppendEntriesLogOK(SSyncNode* pSyncNode, SyncAppendEntries
return
false
;
}
static
int32_t
syncNodeMakeLogSame
(
SSyncNode
*
ths
,
SyncAppendEntries
*
pMsg
,
SSyncRaftEntry
**
ppAppendEntry
)
{
static
int32_t
syncNodeMakeLogSame
(
SSyncNode
*
ths
,
SyncAppendEntries
*
pMsg
,
SSyncRaftEntry
**
ppAppendEntry
,
bool
*
pEntryAlreadyWritten
)
{
int32_t
code
;
*
ppAppendEntry
=
NULL
;
*
pEntryAlreadyWritten
=
false
;
// not conflict by default
bool
conflict
=
false
;
...
...
@@ -466,10 +468,15 @@ static int32_t syncNodeMakeLogSame(SSyncNode* ths, SyncAppendEntries* pMsg, SSyn
*
ppAppendEntry
=
syncEntryDeserialize
(
pMsg
->
data
,
pMsg
->
dataLen
);
ASSERT
(
*
ppAppendEntry
!=
NULL
);
// log not match, conflict, need delete
ASSERT
(
extraIndex
==
(
*
ppAppendEntry
)
->
index
);
if
(
pExtraEntry
->
term
!=
(
*
ppAppendEntry
)
->
term
)
{
// log not match, conflict, need delete
conflict
=
true
;
}
else
{
// log match, already written
ASSERT
(
extraIndex
==
(
*
ppAppendEntry
)
->
index
&&
pExtraEntry
->
term
==
(
*
ppAppendEntry
)
->
term
);
*
pEntryAlreadyWritten
=
true
;
sInfo
(
"entry already written, term:%lu, index:%ld"
,
pExtraEntry
->
term
,
pExtraEntry
->
index
);
}
syncEntryDestory
(
pExtraEntry
);
...
...
@@ -606,17 +613,20 @@ int32_t syncNodeOnAppendEntriesSnapshotCb(SSyncNode* ths, SyncAppendEntries* pMs
if
(
hasExtraEntries
&&
hasAppendEntries
)
{
// make log same
SSyncRaftEntry
*
pAppendEntry
;
code
=
syncNodeMakeLogSame
(
ths
,
pMsg
,
&
pAppendEntry
);
bool
entryAlreadyWritten
;
code
=
syncNodeMakeLogSame
(
ths
,
pMsg
,
&
pAppendEntry
,
&
entryAlreadyWritten
);
ASSERT
(
code
==
0
);
ASSERT
(
pAppendEntry
!=
NULL
);
// append new entries
code
=
ths
->
pLogStore
->
syncLogAppendEntry
(
ths
->
pLogStore
,
pAppendEntry
);
ASSERT
(
code
==
0
);
if
(
!
entryAlreadyWritten
)
{
// append new entries
code
=
ths
->
pLogStore
->
syncLogAppendEntry
(
ths
->
pLogStore
,
pAppendEntry
);
ASSERT
(
code
==
0
);
// pre commit
code
=
syncNodePreCommit
(
ths
,
pAppendEntry
);
ASSERT
(
code
==
0
);
// pre commit
code
=
syncNodePreCommit
(
ths
,
pAppendEntry
);
ASSERT
(
code
==
0
);
}
syncEntryDestory
(
pAppendEntry
);
...
...
source/libs/sync/src/syncMain.c
浏览文件 @
2071c5a7
...
...
@@ -1612,7 +1612,7 @@ int32_t syncNodeOnClientRequestCb(SSyncNode* ths, SyncClientRequest* pMsg) {
int32_t
ret
=
0
;
syncClientRequestLog2
(
"==syncNodeOnClientRequestCb=="
,
pMsg
);
SyncIndex
index
=
ths
->
pLogStore
->
getLastIndex
(
ths
->
pLogStore
)
+
1
;
SyncIndex
index
=
ths
->
pLogStore
->
syncLogWriteIndex
(
ths
->
pLogStore
)
;
SyncTerm
term
=
ths
->
pRaftStore
->
currentTerm
;
SSyncRaftEntry
*
pEntry
=
syncEntryBuild2
((
SyncClientRequest
*
)
pMsg
,
term
,
index
);
assert
(
pEntry
!=
NULL
);
...
...
source/libs/sync/src/syncRaftLog.c
浏览文件 @
2071c5a7
...
...
@@ -477,13 +477,20 @@ cJSON* logStoreSimple2Json(SSyncLogStore* pLogStore) {
cJSON_AddStringToObject
(
pRoot
,
"pSyncNode"
,
u64buf
);
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%p"
,
pData
->
pWal
);
cJSON_AddStringToObject
(
pRoot
,
"pWal"
,
u64buf
);
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%ld"
,
logStore
LastIndex
(
pLogStore
));
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%ld"
,
raftLog
LastIndex
(
pLogStore
));
cJSON_AddStringToObject
(
pRoot
,
"LastIndex"
,
u64buf
);
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%lu"
,
logStore
LastTerm
(
pLogStore
));
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%lu"
,
raftLog
LastTerm
(
pLogStore
));
cJSON_AddStringToObject
(
pRoot
,
"LastTerm"
,
u64buf
);
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%ld"
,
pData
->
beginIndex
);
cJSON_AddStringToObject
(
pRoot
,
"beginIndex"
,
u64buf
);
SyncIndex
endIndex
=
raftLogEndIndex
(
pLogStore
);
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%ld"
,
endIndex
);
cJSON_AddStringToObject
(
pRoot
,
"endIndex"
,
u64buf
);
int32_t
count
=
raftLogEntryCount
(
pLogStore
);
cJSON_AddNumberToObject
(
pRoot
,
"entryCount"
,
count
);
}
cJSON
*
pJson
=
cJSON_CreateObject
();
...
...
source/libs/sync/src/syncSnapshot.c
浏览文件 @
2071c5a7
...
...
@@ -14,6 +14,7 @@
*/
#include "syncSnapshot.h"
#include "syncRaftLog.h"
#include "syncRaftStore.h"
#include "syncUtil.h"
#include "wal.h"
...
...
@@ -284,7 +285,7 @@ cJSON *snapshotSender2Json(SSyncSnapshotSender *pSender) {
char
*
snapshotSender2Str
(
SSyncSnapshotSender
*
pSender
)
{
cJSON
*
pJson
=
snapshotSender2Json
(
pSender
);
char
*
serialized
=
cJSON_Print
(
pJson
);
char
*
serialized
=
cJSON_Print
(
pJson
);
cJSON_Delete
(
pJson
);
return
serialized
;
}
...
...
@@ -398,7 +399,7 @@ cJSON *snapshotReceiver2Json(SSyncSnapshotReceiver *pReceiver) {
char
*
snapshotReceiver2Str
(
SSyncSnapshotReceiver
*
pReceiver
)
{
cJSON
*
pJson
=
snapshotReceiver2Json
(
pReceiver
);
char
*
serialized
=
cJSON_Print
(
pJson
);
char
*
serialized
=
cJSON_Print
(
pJson
);
cJSON_Delete
(
pJson
);
return
serialized
;
}
...
...
@@ -427,8 +428,13 @@ int32_t syncNodeOnSnapshotSendCb(SSyncNode *pSyncNode, SyncSnapshotSend *pMsg) {
pSyncNode
->
pFsm
->
FpSnapshotDoWrite
(
pSyncNode
->
pFsm
,
pReceiver
->
pWriter
,
pMsg
->
data
,
pMsg
->
dataLen
);
pSyncNode
->
pFsm
->
FpSnapshotStopWrite
(
pSyncNode
->
pFsm
,
pReceiver
->
pWriter
,
true
);
walRestoreFromSnapshot
(
pSyncNode
->
pWal
,
pMsg
->
lastIndex
);
sInfo
(
"walRestoreFromSnapshot lastIndex:%ld"
,
pMsg
->
lastIndex
);
pSyncNode
->
pLogStore
->
syncLogSetBeginIndex
(
pSyncNode
->
pLogStore
,
pMsg
->
lastIndex
+
1
);
char
*
logSimpleStr
=
logStoreSimple2Str
(
pSyncNode
->
pLogStore
);
sInfo
(
"snapshot receive finish, update log begin index:%ld, raft log:%s"
,
pMsg
->
lastIndex
+
1
,
logSimpleStr
);
taosMemoryFree
(
logSimpleStr
);
// walRestoreFromSnapshot(pSyncNode->pWal, pMsg->lastIndex);
// sInfo("walRestoreFromSnapshot lastIndex:%ld", pMsg->lastIndex);
pReceiver
->
pWriter
=
NULL
;
snapshotReceiverStop
(
pReceiver
);
...
...
source/libs/sync/test/syncTestTool.cpp
浏览文件 @
2071c5a7
...
...
@@ -295,7 +295,7 @@ int main(int argc, char** argv) {
int32_t
lastApplyTerm
=
atoi
(
argv
[
5
]);
int32_t
writeRecordNum
=
atoi
(
argv
[
6
]);
bool
isStandBy
=
atoi
(
argv
[
7
]);
bool
isConfigChange
=
atoi
(
argv
[
8
]);
int32_t
isConfigChange
=
atoi
(
argv
[
8
]);
int32_t
iterTimes
=
atoi
(
argv
[
9
]);
int32_t
finishLastApplyIndex
=
atoi
(
argv
[
10
]);
int32_t
finishLastApplyTerm
=
atoi
(
argv
[
11
]);
...
...
@@ -308,7 +308,7 @@ int main(int argc, char** argv) {
// check parameter
assert
(
replicaNum
>=
1
&&
replicaNum
<=
5
);
assert
(
myIndex
>=
0
&&
myIndex
<
replicaNum
);
//
assert(myIndex >= 0 && myIndex < replicaNum);
assert
(
lastApplyIndex
>=
-
1
);
assert
(
lastApplyTerm
>=
0
);
assert
(
writeRecordNum
>=
0
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录