From 116a5b04a2141b412d1e4cb48ba7981f3e1785cb Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Fri, 29 May 2020 10:32:20 +0000 Subject: [PATCH] add config table message --- src/dnode/src/dnodeShell.c | 38 +++++++++++++++++++++++++++++++++++++ src/inc/dnode.h | 7 ++++--- src/inc/taosmsg.h | 6 +++--- src/mnode/src/mnodeTable.c | 39 +++++++++++++------------------------- 4 files changed, 58 insertions(+), 32 deletions(-) diff --git a/src/dnode/src/dnodeShell.c b/src/dnode/src/dnodeShell.c index b875f465c2..1d1e41bb38 100644 --- a/src/dnode/src/dnodeShell.c +++ b/src/dnode/src/dnodeShell.c @@ -168,6 +168,44 @@ static int dnodeRetrieveUserAuthInfo(char *user, char *spi, char *encrypt, char return rpcRsp.code; } +void *dnodeSendCfgTableToRecv(int32_t vgId, int32_t sid) { + dTrace("vgId:%d, sid:%d send config table msg to mnode", vgId, sid); + + int32_t contLen = sizeof(SDMConfigTableMsg); + SDMConfigTableMsg *pMsg = rpcMallocCont(contLen); + + pMsg->dnodeId = htonl(dnodeGetDnodeId()); + pMsg->vgId = htonl(vgId); + pMsg->sid = htonl(sid); + + SRpcMsg rpcMsg = {0}; + rpcMsg.pCont = pMsg; + rpcMsg.contLen = contLen; + rpcMsg.msgType = TSDB_MSG_TYPE_DM_CONFIG_TABLE; + + SRpcMsg rpcRsp = {0}; + dnodeSendMsgToDnodeRecv(&rpcMsg, &rpcRsp); + terrno = rpcRsp.code; + + if (rpcRsp.code != 0) { + rpcFreeCont(rpcRsp.pCont); + dError("vgId:%d, sid:%d failed to config table from mnode", vgId, sid); + return NULL; + } else { + dPrint("vgId:%d, sid:%d config table msg is received", vgId, sid); + + // delete this after debug finished + SMDCreateTableMsg *pTable = rpcRsp.pCont; + int16_t numOfColumns = htons(pTable->numOfColumns); + int16_t numOfTags = htons(pTable->numOfTags); + int32_t sid = htonl(pTable->sid); + uint64_t uid = htobe64(pTable->uid); + dPrint("table:%s, numOfColumns:%d numOfTags:%d sid:%d uid:%d", pTable->tableId, numOfColumns, numOfTags, sid, uid); + + return rpcRsp.pCont; + } +} + SDnodeStatisInfo dnodeGetStatisInfo() { SDnodeStatisInfo info = {0}; if (dnodeGetRunStatus() == TSDB_DNODE_RUN_STATUS_RUNING) { diff --git a/src/inc/dnode.h b/src/inc/dnode.h index 3d3616085d..b561c407a3 100644 --- a/src/inc/dnode.h +++ b/src/inc/dnode.h @@ -44,9 +44,10 @@ void dnodeGetMnodeIpSetForShell(void *ipSet); void * dnodeGetMnodeInfos(); int32_t dnodeGetDnodeId(); -void dnodeAddClientRspHandle(uint8_t msgType, void (*fp)(SRpcMsg *rpcMsg)); -void dnodeSendMsgToDnode(SRpcIpSet *ipSet, SRpcMsg *rpcMsg); -void dnodeSendMsgToDnodeRecv(SRpcMsg *rpcMsg, SRpcMsg *rpcRsp); +void dnodeAddClientRspHandle(uint8_t msgType, void (*fp)(SRpcMsg *rpcMsg)); +void dnodeSendMsgToDnode(SRpcIpSet *ipSet, SRpcMsg *rpcMsg); +void dnodeSendMsgToDnodeRecv(SRpcMsg *rpcMsg, SRpcMsg *rpcRsp); +void *dnodeSendCfgTableToRecv(int32_t vgId, int32_t sid); void *dnodeAllocateVnodeWqueue(void *pVnode); void dnodeFreeVnodeWqueue(void *queue); diff --git a/src/inc/taosmsg.h b/src/inc/taosmsg.h index 17b975c193..ba95560f7d 100644 --- a/src/inc/taosmsg.h +++ b/src/inc/taosmsg.h @@ -676,9 +676,9 @@ typedef struct { } SCMCreateDnodeMsg, SCMDropDnodeMsg; typedef struct { - uint32_t dnode; - int32_t vnode; - int32_t sid; + int32_t dnodeId; + int32_t vgId; + int32_t sid; } SDMConfigTableMsg; typedef struct { diff --git a/src/mnode/src/mnodeTable.c b/src/mnode/src/mnodeTable.c index 92ab990da4..07520fbb2b 100644 --- a/src/mnode/src/mnodeTable.c +++ b/src/mnode/src/mnodeTable.c @@ -1877,38 +1877,25 @@ static SChildTableObj* mnodeGetTableByPos(int32_t vnode, int32_t sid) { static int32_t mnodeProcessTableCfgMsg(SMnodeMsg *pMsg) { SDMConfigTableMsg *pCfg = pMsg->rpcMsg.pCont; - pCfg->dnode = htonl(pCfg->dnode); - pCfg->vnode = htonl(pCfg->vnode); - pCfg->sid = htonl(pCfg->sid); - mTrace("dnode:%s, vnode:%d, sid:%d, receive table config msg", taosIpStr(pCfg->dnode), pCfg->vnode, pCfg->sid); + pCfg->dnodeId = htonl(pCfg->dnodeId); + pCfg->vgId = htonl(pCfg->vgId); + pCfg->sid = htonl(pCfg->sid); + mTrace("dnode:%d, vgId:%d sid:%d, receive table config msg", pCfg->dnodeId, pCfg->vgId, pCfg->sid); - SChildTableObj *pTable = mnodeGetTableByPos(pCfg->vnode, pCfg->sid); + SChildTableObj *pTable = mnodeGetTableByPos(pCfg->vgId, pCfg->sid); if (pTable == NULL) { - mError("dnode:%s, vnode:%d, sid:%d, table not found", taosIpStr(pCfg->dnode), pCfg->vnode, pCfg->sid); + mError("dnode:%d, vgId:%d sid:%d, table not found", pCfg->dnodeId, pCfg->vgId, pCfg->sid); return TSDB_CODE_NOT_ACTIVE_TABLE; } - SMDCreateTableMsg *pMDCreate = NULL; - pMDCreate = mnodeBuildCreateChildTableMsg(NULL, (SChildTableObj *)pTable); - if (pMDCreate == NULL) { - mnodeDecTableRef(pTable); - return terrno; - } - - SDnodeObj *pDnode = mnodeGetDnode(pCfg->dnode); - SRpcIpSet ipSet = mnodeGetIpSetFromIp(pDnode->dnodeEp); - SRpcMsg rpcRsp = { - .handle = NULL, - .pCont = pMDCreate, - .contLen = htonl(pMDCreate->contLen), - .code = 0, - .msgType = TSDB_MSG_TYPE_MD_CREATE_TABLE - }; - dnodeSendMsgToDnode(&ipSet, &rpcRsp); - + SMDCreateTableMsg *pCreate = NULL; + pCreate = mnodeBuildCreateChildTableMsg(NULL, (SChildTableObj *)pTable); mnodeDecTableRef(pTable); - mnodeDecDnodeRef(pDnode); - + + if (pCreate == NULL) return terrno; + + pMsg->rpcRsp.rsp = pCreate; + pMsg->rpcRsp.len = htonl(pCreate->contLen); return TSDB_CODE_SUCCESS; } -- GitLab