From 5d87d141eb40bb2bb9e2a1c585ae70179a8e9f68 Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Wed, 24 Jun 2020 17:43:41 +0800 Subject: [PATCH 1/6] [td-719] --- src/client/src/tscParseInsert.c | 190 +++++++++++++++++++++----------- 1 file changed, 126 insertions(+), 64 deletions(-) diff --git a/src/client/src/tscParseInsert.c b/src/client/src/tscParseInsert.c index f2af4f1d32..34741e2ed3 100644 --- a/src/client/src/tscParseInsert.c +++ b/src/client/src/tscParseInsert.c @@ -1377,24 +1377,114 @@ static int doPackSendDataBlock(SSqlObj *pSql, int32_t numOfRows, STableDataBlock return code; } - if ((code = tscProcessSql(pSql)) != TSDB_CODE_SUCCESS) { - return code; - } - - return TSDB_CODE_SUCCESS; + return tscProcessSql(pSql); } -static int tscInsertDataFromFile(SSqlObj *pSql, FILE *fp, char *tmpTokenBuf) { +typedef struct SImportFileSupport { + SSqlObj *pSql; + FILE *fp; +} SImportFileSupport; + +static void parseFileSendDataBlock(void *param, TAOS_RES *tres, int code) { + assert(param != NULL && tres != NULL); + + SSqlObj *pSql = tres; + SSqlCmd *pCmd = &pSql->cmd; + + SImportFileSupport *pSupporter = (SImportFileSupport *) param; + + SSqlObj *pParentSql = pSupporter->pSql; + FILE *fp = pSupporter->fp; + + if (taos_errno(pSql) != TSDB_CODE_SUCCESS) { // handle error + assert(taos_errno(pSql) == code); + + taos_free_result(pSql); + tfree(pSupporter); + fclose(fp); + + pParentSql->res.code = code; + return; + } + + // accumulate the total submit records + pParentSql->res.numOfRows += pSql->res.numOfRows; + + STableMetaInfo *pTableMetaInfo = tscGetTableMetaInfoFromCmd(pCmd, pCmd->clauseIndex, 0); + STableMeta * pTableMeta = pTableMetaInfo->pTableMeta; + SSchema * pSchema = tscGetTableSchema(pTableMeta); + STableComInfo tinfo = tscGetTableInfo(pTableMeta); + + SParsedDataColInfo spd = {.numOfCols = tinfo.numOfColumns}; + tscSetAssignedColumnInfo(&spd, pSchema, tinfo.numOfColumns); + + size_t n = 0; + ssize_t readLen = 0; + char * line = NULL; + int32_t count = 0; + int32_t maxRows = 0; + + STableDataBlocks *pTableDataBlock = taosArrayGetP(pSql->cmd.pDataBlocks, 0); + pTableDataBlock->size = pTableDataBlock->headerSize; + + tscAllocateMemIfNeed(pTableDataBlock, tinfo.rowSize, &maxRows); + char *tokenBuf = calloc(1, 4096); + + while ((readLen = getline(&line, &n, fp)) != -1) { + if (('\r' == line[readLen - 1]) || ('\n' == line[readLen - 1])) { + line[--readLen] = 0; + } + + if (readLen == 0) { + continue; + } + + char *lineptr = line; + strtolower(line, line); + + int32_t len = + tsParseOneRowData(&lineptr, pTableDataBlock, pSchema, &spd, pCmd->payload, tinfo.precision, &code, tokenBuf); + if (len <= 0 || pTableDataBlock->numOfParams > 0) { + pSql->res.code = code; + break; + } + + pTableDataBlock->size += len; + + if (++count >= maxRows) { + break; + } + } + + tfree(tokenBuf); + free(line); + + if (count > 0) { + if ((code = doPackSendDataBlock(pSql, count, pTableDataBlock)) != TSDB_CODE_SUCCESS) { + pParentSql->res.code = code; + } + + } else { + taos_free_result(pSql); + tfree(pSupporter); + fclose(fp); + + pParentSql->fp = pParentSql->fetchFp; + + // all data has been sent to vnode, call user function + int32_t v = (pParentSql->res.code != TSDB_CODE_SUCCESS) ? pParentSql->res.code : pParentSql->res.numOfRows; + (*pParentSql->fp)(pParentSql->param, pParentSql, v); + } +} + +static UNUSED_FUNC int tscInsertDataFromFile(SSqlObj *pSql, FILE *fp, char *tmpTokenBuf) { size_t readLen = 0; char * line = NULL; - size_t n = 0; - int len = 0; int32_t maxRows = 0; SSqlCmd * pCmd = &pSql->cmd; int numOfRows = 0; int32_t code = 0; - int nrows = 0; - + STableMetaInfo *pTableMetaInfo = tscGetTableMetaInfoFromCmd(pCmd, pCmd->clauseIndex, 0); STableMeta * pTableMeta = pTableMetaInfo->pTableMeta; STableComInfo tinfo = tscGetTableInfo(pTableMeta); @@ -1422,6 +1512,7 @@ static int tscInsertDataFromFile(SSqlObj *pSql, FILE *fp, char *tmpTokenBuf) { tscSetAssignedColumnInfo(&spd, pSchema, tinfo.numOfColumns); + size_t n = 0; while ((readLen = getline(&line, &n, fp)) != -1) { // line[--readLen] = '\0'; if (('\r' == line[readLen - 1]) || ('\n' == line[readLen - 1])) line[--readLen] = 0; @@ -1430,19 +1521,18 @@ static int tscInsertDataFromFile(SSqlObj *pSql, FILE *fp, char *tmpTokenBuf) { char *lineptr = line; strtolower(line, line); - len = tsParseOneRowData(&lineptr, pTableDataBlock, pSchema, &spd, pCmd->payload, tinfo.precision, &code, tmpTokenBuf); + int32_t len = tsParseOneRowData(&lineptr, pTableDataBlock, pSchema, &spd, pCmd->payload, tinfo.precision, &code, tmpTokenBuf); if (len <= 0 || pTableDataBlock->numOfParams > 0) { pSql->res.code = code; - return (-code); + return code; } pTableDataBlock->size += len; count++; - nrows++; if (count >= maxRows) { if ((code = doPackSendDataBlock(pSql, count, pTableDataBlock)) != TSDB_CODE_SUCCESS) { - return -code; + return code; } pTableDataBlock = taosArrayGetP(pCmd->pDataBlocks, 0); @@ -1457,7 +1547,7 @@ static int tscInsertDataFromFile(SSqlObj *pSql, FILE *fp, char *tmpTokenBuf) { if (count > 0) { if ((code = doPackSendDataBlock(pSql, count, pTableDataBlock)) != TSDB_CODE_SUCCESS) { - return -code; + return code; } numOfRows += pSql->res.numOfRows; @@ -1477,26 +1567,32 @@ void tscProcessMultiVnodesInsertFromFile(SSqlObj *pSql) { SQueryInfo * pQueryInfo = tscGetQueryInfoDetail(pCmd, 0); STableMetaInfo *pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0); + STableComInfo tinfo = tscGetTableInfo(pTableMetaInfo->pTableMeta); + STableMeta* pTableMeta = pTableMetaInfo->pTableMeta; - STableDataBlocks *pDataBlock = NULL; - int32_t affected_rows = 0; - - assert(pCmd->dataSourceType == DATA_FROM_DATA_FILE && pCmd->pDataBlocks != NULL); + assert(pCmd->dataSourceType == DATA_FROM_DATA_FILE/* && pCmd->pDataBlocks != NULL*/); SArray *pDataBlockList = pCmd->pDataBlocks; - pCmd->pDataBlocks = NULL; + STableDataBlocks* pDataBlock = taosArrayGetP(pDataBlockList, 0); char path[PATH_MAX] = {0}; - size_t size = taosArrayGetSize(pDataBlockList); - for (int32_t i = 0; i < size; ++i) { - pDataBlock = taosArrayGetP(pDataBlockList, i ); - if (pDataBlock == NULL) { - continue; - } + SImportFileSupport* pSupporter = calloc(1, sizeof(SImportFileSupport)); + pSupporter->pSql = pSql; + + SSqlObj *pNew = createSubqueryObj(pSql, 0, parseFileSendDataBlock, pSupporter, TSDB_SQL_INSERT, NULL); + + pNew->cmd.pDataBlocks = taosArrayInit(4, POINTER_BYTES); + + STableDataBlocks *pTableDataBlock = NULL; + int32_t ret = tscCreateDataBlock(TSDB_PAYLOAD_SIZE, tinfo.rowSize, sizeof(SSubmitBlk), pTableMetaInfo->name, pTableMeta, &pTableDataBlock); + if (ret != TSDB_CODE_SUCCESS) { +// return ret; + } + + taosArrayPush(pNew->cmd.pDataBlocks, &pTableDataBlock); if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, TSDB_PAYLOAD_SIZE)) { tscError("%p failed to malloc when insert file", pSql); - continue; } pCmd->count = 1; @@ -1505,44 +1601,10 @@ void tscProcessMultiVnodesInsertFromFile(SSqlObj *pSql) { FILE *fp = fopen(path, "r"); if (fp == NULL) { tscError("%p failed to open file %s to load data from file, reason:%s", pSql, path, strerror(errno)); - continue; +// continue;// todo handle error } - tstrncpy(pTableMetaInfo->name, pDataBlock->tableId, sizeof(pTableMetaInfo->name)); - memset(pDataBlock->pData, 0, pDataBlock->nAllocSize); + pSupporter->fp = fp; - int32_t ret = tscGetTableMeta(pSql, pTableMetaInfo); - if (ret != TSDB_CODE_SUCCESS) { - tscError("%p get meter meta failed, abort", pSql); - continue; - } - - char *tmpTokenBuf = calloc(1, 4096); // used for deleting Escape character: \\, \', \" - if (NULL == tmpTokenBuf) { - tscError("%p calloc failed", pSql); - continue; - } - - int nrows = tscInsertDataFromFile(pSql, fp, tmpTokenBuf); - free(tmpTokenBuf); - - pCmd->pDataBlocks = tscDestroyBlockArrayList(pCmd->pDataBlocks); - - if (nrows < 0) { - fclose(fp); - tscTrace("%p no records(%d) in file %s", pSql, nrows, path); - continue; - } - - fclose(fp); - affected_rows += nrows; - - tscTrace("%p Insert data %d records from file %s", pSql, nrows, path); - } - - pSql->res.numOfRows = affected_rows; - - // all data have been submit to vnode, release data blocks - pCmd->pDataBlocks = tscDestroyBlockArrayList(pCmd->pDataBlocks); - tscDestroyBlockArrayList(pDataBlockList); + parseFileSendDataBlock(pSupporter, pNew, 0); } From afcc90a4b4a2989adda540e29c3f0bc14c5e098d Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Wed, 24 Jun 2020 23:54:15 +0800 Subject: [PATCH 2/6] [td-719] --- src/client/inc/tsclient.h | 8 +--- src/client/src/tscParseInsert.c | 85 +++++++++++++-------------------- src/client/src/tscUtil.c | 2 +- src/inc/taosdef.h | 2 +- 4 files changed, 36 insertions(+), 61 deletions(-) diff --git a/src/client/inc/tsclient.h b/src/client/inc/tsclient.h index 29abff7685..471db9c99f 100644 --- a/src/client/inc/tsclient.h +++ b/src/client/inc/tsclient.h @@ -171,11 +171,7 @@ typedef struct STableDataBlocks { * to avoid it to be removed from cache */ STableMeta *pTableMeta; - - union { - char *filename; - char *pData; - }; + char *pData; // for parameter ('?') binding uint32_t numOfAllocedParams; @@ -398,7 +394,7 @@ void waitForQueryRsp(void *param, TAOS_RES *tres, int code) ; int doAsyncParseSql(SSqlObj* pSql); void doAsyncQuery(STscObj *pObj, SSqlObj *pSql, void (*fp)(), void *param, const char *sqlstr, size_t sqlLen); -void tscProcessMultiVnodesInsertFromFile(SSqlObj *pSql); +void tscProcessMultiVnodesImportFromFile(SSqlObj *pSql); void tscKillSTableQuery(SSqlObj *pSql); void tscInitResObjForLocalQuery(SSqlObj *pObj, int32_t numOfRes, int32_t rowLen); bool tscIsUpdateQuery(SSqlObj* pSql); diff --git a/src/client/src/tscParseInsert.c b/src/client/src/tscParseInsert.c index 34741e2ed3..c2ce81992c 100644 --- a/src/client/src/tscParseInsert.c +++ b/src/client/src/tscParseInsert.c @@ -1153,29 +1153,19 @@ int tsParseInsertSql(SSqlObj *pSql) { goto _error; } - char fname[PATH_MAX] = {0}; - strncpy(fname, sToken.z, sToken.n); - strdequote(fname); + strncpy(pCmd->payload, sToken.z, sToken.n); + strdequote(pCmd->payload); + // todo refactor extract method wordexp_t full_path; - if (wordexp(fname, &full_path, 0) != 0) { + if (wordexp(pCmd->payload, &full_path, 0) != 0) { code = tscInvalidSQLErrMsg(pCmd->payload, "invalid filename", sToken.z); goto _error; } - strcpy(fname, full_path.we_wordv[0]); + + tstrncpy(pCmd->payload, full_path.we_wordv[0], pCmd->allocSize); wordfree(&full_path); - STableDataBlocks *pDataBlock = NULL; - STableMeta* pTableMeta = pTableMetaInfo->pTableMeta; - - int32_t ret = tscCreateDataBlock(PATH_MAX, tinfo.rowSize, sizeof(SSubmitBlk), pTableMetaInfo->name, - pTableMeta, &pDataBlock); - if (ret != TSDB_CODE_SUCCESS) { - goto _error; - } - - taosArrayPush(pCmd->pDataBlocks, &pDataBlock); - strcpy(pDataBlock->filename, fname); } else if (sToken.type == TK_LP) { /* insert into tablename(col1, col2,..., coln) values(v1, v2,... vn); */ STableMeta *pTableMeta = tscGetTableMetaInfoFromCmd(pCmd, pCmd->clauseIndex, 0)->pTableMeta; @@ -1424,10 +1414,18 @@ static void parseFileSendDataBlock(void *param, TAOS_RES *tres, int code) { int32_t count = 0; int32_t maxRows = 0; - STableDataBlocks *pTableDataBlock = taosArrayGetP(pSql->cmd.pDataBlocks, 0); - pTableDataBlock->size = pTableDataBlock->headerSize; + tscDestroyBlockArrayList(pSql->cmd.pDataBlocks); + pCmd->pDataBlocks = taosArrayInit(1, POINTER_BYTES); + STableDataBlocks *pTableDataBlock = NULL; + int32_t ret = tscCreateDataBlock(TSDB_PAYLOAD_SIZE, tinfo.rowSize, sizeof(SSubmitBlk), pTableMetaInfo->name, pTableMeta, &pTableDataBlock); + if (ret != TSDB_CODE_SUCCESS) { +// return ret; + } + + taosArrayPush(pCmd->pDataBlocks, &pTableDataBlock); tscAllocateMemIfNeed(pTableDataBlock, tinfo.rowSize, &maxRows); + char *tokenBuf = calloc(1, 4096); while ((readLen = getline(&line, &n, fp)) != -1) { @@ -1559,52 +1557,33 @@ static UNUSED_FUNC int tscInsertDataFromFile(SSqlObj *pSql, FILE *fp, char *tmpT return numOfRows; } -void tscProcessMultiVnodesInsertFromFile(SSqlObj *pSql) { +void tscProcessMultiVnodesImportFromFile(SSqlObj *pSql) { SSqlCmd *pCmd = &pSql->cmd; if (pCmd->command != TSDB_SQL_INSERT) { return; } - SQueryInfo * pQueryInfo = tscGetQueryInfoDetail(pCmd, 0); - STableMetaInfo *pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0); - STableComInfo tinfo = tscGetTableInfo(pTableMetaInfo->pTableMeta); - STableMeta* pTableMeta = pTableMetaInfo->pTableMeta; - - assert(pCmd->dataSourceType == DATA_FROM_DATA_FILE/* && pCmd->pDataBlocks != NULL*/); - SArray *pDataBlockList = pCmd->pDataBlocks; - STableDataBlocks* pDataBlock = taosArrayGetP(pDataBlockList, 0); - - char path[PATH_MAX] = {0}; - - SImportFileSupport* pSupporter = calloc(1, sizeof(SImportFileSupport)); - pSupporter->pSql = pSql; + assert(pCmd->dataSourceType == DATA_FROM_DATA_FILE && strlen(pCmd->payload) != 0); + SImportFileSupport *pSupporter = calloc(1, sizeof(SImportFileSupport)); SSqlObj *pNew = createSubqueryObj(pSql, 0, parseFileSendDataBlock, pSupporter, TSDB_SQL_INSERT, NULL); pNew->cmd.pDataBlocks = taosArrayInit(4, POINTER_BYTES); + pCmd->count = 1; - STableDataBlocks *pTableDataBlock = NULL; - int32_t ret = tscCreateDataBlock(TSDB_PAYLOAD_SIZE, tinfo.rowSize, sizeof(SSubmitBlk), pTableMetaInfo->name, pTableMeta, &pTableDataBlock); - if (ret != TSDB_CODE_SUCCESS) { -// return ret; + FILE *fp = fopen(pCmd->payload, "r"); + if (fp == NULL) { + pSql->res.code = TAOS_SYSTEM_ERROR(errno); + tscError("%p failed to open file %s to load data from file, code:%s", pSql, pCmd->payload, tstrerror(pSql->res.code)); + + tfree(pSupporter) + tscQueueAsyncRes(pSql); + + return; } - taosArrayPush(pNew->cmd.pDataBlocks, &pTableDataBlock); + pSupporter->pSql = pSql; + pSupporter->fp = fp; - if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, TSDB_PAYLOAD_SIZE)) { - tscError("%p failed to malloc when insert file", pSql); - } - pCmd->count = 1; - - tstrncpy(path, pDataBlock->filename, sizeof(path)); - - FILE *fp = fopen(path, "r"); - if (fp == NULL) { - tscError("%p failed to open file %s to load data from file, reason:%s", pSql, path, strerror(errno)); -// continue;// todo handle error - } - - pSupporter->fp = fp; - - parseFileSendDataBlock(pSupporter, pNew, 0); + parseFileSendDataBlock(pSupporter, pNew, 0); } diff --git a/src/client/src/tscUtil.c b/src/client/src/tscUtil.c index 4d90caddcb..b4fe670df8 100644 --- a/src/client/src/tscUtil.c +++ b/src/client/src/tscUtil.c @@ -1880,7 +1880,7 @@ void tscDoQuery(SSqlObj* pSql) { } if (pCmd->dataSourceType == DATA_FROM_DATA_FILE) { - tscProcessMultiVnodesInsertFromFile(pSql); + tscProcessMultiVnodesImportFromFile(pSql); } else { SQueryInfo *pQueryInfo = tscGetQueryInfoDetail(pCmd, pCmd->clauseIndex); uint16_t type = pQueryInfo->type; diff --git a/src/inc/taosdef.h b/src/inc/taosdef.h index 8cc5e82590..eefd9f0c00 100644 --- a/src/inc/taosdef.h +++ b/src/inc/taosdef.h @@ -245,7 +245,7 @@ void tsDataSwap(void *pLeft, void *pRight, int32_t type, int32_t size); #define TSDB_DEFAULT_PKT_SIZE 65480 //same as RPC_MAX_UDP_SIZE #define TSDB_PAYLOAD_SIZE TSDB_DEFAULT_PKT_SIZE -#define TSDB_DEFAULT_PAYLOAD_SIZE 2048 // default payload size +#define TSDB_DEFAULT_PAYLOAD_SIZE 5120 // default payload size, greater than PATH_MAX value #define TSDB_EXTRA_PAYLOAD_SIZE 128 // extra bytes for auth #define TSDB_CQ_SQL_SIZE 1024 #define TSDB_MAX_VNODES 256 From bc4925ac0b2c81ad606313cfd5d018e5916548ca Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Thu, 25 Jun 2020 00:26:32 +0800 Subject: [PATCH 3/6] [td-717] --- src/client/src/tscServer.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/client/src/tscServer.c b/src/client/src/tscServer.c index 631a9b5eb3..e9b84ecd13 100644 --- a/src/client/src/tscServer.c +++ b/src/client/src/tscServer.c @@ -195,7 +195,10 @@ int tscSendMsgToServer(SSqlObj *pSql) { .code = 0 }; - pSql->pRpcCtx = rpcSendRequest(pObj->pDnodeConn, &pSql->ipList, &rpcMsg); + // NOTE: the rpc context should be acquired before sent data to server. + // Otherwise, the pSql object may have been released already in during the processMsgFromServer function, in the + // meanwhile, the assignment of the rpc context to sql object will absolutely caused crash. + /*pSql->pRpcCtx = */rpcSendRequest(pObj->pDnodeConn, &pSql->ipList, &rpcMsg); return TSDB_CODE_SUCCESS; } From 04a07f801237ba89dddce7429f75d3dae74c97fa Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Thu, 25 Jun 2020 00:40:57 +0800 Subject: [PATCH 4/6] [td-225] remove the unused function. --- src/client/src/tscParseInsert.c | 82 --------------------------------- 1 file changed, 82 deletions(-) diff --git a/src/client/src/tscParseInsert.c b/src/client/src/tscParseInsert.c index c2ce81992c..df4ccca9bc 100644 --- a/src/client/src/tscParseInsert.c +++ b/src/client/src/tscParseInsert.c @@ -1475,88 +1475,6 @@ static void parseFileSendDataBlock(void *param, TAOS_RES *tres, int code) { } } -static UNUSED_FUNC int tscInsertDataFromFile(SSqlObj *pSql, FILE *fp, char *tmpTokenBuf) { - size_t readLen = 0; - char * line = NULL; - int32_t maxRows = 0; - SSqlCmd * pCmd = &pSql->cmd; - int numOfRows = 0; - int32_t code = 0; - - STableMetaInfo *pTableMetaInfo = tscGetTableMetaInfoFromCmd(pCmd, pCmd->clauseIndex, 0); - STableMeta * pTableMeta = pTableMetaInfo->pTableMeta; - STableComInfo tinfo = tscGetTableInfo(pTableMeta); - - assert(pCmd->numOfClause == 1); - - int32_t rowSize = tinfo.rowSize; - - pCmd->pDataBlocks = taosArrayInit(4, POINTER_BYTES); - STableDataBlocks *pTableDataBlock = NULL; - - int32_t ret = tscCreateDataBlock(TSDB_PAYLOAD_SIZE, rowSize, sizeof(SSubmitBlk), pTableMetaInfo->name, pTableMeta, &pTableDataBlock); - if (ret != TSDB_CODE_SUCCESS) { - return ret; - } - - taosArrayPush(pCmd->pDataBlocks, &pTableDataBlock); - - code = tscAllocateMemIfNeed(pTableDataBlock, rowSize, &maxRows); - if (TSDB_CODE_SUCCESS != code) return -1; - - int count = 0; - SParsedDataColInfo spd = {.numOfCols = tinfo.numOfColumns}; - SSchema * pSchema = tscGetTableSchema(pTableMeta); - - tscSetAssignedColumnInfo(&spd, pSchema, tinfo.numOfColumns); - - size_t n = 0; - while ((readLen = getline(&line, &n, fp)) != -1) { - // line[--readLen] = '\0'; - if (('\r' == line[readLen - 1]) || ('\n' == line[readLen - 1])) line[--readLen] = 0; - if (readLen == 0) continue; // fang, <= to == - - char *lineptr = line; - strtolower(line, line); - - int32_t len = tsParseOneRowData(&lineptr, pTableDataBlock, pSchema, &spd, pCmd->payload, tinfo.precision, &code, tmpTokenBuf); - if (len <= 0 || pTableDataBlock->numOfParams > 0) { - pSql->res.code = code; - return code; - } - - pTableDataBlock->size += len; - - count++; - if (count >= maxRows) { - if ((code = doPackSendDataBlock(pSql, count, pTableDataBlock)) != TSDB_CODE_SUCCESS) { - return code; - } - - pTableDataBlock = taosArrayGetP(pCmd->pDataBlocks, 0); - pTableDataBlock->size = sizeof(SSubmitBlk); - pTableDataBlock->rowSize = tinfo.rowSize; - - numOfRows += pSql->res.numOfRows; - pSql->res.numOfRows = 0; - count = 0; - } - } - - if (count > 0) { - if ((code = doPackSendDataBlock(pSql, count, pTableDataBlock)) != TSDB_CODE_SUCCESS) { - return code; - } - - numOfRows += pSql->res.numOfRows; - pSql->res.numOfRows = 0; - } - - if (line) tfree(line); - - return numOfRows; -} - void tscProcessMultiVnodesImportFromFile(SSqlObj *pSql) { SSqlCmd *pCmd = &pSql->cmd; if (pCmd->command != TSDB_SQL_INSERT) { From 9a4414c3affb12306019da8fd265dc69e87a2a7e Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Thu, 25 Jun 2020 00:41:27 +0800 Subject: [PATCH 5/6] [td-225] fix some typo --- src/client/src/tscServer.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/client/src/tscServer.c b/src/client/src/tscServer.c index e9b84ecd13..5448e5433a 100644 --- a/src/client/src/tscServer.c +++ b/src/client/src/tscServer.c @@ -195,9 +195,10 @@ int tscSendMsgToServer(SSqlObj *pSql) { .code = 0 }; - // NOTE: the rpc context should be acquired before sent data to server. - // Otherwise, the pSql object may have been released already in during the processMsgFromServer function, in the - // meanwhile, the assignment of the rpc context to sql object will absolutely caused crash. + // NOTE: the rpc context should be acquired before sending data to server. + // Otherwise, the pSql object may have been released already during the response function, which is + // processMsgFromServer function. In the meanwhile, the assignment of the rpc context to sql object will absolutely + // cause crash. /*pSql->pRpcCtx = */rpcSendRequest(pObj->pDnodeConn, &pSql->ipList, &rpcMsg); return TSDB_CODE_SUCCESS; } From 1ed5309d975bb386763c68fafe4997be99a8305a Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Thu, 25 Jun 2020 00:45:29 +0800 Subject: [PATCH 6/6] [td-717] fix memory leak in taosdemo.c --- src/kit/taosdemo/taosdemo.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/kit/taosdemo/taosdemo.c b/src/kit/taosdemo/taosdemo.c index e4b84fc8e8..e673277a0b 100644 --- a/src/kit/taosdemo/taosdemo.c +++ b/src/kit/taosdemo/taosdemo.c @@ -470,11 +470,12 @@ int main(int argc, char *argv[]) { char command[BUFFER_SIZE] = "\0"; sprintf(command, "drop database %s;", db_name); - taos_query(taos, command); - + TAOS_RES* res = taos_query(taos, command); + taos_free_result(res); sprintf(command, "create database %s;", db_name); - taos_query(taos, command); + res = taos_query(taos, command); + taos_free_result(res); char cols[STRING_LEN] = "\0"; int colIndex = 0;