Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
f078f5b3
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看板
提交
f078f5b3
编写于
5月 26, 2022
作者:
M
Minghao Li
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix(sync): syncSetStandby
上级
4e1aa6b5
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
42 addition
and
2 deletion
+42
-2
include/libs/sync/sync.h
include/libs/sync/sync.h
+1
-0
source/libs/sync/src/syncMain.c
source/libs/sync/src/syncMain.c
+29
-0
source/libs/sync/test/syncConfigChangeTest.cpp
source/libs/sync/test/syncConfigChangeTest.cpp
+12
-2
未找到文件。
include/libs/sync/sync.h
浏览文件 @
f078f5b3
...
...
@@ -166,6 +166,7 @@ void syncCleanUp();
int64_t
syncOpen
(
const
SSyncInfo
*
pSyncInfo
);
void
syncStart
(
int64_t
rid
);
void
syncStop
(
int64_t
rid
);
int32_t
syncSetStandby
(
int64_t
rid
);
int32_t
syncReconfig
(
int64_t
rid
,
const
SSyncCfg
*
pSyncCfg
);
ESyncState
syncGetMyRole
(
int64_t
rid
);
const
char
*
syncGetMyRoleStr
(
int64_t
rid
);
...
...
source/libs/sync/src/syncMain.c
浏览文件 @
f078f5b3
...
...
@@ -141,9 +141,38 @@ void syncStop(int64_t rid) {
taosRemoveRef
(
tsNodeRefId
,
rid
);
}
int32_t
syncSetStandby
(
int64_t
rid
)
{
SSyncNode
*
pSyncNode
=
(
SSyncNode
*
)
taosAcquireRef
(
tsNodeRefId
,
rid
);
if
(
pSyncNode
==
NULL
)
{
return
-
1
;
}
if
(
pSyncNode
->
state
!=
TAOS_SYNC_STATE_LEADER
)
{
taosReleaseRef
(
tsNodeRefId
,
pSyncNode
->
rid
);
return
-
1
;
}
// state change
pSyncNode
->
state
=
TAOS_SYNC_STATE_FOLLOWER
;
syncNodeStopHeartbeatTimer
(
pSyncNode
);
// reset elect timer, long enough
int32_t
electMS
=
TIMER_MAX_MS
;
int32_t
ret
=
syncNodeRestartElectTimer
(
pSyncNode
,
electMS
);
ASSERT
(
ret
==
0
);
pSyncNode
->
pRaftCfg
->
isStandBy
=
1
;
raftCfgPersist
(
pSyncNode
->
pRaftCfg
);
taosReleaseRef
(
tsNodeRefId
,
pSyncNode
->
rid
);
return
0
;
}
int32_t
syncReconfig
(
int64_t
rid
,
const
SSyncCfg
*
pSyncCfg
)
{
int32_t
ret
=
0
;
char
*
configChange
=
syncCfg2Str
((
SSyncCfg
*
)
pSyncCfg
);
sInfo
(
"==syncReconfig== newconfig:%s"
,
configChange
);
SRpcMsg
rpcMsg
=
{
0
};
rpcMsg
.
msgType
=
TDMT_VND_SYNC_CONFIG_CHANGE
;
rpcMsg
.
info
.
noResp
=
1
;
...
...
source/libs/sync/test/syncConfigChangeTest.cpp
浏览文件 @
f078f5b3
...
...
@@ -77,13 +77,23 @@ 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
);
}
SSyncFSM
*
createFsm
()
{
SSyncFSM
*
pFsm
=
(
SSyncFSM
*
)
taosMemoryMalloc
(
sizeof
(
SSyncFSM
));
pFsm
->
FpCommitCb
=
CommitCb
;
pFsm
->
FpPreCommitCb
=
PreCommitCb
;
pFsm
->
FpRollBackCb
=
RollBackCb
;
pFsm
->
FpGetSnapshot
=
GetSnapshotCb
;
pFsm
->
FpRestoreFinishCb
=
RestoreFinishCb
;
pFsm
->
FpSnapshotApply
=
NULL
;
pFsm
->
FpSnapshotRead
=
NULL
;
pFsm
->
FpReConfigCb
=
ReConfigCb
;
return
pFsm
;
}
...
...
@@ -183,7 +193,7 @@ SRpcMsg* createRpcMsg(int i, int count, int myIndex) {
int
main
(
int
argc
,
char
**
argv
)
{
tsAsyncLog
=
0
;
sDebugFlag
=
DEBUG_TRACE
+
DEBUG_SCREEN
+
DEBUG_FILE
;
sDebugFlag
=
DEBUG_TRACE
+
DEBUG_SCREEN
+
DEBUG_FILE
+
DEBUG_INFO
;
if
(
argc
!=
7
)
{
usage
(
argv
[
0
]);
exit
(
-
1
);
...
...
@@ -229,7 +239,7 @@ int main(int argc, char** argv) {
assert
(
pSyncNode
!=
NULL
);
if
(
isConfigChange
)
{
configChange
(
rid
,
3
,
myIndex
);
configChange
(
rid
,
2
,
myIndex
);
}
//---------------------------
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录