From c06fb4d927c79c63c5e5af0ab78e3547913eeee5 Mon Sep 17 00:00:00 2001 From: slguan Date: Thu, 2 Apr 2020 17:50:02 +0800 Subject: [PATCH] [TD-17] add show mnodes command in cluster version --- cmake/define.inc | 13 +- src/mnode/inc/mgmtMnode.h | 3 - src/mnode/src/mgmtBalance.c | 3 +- src/mnode/src/mgmtDnode.c | 455 ++++++++++++++++++++++++++- src/mnode/src/mgmtMnode.c | 162 ++++------ src/mnode/src/mgmtVgroup.c | 9 + src/util/inc/tstatus.h | 15 + src/util/src/.tqueue.c.swp | Bin 20480 -> 0 bytes src/util/src/tstatus.c | 19 ++ tests/script/general/show/dnodes.sim | 16 + 10 files changed, 585 insertions(+), 110 deletions(-) delete mode 100644 src/util/src/.tqueue.c.swp create mode 100644 tests/script/general/show/dnodes.sim diff --git a/cmake/define.inc b/cmake/define.inc index ba61d3fe9d..e43e570979 100755 --- a/cmake/define.inc +++ b/cmake/define.inc @@ -3,10 +3,17 @@ PROJECT(TDengine) IF (TD_CLUSTER) ADD_DEFINITIONS(-D_CLUSTER) - ADD_DEFINITIONS(-DTSDB_REPLICA_MAX_NUM=1) +ENDIF () + +IF (TD_MPEER) + ADD_DEFINITIONS(-D_MPEER) +ENDIF () + +IF (TD_VPEER) + ADD_DEFINITIONS(-D_VPEER) + ADD_DEFINITIONS(-DTSDB_REPLICA_MAX_NUM=3) ELSE () - ADD_DEFINITIONS(-DLITE) - ADD_DEFINITIONS(-DTSDB_REPLICA_MAX_NUM=1) + ADD_DEFINITIONS(-DTSDB_REPLICA_MAX_NUM=1) ENDIF () IF (TD_ACCOUNT) diff --git a/src/mnode/inc/mgmtMnode.h b/src/mnode/inc/mgmtMnode.h index 8cfe3c7e23..f82806a645 100644 --- a/src/mnode/inc/mgmtMnode.h +++ b/src/mnode/inc/mgmtMnode.h @@ -30,9 +30,6 @@ bool mgmtCheckRedirect(void *handle); void mgmtGetMnodePrivateIpList(SRpcIpSet *ipSet); void mgmtGetMnodePublicIpList(SRpcIpSet *ipSet); -int32_t mgmtAddMnode(uint32_t privateIp, uint32_t publicIp); -int32_t mgmtRemoveMnode(uint32_t privateIp); - #ifdef __cplusplus } #endif diff --git a/src/mnode/src/mgmtBalance.c b/src/mnode/src/mgmtBalance.c index fc74075878..3b8a6abc86 100644 --- a/src/mnode/src/mgmtBalance.c +++ b/src/mnode/src/mgmtBalance.c @@ -49,6 +49,7 @@ int32_t mgmtAllocVnodes(SVgObj *pVgroup) { pVgroup->vnodeGid[0].dnodeId = pSelDnode->dnodeId; pVgroup->vnodeGid[0].privateIp = pSelDnode->privateIp; pVgroup->vnodeGid[0].publicIp = pSelDnode->publicIp; - mTrace("dnode:%d, alloc one vnode to vgroup", pSelDnode->dnodeId); + + mTrace("dnode:%d, alloc one vnode to vgroup, openVnodes:%d", pSelDnode->dnodeId, pSelDnode->openVnodes); return TSDB_CODE_SUCCESS; } diff --git a/src/mnode/src/mgmtDnode.c b/src/mnode/src/mgmtDnode.c index 53f0a668b4..9930a3a114 100644 --- a/src/mnode/src/mgmtDnode.c +++ b/src/mnode/src/mgmtDnode.c @@ -29,10 +29,19 @@ static void mgmtProcessCfgDnodeMsg(SQueuedMsg *pMsg); static void mgmtProcessCfgDnodeMsgRsp(SRpcMsg *rpcMsg) ; static void mgmtProcessDnodeStatusMsg(SRpcMsg *rpcMsg); +static int32_t mgmtGetModuleMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn); +static int32_t mgmtRetrieveModules(SShowObj *pShow, char *data, int32_t rows, void *pConn); +static int32_t mgmtGetConfigMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn); +static int32_t mgmtRetrieveConfigs(SShowObj *pShow, char *data, int32_t rows, void *pConn); +static int32_t mgmtGetVnodeMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn); +static int32_t mgmtRetrieveVnodes(SShowObj *pShow, char *data, int32_t rows, void *pConn); +static int32_t mgmtGetDnodeMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn); +static int32_t mgmtRetrieveDnodes(SShowObj *pShow, char *data, int32_t rows, void *pConn); + extern int32_t clusterInit(); extern void clusterCleanUp(); extern int32_t clusterGetDnodesNum(); -extern void * clusterGetNextDnode(void *pNode, SDnodeObj **pDnode); +extern void * clusterGetNextDnode(void *pNode, void **pDnode); extern SDnodeObj* clusterGetDnode(int32_t dnodeId); extern SDnodeObj* clusterGetDnodeByIp(uint32_t ip); #ifndef _CLUSTER @@ -43,7 +52,15 @@ int32_t mgmtInitDnodes() { mgmtAddShellMsgHandle(TSDB_MSG_TYPE_CM_CONFIG_DNODE, mgmtProcessCfgDnodeMsg); mgmtAddDClientRspHandle(TSDB_MSG_TYPE_MD_CONFIG_DNODE_RSP, mgmtProcessCfgDnodeMsgRsp); mgmtAddDServerMsgHandle(TSDB_MSG_TYPE_DM_STATUS, mgmtProcessDnodeStatusMsg); - + mgmtAddShellShowMetaHandle(TSDB_MGMT_TABLE_MODULE, mgmtGetModuleMeta); + mgmtAddShellShowRetrieveHandle(TSDB_MGMT_TABLE_MODULE, mgmtRetrieveModules); + mgmtAddShellShowMetaHandle(TSDB_MGMT_TABLE_CONFIGS, mgmtGetConfigMeta); + mgmtAddShellShowRetrieveHandle(TSDB_MGMT_TABLE_CONFIGS, mgmtRetrieveConfigs); + mgmtAddShellShowMetaHandle(TSDB_MGMT_TABLE_VNODES, mgmtGetVnodeMeta); + mgmtAddShellShowRetrieveHandle(TSDB_MGMT_TABLE_VNODES, mgmtRetrieveVnodes); + mgmtAddShellShowMetaHandle(TSDB_MGMT_TABLE_DNODE, mgmtGetDnodeMeta); + mgmtAddShellShowRetrieveHandle(TSDB_MGMT_TABLE_DNODE, mgmtRetrieveDnodes); + #ifdef _CLUSTER return clusterInit(); #else @@ -250,3 +267,437 @@ void mgmtProcessDnodeStatusMsg(SRpcMsg *rpcMsg) { rpcSendResponse(&rpcRsp); } + +static int32_t mgmtGetDnodeMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn) { + SUserObj *pUser = mgmtGetUserFromConn(pConn, NULL); + if (pUser == NULL) return 0; + + if (strcmp(pUser->pAcct->user, "root") != 0) return TSDB_CODE_NO_RIGHTS; + + int32_t cols = 0; + SSchema *pSchema = pMeta->schema; + + pShow->bytes[cols] = 2; + pSchema[cols].type = TSDB_DATA_TYPE_SMALLINT; + strcpy(pSchema[cols].name, "id"); + pSchema[cols].bytes = htons(pShow->bytes[cols]); + cols++; + + pShow->bytes[cols] = 16; + pSchema[cols].type = TSDB_DATA_TYPE_BINARY; + strcpy(pSchema[cols].name, "private ip"); + pSchema[cols].bytes = htons(pShow->bytes[cols]); + cols++; + + pShow->bytes[cols] = 16; + pSchema[cols].type = TSDB_DATA_TYPE_BINARY; + strcpy(pSchema[cols].name, "public ip"); + pSchema[cols].bytes = htons(pShow->bytes[cols]); + cols++; + + pShow->bytes[cols] = 8; + pSchema[cols].type = TSDB_DATA_TYPE_TIMESTAMP; + strcpy(pSchema[cols].name, "create time"); + pSchema[cols].bytes = htons(pShow->bytes[cols]); + cols++; + + pShow->bytes[cols] = 10; + pSchema[cols].type = TSDB_DATA_TYPE_BINARY; + strcpy(pSchema[cols].name, "status"); + pSchema[cols].bytes = htons(pShow->bytes[cols]); + cols++; + + pShow->bytes[cols] = 2; + pSchema[cols].type = TSDB_DATA_TYPE_SMALLINT; + strcpy(pSchema[cols].name, "open vnodes"); + pSchema[cols].bytes = htons(pShow->bytes[cols]); + cols++; + + pShow->bytes[cols] = 2; + pSchema[cols].type = TSDB_DATA_TYPE_SMALLINT; + strcpy(pSchema[cols].name, "total vnodes"); + pSchema[cols].bytes = htons(pShow->bytes[cols]); + cols++; + +#ifdef _VPEER + pShow->bytes[cols] = 18; + pSchema[cols].type = TSDB_DATA_TYPE_BINARY; + strcpy(pSchema[cols].name, "balance"); + pSchema[cols].bytes = htons(pShow->bytes[cols]); + cols++; +#endif + + pMeta->numOfColumns = htons(cols); + pShow->numOfColumns = cols; + + pShow->offset[0] = 0; + for (int32_t i = 1; i < cols; ++i) { + pShow->offset[i] = pShow->offset[i - 1] + pShow->bytes[i - 1]; + } + + pShow->numOfRows = mgmtGetDnodesNum(); + pShow->rowSize = pShow->offset[cols - 1] + pShow->bytes[cols - 1]; + pShow->pNode = NULL; + + return 0; +} + +static int32_t mgmtRetrieveDnodes(SShowObj *pShow, char *data, int32_t rows, void *pConn) { + int32_t numOfRows = 0; + int32_t cols = 0; + SDnodeObj *pDnode = NULL; + char *pWrite; + char ipstr[32]; + + while (numOfRows < rows) { + pShow->pNode = mgmtGetNextDnode(pShow->pNode, (SDnodeObj **)&pDnode); + if (pDnode == NULL) break; + + cols = 0; + + pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; + *(int16_t *)pWrite = pDnode->dnodeId; + cols++; + + tinet_ntoa(ipstr, pDnode->privateIp); + pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; + strcpy(pWrite, ipstr); + cols++; + + tinet_ntoa(ipstr, pDnode->publicIp); + pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; + strcpy(pWrite, ipstr); + cols++; + + pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; + *(int64_t *)pWrite = pDnode->createdTime; + cols++; + + pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; + strcpy(pWrite, taosGetDnodeStatusStr(pDnode->status) ); + cols++; + + pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; + *(int16_t *)pWrite = pDnode->openVnodes; + cols++; + + pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; + *(int16_t *)pWrite = pDnode->numOfTotalVnodes; + cols++; + +#ifdef _VPEER + pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; + strcpy(pWrite, taosGetDnodeLbStatusStr(pDnode->lbStatus)); + cols++; +#endif + + numOfRows++; + } + + pShow->numOfReads += numOfRows; + return numOfRows; +} + +static bool clusterCheckModuleInDnode(SDnodeObj *pDnode, int32_t moduleType) { + uint32_t status = pDnode->moduleStatus & (1 << moduleType); + return status > 0; +} + +static int32_t mgmtGetModuleMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn) { + int32_t cols = 0; + + SUserObj *pUser = mgmtGetUserFromConn(pConn, NULL); + if (pUser == NULL) return 0; + + if (strcmp(pUser->user, "root") != 0) return TSDB_CODE_NO_RIGHTS; + + SSchema *pSchema = pMeta->schema; + + pShow->bytes[cols] = 16; + pSchema[cols].type = TSDB_DATA_TYPE_BINARY; + strcpy(pSchema[cols].name, "IP"); + pSchema[cols].bytes = htons(pShow->bytes[cols]); + cols++; + + pShow->bytes[cols] = 10; + pSchema[cols].type = TSDB_DATA_TYPE_BINARY; + strcpy(pSchema[cols].name, "module type"); + pSchema[cols].bytes = htons(pShow->bytes[cols]); + cols++; + + pShow->bytes[cols] = 10; + pSchema[cols].type = TSDB_DATA_TYPE_BINARY; + strcpy(pSchema[cols].name, "module status"); + pSchema[cols].bytes = htons(pShow->bytes[cols]); + cols++; + + pMeta->numOfColumns = htons(cols); + pShow->numOfColumns = cols; + + pShow->offset[0] = 0; + for (int32_t i = 1; i < cols; ++i) { + pShow->offset[i] = pShow->offset[i - 1] + pShow->bytes[i - 1]; + } + + pShow->numOfRows = 0; + SDnodeObj *pDnode = NULL; + while (1) { + pShow->pNode = mgmtGetNextDnode(pShow->pNode, (SDnodeObj **)&pDnode); + if (pDnode == NULL) break; + for (int32_t moduleType = 0; moduleType < TSDB_MOD_MAX; ++moduleType) { + if (clusterCheckModuleInDnode(pDnode, moduleType)) { + pShow->numOfRows++; + } + } + } + + pShow->rowSize = pShow->offset[cols - 1] + pShow->bytes[cols - 1]; + pShow->pNode = NULL; + + return 0; +} + +int32_t mgmtRetrieveModules(SShowObj *pShow, char *data, int32_t rows, void *pConn) { + int32_t numOfRows = 0; + SDnodeObj *pDnode = NULL; + char * pWrite; + int32_t cols = 0; + char ipstr[20]; + + while (numOfRows < rows) { + pShow->pNode = mgmtGetNextDnode(pShow->pNode, (SDnodeObj **)&pDnode); + if (pDnode == NULL) break; + + for (int32_t moduleType = 0; moduleType < TSDB_MOD_MAX; ++moduleType) { + if (!clusterCheckModuleInDnode(pDnode, moduleType)) { + continue; + } + + cols = 0; + + tinet_ntoa(ipstr, pDnode->privateIp); + pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; + strcpy(pWrite, ipstr); + cols++; + + pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; + strcpy(pWrite, tsModule[moduleType].name); + cols++; + + pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; + strcpy(pWrite, taosGetDnodeStatusStr(pDnode->status) ); + cols++; + + numOfRows++; + } + } + + pShow->numOfReads += numOfRows; + return numOfRows; +} + +static bool clusterCheckConfigShow(SGlobalConfig *cfg) { + if (!(cfg->cfgType & TSDB_CFG_CTYPE_B_SHOW)) + return false; + return true; +} + +static int32_t mgmtGetConfigMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn) { + int32_t cols = 0; + + SUserObj *pUser = mgmtGetUserFromConn(pConn, NULL); + if (pUser == NULL) return 0; + + if (strcmp(pUser->user, "root") != 0) return TSDB_CODE_NO_RIGHTS; + + SSchema *pSchema = pMeta->schema; + + pShow->bytes[cols] = TSDB_CFG_OPTION_LEN; + pSchema[cols].type = TSDB_DATA_TYPE_BINARY; + strcpy(pSchema[cols].name, "config name"); + pSchema[cols].bytes = htons(pShow->bytes[cols]); + cols++; + + pShow->bytes[cols] = TSDB_CFG_VALUE_LEN; + pSchema[cols].type = TSDB_DATA_TYPE_BINARY; + strcpy(pSchema[cols].name, "config value"); + pSchema[cols].bytes = htons(pShow->bytes[cols]); + cols++; + + pMeta->numOfColumns = htons(cols); + pShow->numOfColumns = cols; + + pShow->offset[0] = 0; + for (int32_t i = 1; i < cols; ++i) pShow->offset[i] = pShow->offset[i - 1] + pShow->bytes[i - 1]; + + pShow->numOfRows = 0; + for (int32_t i = tsGlobalConfigNum - 1; i >= 0; --i) { + SGlobalConfig *cfg = tsGlobalConfig + i; + if (!clusterCheckConfigShow(cfg)) continue; + pShow->numOfRows++; + } + + pShow->rowSize = pShow->offset[cols - 1] + pShow->bytes[cols - 1]; + pShow->pNode = NULL; + + return 0; +} + +static int32_t mgmtRetrieveConfigs(SShowObj *pShow, char *data, int32_t rows, void *pConn) { + int32_t numOfRows = 0; + + for (int32_t i = tsGlobalConfigNum - 1; i >= 0 && numOfRows < rows; --i) { + SGlobalConfig *cfg = tsGlobalConfig + i; + if (!clusterCheckConfigShow(cfg)) continue; + + char *pWrite; + int32_t cols = 0; + + pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; + snprintf(pWrite, TSDB_CFG_OPTION_LEN, "%s", cfg->option); + cols++; + + pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; + switch (cfg->valType) { + case TSDB_CFG_VTYPE_SHORT: + snprintf(pWrite, TSDB_CFG_VALUE_LEN, "%d", *((int16_t *)cfg->ptr)); + numOfRows++; + break; + case TSDB_CFG_VTYPE_INT: + snprintf(pWrite, TSDB_CFG_VALUE_LEN, "%d", *((int32_t *)cfg->ptr)); + numOfRows++; + break; + case TSDB_CFG_VTYPE_UINT: + snprintf(pWrite, TSDB_CFG_VALUE_LEN, "%d", *((uint32_t *)cfg->ptr)); + numOfRows++; + break; + case TSDB_CFG_VTYPE_FLOAT: + snprintf(pWrite, TSDB_CFG_VALUE_LEN, "%f", *((float *)cfg->ptr)); + numOfRows++; + break; + case TSDB_CFG_VTYPE_STRING: + case TSDB_CFG_VTYPE_IPSTR: + case TSDB_CFG_VTYPE_DIRECTORY: + snprintf(pWrite, TSDB_CFG_VALUE_LEN, "%s", (char *)cfg->ptr); + numOfRows++; + break; + default: + break; + } + } + + pShow->numOfReads += numOfRows; + return numOfRows; +} + +static int32_t mgmtGetVnodeMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn) { + int32_t cols = 0; + SUserObj *pUser = mgmtGetUserFromConn(pConn, NULL); + if (pUser == NULL) return 0; + if (strcmp(pUser->user, "root") != 0) return TSDB_CODE_NO_RIGHTS; + + SSchema *pSchema = pMeta->schema; + + pShow->bytes[cols] = 4; + pSchema[cols].type = TSDB_DATA_TYPE_INT; + strcpy(pSchema[cols].name, "vnode"); + pSchema[cols].bytes = htons(pShow->bytes[cols]); + cols++; + + pShow->bytes[cols] = 12; + pSchema[cols].type = TSDB_DATA_TYPE_BINARY; + strcpy(pSchema[cols].name, "status"); + pSchema[cols].bytes = htons(pShow->bytes[cols]); + cols++; + + pShow->bytes[cols] = 12; + pSchema[cols].type = TSDB_DATA_TYPE_BINARY; + strcpy(pSchema[cols].name, "sync_status"); + pSchema[cols].bytes = htons(pShow->bytes[cols]); + cols++; + + pMeta->numOfColumns = htons(cols); + pShow->numOfColumns = cols; + + pShow->offset[0] = 0; + for (int32_t i = 1; i < cols; ++i) pShow->offset[i] = pShow->offset[i - 1] + pShow->bytes[i - 1]; + + SDnodeObj *pDnode = NULL; + if (pShow->payloadLen > 0 ) { + uint32_t ip = ip2uint(pShow->payload); + pDnode = mgmtGetDnodeByIp(ip); + if (NULL == pDnode) { + return TSDB_CODE_NODE_OFFLINE; + } + + SVnodeLoad* pVnode; + pShow->numOfRows = 0; + for (int32_t i = 0 ; i < TSDB_MAX_VNODES; i++) { + pVnode = &pDnode->vload[i]; + if (0 != pVnode->vgId) { + pShow->numOfRows++; + } + } + + pShow->pNode = pDnode; + } else { + while (true) { + pShow->pNode = mgmtGetNextDnode(pShow->pNode, (SDnodeObj **)&pDnode); + if (pDnode == NULL) break; + pShow->numOfRows += pDnode->openVnodes; + + if (0 == pShow->numOfRows) return TSDB_CODE_NODE_OFFLINE; + } + + pShow->pNode = NULL; + } + + pShow->rowSize = pShow->offset[cols - 1] + pShow->bytes[cols - 1]; + + return 0; +} + +static int32_t mgmtRetrieveVnodes(SShowObj *pShow, char *data, int32_t rows, void *pConn) { + int32_t numOfRows = 0; + SDnodeObj *pDnode = NULL; + char * pWrite; + int32_t cols = 0; + + if (0 == rows) return 0; + + if (pShow->payloadLen) { + // output the vnodes info of the designated dnode. And output all vnodes of this dnode, instead of rows (max 100) + pDnode = (SDnodeObj *)(pShow->pNode); + if (pDnode != NULL) { + SVnodeLoad* pVnode; + for (int32_t i = 0 ; i < TSDB_MAX_VNODES; i++) { + pVnode = &pDnode->vload[i]; + if (0 == pVnode->vgId) { + continue; + } + + cols = 0; + + pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; + *(uint32_t *)pWrite = pVnode->vgId; + cols++; + + pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; + strcpy(pWrite, taosGetVnodeStatusStr(pVnode->status)); + cols++; + + pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; + strcpy(pWrite, taosGetVnodeSyncStatusStr(pVnode->syncStatus)); + cols++; + + numOfRows++; + } + } + } else { + // TODO: output all vnodes of all dnodes + numOfRows = 0; + } + + pShow->numOfReads += numOfRows; + return numOfRows; +} \ No newline at end of file diff --git a/src/mnode/src/mgmtMnode.c b/src/mnode/src/mgmtMnode.c index 71ce50eccb..e9277651c7 100644 --- a/src/mnode/src/mgmtMnode.c +++ b/src/mnode/src/mgmtMnode.c @@ -15,122 +15,82 @@ #define _DEFAULT_SOURCE #include "os.h" +#include "taoserror.h" +#include "tstatus.h" #include "trpc.h" #include "mgmtMnode.h" #include "mgmtSdb.h" +#include "mgmtShell.h" #include "mgmtUser.h" -int32_t (*mpeerAddMnodeFp)(uint32_t privateIp, uint32_t publicIp) = NULL; -int32_t (*mpeerRemoveMnodeFp)(uint32_t privateIp) = NULL; -int32_t (*mpeerGetMnodesNumFp)() = NULL; -void * (*mpeerGetNextMnodeFp)(SShowObj *pShow, SMnodeObj **pMnode) = NULL; -int32_t (*mpeerInitMnodesFp)() = NULL; -void (*mpeerCleanUpMnodesFp)() = NULL; +#ifndef _MPEER static SMnodeObj tsMnodeObj = {0}; -static bool tsMnodeIsMaster = false; -static bool tsMnodeIsServing = false; static int32_t mgmtGetMnodeMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn); static int32_t mgmtRetrieveMnodes(SShowObj *pShow, char *data, int32_t rows, void *pConn); -static char *mgmtMnodeStatusStr[] = { - "offline", - "unsynced", - "syncing", - "serving", - "null" -}; - -static char *mgmtMnodeRoleStr[] = { - "unauthed", - "undecided", - "master", - "slave", - "null" -}; - int32_t mgmtInitMnodes() { - if (mpeerInitMnodesFp) { - return (*mpeerInitMnodesFp)(); - } else { - tsMnodeIsServing = true; - tsMnodeIsMaster = true; - return 0; - } -} - -void mgmtCleanupMnodes() { - if (mpeerCleanUpMnodesFp) { - (*mpeerCleanUpMnodesFp)(); - } -} - -bool mgmtInServerStatus() { - return tsMnodeIsServing; -} - -bool mgmtIsMaster() { - return tsMnodeIsMaster; -} - -bool mgmtCheckRedirect(void *handle) { - return false; -} - -int32_t mgmtAddMnode(uint32_t privateIp, uint32_t publicIp) { - if (mpeerAddMnodeFp) { - return (*mpeerAddMnodeFp)(privateIp, publicIp); - } else { - return 0; - } + mgmtAddShellShowMetaHandle(TSDB_MGMT_TABLE_MNODE, mgmtGetMnodeMeta); + mgmtAddShellShowRetrieveHandle(TSDB_MGMT_TABLE_MNODE, mgmtRetrieveMnodes); + + tsMnodeObj.mnodeId = 1; + tsMnodeObj.privateIp = inet_addr(tsPrivateIp); + tsMnodeObj.publicIp = inet_addr(tsPublicIp); + tsMnodeObj.createdTime = taosGetTimestampMs(); + tsMnodeObj.role = TSDB_MN_ROLE_MASTER; + tsMnodeObj.status = TSDB_MN_STATUS_SERVING; + tsMnodeObj.numOfMnodes = 1; + sprintf(tsMnodeObj.mnodeName, "%d", tsMnodeObj.mnodeId); + + return TSDB_CODE_SUCCESS; } -int32_t mgmtRemoveMnode(uint32_t privateIp) { - if (mpeerRemoveMnodeFp) { - return (*mpeerRemoveMnodeFp)(privateIp); - } else { - return 0; - } -} +void mgmtCleanupMnodes() {} +bool mgmtInServerStatus() { return tsMnodeObj.status == TSDB_MN_STATUS_SERVING; } +bool mgmtIsMaster() { return tsMnodeObj.role == TSDB_MN_ROLE_MASTER; } +bool mgmtCheckRedirect(void *handle) { return false; } static int32_t mgmtGetMnodesNum() { - if (mpeerGetMnodesNumFp) { - return (*mpeerGetMnodesNumFp)(); - } else { - return 1; - } + return 1; } -static void *mgmtGetNextMnode(SShowObj *pShow, SMnodeObj **pMnode) { - if (mpeerGetNextMnodeFp) { - return (*mpeerGetNextMnodeFp)(pShow, pMnode); +static void *mgmtGetNextMnode(void *pNode, SMnodeObj **pMnode) { + if (*pMnode == NULL) { + *pMnode = &tsMnodeObj; } else { - if (*pMnode == NULL) { - *pMnode = &tsMnodeObj; - } else { - *pMnode = NULL; - } + *pMnode = NULL; } return *pMnode; } static int32_t mgmtGetMnodeMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn) { - int32_t cols = 0; - SUserObj *pUser = mgmtGetUserFromConn(pConn, NULL); if (pUser == NULL) return 0; - if (strcmp(pUser->user, "root") != 0) return TSDB_CODE_NO_RIGHTS; + if (strcmp(pUser->pAcct->user, "root") != 0) return TSDB_CODE_NO_RIGHTS; + int32_t cols = 0; SSchema *pSchema = pMeta->schema; + pShow->bytes[cols] = 2; + pSchema[cols].type = TSDB_DATA_TYPE_SMALLINT; + strcpy(pSchema[cols].name, "id"); + pSchema[cols].bytes = htons(pShow->bytes[cols]); + cols++; + pShow->bytes[cols] = 16; pSchema[cols].type = TSDB_DATA_TYPE_BINARY; strcpy(pSchema[cols].name, "private ip"); pSchema[cols].bytes = htons(pShow->bytes[cols]); cols++; + pShow->bytes[cols] = 16; + pSchema[cols].type = TSDB_DATA_TYPE_BINARY; + strcpy(pSchema[cols].name, "public ip"); + pSchema[cols].bytes = htons(pShow->bytes[cols]); + cols++; + pShow->bytes[cols] = 8; pSchema[cols].type = TSDB_DATA_TYPE_TIMESTAMP; strcpy(pSchema[cols].name, "create time"); @@ -149,12 +109,6 @@ static int32_t mgmtGetMnodeMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pCo pSchema[cols].bytes = htons(pShow->bytes[cols]); cols++; - pShow->bytes[cols] = 16; - pSchema[cols].type = TSDB_DATA_TYPE_BINARY; - strcpy(pSchema[cols].name, "public ip"); - pSchema[cols].bytes = htons(pShow->bytes[cols]); - cols++; - pMeta->numOfColumns = htons(cols); pShow->numOfColumns = cols; @@ -163,7 +117,7 @@ static int32_t mgmtGetMnodeMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pCo pShow->offset[i] = pShow->offset[i - 1] + pShow->bytes[i - 1]; } - pShow->numOfRows = mgmtGetMnodesNum(); + pShow->numOfRows = mgmtGetDnodesNum(); pShow->rowSize = pShow->offset[cols - 1] + pShow->bytes[cols - 1]; pShow->pNode = NULL; @@ -171,38 +125,42 @@ static int32_t mgmtGetMnodeMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pCo } static int32_t mgmtRetrieveMnodes(SShowObj *pShow, char *data, int32_t rows, void *pConn) { - int32_t numOfRows = 0; - int32_t cols = 0; + int32_t numOfRows = 0; + int32_t cols = 0; SMnodeObj *pMnode = NULL; - char *pWrite; - char ipstr[32]; + char *pWrite; + char ipstr[32]; while (numOfRows < rows) { - pShow->pNode = mgmtGetNextMnode(pShow, (SMnodeObj **)&pMnode); + pShow->pNode = mgmtGetNextMnode(pShow->pNode, (SMnodeObj **)&pMnode); if (pMnode == NULL) break; cols = 0; + pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; + *(int16_t *)pWrite = pMnode->mnodeId; + cols++; + tinet_ntoa(ipstr, pMnode->privateIp); pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; strcpy(pWrite, ipstr); cols++; + tinet_ntoa(ipstr, pMnode->publicIp); pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; - *(int64_t *)pWrite = pMnode->createdTime; + strcpy(pWrite, ipstr); cols++; pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; - strcpy(pWrite, mgmtMnodeStatusStr[pMnode->status]); + *(int64_t *)pWrite = pMnode->createdTime; cols++; pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; - strcpy(pWrite, mgmtMnodeRoleStr[pMnode->role]); + strcpy(pWrite, taosGetMnodeStatusStr(pMnode->status)); cols++; - tinet_ntoa(ipstr, pMnode->publicIp); - pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; - strcpy(pWrite, ipstr); + pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; + strcpy(pWrite, taosGetMnodeRoleStr(pMnode->role)); cols++; numOfRows++; @@ -216,12 +174,14 @@ void mgmtGetMnodePrivateIpList(SRpcIpSet *ipSet) { ipSet->inUse = 0; ipSet->port = htons(tsMnodeDnodePort); ipSet->numOfIps = 1; - ipSet->ip[0] = htonl(inet_addr(tsMasterIp)); + ipSet->ip[0] = htonl(tsMnodeObj.privateIp); } void mgmtGetMnodePublicIpList(SRpcIpSet *ipSet) { ipSet->inUse = 0; ipSet->port = htons(tsMnodeDnodePort); ipSet->numOfIps = 1; - ipSet->ip[0] = htonl(inet_addr(tsMasterIp)); -} \ No newline at end of file + ipSet->ip[0] = htonl(tsMnodeObj.publicIp); +} + +#endif \ No newline at end of file diff --git a/src/mnode/src/mgmtVgroup.c b/src/mnode/src/mgmtVgroup.c index 59880d204d..7e46b61d0c 100644 --- a/src/mnode/src/mgmtVgroup.c +++ b/src/mnode/src/mgmtVgroup.c @@ -53,6 +53,14 @@ static int32_t mgmtVgroupActionDestroy(SSdbOperDesc *pOper) { if (pVgroup->tableList) { tfree(pVgroup->tableList); } + + for (int32_t i = 0; i < pVgroup->numOfVnodes; ++i) { + SDnodeObj *pDnode = mgmtGetDnode(pVgroup->vnodeGid[i].dnodeId); + if (pDnode) { + atomic_sub_fetch_32(&pDnode->openVnodes, 1); + } + } + tfree(pOper->pObj); return TSDB_CODE_SUCCESS; } @@ -87,6 +95,7 @@ static int32_t mgmtVgroupActionInsert(SSdbOperDesc *pOper) { pVgroup->vnodeGid[i].privateIp = pDnode->privateIp; pVgroup->vnodeGid[i].publicIp = pDnode->publicIp; pVgroup->vnodeGid[i].vnode = pVgroup->vgId; + atomic_add_fetch_32(&pDnode->openVnodes, 1); } mgmtAddVgroupIntoDb(pVgroup); diff --git a/src/util/inc/tstatus.h b/src/util/inc/tstatus.h index 9a65bb3ac1..223ed1d52d 100644 --- a/src/util/inc/tstatus.h +++ b/src/util/inc/tstatus.h @@ -62,6 +62,19 @@ enum _TSDB_VN_DROP_STATUS { TSDB_VN_DROP_STATUS_DROPPING }; +enum _TSDB_MN_STATUS { + TSDB_MN_STATUS_OFFLINE, + TSDB_MN_STATUS_UNSYNCED, + TSDB_MN_STATUS_SYNCING, + TSDB_MN_STATUS_SERVING +}; + +enum _TSDB_MN_ROLE { + TSDB_MN_ROLE_UNDECIDED, + TSDB_MN_ROLE_SLAVE, + TSDB_MN_ROLE_MASTER +}; + enum _TSDB_DN_STATUS { TSDB_DN_STATUS_OFFLINE, TSDB_DN_STATUS_READY @@ -104,6 +117,8 @@ char* taosGetVgroupLbStatusStr(int32_t vglbStatus); char* taosGetVnodeStreamStatusStr(int32_t vnodeStreamStatus); char* taosGetTableStatusStr(int32_t tableStatus); char *taosGetShowTypeStr(int32_t showType); +char *taosGetMnodeStatusStr(int32_t mnodeStatus); +char *taosGetMnodeRoleStr(int32_t mnodeRole); #ifdef __cplusplus } diff --git a/src/util/src/.tqueue.c.swp b/src/util/src/.tqueue.c.swp deleted file mode 100644 index 40a09d5f638ccd61507bd50661e64d34cccce61c..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 20480 zcmeI2dyHIF8NhEv1QCP)iGres#p2F(ccRai9s#k10v#ER4@jO37RN~;sXeVhz}xyAc~5{2Y(P12on8$=bZbRM|Yc$_{g2) zx3hE4>pS21&g1*;nO}YGi};ZqzwM>)>vC%*eFH(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5?dkLjWQ9WIkyRjtg@HvP#(TTRrd_Tb@YoMayZc(LZ+0o0lSr*!_ z>!AaCBd_bSp)Ydj^=6=fXp3ZTzhP&!XfnyNHy&QAle!}r>>979h6Jn+a9;GdsVLWl tm0WBn6K6BVmbxWtmZe@thlDvt@vnp}nBDonCSV*D>zH$~FVKC~{TrwbDt!O| diff --git a/src/util/src/tstatus.c b/src/util/src/tstatus.c index 4cf8430484..e8534de30b 100644 --- a/src/util/src/tstatus.c +++ b/src/util/src/tstatus.c @@ -136,3 +136,22 @@ char *taosGetShowTypeStr(int32_t showType) { default: return "undefined"; } } + +char *taosGetMnodeStatusStr(int32_t mnodeStatus) { + switch (mnodeStatus) { + case TSDB_MN_STATUS_OFFLINE: return "offline"; + case TSDB_MN_STATUS_UNSYNCED: return "unsynced"; + case TSDB_MN_STATUS_SYNCING: return "syncing"; + case TSDB_MN_STATUS_SERVING: return "serving"; + default: return "undefined"; + } +} + +char *taosGetMnodeRoleStr(int32_t mnodeRole) { + switch (mnodeRole) { + case TSDB_MN_ROLE_UNDECIDED: return "undicided"; + case TSDB_MN_ROLE_SLAVE: return "slave"; + case TSDB_MN_ROLE_MASTER: return "master"; + default: return "undefined"; + } +} diff --git a/tests/script/general/show/dnodes.sim b/tests/script/general/show/dnodes.sim new file mode 100644 index 0000000000..df78194365 --- /dev/null +++ b/tests/script/general/show/dnodes.sim @@ -0,0 +1,16 @@ +system sh/stop_dnodes.sh +system sh/deploy.sh -n dnode1 -m 192.168.0.1 -i 192.168.0.1 +system sh/exec.sh -n dnode1 -s start +sql connect + +print =============== unsupport +sql_error create dnode 192.168.0.2 +sql_error drop dnode 192.168.0.2 + +print =============== show dnodes +sql show dnodes; +if $rows != 1 then + return -1 +endi + +print $data00 $data01 $data02 -- GitLab