From bcba45e38bcd2769057f3b631ee390a9289a8599 Mon Sep 17 00:00:00 2001 From: Shenglian Zhou Date: Tue, 13 Jul 2021 14:19:56 +0800 Subject: [PATCH] retry afer batch execute reconfigure table --- src/client/src/tscParseLineProtocol.c | 61 +++++++++++++++------------ tests/examples/c/apitest.c | 8 ++-- 2 files changed, 36 insertions(+), 33 deletions(-) diff --git a/src/client/src/tscParseLineProtocol.c b/src/client/src/tscParseLineProtocol.c index 85a6c41ccf..04b96dc52a 100644 --- a/src/client/src/tscParseLineProtocol.c +++ b/src/client/src/tscParseLineProtocol.c @@ -324,7 +324,7 @@ static int32_t applySchemaAction(TAOS* taos, SSchemaAction* action) { return code; } -static int32_t destorySmlSTableSchema(SSmlSTableSchema* schema) { +static int32_t destroySmlSTableSchema(SSmlSTableSchema* schema) { taosHashCleanup(schema->tagHash); taosHashCleanup(schema->fieldHash); taosArrayDestroy(schema->tags); @@ -435,7 +435,7 @@ static int32_t reconcileDBSchemas(TAOS* taos, SArray* stableSchemas) { pointSchema->precision = dbSchema.precision; - destorySmlSTableSchema(&dbSchema); + destroySmlSTableSchema(&dbSchema); } else if (code == TSDB_CODE_SUCCESS) { size_t pointTagSize = taosArrayGetSize(pointSchema->tags); size_t pointFieldSize = taosArrayGetSize(pointSchema->fields); @@ -469,7 +469,7 @@ static int32_t reconcileDBSchemas(TAOS* taos, SArray* stableSchemas) { pointSchema->precision = dbSchema.precision; - destorySmlSTableSchema(&dbSchema); + destroySmlSTableSchema(&dbSchema); } else { return code; } @@ -565,42 +565,47 @@ static int32_t insertChildTableBatch(TAOS* taos, char* cTableName, SArray* cols } snprintf(sql + strlen(sql)-1, freeBytes-strlen(sql)+1, ")"); - TAOS_STMT* stmt = taos_stmt_init(taos); - int32_t code; - code = taos_stmt_prepare(stmt, sql, strlen(sql)); - if (code != 0) { - printf("%s", taos_stmt_errstr(stmt)); - return code; - } + int32_t code = 0; + int32_t try = 0; + do { + TAOS_STMT* stmt = taos_stmt_init(taos); - code = taos_stmt_set_tbname(stmt, cTableName); - if (code != 0) { - printf("%s", taos_stmt_errstr(stmt)); - return code; - } - - size_t rows = taosArrayGetSize(rowsBind); - for (int32_t i = 0; i < rows; ++i) { - TAOS_BIND* colsBinds = taosArrayGetP(rowsBind, i); - code = taos_stmt_bind_param(stmt, colsBinds); + code = taos_stmt_prepare(stmt, sql, strlen(sql)); if (code != 0) { printf("%s", taos_stmt_errstr(stmt)); return code; } - code = taos_stmt_add_batch(stmt); + + code = taos_stmt_set_tbname(stmt, cTableName); if (code != 0) { printf("%s", taos_stmt_errstr(stmt)); return code; } - } - code = taos_stmt_execute(stmt); - if (code != 0) { - printf("%s", taos_stmt_errstr(stmt)); - return code; - } + size_t rows = taosArrayGetSize(rowsBind); + for (int32_t i = 0; i < rows; ++i) { + TAOS_BIND* colsBinds = taosArrayGetP(rowsBind, i); + code = taos_stmt_bind_param(stmt, colsBinds); + if (code != 0) { + printf("%s", taos_stmt_errstr(stmt)); + return code; + } + code = taos_stmt_add_batch(stmt); + if (code != 0) { + printf("%s", taos_stmt_errstr(stmt)); + return code; + } + } + + 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); - taos_stmt_close(stmt); return code; } diff --git a/tests/examples/c/apitest.c b/tests/examples/c/apitest.c index f4e222c4dc..e7d4b087f7 100644 --- a/tests/examples/c/apitest.c +++ b/tests/examples/c/apitest.c @@ -6,7 +6,6 @@ #include #include #include -#include static void prepare_data(TAOS* taos) { TAOS_RES *result; @@ -972,9 +971,9 @@ int32_t verify_schema_less(TAOS* taos) { "ste,t2=5,t3=L\"ste2\" c3=\"iamszhou\",c4=false 1626056811843316532" }; - int code = taos_insert_by_lines(taos, lines , 5); - //int code = taos_insert_by_lines(taos, &lines[0], 1); - //code = taos_insert_by_lines(taos, &lines[1], 1); + // int code = taos_insert_by_lines(taos, lines , 5); + int code = taos_insert_by_lines(taos, &lines[0], 1); + code = taos_insert_by_lines(taos, &lines[1], 1); return code; } @@ -985,7 +984,6 @@ int main(int argc, char *argv[]) { const char* passwd = "taosdata"; taos_options(TSDB_OPTION_TIMEZONE, "GMT-8"); - taosDumpGlobalCfg(); TAOS* taos = taos_connect(host, user, passwd, "", 0); if (taos == NULL) { printf("\033[31mfailed to connect to db, reason:%s\033[0m\n", taos_errstr(taos));