diff --git a/src/client/src/tscParseLineProtocol.c b/src/client/src/tscParseLineProtocol.c index 1bce10f95e61664fc5c8572352a2c6749a17db8c..e3ed89a591ab45ce7a60d3a198eaf0aac6dbfafd 100644 --- a/src/client/src/tscParseLineProtocol.c +++ b/src/client/src/tscParseLineProtocol.c @@ -849,6 +849,8 @@ static int32_t insertChildTableBatch(TAOS* taos, char* cTableName, SArray* cols return code; } + bool tryAgain = false; + do { code = taos_stmt_set_tbname(stmt, cTableName); if (code != 0) { @@ -878,7 +880,26 @@ static int32_t insertChildTableBatch(TAOS* taos, char* cTableName, SArray* cols if (code != 0) { tscError("SML:0x%"PRIx64" taos_stmt_execute return %d:%s", info->id, code, tstrerror(code)); } - } while (code == TSDB_CODE_TDB_TABLE_RECONFIGURE && try++ < TSDB_MAX_REPLICA); + + tryAgain = false; + if ((code == TSDB_CODE_TDB_INVALID_TABLE_ID + || code == TSDB_CODE_VND_INVALID_VGROUP_ID + || code == TSDB_CODE_TDB_TABLE_RECONFIGURE) && try++ < TSDB_MAX_REPLICA) { + tryAgain = true; + } + + if (code == TSDB_CODE_TDB_INVALID_TABLE_ID || code == TSDB_CODE_VND_INVALID_VGROUP_ID) { + TAOS_RES* res2 = taos_query(taos, "RESET QUERY CACHE"); + int32_t code2 = taos_errno(res2); + if (code2 != TSDB_CODE_SUCCESS) { + tscError("SML:0x%" PRIx64 " apply schema action. reset query cache. error: %s", info->id, taos_errstr(res2)); + } + taos_free_result(res2); + if (tryAgain) { + taosMsleep(100 * (2 << (try))); + } + } + } while (tryAgain); if (code != 0) { tscError("SML:0x%"PRIx64" %d:%s", info->id, code, tstrerror(code)); @@ -1084,28 +1105,10 @@ static int32_t applyChildTableFields(TAOS* taos, SSmlSTableSchema* sTableSchema, taosArrayPush(rowsBind, &colBinds); } - int32_t retry = 0; - bool retryAgain = false; - do { - code = insertChildTableBatch(taos, cTableName, sTableSchema->fields, rowsBind, info); - if (code != 0) { - tscError("SML:0x%" PRIx64 " insert into child table %s failed. error %s, retry %d", info->id, cTableName, tstrerror(code), retry); - if (code == TSDB_CODE_TDB_INVALID_TABLE_ID || code == TSDB_CODE_VND_INVALID_VGROUP_ID) { - TAOS_RES* res2 = taos_query(taos, "RESET QUERY CACHE"); - int32_t code2 = taos_errno(res2); - if (code2 != TSDB_CODE_SUCCESS) { - tscError("SML:0x%" PRIx64 " apply schema action. reset query cache. error: %s", info->id, taos_errstr(res2)); - } - taos_free_result(res2); - retryAgain = (++retry < TSDB_MAX_REPLICA) ? true : false; - if (retryAgain) { - taosMsleep(100 * (2 << (retry))); - } else { - tscError("SML:0x%" PRIx64 " insert into child table %s reached max retry", info->id, cTableName); - } - } - } - } while (retryAgain); + code = insertChildTableBatch(taos, cTableName, sTableSchema->fields, rowsBind, info); + if (code != 0) { + tscError("SML:0x%"PRIx64" insert into child table %s failed. error %s", info->id, cTableName, tstrerror(code)); + } for (int i = 0; i < rows; ++i) { TAOS_BIND* colBinds = taosArrayGetP(rowsBind, i);