提交 df73e693 编写于 作者: F freemine

Merge remote-tracking branch 'upstream/develop' into odbc2

...@@ -120,7 +120,7 @@ TDengine是一个高效的存储、查询、分析时序大数据的平台,专 ...@@ -120,7 +120,7 @@ TDengine是一个高效的存储、查询、分析时序大数据的平台,专
* [TDengine性能对比测试工具](https://www.taosdata.com/blog/2020/01/18/1166.html) * [TDengine性能对比测试工具](https://www.taosdata.com/blog/2020/01/18/1166.html)
* [IDEA数据库管理工具可视化使用TDengine](https://www.taosdata.com/blog/2020/08/27/1767.html) * [IDEA数据库管理工具可视化使用TDengine](https://www.taosdata.com/blog/2020/08/27/1767.html)
* [基于eletron开发的跨平台TDengine图形化管理工具](https://github.com/skye0207/TDengineGUI) * [基于eletron开发的跨平台TDengine图形化管理工具](https://github.com/skye0207/TDengineGUI)
* [DataX,支持TDengine的离线数据采集/同步工具](https://github.com/wgzhao/DataX)(文档:[读取插件](https://github.com/wgzhao/DataX/blob/master/docs/src/main/sphinx/reader/tdenginereader.md)[写入插件](https://github.com/wgzhao/DataX/blob/master/docs/src/main/sphinx/writer/tdenginewriter.md) * [DataX,支持TDengine的离线数据采集/同步工具](https://github.com/alibaba/DataX)
## TDengine与其他数据库的对比测试 ## TDengine与其他数据库的对比测试
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
"confirm_parameter_prompt": "no", "confirm_parameter_prompt": "no",
"insert_interval": 0, "insert_interval": 0,
"num_of_records_per_req": 100, "num_of_records_per_req": 100,
"max_sql_len": 1024000,
"databases": [{ "databases": [{
"dbinfo": { "dbinfo": {
"name": "db", "name": "db",
...@@ -38,7 +39,9 @@ ...@@ -38,7 +39,9 @@
"auto_create_table": "no", "auto_create_table": "no",
"data_source": "rand", "data_source": "rand",
"insert_mode": "taosc", "insert_mode": "taosc",
"insert_rows": 100000, "childtable_limit": 33,
"childtable_offset": 33,
"insert_rows": 1000,
"multi_thread_write_one_tbl": "no", "multi_thread_write_one_tbl": "no",
"number_of_tbl_in_one_sql": 0, "number_of_tbl_in_one_sql": 0,
"rows_per_tbl": 100, "rows_per_tbl": 100,
......
...@@ -98,6 +98,8 @@ extern char configDir[]; ...@@ -98,6 +98,8 @@ extern char configDir[];
#define MAX_DATABASE_COUNT 256 #define MAX_DATABASE_COUNT 256
#define INPUT_BUF_LEN 256 #define INPUT_BUF_LEN 256
#define DEFAULT_TIMESTAMP_STEP 10
typedef enum CREATE_SUB_TALBE_MOD_EN { typedef enum CREATE_SUB_TALBE_MOD_EN {
PRE_CREATE_SUBTBL, PRE_CREATE_SUBTBL,
AUTO_CREATE_SUBTBL, AUTO_CREATE_SUBTBL,
...@@ -196,6 +198,7 @@ typedef struct SArguments_S { ...@@ -196,6 +198,7 @@ typedef struct SArguments_S {
int num_of_threads; int num_of_threads;
int insert_interval; int insert_interval;
int num_of_RPR; int num_of_RPR;
int max_sql_len;
int num_of_tables; int num_of_tables;
int num_of_DPT; int num_of_DPT;
int abort; int abort;
...@@ -222,6 +225,8 @@ typedef struct SSuperTable_S { ...@@ -222,6 +225,8 @@ typedef struct SSuperTable_S {
char childTblPrefix[MAX_TB_NAME_SIZE]; char childTblPrefix[MAX_TB_NAME_SIZE];
char dataSource[MAX_TB_NAME_SIZE+1]; // rand_gen or sample char dataSource[MAX_TB_NAME_SIZE+1]; // rand_gen or sample
char insertMode[MAX_TB_NAME_SIZE]; // taosc, restful char insertMode[MAX_TB_NAME_SIZE]; // taosc, restful
int childTblLimit;
int childTblOffset;
int multiThreadWriteOneTbl; // 0: no, 1: yes int multiThreadWriteOneTbl; // 0: no, 1: yes
int numberOfTblInOneSql; // 0/1: one table, > 1: number of tbl int numberOfTblInOneSql; // 0/1: one table, > 1: number of tbl
...@@ -259,7 +264,7 @@ typedef struct SSuperTable_S { ...@@ -259,7 +264,7 @@ typedef struct SSuperTable_S {
int tagUsePos; int tagUsePos;
// statistics // statistics
int64_t totalRowsInserted; int64_t totalInsertRows;
int64_t totalAffectedRows; int64_t totalAffectedRows;
} SSuperTable; } SSuperTable;
...@@ -329,7 +334,7 @@ typedef struct SDbs_S { ...@@ -329,7 +334,7 @@ typedef struct SDbs_S {
SDataBase db[MAX_DB_COUNT]; SDataBase db[MAX_DB_COUNT];
// statistics // statistics
int64_t totalRowsInserted; int64_t totalInsertRows;
int64_t totalAffectedRows; int64_t totalAffectedRows;
} SDbs; } SDbs;
...@@ -400,7 +405,7 @@ typedef struct SThreadInfo_S { ...@@ -400,7 +405,7 @@ typedef struct SThreadInfo_S {
int64_t lastTs; int64_t lastTs;
// statistics // statistics
int64_t totalRowsInserted; int64_t totalInsertRows;
int64_t totalAffectedRows; int64_t totalAffectedRows;
// insert delay statistics // insert delay statistics
...@@ -514,6 +519,7 @@ SArguments g_args = { ...@@ -514,6 +519,7 @@ SArguments g_args = {
10, // num_of_connections/thread 10, // num_of_connections/thread
0, // insert_interval 0, // insert_interval
100, // num_of_RPR 100, // num_of_RPR
TSDB_PAYLOAD_SIZE, // max_sql_len
10000, // num_of_tables 10000, // num_of_tables
10000, // num_of_DPT 10000, // num_of_DPT
0, // abort 0, // abort
...@@ -761,6 +767,8 @@ void parse_args(int argc, char *argv[], SArguments *arguments) { ...@@ -761,6 +767,8 @@ void parse_args(int argc, char *argv[], SArguments *arguments) {
} }
printf("# Insertion interval: %d\n", arguments->insert_interval); printf("# Insertion interval: %d\n", arguments->insert_interval);
printf("# Number of records per req: %d\n", arguments->num_of_RPR); printf("# Number of records per req: %d\n", arguments->num_of_RPR);
printf("# Max SQL length: %d\n", arguments->max_sql_len);
printf("# Length of Binary: %d\n", arguments->len_of_binary);
printf("# Number of Threads: %d\n", arguments->num_of_threads); printf("# Number of Threads: %d\n", arguments->num_of_threads);
printf("# Number of Tables: %d\n", arguments->num_of_tables); printf("# Number of Tables: %d\n", arguments->num_of_tables);
printf("# Number of Data per Table: %d\n", arguments->num_of_DPT); printf("# Number of Data per Table: %d\n", arguments->num_of_DPT);
...@@ -774,6 +782,7 @@ void parse_args(int argc, char *argv[], SArguments *arguments) { ...@@ -774,6 +782,7 @@ void parse_args(int argc, char *argv[], SArguments *arguments) {
printf("# Delete method: %d\n", arguments->method_of_delete); printf("# Delete method: %d\n", arguments->method_of_delete);
printf("# Answer yes when prompt: %d\n", arguments->answer_yes); printf("# Answer yes when prompt: %d\n", arguments->answer_yes);
printf("# Print debug info: %d\n", arguments->debug_print); printf("# Print debug info: %d\n", arguments->debug_print);
printf("# Print verbose info: %d\n", arguments->verbose_print);
printf("###################################################################\n"); printf("###################################################################\n");
if (!arguments->answer_yes) { if (!arguments->answer_yes) {
printf("Press enter key to continue\n\n"); printf("Press enter key to continue\n\n");
...@@ -1006,6 +1015,7 @@ static int printfInsertMeta() { ...@@ -1006,6 +1015,7 @@ static int printfInsertMeta() {
printf("thread num of create table: \033[33m%d\033[0m\n", g_Dbs.threadCountByCreateTbl); printf("thread num of create table: \033[33m%d\033[0m\n", g_Dbs.threadCountByCreateTbl);
printf("insert interval: \033[33m%d\033[0m\n", g_args.insert_interval); printf("insert interval: \033[33m%d\033[0m\n", g_args.insert_interval);
printf("number of records per req: \033[33m%d\033[0m\n", g_args.num_of_RPR); printf("number of records per req: \033[33m%d\033[0m\n", g_args.num_of_RPR);
printf("max sql length: \033[33m%d\033[0m\n", g_args.max_sql_len);
printf("database count: \033[33m%d\033[0m\n", g_Dbs.dbCount); printf("database count: \033[33m%d\033[0m\n", g_Dbs.dbCount);
for (int i = 0; i < g_Dbs.dbCount; i++) { for (int i = 0; i < g_Dbs.dbCount; i++) {
...@@ -1090,6 +1100,12 @@ static int printfInsertMeta() { ...@@ -1090,6 +1100,12 @@ static int printfInsertMeta() {
printf(" childTblPrefix: \033[33m%s\033[0m\n", g_Dbs.db[i].superTbls[j].childTblPrefix); printf(" childTblPrefix: \033[33m%s\033[0m\n", g_Dbs.db[i].superTbls[j].childTblPrefix);
printf(" dataSource: \033[33m%s\033[0m\n", g_Dbs.db[i].superTbls[j].dataSource); printf(" dataSource: \033[33m%s\033[0m\n", g_Dbs.db[i].superTbls[j].dataSource);
printf(" insertMode: \033[33m%s\033[0m\n", g_Dbs.db[i].superTbls[j].insertMode); printf(" insertMode: \033[33m%s\033[0m\n", g_Dbs.db[i].superTbls[j].insertMode);
if (g_Dbs.db[i].superTbls[j].childTblLimit > 0) {
printf(" childTblLimit: \033[33m%d\033[0m\n", g_Dbs.db[i].superTbls[j].childTblLimit);
}
if (g_Dbs.db[i].superTbls[j].childTblOffset > 0) {
printf(" childTblOffset: \033[33m%d\033[0m\n", g_Dbs.db[i].superTbls[j].childTblOffset);
}
printf(" insertRows: \033[33m%"PRId64"\033[0m\n", g_Dbs.db[i].superTbls[j].insertRows); printf(" insertRows: \033[33m%"PRId64"\033[0m\n", g_Dbs.db[i].superTbls[j].insertRows);
if (0 == g_Dbs.db[i].superTbls[j].multiThreadWriteOneTbl) { if (0 == g_Dbs.db[i].superTbls[j].multiThreadWriteOneTbl) {
...@@ -1097,25 +1113,37 @@ static int printfInsertMeta() { ...@@ -1097,25 +1113,37 @@ static int printfInsertMeta() {
}else { }else {
printf(" multiThreadWriteOneTbl: \033[33myes\033[0m\n"); printf(" multiThreadWriteOneTbl: \033[33myes\033[0m\n");
} }
printf(" numberOfTblInOneSql: \033[33m%d\033[0m\n", g_Dbs.db[i].superTbls[j].numberOfTblInOneSql); printf(" numberOfTblInOneSql: \033[33m%d\033[0m\n",
printf(" rowsPerTbl: \033[33m%d\033[0m\n", g_Dbs.db[i].superTbls[j].rowsPerTbl); g_Dbs.db[i].superTbls[j].numberOfTblInOneSql);
printf(" disorderRange: \033[33m%d\033[0m\n", g_Dbs.db[i].superTbls[j].disorderRange); printf(" rowsPerTbl: \033[33m%d\033[0m\n",
printf(" disorderRatio: \033[33m%d\033[0m\n", g_Dbs.db[i].superTbls[j].disorderRatio); g_Dbs.db[i].superTbls[j].rowsPerTbl);
printf(" maxSqlLen: \033[33m%d\033[0m\n", g_Dbs.db[i].superTbls[j].maxSqlLen); printf(" disorderRange: \033[33m%d\033[0m\n",
g_Dbs.db[i].superTbls[j].disorderRange);
printf(" timeStampStep: \033[33m%d\033[0m\n", g_Dbs.db[i].superTbls[j].timeStampStep); printf(" disorderRatio: \033[33m%d\033[0m\n",
printf(" startTimestamp: \033[33m%s\033[0m\n", g_Dbs.db[i].superTbls[j].startTimestamp); g_Dbs.db[i].superTbls[j].disorderRatio);
printf(" sampleFormat: \033[33m%s\033[0m\n", g_Dbs.db[i].superTbls[j].sampleFormat); printf(" maxSqlLen: \033[33m%d\033[0m\n",
printf(" sampleFile: \033[33m%s\033[0m\n", g_Dbs.db[i].superTbls[j].sampleFile); g_Dbs.db[i].superTbls[j].maxSqlLen);
printf(" tagsFile: \033[33m%s\033[0m\n", g_Dbs.db[i].superTbls[j].tagsFile); printf(" timeStampStep: \033[33m%d\033[0m\n",
g_Dbs.db[i].superTbls[j].timeStampStep);
printf(" columnCount: \033[33m%d\033[0m\n ", g_Dbs.db[i].superTbls[j].columnCount); printf(" startTimestamp: \033[33m%s\033[0m\n",
g_Dbs.db[i].superTbls[j].startTimestamp);
printf(" sampleFormat: \033[33m%s\033[0m\n",
g_Dbs.db[i].superTbls[j].sampleFormat);
printf(" sampleFile: \033[33m%s\033[0m\n",
g_Dbs.db[i].superTbls[j].sampleFile);
printf(" tagsFile: \033[33m%s\033[0m\n",
g_Dbs.db[i].superTbls[j].tagsFile);
printf(" columnCount: \033[33m%d\033[0m\n ",
g_Dbs.db[i].superTbls[j].columnCount);
for (int k = 0; k < g_Dbs.db[i].superTbls[j].columnCount; k++) { for (int k = 0; k < g_Dbs.db[i].superTbls[j].columnCount; k++) {
//printf("dataType:%s, dataLen:%d\t", g_Dbs.db[i].superTbls[j].columns[k].dataType, g_Dbs.db[i].superTbls[j].columns[k].dataLen); //printf("dataType:%s, dataLen:%d\t", g_Dbs.db[i].superTbls[j].columns[k].dataType, g_Dbs.db[i].superTbls[j].columns[k].dataLen);
if ((0 == strncasecmp(g_Dbs.db[i].superTbls[j].columns[k].dataType, "binary", 6)) if ((0 == strncasecmp(g_Dbs.db[i].superTbls[j].columns[k].dataType,
|| (0 == strncasecmp(g_Dbs.db[i].superTbls[j].columns[k].dataType, "nchar", 5))) { "binary", 6))
|| (0 == strncasecmp(g_Dbs.db[i].superTbls[j].columns[k].dataType,
"nchar", 5))) {
printf("column[\033[33m%d\033[0m]:\033[33m%s(%d)\033[0m ", k, printf("column[\033[33m%d\033[0m]:\033[33m%s(%d)\033[0m ", k,
g_Dbs.db[i].superTbls[j].columns[k].dataType, g_Dbs.db[i].superTbls[j].columns[k].dataLen); g_Dbs.db[i].superTbls[j].columns[k].dataType,
g_Dbs.db[i].superTbls[j].columns[k].dataLen);
} else { } else {
printf("column[%d]:\033[33m%s\033[0m ", k, printf("column[%d]:\033[33m%s\033[0m ", k,
g_Dbs.db[i].superTbls[j].columns[k].dataType); g_Dbs.db[i].superTbls[j].columns[k].dataType);
...@@ -1130,7 +1158,8 @@ static int printfInsertMeta() { ...@@ -1130,7 +1158,8 @@ static int printfInsertMeta() {
if ((0 == strncasecmp(g_Dbs.db[i].superTbls[j].tags[k].dataType, "binary", 6)) if ((0 == strncasecmp(g_Dbs.db[i].superTbls[j].tags[k].dataType, "binary", 6))
|| (0 == strncasecmp(g_Dbs.db[i].superTbls[j].tags[k].dataType, "nchar", 5))) { || (0 == strncasecmp(g_Dbs.db[i].superTbls[j].tags[k].dataType, "nchar", 5))) {
printf("tag[%d]:\033[33m%s(%d)\033[0m ", k, printf("tag[%d]:\033[33m%s(%d)\033[0m ", k,
g_Dbs.db[i].superTbls[j].tags[k].dataType, g_Dbs.db[i].superTbls[j].tags[k].dataLen); g_Dbs.db[i].superTbls[j].tags[k].dataType,
g_Dbs.db[i].superTbls[j].tags[k].dataLen);
} else { } else {
printf("tag[%d]:\033[33m%s\033[0m ", k, printf("tag[%d]:\033[33m%s\033[0m ", k,
g_Dbs.db[i].superTbls[j].tags[k].dataType); g_Dbs.db[i].superTbls[j].tags[k].dataType);
...@@ -1768,8 +1797,7 @@ int postProceSql(char* host, uint16_t port, char* sqlstr) ...@@ -1768,8 +1797,7 @@ int postProceSql(char* host, uint16_t port, char* sqlstr)
return 0; return 0;
} }
static char* getTagValueFromTagSample(SSuperTable* stbInfo, int tagUsePos) {
char* getTagValueFromTagSample( SSuperTable* stbInfo, int tagUsePos) {
char* dataBuf = (char*)calloc(TSDB_MAX_SQL_LEN+1, 1); char* dataBuf = (char*)calloc(TSDB_MAX_SQL_LEN+1, 1);
if (NULL == dataBuf) { if (NULL == dataBuf) {
printf("calloc failed! size:%d\n", TSDB_MAX_SQL_LEN+1); printf("calloc failed! size:%d\n", TSDB_MAX_SQL_LEN+1);
...@@ -1777,12 +1805,13 @@ char* getTagValueFromTagSample( SSuperTable* stbInfo, int tagUsePos) { ...@@ -1777,12 +1805,13 @@ char* getTagValueFromTagSample( SSuperTable* stbInfo, int tagUsePos) {
} }
int dataLen = 0; int dataLen = 0;
dataLen += snprintf(dataBuf + dataLen, TSDB_MAX_SQL_LEN - dataLen, "(%s)", stbInfo->tagDataBuf + stbInfo->lenOfTagOfOneRow * tagUsePos); dataLen += snprintf(dataBuf + dataLen, TSDB_MAX_SQL_LEN - dataLen,
"(%s)", stbInfo->tagDataBuf + stbInfo->lenOfTagOfOneRow * tagUsePos);
return dataBuf; return dataBuf;
} }
char* generateTagVaulesForStb(SSuperTable* stbInfo) { static char* generateTagVaulesForStb(SSuperTable* stbInfo) {
char* dataBuf = (char*)calloc(TSDB_MAX_SQL_LEN+1, 1); char* dataBuf = (char*)calloc(TSDB_MAX_SQL_LEN+1, 1);
if (NULL == dataBuf) { if (NULL == dataBuf) {
printf("calloc failed! size:%d\n", TSDB_MAX_SQL_LEN+1); printf("calloc failed! size:%d\n", TSDB_MAX_SQL_LEN+1);
...@@ -1792,9 +1821,11 @@ char* generateTagVaulesForStb(SSuperTable* stbInfo) { ...@@ -1792,9 +1821,11 @@ char* generateTagVaulesForStb(SSuperTable* stbInfo) {
int dataLen = 0; int dataLen = 0;
dataLen += snprintf(dataBuf + dataLen, TSDB_MAX_SQL_LEN - dataLen, "("); dataLen += snprintf(dataBuf + dataLen, TSDB_MAX_SQL_LEN - dataLen, "(");
for (int i = 0; i < stbInfo->tagCount; i++) { for (int i = 0; i < stbInfo->tagCount; i++) {
if ((0 == strncasecmp(stbInfo->tags[i].dataType, "binary", 6)) || (0 == strncasecmp(stbInfo->tags[i].dataType, "nchar", 5))) { if ((0 == strncasecmp(stbInfo->tags[i].dataType, "binary", strlen("binary")))
|| (0 == strncasecmp(stbInfo->tags[i].dataType, "nchar", strlen("nchar")))) {
if (stbInfo->tags[i].dataLen > TSDB_MAX_BINARY_LEN) { if (stbInfo->tags[i].dataLen > TSDB_MAX_BINARY_LEN) {
printf("binary or nchar length overflow, max size:%u\n", (uint32_t)TSDB_MAX_BINARY_LEN); printf("binary or nchar length overflow, max size:%u\n",
(uint32_t)TSDB_MAX_BINARY_LEN);
tmfree(dataBuf); tmfree(dataBuf);
return NULL; return NULL;
} }
...@@ -1806,30 +1837,48 @@ char* generateTagVaulesForStb(SSuperTable* stbInfo) { ...@@ -1806,30 +1837,48 @@ char* generateTagVaulesForStb(SSuperTable* stbInfo) {
return NULL; return NULL;
} }
rand_string(buf, stbInfo->tags[i].dataLen); rand_string(buf, stbInfo->tags[i].dataLen);
dataLen += snprintf(dataBuf + dataLen, TSDB_MAX_SQL_LEN - dataLen, "\'%s\', ", buf); dataLen += snprintf(dataBuf + dataLen, TSDB_MAX_SQL_LEN - dataLen,
"\'%s\', ", buf);
tmfree(buf); tmfree(buf);
} else if (0 == strncasecmp(stbInfo->tags[i].dataType, "int", 3)) { } else if (0 == strncasecmp(stbInfo->tags[i].dataType,
dataLen += snprintf(dataBuf + dataLen, TSDB_MAX_SQL_LEN - dataLen, "%d, ", rand_int()); "int", strlen("int"))) {
} else if (0 == strncasecmp(stbInfo->tags[i].dataType, "bigint", 6)) { dataLen += snprintf(dataBuf + dataLen, TSDB_MAX_SQL_LEN - dataLen,
dataLen += snprintf(dataBuf + dataLen, TSDB_MAX_SQL_LEN - dataLen, "%"PRId64", ", rand_bigint()); "%d, ", rand_int());
} else if (0 == strncasecmp(stbInfo->tags[i].dataType, "float", 5)) { } else if (0 == strncasecmp(stbInfo->tags[i].dataType,
dataLen += snprintf(dataBuf + dataLen, TSDB_MAX_SQL_LEN - dataLen, "%f, ", rand_float()); "bigint", strlen("bigint"))) {
} else if (0 == strncasecmp(stbInfo->tags[i].dataType, "double", 6)) { dataLen += snprintf(dataBuf + dataLen, TSDB_MAX_SQL_LEN - dataLen,
dataLen += snprintf(dataBuf + dataLen, TSDB_MAX_SQL_LEN - dataLen, "%f, ", rand_double()); "%"PRId64", ", rand_bigint());
} else if (0 == strncasecmp(stbInfo->tags[i].dataType, "smallint", 8)) { } else if (0 == strncasecmp(stbInfo->tags[i].dataType,
dataLen += snprintf(dataBuf + dataLen, TSDB_MAX_SQL_LEN - dataLen, "%d, ", rand_smallint()); "float", strlen("float"))) {
} else if (0 == strncasecmp(stbInfo->tags[i].dataType, "tinyint", 7)) { dataLen += snprintf(dataBuf + dataLen, TSDB_MAX_SQL_LEN - dataLen,
dataLen += snprintf(dataBuf + dataLen, TSDB_MAX_SQL_LEN - dataLen, "%d, ", rand_tinyint()); "%f, ", rand_float());
} else if (0 == strncasecmp(stbInfo->tags[i].dataType, "bool", 4)) { } else if (0 == strncasecmp(stbInfo->tags[i].dataType,
dataLen += snprintf(dataBuf + dataLen, TSDB_MAX_SQL_LEN - dataLen, "%d, ", rand_bool()); "double", strlen("double"))) {
} else if (0 == strncasecmp(stbInfo->tags[i].dataType, "timestamp", 4)) { dataLen += snprintf(dataBuf + dataLen, TSDB_MAX_SQL_LEN - dataLen,
dataLen += snprintf(dataBuf + dataLen, TSDB_MAX_SQL_LEN - dataLen, "%"PRId64", ", rand_bigint()); "%f, ", rand_double());
} else if (0 == strncasecmp(stbInfo->tags[i].dataType,
"smallint", strlen("smallint"))) {
dataLen += snprintf(dataBuf + dataLen, TSDB_MAX_SQL_LEN - dataLen,
"%d, ", rand_smallint());
} else if (0 == strncasecmp(stbInfo->tags[i].dataType,
"tinyint", strlen("tinyint"))) {
dataLen += snprintf(dataBuf + dataLen, TSDB_MAX_SQL_LEN - dataLen,
"%d, ", rand_tinyint());
} else if (0 == strncasecmp(stbInfo->tags[i].dataType,
"bool", strlen("bool"))) {
dataLen += snprintf(dataBuf + dataLen, TSDB_MAX_SQL_LEN - dataLen,
"%d, ", rand_bool());
} else if (0 == strncasecmp(stbInfo->tags[i].dataType,
"timestamp", strlen("timestamp"))) {
dataLen += snprintf(dataBuf + dataLen, TSDB_MAX_SQL_LEN - dataLen,
"%"PRId64", ", rand_bigint());
} else { } else {
printf("No support data type: %s\n", stbInfo->tags[i].dataType); printf("No support data type: %s\n", stbInfo->tags[i].dataType);
tmfree(dataBuf); tmfree(dataBuf);
return NULL; return NULL;
} }
} }
dataLen -= 2; dataLen -= 2;
dataLen += snprintf(dataBuf + dataLen, TSDB_MAX_SQL_LEN - dataLen, ")"); dataLen += snprintf(dataBuf + dataLen, TSDB_MAX_SQL_LEN - dataLen, ")");
return dataBuf; return dataBuf;
...@@ -1905,15 +1954,25 @@ static int calcRowLen(SSuperTable* superTbls) { ...@@ -1905,15 +1954,25 @@ static int calcRowLen(SSuperTable* superTbls) {
} }
static int getAllChildNameOfSuperTable(TAOS * taos, char* dbName, char* sTblName, char** childTblNameOfSuperTbl, int* childTblCountOfSuperTbl) { static int getChildNameOfSuperTableWithLimitAndOffset(TAOS * taos,
char* dbName, char* sTblName, char** childTblNameOfSuperTbl,
int* childTblCountOfSuperTbl, int limit, int offset) {
char command[BUFFER_SIZE] = "\0"; char command[BUFFER_SIZE] = "\0";
char limitBuf[100] = "\0";
TAOS_RES * res; TAOS_RES * res;
TAOS_ROW row = NULL; TAOS_ROW row = NULL;
char* childTblName = *childTblNameOfSuperTbl; char* childTblName = *childTblNameOfSuperTbl;
if (offset >= 0) {
snprintf(limitBuf, 100, " limit %d offset %d", limit, offset);
}
//get all child table name use cmd: select tbname from superTblName; //get all child table name use cmd: select tbname from superTblName;
snprintf(command, BUFFER_SIZE, "select tbname from %s.%s", dbName, sTblName); snprintf(command, BUFFER_SIZE, "select tbname from %s.%s %s", dbName, sTblName, limitBuf);
res = taos_query(taos, command); res = taos_query(taos, command);
int32_t code = taos_errno(res); int32_t code = taos_errno(res);
if (code != 0) { if (code != 0) {
...@@ -1923,7 +1982,7 @@ static int getAllChildNameOfSuperTable(TAOS * taos, char* dbName, char* sTblName ...@@ -1923,7 +1982,7 @@ static int getAllChildNameOfSuperTable(TAOS * taos, char* dbName, char* sTblName
exit(-1); exit(-1);
} }
int childTblCount = 10000; int childTblCount = (limit < 0)?10000:limit;
int count = 0; int count = 0;
childTblName = (char*)calloc(1, childTblCount * TSDB_TABLE_NAME_LEN); childTblName = (char*)calloc(1, childTblCount * TSDB_TABLE_NAME_LEN);
char* pTblName = childTblName; char* pTblName = childTblName;
...@@ -1937,7 +1996,8 @@ static int getAllChildNameOfSuperTable(TAOS * taos, char* dbName, char* sTblName ...@@ -1937,7 +1996,8 @@ static int getAllChildNameOfSuperTable(TAOS * taos, char* dbName, char* sTblName
if (tmp != NULL) { if (tmp != NULL) {
childTblName = tmp; childTblName = tmp;
childTblCount = (int)(childTblCount*1.5); childTblCount = (int)(childTblCount*1.5);
memset(childTblName + count*TSDB_TABLE_NAME_LEN, 0, (size_t)((childTblCount-count)*TSDB_TABLE_NAME_LEN)); memset(childTblName + count*TSDB_TABLE_NAME_LEN, 0,
(size_t)((childTblCount-count)*TSDB_TABLE_NAME_LEN));
} else { } else {
// exit, if allocate more memory failed // exit, if allocate more memory failed
printf("realloc fail for save child table name of %s.%s\n", dbName, sTblName); printf("realloc fail for save child table name of %s.%s\n", dbName, sTblName);
...@@ -1957,7 +2017,17 @@ static int getAllChildNameOfSuperTable(TAOS * taos, char* dbName, char* sTblName ...@@ -1957,7 +2017,17 @@ static int getAllChildNameOfSuperTable(TAOS * taos, char* dbName, char* sTblName
return 0; return 0;
} }
static int getSuperTableFromServer(TAOS * taos, char* dbName, SSuperTable* superTbls) { static int getAllChildNameOfSuperTable(TAOS * taos, char* dbName,
char* sTblName, char** childTblNameOfSuperTbl,
int* childTblCountOfSuperTbl) {
return getChildNameOfSuperTableWithLimitAndOffset(taos, dbName, sTblName,
childTblNameOfSuperTbl, childTblCountOfSuperTbl,
-1, -1);
}
static int getSuperTableFromServer(TAOS * taos, char* dbName,
SSuperTable* superTbls) {
char command[BUFFER_SIZE] = "\0"; char command[BUFFER_SIZE] = "\0";
TAOS_RES * res; TAOS_RES * res;
TAOS_ROW row = NULL; TAOS_ROW row = NULL;
...@@ -1983,16 +2053,30 @@ static int getSuperTableFromServer(TAOS * taos, char* dbName, SSuperTable* supe ...@@ -1983,16 +2053,30 @@ static int getSuperTableFromServer(TAOS * taos, char* dbName, SSuperTable* supe
} }
if (strcmp((char *)row[TSDB_DESCRIBE_METRIC_NOTE_INDEX], "TAG") == 0) { if (strcmp((char *)row[TSDB_DESCRIBE_METRIC_NOTE_INDEX], "TAG") == 0) {
tstrncpy(superTbls->tags[tagIndex].field, (char *)row[TSDB_DESCRIBE_METRIC_FIELD_INDEX], fields[TSDB_DESCRIBE_METRIC_FIELD_INDEX].bytes); tstrncpy(superTbls->tags[tagIndex].field,
tstrncpy(superTbls->tags[tagIndex].dataType, (char *)row[TSDB_DESCRIBE_METRIC_TYPE_INDEX], fields[TSDB_DESCRIBE_METRIC_TYPE_INDEX].bytes); (char *)row[TSDB_DESCRIBE_METRIC_FIELD_INDEX],
superTbls->tags[tagIndex].dataLen = *((int *)row[TSDB_DESCRIBE_METRIC_LENGTH_INDEX]); fields[TSDB_DESCRIBE_METRIC_FIELD_INDEX].bytes);
tstrncpy(superTbls->tags[tagIndex].note, (char *)row[TSDB_DESCRIBE_METRIC_NOTE_INDEX], fields[TSDB_DESCRIBE_METRIC_NOTE_INDEX].bytes); tstrncpy(superTbls->tags[tagIndex].dataType,
(char *)row[TSDB_DESCRIBE_METRIC_TYPE_INDEX],
fields[TSDB_DESCRIBE_METRIC_TYPE_INDEX].bytes);
superTbls->tags[tagIndex].dataLen =
*((int *)row[TSDB_DESCRIBE_METRIC_LENGTH_INDEX]);
tstrncpy(superTbls->tags[tagIndex].note,
(char *)row[TSDB_DESCRIBE_METRIC_NOTE_INDEX],
fields[TSDB_DESCRIBE_METRIC_NOTE_INDEX].bytes);
tagIndex++; tagIndex++;
} else { } else {
tstrncpy(superTbls->columns[columnIndex].field, (char *)row[TSDB_DESCRIBE_METRIC_FIELD_INDEX], fields[TSDB_DESCRIBE_METRIC_FIELD_INDEX].bytes); tstrncpy(superTbls->columns[columnIndex].field,
tstrncpy(superTbls->columns[columnIndex].dataType, (char *)row[TSDB_DESCRIBE_METRIC_TYPE_INDEX], fields[TSDB_DESCRIBE_METRIC_TYPE_INDEX].bytes); (char *)row[TSDB_DESCRIBE_METRIC_FIELD_INDEX],
superTbls->columns[columnIndex].dataLen = *((int *)row[TSDB_DESCRIBE_METRIC_LENGTH_INDEX]); fields[TSDB_DESCRIBE_METRIC_FIELD_INDEX].bytes);
tstrncpy(superTbls->columns[columnIndex].note, (char *)row[TSDB_DESCRIBE_METRIC_NOTE_INDEX], fields[TSDB_DESCRIBE_METRIC_NOTE_INDEX].bytes); tstrncpy(superTbls->columns[columnIndex].dataType,
(char *)row[TSDB_DESCRIBE_METRIC_TYPE_INDEX],
fields[TSDB_DESCRIBE_METRIC_TYPE_INDEX].bytes);
superTbls->columns[columnIndex].dataLen =
*((int *)row[TSDB_DESCRIBE_METRIC_LENGTH_INDEX]);
tstrncpy(superTbls->columns[columnIndex].note,
(char *)row[TSDB_DESCRIBE_METRIC_NOTE_INDEX],
fields[TSDB_DESCRIBE_METRIC_NOTE_INDEX].bytes);
columnIndex++; columnIndex++;
} }
count++; count++;
...@@ -2006,7 +2090,10 @@ static int getSuperTableFromServer(TAOS * taos, char* dbName, SSuperTable* supe ...@@ -2006,7 +2090,10 @@ static int getSuperTableFromServer(TAOS * taos, char* dbName, SSuperTable* supe
if (TBL_ALREADY_EXISTS == superTbls->childTblExists) { if (TBL_ALREADY_EXISTS == superTbls->childTblExists) {
//get all child table name use cmd: select tbname from superTblName; //get all child table name use cmd: select tbname from superTblName;
getAllChildNameOfSuperTable(taos, dbName, superTbls->sTblName, &superTbls->childTblName, &superTbls->childTblCount); getAllChildNameOfSuperTable(taos, dbName,
superTbls->sTblName,
&superTbls->childTblName,
&superTbls->childTblCount);
} }
return 0; return 0;
} }
...@@ -2087,31 +2174,40 @@ static int createSuperTable(TAOS * taos, char* dbName, SSuperTable* superTbls, ...@@ -2087,31 +2174,40 @@ static int createSuperTable(TAOS * taos, char* dbName, SSuperTable* superTbls,
char* dataType = superTbls->tags[tagIndex].dataType; char* dataType = superTbls->tags[tagIndex].dataType;
if (strcasecmp(dataType, "BINARY") == 0) { if (strcasecmp(dataType, "BINARY") == 0) {
len += snprintf(tags + len, STRING_LEN - len, "t%d %s(%d), ", tagIndex, "BINARY", superTbls->tags[tagIndex].dataLen); len += snprintf(tags + len, STRING_LEN - len, "t%d %s(%d), ", tagIndex,
"BINARY", superTbls->tags[tagIndex].dataLen);
lenOfTagOfOneRow += superTbls->tags[tagIndex].dataLen + 3; lenOfTagOfOneRow += superTbls->tags[tagIndex].dataLen + 3;
} else if (strcasecmp(dataType, "NCHAR") == 0) { } else if (strcasecmp(dataType, "NCHAR") == 0) {
len += snprintf(tags + len, STRING_LEN - len, "t%d %s(%d), ", tagIndex, "NCHAR", superTbls->tags[tagIndex].dataLen); len += snprintf(tags + len, STRING_LEN - len, "t%d %s(%d), ", tagIndex,
"NCHAR", superTbls->tags[tagIndex].dataLen);
lenOfTagOfOneRow += superTbls->tags[tagIndex].dataLen + 3; lenOfTagOfOneRow += superTbls->tags[tagIndex].dataLen + 3;
} else if (strcasecmp(dataType, "INT") == 0) { } else if (strcasecmp(dataType, "INT") == 0) {
len += snprintf(tags + len, STRING_LEN - len, "t%d %s, ", tagIndex, "INT"); len += snprintf(tags + len, STRING_LEN - len, "t%d %s, ", tagIndex,
"INT");
lenOfTagOfOneRow += superTbls->tags[tagIndex].dataLen + 11; lenOfTagOfOneRow += superTbls->tags[tagIndex].dataLen + 11;
} else if (strcasecmp(dataType, "BIGINT") == 0) { } else if (strcasecmp(dataType, "BIGINT") == 0) {
len += snprintf(tags + len, STRING_LEN - len, "t%d %s, ", tagIndex, "BIGINT"); len += snprintf(tags + len, STRING_LEN - len, "t%d %s, ", tagIndex,
"BIGINT");
lenOfTagOfOneRow += superTbls->tags[tagIndex].dataLen + 21; lenOfTagOfOneRow += superTbls->tags[tagIndex].dataLen + 21;
} else if (strcasecmp(dataType, "SMALLINT") == 0) { } else if (strcasecmp(dataType, "SMALLINT") == 0) {
len += snprintf(tags + len, STRING_LEN - len, "t%d %s, ", tagIndex, "SMALLINT"); len += snprintf(tags + len, STRING_LEN - len, "t%d %s, ", tagIndex,
"SMALLINT");
lenOfTagOfOneRow += superTbls->tags[tagIndex].dataLen + 6; lenOfTagOfOneRow += superTbls->tags[tagIndex].dataLen + 6;
} else if (strcasecmp(dataType, "TINYINT") == 0) { } else if (strcasecmp(dataType, "TINYINT") == 0) {
len += snprintf(tags + len, STRING_LEN - len, "t%d %s, ", tagIndex, "TINYINT"); len += snprintf(tags + len, STRING_LEN - len, "t%d %s, ", tagIndex,
"TINYINT");
lenOfTagOfOneRow += superTbls->tags[tagIndex].dataLen + 4; lenOfTagOfOneRow += superTbls->tags[tagIndex].dataLen + 4;
} else if (strcasecmp(dataType, "BOOL") == 0) { } else if (strcasecmp(dataType, "BOOL") == 0) {
len += snprintf(tags + len, STRING_LEN - len, "t%d %s, ", tagIndex, "BOOL"); len += snprintf(tags + len, STRING_LEN - len, "t%d %s, ", tagIndex,
"BOOL");
lenOfTagOfOneRow += superTbls->tags[tagIndex].dataLen + 6; lenOfTagOfOneRow += superTbls->tags[tagIndex].dataLen + 6;
} else if (strcasecmp(dataType, "FLOAT") == 0) { } else if (strcasecmp(dataType, "FLOAT") == 0) {
len += snprintf(tags + len, STRING_LEN - len, "t%d %s, ", tagIndex, "FLOAT"); len += snprintf(tags + len, STRING_LEN - len, "t%d %s, ", tagIndex,
"FLOAT");
lenOfTagOfOneRow += superTbls->tags[tagIndex].dataLen + 22; lenOfTagOfOneRow += superTbls->tags[tagIndex].dataLen + 22;
} else if (strcasecmp(dataType, "DOUBLE") == 0) { } else if (strcasecmp(dataType, "DOUBLE") == 0) {
len += snprintf(tags + len, STRING_LEN - len, "t%d %s, ", tagIndex, "DOUBLE"); len += snprintf(tags + len, STRING_LEN - len, "t%d %s, ", tagIndex,
"DOUBLE");
lenOfTagOfOneRow += superTbls->tags[tagIndex].dataLen + 42; lenOfTagOfOneRow += superTbls->tags[tagIndex].dataLen + 42;
} else { } else {
taos_close(taos); taos_close(taos);
...@@ -2130,7 +2226,8 @@ static int createSuperTable(TAOS * taos, char* dbName, SSuperTable* superTbls, ...@@ -2130,7 +2226,8 @@ static int createSuperTable(TAOS * taos, char* dbName, SSuperTable* superTbls,
verbosePrint("%s() LN%d: %s\n", __func__, __LINE__, command); verbosePrint("%s() LN%d: %s\n", __func__, __LINE__, command);
if (0 != queryDbExec(taos, command, NO_INSERT_TYPE)) { if (0 != queryDbExec(taos, command, NO_INSERT_TYPE)) {
fprintf(stderr, "create supertable %s failed!\n\n", superTbls->sTblName); fprintf(stderr, "create supertable %s failed!\n\n",
superTbls->sTblName);
return -1; return -1;
} }
debugPrint("create supertable %s success!\n\n", superTbls->sTblName); debugPrint("create supertable %s success!\n\n", superTbls->sTblName);
...@@ -2138,7 +2235,6 @@ static int createSuperTable(TAOS * taos, char* dbName, SSuperTable* superTbls, ...@@ -2138,7 +2235,6 @@ static int createSuperTable(TAOS * taos, char* dbName, SSuperTable* superTbls,
return 0; return 0;
} }
static int createDatabases() { static int createDatabases() {
TAOS * taos = NULL; TAOS * taos = NULL;
int ret = 0; int ret = 0;
...@@ -2352,7 +2448,7 @@ static void* createTable(void *sarg) ...@@ -2352,7 +2448,7 @@ static void* createTable(void *sarg)
} }
int startMultiThreadCreateChildTable( int startMultiThreadCreateChildTable(
char* cols, int threads, int ntables, char* cols, int threads, int startFrom, int ntables,
char* db_name, SSuperTable* superTblInfo) { char* db_name, SSuperTable* superTblInfo) {
pthread_t *pids = malloc(threads * sizeof(pthread_t)); pthread_t *pids = malloc(threads * sizeof(pthread_t));
threadInfo *infos = malloc(threads * sizeof(threadInfo)); threadInfo *infos = malloc(threads * sizeof(threadInfo));
...@@ -2375,7 +2471,7 @@ int startMultiThreadCreateChildTable( ...@@ -2375,7 +2471,7 @@ int startMultiThreadCreateChildTable(
int b = 0; int b = 0;
b = ntables % threads; b = ntables % threads;
int last = 0; int last = startFrom;
for (int i = 0; i < threads; i++) { for (int i = 0; i < threads; i++) {
threadInfo *t_info = infos + i; threadInfo *t_info = infos + i;
t_info->threadID = i; t_info->threadID = i;
...@@ -2434,12 +2530,17 @@ static void createChildTables() { ...@@ -2434,12 +2530,17 @@ static void createChildTables() {
verbosePrint("%s() LN%d: %s\n", __func__, __LINE__, verbosePrint("%s() LN%d: %s\n", __func__, __LINE__,
g_Dbs.db[i].superTbls[j].colsOfCreateChildTable); g_Dbs.db[i].superTbls[j].colsOfCreateChildTable);
int startFrom = 0;
g_totalChildTables += g_Dbs.db[i].superTbls[j].childTblCount;
verbosePrint("%s() LN%d: create %d child tables from %d\n", __func__, __LINE__,
g_totalChildTables, startFrom);
startMultiThreadCreateChildTable( startMultiThreadCreateChildTable(
g_Dbs.db[i].superTbls[j].colsOfCreateChildTable, g_Dbs.db[i].superTbls[j].colsOfCreateChildTable,
g_Dbs.threadCountByCreateTbl, g_Dbs.threadCountByCreateTbl,
g_Dbs.db[i].superTbls[j].childTblCount, startFrom,
g_totalChildTables,
g_Dbs.db[i].dbName, &(g_Dbs.db[i].superTbls[j])); g_Dbs.db[i].dbName, &(g_Dbs.db[i].superTbls[j]));
g_totalChildTables += g_Dbs.db[i].superTbls[j].childTblCount;
} }
} else { } else {
// normal table // normal table
...@@ -2447,10 +2548,13 @@ static void createChildTables() { ...@@ -2447,10 +2548,13 @@ static void createChildTables() {
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], "NCHAR", strlen("NCHAR")) == 0)) { || (strncasecmp(g_args.datatype[j],
len = snprintf(tblColsBuf + len, MAX_SQL_SIZE, ", COL%d %s(60)", j, g_args.datatype[j]); "NCHAR", strlen("NCHAR")) == 0)) {
len = snprintf(tblColsBuf + len, MAX_SQL_SIZE,
", COL%d %s(60)", j, g_args.datatype[j]);
} else { } else {
len = snprintf(tblColsBuf + len, MAX_SQL_SIZE, ", COL%d %s", j, g_args.datatype[j]); len = snprintf(tblColsBuf + len, MAX_SQL_SIZE,
", COL%d %s", j, g_args.datatype[j]);
} }
len = strlen(tblColsBuf); len = strlen(tblColsBuf);
j++; j++;
...@@ -2458,11 +2562,13 @@ static void createChildTables() { ...@@ -2458,11 +2562,13 @@ static void createChildTables() {
len = snprintf(tblColsBuf + len, MAX_SQL_SIZE - len, ")"); len = snprintf(tblColsBuf + len, MAX_SQL_SIZE - len, ")");
verbosePrint("%s() LN%d: dbName: %s num of tb: %d schema: %s\n", __func__, __LINE__, verbosePrint("%s() LN%d: dbName: %s num of tb: %d schema: %s\n",
__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,
g_args.num_of_tables, g_args.num_of_tables,
g_Dbs.db[i].dbName, g_Dbs.db[i].dbName,
NULL); NULL);
...@@ -2470,30 +2576,6 @@ static void createChildTables() { ...@@ -2470,30 +2576,6 @@ static void createChildTables() {
} }
} }
/*
static int taosGetLineNum(const char *fileName)
{
int lineNum = 0;
char cmd[1024] = { 0 };
char buf[1024] = { 0 };
sprintf(cmd, "wc -l %s", fileName);
FILE *fp = popen(cmd, "r");
if (fp == NULL) {
fprintf(stderr, "ERROR: failed to execute:%s, error:%s\n", cmd, strerror(errno));
return lineNum;
}
if (fgets(buf, sizeof(buf), fp)) {
int index = strchr((const char*)buf, ' ') - buf;
buf[index] = '\0';
lineNum = atoi(buf);
}
pclose(fp);
return lineNum;
}
*/
/* /*
Read 10000 lines at most. If more than 10000 lines, continue to read after using Read 10000 lines at most. If more than 10000 lines, continue to read after using
*/ */
...@@ -2571,19 +2653,29 @@ int readSampleFromJsonFileToMem(SSuperTable * superTblInfo) { ...@@ -2571,19 +2653,29 @@ int readSampleFromJsonFileToMem(SSuperTable * superTblInfo) {
/* /*
Read 10000 lines at most. If more than 10000 lines, continue to read after using Read 10000 lines at most. If more than 10000 lines, continue to read after using
*/ */
int readSampleFromCsvFileToMem(FILE *fp, SSuperTable* superTblInfo, char* sampleBuf) { static int readSampleFromCsvFileToMem(
SSuperTable* superTblInfo) {
size_t n = 0; size_t n = 0;
ssize_t readLen = 0; ssize_t readLen = 0;
char * line = NULL; char * line = NULL;
int getRows = 0; int getRows = 0;
memset(sampleBuf, 0, MAX_SAMPLES_ONCE_FROM_FILE* superTblInfo->lenOfOneRow); FILE* fp = fopen(superTblInfo->sampleFile, "r");
if (fp == NULL) {
fprintf(stderr, "Failed to open sample file: %s, reason:%s\n",
superTblInfo->sampleFile, strerror(errno));
return -1;
}
memset(superTblInfo->sampleDataBuf, 0,
MAX_SAMPLES_ONCE_FROM_FILE * superTblInfo->lenOfOneRow);
while (1) { while (1) {
readLen = tgetline(&line, &n, fp); readLen = tgetline(&line, &n, fp);
if (-1 == readLen) { if (-1 == readLen) {
if(0 != fseek(fp, 0, SEEK_SET)) { if(0 != fseek(fp, 0, SEEK_SET)) {
printf("Failed to fseek file: %s, reason:%s\n", fprintf(stderr, "Failed to fseek file: %s, reason:%s\n",
superTblInfo->sampleFile, strerror(errno)); superTblInfo->sampleFile, strerror(errno));
fclose(fp);
return -1; return -1;
} }
continue; continue;
...@@ -2603,7 +2695,8 @@ int readSampleFromCsvFileToMem(FILE *fp, SSuperTable* superTblInfo, char* sample ...@@ -2603,7 +2695,8 @@ int readSampleFromCsvFileToMem(FILE *fp, SSuperTable* superTblInfo, char* sample
continue; continue;
} }
memcpy(sampleBuf + getRows * superTblInfo->lenOfOneRow, line, readLen); memcpy(superTblInfo->sampleDataBuf + getRows * superTblInfo->lenOfOneRow,
line, readLen);
getRows++; getRows++;
if (getRows == MAX_SAMPLES_ONCE_FROM_FILE) { if (getRows == MAX_SAMPLES_ONCE_FROM_FILE) {
...@@ -2611,6 +2704,7 @@ int readSampleFromCsvFileToMem(FILE *fp, SSuperTable* superTblInfo, char* sample ...@@ -2611,6 +2704,7 @@ int readSampleFromCsvFileToMem(FILE *fp, SSuperTable* superTblInfo, char* sample
} }
} }
fclose(fp);
tmfree(line); tmfree(line);
return 0; return 0;
} }
...@@ -2635,7 +2729,7 @@ static bool getColumnAndTagTypeFromInsertJsonFile(cJSON* stbInfo, SSuperTable* s ...@@ -2635,7 +2729,7 @@ static bool getColumnAndTagTypeFromInsertJsonFile(cJSON* stbInfo, SSuperTable* s
// columns // columns
cJSON *columns = cJSON_GetObjectItem(stbInfo, "columns"); cJSON *columns = cJSON_GetObjectItem(stbInfo, "columns");
if (columns && columns->type != cJSON_Array) { if (columns && columns->type != cJSON_Array) {
printf("failed to read json, columns not found\n"); printf("ERROR: failed to read json, columns not found\n");
goto PARSE_OVER; goto PARSE_OVER;
} else if (NULL == columns) { } else if (NULL == columns) {
superTbls->columnCount = 0; superTbls->columnCount = 0;
...@@ -2645,7 +2739,7 @@ static bool getColumnAndTagTypeFromInsertJsonFile(cJSON* stbInfo, SSuperTable* s ...@@ -2645,7 +2739,7 @@ static bool getColumnAndTagTypeFromInsertJsonFile(cJSON* stbInfo, SSuperTable* s
int columnSize = cJSON_GetArraySize(columns); int columnSize = cJSON_GetArraySize(columns);
if (columnSize > MAX_COLUMN_COUNT) { if (columnSize > MAX_COLUMN_COUNT) {
printf("failed to read json, column size overflow, max column size is %d\n", printf("ERROR: failed to read json, column size overflow, max column size is %d\n",
MAX_COLUMN_COUNT); MAX_COLUMN_COUNT);
goto PARSE_OVER; goto PARSE_OVER;
} }
...@@ -2664,7 +2758,7 @@ static bool getColumnAndTagTypeFromInsertJsonFile(cJSON* stbInfo, SSuperTable* s ...@@ -2664,7 +2758,7 @@ static bool getColumnAndTagTypeFromInsertJsonFile(cJSON* stbInfo, SSuperTable* s
if (countObj && countObj->type == cJSON_Number) { if (countObj && countObj->type == cJSON_Number) {
count = countObj->valueint; count = countObj->valueint;
} else if (countObj && countObj->type != cJSON_Number) { } else if (countObj && countObj->type != cJSON_Number) {
printf("failed to read json, column count not found"); printf("ERROR: failed to read json, column count not found\n");
goto PARSE_OVER; goto PARSE_OVER;
} else { } else {
count = 1; count = 1;
...@@ -2674,7 +2768,7 @@ static bool getColumnAndTagTypeFromInsertJsonFile(cJSON* stbInfo, SSuperTable* s ...@@ -2674,7 +2768,7 @@ static bool getColumnAndTagTypeFromInsertJsonFile(cJSON* stbInfo, SSuperTable* s
memset(&columnCase, 0, sizeof(StrColumn)); memset(&columnCase, 0, sizeof(StrColumn));
cJSON *dataType = cJSON_GetObjectItem(column, "type"); cJSON *dataType = cJSON_GetObjectItem(column, "type");
if (!dataType || dataType->type != cJSON_String || dataType->valuestring == NULL) { if (!dataType || dataType->type != cJSON_String || dataType->valuestring == NULL) {
printf("failed to read json, column type not found"); printf("ERROR: failed to read json, column type not found\n");
goto PARSE_OVER; goto PARSE_OVER;
} }
//tstrncpy(superTbls->columns[k].dataType, dataType->valuestring, MAX_TB_NAME_SIZE); //tstrncpy(superTbls->columns[k].dataType, dataType->valuestring, MAX_TB_NAME_SIZE);
...@@ -2684,7 +2778,7 @@ static bool getColumnAndTagTypeFromInsertJsonFile(cJSON* stbInfo, SSuperTable* s ...@@ -2684,7 +2778,7 @@ static bool getColumnAndTagTypeFromInsertJsonFile(cJSON* stbInfo, SSuperTable* s
if (dataLen && dataLen->type == cJSON_Number) { if (dataLen && dataLen->type == cJSON_Number) {
columnCase.dataLen = dataLen->valueint; columnCase.dataLen = dataLen->valueint;
} else if (dataLen && dataLen->type != cJSON_Number) { } else if (dataLen && dataLen->type != cJSON_Number) {
printf("failed to read json, column len not found"); printf("ERROR: failed to read json, column len not found\n");
goto PARSE_OVER; goto PARSE_OVER;
} else { } else {
columnCase.dataLen = 8; columnCase.dataLen = 8;
...@@ -2703,13 +2797,13 @@ static bool getColumnAndTagTypeFromInsertJsonFile(cJSON* stbInfo, SSuperTable* s ...@@ -2703,13 +2797,13 @@ static bool getColumnAndTagTypeFromInsertJsonFile(cJSON* stbInfo, SSuperTable* s
// tags // tags
cJSON *tags = cJSON_GetObjectItem(stbInfo, "tags"); cJSON *tags = cJSON_GetObjectItem(stbInfo, "tags");
if (!tags || tags->type != cJSON_Array) { if (!tags || tags->type != cJSON_Array) {
printf("failed to read json, tags not found"); printf("ERROR: failed to read json, tags not found\n");
goto PARSE_OVER; goto PARSE_OVER;
} }
int tagSize = cJSON_GetArraySize(tags); int tagSize = cJSON_GetArraySize(tags);
if (tagSize > MAX_TAG_COUNT) { if (tagSize > MAX_TAG_COUNT) {
printf("failed to read json, tags size overflow, max tag size is %d\n", MAX_TAG_COUNT); printf("ERROR: failed to read json, tags size overflow, max tag size is %d\n", MAX_TAG_COUNT);
goto PARSE_OVER; goto PARSE_OVER;
} }
...@@ -2723,7 +2817,7 @@ static bool getColumnAndTagTypeFromInsertJsonFile(cJSON* stbInfo, SSuperTable* s ...@@ -2723,7 +2817,7 @@ static bool getColumnAndTagTypeFromInsertJsonFile(cJSON* stbInfo, SSuperTable* s
if (countObj && countObj->type == cJSON_Number) { if (countObj && countObj->type == cJSON_Number) {
count = countObj->valueint; count = countObj->valueint;
} else if (countObj && countObj->type != cJSON_Number) { } else if (countObj && countObj->type != cJSON_Number) {
printf("failed to read json, column count not found"); printf("ERROR: failed to read json, column count not found\n");
goto PARSE_OVER; goto PARSE_OVER;
} else { } else {
count = 1; count = 1;
...@@ -2733,7 +2827,7 @@ static bool getColumnAndTagTypeFromInsertJsonFile(cJSON* stbInfo, SSuperTable* s ...@@ -2733,7 +2827,7 @@ static bool getColumnAndTagTypeFromInsertJsonFile(cJSON* stbInfo, SSuperTable* s
memset(&columnCase, 0, sizeof(StrColumn)); memset(&columnCase, 0, sizeof(StrColumn));
cJSON *dataType = cJSON_GetObjectItem(tag, "type"); cJSON *dataType = cJSON_GetObjectItem(tag, "type");
if (!dataType || dataType->type != cJSON_String || dataType->valuestring == NULL) { if (!dataType || dataType->type != cJSON_String || dataType->valuestring == NULL) {
printf("failed to read json, tag type not found"); printf("ERROR: failed to read json, tag type not found\n");
goto PARSE_OVER; goto PARSE_OVER;
} }
tstrncpy(columnCase.dataType, dataType->valuestring, MAX_TB_NAME_SIZE); tstrncpy(columnCase.dataType, dataType->valuestring, MAX_TB_NAME_SIZE);
...@@ -2742,7 +2836,7 @@ static bool getColumnAndTagTypeFromInsertJsonFile(cJSON* stbInfo, SSuperTable* s ...@@ -2742,7 +2836,7 @@ static bool getColumnAndTagTypeFromInsertJsonFile(cJSON* stbInfo, SSuperTable* s
if (dataLen && dataLen->type == cJSON_Number) { if (dataLen && dataLen->type == cJSON_Number) {
columnCase.dataLen = dataLen->valueint; columnCase.dataLen = dataLen->valueint;
} else if (dataLen && dataLen->type != cJSON_Number) { } else if (dataLen && dataLen->type != cJSON_Number) {
printf("failed to read json, column len not found"); printf("ERROR: failed to read json, column len not found\n");
goto PARSE_OVER; goto PARSE_OVER;
} else { } else {
columnCase.dataLen = 0; columnCase.dataLen = 0;
...@@ -2779,7 +2873,7 @@ static bool getMetaFromInsertJsonFile(cJSON* root) { ...@@ -2779,7 +2873,7 @@ static bool getMetaFromInsertJsonFile(cJSON* root) {
} else if (!host) { } else if (!host) {
tstrncpy(g_Dbs.host, "127.0.0.1", MAX_DB_NAME_SIZE); tstrncpy(g_Dbs.host, "127.0.0.1", MAX_DB_NAME_SIZE);
} else { } else {
printf("failed to read json, host not found\n"); printf("ERROR: failed to read json, host not found\n");
goto PARSE_OVER; goto PARSE_OVER;
} }
...@@ -2817,7 +2911,7 @@ static bool getMetaFromInsertJsonFile(cJSON* root) { ...@@ -2817,7 +2911,7 @@ static bool getMetaFromInsertJsonFile(cJSON* root) {
} else if (!threads) { } else if (!threads) {
g_Dbs.threadCount = 1; g_Dbs.threadCount = 1;
} else { } else {
printf("failed to read json, threads not found"); printf("ERROR: failed to read json, threads not found\n");
goto PARSE_OVER; goto PARSE_OVER;
} }
...@@ -2827,7 +2921,7 @@ static bool getMetaFromInsertJsonFile(cJSON* root) { ...@@ -2827,7 +2921,7 @@ static bool getMetaFromInsertJsonFile(cJSON* root) {
} else if (!threads2) { } else if (!threads2) {
g_Dbs.threadCountByCreateTbl = 1; g_Dbs.threadCountByCreateTbl = 1;
} else { } else {
printf("failed to read json, threads2 not found"); printf("ERROR: failed to read json, threads2 not found\n");
goto PARSE_OVER; goto PARSE_OVER;
} }
...@@ -2837,17 +2931,28 @@ static bool getMetaFromInsertJsonFile(cJSON* root) { ...@@ -2837,17 +2931,28 @@ static bool getMetaFromInsertJsonFile(cJSON* root) {
} else if (!gInsertInterval) { } else if (!gInsertInterval) {
g_args.insert_interval = 0; g_args.insert_interval = 0;
} else { } else {
printf("failed to read json, insert_interval input mistake"); fprintf(stderr, "ERROR: failed to read json, insert_interval input mistake\n");
goto PARSE_OVER;
}
cJSON* maxSqlLen = cJSON_GetObjectItem(root, "max_sql_len");
if (maxSqlLen && maxSqlLen->type == cJSON_Number) {
g_args.max_sql_len = maxSqlLen->valueint;
} else if (!maxSqlLen) {
g_args.max_sql_len = TSDB_PAYLOAD_SIZE;
} else {
fprintf(stderr, "ERROR: failed to read json, max_sql_len input mistake\n");
goto PARSE_OVER; goto PARSE_OVER;
} }
cJSON* numRecPerReq = cJSON_GetObjectItem(root, "num_of_records_per_req"); cJSON* numRecPerReq = cJSON_GetObjectItem(root, "num_of_records_per_req");
if (numRecPerReq && numRecPerReq->type == cJSON_Number) { if (numRecPerReq && numRecPerReq->type == cJSON_Number) {
g_args.num_of_RPR = numRecPerReq->valueint; g_args.num_of_RPR = numRecPerReq->valueint;
} else if (!numRecPerReq) { } else if (!numRecPerReq) {
g_args.num_of_RPR = 100; g_args.num_of_RPR = 100;
} else { } else {
printf("failed to read json, num_of_records_per_req not found"); printf("ERROR: failed to read json, num_of_records_per_req not found\n");
goto PARSE_OVER; goto PARSE_OVER;
} }
...@@ -2865,19 +2970,19 @@ static bool getMetaFromInsertJsonFile(cJSON* root) { ...@@ -2865,19 +2970,19 @@ static bool getMetaFromInsertJsonFile(cJSON* root) {
} else if (!answerPrompt) { } else if (!answerPrompt) {
g_args.answer_yes = false; g_args.answer_yes = false;
} else { } else {
printf("failed to read json, confirm_parameter_prompt not found"); printf("ERROR: failed to read json, confirm_parameter_prompt not found\n");
goto PARSE_OVER; goto PARSE_OVER;
} }
cJSON* dbs = cJSON_GetObjectItem(root, "databases"); cJSON* dbs = cJSON_GetObjectItem(root, "databases");
if (!dbs || dbs->type != cJSON_Array) { if (!dbs || dbs->type != cJSON_Array) {
printf("failed to read json, databases not found\n"); printf("ERROR: failed to read json, databases not found\n");
goto PARSE_OVER; goto PARSE_OVER;
} }
int dbSize = cJSON_GetArraySize(dbs); int dbSize = cJSON_GetArraySize(dbs);
if (dbSize > MAX_DB_COUNT) { if (dbSize > MAX_DB_COUNT) {
printf("failed to read json, databases size overflow, max database is %d\n", MAX_DB_COUNT); printf("ERROR: failed to read json, databases size overflow, max database is %d\n", MAX_DB_COUNT);
goto PARSE_OVER; goto PARSE_OVER;
} }
...@@ -2889,13 +2994,13 @@ static bool getMetaFromInsertJsonFile(cJSON* root) { ...@@ -2889,13 +2994,13 @@ static bool getMetaFromInsertJsonFile(cJSON* root) {
// dbinfo // dbinfo
cJSON *dbinfo = cJSON_GetObjectItem(dbinfos, "dbinfo"); cJSON *dbinfo = cJSON_GetObjectItem(dbinfos, "dbinfo");
if (!dbinfo || dbinfo->type != cJSON_Object) { if (!dbinfo || dbinfo->type != cJSON_Object) {
printf("failed to read json, dbinfo not found"); printf("ERROR: failed to read json, dbinfo not found\n");
goto PARSE_OVER; goto PARSE_OVER;
} }
cJSON *dbName = cJSON_GetObjectItem(dbinfo, "name"); cJSON *dbName = cJSON_GetObjectItem(dbinfo, "name");
if (!dbName || dbName->type != cJSON_String || dbName->valuestring == NULL) { if (!dbName || dbName->type != cJSON_String || dbName->valuestring == NULL) {
printf("failed to read json, db name not found"); printf("ERROR: failed to read json, db name not found\n");
goto PARSE_OVER; goto PARSE_OVER;
} }
tstrncpy(g_Dbs.db[i].dbName, dbName->valuestring, MAX_DB_NAME_SIZE); tstrncpy(g_Dbs.db[i].dbName, dbName->valuestring, MAX_DB_NAME_SIZE);
...@@ -2910,7 +3015,7 @@ static bool getMetaFromInsertJsonFile(cJSON* root) { ...@@ -2910,7 +3015,7 @@ static bool getMetaFromInsertJsonFile(cJSON* root) {
} else if (!drop) { } else if (!drop) {
g_Dbs.db[i].drop = 0; g_Dbs.db[i].drop = 0;
} else { } else {
printf("failed to read json, drop not found"); printf("ERROR: failed to read json, drop not found\n");
goto PARSE_OVER; goto PARSE_OVER;
} }
...@@ -2921,7 +3026,7 @@ static bool getMetaFromInsertJsonFile(cJSON* root) { ...@@ -2921,7 +3026,7 @@ static bool getMetaFromInsertJsonFile(cJSON* root) {
//tstrncpy(g_Dbs.db[i].dbCfg.precision, "ms", MAX_DB_NAME_SIZE); //tstrncpy(g_Dbs.db[i].dbCfg.precision, "ms", MAX_DB_NAME_SIZE);
memset(g_Dbs.db[i].dbCfg.precision, 0, MAX_DB_NAME_SIZE); memset(g_Dbs.db[i].dbCfg.precision, 0, MAX_DB_NAME_SIZE);
} else { } else {
printf("failed to read json, precision not found"); printf("ERROR: failed to read json, precision not found\n");
goto PARSE_OVER; goto PARSE_OVER;
} }
...@@ -2931,7 +3036,7 @@ static bool getMetaFromInsertJsonFile(cJSON* root) { ...@@ -2931,7 +3036,7 @@ static bool getMetaFromInsertJsonFile(cJSON* root) {
} else if (!update) { } else if (!update) {
g_Dbs.db[i].dbCfg.update = -1; g_Dbs.db[i].dbCfg.update = -1;
} else { } else {
printf("failed to read json, update not found"); printf("ERROR: failed to read json, update not found\n");
goto PARSE_OVER; goto PARSE_OVER;
} }
...@@ -2941,7 +3046,7 @@ static bool getMetaFromInsertJsonFile(cJSON* root) { ...@@ -2941,7 +3046,7 @@ static bool getMetaFromInsertJsonFile(cJSON* root) {
} else if (!replica) { } else if (!replica) {
g_Dbs.db[i].dbCfg.replica = -1; g_Dbs.db[i].dbCfg.replica = -1;
} else { } else {
printf("failed to read json, replica not found"); printf("ERROR: failed to read json, replica not found\n");
goto PARSE_OVER; goto PARSE_OVER;
} }
...@@ -2951,7 +3056,7 @@ static bool getMetaFromInsertJsonFile(cJSON* root) { ...@@ -2951,7 +3056,7 @@ static bool getMetaFromInsertJsonFile(cJSON* root) {
} else if (!keep) { } else if (!keep) {
g_Dbs.db[i].dbCfg.keep = -1; g_Dbs.db[i].dbCfg.keep = -1;
} else { } else {
printf("failed to read json, keep not found"); printf("ERROR: failed to read json, keep not found\n");
goto PARSE_OVER; goto PARSE_OVER;
} }
...@@ -2961,7 +3066,7 @@ static bool getMetaFromInsertJsonFile(cJSON* root) { ...@@ -2961,7 +3066,7 @@ static bool getMetaFromInsertJsonFile(cJSON* root) {
} else if (!days) { } else if (!days) {
g_Dbs.db[i].dbCfg.days = -1; g_Dbs.db[i].dbCfg.days = -1;
} else { } else {
printf("failed to read json, days not found"); printf("ERROR: failed to read json, days not found\n");
goto PARSE_OVER; goto PARSE_OVER;
} }
...@@ -2971,7 +3076,7 @@ static bool getMetaFromInsertJsonFile(cJSON* root) { ...@@ -2971,7 +3076,7 @@ static bool getMetaFromInsertJsonFile(cJSON* root) {
} else if (!cache) { } else if (!cache) {
g_Dbs.db[i].dbCfg.cache = -1; g_Dbs.db[i].dbCfg.cache = -1;
} else { } else {
printf("failed to read json, cache not found"); printf("ERROR: failed to read json, cache not found\n");
goto PARSE_OVER; goto PARSE_OVER;
} }
...@@ -2981,7 +3086,7 @@ static bool getMetaFromInsertJsonFile(cJSON* root) { ...@@ -2981,7 +3086,7 @@ static bool getMetaFromInsertJsonFile(cJSON* root) {
} else if (!blocks) { } else if (!blocks) {
g_Dbs.db[i].dbCfg.blocks = -1; g_Dbs.db[i].dbCfg.blocks = -1;
} else { } else {
printf("failed to read json, block not found"); printf("ERROR: failed to read json, block not found\n");
goto PARSE_OVER; goto PARSE_OVER;
} }
...@@ -3001,7 +3106,7 @@ static bool getMetaFromInsertJsonFile(cJSON* root) { ...@@ -3001,7 +3106,7 @@ static bool getMetaFromInsertJsonFile(cJSON* root) {
} else if (!minRows) { } else if (!minRows) {
g_Dbs.db[i].dbCfg.minRows = -1; g_Dbs.db[i].dbCfg.minRows = -1;
} else { } else {
printf("failed to read json, minRows not found"); printf("ERROR: failed to read json, minRows not found\n");
goto PARSE_OVER; goto PARSE_OVER;
} }
...@@ -3011,7 +3116,7 @@ static bool getMetaFromInsertJsonFile(cJSON* root) { ...@@ -3011,7 +3116,7 @@ static bool getMetaFromInsertJsonFile(cJSON* root) {
} else if (!maxRows) { } else if (!maxRows) {
g_Dbs.db[i].dbCfg.maxRows = -1; g_Dbs.db[i].dbCfg.maxRows = -1;
} else { } else {
printf("failed to read json, maxRows not found"); printf("ERROR: failed to read json, maxRows not found\n");
goto PARSE_OVER; goto PARSE_OVER;
} }
...@@ -3021,7 +3126,7 @@ static bool getMetaFromInsertJsonFile(cJSON* root) { ...@@ -3021,7 +3126,7 @@ static bool getMetaFromInsertJsonFile(cJSON* root) {
} else if (!comp) { } else if (!comp) {
g_Dbs.db[i].dbCfg.comp = -1; g_Dbs.db[i].dbCfg.comp = -1;
} else { } else {
printf("failed to read json, comp not found"); printf("ERROR: failed to read json, comp not found\n");
goto PARSE_OVER; goto PARSE_OVER;
} }
...@@ -3031,7 +3136,7 @@ static bool getMetaFromInsertJsonFile(cJSON* root) { ...@@ -3031,7 +3136,7 @@ static bool getMetaFromInsertJsonFile(cJSON* root) {
} else if (!walLevel) { } else if (!walLevel) {
g_Dbs.db[i].dbCfg.walLevel = -1; g_Dbs.db[i].dbCfg.walLevel = -1;
} else { } else {
printf("failed to read json, walLevel not found"); printf("ERROR: failed to read json, walLevel not found\n");
goto PARSE_OVER; goto PARSE_OVER;
} }
...@@ -3041,7 +3146,7 @@ static bool getMetaFromInsertJsonFile(cJSON* root) { ...@@ -3041,7 +3146,7 @@ static bool getMetaFromInsertJsonFile(cJSON* root) {
} else if (!cacheLast) { } else if (!cacheLast) {
g_Dbs.db[i].dbCfg.cacheLast = -1; g_Dbs.db[i].dbCfg.cacheLast = -1;
} else { } else {
printf("failed to read json, cacheLast not found"); printf("ERROR: failed to read json, cacheLast not found\n");
goto PARSE_OVER; goto PARSE_OVER;
} }
...@@ -3061,20 +3166,20 @@ static bool getMetaFromInsertJsonFile(cJSON* root) { ...@@ -3061,20 +3166,20 @@ static bool getMetaFromInsertJsonFile(cJSON* root) {
} else if (!fsync) { } else if (!fsync) {
g_Dbs.db[i].dbCfg.fsync = -1; g_Dbs.db[i].dbCfg.fsync = -1;
} else { } else {
printf("failed to read json, fsync not found"); printf("ERROR: failed to read json, fsync not found\n");
goto PARSE_OVER; goto PARSE_OVER;
} }
// super_talbes // super_talbes
cJSON *stables = cJSON_GetObjectItem(dbinfos, "super_tables"); cJSON *stables = cJSON_GetObjectItem(dbinfos, "super_tables");
if (!stables || stables->type != cJSON_Array) { if (!stables || stables->type != cJSON_Array) {
printf("failed to read json, super_tables not found"); printf("ERROR: failed to read json, super_tables not found\n");
goto PARSE_OVER; goto PARSE_OVER;
} }
int stbSize = cJSON_GetArraySize(stables); int stbSize = cJSON_GetArraySize(stables);
if (stbSize > MAX_SUPER_TABLE_COUNT) { if (stbSize > MAX_SUPER_TABLE_COUNT) {
printf("failed to read json, databases size overflow, max database is %d\n", MAX_SUPER_TABLE_COUNT); printf("ERROR: failed to read json, databases size overflow, max database is %d\n", MAX_SUPER_TABLE_COUNT);
goto PARSE_OVER; goto PARSE_OVER;
} }
...@@ -3086,14 +3191,14 @@ static bool getMetaFromInsertJsonFile(cJSON* root) { ...@@ -3086,14 +3191,14 @@ static bool getMetaFromInsertJsonFile(cJSON* root) {
// dbinfo // dbinfo
cJSON *stbName = cJSON_GetObjectItem(stbInfo, "name"); cJSON *stbName = cJSON_GetObjectItem(stbInfo, "name");
if (!stbName || stbName->type != cJSON_String || stbName->valuestring == NULL) { if (!stbName || stbName->type != cJSON_String || stbName->valuestring == NULL) {
printf("failed to read json, stb name not found"); printf("ERROR: failed to read json, stb name not found\n");
goto PARSE_OVER; goto PARSE_OVER;
} }
tstrncpy(g_Dbs.db[i].superTbls[j].sTblName, stbName->valuestring, MAX_TB_NAME_SIZE); tstrncpy(g_Dbs.db[i].superTbls[j].sTblName, stbName->valuestring, MAX_TB_NAME_SIZE);
cJSON *prefix = cJSON_GetObjectItem(stbInfo, "childtable_prefix"); cJSON *prefix = cJSON_GetObjectItem(stbInfo, "childtable_prefix");
if (!prefix || prefix->type != cJSON_String || prefix->valuestring == NULL) { if (!prefix || prefix->type != cJSON_String || prefix->valuestring == NULL) {
printf("failed to read json, childtable_prefix not found"); printf("ERROR: failed to read json, childtable_prefix not found\n");
goto PARSE_OVER; goto PARSE_OVER;
} }
tstrncpy(g_Dbs.db[i].superTbls[j].childTblPrefix, prefix->valuestring, MAX_DB_NAME_SIZE); tstrncpy(g_Dbs.db[i].superTbls[j].childTblPrefix, prefix->valuestring, MAX_DB_NAME_SIZE);
...@@ -3112,7 +3217,7 @@ static bool getMetaFromInsertJsonFile(cJSON* root) { ...@@ -3112,7 +3217,7 @@ static bool getMetaFromInsertJsonFile(cJSON* root) {
} else if (!autoCreateTbl) { } else if (!autoCreateTbl) {
g_Dbs.db[i].superTbls[j].autoCreateTable = PRE_CREATE_SUBTBL; g_Dbs.db[i].superTbls[j].autoCreateTable = PRE_CREATE_SUBTBL;
} else { } else {
printf("failed to read json, auto_create_table not found"); printf("ERROR: failed to read json, auto_create_table not found\n");
goto PARSE_OVER; goto PARSE_OVER;
} }
...@@ -3122,7 +3227,7 @@ static bool getMetaFromInsertJsonFile(cJSON* root) { ...@@ -3122,7 +3227,7 @@ static bool getMetaFromInsertJsonFile(cJSON* root) {
} else if (!batchCreateTbl) { } else if (!batchCreateTbl) {
g_Dbs.db[i].superTbls[j].batchCreateTableNum = 1000; g_Dbs.db[i].superTbls[j].batchCreateTableNum = 1000;
} else { } else {
printf("failed to read json, batch_create_tbl_num not found"); printf("ERROR: failed to read json, batch_create_tbl_num not found\n");
goto PARSE_OVER; goto PARSE_OVER;
} }
...@@ -3140,13 +3245,13 @@ static bool getMetaFromInsertJsonFile(cJSON* root) { ...@@ -3140,13 +3245,13 @@ static bool getMetaFromInsertJsonFile(cJSON* root) {
} else if (!childTblExists) { } else if (!childTblExists) {
g_Dbs.db[i].superTbls[j].childTblExists = TBL_NO_EXISTS; g_Dbs.db[i].superTbls[j].childTblExists = TBL_NO_EXISTS;
} else { } else {
printf("failed to read json, child_table_exists not found"); printf("ERROR: failed to read json, child_table_exists not found\n");
goto PARSE_OVER; goto PARSE_OVER;
} }
cJSON* count = cJSON_GetObjectItem(stbInfo, "childtable_count"); cJSON* count = cJSON_GetObjectItem(stbInfo, "childtable_count");
if (!count || count->type != cJSON_Number || 0 >= count->valueint) { if (!count || count->type != cJSON_Number || 0 >= count->valueint) {
printf("failed to read json, childtable_count not found"); printf("ERROR: failed to read json, childtable_count not found\n");
goto PARSE_OVER; goto PARSE_OVER;
} }
g_Dbs.db[i].superTbls[j].childTblCount = count->valueint; g_Dbs.db[i].superTbls[j].childTblCount = count->valueint;
...@@ -3159,7 +3264,7 @@ static bool getMetaFromInsertJsonFile(cJSON* root) { ...@@ -3159,7 +3264,7 @@ static bool getMetaFromInsertJsonFile(cJSON* root) {
} else if (!dataSource) { } else if (!dataSource) {
tstrncpy(g_Dbs.db[i].superTbls[j].dataSource, "rand", MAX_DB_NAME_SIZE); tstrncpy(g_Dbs.db[i].superTbls[j].dataSource, "rand", MAX_DB_NAME_SIZE);
} else { } else {
printf("failed to read json, data_source not found"); printf("ERROR: failed to read json, data_source not found\n");
goto PARSE_OVER; goto PARSE_OVER;
} }
...@@ -3171,9 +3276,31 @@ static bool getMetaFromInsertJsonFile(cJSON* root) { ...@@ -3171,9 +3276,31 @@ static bool getMetaFromInsertJsonFile(cJSON* root) {
} else if (!insertMode) { } else if (!insertMode) {
tstrncpy(g_Dbs.db[i].superTbls[j].insertMode, "taosc", MAX_DB_NAME_SIZE); tstrncpy(g_Dbs.db[i].superTbls[j].insertMode, "taosc", MAX_DB_NAME_SIZE);
} else { } else {
printf("failed to read json, insert_mode not found"); printf("ERROR: failed to read json, insert_mode not found\n");
goto PARSE_OVER;
}
cJSON* childTbl_limit = cJSON_GetObjectItem(stbInfo, "childtable_limit");
if (childTbl_limit) {
if (childTbl_limit->type != cJSON_Number) {
printf("ERROR: failed to read json, childtable_limit\n");
goto PARSE_OVER;
}
g_Dbs.db[i].superTbls[j].childTblLimit = childTbl_limit->valueint;
} else {
g_Dbs.db[i].superTbls[j].childTblLimit = -1; // select ... limit -1 means all query result
}
cJSON* childTbl_offset = cJSON_GetObjectItem(stbInfo, "childtable_offset");
if (childTbl_offset) {
if (childTbl_offset->type != cJSON_Number || 0 > childTbl_offset->valueint) {
printf("ERROR: failed to read json, childtable_offset\n");
goto PARSE_OVER; goto PARSE_OVER;
} }
g_Dbs.db[i].superTbls[j].childTblOffset = childTbl_offset->valueint;
} else {
g_Dbs.db[i].superTbls[j].childTblOffset = 0;
}
cJSON *ts = cJSON_GetObjectItem(stbInfo, "start_timestamp"); cJSON *ts = cJSON_GetObjectItem(stbInfo, "start_timestamp");
if (ts && ts->type == cJSON_String && ts->valuestring != NULL) { if (ts && ts->type == cJSON_String && ts->valuestring != NULL) {
...@@ -3181,7 +3308,7 @@ static bool getMetaFromInsertJsonFile(cJSON* root) { ...@@ -3181,7 +3308,7 @@ static bool getMetaFromInsertJsonFile(cJSON* root) {
} else if (!ts) { } else if (!ts) {
tstrncpy(g_Dbs.db[i].superTbls[j].startTimestamp, "now", MAX_DB_NAME_SIZE); tstrncpy(g_Dbs.db[i].superTbls[j].startTimestamp, "now", MAX_DB_NAME_SIZE);
} else { } else {
printf("failed to read json, start_timestamp not found"); printf("ERROR: failed to read json, start_timestamp not found\n");
goto PARSE_OVER; goto PARSE_OVER;
} }
...@@ -3189,9 +3316,9 @@ static bool getMetaFromInsertJsonFile(cJSON* root) { ...@@ -3189,9 +3316,9 @@ static bool getMetaFromInsertJsonFile(cJSON* root) {
if (timestampStep && timestampStep->type == cJSON_Number) { if (timestampStep && timestampStep->type == cJSON_Number) {
g_Dbs.db[i].superTbls[j].timeStampStep = timestampStep->valueint; g_Dbs.db[i].superTbls[j].timeStampStep = timestampStep->valueint;
} else if (!timestampStep) { } else if (!timestampStep) {
g_Dbs.db[i].superTbls[j].timeStampStep = 1000; g_Dbs.db[i].superTbls[j].timeStampStep = DEFAULT_TIMESTAMP_STEP;
} else { } else {
printf("failed to read json, timestamp_step not found"); printf("ERROR: failed to read json, timestamp_step not found\n");
goto PARSE_OVER; goto PARSE_OVER;
} }
...@@ -3204,7 +3331,7 @@ static bool getMetaFromInsertJsonFile(cJSON* root) { ...@@ -3204,7 +3331,7 @@ static bool getMetaFromInsertJsonFile(cJSON* root) {
} else if (!sampleDataBufSize) { } else if (!sampleDataBufSize) {
g_Dbs.db[i].superTbls[j].sampleDataBufSize = 1024*1024 + 1024; g_Dbs.db[i].superTbls[j].sampleDataBufSize = 1024*1024 + 1024;
} else { } else {
printf("failed to read json, sample_buf_size not found"); printf("ERROR: failed to read json, sample_buf_size not found\n");
goto PARSE_OVER; goto PARSE_OVER;
} }
...@@ -3215,7 +3342,7 @@ static bool getMetaFromInsertJsonFile(cJSON* root) { ...@@ -3215,7 +3342,7 @@ static bool getMetaFromInsertJsonFile(cJSON* root) {
} else if (!sampleFormat) { } else if (!sampleFormat) {
tstrncpy(g_Dbs.db[i].superTbls[j].sampleFormat, "csv", MAX_DB_NAME_SIZE); tstrncpy(g_Dbs.db[i].superTbls[j].sampleFormat, "csv", MAX_DB_NAME_SIZE);
} else { } else {
printf("failed to read json, sample_format not found"); printf("ERROR: failed to read json, sample_format not found\n");
goto PARSE_OVER; goto PARSE_OVER;
} }
...@@ -3226,7 +3353,7 @@ static bool getMetaFromInsertJsonFile(cJSON* root) { ...@@ -3226,7 +3353,7 @@ static bool getMetaFromInsertJsonFile(cJSON* root) {
} else if (!sampleFile) { } else if (!sampleFile) {
memset(g_Dbs.db[i].superTbls[j].sampleFile, 0, MAX_FILE_NAME_LEN); memset(g_Dbs.db[i].superTbls[j].sampleFile, 0, MAX_FILE_NAME_LEN);
} else { } else {
printf("failed to read json, sample_file not found"); printf("ERROR: failed to read json, sample_file not found\n");
goto PARSE_OVER; goto PARSE_OVER;
} }
...@@ -3243,7 +3370,7 @@ static bool getMetaFromInsertJsonFile(cJSON* root) { ...@@ -3243,7 +3370,7 @@ static bool getMetaFromInsertJsonFile(cJSON* root) {
memset(g_Dbs.db[i].superTbls[j].tagsFile, 0, MAX_FILE_NAME_LEN); memset(g_Dbs.db[i].superTbls[j].tagsFile, 0, MAX_FILE_NAME_LEN);
g_Dbs.db[i].superTbls[j].tagSource = 0; g_Dbs.db[i].superTbls[j].tagSource = 0;
} else { } else {
printf("failed to read json, tags_file not found"); printf("ERROR: failed to read json, tags_file not found\n");
goto PARSE_OVER; goto PARSE_OVER;
} }
...@@ -3259,7 +3386,7 @@ static bool getMetaFromInsertJsonFile(cJSON* root) { ...@@ -3259,7 +3386,7 @@ static bool getMetaFromInsertJsonFile(cJSON* root) {
} else if (!maxSqlLen) { } else if (!maxSqlLen) {
g_Dbs.db[i].superTbls[j].maxSqlLen = TSDB_MAX_SQL_LEN; g_Dbs.db[i].superTbls[j].maxSqlLen = TSDB_MAX_SQL_LEN;
} else { } else {
printf("failed to read json, maxSqlLen not found"); printf("ERROR: failed to read json, maxSqlLen not found\n");
goto PARSE_OVER; goto PARSE_OVER;
} }
...@@ -3276,7 +3403,7 @@ static bool getMetaFromInsertJsonFile(cJSON* root) { ...@@ -3276,7 +3403,7 @@ static bool getMetaFromInsertJsonFile(cJSON* root) {
} else if (!multiThreadWriteOneTbl) { } else if (!multiThreadWriteOneTbl) {
g_Dbs.db[i].superTbls[j].multiThreadWriteOneTbl = 0; g_Dbs.db[i].superTbls[j].multiThreadWriteOneTbl = 0;
} else { } else {
printf("failed to read json, multiThreadWriteOneTbl not found"); printf("ERROR: failed to read json, multiThreadWriteOneTbl not found\n");
goto PARSE_OVER; goto PARSE_OVER;
} }
...@@ -3286,7 +3413,7 @@ static bool getMetaFromInsertJsonFile(cJSON* root) { ...@@ -3286,7 +3413,7 @@ static bool getMetaFromInsertJsonFile(cJSON* root) {
} else if (!numberOfTblInOneSql) { } else if (!numberOfTblInOneSql) {
g_Dbs.db[i].superTbls[j].numberOfTblInOneSql = 0; g_Dbs.db[i].superTbls[j].numberOfTblInOneSql = 0;
} else { } else {
printf("failed to read json, numberOfTblInOneSql not found"); printf("ERROR: failed to read json, numberOfTblInOneSql not found\n");
goto PARSE_OVER; goto PARSE_OVER;
} }
...@@ -3296,7 +3423,7 @@ static bool getMetaFromInsertJsonFile(cJSON* root) { ...@@ -3296,7 +3423,7 @@ static bool getMetaFromInsertJsonFile(cJSON* root) {
} else if (!rowsPerTbl) { } else if (!rowsPerTbl) {
g_Dbs.db[i].superTbls[j].rowsPerTbl = 1; g_Dbs.db[i].superTbls[j].rowsPerTbl = 1;
} else { } else {
printf("failed to read json, rowsPerTbl not found"); printf("ERROR: failed to read json, rowsPerTbl not found\n");
goto PARSE_OVER; goto PARSE_OVER;
} }
...@@ -3306,7 +3433,7 @@ static bool getMetaFromInsertJsonFile(cJSON* root) { ...@@ -3306,7 +3433,7 @@ static bool getMetaFromInsertJsonFile(cJSON* root) {
} else if (!disorderRatio) { } else if (!disorderRatio) {
g_Dbs.db[i].superTbls[j].disorderRatio = 0; g_Dbs.db[i].superTbls[j].disorderRatio = 0;
} else { } else {
printf("failed to read json, disorderRatio not found"); printf("ERROR: failed to read json, disorderRatio not found\n");
goto PARSE_OVER; goto PARSE_OVER;
} }
...@@ -3316,7 +3443,7 @@ static bool getMetaFromInsertJsonFile(cJSON* root) { ...@@ -3316,7 +3443,7 @@ static bool getMetaFromInsertJsonFile(cJSON* root) {
} else if (!disorderRange) { } else if (!disorderRange) {
g_Dbs.db[i].superTbls[j].disorderRange = 1000; g_Dbs.db[i].superTbls[j].disorderRange = 1000;
} else { } else {
printf("failed to read json, disorderRange not found"); printf("ERROR: failed to read json, disorderRange not found\n");
goto PARSE_OVER; goto PARSE_OVER;
} }
...@@ -3326,7 +3453,7 @@ static bool getMetaFromInsertJsonFile(cJSON* root) { ...@@ -3326,7 +3453,7 @@ static bool getMetaFromInsertJsonFile(cJSON* root) {
} else if (!insertRows) { } else if (!insertRows) {
g_Dbs.db[i].superTbls[j].insertRows = 0x7FFFFFFFFFFFFFFF; g_Dbs.db[i].superTbls[j].insertRows = 0x7FFFFFFFFFFFFFFF;
} else { } else {
printf("failed to read json, insert_rows input mistake"); fprintf(stderr, "failed to read json, insert_rows input mistake");
goto PARSE_OVER; goto PARSE_OVER;
} }
...@@ -3338,7 +3465,7 @@ static bool getMetaFromInsertJsonFile(cJSON* root) { ...@@ -3338,7 +3465,7 @@ static bool getMetaFromInsertJsonFile(cJSON* root) {
__func__, __LINE__, g_args.insert_interval); __func__, __LINE__, g_args.insert_interval);
g_Dbs.db[i].superTbls[j].insertInterval = g_args.insert_interval; g_Dbs.db[i].superTbls[j].insertInterval = g_args.insert_interval;
} else { } else {
printf("failed to read json, insert_interval input mistake"); fprintf(stderr, "failed to read json, insert_interval input mistake");
goto PARSE_OVER; goto PARSE_OVER;
} }
...@@ -3377,7 +3504,7 @@ static bool getMetaFromQueryJsonFile(cJSON* root) { ...@@ -3377,7 +3504,7 @@ static bool getMetaFromQueryJsonFile(cJSON* root) {
} else if (!host) { } else if (!host) {
tstrncpy(g_queryInfo.host, "127.0.0.1", MAX_DB_NAME_SIZE); tstrncpy(g_queryInfo.host, "127.0.0.1", MAX_DB_NAME_SIZE);
} else { } else {
printf("failed to read json, host not found\n"); printf("ERROR: failed to read json, host not found\n");
goto PARSE_OVER; goto PARSE_OVER;
} }
...@@ -3415,7 +3542,7 @@ static bool getMetaFromQueryJsonFile(cJSON* root) { ...@@ -3415,7 +3542,7 @@ static bool getMetaFromQueryJsonFile(cJSON* root) {
} else if (!answerPrompt) { } else if (!answerPrompt) {
g_args.answer_yes = false; g_args.answer_yes = false;
} else { } else {
printf("failed to read json, confirm_parameter_prompt not found"); printf("ERROR: failed to read json, confirm_parameter_prompt not found\n");
goto PARSE_OVER; goto PARSE_OVER;
} }
...@@ -3423,7 +3550,7 @@ static bool getMetaFromQueryJsonFile(cJSON* root) { ...@@ -3423,7 +3550,7 @@ static bool getMetaFromQueryJsonFile(cJSON* root) {
if (dbs && dbs->type == cJSON_String && dbs->valuestring != NULL) { if (dbs && dbs->type == cJSON_String && dbs->valuestring != NULL) {
tstrncpy(g_queryInfo.dbName, dbs->valuestring, MAX_DB_NAME_SIZE); tstrncpy(g_queryInfo.dbName, dbs->valuestring, MAX_DB_NAME_SIZE);
} else if (!dbs) { } else if (!dbs) {
printf("failed to read json, databases not found\n"); printf("ERROR: failed to read json, databases not found\n");
goto PARSE_OVER; goto PARSE_OVER;
} }
...@@ -3433,7 +3560,7 @@ static bool getMetaFromQueryJsonFile(cJSON* root) { ...@@ -3433,7 +3560,7 @@ static bool getMetaFromQueryJsonFile(cJSON* root) {
} else if (!queryMode) { } else if (!queryMode) {
tstrncpy(g_queryInfo.queryMode, "taosc", MAX_TB_NAME_SIZE); tstrncpy(g_queryInfo.queryMode, "taosc", MAX_TB_NAME_SIZE);
} else { } else {
printf("failed to read json, query_mode not found\n"); printf("ERROR: failed to read json, query_mode not found\n");
goto PARSE_OVER; goto PARSE_OVER;
} }
...@@ -3443,7 +3570,7 @@ static bool getMetaFromQueryJsonFile(cJSON* root) { ...@@ -3443,7 +3570,7 @@ static bool getMetaFromQueryJsonFile(cJSON* root) {
g_queryInfo.superQueryInfo.concurrent = 0; g_queryInfo.superQueryInfo.concurrent = 0;
g_queryInfo.superQueryInfo.sqlCount = 0; g_queryInfo.superQueryInfo.sqlCount = 0;
} else if (superQuery->type != cJSON_Object) { } else if (superQuery->type != cJSON_Object) {
printf("failed to read json, super_table_query not found"); printf("ERROR: failed to read json, super_table_query not found\n");
goto PARSE_OVER; goto PARSE_OVER;
} else { } else {
cJSON* rate = cJSON_GetObjectItem(superQuery, "query_interval"); cJSON* rate = cJSON_GetObjectItem(superQuery, "query_interval");
...@@ -3467,7 +3594,7 @@ static bool getMetaFromQueryJsonFile(cJSON* root) { ...@@ -3467,7 +3594,7 @@ static bool getMetaFromQueryJsonFile(cJSON* root) {
} else if (0 == strcmp("async", mode->valuestring)) { } else if (0 == strcmp("async", mode->valuestring)) {
g_queryInfo.superQueryInfo.subscribeMode = 1; g_queryInfo.superQueryInfo.subscribeMode = 1;
} else { } else {
printf("failed to read json, subscribe mod error\n"); printf("ERROR: failed to read json, subscribe mod error\n");
goto PARSE_OVER; goto PARSE_OVER;
} }
} else { } else {
...@@ -3490,7 +3617,7 @@ static bool getMetaFromQueryJsonFile(cJSON* root) { ...@@ -3490,7 +3617,7 @@ static bool getMetaFromQueryJsonFile(cJSON* root) {
} else if (0 == strcmp("no", restart->valuestring)) { } else if (0 == strcmp("no", restart->valuestring)) {
g_queryInfo.superQueryInfo.subscribeRestart = 0; g_queryInfo.superQueryInfo.subscribeRestart = 0;
} else { } else {
printf("failed to read json, subscribe restart error\n"); printf("ERROR: failed to read json, subscribe restart error\n");
goto PARSE_OVER; goto PARSE_OVER;
} }
} else { } else {
...@@ -3506,7 +3633,7 @@ static bool getMetaFromQueryJsonFile(cJSON* root) { ...@@ -3506,7 +3633,7 @@ static bool getMetaFromQueryJsonFile(cJSON* root) {
} else if (0 == strcmp("no", keepProgress->valuestring)) { } else if (0 == strcmp("no", keepProgress->valuestring)) {
g_queryInfo.superQueryInfo.subscribeKeepProgress = 0; g_queryInfo.superQueryInfo.subscribeKeepProgress = 0;
} else { } else {
printf("failed to read json, subscribe keepProgress error\n"); printf("ERROR: failed to read json, subscribe keepProgress error\n");
goto PARSE_OVER; goto PARSE_OVER;
} }
} else { } else {
...@@ -3518,12 +3645,12 @@ static bool getMetaFromQueryJsonFile(cJSON* root) { ...@@ -3518,12 +3645,12 @@ static bool getMetaFromQueryJsonFile(cJSON* root) {
if (!superSqls) { if (!superSqls) {
g_queryInfo.superQueryInfo.sqlCount = 0; g_queryInfo.superQueryInfo.sqlCount = 0;
} else if (superSqls->type != cJSON_Array) { } else if (superSqls->type != cJSON_Array) {
printf("failed to read json, super sqls not found\n"); printf("ERROR: failed to read json, super sqls not found\n");
goto PARSE_OVER; goto PARSE_OVER;
} else { } else {
int superSqlSize = cJSON_GetArraySize(superSqls); int superSqlSize = cJSON_GetArraySize(superSqls);
if (superSqlSize > MAX_QUERY_SQL_COUNT) { if (superSqlSize > MAX_QUERY_SQL_COUNT) {
printf("failed to read json, query sql size overflow, max is %d\n", MAX_QUERY_SQL_COUNT); printf("ERROR: failed to read json, query sql size overflow, max is %d\n", MAX_QUERY_SQL_COUNT);
goto PARSE_OVER; goto PARSE_OVER;
} }
...@@ -3534,7 +3661,7 @@ static bool getMetaFromQueryJsonFile(cJSON* root) { ...@@ -3534,7 +3661,7 @@ static bool getMetaFromQueryJsonFile(cJSON* root) {
cJSON *sqlStr = cJSON_GetObjectItem(sql, "sql"); cJSON *sqlStr = cJSON_GetObjectItem(sql, "sql");
if (!sqlStr || sqlStr->type != cJSON_String || sqlStr->valuestring == NULL) { if (!sqlStr || sqlStr->type != cJSON_String || sqlStr->valuestring == NULL) {
printf("failed to read json, sql not found\n"); printf("ERROR: failed to read json, sql not found\n");
goto PARSE_OVER; goto PARSE_OVER;
} }
tstrncpy(g_queryInfo.superQueryInfo.sql[j], sqlStr->valuestring, MAX_QUERY_SQL_LENGTH); tstrncpy(g_queryInfo.superQueryInfo.sql[j], sqlStr->valuestring, MAX_QUERY_SQL_LENGTH);
...@@ -3545,7 +3672,7 @@ static bool getMetaFromQueryJsonFile(cJSON* root) { ...@@ -3545,7 +3672,7 @@ static bool getMetaFromQueryJsonFile(cJSON* root) {
} else if (NULL == result) { } else if (NULL == result) {
memset(g_queryInfo.superQueryInfo.result[j], 0, MAX_FILE_NAME_LEN); memset(g_queryInfo.superQueryInfo.result[j], 0, MAX_FILE_NAME_LEN);
} else { } else {
printf("failed to read json, super query result file not found\n"); printf("ERROR: failed to read json, super query result file not found\n");
goto PARSE_OVER; goto PARSE_OVER;
} }
} }
...@@ -3558,7 +3685,7 @@ static bool getMetaFromQueryJsonFile(cJSON* root) { ...@@ -3558,7 +3685,7 @@ static bool getMetaFromQueryJsonFile(cJSON* root) {
g_queryInfo.subQueryInfo.threadCnt = 0; g_queryInfo.subQueryInfo.threadCnt = 0;
g_queryInfo.subQueryInfo.sqlCount = 0; g_queryInfo.subQueryInfo.sqlCount = 0;
} else if (subQuery->type != cJSON_Object) { } else if (subQuery->type != cJSON_Object) {
printf("failed to read json, sub_table_query not found"); printf("ERROR: failed to read json, sub_table_query not found\n");
ret = true; ret = true;
goto PARSE_OVER; goto PARSE_OVER;
} else { } else {
...@@ -3587,7 +3714,7 @@ static bool getMetaFromQueryJsonFile(cJSON* root) { ...@@ -3587,7 +3714,7 @@ static bool getMetaFromQueryJsonFile(cJSON* root) {
if (stblname && stblname->type == cJSON_String && stblname->valuestring != NULL) { if (stblname && stblname->type == cJSON_String && stblname->valuestring != NULL) {
tstrncpy(g_queryInfo.subQueryInfo.sTblName, stblname->valuestring, MAX_TB_NAME_SIZE); tstrncpy(g_queryInfo.subQueryInfo.sTblName, stblname->valuestring, MAX_TB_NAME_SIZE);
} else { } else {
printf("failed to read json, super table name not found\n"); printf("ERROR: failed to read json, super table name not found\n");
goto PARSE_OVER; goto PARSE_OVER;
} }
...@@ -3598,7 +3725,7 @@ static bool getMetaFromQueryJsonFile(cJSON* root) { ...@@ -3598,7 +3725,7 @@ static bool getMetaFromQueryJsonFile(cJSON* root) {
} else if (0 == strcmp("async", submode->valuestring)) { } else if (0 == strcmp("async", submode->valuestring)) {
g_queryInfo.subQueryInfo.subscribeMode = 1; g_queryInfo.subQueryInfo.subscribeMode = 1;
} else { } else {
printf("failed to read json, subscribe mod error\n"); printf("ERROR: failed to read json, subscribe mod error\n");
goto PARSE_OVER; goto PARSE_OVER;
} }
} else { } else {
...@@ -3621,7 +3748,7 @@ static bool getMetaFromQueryJsonFile(cJSON* root) { ...@@ -3621,7 +3748,7 @@ static bool getMetaFromQueryJsonFile(cJSON* root) {
} else if (0 == strcmp("no", subrestart->valuestring)) { } else if (0 == strcmp("no", subrestart->valuestring)) {
g_queryInfo.subQueryInfo.subscribeRestart = 0; g_queryInfo.subQueryInfo.subscribeRestart = 0;
} else { } else {
printf("failed to read json, subscribe restart error\n"); printf("ERROR: failed to read json, subscribe restart error\n");
goto PARSE_OVER; goto PARSE_OVER;
} }
} else { } else {
...@@ -3635,7 +3762,7 @@ static bool getMetaFromQueryJsonFile(cJSON* root) { ...@@ -3635,7 +3762,7 @@ static bool getMetaFromQueryJsonFile(cJSON* root) {
} else if (0 == strcmp("no", subkeepProgress->valuestring)) { } else if (0 == strcmp("no", subkeepProgress->valuestring)) {
g_queryInfo.subQueryInfo.subscribeKeepProgress = 0; g_queryInfo.subQueryInfo.subscribeKeepProgress = 0;
} else { } else {
printf("failed to read json, subscribe keepProgress error\n"); printf("ERROR: failed to read json, subscribe keepProgress error\n");
goto PARSE_OVER; goto PARSE_OVER;
} }
} else { } else {
...@@ -3647,12 +3774,12 @@ static bool getMetaFromQueryJsonFile(cJSON* root) { ...@@ -3647,12 +3774,12 @@ static bool getMetaFromQueryJsonFile(cJSON* root) {
if (!subsqls) { if (!subsqls) {
g_queryInfo.subQueryInfo.sqlCount = 0; g_queryInfo.subQueryInfo.sqlCount = 0;
} else if (subsqls->type != cJSON_Array) { } else if (subsqls->type != cJSON_Array) {
printf("failed to read json, super sqls not found\n"); printf("ERROR: failed to read json, super sqls not found\n");
goto PARSE_OVER; goto PARSE_OVER;
} else { } else {
int superSqlSize = cJSON_GetArraySize(subsqls); int superSqlSize = cJSON_GetArraySize(subsqls);
if (superSqlSize > MAX_QUERY_SQL_COUNT) { if (superSqlSize > MAX_QUERY_SQL_COUNT) {
printf("failed to read json, query sql size overflow, max is %d\n", MAX_QUERY_SQL_COUNT); printf("ERROR: failed to read json, query sql size overflow, max is %d\n", MAX_QUERY_SQL_COUNT);
goto PARSE_OVER; goto PARSE_OVER;
} }
...@@ -3663,7 +3790,7 @@ static bool getMetaFromQueryJsonFile(cJSON* root) { ...@@ -3663,7 +3790,7 @@ static bool getMetaFromQueryJsonFile(cJSON* root) {
cJSON *sqlStr = cJSON_GetObjectItem(sql, "sql"); cJSON *sqlStr = cJSON_GetObjectItem(sql, "sql");
if (!sqlStr || sqlStr->type != cJSON_String || sqlStr->valuestring == NULL) { if (!sqlStr || sqlStr->type != cJSON_String || sqlStr->valuestring == NULL) {
printf("failed to read json, sql not found\n"); printf("ERROR: failed to read json, sql not found\n");
goto PARSE_OVER; goto PARSE_OVER;
} }
tstrncpy(g_queryInfo.subQueryInfo.sql[j], sqlStr->valuestring, MAX_QUERY_SQL_LENGTH); tstrncpy(g_queryInfo.subQueryInfo.sql[j], sqlStr->valuestring, MAX_QUERY_SQL_LENGTH);
...@@ -3674,7 +3801,7 @@ static bool getMetaFromQueryJsonFile(cJSON* root) { ...@@ -3674,7 +3801,7 @@ static bool getMetaFromQueryJsonFile(cJSON* root) {
} else if (NULL == result) { } else if (NULL == result) {
memset(g_queryInfo.subQueryInfo.result[j], 0, MAX_FILE_NAME_LEN); memset(g_queryInfo.subQueryInfo.result[j], 0, MAX_FILE_NAME_LEN);
} else { } else {
printf("failed to read json, sub query result file not found\n"); printf("ERROR: failed to read json, sub query result file not found\n");
goto PARSE_OVER; goto PARSE_OVER;
} }
} }
...@@ -3713,7 +3840,7 @@ static bool getInfoFromJsonFile(char* file) { ...@@ -3713,7 +3840,7 @@ static bool getInfoFromJsonFile(char* file) {
content[len] = 0; content[len] = 0;
cJSON* root = cJSON_Parse(content); cJSON* root = cJSON_Parse(content);
if (root == NULL) { if (root == NULL) {
printf("failed to cjson parse %s, invalid json format", file); printf("ERROR: failed to cjson parse %s, invalid json format\n", file);
goto PARSE_OVER; goto PARSE_OVER;
} }
...@@ -3726,13 +3853,13 @@ static bool getInfoFromJsonFile(char* file) { ...@@ -3726,13 +3853,13 @@ static bool getInfoFromJsonFile(char* file) {
} else if (0 == strcasecmp("subscribe", filetype->valuestring)) { } else if (0 == strcasecmp("subscribe", filetype->valuestring)) {
g_args.test_mode = SUBSCRIBE_MODE; g_args.test_mode = SUBSCRIBE_MODE;
} else { } else {
printf("failed to read json, filetype not support\n"); printf("ERROR: failed to read json, filetype not support\n");
goto PARSE_OVER; goto PARSE_OVER;
} }
} else if (!filetype) { } else if (!filetype) {
g_args.test_mode = INSERT_MODE; g_args.test_mode = INSERT_MODE;
} else { } else {
printf("failed to read json, filetype not found\n"); printf("ERROR: failed to read json, filetype not found\n");
goto PARSE_OVER; goto PARSE_OVER;
} }
...@@ -3743,7 +3870,7 @@ static bool getInfoFromJsonFile(char* file) { ...@@ -3743,7 +3870,7 @@ static bool getInfoFromJsonFile(char* file) {
} else if (SUBSCRIBE_MODE == g_args.test_mode) { } else if (SUBSCRIBE_MODE == g_args.test_mode) {
ret = getMetaFromQueryJsonFile(root); ret = getMetaFromQueryJsonFile(root);
} else { } else {
printf("input json file type error! please input correct file type: insert or query or subscribe\n"); printf("ERROR: input json file type error! please input correct file type: insert or query or subscribe\n");
goto PARSE_OVER; goto PARSE_OVER;
} }
...@@ -3754,7 +3881,7 @@ PARSE_OVER: ...@@ -3754,7 +3881,7 @@ PARSE_OVER:
return ret; return ret;
} }
void prePareSampleData() { void prepareSampleData() {
for (int i = 0; i < g_Dbs.dbCount; i++) { for (int i = 0; i < g_Dbs.dbCount; i++) {
for (int j = 0; j < g_Dbs.db[i].superTblCount; j++) { for (int j = 0; j < g_Dbs.db[i].superTblCount; j++) {
//if (0 == strncasecmp(g_Dbs.db[i].superTbls[j].dataSource, "sample", 6)) { //if (0 == strncasecmp(g_Dbs.db[i].superTbls[j].dataSource, "sample", 6)) {
...@@ -3792,18 +3919,22 @@ void postFreeResource() { ...@@ -3792,18 +3919,22 @@ void postFreeResource() {
} }
} }
int getRowDataFromSample(char* dataBuf, int maxLen, int64_t timestamp, SSuperTable* superTblInfo, int* sampleUsePos, FILE *fp, char* sampleBuf) { static int getRowDataFromSample(char* dataBuf, int maxLen, int64_t timestamp,
SSuperTable* superTblInfo, int* sampleUsePos) {
if ((*sampleUsePos) == MAX_SAMPLES_ONCE_FROM_FILE) { if ((*sampleUsePos) == MAX_SAMPLES_ONCE_FROM_FILE) {
int ret = readSampleFromCsvFileToMem(fp, superTblInfo, sampleBuf); int ret = readSampleFromCsvFileToMem(superTblInfo);
if (0 != ret) { if (0 != ret) {
tmfree(superTblInfo->sampleDataBuf);
return -1; return -1;
} }
*sampleUsePos = 0; *sampleUsePos = 0;
} }
int dataLen = 0; int dataLen = 0;
dataLen += snprintf(dataBuf + dataLen, maxLen - dataLen, "(%" PRId64 ", ", timestamp); dataLen += snprintf(dataBuf + dataLen, maxLen - dataLen,
dataLen += snprintf(dataBuf + dataLen, maxLen - dataLen, "%s", sampleBuf + superTblInfo->lenOfOneRow * (*sampleUsePos)); "(%" PRId64 ", ", timestamp);
dataLen += snprintf(dataBuf + dataLen, maxLen - dataLen,
"%s", superTblInfo->sampleDataBuf + superTblInfo->lenOfOneRow * (*sampleUsePos));
dataLen += snprintf(dataBuf + dataLen, maxLen - dataLen, ")"); dataLen += snprintf(dataBuf + dataLen, maxLen - dataLen, ")");
(*sampleUsePos)++; (*sampleUsePos)++;
...@@ -3858,14 +3989,12 @@ int generateRowData(char* dataBuf, int maxLen, int64_t timestamp, SSuperTable* ...@@ -3858,14 +3989,12 @@ int generateRowData(char* dataBuf, int maxLen, int64_t timestamp, SSuperTable*
} }
static void syncWriteForNumberOfTblInOneSql( static void syncWriteForNumberOfTblInOneSql(
threadInfo *winfo, FILE *fp, char* sampleDataBuf) { threadInfo *winfo, char* sampleDataBuf) {
SSuperTable* superTblInfo = winfo->superTblInfo; SSuperTable* superTblInfo = winfo->superTblInfo;
int samplePos = 0; int samplePos = 0;
//printf("========threadID[%d], table rang: %d - %d \n", winfo->threadID, winfo->start_table_id, winfo->end_table_id); //printf("========threadID[%d], table rang: %d - %d \n", winfo->threadID, winfo->start_table_id, winfo->end_table_id);
int64_t totalRowsInserted = 0;
int64_t totalAffectedRows = 0;
int64_t lastPrintTime = taosGetTimestampMs(); int64_t lastPrintTime = taosGetTimestampMs();
char* buffer = calloc(superTblInfo->maxSqlLen+1, 1); char* buffer = calloc(superTblInfo->maxSqlLen+1, 1);
...@@ -3883,12 +4012,13 @@ static void syncWriteForNumberOfTblInOneSql( ...@@ -3883,12 +4012,13 @@ static void syncWriteForNumberOfTblInOneSql(
uint64_t time_counter = winfo->start_time; uint64_t time_counter = winfo->start_time;
int sampleUsePos; int sampleUsePos;
int insert_interval = superTblInfo?superTblInfo->insertInterval:g_args.insert_interval;
int64_t st = 0; int64_t st = 0;
int64_t et = 0; int64_t et = 0xffffffff;
for (int i = 0; i < superTblInfo->insertRows;) { for (int i = 0; i < superTblInfo->insertRows;) {
int32_t tbl_id = 0; int32_t tbl_id = 0;
for (int tID = winfo->start_table_id; tID <= winfo->end_table_id; ) { for (int tableSeq = winfo->start_table_id; tableSeq <= winfo->end_table_id; ) {
int64_t tmp_time = 0; int64_t start_time = 0;
int inserted = i; int inserted = i;
for (int k = 0; k < g_args.num_of_RPR;) { for (int k = 0; k < g_args.num_of_RPR;) {
...@@ -3896,12 +4026,12 @@ static void syncWriteForNumberOfTblInOneSql( ...@@ -3896,12 +4026,12 @@ static void syncWriteForNumberOfTblInOneSql(
memset(buffer, 0, superTblInfo->maxSqlLen); memset(buffer, 0, superTblInfo->maxSqlLen);
char *pstr = buffer; char *pstr = buffer;
int32_t end_tbl_id = tID + numberOfTblInOneSql; int32_t end_tbl_id = tableSeq + numberOfTblInOneSql;
if (end_tbl_id > winfo->end_table_id) { if (end_tbl_id > winfo->end_table_id) {
end_tbl_id = winfo->end_table_id+1; end_tbl_id = winfo->end_table_id+1;
} }
for (tbl_id = tID; tbl_id < end_tbl_id; tbl_id++) { for (tbl_id = tableSeq ; tbl_id < end_tbl_id; tbl_id++) {
sampleUsePos = samplePos; sampleUsePos = samplePos;
if (AUTO_CREATE_SUBTBL == superTblInfo->autoCreateTable) { if (AUTO_CREATE_SUBTBL == superTblInfo->autoCreateTable) {
char* tagsValBuf = NULL; char* tagsValBuf = NULL;
...@@ -3969,18 +4099,16 @@ static void syncWriteForNumberOfTblInOneSql( ...@@ -3969,18 +4099,16 @@ static void syncWriteForNumberOfTblInOneSql(
} }
} }
tmp_time = time_counter; start_time = time_counter;
for (k = 0; k < superTblInfo->rowsPerTbl;) { for (int j = 0; j < superTblInfo->rowsPerTbl;) {
int retLen = 0; int retLen = 0;
if (0 == strncasecmp(superTblInfo->dataSource, if (0 == strncasecmp(superTblInfo->dataSource,
"sample", strlen("sample"))) { "sample", strlen("sample"))) {
retLen = getRowDataFromSample(pstr + len, retLen = getRowDataFromSample(pstr + len,
superTblInfo->maxSqlLen - len, superTblInfo->maxSqlLen - len,
tmp_time += superTblInfo->timeStampStep, start_time += superTblInfo->timeStampStep,
superTblInfo, superTblInfo,
&sampleUsePos, &sampleUsePos);
fp,
sampleDataBuf);
if (retLen < 0) { if (retLen < 0) {
goto free_and_statistics; goto free_and_statistics;
} }
...@@ -3989,7 +4117,7 @@ static void syncWriteForNumberOfTblInOneSql( ...@@ -3989,7 +4117,7 @@ static void syncWriteForNumberOfTblInOneSql(
int rand_num = rand_tinyint() % 100; int rand_num = rand_tinyint() % 100;
if (0 != superTblInfo->disorderRatio if (0 != superTblInfo->disorderRatio
&& rand_num < superTblInfo->disorderRatio) { && rand_num < superTblInfo->disorderRatio) {
int64_t d = tmp_time - rand() % superTblInfo->disorderRange; int64_t d = start_time - rand() % superTblInfo->disorderRange;
retLen = generateRowData(pstr + len, retLen = generateRowData(pstr + len,
superTblInfo->maxSqlLen - len, superTblInfo->maxSqlLen - len,
d, d,
...@@ -3997,7 +4125,7 @@ static void syncWriteForNumberOfTblInOneSql( ...@@ -3997,7 +4125,7 @@ static void syncWriteForNumberOfTblInOneSql(
} else { } else {
retLen = generateRowData(pstr + len, retLen = generateRowData(pstr + len,
superTblInfo->maxSqlLen - len, superTblInfo->maxSqlLen - len,
tmp_time += superTblInfo->timeStampStep, start_time += superTblInfo->timeStampStep,
superTblInfo); superTblInfo);
} }
if (retLen < 0) { if (retLen < 0) {
...@@ -4006,12 +4134,12 @@ static void syncWriteForNumberOfTblInOneSql( ...@@ -4006,12 +4134,12 @@ static void syncWriteForNumberOfTblInOneSql(
} }
len += retLen; len += retLen;
//inserted++; //inserted++;
k++; j++;
totalRowsInserted++; winfo->totalInsertRows++;
if (inserted >= superTblInfo->insertRows || if (inserted >= superTblInfo->insertRows ||
(superTblInfo->maxSqlLen - len) < (superTblInfo->lenOfOneRow + 128)) { (superTblInfo->maxSqlLen - len) < (superTblInfo->lenOfOneRow + 128)) {
tID = tbl_id + 1; tableSeq = tbl_id + 1;
printf("config rowsPerTbl and numberOfTblInOneSql not match with max_sql_lenth, please reconfig![lenOfOneRow:%d]\n", printf("config rowsPerTbl and numberOfTblInOneSql not match with max_sql_lenth, please reconfig![lenOfOneRow:%d]\n",
superTblInfo->lenOfOneRow); superTblInfo->lenOfOneRow);
goto send_to_server; goto send_to_server;
...@@ -4019,18 +4147,18 @@ static void syncWriteForNumberOfTblInOneSql( ...@@ -4019,18 +4147,18 @@ static void syncWriteForNumberOfTblInOneSql(
} }
} }
tID = tbl_id; tableSeq = tbl_id;
inserted += superTblInfo->rowsPerTbl; inserted += superTblInfo->rowsPerTbl;
send_to_server: send_to_server:
if (g_args.insert_interval && (g_args.insert_interval > (et - st))) { if (insert_interval) {
int sleep_time = g_args.insert_interval - (et -st); st = taosGetTimestampUs();
if (insert_interval > ((et - st)/1000)) {
int sleep_time = insert_interval - (et -st);
printf("sleep: %d ms insert interval\n", sleep_time); printf("sleep: %d ms insert interval\n", sleep_time);
taosMsleep(sleep_time); // ms taosMsleep(sleep_time); // ms
} }
if (g_args.insert_interval) {
st = taosGetTimestampMs();
} }
if (0 == strncasecmp(superTblInfo->insertMode, if (0 == strncasecmp(superTblInfo->insertMode,
...@@ -4064,7 +4192,7 @@ send_to_server: ...@@ -4064,7 +4192,7 @@ send_to_server:
if (currentPrintTime - lastPrintTime > 30*1000) { if (currentPrintTime - lastPrintTime > 30*1000) {
printf("thread[%d] has currently inserted rows: %"PRId64 ", affected rows: %"PRId64 "\n", printf("thread[%d] has currently inserted rows: %"PRId64 ", affected rows: %"PRId64 "\n",
winfo->threadID, winfo->threadID,
winfo->totalRowsInserted, winfo->totalInsertRows,
winfo->totalAffectedRows); winfo->totalAffectedRows);
lastPrintTime = currentPrintTime; lastPrintTime = currentPrintTime;
} }
...@@ -4081,19 +4209,19 @@ send_to_server: ...@@ -4081,19 +4209,19 @@ send_to_server:
goto free_and_statistics; goto free_and_statistics;
} }
} }
if (g_args.insert_interval) { if (insert_interval) {
et = taosGetTimestampMs(); et = taosGetTimestampUs();
} }
break; break;
} }
if (tID > winfo->end_table_id) { if (tableSeq > winfo->end_table_id) {
if (0 == strncasecmp(superTblInfo->dataSource, "sample", strlen("sample"))) { if (0 == strncasecmp(superTblInfo->dataSource, "sample", strlen("sample"))) {
samplePos = sampleUsePos; samplePos = sampleUsePos;
} }
i = inserted; i = inserted;
time_counter = tmp_time; time_counter = start_time;
} }
} }
...@@ -4102,14 +4230,13 @@ send_to_server: ...@@ -4102,14 +4230,13 @@ send_to_server:
free_and_statistics: free_and_statistics:
tmfree(buffer); tmfree(buffer);
winfo->totalRowsInserted = totalRowsInserted; printf("====thread[%d] completed total inserted rows: %"PRId64 ", affected rows: %"PRId64 "====\n",
winfo->totalAffectedRows = totalAffectedRows; winfo->threadID, winfo->totalInsertRows, winfo->totalAffectedRows);
printf("====thread[%d] completed total inserted rows: %"PRId64 ", affected rows: %"PRId64 "====\n", winfo->threadID, totalRowsInserted, totalAffectedRows);
return; return;
} }
int32_t generateData(char *res, char **data_type, int32_t generateData(char *res, char **data_type,
int num_of_cols, int64_t timestamp, int len_of_binary) { int num_of_cols, int64_t timestamp, int lenOfBinary) {
memset(res, 0, MAX_DATA_SIZE); memset(res, 0, MAX_DATA_SIZE);
char *pstr = res; char *pstr = res;
pstr += sprintf(pstr, "(%" PRId64, timestamp); pstr += sprintf(pstr, "(%" PRId64, timestamp);
...@@ -4144,13 +4271,13 @@ int32_t generateData(char *res, char **data_type, ...@@ -4144,13 +4271,13 @@ int32_t generateData(char *res, char **data_type,
bool b = rand() & 1; bool b = rand() & 1;
pstr += sprintf(pstr, ", %s", b ? "true" : "false"); pstr += sprintf(pstr, ", %s", b ? "true" : "false");
} else if (strcasecmp(data_type[i % c], "binary") == 0) { } else if (strcasecmp(data_type[i % c], "binary") == 0) {
char *s = malloc(len_of_binary); char *s = malloc(lenOfBinary);
rand_string(s, len_of_binary); rand_string(s, lenOfBinary);
pstr += sprintf(pstr, ", \"%s\"", s); pstr += sprintf(pstr, ", \"%s\"", s);
free(s); free(s);
}else if (strcasecmp(data_type[i % c], "nchar") == 0) { }else if (strcasecmp(data_type[i % c], "nchar") == 0) {
char *s = malloc(len_of_binary); char *s = malloc(lenOfBinary);
rand_string(s, len_of_binary); rand_string(s, lenOfBinary);
pstr += sprintf(pstr, ", \"%s\"", s); pstr += sprintf(pstr, ", \"%s\"", s);
free(s); free(s);
} }
...@@ -4166,143 +4293,8 @@ int32_t generateData(char *res, char **data_type, ...@@ -4166,143 +4293,8 @@ int32_t generateData(char *res, char **data_type,
return (int32_t)(pstr - res); return (int32_t)(pstr - res);
} }
// sync insertion static int prepareSampleDataForSTable(SSuperTable *superTblInfo) {
/*
1 thread: 100 tables * 2000 rows/s
1 thread: 10 tables * 20000 rows/s
6 thread: 300 tables * 2000 rows/s
2 taosinsertdata , 1 thread: 10 tables * 20000 rows/s
*/
static void* syncWrite(void *sarg) {
threadInfo *winfo = (threadInfo *)sarg;
char buffer[BUFFER_SIZE] = "\0";
char data[MAX_DATA_SIZE];
char **data_type = g_args.datatype;
int len_of_binary = g_args.len_of_binary;
int ncols_per_record = 1; // count first col ts
int i = 0;
while(g_args.datatype[i]) {
i ++;
ncols_per_record ++;
}
srand((uint32_t)time(NULL));
int64_t time_counter = winfo->start_time;
uint64_t st = 0;
uint64_t et = 0;
winfo->totalRowsInserted = 0;
winfo->totalAffectedRows = 0;
for (int tID = winfo->start_table_id; tID <= winfo->end_table_id; tID++) {
int64_t tmp_time = time_counter;
for (int i = 0; i < g_args.num_of_DPT;) {
int tblInserted = i;
char *pstr = buffer;
pstr += sprintf(pstr,
"insert into %s.%s%d values ",
winfo->db_name, g_args.tb_prefix, tID);
int k;
for (k = 0; k < g_args.num_of_RPR;) {
int rand_num = rand() % 100;
int len = -1;
if ((g_args.disorderRatio != 0)
&& (rand_num < g_args.disorderRange)) {
int64_t d = tmp_time - rand() % 1000000 + rand_num;
len = generateData(data, data_type,
ncols_per_record, d, len_of_binary);
} else {
len = generateData(data, data_type,
ncols_per_record, tmp_time += 1000, len_of_binary);
}
//assert(len + pstr - buffer < BUFFER_SIZE);
if (len + pstr - buffer >= BUFFER_SIZE) { // too long
break;
}
pstr += sprintf(pstr, " %s", data);
tblInserted++;
k++;
i++;
if (tblInserted >= g_args.num_of_DPT)
break;
}
winfo->totalRowsInserted += k;
/* puts(buffer); */
int64_t startTs;
int64_t endTs;
startTs = taosGetTimestampUs();
//queryDB(winfo->taos, buffer);
if (i > 0 && g_args.insert_interval
&& (g_args.insert_interval > (et - st) )) {
int sleep_time = g_args.insert_interval - (et -st);
printf("sleep: %d ms specified by insert_interval\n", sleep_time);
taosMsleep(sleep_time); // ms
}
if (g_args.insert_interval) {
st = taosGetTimestampMs();
}
verbosePrint("%s() LN%d %s\n", __func__, __LINE__, buffer);
int affectedRows = queryDbExec(winfo->taos, buffer, 1);
if (0 < affectedRows){
endTs = taosGetTimestampUs();
int64_t delay = endTs - startTs;
if (delay > winfo->maxDelay)
winfo->maxDelay = delay;
if (delay < winfo->minDelay)
winfo->minDelay = delay;
winfo->cntDelay++;
winfo->totalDelay += delay;
winfo->totalAffectedRows += affectedRows;
winfo->avgDelay = (double)winfo->totalDelay / winfo->cntDelay;
} else {
fprintf(stderr, "queryDbExec() buffer:\n%s\naffected rows is %d", buffer, affectedRows);
}
verbosePrint("%s() LN%d: totalaffectedRows:%"PRId64" tblInserted=%d\n", __func__, __LINE__, winfo->totalAffectedRows, tblInserted);
if (g_args.insert_interval) {
et = taosGetTimestampMs();
}
if (tblInserted >= g_args.num_of_DPT) {
break;
}
} // num_of_DPT
} // tId
printf("====thread[%d] completed total inserted rows: %"PRId64 ", total affected rows: %"PRId64 "====\n",
winfo->threadID,
winfo->totalRowsInserted,
winfo->totalAffectedRows);
return NULL;
}
static void* syncWriteWithStb(void *sarg) {
uint64_t lastPrintTime = taosGetTimestampMs();
threadInfo *winfo = (threadInfo *)sarg;
SSuperTable* superTblInfo = winfo->superTblInfo;
FILE *fp = NULL;
char* sampleDataBuf = NULL; char* sampleDataBuf = NULL;
int samplePos = 0;
// each thread read sample data from csv file // each thread read sample data from csv file
if (0 == strncasecmp(superTblInfo->dataSource, if (0 == strncasecmp(superTblInfo->dataSource,
...@@ -4311,82 +4303,100 @@ static void* syncWriteWithStb(void *sarg) { ...@@ -4311,82 +4303,100 @@ static void* syncWriteWithStb(void *sarg) {
sampleDataBuf = calloc( sampleDataBuf = calloc(
superTblInfo->lenOfOneRow * MAX_SAMPLES_ONCE_FROM_FILE, 1); superTblInfo->lenOfOneRow * MAX_SAMPLES_ONCE_FROM_FILE, 1);
if (sampleDataBuf == NULL) { if (sampleDataBuf == NULL) {
printf("Failed to calloc %d Bytes, reason:%s\n", fprintf(stderr, "Failed to calloc %d Bytes, reason:%s\n",
superTblInfo->lenOfOneRow * MAX_SAMPLES_ONCE_FROM_FILE, superTblInfo->lenOfOneRow * MAX_SAMPLES_ONCE_FROM_FILE,
strerror(errno)); strerror(errno));
return NULL; return -1;
} }
fp = fopen(superTblInfo->sampleFile, "r"); int ret = readSampleFromCsvFileToMem(superTblInfo);
if (fp == NULL) {
printf("Failed to open sample file: %s, reason:%s\n",
superTblInfo->sampleFile, strerror(errno));
tmfree(sampleDataBuf);
return NULL;
}
int ret = readSampleFromCsvFileToMem(fp,
superTblInfo, sampleDataBuf);
if (0 != ret) { if (0 != ret) {
tmfree(sampleDataBuf); tmfree(superTblInfo->sampleDataBuf);
tmfclose(fp); return -1;
return NULL;
} }
} }
if (superTblInfo->numberOfTblInOneSql > 0) { superTblInfo->sampleDataBuf = sampleDataBuf;
syncWriteForNumberOfTblInOneSql(winfo, fp, sampleDataBuf);
tmfree(sampleDataBuf);
tmfclose(fp);
return NULL;
}
char* buffer = calloc(superTblInfo->maxSqlLen, 1); return 0;
if (NULL == buffer) { }
printf("Failed to calloc %d Bytes, reason:%s\n",
superTblInfo->maxSqlLen,
strerror(errno));
tmfree(sampleDataBuf);
tmfclose(fp);
return NULL;
}
uint64_t st = 0; static int execInsert(threadInfo *winfo, char *buffer, int k)
uint64_t et = 0; {
int affectedRows;
SSuperTable* superTblInfo = winfo->superTblInfo;
winfo->totalRowsInserted = 0; if (superTblInfo) {
winfo->totalAffectedRows = 0; if (0 == strncasecmp(superTblInfo->insertMode, "taosc", strlen("taosc"))) {
verbosePrint("%s() LN%d %s\n", __func__, __LINE__, buffer);
affectedRows = queryDbExec(winfo->taos, buffer, INSERT_TYPE);
} else {
verbosePrint("%s() LN%d %s\n", __func__, __LINE__, buffer);
int retCode = postProceSql(g_Dbs.host, g_Dbs.port, buffer);
int sampleUsePos; if (0 != retCode) {
affectedRows = -1;
printf("========restful return fail, threadID[%d]\n", winfo->threadID);
} else {
affectedRows = k;
}
}
} else {
verbosePrint("%s() LN%d %s\n", __func__, __LINE__, buffer);
affectedRows = queryDbExec(winfo->taos, buffer, 1);
}
verbosePrint("%s() LN%d insertRows=%"PRId64"\n", __func__, __LINE__, superTblInfo->insertRows); if (0 > affectedRows){
return affectedRows;
}
for (uint32_t tID = winfo->start_table_id; tID <= winfo->end_table_id; return affectedRows;
tID++) { }
int64_t start_time = winfo->start_time;
for (int i = 0; i < superTblInfo->insertRows;) { static int generateDataBuffer(int32_t tableSeq,
threadInfo *pThreadInfo, char *buffer,
int64_t insertRows,
int64_t startFrom, int64_t startTime, int *pSampleUsePos)
{
SSuperTable* superTblInfo = pThreadInfo->superTblInfo;
int64_t tblInserted = i; int ncols_per_record = 1; // count first col ts
if (i > 0 && superTblInfo->insertInterval if (superTblInfo == NULL) {
&& (superTblInfo->insertInterval > (et - st) )) { int datatypeSeq = 0;
int sleep_time = superTblInfo->insertInterval - (et -st); while(g_args.datatype[datatypeSeq]) {
printf("sleep: %d ms insert interval\n", sleep_time); datatypeSeq ++;
taosMsleep(sleep_time); // ms ncols_per_record ++;
} }
if (superTblInfo->insertInterval) {
st = taosGetTimestampMs();
} }
sampleUsePos = samplePos; assert(buffer != NULL);
verbosePrint("%s() LN%d num_of_RPR=%d\n", __func__, __LINE__, g_args.num_of_RPR);
memset(buffer, 0, superTblInfo->maxSqlLen); char *pChildTblName;
int len = 0; int childTblCount;
if (superTblInfo && (superTblInfo->childTblOffset > 0)) {
// TODO
// select tbname from stb limit 1 offset tableSeq
getChildNameOfSuperTableWithLimitAndOffset(pThreadInfo->taos,
pThreadInfo->db_name, superTblInfo->sTblName,
&pChildTblName, &childTblCount,
1, tableSeq);
} else {
pChildTblName = calloc(TSDB_TABLE_NAME_LEN, 1);
if (NULL == pChildTblName) {
fprintf(stderr, "failed to alloc memory %d\n", TSDB_TABLE_NAME_LEN);
return -1;
}
snprintf(pChildTblName, TSDB_TABLE_NAME_LEN, "%s%d",
superTblInfo?superTblInfo->childTblPrefix:g_args.tb_prefix, tableSeq);
}
memset(buffer, 0, superTblInfo?superTblInfo->maxSqlLen:g_args.max_sql_len);
char *pstr = buffer; char *pstr = buffer;
if (superTblInfo) {
if (AUTO_CREATE_SUBTBL == superTblInfo->autoCreateTable) { if (AUTO_CREATE_SUBTBL == superTblInfo->autoCreateTable) {
char* tagsValBuf = NULL; char* tagsValBuf = NULL;
if (0 == superTblInfo->tagSource) { if (0 == superTblInfo->tagSource) {
...@@ -4394,109 +4404,203 @@ static void* syncWriteWithStb(void *sarg) { ...@@ -4394,109 +4404,203 @@ static void* syncWriteWithStb(void *sarg) {
} else { } else {
tagsValBuf = getTagValueFromTagSample( tagsValBuf = getTagValueFromTagSample(
superTblInfo, superTblInfo,
tID % superTblInfo->tagSampleCount); tableSeq % superTblInfo->tagSampleCount);
} }
if (NULL == tagsValBuf) { if (NULL == tagsValBuf) {
goto free_and_statistics_2; fprintf(stderr, "tag buf failed to allocate memory\n");
free(pChildTblName);
return -1;
} }
len += snprintf(pstr + len, pstr += snprintf(pstr,
superTblInfo->maxSqlLen - len, superTblInfo->maxSqlLen,
"insert into %s.%s%d using %s.%s tags %s values", "insert into %s.%s using %s.%s tags %s values",
winfo->db_name, pThreadInfo->db_name,
superTblInfo->childTblPrefix, pChildTblName,
tID, pThreadInfo->db_name,
winfo->db_name,
superTblInfo->sTblName, superTblInfo->sTblName,
tagsValBuf); tagsValBuf);
tmfree(tagsValBuf); tmfree(tagsValBuf);
} else if (TBL_ALREADY_EXISTS == superTblInfo->childTblExists) { } else if (TBL_ALREADY_EXISTS == superTblInfo->childTblExists) {
len += snprintf(pstr + len, pstr += snprintf(pstr,
superTblInfo->maxSqlLen - len, superTblInfo->maxSqlLen,
"insert into %s.%s values", "insert into %s.%s values",
winfo->db_name, pThreadInfo->db_name,
superTblInfo->childTblName + tID * TSDB_TABLE_NAME_LEN); superTblInfo->childTblName + tableSeq * TSDB_TABLE_NAME_LEN);
} else { } else {
len += snprintf(pstr + len, pstr += snprintf(pstr,
superTblInfo->maxSqlLen - len, (superTblInfo?superTblInfo->maxSqlLen:g_args.max_sql_len),
"insert into %s.%s%d values", "insert into %s.%s values",
winfo->db_name, pThreadInfo->db_name,
superTblInfo->childTblPrefix, pChildTblName);
tID); }
} else {
pstr += snprintf(pstr,
(superTblInfo?superTblInfo->maxSqlLen:g_args.max_sql_len),
"insert into %s.%s values",
pThreadInfo->db_name,
pChildTblName);
} }
int k; int k;
int len = 0;
verbosePrint("%s() LN%d num_of_RPR=%d\n", __func__, __LINE__, g_args.num_of_RPR);
for (k = 0; k < g_args.num_of_RPR;) { for (k = 0; k < g_args.num_of_RPR;) {
if (superTblInfo) {
int retLen = 0; int retLen = 0;
if (0 == strncasecmp(superTblInfo->dataSource, "sample", strlen("sample"))) {
if (0 == strncasecmp(superTblInfo->dataSource,
"sample", strlen("sample"))) {
retLen = getRowDataFromSample( retLen = getRowDataFromSample(
pstr + len, pstr + len,
superTblInfo->maxSqlLen - len, superTblInfo->maxSqlLen - len,
start_time + superTblInfo->timeStampStep * i, startTime + superTblInfo->timeStampStep * startFrom,
superTblInfo, superTblInfo,
&sampleUsePos, pSampleUsePos);
fp, } else if (0 == strncasecmp(superTblInfo->dataSource,
sampleDataBuf); "rand", strlen("rand"))) {
if (retLen < 0) {
goto free_and_statistics_2;
}
} else if (0 == strncasecmp(superTblInfo->dataSource, "rand", strlen("rand"))) {
int rand_num = rand_tinyint() % 100; int rand_num = rand_tinyint() % 100;
if (0 != superTblInfo->disorderRatio if (0 != superTblInfo->disorderRatio
&& rand_num < superTblInfo->disorderRatio) { && rand_num < superTblInfo->disorderRatio) {
int64_t d = start_time - rand() % superTblInfo->disorderRange; int64_t d = startTime - rand() % superTblInfo->disorderRange;
retLen = generateRowData( retLen = generateRowData(
pstr + len, pstr + len,
superTblInfo->maxSqlLen - len, superTblInfo->maxSqlLen - len,
d, d,
superTblInfo); superTblInfo);
//printf("disorder rows, rand_num:%d, last ts:%"PRId64" current ts:%"PRId64"\n", rand_num, tmp_time, d); //printf("disorder rows, rand_num:%d, last ts:%"PRId64" current ts:%"PRId64"\n", rand_num, start_time, d);
} else { } else {
retLen = generateRowData( retLen = generateRowData(
pstr + len, pstr + len,
superTblInfo->maxSqlLen - len, superTblInfo->maxSqlLen - len,
start_time + superTblInfo->timeStampStep * i, startTime + superTblInfo->timeStampStep * startFrom,
superTblInfo); superTblInfo);
} }
if (retLen < 0) { if (retLen < 0) {
goto free_and_statistics_2; free(pChildTblName);
} return -1;
} }
len += retLen; len += retLen;
verbosePrint("%s() LN%d retLen=%d len=%d k=%d \nbuffer=%s\n", __func__, __LINE__, retLen, len, k, buffer); }
} else {
int rand_num = rand() % 100;
char data[MAX_DATA_SIZE];
char **data_type = g_args.datatype;
int lenOfBinary = g_args.len_of_binary;
if ((g_args.disorderRatio != 0)
&& (rand_num < g_args.disorderRange)) {
int64_t d = startTime - rand() % 1000000 + rand_num;
len = generateData(data, data_type,
ncols_per_record, d, lenOfBinary);
} else {
len = generateData(data, data_type,
ncols_per_record,
startTime + DEFAULT_TIMESTAMP_STEP * startFrom,
lenOfBinary);
}
//assert(len + pstr - buffer < BUFFER_SIZE);
if (len + pstr - buffer >= g_args.max_sql_len) { // too long
break;
}
pstr += sprintf(pstr, " %s", data);
}
verbosePrint("%s() LN%d len=%d k=%d \nbuffer=%s\n", __func__, __LINE__, len, k, buffer);
tblInserted++;
k++; k++;
i++; startFrom ++;
if (tblInserted >= superTblInfo->insertRows) if (startFrom >= insertRows)
break; break;
} }
winfo->totalRowsInserted += k; return k;
}
// sync insertion
/*
1 thread: 100 tables * 2000 rows/s
1 thread: 10 tables * 20000 rows/s
6 thread: 300 tables * 2000 rows/s
2 taosinsertdata , 1 thread: 10 tables * 20000 rows/s
*/
static void* syncWrite(void *sarg) {
threadInfo *winfo = (threadInfo *)sarg;
SSuperTable* superTblInfo = winfo->superTblInfo;
if (superTblInfo) {
if (0 != prepareSampleDataForSTable(superTblInfo))
return NULL;
if (superTblInfo->numberOfTblInOneSql > 0) {
syncWriteForNumberOfTblInOneSql(winfo, superTblInfo->sampleDataBuf);
tmfree(superTblInfo->sampleDataBuf);
return NULL;
}
}
int samplePos = 0;
char* buffer = calloc(superTblInfo?superTblInfo->maxSqlLen:g_args.max_sql_len, 1);
if (NULL == buffer) {
fprintf(stderr, "Failed to alloc %d Bytes, reason:%s\n",
superTblInfo->maxSqlLen,
strerror(errno));
tmfree(superTblInfo->sampleDataBuf);
return NULL;
}
int64_t lastPrintTime = taosGetTimestampMs();
int64_t startTs = taosGetTimestampUs(); int64_t startTs = taosGetTimestampUs();
int64_t endTs; int64_t endTs;
int affectedRows;
if (0 == strncasecmp(superTblInfo->insertMode, "taosc", strlen("taosc"))) {
verbosePrint("%s() LN%d %s\n", __func__, __LINE__, buffer);
affectedRows = queryDbExec(winfo->taos, buffer, INSERT_TYPE);
if (0 > affectedRows){ int insert_interval = superTblInfo?superTblInfo->insertInterval:
goto free_and_statistics_2; g_args.insert_interval;
uint64_t st = 0;
uint64_t et = 0xffffffff;
winfo->totalInsertRows = 0;
winfo->totalAffectedRows = 0;
int sampleUsePos;
for (uint32_t tableSeq = winfo->start_table_id; tableSeq <= winfo->end_table_id;
tableSeq ++) {
int64_t start_time = winfo->start_time;
int64_t insertRows = (superTblInfo)?superTblInfo->insertRows:g_args.num_of_DPT;
verbosePrint("%s() LN%d insertRows=%"PRId64"\n", __func__, __LINE__, insertRows);
for (int64_t i = 0; i < insertRows;) {
if (insert_interval) {
st = taosGetTimestampUs();
} }
} else {
verbosePrint("%s() LN%d %s\n", __func__, __LINE__, buffer);
int retCode = postProceSql(g_Dbs.host, g_Dbs.port, buffer);
if (0 != retCode) { sampleUsePos = samplePos;
printf("========restful return fail, threadID[%d]\n", winfo->threadID);
int generated = generateDataBuffer(tableSeq, winfo, buffer, insertRows,
i, start_time, &sampleUsePos);
if (generated > 0)
i += generated;
else
goto free_and_statistics_2; goto free_and_statistics_2;
}
affectedRows = k; int affectedRows = execInsert(winfo, buffer, generated);
} if (affectedRows < 0)
goto free_and_statistics_2;
winfo->totalInsertRows += generated;
winfo->totalAffectedRows += affectedRows;
endTs = taosGetTimestampUs(); endTs = taosGetTimestampUs();
int64_t delay = endTs - startTs; int64_t delay = endTs - startTs;
...@@ -4505,53 +4609,57 @@ static void* syncWriteWithStb(void *sarg) { ...@@ -4505,53 +4609,57 @@ static void* syncWriteWithStb(void *sarg) {
winfo->cntDelay++; winfo->cntDelay++;
winfo->totalDelay += delay; winfo->totalDelay += delay;
winfo->totalAffectedRows += affectedRows;
int64_t currentPrintTime = taosGetTimestampMs(); int64_t currentPrintTime = taosGetTimestampMs();
if (currentPrintTime - lastPrintTime > 30*1000) { if (currentPrintTime - lastPrintTime > 30*1000) {
printf("thread[%d] has currently inserted rows: %"PRId64 ", affected rows: %"PRId64 "\n", printf("thread[%d] has currently inserted rows: %"PRId64 ", affected rows: %"PRId64 "\n",
winfo->threadID, winfo->threadID,
winfo->totalRowsInserted, winfo->totalInsertRows,
winfo->totalAffectedRows); winfo->totalAffectedRows);
lastPrintTime = currentPrintTime; lastPrintTime = currentPrintTime;
} }
if (superTblInfo->insertInterval) { if (i >= insertRows)
et = taosGetTimestampMs();
}
if (tblInserted >= superTblInfo->insertRows)
break; break;
} // num_of_DPT
if (tID == winfo->end_table_id) { if (insert_interval) {
if (0 == strncasecmp( et = taosGetTimestampUs();
superTblInfo->dataSource, "sample", strlen("sample"))) {
samplePos = sampleUsePos; if (insert_interval > ((et - st)/1000) ) {
int sleep_time = insert_interval - (et -st)/1000;
verbosePrint("%s() LN%d sleep: %d ms for insert interval\n", __func__, __LINE__, sleep_time);
taosMsleep(sleep_time); // ms
}
} }
} // num_of_DPT
if ((tableSeq == winfo->end_table_id) && superTblInfo &&
(0 == strncasecmp(
superTblInfo->dataSource, "sample", strlen("sample")))) {
samplePos = sampleUsePos;
} }
} // tID } // tableSeq
free_and_statistics_2: free_and_statistics_2:
tmfree(buffer); tmfree(buffer);
tmfree(sampleDataBuf); if (superTblInfo)
tmfclose(fp); tmfree(superTblInfo->sampleDataBuf);
printf("====thread[%d] completed total inserted rows: %"PRId64 ", total affected rows: %"PRId64 "====\n", printf("====thread[%d] completed total inserted rows: %"PRId64 ", total affected rows: %"PRId64 "====\n",
winfo->threadID, winfo->threadID,
winfo->totalRowsInserted, winfo->totalInsertRows,
winfo->totalAffectedRows); winfo->totalAffectedRows);
return NULL; return NULL;
} }
void callBack(void *param, TAOS_RES *res, int code) { void callBack(void *param, TAOS_RES *res, int code) {
threadInfo* winfo = (threadInfo*)param; threadInfo* winfo = (threadInfo*)param;
SSuperTable* superTblInfo = winfo->superTblInfo;
if (g_args.insert_interval) { int insert_interval = superTblInfo?superTblInfo->insertInterval:g_args.insert_interval;
winfo->et = taosGetTimestampMs(); if (insert_interval) {
if (winfo->et - winfo->st < 1000) { winfo->et = taosGetTimestampUs();
taosMsleep(1000 - (winfo->et - winfo->st)); // ms if (((winfo->et - winfo->st)/1000) < insert_interval) {
taosMsleep(insert_interval - (winfo->et - winfo->st)/1000); // ms
} }
} }
...@@ -4580,7 +4688,7 @@ void callBack(void *param, TAOS_RES *res, int code) { ...@@ -4580,7 +4688,7 @@ void callBack(void *param, TAOS_RES *res, int code) {
//generateData(data, datatype, ncols_per_record, d, len_of_binary); //generateData(data, datatype, ncols_per_record, d, len_of_binary);
(void)generateRowData(data, MAX_DATA_SIZE, d, winfo->superTblInfo); (void)generateRowData(data, MAX_DATA_SIZE, d, winfo->superTblInfo);
} else { } else {
//generateData(data, datatype, ncols_per_record, tmp_time += 1000, len_of_binary); //generateData(data, datatype, ncols_per_record, start_time += 1000, len_of_binary);
(void)generateRowData(data, MAX_DATA_SIZE, winfo->lastTs += 1000, winfo->superTblInfo); (void)generateRowData(data, MAX_DATA_SIZE, winfo->lastTs += 1000, winfo->superTblInfo);
} }
pstr += sprintf(pstr, "%s", data); pstr += sprintf(pstr, "%s", data);
...@@ -4591,8 +4699,8 @@ void callBack(void *param, TAOS_RES *res, int code) { ...@@ -4591,8 +4699,8 @@ void callBack(void *param, TAOS_RES *res, int code) {
} }
} }
if (g_args.insert_interval) { if (insert_interval) {
winfo->st = taosGetTimestampMs(); winfo->st = taosGetTimestampUs();
} }
taos_query_a(winfo->taos, buffer, callBack, winfo); taos_query_a(winfo->taos, buffer, callBack, winfo);
free(buffer); free(buffer);
...@@ -4603,13 +4711,15 @@ void callBack(void *param, TAOS_RES *res, int code) { ...@@ -4603,13 +4711,15 @@ void callBack(void *param, TAOS_RES *res, int code) {
void *asyncWrite(void *sarg) { void *asyncWrite(void *sarg) {
threadInfo *winfo = (threadInfo *)sarg; threadInfo *winfo = (threadInfo *)sarg;
SSuperTable* superTblInfo = winfo->superTblInfo;
winfo->st = 0; winfo->st = 0;
winfo->et = 0; winfo->et = 0;
winfo->lastTs = winfo->start_time; winfo->lastTs = winfo->start_time;
if (g_args.insert_interval) { int insert_interval = superTblInfo?superTblInfo->insertInterval:g_args.insert_interval;
winfo->st = taosGetTimestampMs(); if (insert_interval) {
winfo->st = taosGetTimestampUs();
} }
taos_query_a(winfo->taos, "show databases", callBack, winfo); taos_query_a(winfo->taos, "show databases", callBack, winfo);
...@@ -4618,16 +4728,23 @@ void *asyncWrite(void *sarg) { ...@@ -4618,16 +4728,23 @@ void *asyncWrite(void *sarg) {
return NULL; return NULL;
} }
void startMultiThreadInsertData(int threads, char* db_name, char* precision, static void startMultiThreadInsertData(int threads, char* db_name,
SSuperTable* superTblInfo) { char* precision,SSuperTable* superTblInfo) {
pthread_t *pids = malloc(threads * sizeof(pthread_t)); pthread_t *pids = malloc(threads * sizeof(pthread_t));
assert(pids != NULL);
threadInfo *infos = malloc(threads * sizeof(threadInfo)); threadInfo *infos = malloc(threads * sizeof(threadInfo));
assert(infos != NULL);
memset(pids, 0, threads * sizeof(pthread_t)); memset(pids, 0, threads * sizeof(pthread_t));
memset(infos, 0, threads * sizeof(threadInfo)); memset(infos, 0, threads * sizeof(threadInfo));
int ntables = 0; int ntables = 0;
if (superTblInfo) if (superTblInfo)
if (superTblInfo->childTblOffset)
ntables = superTblInfo->childTblLimit;
else
ntables = superTblInfo->childTblCount; ntables = superTblInfo->childTblCount;
else else
ntables = g_args.num_of_tables; ntables = g_args.num_of_tables;
...@@ -4659,7 +4776,7 @@ void startMultiThreadInsertData(int threads, char* db_name, char* precision, ...@@ -4659,7 +4776,7 @@ void startMultiThreadInsertData(int threads, char* db_name, char* precision,
} else if (0 == strncasecmp(precision, "us", 2)) { } else if (0 == strncasecmp(precision, "us", 2)) {
timePrec = TSDB_TIME_PRECISION_MICRO; timePrec = TSDB_TIME_PRECISION_MICRO;
} else { } else {
printf("No support precision: %s\n", precision); fprintf(stderr, "No support precision: %s\n", precision);
exit(-1); exit(-1);
} }
} }
...@@ -4684,7 +4801,13 @@ void startMultiThreadInsertData(int threads, char* db_name, char* precision, ...@@ -4684,7 +4801,13 @@ void startMultiThreadInsertData(int threads, char* db_name, char* precision,
double start = getCurrentTime(); double start = getCurrentTime();
int last = 0; int last;
if ((superTblInfo) && (superTblInfo->childTblOffset))
last = superTblInfo->childTblOffset;
else
last = 0;
for (int i = 0; i < threads; i++) { for (int i = 0; i < threads; i++) {
threadInfo *t_info = infos + i; threadInfo *t_info = infos + i;
t_info->threadID = i; t_info->threadID = i;
...@@ -4722,11 +4845,7 @@ void startMultiThreadInsertData(int threads, char* db_name, char* precision, ...@@ -4722,11 +4845,7 @@ void startMultiThreadInsertData(int threads, char* db_name, char* precision,
tsem_init(&(t_info->lock_sem), 0, 0); tsem_init(&(t_info->lock_sem), 0, 0);
if (SYNC == g_Dbs.queryMode) { if (SYNC == g_Dbs.queryMode) {
if (superTblInfo) {
pthread_create(pids + i, NULL, syncWriteWithStb, t_info);
} else {
pthread_create(pids + i, NULL, syncWrite, t_info); pthread_create(pids + i, NULL, syncWrite, t_info);
}
} else { } else {
pthread_create(pids + i, NULL, asyncWrite, t_info); pthread_create(pids + i, NULL, asyncWrite, t_info);
} }
...@@ -4750,7 +4869,7 @@ void startMultiThreadInsertData(int threads, char* db_name, char* precision, ...@@ -4750,7 +4869,7 @@ void startMultiThreadInsertData(int threads, char* db_name, char* precision,
if (superTblInfo) { if (superTblInfo) {
superTblInfo->totalAffectedRows += t_info->totalAffectedRows; superTblInfo->totalAffectedRows += t_info->totalAffectedRows;
superTblInfo->totalRowsInserted += t_info->totalRowsInserted; superTblInfo->totalInsertRows += t_info->totalInsertRows;
} }
totalDelay += t_info->totalDelay; totalDelay += t_info->totalDelay;
...@@ -4768,15 +4887,16 @@ void startMultiThreadInsertData(int threads, char* db_name, char* precision, ...@@ -4768,15 +4887,16 @@ void startMultiThreadInsertData(int threads, char* db_name, char* precision,
if (superTblInfo) { if (superTblInfo) {
printf("Spent %.4f seconds to insert rows: %"PRId64", affected rows: %"PRId64" with %d thread(s) into %s.%s. %2.f records/second\n\n", printf("Spent %.4f seconds to insert rows: %"PRId64", affected rows: %"PRId64" with %d thread(s) into %s.%s. %2.f records/second\n\n",
t, superTblInfo->totalRowsInserted, t, superTblInfo->totalInsertRows,
superTblInfo->totalAffectedRows, superTblInfo->totalAffectedRows,
threads, db_name, superTblInfo->sTblName, threads, db_name, superTblInfo->sTblName,
superTblInfo->totalRowsInserted / t); superTblInfo->totalInsertRows / t);
fprintf(g_fpOfInsertResult, "Spent %.4f seconds to insert rows: %"PRId64", affected rows: %"PRId64" with %d thread(s) into %s.%s. %2.f records/second\n\n", fprintf(g_fpOfInsertResult,
t, superTblInfo->totalRowsInserted, "Spent %.4f seconds to insert rows: %"PRId64", affected rows: %"PRId64" with %d thread(s) into %s.%s. %2.f records/second\n\n",
t, superTblInfo->totalInsertRows,
superTblInfo->totalAffectedRows, superTblInfo->totalAffectedRows,
threads, db_name, superTblInfo->sTblName, threads, db_name, superTblInfo->sTblName,
superTblInfo->totalRowsInserted / t); superTblInfo->totalInsertRows/ t);
} }
printf("insert delay, avg: %10.6fms, max: %10.6fms, min: %10.6fms\n\n", printf("insert delay, avg: %10.6fms, max: %10.6fms, min: %10.6fms\n\n",
...@@ -4790,7 +4910,6 @@ void startMultiThreadInsertData(int threads, char* db_name, char* precision, ...@@ -4790,7 +4910,6 @@ void startMultiThreadInsertData(int threads, char* db_name, char* precision,
free(infos); free(infos);
} }
void *readTable(void *sarg) { void *readTable(void *sarg) {
#if 1 #if 1
threadInfo *rinfo = (threadInfo *)sarg; threadInfo *rinfo = (threadInfo *)sarg;
...@@ -4935,7 +5054,7 @@ void *readMetric(void *sarg) { ...@@ -4935,7 +5054,7 @@ void *readMetric(void *sarg) {
} }
int insertTestProcess() { static int insertTestProcess() {
setupForAnsiEscape(); setupForAnsiEscape();
int ret = printfInsertMeta(); int ret = printfInsertMeta();
...@@ -4949,10 +5068,10 @@ int insertTestProcess() { ...@@ -4949,10 +5068,10 @@ int insertTestProcess() {
if (NULL == g_fpOfInsertResult) { if (NULL == g_fpOfInsertResult) {
fprintf(stderr, "Failed to open %s for save result\n", g_Dbs.resultFile); fprintf(stderr, "Failed to open %s for save result\n", g_Dbs.resultFile);
return -1; return -1;
} {
printfInsertMetaToFile(g_fpOfInsertResult);
} }
printfInsertMetaToFile(g_fpOfInsertResult);
if (!g_args.answer_yes) { if (!g_args.answer_yes) {
printf("Press enter key to continue\n\n"); printf("Press enter key to continue\n\n");
(void)getchar(); (void)getchar();
...@@ -4967,7 +5086,7 @@ int insertTestProcess() { ...@@ -4967,7 +5086,7 @@ int insertTestProcess() {
} }
// pretreatement // pretreatement
prePareSampleData(); prepareSampleData();
double start; double start;
double end; double end;
...@@ -5011,14 +5130,14 @@ int insertTestProcess() { ...@@ -5011,14 +5130,14 @@ int insertTestProcess() {
} }
//end = getCurrentTime(); //end = getCurrentTime();
//int64_t totalRowsInserted = 0; //int64_t totalInsertRows = 0;
//int64_t totalAffectedRows = 0; //int64_t totalAffectedRows = 0;
//for (int i = 0; i < g_Dbs.dbCount; i++) { //for (int i = 0; i < g_Dbs.dbCount; i++) {
// for (int j = 0; j < g_Dbs.db[i].superTblCount; j++) { // for (int j = 0; j < g_Dbs.db[i].superTblCount; j++) {
// totalRowsInserted += g_Dbs.db[i].superTbls[j].totalRowsInserted; // totalInsertRows+= g_Dbs.db[i].superTbls[j].totalInsertRows;
// totalAffectedRows += g_Dbs.db[i].superTbls[j].totalAffectedRows; // totalAffectedRows += g_Dbs.db[i].superTbls[j].totalAffectedRows;
//} //}
//printf("Spent %.4f seconds to insert rows: %"PRId64", affected rows: %"PRId64" with %d thread(s)\n\n", end - start, totalRowsInserted, totalAffectedRows, g_Dbs.threadCount); //printf("Spent %.4f seconds to insert rows: %"PRId64", affected rows: %"PRId64" with %d thread(s)\n\n", end - start, totalInsertRows, totalAffectedRows, g_Dbs.threadCount);
postFreeResource(); postFreeResource();
return 0; return 0;
...@@ -5039,7 +5158,7 @@ void *superQueryProcess(void *sarg) { ...@@ -5039,7 +5158,7 @@ void *superQueryProcess(void *sarg) {
//printf("========sleep duration:%"PRId64 "========inserted rows:%d, table range:%d - %d\n", (1000 - (et - st)), i, winfo->start_table_id, winfo->end_table_id); //printf("========sleep duration:%"PRId64 "========inserted rows:%d, table range:%d - %d\n", (1000 - (et - st)), i, winfo->start_table_id, winfo->end_table_id);
} }
st = taosGetTimestampMs(); st = taosGetTimestampUs();
for (int i = 0; i < g_queryInfo.superQueryInfo.sqlCount; i++) { for (int i = 0; i < g_queryInfo.superQueryInfo.sqlCount; i++) {
if (0 == strncasecmp(g_queryInfo.queryMode, "taosc", 5)) { if (0 == strncasecmp(g_queryInfo.queryMode, "taosc", 5)) {
int64_t t1 = taosGetTimestampUs(); int64_t t1 = taosGetTimestampUs();
...@@ -5065,14 +5184,14 @@ void *superQueryProcess(void *sarg) { ...@@ -5065,14 +5184,14 @@ void *superQueryProcess(void *sarg) {
} }
} }
} }
et = taosGetTimestampMs(); et = taosGetTimestampUs();
printf("==thread[%"PRId64"] complete all sqls to specify tables once queries duration:%.6fs\n\n", printf("==thread[%"PRId64"] complete all sqls to specify tables once queries duration:%.6fs\n\n",
taosGetSelfPthreadId(), (double)(et - st)/1000.0); taosGetSelfPthreadId(), (double)(et - st)/1000.0);
} }
return NULL; return NULL;
} }
void replaceSubTblName(char* inSql, char* outSql, int tblIndex) { static void replaceSubTblName(char* inSql, char* outSql, int tblIndex) {
char sourceString[32] = "xxxx"; char sourceString[32] = "xxxx";
char subTblName[MAX_TB_NAME_SIZE*3]; char subTblName[MAX_TB_NAME_SIZE*3];
sprintf(subTblName, "%s.%s", sprintf(subTblName, "%s.%s",
...@@ -5094,7 +5213,7 @@ void replaceSubTblName(char* inSql, char* outSql, int tblIndex) { ...@@ -5094,7 +5213,7 @@ void replaceSubTblName(char* inSql, char* outSql, int tblIndex) {
//printf("3: %s\n", outSql); //printf("3: %s\n", outSql);
} }
void *subQueryProcess(void *sarg) { static void *subQueryProcess(void *sarg) {
char sqlstr[1024]; char sqlstr[1024];
threadInfo *winfo = (threadInfo *)sarg; threadInfo *winfo = (threadInfo *)sarg;
int64_t st = 0; int64_t st = 0;
...@@ -5105,7 +5224,7 @@ void *subQueryProcess(void *sarg) { ...@@ -5105,7 +5224,7 @@ void *subQueryProcess(void *sarg) {
//printf("========sleep duration:%"PRId64 "========inserted rows:%d, table range:%d - %d\n", (1000 - (et - st)), i, winfo->start_table_id, winfo->end_table_id); //printf("========sleep duration:%"PRId64 "========inserted rows:%d, table range:%d - %d\n", (1000 - (et - st)), i, winfo->start_table_id, winfo->end_table_id);
} }
st = taosGetTimestampMs(); st = taosGetTimestampUs();
for (int i = winfo->start_table_id; i <= winfo->end_table_id; i++) { for (int i = winfo->start_table_id; i <= winfo->end_table_id; i++) {
for (int j = 0; j < g_queryInfo.subQueryInfo.sqlCount; j++) { for (int j = 0; j < g_queryInfo.subQueryInfo.sqlCount; j++) {
memset(sqlstr,0,sizeof(sqlstr)); memset(sqlstr,0,sizeof(sqlstr));
...@@ -5119,12 +5238,12 @@ void *subQueryProcess(void *sarg) { ...@@ -5119,12 +5238,12 @@ void *subQueryProcess(void *sarg) {
selectAndGetResult(winfo->taos, sqlstr, tmpFile); selectAndGetResult(winfo->taos, sqlstr, tmpFile);
} }
} }
et = taosGetTimestampMs(); et = taosGetTimestampUs();
printf("####thread[%"PRId64"] complete all sqls to allocate all sub-tables[%d - %d] once queries duration:%.4fs\n\n", printf("####thread[%"PRId64"] complete all sqls to allocate all sub-tables[%d - %d] once queries duration:%.4fs\n\n",
taosGetSelfPthreadId(), taosGetSelfPthreadId(),
winfo->start_table_id, winfo->start_table_id,
winfo->end_table_id, winfo->end_table_id,
(double)(et - st)/1000.0); (double)(et - st)/1000000.0);
} }
return NULL; return NULL;
} }
...@@ -5142,7 +5261,7 @@ static int queryTestProcess() { ...@@ -5142,7 +5261,7 @@ static int queryTestProcess() {
} }
if (0 != g_queryInfo.subQueryInfo.sqlCount) { if (0 != g_queryInfo.subQueryInfo.sqlCount) {
(void)getAllChildNameOfSuperTable(taos, getAllChildNameOfSuperTable(taos,
g_queryInfo.dbName, g_queryInfo.dbName,
g_queryInfo.subQueryInfo.sTblName, g_queryInfo.subQueryInfo.sTblName,
&g_queryInfo.subQueryInfo.childTblName, &g_queryInfo.subQueryInfo.childTblName,
...@@ -5195,7 +5314,8 @@ static int queryTestProcess() { ...@@ -5195,7 +5314,8 @@ static int queryTestProcess() {
pthread_t *pidsOfSub = NULL; pthread_t *pidsOfSub = NULL;
threadInfo *infosOfSub = NULL; threadInfo *infosOfSub = NULL;
//==== create sub threads for query from all sub table of the super table //==== create sub threads for query from all sub table of the super table
if ((g_queryInfo.subQueryInfo.sqlCount > 0) && (g_queryInfo.subQueryInfo.threadCnt > 0)) { if ((g_queryInfo.subQueryInfo.sqlCount > 0)
&& (g_queryInfo.subQueryInfo.threadCnt > 0)) {
pidsOfSub = malloc(g_queryInfo.subQueryInfo.threadCnt * sizeof(pthread_t)); pidsOfSub = malloc(g_queryInfo.subQueryInfo.threadCnt * sizeof(pthread_t));
infosOfSub = malloc(g_queryInfo.subQueryInfo.threadCnt * sizeof(threadInfo)); infosOfSub = malloc(g_queryInfo.subQueryInfo.threadCnt * sizeof(threadInfo));
if ((NULL == pidsOfSub) || (NULL == infosOfSub)) { if ((NULL == pidsOfSub) || (NULL == infosOfSub)) {
...@@ -5439,14 +5559,13 @@ static int subscribeTestProcess() { ...@@ -5439,14 +5559,13 @@ static int subscribeTestProcess() {
} }
if (0 != g_queryInfo.subQueryInfo.sqlCount) { if (0 != g_queryInfo.subQueryInfo.sqlCount) {
(void)getAllChildNameOfSuperTable(taos, getAllChildNameOfSuperTable(taos,
g_queryInfo.dbName, g_queryInfo.dbName,
g_queryInfo.subQueryInfo.sTblName, g_queryInfo.subQueryInfo.sTblName,
&g_queryInfo.subQueryInfo.childTblName, &g_queryInfo.subQueryInfo.childTblName,
&g_queryInfo.subQueryInfo.childTblCount); &g_queryInfo.subQueryInfo.childTblCount);
} }
pthread_t *pids = NULL; pthread_t *pids = NULL;
threadInfo *infos = NULL; threadInfo *infos = NULL;
//==== create sub threads for query from super table //==== create sub threads for query from super table
...@@ -5615,7 +5734,7 @@ void setParaFromArg(){ ...@@ -5615,7 +5734,7 @@ void setParaFromArg(){
tstrncpy(g_Dbs.db[0].superTbls[0].insertMode, "taosc", MAX_TB_NAME_SIZE); tstrncpy(g_Dbs.db[0].superTbls[0].insertMode, "taosc", MAX_TB_NAME_SIZE);
tstrncpy(g_Dbs.db[0].superTbls[0].startTimestamp, tstrncpy(g_Dbs.db[0].superTbls[0].startTimestamp,
"2017-07-14 10:40:00.000", MAX_TB_NAME_SIZE); "2017-07-14 10:40:00.000", MAX_TB_NAME_SIZE);
g_Dbs.db[0].superTbls[0].timeStampStep = 10; g_Dbs.db[0].superTbls[0].timeStampStep = DEFAULT_TIMESTAMP_STEP;
g_Dbs.db[0].superTbls[0].insertRows = g_args.num_of_DPT; g_Dbs.db[0].superTbls[0].insertRows = g_args.num_of_DPT;
g_Dbs.db[0].superTbls[0].maxSqlLen = TSDB_PAYLOAD_SIZE; g_Dbs.db[0].superTbls[0].maxSqlLen = TSDB_PAYLOAD_SIZE;
...@@ -5761,14 +5880,7 @@ static void testMetaFile() { ...@@ -5761,14 +5880,7 @@ static void testMetaFile() {
} }
} }
static void testCmdLine() { static void queryResult() {
g_args.test_mode = INSERT_MODE;
insertTestProcess();
if (g_Dbs.insert_only)
return;
// select // select
if (false == g_Dbs.insert_only) { if (false == g_Dbs.insert_only) {
// query data // query data
...@@ -5814,6 +5926,17 @@ static void testCmdLine() { ...@@ -5814,6 +5926,17 @@ static void testCmdLine() {
} }
} }
static void testCmdLine() {
g_args.test_mode = INSERT_MODE;
insertTestProcess();
if (g_Dbs.insert_only)
return;
else
queryResult();
}
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
parse_args(argc, argv, &g_args); parse_args(argc, argv, &g_args);
......
###################################################################
# Copyright (c) 2016 by TAOS Technologies, Inc.
# All rights reserved.
#
# This file is proprietary and confidential to TAOS Technologies.
# No part of this file may be reproduced, stored, transmitted,
# disclosed or used in any form or by any means other than as
# expressly provided by the written permission from Jianhui Tao
#
###################################################################
# -*- coding: utf-8 -*-
import sys
import os
from util.log import *
from util.cases import *
from util.sql import *
from util.dnodes import *
class TDTestCase:
def init(self, conn, logSql):
tdLog.debug("start to execute %s" % __file__)
tdSql.init(conn.cursor(), logSql)
self.numberOfTables = 100
self.numberOfRecords = 1000
def getBuildPath(self):
selfPath = os.path.dirname(os.path.realpath(__file__))
if ("community" in selfPath):
projPath = selfPath[:selfPath.find("community")]
else:
projPath = selfPath[:selfPath.find("tests")]
for root, dirs, files in os.walk(projPath):
if ("taosd" in files):
rootRealPath = os.path.dirname(os.path.realpath(root))
if ("packaging" not in rootRealPath):
buildPath = root[:len(root) - len("/build/bin")]
break
return buildPath
def run(self):
buildPath = self.getBuildPath()
if (buildPath == ""):
tdLog.exit("taosd not found!")
else:
tdLog.info("taosd found in %s" % buildPath)
binPath = buildPath + "/build/bin/"
os.system("%staosdemo -y -t %d -n %d -x" %
(binPath, self.numberOfTables, self.numberOfRecords))
tdSql.query("show databases")
for i in range(18):
print(tdSql.getData(0, i) )
tdSql.checkData(0, 2, self.numberOfTables)
tdSql.execute("use test")
tdSql.query(
"select count(*) from test.t%d" % (self.numberOfTables -1))
tdSql.checkData(0, 0, self.numberOfRecords)
def stop(self):
tdSql.close()
tdLog.success("%s successfully executed" % __file__)
tdCases.addWindows(__file__, TDTestCase())
tdCases.addLinux(__file__, TDTestCase())
...@@ -316,6 +316,7 @@ if [ "$2" != "sim" ] && [ "$2" != "python" ] && [ "$2" != "unit" ] && [ "$1" == ...@@ -316,6 +316,7 @@ if [ "$2" != "sim" ] && [ "$2" != "python" ] && [ "$2" != "unit" ] && [ "$1" ==
cd debug/ cd debug/
stopTaosd stopTaosd
rm -rf /var/lib/taos/*
nohup build/bin/taosd -c /etc/taos/ > /dev/null 2>&1 & nohup build/bin/taosd -c /etc/taos/ > /dev/null 2>&1 &
sleep 30 sleep 30
...@@ -358,6 +359,7 @@ if [ "$2" != "sim" ] && [ "$2" != "python" ] && [ "$2" != "jdbc" ] && [ "$1" == ...@@ -358,6 +359,7 @@ if [ "$2" != "sim" ] && [ "$2" != "python" ] && [ "$2" != "jdbc" ] && [ "$1" ==
pwd pwd
cd debug/build/bin cd debug/build/bin
rm -rf /var/lib/taos/*
nohup ./taosd -c /etc/taos/ > /dev/null 2>&1 & nohup ./taosd -c /etc/taos/ > /dev/null 2>&1 &
sleep 30 sleep 30
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册