From 6f65c5a9616a67431be62a7864a7d92a0fb9c5f0 Mon Sep 17 00:00:00 2001 From: slguan Date: Thu, 26 Mar 2020 11:22:06 +0800 Subject: [PATCH] [TD-9] error while get metadata --- src/mnode/src/mgmtChildTable.c | 12 ++++++------ src/mnode/src/mgmtSuperTable.c | 4 ++-- src/mnode/src/mgmtTable.c | 7 +++++++ src/mnode/src/mgmtVgroup.c | 29 +++++++++++++---------------- 4 files changed, 28 insertions(+), 24 deletions(-) diff --git a/src/mnode/src/mgmtChildTable.c b/src/mnode/src/mgmtChildTable.c index 2d4f37581d..58cee331b3 100644 --- a/src/mnode/src/mgmtChildTable.c +++ b/src/mnode/src/mgmtChildTable.c @@ -725,13 +725,13 @@ static int32_t mgmtDoGetChildTableMeta(SDbObj *pDb, SChildTableObj *pTable, STab if (pTable->info.type == TSDB_CHILD_TABLE) { pMeta->sversion = htons(pTable->superTable->sversion); - pMeta->numOfTags = htons(pTable->superTable->numOfTags); - pMeta->numOfColumns = htons(pTable->superTable->numOfColumns); + pMeta->numOfTags = 0; + pMeta->numOfColumns = htons((int16_t)pTable->superTable->numOfColumns); pMeta->contLen = sizeof(STableMetaMsg) + mgmtSetSchemaFromSuperTable(pMeta->schema, pTable->superTable); } else { pMeta->sversion = htons(pTable->sversion); pMeta->numOfTags = 0; - pMeta->numOfColumns = htons(pTable->numOfColumns); + pMeta->numOfColumns = htons((int16_t)pTable->numOfColumns); pMeta->contLen = sizeof(STableMetaMsg) + mgmtSetSchemaFromNormalTable(pMeta->schema, pTable); } @@ -758,9 +758,9 @@ static int32_t mgmtDoGetChildTableMeta(SDbObj *pDb, SChildTableObj *pTable, STab void mgmtGetChildTableMeta(SQueuedMsg *pMsg, SChildTableObj *pTable) { SCMTableInfoMsg *pInfo = pMsg->pCont; - SDbObj *pDb = mgmtGetDbByTableId(pTable->info.tableId); + SDbObj *pDb = mgmtGetDbByTableId(pInfo->tableId); if (pDb == NULL || pDb->dirty) { - mError("table:%s, failed to get table meta, db not selected", pTable->info.tableId); + mError("table:%s, failed to get table meta, db not selected", pInfo->tableId); mgmtSendSimpleResp(pMsg->thandle, TSDB_CODE_DB_NOT_SELECTED); return; } @@ -877,7 +877,7 @@ static STableInfo* mgmtGetTableByPos(uint32_t dnodeId, int32_t vnode, int32_t si return NULL; } - return pVgroup->tableList[sid]; + return (STableInfo *)pVgroup->tableList[sid]; } static void mgmtProcessTableCfgMsg(SRpcMsg *rpcMsg) { diff --git a/src/mnode/src/mgmtSuperTable.c b/src/mnode/src/mgmtSuperTable.c index e340643998..ba7be9ba59 100644 --- a/src/mnode/src/mgmtSuperTable.c +++ b/src/mnode/src/mgmtSuperTable.c @@ -610,8 +610,8 @@ void mgmtGetSuperTableMeta(SQueuedMsg *pMsg, SSuperTableObj *pTable) { pMeta->uid = htobe64(pTable->uid); pMeta->sversion = htons(pTable->sversion); pMeta->precision = pDb->cfg.precision; - pMeta->numOfTags = pTable->numOfTags; - pMeta->numOfColumns = htons(pTable->numOfColumns); + pMeta->numOfTags = htons((int16_t)pTable->numOfTags); + pMeta->numOfColumns = htons((int16_t)pTable->numOfColumns); pMeta->tableType = pTable->info.type; pMeta->contLen = sizeof(STableMetaMsg) + mgmtSetSchemaFromSuperTable(pMeta->schema, pTable); strcpy(pMeta->tableId, pTable->info.tableId); diff --git a/src/mnode/src/mgmtTable.c b/src/mnode/src/mgmtTable.c index 3e47a7c277..5169f4a817 100644 --- a/src/mnode/src/mgmtTable.c +++ b/src/mnode/src/mgmtTable.c @@ -230,6 +230,13 @@ static void mgmtProcessTableMetaMsg(SQueuedMsg *pMsg) { SCMTableInfoMsg *pInfo = pMsg->pCont; mTrace("table:%s, table meta msg is received from thandle:%p", pInfo->tableId, pMsg->thandle); + pMsg->pDb = mgmtGetDbByTableId(pInfo->tableId); + if (pMsg->pDb == NULL || pMsg->pDb->dirty) { + mError("table:%s, failed to get table meta, db not selected", pInfo->tableId); + mgmtSendSimpleResp(pMsg->thandle, TSDB_CODE_DB_NOT_SELECTED); + return; + } + STableInfo *pTable = mgmtGetTable(pInfo->tableId); if (pTable == NULL || pTable->type != TSDB_SUPER_TABLE) { mgmtGetChildTableMeta(pMsg, (SChildTableObj *)pTable); diff --git a/src/mnode/src/mgmtVgroup.c b/src/mnode/src/mgmtVgroup.c index a8e7219e2e..f6f0e9b76a 100644 --- a/src/mnode/src/mgmtVgroup.c +++ b/src/mnode/src/mgmtVgroup.c @@ -25,6 +25,7 @@ #include "mgmtDClient.h" #include "mgmtDnode.h" #include "mgmtDServer.h" +#include "mgmtMnode.h" #include "mgmtProfile.h" #include "mgmtSdb.h" #include "mgmtShell.h" @@ -483,17 +484,6 @@ SMDCreateVnodeMsg *mgmtBuildCreateVnodeMsg(SVgObj *pVgroup) { return pVnode; } -static SVgObj *mgmtGetVgroupInDnode(uint32_t dnodeId, int32_t vgId) { - if (vnovgId < 1 || dnodeId < 1) return NULL; - - SDnodeObj *pDnode = mgmtGetDnode(dnodeId); - if (pDnode == NULL) { - return NULL; - } - - return mgmtGetVgroup(vgId); -} - SRpcIpSet mgmtGetIpSetFromVgroup(SVgObj *pVgroup) { SRpcIpSet ipSet = { .numOfIps = pVgroup->numOfVnodes, @@ -657,19 +647,26 @@ static void mgmtProcessVnodeCfgMsg(SRpcMsg *rpcMsg) { if (mgmtCheckRedirect(rpcMsg->handle)) return; SDMConfigVnodeMsg *pCfg = (SDMConfigVnodeMsg *) rpcMsg->pCont; - pCfg->dnodeId = htonl(pCfg->dnode); - pCfg->vgId = htonl(pCfg->vnode); + pCfg->dnodeId = htonl(pCfg->dnodeId); + pCfg->vgId = htonl(pCfg->vgId); + + SDnodeObj *pDnode = mgmtGetDnode(pCfg->dnodeId); + if (pDnode == NULL) { + mTrace("dnode:%s, invalid dnode", taosIpStr(pCfg->dnodeId), pCfg->vgId); + mgmtSendSimpleResp(rpcMsg->handle, TSDB_CODE_NOT_ACTIVE_VNODE); + return; + } - SVgObj *pVgroup = mgmtGetVgroupInDnode(pCfg->dnodeId, pCfg->vgId); + SVgObj *pVgroup = mgmtGetVgroup(pCfg->vgId); if (pVgroup == NULL) { - mTrace("dnode:%s, vnode:%d, no vgroup info", taosIpStr(pCfg->dnode), pCfg->vnode); + mTrace("dnode:%s, vgId:%d, no vgroup info", taosIpStr(pCfg->dnodeId), pCfg->vgId); mgmtSendSimpleResp(rpcMsg->handle, TSDB_CODE_NOT_ACTIVE_VNODE); return; } mgmtSendSimpleResp(rpcMsg->handle, TSDB_CODE_SUCCESS); - SRpcIpSet ipSet = mgmtGetIpSetFromIp(pCfg->dnode); + SRpcIpSet ipSet = mgmtGetIpSetFromIp(pDnode->privateIp); mgmtSendCreateVnodeMsg(pVgroup, &ipSet, NULL); } -- GitLab