From 3cb51e980f5ab636965b8f037f2305a621a9247d Mon Sep 17 00:00:00 2001 From: Shuduo Sang Date: Wed, 17 Mar 2021 00:10:45 +0800 Subject: [PATCH] Hotfix/sangshuduo/td 3316 testcase for taosdemo limit offset (#5462) * [TD-3316] : add testcase for taosdemo limit and offset. check offset 0. * [TD-3316] : add testcase for taosdemo limit and offset. fix sample file import bug. --- src/kit/taosdemo/taosdemo.c | 49 ++++++++++++++++++++++++++++--------- 1 file changed, 37 insertions(+), 12 deletions(-) diff --git a/src/kit/taosdemo/taosdemo.c b/src/kit/taosdemo/taosdemo.c index 6b1cf5f657..b03f47bfaf 100644 --- a/src/kit/taosdemo/taosdemo.c +++ b/src/kit/taosdemo/taosdemo.c @@ -4145,7 +4145,6 @@ static int generateDataBuffer(int32_t tableSeq, assert(buffer != NULL); char *pChildTblName; - int childTblCount; pChildTblName = calloc(TSDB_TABLE_NAME_LEN, 1); if (NULL == pChildTblName) { @@ -4155,13 +4154,10 @@ static int generateDataBuffer(int32_t tableSeq, if (superTblInfo && (superTblInfo->childTblOffset >= 0) && (superTblInfo->childTblLimit > 0)) { - // select tbname from stb limit 1 offset tableSeq - getChildNameOfSuperTableWithLimitAndOffset(pThreadInfo->taos, - pThreadInfo->db_name, superTblInfo->sTblName, - &pChildTblName, &childTblCount, - 1, tableSeq); + snprintf(pChildTblName, TSDB_TABLE_NAME_LEN, "%s", + superTblInfo->childTblName + (tableSeq - superTblInfo->childTblOffset) * TSDB_TABLE_NAME_LEN); } else { - snprintf(pChildTblName, TSDB_TABLE_NAME_LEN, "%s%d", + snprintf(pChildTblName, TSDB_TABLE_NAME_LEN, "%s%d", superTblInfo?superTblInfo->childTblPrefix:g_args.tb_prefix, tableSeq); } @@ -4577,10 +4573,40 @@ static void startMultiThreadInsertData(int threads, char* db_name, // read sample data from file first if ((superTblInfo) && (0 == strncasecmp(superTblInfo->dataSource, "sample", strlen("sample")))) { - if (0 != prepareSampleDataForSTable(superTblInfo)) { - fprintf(stderr, "prepare sample data for stable failed!\n"); - exit(-1); - } + if (0 != prepareSampleDataForSTable(superTblInfo)) { + fprintf(stderr, "prepare sample data for stable failed!\n"); + exit(-1); + } + } + + if (superTblInfo && (superTblInfo->childTblOffset >= 0) + && (superTblInfo->childTblLimit > 0)) { + + TAOS* taos = taos_connect( + g_Dbs.host, g_Dbs.user, + g_Dbs.password, db_name, g_Dbs.port); + if (NULL == taos) { + fprintf(stderr, "connect to server fail , reason: %s\n", + taos_errstr(NULL)); + exit(-1); + } + + superTblInfo->childTblName = (char*)calloc(1, + superTblInfo->childTblLimit * TSDB_TABLE_NAME_LEN); + if (superTblInfo->childTblName == NULL) { + fprintf(stderr, "alloc memory failed!"); + taos_close(taos); + exit(-1); + } + int childTblCount; + + getChildNameOfSuperTableWithLimitAndOffset( + taos, + db_name, superTblInfo->sTblName, + &superTblInfo->childTblName, &childTblCount, + superTblInfo->childTblLimit, + superTblInfo->childTblOffset); + taos_close(taos); } for (int i = 0; i < threads; i++) { @@ -4618,7 +4644,6 @@ static void startMultiThreadInsertData(int threads, char* db_name, t_info->start_time = t_info->start_time + rand_int() % 10000 - rand_tinyint(); } - tsem_init(&(t_info->lock_sem), 0, 0); if (SYNC == g_Dbs.queryMode) { pthread_create(pids + i, NULL, syncWrite, t_info); -- GitLab