From 327cfce68c399357515a06aff2c9d117d8bc3aec Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Sat, 20 Jun 2020 12:03:41 +0800 Subject: [PATCH 1/2] [td-225] fix bugs in insert. --- src/client/src/tscSubquery.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/client/src/tscSubquery.c b/src/client/src/tscSubquery.c index 5faa515d40..03c3c77459 100644 --- a/src/client/src/tscSubquery.c +++ b/src/client/src/tscSubquery.c @@ -1901,7 +1901,6 @@ int32_t tscHandleMultivnodeInsert(SSqlObj *pSql) { tscTrace("%p submit data to %d vnode(s)", pSql, pDataBlocks->nSize); SSubqueryState *pState = calloc(1, sizeof(SSubqueryState)); pState->numOfTotal = pSql->numOfSubs; - pState->numOfRemain = pSql->numOfSubs; pRes->code = TSDB_CODE_SUCCESS; @@ -1928,7 +1927,7 @@ int32_t tscHandleMultivnodeInsert(SSqlObj *pSql) { pSupporter1->pSql = pSql; pSupporter1->pState = pState; - SSqlObj *pNew = createSubqueryObj(pSql, 0, multiVnodeInsertFinalize, pSupporter, TSDB_SQL_INSERT, NULL); + SSqlObj *pNew = createSubqueryObj(pSql, 0, multiVnodeInsertFinalize, pSupporter1, TSDB_SQL_INSERT, NULL); if (pNew == NULL) { tscError("%p failed to malloc buffer for subObj, orderOfSub:%d, reason:%s", pSql, i, strerror(errno)); goto _error; From 550028db61d3b91280cc0ace0f9a6594357af09f Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Sat, 20 Jun 2020 12:32:43 +0800 Subject: [PATCH 2/2] [td-225] fix compiler error --- src/client/src/tscSubquery.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/client/src/tscSubquery.c b/src/client/src/tscSubquery.c index 03c3c77459..6c6284b4a6 100644 --- a/src/client/src/tscSubquery.c +++ b/src/client/src/tscSubquery.c @@ -1914,6 +1914,7 @@ int32_t tscHandleMultivnodeInsert(SSqlObj *pSql) { pSql->pSubs[0] = pSql; // the first sub insert points back to itself tscTrace("%p sub:%p create subObj success. orderOfSub:%d", pSql, pSql, 0); + int32_t numOfSub = 1; int32_t code = tscCopyDataBlockToPayload(pSql, pDataBlocks->pData[0]); if (code != TSDB_CODE_SUCCESS) { tscTrace("%p prepare submit data block failed in async insertion, vnodeIdx:%d, total:%d, code:%d", pSql, 0, @@ -1921,15 +1922,14 @@ int32_t tscHandleMultivnodeInsert(SSqlObj *pSql) { goto _error; } - int32_t i = 1; - for (; i < pSql->numOfSubs; ++i) { + for (; numOfSub < pSql->numOfSubs; ++numOfSub) { SInsertSupporter* pSupporter1 = calloc(1, sizeof(SInsertSupporter)); pSupporter1->pSql = pSql; pSupporter1->pState = pState; SSqlObj *pNew = createSubqueryObj(pSql, 0, multiVnodeInsertFinalize, pSupporter1, TSDB_SQL_INSERT, NULL); if (pNew == NULL) { - tscError("%p failed to malloc buffer for subObj, orderOfSub:%d, reason:%s", pSql, i, strerror(errno)); + tscError("%p failed to malloc buffer for subObj, orderOfSub:%d, reason:%s", pSql, numOfSub, strerror(errno)); goto _error; } @@ -1938,26 +1938,25 @@ int32_t tscHandleMultivnodeInsert(SSqlObj *pSql) { * the callback function (multiVnodeInsertFinalize) correctly. */ pNew->fetchFp = pNew->fp; - pSql->pSubs[i] = pNew; + pSql->pSubs[numOfSub] = pNew; - code = tscCopyDataBlockToPayload(pNew, pDataBlocks->pData[i]); + code = tscCopyDataBlockToPayload(pNew, pDataBlocks->pData[numOfSub]); if (code != TSDB_CODE_SUCCESS) { - tscTrace("%p prepare submit data block failed in async insertion, vnodeIdx:%d, total:%d, code:%d", pSql, i, + tscTrace("%p prepare submit data block failed in async insertion, vnodeIdx:%d, total:%d, code:%d", pSql, numOfSub, pDataBlocks->nSize, code); goto _error; } else { - tscTrace("%p sub:%p create subObj success. orderOfSub:%d", pSql, pNew, i); + tscTrace("%p sub:%p create subObj success. orderOfSub:%d", pSql, pNew, numOfSub); } } - if (i < pSql->numOfSubs) { + if (numOfSub < pSql->numOfSubs) { tscError("%p failed to prepare subObj structure and launch sub-insertion", pSql); pRes->code = TSDB_CODE_TSC_OUT_OF_MEMORY; return pRes->code; // free all allocated resource } // use the local variable - int32_t numOfSub = pSql->numOfSubs; for (int32_t j = 0; j < numOfSub; ++j) { SSqlObj *pSub = pSql->pSubs[j]; tscTrace("%p sub:%p launch sub insert, orderOfSub:%d", pSql, pSub, j); @@ -1969,11 +1968,12 @@ int32_t tscHandleMultivnodeInsert(SSqlObj *pSql) { _error: // restore the udf fp pSql->fp = pSql->fetchFp; + pSql->pSubs[0] = NULL; tfree(pState); tfree(pSql->param); - for(int32_t j = 1; j < i; ++j) { + for(int32_t j = 1; j < numOfSub; ++j) { tfree(pSql->pSubs[j]->param); taos_free_result(pSql->pSubs[j]); }