From de76b5bd30d6ca2a813e8e57930f2bc6c43d5a69 Mon Sep 17 00:00:00 2001 From: slguan Date: Thu, 16 Apr 2020 13:31:56 +0800 Subject: [PATCH] change super table vgroup --- src/inc/mnode.h | 1 + src/inc/taosmsg.h | 11 ++++----- src/mnode/src/mgmtTable.c | 50 +++++++++++++++++++++++---------------- 3 files changed, 35 insertions(+), 27 deletions(-) diff --git a/src/inc/mnode.h b/src/inc/mnode.h index 3a55679b21..f0407aa9e4 100644 --- a/src/inc/mnode.h +++ b/src/inc/mnode.h @@ -88,6 +88,7 @@ typedef struct _dnode_obj { typedef struct { int32_t dnodeId; + uint16_t port; uint32_t privateIp; uint32_t publicIp; } SVnodeGid; diff --git a/src/inc/taosmsg.h b/src/inc/taosmsg.h index 94e90c0bc8..2e25f7f761 100644 --- a/src/inc/taosmsg.h +++ b/src/inc/taosmsg.h @@ -634,14 +634,13 @@ typedef struct SCMSTableVgroupMsg { } SCMSTableVgroupMsg; typedef struct { - SIpAddr ipAddr; - int32_t numOfVgroups; - int32_t vgId[]; -} STableDnodeVgroupInfo; + int32_t vgId; + SIpAddr ipAddr[TSDB_REPLICA_MAX_NUM]; +} SCMVgroupInfo; typedef struct { - int32_t numOfDnodes; - STableDnodeVgroupInfo dnodeVgroups[]; + int32_t numOfVgroups; + SCMVgroupInfo vgroups[]; } SCMSTableVgroupRspMsg; typedef struct { diff --git a/src/mnode/src/mgmtTable.c b/src/mnode/src/mgmtTable.c index 27ddd46e29..0dd8960648 100644 --- a/src/mnode/src/mgmtTable.c +++ b/src/mnode/src/mgmtTable.c @@ -1166,40 +1166,48 @@ static void mgmtGetSuperTableMeta(SQueuedMsg *pMsg) { static void mgmtProcessSuperTableVgroupMsg(SQueuedMsg *pMsg) { SCMSTableVgroupMsg *pInfo = pMsg->pCont; - pMsg->pTable = mgmtGetSuperTable(pInfo->tableId); + SSuperTableObj *pTable = mgmtGetSuperTable(pInfo->tableId); + + pMsg->pTable = pTable; if (pMsg->pTable == NULL) { mgmtSendSimpleResp(pMsg->thandle, TSDB_CODE_INVALID_TABLE); return; } - SCMSTableVgroupRspMsg *pRsp = rpcMallocCont(sizeof(SCMSTableVgroupRspMsg) + sizeof(uint32_t) * clusterGetDnodesNum()); + int32_t contLen = sizeof(SCMSTableVgroupRspMsg) + sizeof(SCMVgroupInfo) * pTable->vgLen; + SCMSTableVgroupRspMsg *pRsp = rpcMallocCont(contLen); if (pRsp == NULL) { - mgmtSendSimpleResp(pMsg->thandle, TSDB_CODE_INVALID_TABLE); + mgmtSendSimpleResp(pMsg->thandle, TSDB_CODE_SERV_OUT_OF_MEMORY); return; } - int32_t numOfVgroups = 1; - int32_t numOfDnodes = 1; - - pRsp->numOfDnodes = htonl(numOfDnodes); - STableDnodeVgroupInfo* pVgroupInfo = pRsp->dnodeVgroups; - pVgroupInfo->ipAddr.ip = htonl(inet_addr(tsPrivateIp)); - - pVgroupInfo->ipAddr.port = htons(0); // todo fix it - pVgroupInfo->numOfVgroups = htonl(numOfVgroups); // todo fix it - int32_t* vgIdList = pVgroupInfo->vgId; - - for(int32_t i = 0; i < numOfVgroups; ++i) { - vgIdList[i] = htonl(2); // todo fix it + int32_t vg = 0; + for (; vg < pTable->vgLen; ++vg) { + int32_t vgId = pTable->vgList[vg]; + if (vgId == 0) break; + + SVgObj *pVgroup = mgmtGetVgroup(vgId); + if (pVgroup == NULL) break; + + pRsp->vgroups[vg].vgId = htonl(vgId); + for (int32_t vn = 0; vn < pVgroup->numOfVnodes; ++vn) { + SDnodeObj *pDnode = clusterGetDnode(pVgroup->vnodeGid[vn].dnodeId); + if (pDnode == NULL) break; + + pRsp->vgroups[vg].ipAddr[vn].ip = htonl(pDnode->privateIp); + pRsp->vgroups[vg].ipAddr[vn].port = htons(tsDnodeShellPort); + + clusterReleaseDnode(pDnode); + } + + mgmtReleaseVgroup(pVgroup); } - - assert(numOfDnodes == 1); // this size is valid only when numOfDnodes equals 1 - int32_t msgLen = sizeof(SCMSTableVgroupRspMsg) + sizeof(STableDnodeVgroupInfo) + numOfVgroups * sizeof(int32_t); - + pRsp->numOfVgroups = htonl(vg); + SRpcMsg rpcRsp = {0}; rpcRsp.handle = pMsg->thandle; rpcRsp.pCont = pRsp; - rpcRsp.contLen = msgLen; + rpcRsp.contLen = sizeof(SCMSTableVgroupRspMsg) + sizeof(SCMVgroupInfo) * vg; rpcSendResponse(&rpcRsp); } -- GitLab