提交 f99b20aa 编写于 作者: S Shengliang Guan

refactor: add standby option for mnode

上级 6cf9f50c
...@@ -29,6 +29,7 @@ extern "C" { ...@@ -29,6 +29,7 @@ extern "C" {
typedef struct SMnode SMnode; typedef struct SMnode SMnode;
typedef struct { typedef struct {
bool isStandBy;
bool deploy; bool deploy;
int8_t replica; int8_t replica;
int8_t selfIndex; int8_t selfIndex;
......
...@@ -55,29 +55,31 @@ static void mmBuildOptionForDeploy(SMnodeMgmt *pMgmt, const SMgmtInputOpt *pInpu ...@@ -55,29 +55,31 @@ static void mmBuildOptionForDeploy(SMnodeMgmt *pMgmt, const SMgmtInputOpt *pInpu
static void mmBuildOptionForOpen(SMnodeMgmt *pMgmt, SMnodeOpt *pOption) { static void mmBuildOptionForOpen(SMnodeMgmt *pMgmt, SMnodeOpt *pOption) {
pOption->msgCb = pMgmt->msgCb; pOption->msgCb = pMgmt->msgCb;
#if 1
pOption->replica = 1; if (pMgmt->replica > 1) {
pOption->selfIndex = 0; pOption->replica = 1;
SReplica *pReplica = &pOption->replicas[0]; pOption->selfIndex = 0;
for (int32_t i = 0; i < pMgmt->replica; ++i) { SReplica *pReplica = &pOption->replicas[0];
if (pMgmt->replicas[i].id == pMgmt->pData->dnodeId) { for (int32_t i = 0; i < pMgmt->replica; ++i) {
pReplica->id = pMgmt->replicas[i].id; if (pMgmt->replicas[i].id == pMgmt->pData->dnodeId) {
pReplica->port = pMgmt->replicas[i].port; pReplica->id = pMgmt->replicas[i].id;
memcpy(pReplica->fqdn, pMgmt->replicas[i].fqdn, TSDB_FQDN_LEN); pReplica->port = pMgmt->replicas[i].port;
memcpy(pReplica->fqdn, pMgmt->replicas[i].fqdn, TSDB_FQDN_LEN);
}
} }
} pMgmt->selfIndex = pOption->selfIndex;
pMgmt->selfIndex = pOption->selfIndex; pOption->isStandBy = 1;
#else } else {
pOption->replica = pMgmt->replica; pOption->replica = pMgmt->replica;
pOption->selfIndex = -1; pOption->selfIndex = -1;
memcpy(&pOption->replicas, pMgmt->replicas, sizeof(SReplica) * TSDB_MAX_REPLICA); memcpy(&pOption->replicas, pMgmt->replicas, sizeof(SReplica) * TSDB_MAX_REPLICA);
for (int32_t i = 0; i < pOption->replica; ++i) { for (int32_t i = 0; i < pOption->replica; ++i) {
if (pOption->replicas[i].id == pMgmt->pData->dnodeId) { if (pOption->replicas[i].id == pMgmt->pData->dnodeId) {
pOption->selfIndex = i; pOption->selfIndex = i;
}
} }
pMgmt->selfIndex = pOption->selfIndex;
} }
pMgmt->selfIndex = pOption->selfIndex;
#endif
pOption->deploy = false; pOption->deploy = false;
} }
......
...@@ -121,7 +121,8 @@ int32_t mndInitSync(SMnode *pMnode) { ...@@ -121,7 +121,8 @@ int32_t mndInitSync(SMnode *pMnode) {
SSyncCfg *pCfg = &syncInfo.syncCfg; SSyncCfg *pCfg = &syncInfo.syncCfg;
pCfg->replicaNum = pMnode->replica; pCfg->replicaNum = pMnode->replica;
pCfg->myIndex = pMnode->selfIndex; pCfg->myIndex = pMnode->selfIndex;
mInfo("start to open mnode sync, replica:%d myIndex:%d", pCfg->replicaNum, pCfg->myIndex); mInfo("start to open mnode sync, replica:%d myIndex:%d standBy:%d", pCfg->replicaNum, pCfg->myIndex,
pMgmt->isStandBy);
for (int32_t i = 0; i < pMnode->replica; ++i) { for (int32_t i = 0; i < pMnode->replica; ++i) {
SNodeInfo *pNode = &pCfg->nodeInfo[i]; SNodeInfo *pNode = &pCfg->nodeInfo[i];
tstrncpy(pNode->nodeFqdn, pMnode->replicas[i].fqdn, sizeof(pNode->nodeFqdn)); tstrncpy(pNode->nodeFqdn, pMnode->replicas[i].fqdn, sizeof(pNode->nodeFqdn));
...@@ -201,7 +202,7 @@ bool mndIsMaster(SMnode *pMnode) { ...@@ -201,7 +202,7 @@ bool mndIsMaster(SMnode *pMnode) {
int32_t mndAlter(SMnode *pMnode, const SMnodeOpt *pOption) { int32_t mndAlter(SMnode *pMnode, const SMnodeOpt *pOption) {
SSyncCfg cfg = {.replicaNum = pOption->replica, .myIndex = pOption->selfIndex}; SSyncCfg cfg = {.replicaNum = pOption->replica, .myIndex = pOption->selfIndex};
mInfo("start to alter mnode sync, replica:%d myIndex:%d", cfg.replicaNum, cfg.myIndex); mInfo("start to alter mnode sync, replica:%d myIndex:%d standBy:%d", cfg.replicaNum, cfg.myIndex, pOption->isStandBy);
for (int32_t i = 0; i < pOption->replica; ++i) { for (int32_t i = 0; i < pOption->replica; ++i) {
SNodeInfo *pNode = &cfg.nodeInfo[i]; SNodeInfo *pNode = &cfg.nodeInfo[i];
tstrncpy(pNode->nodeFqdn, pOption->replicas[i].fqdn, sizeof(pNode->nodeFqdn)); tstrncpy(pNode->nodeFqdn, pOption->replicas[i].fqdn, sizeof(pNode->nodeFqdn));
...@@ -210,5 +211,6 @@ int32_t mndAlter(SMnode *pMnode, const SMnodeOpt *pOption) { ...@@ -210,5 +211,6 @@ int32_t mndAlter(SMnode *pMnode, const SMnodeOpt *pOption) {
} }
SSyncMgmt *pMgmt = &pMnode->syncMgmt; SSyncMgmt *pMgmt = &pMnode->syncMgmt;
pMgmt->isStandBy = pOption->isStandBy;
return syncReconfig(pMgmt->sync, &cfg); return syncReconfig(pMgmt->sync, &cfg);
} }
\ No newline at end of file
...@@ -263,6 +263,7 @@ static void mndSetOptions(SMnode *pMnode, const SMnodeOpt *pOption) { ...@@ -263,6 +263,7 @@ static void mndSetOptions(SMnode *pMnode, const SMnodeOpt *pOption) {
memcpy(&pMnode->replicas, pOption->replicas, sizeof(SReplica) * TSDB_MAX_REPLICA); memcpy(&pMnode->replicas, pOption->replicas, sizeof(SReplica) * TSDB_MAX_REPLICA);
pMnode->msgCb = pOption->msgCb; pMnode->msgCb = pOption->msgCb;
pMnode->selfId = pOption->replicas[pOption->selfIndex].id; pMnode->selfId = pOption->replicas[pOption->selfIndex].id;
pMnode->syncMgmt.isStandBy = pOption->isStandBy;
} }
SMnode *mndOpen(const char *path, const SMnodeOpt *pOption) { SMnode *mndOpen(const char *path, const SMnodeOpt *pOption) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册