未验证 提交 b2b514f8 编写于 作者: sangshuduo's avatar sangshuduo 提交者: GitHub

[TD-3705]<fix>: taosdemo columns or tags count overflow. (#5745) (#5760)

* [TD-3705]<fix>: taosdemo columns or tags count overflow.

* [TD-3705]<fix>: taosdemo columns or tags count overflow.

compare columns+tags with max columns count.
Co-authored-by: NShuduo Sang <sdsang@taosdata.com>
Co-authored-by: NShuduo Sang <sdsang@taosdata.com>
上级 395c2d98
...@@ -2364,7 +2364,8 @@ static int createSuperTable(TAOS * taos, char* dbName, ...@@ -2364,7 +2364,8 @@ static int createSuperTable(TAOS * taos, char* dbName,
lenOfOneRow += 21; lenOfOneRow += 21;
} else { } else {
taos_close(taos); taos_close(taos);
printf("config error data type : %s\n", dataType); errorPrint("%s() LN%d, config error data type : %s\n",
__func__, __LINE__, dataType);
exit(-1); exit(-1);
} }
} }
...@@ -2382,7 +2383,8 @@ static int createSuperTable(TAOS * taos, char* dbName, ...@@ -2382,7 +2383,8 @@ static int createSuperTable(TAOS * taos, char* dbName,
} }
snprintf(superTbl->colsOfCreateChildTable, len+20, "(ts timestamp%s)", cols); snprintf(superTbl->colsOfCreateChildTable, len+20, "(ts timestamp%s)", cols);
verbosePrint("%s() LN%d: %s\n", __func__, __LINE__, superTbl->colsOfCreateChildTable); verbosePrint("%s() LN%d: %s\n",
__func__, __LINE__, superTbl->colsOfCreateChildTable);
if (superTbl->tagCount == 0) { if (superTbl->tagCount == 0) {
errorPrint("%s() LN%d, super table tag count is %d\n", errorPrint("%s() LN%d, super table tag count is %d\n",
...@@ -2437,7 +2439,8 @@ static int createSuperTable(TAOS * taos, char* dbName, ...@@ -2437,7 +2439,8 @@ static int createSuperTable(TAOS * taos, char* dbName,
lenOfTagOfOneRow += superTbl->tags[tagIndex].dataLen + 42; lenOfTagOfOneRow += superTbl->tags[tagIndex].dataLen + 42;
} else { } else {
taos_close(taos); taos_close(taos);
printf("config error tag type : %s\n", dataType); errorPrint("%s() LN%d, config error tag type : %s\n",
__func__, __LINE__, dataType);
exit(-1); exit(-1);
} }
} }
...@@ -2732,7 +2735,8 @@ static int startMultiThreadCreateChildTable( ...@@ -2732,7 +2735,8 @@ static int startMultiThreadCreateChildTable(
db_name, db_name,
g_Dbs.port); g_Dbs.port);
if (t_info->taos == NULL) { if (t_info->taos == NULL) {
errorPrint( "Failed to connect to TDengine, reason:%s\n", taos_errstr(NULL)); errorPrint( "%s() LN%d, Failed to connect to TDengine, reason:%s\n",
__func__, __LINE__, taos_errstr(NULL));
free(pids); free(pids);
free(infos); free(infos);
return -1; return -1;
...@@ -2793,35 +2797,35 @@ static void createChildTables() { ...@@ -2793,35 +2797,35 @@ static void createChildTables() {
} }
} }
} else { } else {
// normal table // normal table
len = snprintf(tblColsBuf, MAX_SQL_SIZE, "(TS TIMESTAMP"); len = snprintf(tblColsBuf, MAX_SQL_SIZE, "(TS TIMESTAMP");
int j = 0; int j = 0;
while(g_args.datatype[j]) { while(g_args.datatype[j]) {
if ((strncasecmp(g_args.datatype[j], "BINARY", strlen("BINARY")) == 0) if ((strncasecmp(g_args.datatype[j], "BINARY", strlen("BINARY")) == 0)
|| (strncasecmp(g_args.datatype[j], || (strncasecmp(g_args.datatype[j],
"NCHAR", strlen("NCHAR")) == 0)) { "NCHAR", strlen("NCHAR")) == 0)) {
snprintf(tblColsBuf + len, MAX_SQL_SIZE - len, snprintf(tblColsBuf + len, MAX_SQL_SIZE - len,
", COL%d %s(60)", j, g_args.datatype[j]); ", COL%d %s(60)", j, g_args.datatype[j]);
} else { } else {
snprintf(tblColsBuf + len, MAX_SQL_SIZE - len, snprintf(tblColsBuf + len, MAX_SQL_SIZE - len,
", COL%d %s", j, g_args.datatype[j]); ", COL%d %s", j, g_args.datatype[j]);
} }
len = strlen(tblColsBuf); len = strlen(tblColsBuf);
j++; j++;
} }
snprintf(tblColsBuf + len, MAX_SQL_SIZE - len, ")"); snprintf(tblColsBuf + len, MAX_SQL_SIZE - len, ")");
verbosePrint("%s() LN%d: dbName: %s num of tb: %d schema: %s\n", verbosePrint("%s() LN%d: dbName: %s num of tb: %d schema: %s\n",
__func__, __LINE__, __func__, __LINE__,
g_Dbs.db[i].dbName, g_args.num_of_tables, tblColsBuf); g_Dbs.db[i].dbName, g_args.num_of_tables, tblColsBuf);
startMultiThreadCreateChildTable( startMultiThreadCreateChildTable(
tblColsBuf, tblColsBuf,
g_Dbs.threadCountByCreateTbl, g_Dbs.threadCountByCreateTbl,
0, 0,
g_args.num_of_tables, g_args.num_of_tables,
g_Dbs.db[i].dbName, g_Dbs.db[i].dbName,
NULL); NULL);
} }
} }
} }
...@@ -3035,6 +3039,13 @@ static bool getColumnAndTagTypeFromInsertJsonFile( ...@@ -3035,6 +3039,13 @@ static bool getColumnAndTagTypeFromInsertJsonFile(
index++; index++;
} }
} }
if (index > MAX_COLUMN_COUNT) {
errorPrint("%s() LN%d, failed to read json, column size overflow, max column size is %d\n",
__func__, __LINE__, MAX_COLUMN_COUNT);
goto PARSE_OVER;
}
superTbls->columnCount = index; superTbls->columnCount = index;
count = 1; count = 1;
...@@ -3099,8 +3110,20 @@ static bool getColumnAndTagTypeFromInsertJsonFile( ...@@ -3099,8 +3110,20 @@ static bool getColumnAndTagTypeFromInsertJsonFile(
index++; index++;
} }
} }
if (index > MAX_TAG_COUNT) {
errorPrint("%s() LN%d, failed to read json, tags size overflow, max tag size is %d\n",
__func__, __LINE__, MAX_TAG_COUNT);
goto PARSE_OVER;
}
superTbls->tagCount = index; superTbls->tagCount = index;
if ((superTbls->columnCount + superTbls->tagCount) > MAX_COLUMN_COUNT) {
errorPrint("%s() LN%d, columns + tags is more than max columns count: %d\n",
__func__, __LINE__, MAX_TAG_COUNT);
goto PARSE_OVER;
}
ret = true; ret = true;
PARSE_OVER: PARSE_OVER:
...@@ -4324,13 +4347,20 @@ static int generateRowData(char* recBuf, int64_t timestamp, SSuperTable* stbInfo ...@@ -4324,13 +4347,20 @@ static int generateRowData(char* recBuf, int64_t timestamp, SSuperTable* stbInfo
"%f, ", rand_double()); "%f, ", rand_double());
} else if (0 == strncasecmp(stbInfo->columns[i].dataType, } else if (0 == strncasecmp(stbInfo->columns[i].dataType,
"smallint", 8)) { "smallint", 8)) {
dataLen += snprintf(pstr + dataLen, maxLen - dataLen, "%d, ", rand_smallint()); dataLen += snprintf(pstr + dataLen, maxLen - dataLen,
} else if (0 == strncasecmp(stbInfo->columns[i].dataType, "tinyint", 7)) { "%d, ", rand_smallint());
dataLen += snprintf(pstr + dataLen, maxLen - dataLen, "%d, ", rand_tinyint()); } else if (0 == strncasecmp(stbInfo->columns[i].dataType,
} else if (0 == strncasecmp(stbInfo->columns[i].dataType, "bool", 4)) { "tinyint", strlen("tinyint"))) {
dataLen += snprintf(pstr + dataLen, maxLen - dataLen, "%d, ", rand_bool()); dataLen += snprintf(pstr + dataLen, maxLen - dataLen,
} else if (0 == strncasecmp(stbInfo->columns[i].dataType, "timestamp", 9)) { "%d, ", rand_tinyint());
dataLen += snprintf(pstr + dataLen, maxLen - dataLen, "%"PRId64", ", rand_bigint()); } else if (0 == strncasecmp(stbInfo->columns[i].dataType,
"bool", strlen("bool"))) {
dataLen += snprintf(pstr + dataLen, maxLen - dataLen,
"%d, ", rand_bool());
} else if (0 == strncasecmp(stbInfo->columns[i].dataType,
"timestamp", strlen("timestamp"))) {
dataLen += snprintf(pstr + dataLen, maxLen - dataLen,
"%"PRId64", ", rand_bigint());
} else { } else {
errorPrint( "No support data type: %s\n", stbInfo->columns[i].dataType); errorPrint( "No support data type: %s\n", stbInfo->columns[i].dataType);
return -1; return -1;
...@@ -4422,7 +4452,8 @@ static int prepareSampleDataForSTable(SSuperTable *superTblInfo) { ...@@ -4422,7 +4452,8 @@ static int prepareSampleDataForSTable(SSuperTable *superTblInfo) {
int ret = readSampleFromCsvFileToMem(superTblInfo); int ret = readSampleFromCsvFileToMem(superTblInfo);
if (0 != ret) { if (0 != ret) {
errorPrint("%s() LN%d, read sample from csv file failed.\n", __func__, __LINE__); errorPrint("%s() LN%d, read sample from csv file failed.\n",
__func__, __LINE__);
tmfree(sampleDataBuf); tmfree(sampleDataBuf);
superTblInfo->sampleDataBuf = NULL; superTblInfo->sampleDataBuf = NULL;
return -1; return -1;
...@@ -4444,7 +4475,8 @@ static int execInsert(threadInfo *pThreadInfo, char *buffer, int k) ...@@ -4444,7 +4475,8 @@ static int execInsert(threadInfo *pThreadInfo, char *buffer, int k)
} else { } else {
if (0 != postProceSql(g_Dbs.host, g_Dbs.port, buffer)) { if (0 != postProceSql(g_Dbs.host, g_Dbs.port, buffer)) {
affectedRows = -1; affectedRows = -1;
printf("========restful return fail, threadID[%d]\n", pThreadInfo->threadID); printf("========restful return fail, threadID[%d]\n",
pThreadInfo->threadID);
} else { } else {
affectedRows = k; affectedRows = k;
} }
...@@ -4601,7 +4633,8 @@ static int generateSQLHead(char *tableName, int32_t tableSeq, ...@@ -4601,7 +4633,8 @@ static int generateSQLHead(char *tableName, int32_t tableSeq,
tableSeq % superTblInfo->tagSampleCount); tableSeq % superTblInfo->tagSampleCount);
} }
if (NULL == tagsValBuf) { if (NULL == tagsValBuf) {
errorPrint("%s() LN%d, tag buf failed to allocate memory\n", __func__, __LINE__); errorPrint("%s() LN%d, tag buf failed to allocate memory\n",
__func__, __LINE__);
return -1; return -1;
} }
...@@ -4703,11 +4736,11 @@ static void* syncWriteInterlace(threadInfo *pThreadInfo) { ...@@ -4703,11 +4736,11 @@ static void* syncWriteInterlace(threadInfo *pThreadInfo) {
// TODO: prompt tbl count multple interlace rows and batch // TODO: prompt tbl count multple interlace rows and batch
// //
char* buffer = calloc(superTblInfo?superTblInfo->maxSqlLen:g_args.max_sql_len, 1); int maxSqlLen = superTblInfo?superTblInfo->maxSqlLen:g_args.max_sql_len;
char* buffer = calloc(maxSqlLen, 1);
if (NULL == buffer) { if (NULL == buffer) {
errorPrint( "Failed to alloc %d Bytes, reason:%s\n", errorPrint( "%s() LN%d, Failed to alloc %d Bytes, reason:%s\n",
superTblInfo?superTblInfo->maxSqlLen:g_args.max_sql_len, __func__, __LINE__, maxSqlLen, strerror(errno));
strerror(errno));
return NULL; return NULL;
} }
...@@ -4755,7 +4788,6 @@ static void* syncWriteInterlace(threadInfo *pThreadInfo) { ...@@ -4755,7 +4788,6 @@ static void* syncWriteInterlace(threadInfo *pThreadInfo) {
bool flagSleep = true; bool flagSleep = true;
int sleepTimeTotal = 0; int sleepTimeTotal = 0;
int maxSqlLen = superTblInfo?superTblInfo->maxSqlLen:g_args.max_sql_len;
int remainderBufLen; int remainderBufLen;
while(pThreadInfo->totalInsertRows < pThreadInfo->ntables * insertRows) { while(pThreadInfo->totalInsertRows < pThreadInfo->ntables * insertRows) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册