From c0643c94b79df7c81660fa182af32985fd233b42 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Tue, 23 Jun 2020 22:16:59 +0800 Subject: [PATCH] [TD-705] invalid read while create table --- src/mnode/src/mnodeTable.c | 47 +++++++++++++++++++++++++------------- 1 file changed, 31 insertions(+), 16 deletions(-) diff --git a/src/mnode/src/mnodeTable.c b/src/mnode/src/mnodeTable.c index 565ce9910e..346c33f80d 100644 --- a/src/mnode/src/mnodeTable.c +++ b/src/mnode/src/mnodeTable.c @@ -780,6 +780,16 @@ static int32_t mnodeProcessTableMetaMsg(SMnodeMsg *pMsg) { } } +static int32_t mnodeCreateSuperTableCb(SMnodeMsg *pMsg, int32_t code) { + SSuperTableObj *pTable = (SSuperTableObj *)pMsg->pTable; + if (pTable != NULL) { + mLPrint("app:%p:%p, stable:%s, create result:%s", pMsg->rpcMsg.ahandle, pMsg, pTable->info.tableId, + tstrerror(code)); + } + + return code; +} + static int32_t mnodeProcessCreateSuperTableMsg(SMnodeMsg *pMsg) { if (pMsg == NULL) return TSDB_CODE_MND_APP_ERROR; @@ -819,25 +829,27 @@ static int32_t mnodeProcessCreateSuperTableMsg(SMnodeMsg *pMsg) { assert(tschema[col].type >= TSDB_DATA_TYPE_BOOL && tschema[col].type <= TSDB_DATA_TYPE_NCHAR); } + pMsg->pTable = (STableObj *)pStable; + mnodeIncTableRef(pMsg->pTable); + SSdbOper oper = { .type = SDB_OPER_GLOBAL, .table = tsSuperTableSdb, .pObj = pStable, .rowSize = sizeof(SSuperTableObj) + schemaSize, - .pMsg = pMsg + .pMsg = pMsg, + .cb = mnodeCreateSuperTableCb }; int32_t code = sdbInsertRow(&oper); if (code != TSDB_CODE_SUCCESS) { mnodeDestroySuperTable(pStable); + pMsg->pTable = NULL; mError("app:%p:%p, table:%s, failed to create, sdb error", pMsg->rpcMsg.ahandle, pMsg, pCreate->tableId); + return code; } else { - mLPrint("app:%p:%p, table:%s, is created, tags:%d fields:%d", pMsg->rpcMsg.ahandle, pMsg, pStable->info.tableId, - pStable->numOfTags, pStable->numOfColumns); - code = TSDB_CODE_MND_ACTION_IN_PROGRESS; + return TSDB_CODE_MND_ACTION_IN_PROGRESS; } - - return code; } static int32_t mnodeProcessDropSuperTableMsg(SMnodeMsg *pMsg) { @@ -1535,10 +1547,16 @@ static void *mnodeBuildCreateChildTableMsg(SCMCreateTableMsg *pMsg, SChildTableO } static int32_t mnodeDoCreateChildTableCb(SMnodeMsg *pMsg, int32_t code) { + SChildTableObj *pTable = (SChildTableObj *)pMsg->pTable; + if (pTable != NULL) { + mTrace("app:%p:%p, table:%s, create table in id:%d, uid:%" PRIu64 ", result:%s", pMsg->rpcMsg.ahandle, pMsg, + pTable->info.tableId, pTable->sid, pTable->uid, tstrerror(code)); + } + if (code != TSDB_CODE_SUCCESS) return code; - + SCMCreateTableMsg *pCreate = pMsg->rpcMsg.pCont; - SMDCreateTableMsg *pMDCreate = mnodeBuildCreateChildTableMsg(pCreate, (SChildTableObj *)pMsg->pTable); + SMDCreateTableMsg *pMDCreate = mnodeBuildCreateChildTableMsg(pCreate, pTable); if (pMDCreate == NULL) { return terrno; } @@ -1639,16 +1657,13 @@ static int32_t mnodeDoCreateChildTable(SMnodeMsg *pMsg, int32_t tid) { int32_t code = sdbInsertRow(&desc); if (code != TSDB_CODE_SUCCESS) { - free(pTable); + mnodeDestroyChildTable(pTable); + pMsg->pTable = NULL; mError("app:%p:%p, table:%s, update sdb error, reason:%s", pMsg->rpcMsg.ahandle, pMsg, pCreate->tableId, tstrerror(code)); - pMsg->pTable = NULL; - return code; - } else { - mTrace("app:%p:%p, table:%s, create table in vgroup:%d, id:%d, uid:%" PRIu64, pMsg->rpcMsg.ahandle, pMsg, - pTable->info.tableId, pVgroup->vgId, pTable->sid, pTable->uid); - return TSDB_CODE_SUCCESS; - } + } + + return code; } static int32_t mnodeProcessCreateChildTableMsg(SMnodeMsg *pMsg) { -- GitLab