Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
77cd6f44
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看板
提交
77cd6f44
编写于
6月 08, 2022
作者:
M
Minghao Li
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactor(sync): syncUtilJson2Line
上级
2547e8d0
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
66 addition
and
16 deletion
+66
-16
source/libs/sync/inc/syncIndexMgr.h
source/libs/sync/inc/syncIndexMgr.h
+2
-2
source/libs/sync/inc/syncUtil.h
source/libs/sync/inc/syncUtil.h
+1
-0
source/libs/sync/src/syncSnapshot.c
source/libs/sync/src/syncSnapshot.c
+15
-9
source/libs/sync/src/syncUtil.c
source/libs/sync/src/syncUtil.c
+22
-0
source/libs/sync/test/syncIndexMgrTest.cpp
source/libs/sync/test/syncIndexMgrTest.cpp
+5
-5
source/libs/sync/test/syncTimeoutTest.cpp
source/libs/sync/test/syncTimeoutTest.cpp
+21
-0
未找到文件。
source/libs/sync/inc/syncIndexMgr.h
浏览文件 @
77cd6f44
...
...
@@ -41,8 +41,8 @@ void syncIndexMgrDestroy(SSyncIndexMgr *pSyncIndexMgr);
void
syncIndexMgrClear
(
SSyncIndexMgr
*
pSyncIndexMgr
);
void
syncIndexMgrSetIndex
(
SSyncIndexMgr
*
pSyncIndexMgr
,
const
SRaftId
*
pRaftId
,
SyncIndex
index
);
SyncIndex
syncIndexMgrGetIndex
(
SSyncIndexMgr
*
pSyncIndexMgr
,
const
SRaftId
*
pRaftId
);
cJSON
*
syncIndexMgr2Json
(
SSyncIndexMgr
*
pSyncIndexMgr
);
char
*
syncIndexMgr2Str
(
SSyncIndexMgr
*
pSyncIndexMgr
);
cJSON
*
syncIndexMgr2Json
(
SSyncIndexMgr
*
pSyncIndexMgr
);
char
*
syncIndexMgr2Str
(
SSyncIndexMgr
*
pSyncIndexMgr
);
// void syncIndexMgrSetTerm(SSyncIndexMgr *pSyncIndexMgr, const SRaftId *pRaftId, SyncTerm term);
// SyncTerm syncIndexMgrGetTerm(SSyncIndexMgr *pSyncIndexMgr, const SRaftId *pRaftId);
...
...
source/libs/sync/inc/syncUtil.h
浏览文件 @
77cd6f44
...
...
@@ -61,6 +61,7 @@ bool syncUtilIsData(tmsg_t msgType);
bool
syncUtilUserPreCommit
(
tmsg_t
msgType
);
bool
syncUtilUserCommit
(
tmsg_t
msgType
);
bool
syncUtilUserRollback
(
tmsg_t
msgType
);
void
syncUtilJson2Line
(
char
*
jsonStr
);
#ifdef __cplusplus
}
...
...
source/libs/sync/src/syncSnapshot.c
浏览文件 @
77cd6f44
...
...
@@ -296,7 +296,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
;
}
...
...
@@ -416,7 +416,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
;
}
...
...
@@ -438,7 +438,8 @@ int32_t syncNodeOnSnapshotSendCb(SSyncNode *pSyncNode, SyncSnapshotSend *pMsg) {
needRsp
=
true
;
char
*
msgStr
=
syncSnapshotSend2Str
(
pMsg
);
sTrace
(
"snapshot recv begin ack:%d, lastIndex:%ld, lastTerm:%lu, recv msg:%s"
,
pReceiver
->
ack
,
pMsg
->
lastIndex
,
pMsg
->
lastTerm
,
msgStr
);
sTrace
(
"snapshot recv begin ack:%d, lastIndex:%ld, lastTerm:%lu, recv msg:%s"
,
pReceiver
->
ack
,
pMsg
->
lastIndex
,
pMsg
->
lastTerm
,
msgStr
);
taosMemoryFree
(
msgStr
);
}
else
if
(
pMsg
->
seq
==
SYNC_SNAPSHOT_SEQ_END
)
{
...
...
@@ -447,10 +448,13 @@ int32_t syncNodeOnSnapshotSendCb(SSyncNode *pSyncNode, SyncSnapshotSend *pMsg) {
pSyncNode
->
pFsm
->
FpSnapshotStopWrite
(
pSyncNode
->
pFsm
,
pReceiver
->
pWriter
,
true
);
pSyncNode
->
pLogStore
->
syncLogSetBeginIndex
(
pSyncNode
->
pLogStore
,
pMsg
->
lastIndex
+
1
);
char
*
logSimpleStr
=
logStoreSimple2Str
(
pSyncNode
->
pLogStore
);
char
*
logSimpleStr
=
logStoreSimple2Str
(
pSyncNode
->
pLogStore
);
SSnapshot
snapshot
;
pSyncNode
->
pFsm
->
FpGetSnapshot
(
pSyncNode
->
pFsm
,
&
snapshot
);
sInfo
(
"snapshot recv finish, update log begin index:%ld, snapshot.lastApplyIndex:%ld, snapshot.lastApplyTerm:%lu, raft log:%s"
,
pMsg
->
lastIndex
+
1
,
snapshot
.
lastApplyIndex
,
snapshot
.
lastApplyTerm
,
logSimpleStr
);
sInfo
(
"snapshot recv finish, update log begin index:%ld, snapshot.lastApplyIndex:%ld, "
"snapshot.lastApplyTerm:%lu, raft log:%s"
,
pMsg
->
lastIndex
+
1
,
snapshot
.
lastApplyIndex
,
snapshot
.
lastApplyTerm
,
logSimpleStr
);
taosMemoryFree
(
logSimpleStr
);
// walRestoreFromSnapshot(pSyncNode->pWal, pMsg->lastIndex);
...
...
@@ -462,7 +466,8 @@ int32_t syncNodeOnSnapshotSendCb(SSyncNode *pSyncNode, SyncSnapshotSend *pMsg) {
needRsp
=
true
;
char
*
msgStr
=
syncSnapshotSend2Str
(
pMsg
);
sTrace
(
"snapshot recv end ack:%d, lastIndex:%ld, lastTerm:%lu, recv msg:%s"
,
pReceiver
->
ack
,
pMsg
->
lastIndex
,
pMsg
->
lastTerm
,
msgStr
);
sTrace
(
"snapshot recv end ack:%d, lastIndex:%ld, lastTerm:%lu, recv msg:%s"
,
pReceiver
->
ack
,
pMsg
->
lastIndex
,
pMsg
->
lastTerm
,
msgStr
);
taosMemoryFree
(
msgStr
);
}
else
if
(
pMsg
->
seq
==
SYNC_SNAPSHOT_SEQ_FORCE_CLOSE
)
{
...
...
@@ -471,9 +476,9 @@ int32_t syncNodeOnSnapshotSendCb(SSyncNode *pSyncNode, SyncSnapshotSend *pMsg) {
needRsp
=
false
;
char
*
msgStr
=
syncSnapshotSend2Str
(
pMsg
);
sTrace
(
"snapshot recv force close ack:%d, lastIndex:%ld, lastTerm:%lu, recv msg:%s"
,
pReceiver
->
ack
,
pMsg
->
lastIndex
,
pMsg
->
lastTerm
,
msgStr
);
sTrace
(
"snapshot recv force close ack:%d, lastIndex:%ld, lastTerm:%lu, recv msg:%s"
,
pReceiver
->
ack
,
pMsg
->
lastIndex
,
pMsg
->
lastTerm
,
msgStr
);
taosMemoryFree
(
msgStr
);
}
else
if
(
pMsg
->
seq
>
SYNC_SNAPSHOT_SEQ_BEGIN
&&
pMsg
->
seq
<
SYNC_SNAPSHOT_SEQ_END
)
{
...
...
@@ -485,7 +490,8 @@ int32_t syncNodeOnSnapshotSendCb(SSyncNode *pSyncNode, SyncSnapshotSend *pMsg) {
needRsp
=
true
;
char
*
msgStr
=
syncSnapshotSend2Str
(
pMsg
);
sTrace
(
"snapshot recv receiving ack:%d, lastIndex:%ld, lastTerm:%lu, recv msg:%s"
,
pReceiver
->
ack
,
pMsg
->
lastIndex
,
pMsg
->
lastTerm
,
msgStr
);
sTrace
(
"snapshot recv receiving ack:%d, lastIndex:%ld, lastTerm:%lu, recv msg:%s"
,
pReceiver
->
ack
,
pMsg
->
lastIndex
,
pMsg
->
lastTerm
,
msgStr
);
taosMemoryFree
(
msgStr
);
}
else
{
...
...
source/libs/sync/src/syncUtil.c
浏览文件 @
77cd6f44
...
...
@@ -240,4 +240,26 @@ bool syncUtilUserRollback(tmsg_t msgType) {
return
true
;
}
return
false
;
}
void
syncUtilJson2Line
(
char
*
jsonStr
)
{
int
p
,
q
,
len
;
p
=
0
;
q
=
1
;
len
=
strlen
(
jsonStr
);
while
(
1
)
{
if
(
jsonStr
[
q
]
==
'\0'
)
{
jsonStr
[
p
+
1
]
=
'\0'
;
break
;
}
if
(
jsonStr
[
q
]
==
'\n'
||
jsonStr
[
q
]
==
' '
||
jsonStr
[
q
]
==
'\t'
)
{
q
++
;
continue
;
}
else
{
jsonStr
[
p
+
1
]
=
jsonStr
[
q
];
p
++
;
q
++
;
}
}
}
\ No newline at end of file
source/libs/sync/test/syncIndexMgrTest.cpp
浏览文件 @
77cd6f44
...
...
@@ -66,9 +66,9 @@ int main(int argc, char** argv) {
syncIndexMgrSetIndex
(
pSyncIndexMgr
,
&
ids
[
0
],
100
);
syncIndexMgrSetIndex
(
pSyncIndexMgr
,
&
ids
[
1
],
200
);
syncIndexMgrSetIndex
(
pSyncIndexMgr
,
&
ids
[
2
],
300
);
//syncIndexMgrSetTerm(pSyncIndexMgr, &ids[0], 700);
//syncIndexMgrSetTerm(pSyncIndexMgr, &ids[1], 800);
//syncIndexMgrSetTerm(pSyncIndexMgr, &ids[2], 900);
//
syncIndexMgrSetTerm(pSyncIndexMgr, &ids[0], 700);
//
syncIndexMgrSetTerm(pSyncIndexMgr, &ids[1], 800);
//
syncIndexMgrSetTerm(pSyncIndexMgr, &ids[2], 900);
{
char
*
serialized
=
syncIndexMgr2Str
(
pSyncIndexMgr
);
assert
(
serialized
!=
NULL
);
...
...
@@ -80,8 +80,8 @@ int main(int argc, char** argv) {
printf
(
"---------------------------------------
\n
"
);
for
(
int
i
=
0
;
i
<
pSyncIndexMgr
->
replicaNum
;
++
i
)
{
SyncIndex
idx
=
syncIndexMgrGetIndex
(
pSyncIndexMgr
,
&
ids
[
i
]);
//SyncTerm term = syncIndexMgrGetTerm(pSyncIndexMgr, &ids[i]);
//printf("%d: index:%ld term:%lu \n", i, idx, term);
//
SyncTerm term = syncIndexMgrGetTerm(pSyncIndexMgr, &ids[i]);
//
printf("%d: index:%ld term:%lu \n", i, idx, term);
}
printf
(
"---------------------------------------
\n
"
);
...
...
source/libs/sync/test/syncTimeoutTest.cpp
浏览文件 @
77cd6f44
...
...
@@ -78,6 +78,26 @@ void test5() {
syncTimeoutDestroy
(
pMsg2
);
}
void
test6
()
{
SyncTimeout
*
pMsg
=
createMsg
();
char
*
jsonStr
=
syncTimeout2Str
(
pMsg
);
sTrace
(
"jsonStr: %s"
,
jsonStr
);
syncUtilJson2Line
(
jsonStr
);
sTrace
(
"jsonStr: %s"
,
jsonStr
);
char
str
[
10
];
snprintf
(
str
,
sizeof
(
str
),
"%s"
,
"{}"
);
sTrace
(
"str: %s"
,
str
);
syncUtilJson2Line
(
str
);
sTrace
(
"str: %s"
,
str
);
snprintf
(
str
,
sizeof
(
str
),
"%s"
,
""
);
sTrace
(
"str: %s"
,
str
);
syncUtilJson2Line
(
str
);
sTrace
(
"str: %s"
,
str
);
}
int
main
()
{
tsAsyncLog
=
0
;
sDebugFlag
=
DEBUG_TRACE
+
DEBUG_SCREEN
+
DEBUG_FILE
;
...
...
@@ -88,6 +108,7 @@ int main() {
test3
();
test4
();
test5
();
test6
();
return
0
;
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录