diff --git a/include/dnode/mnode/mnode.h b/include/dnode/mnode/mnode.h index 5b88a9d6aff34bf3a151650f42c48e4ef325e81d..08ab63e55abb4498e058c8e014387c1046a76621 100644 --- a/include/dnode/mnode/mnode.h +++ b/include/dnode/mnode/mnode.h @@ -29,8 +29,7 @@ extern "C" { typedef struct SMnode SMnode; typedef struct { - int32_t dnodeId; - int64_t clusterId; + bool deploy; int8_t replica; int8_t selfIndex; SReplica replicas[TSDB_MAX_REPLICA]; diff --git a/source/dnode/mgmt/mm/src/mmFile.c b/source/dnode/mgmt/mm/src/mmFile.c index e5cc0ce0871bfa398bd7c46f4c9260bb16e8f0de..76aba771cbd08271a8995f6d4a79ebb7b4ba235d 100644 --- a/source/dnode/mgmt/mm/src/mmFile.c +++ b/source/dnode/mgmt/mm/src/mmFile.c @@ -111,7 +111,7 @@ int32_t mmWriteFile(SMnodeMgmt *pMgmt, bool deployed) { TdFilePtr pFile = taosOpenFile(file, TD_FILE_CTEATE | TD_FILE_WRITE | TD_FILE_TRUNC); if (pFile == NULL) { - terrno = TAOS_SYSTEM_ERROR(errno);; + terrno = TAOS_SYSTEM_ERROR(errno); dError("failed to write %s since %s", file, terrstr()); return -1; } @@ -145,7 +145,7 @@ int32_t mmWriteFile(SMnodeMgmt *pMgmt, bool deployed) { snprintf(realfile, sizeof(realfile), "%s%smnode.json", pMgmt->path, TD_DIRSEP); if (taosRenameFile(file, realfile) != 0) { - terrno = TAOS_SYSTEM_ERROR(errno);; + terrno = TAOS_SYSTEM_ERROR(errno); dError("failed to rename %s since %s", file, terrstr()); return -1; } diff --git a/source/dnode/mgmt/mm/src/mmInt.c b/source/dnode/mgmt/mm/src/mmInt.c index 3d15c9b9aeeb7768e20139463498885f0372ad3a..f4e00b5921c7c65dfd92037bb0a2a763c15e46f6 100644 --- a/source/dnode/mgmt/mm/src/mmInt.c +++ b/source/dnode/mgmt/mm/src/mmInt.c @@ -39,10 +39,6 @@ static int32_t mmRequire(SMgmtWrapper *pWrapper, bool *required) { } static void mmInitOption(SMnodeMgmt *pMgmt, SMnodeOpt *pOption) { - SDnode *pDnode = pMgmt->pDnode; - pOption->dnodeId = pDnode->dnodeId; - pOption->clusterId = pDnode->clusterId; - SMsgCb msgCb = {0}; msgCb.pWrapper = pMgmt->pWrapper; msgCb.queueFps[QUERY_QUEUE] = mmPutMsgToQueryQueue; @@ -66,6 +62,7 @@ static void mmBuildOptionForDeploy(SMnodeMgmt *pMgmt, SMnodeOpt *pOption) { pReplica->id = 1; pReplica->port = pDnode->serverPort; tstrncpy(pReplica->fqdn, pDnode->localFqdn, TSDB_FQDN_LEN); + pOption->deploy = true; pMgmt->selfIndex = pOption->selfIndex; pMgmt->replica = pOption->replica; @@ -77,6 +74,7 @@ static void mmBuildOptionForOpen(SMnodeMgmt *pMgmt, SMnodeOpt *pOption) { pOption->selfIndex = pMgmt->selfIndex; pOption->replica = pMgmt->replica; memcpy(&pOption->replicas, pMgmt->replicas, sizeof(SReplica) * TSDB_MAX_REPLICA); + pOption->deploy = false; } static int32_t mmBuildOptionFromReq(SMnodeMgmt *pMgmt, SMnodeOpt *pOption, SDCreateMnodeReq *pCreate) { @@ -89,7 +87,7 @@ static int32_t mmBuildOptionFromReq(SMnodeMgmt *pMgmt, SMnodeOpt *pOption, SDCre pReplica->id = pCreate->replicas[i].id; pReplica->port = pCreate->replicas[i].port; memcpy(pReplica->fqdn, pCreate->replicas[i].fqdn, TSDB_FQDN_LEN); - if (pReplica->id == pOption->dnodeId) { + if (pReplica->id == pMgmt->pDnode->dnodeId) { pOption->selfIndex = i; } } @@ -98,6 +96,7 @@ static int32_t mmBuildOptionFromReq(SMnodeMgmt *pMgmt, SMnodeOpt *pOption, SDCre dError("failed to build mnode options since %s", terrstr()); return -1; } + pOption->deploy = true; pMgmt->selfIndex = pOption->selfIndex; pMgmt->replica = pOption->replica; @@ -225,9 +224,7 @@ int32_t mmOpenFromMsg(SMgmtWrapper *pWrapper, SDCreateMnodeReq *pReq) { return code; } -static int32_t mmOpen(SMgmtWrapper *pWrapper) { - return mmOpenFromMsg(pWrapper, NULL); -} +static int32_t mmOpen(SMgmtWrapper *pWrapper) { return mmOpenFromMsg(pWrapper, NULL); } static int32_t mmStart(SMgmtWrapper *pWrapper) { dDebug("mnode-mgmt start to run"); @@ -258,7 +255,7 @@ int32_t mmGetUserAuth(SMgmtWrapper *pWrapper, char *user, char *spi, char *encry } int32_t mmMonitorMnodeInfo(SMgmtWrapper *pWrapper, SMonClusterInfo *pClusterInfo, SMonVgroupInfo *pVgroupInfo, - SMonGrantInfo *pGrantInfo) { + SMonGrantInfo *pGrantInfo) { SMnodeMgmt *pMgmt = pWrapper->pMgmt; return mndGetMonitorInfo(pMgmt->pMnode, pClusterInfo, pVgroupInfo, pGrantInfo); } diff --git a/source/dnode/mnode/impl/inc/mndCluster.h b/source/dnode/mnode/impl/inc/mndCluster.h index 0206695b8814ee83832aeddeed86b4738649b3b7..5b7bac4486492d4c852a49c4c706526092ff83ec 100644 --- a/source/dnode/mnode/impl/inc/mndCluster.h +++ b/source/dnode/mnode/impl/inc/mndCluster.h @@ -25,6 +25,7 @@ extern "C" { int32_t mndInitCluster(SMnode *pMnode); void mndCleanupCluster(SMnode *pMnode); int32_t mndGetClusterName(SMnode *pMnode, char *clusterName, int32_t len); +int64_t mndGetClusterId(SMnode *pMnode); #ifdef __cplusplus } diff --git a/source/dnode/mnode/impl/inc/mndInt.h b/source/dnode/mnode/impl/inc/mndInt.h index f89e9d8fe0536f4848bd5798ce3b4c4fe806e1f6..1cb0c78aa536a9982940e4d5424a1dc9bc86072b 100644 --- a/source/dnode/mnode/impl/inc/mndInt.h +++ b/source/dnode/mnode/impl/inc/mndInt.h @@ -100,7 +100,6 @@ typedef struct { } SGrantInfo; typedef struct SMnode { - int32_t dnodeId; int64_t clusterId; int8_t replica; int8_t selfIndex; diff --git a/source/dnode/mnode/impl/src/mndCluster.c b/source/dnode/mnode/impl/src/mndCluster.c index dde7e1fe8fd946c0f9632dcb7273b89cbe246757..94e1efde61b7f9d5f2dab3969b8a87fb12d27a3d 100644 --- a/source/dnode/mnode/impl/src/mndCluster.c +++ b/source/dnode/mnode/impl/src/mndCluster.c @@ -17,7 +17,7 @@ #include "mndCluster.h" #include "mndShow.h" -#define TSDB_CLUSTER_VER_NUMBE 1 +#define TSDB_CLUSTER_VER_NUMBE 1 #define TSDB_CLUSTER_RESERVE_SIZE 64 static SSdbRaw *mndClusterActionEncode(SClusterObj *pCluster); @@ -61,6 +61,23 @@ int32_t mndGetClusterName(SMnode *pMnode, char *clusterName, int32_t len) { return 0; } +int64_t mndGetClusterId(SMnode *pMnode) { + SSdb *pSdb = pMnode->pSdb; + void *pIter = NULL; + int64_t clusterId = -1; + + while (1) { + SClusterObj *pCluster = NULL; + pIter = sdbFetch(pSdb, SDB_CLUSTER, pIter, (void **)&pCluster); + if (pIter == NULL) break; + + clusterId = pCluster->id; + sdbRelease(pSdb, pCluster); + } + + return clusterId; +} + static SSdbRaw *mndClusterActionEncode(SClusterObj *pCluster) { terrno = TSDB_CODE_OUT_OF_MEMORY; diff --git a/source/dnode/mnode/impl/src/mndQnode.c b/source/dnode/mnode/impl/src/mndQnode.c index 4b19a26bc4f2dc7a6c039b551b17835d347951f0..85718e203717a684117bb2a21645652a785a9a3a 100644 --- a/source/dnode/mnode/impl/src/mndQnode.c +++ b/source/dnode/mnode/impl/src/mndQnode.c @@ -423,7 +423,7 @@ static int32_t mndProcessDropQnodeReq(SNodeMsg *pReq) { DROP_QNODE_OVER: if (code != 0 && code != TSDB_CODE_MND_ACTION_IN_PROGRESS) { - mError("qnode:%d, failed to drop since %s", pMnode->dnodeId, terrstr()); + mError("qnode:%d, failed to drop since %s", dropReq.dnodeId, terrstr()); } mndReleaseQnode(pMnode, pObj); diff --git a/source/dnode/mnode/impl/src/mndSnode.c b/source/dnode/mnode/impl/src/mndSnode.c index 5e0d9fae9a4bccbd382355ad2897b99c13ea8929..4f24c6f7eb957992899f848143f87dbdd827e8ef 100644 --- a/source/dnode/mnode/impl/src/mndSnode.c +++ b/source/dnode/mnode/impl/src/mndSnode.c @@ -433,7 +433,7 @@ static int32_t mndProcessDropSnodeReq(SNodeMsg *pReq) { DROP_SNODE_OVER: if (code != 0 && code != TSDB_CODE_MND_ACTION_IN_PROGRESS) { - mError("snode:%d, failed to drop since %s", pMnode->dnodeId, terrstr()); + mError("snode:%d, failed to drop since %s", dropReq.dnodeId, terrstr()); } mndReleaseSnode(pMnode, pObj); diff --git a/source/dnode/mnode/impl/src/mnode.c b/source/dnode/mnode/impl/src/mnode.c index 67b7d6dd45f754a6378c3b25941b5118ce62f61c..5c3dd778e15cef24ebf734d883f5e6def9d805c5 100644 --- a/source/dnode/mnode/impl/src/mnode.c +++ b/source/dnode/mnode/impl/src/mnode.c @@ -187,7 +187,7 @@ static int32_t mndAllocStep(SMnode *pMnode, char *name, MndInitFp initFp, MndCle return 0; } -static int32_t mndInitSteps(SMnode *pMnode) { +static int32_t mndInitSteps(SMnode *pMnode, bool deploy) { if (mndAllocStep(pMnode, "mnode-sdb", mndInitSdb, mndCleanupSdb) != 0) return -1; if (mndAllocStep(pMnode, "mnode-trans", mndInitTrans, mndCleanupTrans) != 0) return -1; if (mndAllocStep(pMnode, "mnode-cluster", mndInitCluster, mndCleanupCluster) != 0) return -1; @@ -210,7 +210,7 @@ static int32_t mndInitSteps(SMnode *pMnode) { if (mndAllocStep(pMnode, "mnode-infos", mndInitInfos, mndCleanupInfos) != 0) return -1; if (mndAllocStep(pMnode, "mnode-db", mndInitDb, mndCleanupDb) != 0) return -1; if (mndAllocStep(pMnode, "mnode-func", mndInitFunc, mndCleanupFunc) != 0) return -1; - if (pMnode->clusterId <= 0) { + if (deploy) { if (mndAllocStep(pMnode, "mnode-sdb-deploy", mndDeploySdb, NULL) != 0) return -1; } else { if (mndAllocStep(pMnode, "mnode-sdb-read", mndReadSdb, NULL) != 0) return -1; @@ -263,23 +263,15 @@ static int32_t mndExecSteps(SMnode *pMnode) { } } + pMnode->clusterId = mndGetClusterId(pMnode); return 0; } -static int32_t mndSetOptions(SMnode *pMnode, const SMnodeOpt *pOption) { - pMnode->dnodeId = pOption->dnodeId; - pMnode->clusterId = pOption->clusterId; +static void mndSetOptions(SMnode *pMnode, const SMnodeOpt *pOption) { pMnode->replica = pOption->replica; pMnode->selfIndex = pOption->selfIndex; memcpy(&pMnode->replicas, pOption->replicas, sizeof(SReplica) * TSDB_MAX_REPLICA); pMnode->msgCb = pOption->msgCb; - - if (pMnode->dnodeId < 0 || pMnode->clusterId < 0) { - terrno = TSDB_CODE_MND_INVALID_OPTIONS; - return -1; - } - - return 0; } SMnode *mndOpen(const char *path, const SMnodeOpt *pOption) { @@ -294,6 +286,7 @@ SMnode *mndOpen(const char *path, const SMnodeOpt *pOption) { char timestr[24] = "1970-01-01 00:00:00.00"; (void)taosParseTime(timestr, &pMnode->checkTime, (int32_t)strlen(timestr), TSDB_TIME_PRECISION_MILLI, 0); + mndSetOptions(pMnode, pOption); pMnode->pSteps = taosArrayInit(24, sizeof(SMnodeStep)); if (pMnode->pSteps == NULL) { @@ -312,16 +305,7 @@ SMnode *mndOpen(const char *path, const SMnodeOpt *pOption) { return NULL; } - code = mndSetOptions(pMnode, pOption); - if (code != 0) { - code = terrno; - mError("failed to open mnode since %s", terrstr()); - mndClose(pMnode); - terrno = code; - return NULL; - } - - code = mndInitSteps(pMnode); + code = mndInitSteps(pMnode, pOption->deploy); if (code != 0) { code = terrno; mError("failed to open mnode since %s", terrstr());