From 8f2008664e24972fd730aa8d4547d13ad092c26d Mon Sep 17 00:00:00 2001 From: wpan Date: Tue, 13 Jul 2021 16:34:19 +0800 Subject: [PATCH] add retry for reconfigure table --- src/client/src/tscParseLineProtocol.c | 30 +++++++++++++++------------ src/client/src/tscPrepare.c | 10 +++++++-- 2 files changed, 25 insertions(+), 15 deletions(-) diff --git a/src/client/src/tscParseLineProtocol.c b/src/client/src/tscParseLineProtocol.c index 04b96dc52a..5fba602670 100644 --- a/src/client/src/tscParseLineProtocol.c +++ b/src/client/src/tscParseLineProtocol.c @@ -565,16 +565,19 @@ static int32_t insertChildTableBatch(TAOS* taos, char* cTableName, SArray* cols } snprintf(sql + strlen(sql)-1, freeBytes-strlen(sql)+1, ")"); + 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) { - printf("%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) { + printf("%s", taos_stmt_errstr(stmt)); + return code; + } + + do { code = taos_stmt_set_tbname(stmt, cTableName); if (code != 0) { @@ -598,14 +601,15 @@ static int32_t insertChildTableBatch(TAOS* taos, char* cTableName, SArray* cols } code = taos_stmt_execute(stmt); - if (code != 0) { - printf("%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) { + printf("%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 798e79dbcb..3a462c96d6 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); -- GitLab