diff --git a/src/client/src/tscParseLineProtocol.c b/src/client/src/tscParseLineProtocol.c index b657594db447a13b1db495fe63db7307565e2b07..a3bb7c6f150bdf0b949f3637ef96e4386268903a 100644 --- a/src/client/src/tscParseLineProtocol.c +++ b/src/client/src/tscParseLineProtocol.c @@ -611,16 +611,19 @@ static int32_t insertChildTableBatch(TAOS* taos, char* cTableName, SArray* cols snprintf(sql + strlen(sql)-1, freeBytes-strlen(sql)+1, ")"); tscDebug("insert rows %zu into child table %s. ", taosArrayGetSize(rowsBind), cTableName); + int32_t code = 0; int32_t try = 0; - do { - TAOS_STMT* stmt = taos_stmt_init(taos); - code = taos_stmt_prepare(stmt, sql, strlen(sql)); - if (code != 0) { - tscError("%s", taos_stmt_errstr(stmt)); - return code; - } + TAOS_STMT* stmt = taos_stmt_init(taos); + + code = taos_stmt_prepare(stmt, sql, strlen(sql)); + if (code != 0) { + tscError("%s", taos_stmt_errstr(stmt)); + return code; + } + + do { code = taos_stmt_set_tbname(stmt, cTableName); if (code != 0) { @@ -646,12 +649,16 @@ static int32_t insertChildTableBatch(TAOS* taos, char* cTableName, SArray* cols code = taos_stmt_execute(stmt); if (code != 0) { tscError("%s", taos_stmt_errstr(stmt)); - taos_stmt_close(stmt); - } else { - taos_stmt_close(stmt); } } while (code == TSDB_CODE_TDB_TABLE_RECONFIGURE && try++ < TSDB_MAX_REPLICA); + if (code != 0) { + tscError("%s", taos_stmt_errstr(stmt)); + taos_stmt_close(stmt); + } else { + taos_stmt_close(stmt); + } + return code; } diff --git a/src/client/src/tscPrepare.c b/src/client/src/tscPrepare.c index 798e79dbcb650b38f3bdfeec49e80b0b99627b48..3a462c96d6344d2ede6e88bf351bf3be8280ae0d 100644 --- a/src/client/src/tscPrepare.c +++ b/src/client/src/tscPrepare.c @@ -1200,9 +1200,11 @@ static int insertBatchStmtExecute(STscStmt* pStmt) { // wait for the callback function to post the semaphore tsem_wait(&pStmt->pSql->rspSem); + code = pStmt->pSql->res.code; + insertBatchClean(pStmt); - return pStmt->pSql->res.code; + return code; } int stmtParseInsertTbTags(SSqlObj* pSql, STscStmt* pStmt) { @@ -1647,7 +1649,11 @@ int taos_stmt_close(TAOS_STMT* stmt) { } else { if (pStmt->multiTbInsert) { taosHashCleanup(pStmt->mtb.pTableHash); - pStmt->mtb.pTableBlockHashList = tscDestroyBlockHashTable(pStmt->mtb.pTableBlockHashList, false); + bool rmMeta = false; + if (pStmt->pSql && pStmt->pSql->res.code != 0) { + rmMeta = true; + } + pStmt->mtb.pTableBlockHashList = tscDestroyBlockHashTable(pStmt->mtb.pTableBlockHashList, rmMeta); taosHashCleanup(pStmt->pSql->cmd.insertParam.pTableBlockHashList); pStmt->pSql->cmd.insertParam.pTableBlockHashList = NULL; taosArrayDestroy(pStmt->mtb.tags);