From 66de5c58c9497581a02a1e54a0278856aaf10eac Mon Sep 17 00:00:00 2001 From: slguan Date: Thu, 26 Mar 2020 10:09:19 +0800 Subject: [PATCH] [TD-9] fix crash while create table --- src/client/src/tscServer.c | 2 +- src/inc/taosmsg.h | 4 ++-- src/mnode/inc/mgmtDb.h | 13 +++++++------ src/mnode/inc/mgmtMnode.h | 12 ++++++------ src/mnode/inc/mgmtProfile.h | 8 ++++---- src/mnode/inc/mgmtSdb.h | 10 +++++----- src/mnode/inc/mgmtShell.h | 4 ++-- src/mnode/inc/mgmtVgroup.h | 2 -- src/mnode/src/mgmtChildTable.c | 2 +- src/mnode/src/mgmtDb.c | 1 - src/mnode/src/mgmtUser.c | 16 +++++++++------- src/mnode/src/mgmtVgroup.c | 23 ++++++++++------------- src/rpc/src/rpcMain.c | 2 +- 13 files changed, 48 insertions(+), 51 deletions(-) diff --git a/src/client/src/tscServer.c b/src/client/src/tscServer.c index 348c0709f1..7856856606 100644 --- a/src/client/src/tscServer.c +++ b/src/client/src/tscServer.c @@ -1752,7 +1752,7 @@ int tscBuildMetricMetaMsg(SSqlObj *pSql, SSqlInfo *pInfo) { msgLen = pMsg - pStart; pCmd->payloadLen = msgLen; - pCmd->msgType = TSDB_MSG_TYPE_CM_STABLE_META; + pCmd->msgType = TSDB_MSG_TYPE_CM_STABLE_VGROUP; assert(msgLen + minMsgSize() <= size); return TSDB_CODE_SUCCESS; diff --git a/src/inc/taosmsg.h b/src/inc/taosmsg.h index f1e07c98a8..49e498d22f 100644 --- a/src/inc/taosmsg.h +++ b/src/inc/taosmsg.h @@ -738,8 +738,8 @@ typedef struct { } SDMConfigTableMsg; typedef struct { - uint32_t dnode; - int32_t vnode; + uint32_t dnodeId; + int32_t vgId; } SDMConfigVnodeMsg; typedef struct { diff --git a/src/mnode/inc/mgmtDb.h b/src/mnode/inc/mgmtDb.h index f2049f836c..27918b9cf9 100644 --- a/src/mnode/inc/mgmtDb.h +++ b/src/mnode/inc/mgmtDb.h @@ -22,22 +22,23 @@ extern "C" { #include "mnode.h" -void mgmtAddVgroupIntoDb(SVgObj *pVgroup); -void mgmtAddVgroupIntoDbTail(SVgObj *pVgroup); -void mgmtRemoveVgroupFromDb(SVgObj *pVgroup); -void mgmtMoveVgroupToTail(SVgObj *pVgroup); -void mgmtMoveVgroupToHead(SVgObj *pVgroup); - +// api int32_t mgmtInitDbs(); void mgmtCleanUpDbs(); SDbObj *mgmtGetDb(char *db); SDbObj *mgmtGetDbByTableId(char *db); bool mgmtCheckIsMonitorDB(char *db, char *monitordb); +// util func void mgmtAddSuperTableIntoDb(SDbObj *pDb); void mgmtRemoveSuperTableFromDb(SDbObj *pDb); void mgmtAddTableIntoDb(SDbObj *pDb); void mgmtRemoveTableFromDb(SDbObj *pDb); +void mgmtAddVgroupIntoDb(SVgObj *pVgroup); +void mgmtAddVgroupIntoDbTail(SVgObj *pVgroup); +void mgmtRemoveVgroupFromDb(SVgObj *pVgroup); +void mgmtMoveVgroupToTail(SVgObj *pVgroup); +void mgmtMoveVgroupToHead(SVgObj *pVgroup); #ifdef __cplusplus } diff --git a/src/mnode/inc/mgmtMnode.h b/src/mnode/inc/mgmtMnode.h index 729d31544f..8cfe3c7e23 100644 --- a/src/mnode/inc/mgmtMnode.h +++ b/src/mnode/inc/mgmtMnode.h @@ -21,14 +21,14 @@ extern "C" { #endif int32_t mgmtInitMnodes(); -void mgmtCleanupMnodes(); +void mgmtCleanupMnodes(); -bool mgmtInServerStatus(); -bool mgmtIsMaster(); +bool mgmtInServerStatus(); +bool mgmtIsMaster(); -bool mgmtCheckRedirect(void *handle); -void mgmtGetMnodePrivateIpList(SRpcIpSet *ipSet); -void mgmtGetMnodePublicIpList(SRpcIpSet *ipSet); +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); diff --git a/src/mnode/inc/mgmtProfile.h b/src/mnode/inc/mgmtProfile.h index 8c2e073c2d..a40f572f8b 100644 --- a/src/mnode/inc/mgmtProfile.h +++ b/src/mnode/inc/mgmtProfile.h @@ -24,11 +24,11 @@ extern "C" { int32_t mgmtInitProfile(); void mgmtCleanUpProfile(); -bool mgmtCheckQhandle(uint64_t qhandle); -void mgmtSaveQhandle(void *qhandle); -void mgmtFreeQhandle(void *qhandle); +bool mgmtCheckQhandle(uint64_t qhandle); +void mgmtSaveQhandle(void *qhandle); +void mgmtFreeQhandle(void *qhandle); -void mgmtFreeQueuedMsg(SQueuedMsg *pMsg); +void mgmtFreeQueuedMsg(SQueuedMsg *pMsg); #ifdef __cplusplus } diff --git a/src/mnode/inc/mgmtSdb.h b/src/mnode/inc/mgmtSdb.h index ccddc11e04..f291e93418 100644 --- a/src/mnode/inc/mgmtSdb.h +++ b/src/mnode/inc/mgmtSdb.h @@ -53,16 +53,16 @@ typedef struct { int32_t (*destroyFp)(SSdbOperDesc *pDesc); } SSdbTableDesc; -void *sdbOpenTable(SSdbTableDesc *desc); -void sdbCloseTable(void *handle); +void * sdbOpenTable(SSdbTableDesc *desc); +void sdbCloseTable(void *handle); int32_t sdbInsertRow(SSdbOperDesc *pOper); int32_t sdbDeleteRow(SSdbOperDesc *pOper); int32_t sdbUpdateRow(SSdbOperDesc *pOper); -void *sdbGetRow(void *handle, void *key); -void *sdbFetchRow(void *handle, void *pNode, void **ppRow); -int64_t sdbGetNumOfRows(void *handle); +void *sdbGetRow(void *handle, void *key); +void *sdbFetchRow(void *handle, void *pNode, void **ppRow); +int64_t sdbGetNumOfRows(void *handle); uint64_t sdbGetVersion(); #ifdef __cplusplus diff --git a/src/mnode/inc/mgmtShell.h b/src/mnode/inc/mgmtShell.h index 56625b982a..b92e9de1f4 100644 --- a/src/mnode/inc/mgmtShell.h +++ b/src/mnode/inc/mgmtShell.h @@ -22,8 +22,8 @@ extern "C" { #include "mnode.h" int32_t mgmtInitShell(); -void mgmtCleanUpShell(); -void mgmtAddShellMsgHandle(uint8_t msgType, void (*fp)(SQueuedMsg *queuedMsg)); +void mgmtCleanUpShell(); +void mgmtAddShellMsgHandle(uint8_t msgType, void (*fp)(SQueuedMsg *queuedMsg)); typedef int32_t (*SShowMetaFp)(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn); typedef int32_t (*SShowRetrieveFp)(SShowObj *pShow, char *data, int32_t rows, void *pConn); diff --git a/src/mnode/inc/mgmtVgroup.h b/src/mnode/inc/mgmtVgroup.h index aba95fb478..de0648da44 100644 --- a/src/mnode/inc/mgmtVgroup.h +++ b/src/mnode/inc/mgmtVgroup.h @@ -27,12 +27,10 @@ extern "C" { int32_t mgmtInitVgroups(); void mgmtCleanUpVgroups(); SVgObj *mgmtGetVgroup(int32_t vgId); -SVgObj *mgmtGetVgroupByVnode(uint32_t dnode, int32_t vnode); void mgmtDropAllVgroups(SDbObj *pDropDb); void mgmtCreateVgroup(SQueuedMsg *pMsg); void mgmtDropVgroup(SVgObj *pVgroup, void *ahandle); -void mgmtUpdateVgroup(SVgObj *pVgroup); void mgmtAlterVgroup(SVgObj *pVgroup, void *ahandle); SVgObj *mgmtGetAvailableVgroup(SDbObj *pDb); diff --git a/src/mnode/src/mgmtChildTable.c b/src/mnode/src/mgmtChildTable.c index a2605cefd5..2d4f37581d 100644 --- a/src/mnode/src/mgmtChildTable.c +++ b/src/mnode/src/mgmtChildTable.c @@ -332,7 +332,6 @@ static void *mgmtBuildCreateChildTableMsg(SCMCreateTableMsg *pMsg, SChildTableOb } memcpy(pCreate->tableId, pTable->info.tableId, TSDB_TABLE_ID_LEN + 1); - memcpy(pCreate->superTableId, pTable->superTable->info.tableId, TSDB_TABLE_ID_LEN + 1); pCreate->contLen = htonl(contLen); pCreate->vgId = htonl(pTable->vgId); pCreate->tableType = pTable->info.type; @@ -342,6 +341,7 @@ static void *mgmtBuildCreateChildTableMsg(SCMCreateTableMsg *pMsg, SChildTableOb pCreate->uid = htobe64(pTable->uid); if (pTable->info.type == TSDB_CHILD_TABLE) { + memcpy(pCreate->superTableId, pTable->superTable->info.tableId, TSDB_TABLE_ID_LEN + 1); pCreate->numOfColumns = htons(pTable->superTable->numOfColumns); pCreate->numOfTags = htons(pTable->superTable->numOfTags); pCreate->sversion = htonl(pTable->superTable->sversion); diff --git a/src/mnode/src/mgmtDb.c b/src/mnode/src/mgmtDb.c index 16f9751e20..8c8173f781 100644 --- a/src/mnode/src/mgmtDb.c +++ b/src/mnode/src/mgmtDb.c @@ -41,7 +41,6 @@ static int32_t tsDbUpdateSize; static int32_t mgmtCreateDb(SAcctObj *pAcct, SCMCreateDbMsg *pCreate); static void mgmtDropDb(void *handle, void *tmrId); static int32_t mgmtSetDbDirty(SDbObj *pDb); - static int32_t mgmtGetDbMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn); static int32_t mgmtRetrieveDbs(SShowObj *pShow, char *data, int32_t rows, void *pConn); static void mgmtProcessCreateDbMsg(SQueuedMsg *pMsg); diff --git a/src/mnode/src/mgmtUser.c b/src/mnode/src/mgmtUser.c index c69035c304..dc2418efd9 100644 --- a/src/mnode/src/mgmtUser.c +++ b/src/mnode/src/mgmtUser.c @@ -25,14 +25,14 @@ #include "mgmtShell.h" #include "mgmtUser.h" -void *tsUserSdb = NULL; +static void *tsUserSdb = NULL; static int32_t tsUserUpdateSize = 0; -static int32_t mgmtCreateUser(SAcctObj *pAcct, char *name, char *pass); -static int32_t mgmtDropUser(SAcctObj *pAcct, char *name); -static int32_t mgmtUpdateUser(SUserObj *pUser); -static int32_t mgmtGetUserMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn); -static int32_t mgmtRetrieveUsers(SShowObj *pShow, char *data, int32_t rows, void *pConn); +static int32_t mgmtCreateUser(SAcctObj *pAcct, char *name, char *pass); +static int32_t mgmtDropUser(SAcctObj *pAcct, char *name); +static int32_t mgmtUpdateUser(SUserObj *pUser); +static int32_t mgmtGetUserMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn); +static int32_t mgmtRetrieveUsers(SShowObj *pShow, char *data, int32_t rows, void *pConn); static void mgmtProcessCreateUserMsg(SQueuedMsg *pMsg); static void mgmtProcessAlterUserMsg(SQueuedMsg *pMsg); @@ -313,7 +313,9 @@ static int32_t mgmtRetrieveUsers(SShowObj *pShow, char *data, int32_t rows, void SUserObj *mgmtGetUserFromConn(void *pConn, bool *usePublicIp) { SRpcConnInfo connInfo; if (rpcGetConnInfo(pConn, &connInfo) == 0) { - *usePublicIp = (connInfo.serverIp == tsPublicIpInt); + if (usePublicIp) { + *usePublicIp = (connInfo.serverIp == tsPublicIpInt); + } return mgmtGetUser(connInfo.user); } diff --git a/src/mnode/src/mgmtVgroup.c b/src/mnode/src/mgmtVgroup.c index deb1da0025..a8e7219e2e 100644 --- a/src/mnode/src/mgmtVgroup.c +++ b/src/mnode/src/mgmtVgroup.c @@ -67,8 +67,8 @@ static int32_t mgmtVgroupActionInsert(SSdbOperDesc *pOper) { pVgroup->prev = NULL; pVgroup->next = NULL; - int32_t size = sizeof(STableInfo *) * pDb->cfg.maxSessions; - pVgroup->tableList = (STableInfo **)calloc(pDb->cfg.maxSessions, sizeof(STableInfo *)); + int32_t size = sizeof(SChildTableObj *) * pDb->cfg.maxSessions; + pVgroup->tableList = calloc(pDb->cfg.maxSessions, sizeof(SChildTableObj *)); if (pVgroup->tableList == NULL) { mError("vgroup:%d, failed to malloc(size:%d) for the tableList of vgroups", pVgroup->vgId, size); return -1; @@ -112,8 +112,8 @@ static int32_t mgmtVgroupActionUpdate(SSdbOperDesc *pOper) { if (pDb->cfg.maxSessions != oldTables) { mPrint("vgroup:%d tables change from %d to %d", pVgroup->vgId, oldTables, pDb->cfg.maxSessions); taosUpdateIdPool(pVgroup->idPool, pDb->cfg.maxSessions); - int32_t size = sizeof(STableInfo *) * pDb->cfg.maxSessions; - pVgroup->tableList = (STableInfo **)realloc(pVgroup->tableList, size); + int32_t size = sizeof(SChildTableObj *) * pDb->cfg.maxSessions; + pVgroup->tableList = (SChildTableObj **)realloc(pVgroup->tableList, size); } } @@ -483,17 +483,14 @@ SMDCreateVnodeMsg *mgmtBuildCreateVnodeMsg(SVgObj *pVgroup) { return pVnode; } -SVgObj *mgmtGetVgroupByVnode(uint32_t dnode, int32_t vnode) { - if (vnode < 0 || vnode >= TSDB_MAX_VNODES) { - return NULL; - } +static SVgObj *mgmtGetVgroupInDnode(uint32_t dnodeId, int32_t vgId) { + if (vnovgId < 1 || dnodeId < 1) return NULL; - SDnodeObj *pDnode = mgmtGetDnode(dnode); + SDnodeObj *pDnode = mgmtGetDnode(dnodeId); if (pDnode == NULL) { return NULL; } - int32_t vgId = pDnode->vload[vnode].vgId; return mgmtGetVgroup(vgId); } @@ -660,10 +657,10 @@ static void mgmtProcessVnodeCfgMsg(SRpcMsg *rpcMsg) { if (mgmtCheckRedirect(rpcMsg->handle)) return; SDMConfigVnodeMsg *pCfg = (SDMConfigVnodeMsg *) rpcMsg->pCont; - pCfg->dnode = htonl(pCfg->dnode); - pCfg->vnode = htonl(pCfg->vnode); + pCfg->dnodeId = htonl(pCfg->dnode); + pCfg->vgId = htonl(pCfg->vnode); - SVgObj *pVgroup = mgmtGetVgroupByVnode(pCfg->dnode, pCfg->vnode); + SVgObj *pVgroup = mgmtGetVgroupInDnode(pCfg->dnodeId, pCfg->vgId); if (pVgroup == NULL) { mTrace("dnode:%s, vnode:%d, no vgroup info", taosIpStr(pCfg->dnode), pCfg->vnode); mgmtSendSimpleResp(rpcMsg->handle, TSDB_CODE_NOT_ACTIVE_VNODE); diff --git a/src/rpc/src/rpcMain.c b/src/rpc/src/rpcMain.c index c6f527a7d2..93334333ef 100755 --- a/src/rpc/src/rpcMain.c +++ b/src/rpc/src/rpcMain.c @@ -360,7 +360,7 @@ void rpcSendRequest(void *shandle, SRpcIpSet *pIpSet, SRpcMsg *pMsg) { // for TDengine, all the query, show commands shall have TCP connection char type = pMsg->msgType; if (type == TSDB_MSG_TYPE_QUERY || type == TSDB_MSG_TYPE_RETRIEVE || - type == TSDB_MSG_TYPE_CM_STABLE_META || type == TSDB_MSG_TYPE_CM_TABLES_META || + type == TSDB_MSG_TYPE_CM_STABLE_VGROUP || type == TSDB_MSG_TYPE_CM_TABLES_META || type == TSDB_MSG_TYPE_CM_SHOW ) pContext->connType = RPC_CONN_TCPC; -- GitLab