Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
ec786b9d
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看板
提交
ec786b9d
编写于
10月 24, 2022
作者:
S
Shengliang Guan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix: alter replica one by one
上级
bbb0475d
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
68 addition
and
35 deletion
+68
-35
source/dnode/mnode/impl/src/mndSync.c
source/dnode/mnode/impl/src/mndSync.c
+12
-4
source/dnode/mnode/impl/src/mndVgroup.c
source/dnode/mnode/impl/src/mndVgroup.c
+1
-0
source/dnode/vnode/src/vnd/vnodeCommit.c
source/dnode/vnode/src/vnd/vnodeCommit.c
+1
-1
source/dnode/vnode/src/vnd/vnodeOpen.c
source/dnode/vnode/src/vnd/vnodeOpen.c
+7
-0
source/dnode/vnode/src/vnd/vnodeSync.c
source/dnode/vnode/src/vnd/vnodeSync.c
+21
-12
source/libs/sync/src/syncMain.c
source/libs/sync/src/syncMain.c
+26
-18
未找到文件。
source/dnode/mnode/impl/src/mndSync.c
浏览文件 @
ec786b9d
...
...
@@ -204,13 +204,21 @@ int32_t mndInitSync(SMnode *pMnode) {
taosInitRWLatch
(
&
pMgmt
->
lock
);
pMgmt
->
transId
=
0
;
SSyncInfo
syncInfo
=
{.
vgId
=
1
,
.
FpSendMsg
=
mndSyncSendMsg
,
.
FpEqMsg
=
mndSyncEqMsg
};
SSyncInfo
syncInfo
=
{
.
snapshotStrategy
=
SYNC_STRATEGY_STANDARD_SNAPSHOT
,
.
batchSize
=
1
,
.
vgId
=
1
,
.
pWal
=
pMnode
->
pWal
,
.
msgcb
=
NULL
,
.
FpSendMsg
=
mndSyncSendMsg
,
.
FpEqMsg
=
mndSyncEqMsg
,
.
FpEqCtrlMsg
=
NULL
,
};
snprintf
(
syncInfo
.
path
,
sizeof
(
syncInfo
.
path
),
"%s%ssync"
,
pMnode
->
path
,
TD_DIRSEP
);
syncInfo
.
pWal
=
pMnode
->
pWal
;
syncInfo
.
pFsm
=
mndSyncMakeFsm
(
pMnode
);
syncInfo
.
snapshotStrategy
=
SYNC_STRATEGY_STANDARD_SNAPSHOT
;
mInfo
(
"vgId:1, start to open sync,
selfIndex:%d replica:%d"
,
pMgmt
->
selfIndex
,
pMgmt
->
numOfReplicas
);
mInfo
(
"vgId:1, start to open sync,
replica:%d selfIndex:%d"
,
pMgmt
->
numOfReplicas
,
pMgmt
->
selfIndex
);
SSyncCfg
*
pCfg
=
&
syncInfo
.
syncCfg
;
pCfg
->
replicaNum
=
pMgmt
->
numOfReplicas
;
pCfg
->
myIndex
=
pMgmt
->
selfIndex
;
...
...
source/dnode/mnode/impl/src/mndVgroup.c
浏览文件 @
ec786b9d
...
...
@@ -1600,6 +1600,7 @@ int32_t mndBuildAlterVgroupAction(SMnode *pMnode, STrans *pTrans, SDbObj *pOldDb
if
(
mndRemoveVnodeFromVgroup
(
pMnode
,
&
newVgroup
,
pArray
,
&
del1
)
!=
0
)
return
-
1
;
if
(
mndRemoveVnodeFromVgroup
(
pMnode
,
&
newVgroup
,
pArray
,
&
del2
)
!=
0
)
return
-
1
;
if
(
mndAddDropVnodeAction
(
pMnode
,
pTrans
,
pNewDb
,
&
newVgroup
,
&
del1
,
true
)
!=
0
)
return
-
1
;
if
(
mndAddAlterVnodeConfirmAction
(
pMnode
,
pTrans
,
pNewDb
,
&
newVgroup
)
!=
0
)
return
-
1
;
if
(
mndAddDropVnodeAction
(
pMnode
,
pTrans
,
pNewDb
,
&
newVgroup
,
&
del2
,
true
)
!=
0
)
return
-
1
;
if
(
mndAddAlterVnodeReplicaAction
(
pMnode
,
pTrans
,
pNewDb
,
&
newVgroup
,
newVgroup
.
vnodeGid
[
0
].
dnodeId
)
!=
0
)
return
-
1
;
...
...
source/dnode/vnode/src/vnd/vnodeCommit.c
浏览文件 @
ec786b9d
...
...
@@ -107,7 +107,7 @@ int vnodeSaveInfo(const char *dir, const SVnodeInfo *pInfo) {
// free info binary
taosMemoryFree
(
data
);
vInfo
(
"vgId:%d, vnode info is saved, fname:%s
"
,
pInfo
->
config
.
vgId
,
fname
);
vInfo
(
"vgId:%d, vnode info is saved, fname:%s
replica:%d"
,
pInfo
->
config
.
vgId
,
fname
,
pInfo
->
config
.
syncCfg
.
replicaNum
);
return
0
;
...
...
source/dnode/vnode/src/vnd/vnodeOpen.c
浏览文件 @
ec786b9d
...
...
@@ -87,12 +87,19 @@ int32_t vnodeAlter(const char *path, SAlterVnodeReplicaReq *pReq, STfs *pTfs) {
vInfo
(
"vgId:%d, save config, replica:%d ep:%s:%u"
,
pReq
->
vgId
,
i
,
pNode
->
nodeFqdn
,
pNode
->
nodePort
);
}
info
.
config
.
syncCfg
=
*
pCfg
;
ret
=
vnodeSaveInfo
(
dir
,
&
info
);
if
(
ret
<
0
)
{
vError
(
"vgId:%d, failed to save vnode config since %s"
,
pReq
->
vgId
,
tstrerror
(
terrno
));
return
-
1
;
}
ret
=
vnodeCommitInfo
(
dir
,
&
info
);
if
(
ret
<
0
)
{
vError
(
"vgId:%d, failed to commit vnode config since %s"
,
pReq
->
vgId
,
tstrerror
(
terrno
));
return
-
1
;
}
vInfo
(
"vgId:%d, vnode config is saved"
,
info
.
config
.
vgId
);
return
0
;
}
...
...
source/dnode/vnode/src/vnd/vnodeSync.c
浏览文件 @
ec786b9d
...
...
@@ -563,9 +563,7 @@ static int32_t vnodeSnapshotDoWrite(struct SSyncFSM *pFsm, void *pWriter, void *
#endif
}
static
void
vnodeLeaderTransfer
(
struct
SSyncFSM
*
pFsm
,
const
SRpcMsg
*
pMsg
,
SFsmCbMeta
cbMeta
)
{
SVnode
*
pVnode
=
pFsm
->
data
;
}
static
void
vnodeLeaderTransfer
(
struct
SSyncFSM
*
pFsm
,
const
SRpcMsg
*
pMsg
,
SFsmCbMeta
cbMeta
)
{}
static
void
vnodeRestoreFinish
(
struct
SSyncFSM
*
pFsm
)
{
SVnode
*
pVnode
=
pFsm
->
data
;
...
...
@@ -605,12 +603,14 @@ static void vnodeBecomeLeader(struct SSyncFSM *pFsm) {
SVnode
*
pVnode
=
pFsm
->
data
;
vDebug
(
"vgId:%d, become leader"
,
pVnode
->
config
.
vgId
);
// taosThreadMutexLock(&pVnode->lock);
// if (pVnode->blocked) {
// pVnode->blocked = false;
// tsem_post(&pVnode->syncSem);
// }
// taosThreadMutexUnlock(&pVnode->lock);
#if 0
taosThreadMutexLock(&pVnode->lock);
if (pVnode->blocked) {
pVnode->blocked = false;
tsem_post(&pVnode->syncSem);
}
taosThreadMutexUnlock(&pVnode->lock);
#endif
}
static
SSyncFSM
*
vnodeSyncMakeFsm
(
SVnode
*
pVnode
)
{
...
...
@@ -638,10 +638,8 @@ static SSyncFSM *vnodeSyncMakeFsm(SVnode *pVnode) {
int32_t
vnodeSyncOpen
(
SVnode
*
pVnode
,
char
*
path
)
{
SSyncInfo
syncInfo
=
{
.
snapshotStrategy
=
SYNC_STRATEGY_WAL_FIRST
,
//.snapshotStrategy = SYNC_STRATEGY_NO_SNAPSHOT,
.
batchSize
=
1
,
.
vgId
=
pVnode
->
config
.
vgId
,
.
isStandBy
=
pVnode
->
config
.
standby
,
.
syncCfg
=
pVnode
->
config
.
syncCfg
,
.
pWal
=
pVnode
->
pWal
,
.
msgcb
=
NULL
,
...
...
@@ -653,6 +651,13 @@ int32_t vnodeSyncOpen(SVnode *pVnode, char *path) {
snprintf
(
syncInfo
.
path
,
sizeof
(
syncInfo
.
path
),
"%s%ssync"
,
path
,
TD_DIRSEP
);
syncInfo
.
pFsm
=
vnodeSyncMakeFsm
(
pVnode
);
SSyncCfg
*
pCfg
=
&
syncInfo
.
syncCfg
;
vInfo
(
"vgId:%d, start to open sync, replica:%d selfIndex:%d"
,
pVnode
->
config
.
vgId
,
pCfg
->
replicaNum
,
pCfg
->
myIndex
);
for
(
int32_t
i
=
0
;
i
<
pCfg
->
replicaNum
;
++
i
)
{
SNodeInfo
*
pNode
=
&
pCfg
->
nodeInfo
[
i
];
vInfo
(
"vgId:%d, index:%d ep:%s:%u"
,
pVnode
->
config
.
vgId
,
i
,
pNode
->
nodeFqdn
,
pNode
->
nodePort
);
}
pVnode
->
sync
=
syncOpen
(
&
syncInfo
);
if
(
pVnode
->
sync
<=
0
)
{
vError
(
"vgId:%d, failed to open sync since %s"
,
pVnode
->
config
.
vgId
,
terrstr
());
...
...
@@ -666,11 +671,15 @@ int32_t vnodeSyncOpen(SVnode *pVnode, char *path) {
}
void
vnodeSyncStart
(
SVnode
*
pVnode
)
{
vDebug
(
"vgId:%d, start sync"
,
pVnode
->
config
.
vgId
);
syncSetMsgCb
(
pVnode
->
sync
,
&
pVnode
->
msgCb
);
syncStart
(
pVnode
->
sync
);
}
void
vnodeSyncClose
(
SVnode
*
pVnode
)
{
syncStop
(
pVnode
->
sync
);
}
void
vnodeSyncClose
(
SVnode
*
pVnode
)
{
vDebug
(
"vgId:%d, close sync"
,
pVnode
->
config
.
vgId
);
syncStop
(
pVnode
->
sync
);
}
bool
vnodeIsRoleLeader
(
SVnode
*
pVnode
)
{
return
syncGetMyRole
(
pVnode
->
sync
)
==
TAOS_SYNC_STATE_LEADER
;
}
...
...
source/libs/sync/src/syncMain.c
浏览文件 @
ec786b9d
...
...
@@ -90,7 +90,7 @@ void syncCleanUp() {
int64_t
syncOpen
(
SSyncInfo
*
pSyncInfo
)
{
SSyncNode
*
pSyncNode
=
syncNodeOpen
(
pSyncInfo
);
if
(
pSyncNode
==
NULL
)
{
sError
(
"
failed to open sync node. vgId:%d
"
,
pSyncInfo
->
vgId
);
sError
(
"
vgId:%d, failed to open sync node
"
,
pSyncInfo
->
vgId
);
return
-
1
;
}
...
...
@@ -106,7 +106,7 @@ int64_t syncOpen(SSyncInfo* pSyncInfo) {
}
void
syncStart
(
int64_t
rid
)
{
SSyncNode
*
pSyncNode
=
(
SSyncNode
*
)
taosAcquireRef
(
tsNodeRefId
,
rid
);
SSyncNode
*
pSyncNode
=
taosAcquireRef
(
tsNodeRefId
,
rid
);
if
(
pSyncNode
==
NULL
)
{
return
;
}
...
...
@@ -121,7 +121,7 @@ void syncStart(int64_t rid) {
}
void
syncStartNormal
(
int64_t
rid
)
{
SSyncNode
*
pSyncNode
=
(
SSyncNode
*
)
taosAcquireRef
(
tsNodeRefId
,
rid
);
SSyncNode
*
pSyncNode
=
taosAcquireRef
(
tsNodeRefId
,
rid
);
if
(
pSyncNode
==
NULL
)
{
return
;
}
...
...
@@ -131,7 +131,7 @@ void syncStartNormal(int64_t rid) {
}
void
syncStartStandBy
(
int64_t
rid
)
{
SSyncNode
*
pSyncNode
=
(
SSyncNode
*
)
taosAcquireRef
(
tsNodeRefId
,
rid
);
SSyncNode
*
pSyncNode
=
taosAcquireRef
(
tsNodeRefId
,
rid
);
if
(
pSyncNode
==
NULL
)
{
return
;
}
...
...
@@ -141,7 +141,7 @@ void syncStartStandBy(int64_t rid) {
}
void
syncStop
(
int64_t
rid
)
{
SSyncNode
*
pSyncNode
=
(
SSyncNode
*
)
taosAcquireRef
(
tsNodeRefId
,
rid
);
SSyncNode
*
pSyncNode
=
taosAcquireRef
(
tsNodeRefId
,
rid
);
if
(
pSyncNode
==
NULL
)
return
;
int32_t
vgId
=
pSyncNode
->
vgId
;
taosReleaseRef
(
tsNodeRefId
,
pSyncNode
->
rid
);
...
...
@@ -151,7 +151,7 @@ void syncStop(int64_t rid) {
}
int32_t
syncSetStandby
(
int64_t
rid
)
{
SSyncNode
*
pSyncNode
=
(
SSyncNode
*
)
taosAcquireRef
(
tsNodeRefId
,
rid
);
SSyncNode
*
pSyncNode
=
taosAcquireRef
(
tsNodeRefId
,
rid
);
if
(
pSyncNode
==
NULL
)
{
terrno
=
TSDB_CODE_SYN_INTERNAL_ERROR
;
sError
(
"failed to set standby since accquire ref error, rid:%"
PRId64
,
rid
);
...
...
@@ -1089,17 +1089,13 @@ int32_t syncHbTimerStop(SSyncNode* pSyncNode, SSyncTimer* pSyncTimer) {
return
ret
;
}
// open/close --------------
SSyncNode
*
syncNodeOpen
(
SSyncInfo
*
pOldSyncInfo
)
{
SSyncInfo
*
pSyncInfo
=
(
SSyncInfo
*
)
pOldSyncInfo
;
SSyncNode
*
pSyncNode
=
(
SSyncNode
*
)
taosMemoryCalloc
(
1
,
sizeof
(
SSyncNode
));
SSyncNode
*
syncNodeOpen
(
SSyncInfo
*
pSyncInfo
)
{
SSyncNode
*
pSyncNode
=
taosMemoryCalloc
(
1
,
sizeof
(
SSyncNode
));
if
(
pSyncNode
==
NULL
)
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
goto
_error
;
}
int32_t
ret
=
0
;
if
(
!
taosDirExist
((
char
*
)(
pSyncInfo
->
path
)))
{
if
(
taosMkDir
(
pSyncInfo
->
path
)
!=
0
)
{
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
...
...
@@ -1111,32 +1107,44 @@ SSyncNode* syncNodeOpen(SSyncInfo* pOldSyncInfo) {
snprintf
(
pSyncNode
->
configPath
,
sizeof
(
pSyncNode
->
configPath
),
"%s%sraft_config.json"
,
pSyncInfo
->
path
,
TD_DIRSEP
);
if
(
!
taosCheckExistFile
(
pSyncNode
->
configPath
))
{
// create a new raft config file
SRaftCfgMeta
meta
;
SRaftCfgMeta
meta
=
{
0
}
;
meta
.
isStandBy
=
pSyncInfo
->
isStandBy
;
meta
.
snapshotStrategy
=
pSyncInfo
->
snapshotStrategy
;
meta
.
lastConfigIndex
=
SYNC_INDEX_INVALID
;
meta
.
batchSize
=
pSyncInfo
->
batchSize
;
ret
=
raftCfgCreateFile
((
SSyncCfg
*
)
&
(
pSyncInfo
->
syncCfg
),
meta
,
pSyncNode
->
configPath
);
if
(
ret
!=
0
)
{
sError
(
"failed to create raft cfg file. configPath: %s"
,
pSyncNode
->
configPath
);
if
(
raftCfgCreateFile
(
&
pSyncInfo
->
syncCfg
,
meta
,
pSyncNode
->
configPath
)
!=
0
)
{
sError
(
"vgId:%d, failed to create raft cfg file at %s"
,
pSyncNode
->
vgId
,
pSyncNode
->
configPath
);
goto
_error
;
}
if
(
pSyncInfo
->
syncCfg
.
replicaNum
==
0
)
{
sInfo
(
"vgId:%d, sync config not input"
,
pSyncNode
->
vgId
);
pSyncInfo
->
syncCfg
=
pSyncNode
->
pRaftCfg
->
cfg
;
}
}
else
{
// update syncCfg by raft_config.json
pSyncNode
->
pRaftCfg
=
raftCfgOpen
(
pSyncNode
->
configPath
);
if
(
pSyncNode
->
pRaftCfg
==
NULL
)
{
sError
(
"
failed to open raft cfg file. path:%s"
,
pSyncNode
->
configPath
);
sError
(
"
vgId:%d, failed to open raft cfg file at %s"
,
pSyncNode
->
vgId
,
pSyncNode
->
configPath
);
goto
_error
;
}
pSyncInfo
->
syncCfg
=
pSyncNode
->
pRaftCfg
->
cfg
;
if
(
pSyncInfo
->
syncCfg
.
replicaNum
>
0
&&
pSyncInfo
->
syncCfg
.
replicaNum
!=
pSyncNode
->
pRaftCfg
->
cfg
.
replicaNum
)
{
sInfo
(
"vgId:%d, use sync config from input options"
,
pSyncNode
->
vgId
);
}
else
{
sInfo
(
"vgId:%d, use sync config from raft cfg file"
,
pSyncNode
->
vgId
);
pSyncInfo
->
syncCfg
=
pSyncNode
->
pRaftCfg
->
cfg
;
}
raftCfgClose
(
pSyncNode
->
pRaftCfg
);
pSyncNode
->
pRaftCfg
=
NULL
;
}
SSyncCfg
*
pCfg
=
&
pSyncInfo
->
syncCfg
;
sDebug
(
"vgId:%d, replica:%d selfIndex:%d"
,
pSyncNode
->
vgId
,
pCfg
->
replicaNum
,
pCfg
->
myIndex
);
for
(
int32_t
i
=
0
;
i
<
pCfg
->
replicaNum
;
++
i
)
{
SNodeInfo
*
pNode
=
&
pCfg
->
nodeInfo
[
i
];
sDebug
(
"vgId:%d, index:%d ep:%s:%u"
,
pSyncNode
->
vgId
,
i
,
pNode
->
nodeFqdn
,
pNode
->
nodePort
);
}
// init by SSyncInfo
pSyncNode
->
vgId
=
pSyncInfo
->
vgId
;
memcpy
(
pSyncNode
->
path
,
pSyncInfo
->
path
,
sizeof
(
pSyncNode
->
path
));
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录