提交 f29b0c84 编写于 作者: sangshuduo's avatar sangshuduo

fix windows stack overflow issue.

上级 84e1e61d
...@@ -2318,15 +2318,15 @@ static void printfDbInfoForQueryToFile( ...@@ -2318,15 +2318,15 @@ static void printfDbInfoForQueryToFile(
} }
static void printfQuerySystemInfo(TAOS * taos) { static void printfQuerySystemInfo(TAOS * taos) {
char filename[BUFFER_SIZE+1] = {0}; char filename[MAX_FILE_NAME_LEN] = {0};
char buffer[BUFFER_SIZE+1] = {0}; char buffer[1024] = {0};
TAOS_RES* res; TAOS_RES* res;
time_t t; time_t t;
struct tm* lt; struct tm* lt;
time(&t); time(&t);
lt = localtime(&t); lt = localtime(&t);
snprintf(filename, BUFFER_SIZE, "querySystemInfo-%d-%d-%d %d:%d:%d", snprintf(filename, MAX_FILE_NAME_LEN, "querySystemInfo-%d-%d-%d %d:%d:%d",
lt->tm_year+1900, lt->tm_mon, lt->tm_mday, lt->tm_hour, lt->tm_min, lt->tm_year+1900, lt->tm_mon, lt->tm_mday, lt->tm_hour, lt->tm_min,
lt->tm_sec); lt->tm_sec);
...@@ -2358,12 +2358,12 @@ static void printfQuerySystemInfo(TAOS * taos) { ...@@ -2358,12 +2358,12 @@ static void printfQuerySystemInfo(TAOS * taos) {
printfDbInfoForQueryToFile(filename, dbInfos[i], i); printfDbInfoForQueryToFile(filename, dbInfos[i], i);
// show db.vgroups // show db.vgroups
snprintf(buffer, BUFFER_SIZE, "show %s.vgroups;", dbInfos[i]->name); snprintf(buffer, 1024, "show %s.vgroups;", dbInfos[i]->name);
res = taos_query(taos, buffer); res = taos_query(taos, buffer);
xDumpResultToFile(filename, res); xDumpResultToFile(filename, res);
// show db.stables // show db.stables
snprintf(buffer, BUFFER_SIZE, "show %s.stables;", dbInfos[i]->name); snprintf(buffer, 1024, "show %s.stables;", dbInfos[i]->name);
res = taos_query(taos, buffer); res = taos_query(taos, buffer);
xDumpResultToFile(filename, res); xDumpResultToFile(filename, res);
free(dbInfos[i]); free(dbInfos[i]);
...@@ -2712,7 +2712,7 @@ static int getChildNameOfSuperTableWithLimitAndOffset(TAOS * taos, ...@@ -2712,7 +2712,7 @@ static int getChildNameOfSuperTableWithLimitAndOffset(TAOS * taos,
char* dbName, char* sTblName, char** childTblNameOfSuperTbl, char* dbName, char* sTblName, char** childTblNameOfSuperTbl,
int64_t* childTblCountOfSuperTbl, int64_t limit, uint64_t offset) { int64_t* childTblCountOfSuperTbl, int64_t limit, uint64_t offset) {
char command[BUFFER_SIZE] = "\0"; char command[1024] = "\0";
char limitBuf[100] = "\0"; char limitBuf[100] = "\0";
TAOS_RES * res; TAOS_RES * res;
...@@ -2726,7 +2726,7 @@ static int getChildNameOfSuperTableWithLimitAndOffset(TAOS * taos, ...@@ -2726,7 +2726,7 @@ static int getChildNameOfSuperTableWithLimitAndOffset(TAOS * taos,
} }
//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 %s", snprintf(command, 1024, "select tbname from %s.%s %s",
dbName, sTblName, limitBuf); dbName, sTblName, limitBuf);
res = taos_query(taos, command); res = taos_query(taos, command);
...@@ -2804,13 +2804,13 @@ static int getAllChildNameOfSuperTable(TAOS * taos, char* dbName, ...@@ -2804,13 +2804,13 @@ static int getAllChildNameOfSuperTable(TAOS * taos, char* dbName,
static int getSuperTableFromServer(TAOS * taos, char* dbName, static int getSuperTableFromServer(TAOS * taos, char* dbName,
SSuperTable* superTbls) { SSuperTable* superTbls) {
char command[BUFFER_SIZE] = "\0"; char command[1024] = "\0";
TAOS_RES * res; TAOS_RES * res;
TAOS_ROW row = NULL; TAOS_ROW row = NULL;
int count = 0; int count = 0;
//get schema use cmd: describe superTblName; //get schema use cmd: describe superTblName;
snprintf(command, BUFFER_SIZE, "describe %s.%s", dbName, superTbls->sTblName); snprintf(command, 1024, "describe %s.%s", dbName, superTbls->sTblName);
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) {
...@@ -2890,7 +2890,7 @@ static int createSuperTable( ...@@ -2890,7 +2890,7 @@ static int createSuperTable(
TAOS * taos, char* dbName, TAOS * taos, char* dbName,
SSuperTable* superTbl) { SSuperTable* superTbl) {
char command[BUFFER_SIZE] = "\0"; char command[1024] = "\0";
char cols[COL_BUFFER_LEN] = "\0"; char cols[COL_BUFFER_LEN] = "\0";
int colIndex; int colIndex;
...@@ -3059,7 +3059,7 @@ static int createSuperTable( ...@@ -3059,7 +3059,7 @@ static int createSuperTable(
superTbl->lenOfTagOfOneRow = lenOfTagOfOneRow; superTbl->lenOfTagOfOneRow = lenOfTagOfOneRow;
snprintf(command, BUFFER_SIZE, snprintf(command, 1024,
"create table if not exists %s.%s (ts timestamp%s) tags %s", "create table if not exists %s.%s (ts timestamp%s) tags %s",
dbName, superTbl->sTblName, cols, tags); dbName, superTbl->sTblName, cols, tags);
if (0 != queryDbExec(taos, command, NO_INSERT_TYPE, false)) { if (0 != queryDbExec(taos, command, NO_INSERT_TYPE, false)) {
...@@ -3071,7 +3071,7 @@ static int createSuperTable( ...@@ -3071,7 +3071,7 @@ static int createSuperTable(
return 0; return 0;
} }
static int createDatabasesAndStables() { int createDatabasesAndStables(char *command) {
TAOS * taos = NULL; TAOS * taos = NULL;
int ret = 0; int ret = 0;
taos = taos_connect(g_Dbs.host, g_Dbs.user, g_Dbs.password, NULL, g_Dbs.port); taos = taos_connect(g_Dbs.host, g_Dbs.user, g_Dbs.password, NULL, g_Dbs.port);
...@@ -3079,7 +3079,6 @@ static int createDatabasesAndStables() { ...@@ -3079,7 +3079,6 @@ static int createDatabasesAndStables() {
errorPrint( "Failed to connect to TDengine, reason:%s\n", taos_errstr(NULL)); errorPrint( "Failed to connect to TDengine, reason:%s\n", taos_errstr(NULL));
return -1; return -1;
} }
char command[BUFFER_SIZE] = "\0";
for (int i = 0; i < g_Dbs.dbCount; i++) { for (int i = 0; i < g_Dbs.dbCount; i++) {
if (g_Dbs.db[i].drop) { if (g_Dbs.db[i].drop) {
...@@ -7111,7 +7110,8 @@ static void startMultiThreadInsertData(int threads, char* db_name, ...@@ -7111,7 +7110,8 @@ static void startMultiThreadInsertData(int threads, char* db_name,
exit(-1); exit(-1);
} }
char buffer[BUFFER_SIZE]; char *buffer = calloc(1, BUFFER_SIZE);
assert(buffer);
char *pstr = buffer; char *pstr = buffer;
if ((superTblInfo) if ((superTblInfo)
...@@ -7140,8 +7140,11 @@ static void startMultiThreadInsertData(int threads, char* db_name, ...@@ -7140,8 +7140,11 @@ static void startMultiThreadInsertData(int threads, char* db_name,
ret, taos_stmt_errstr(pThreadInfo->stmt)); ret, taos_stmt_errstr(pThreadInfo->stmt));
free(pids); free(pids);
free(infos); free(infos);
free(buffer);
exit(-1); exit(-1);
} }
free(buffer);
} }
#endif #endif
} else { } else {
...@@ -7272,12 +7275,15 @@ static void *readTable(void *sarg) { ...@@ -7272,12 +7275,15 @@ static void *readTable(void *sarg) {
threadInfo *pThreadInfo = (threadInfo *)sarg; threadInfo *pThreadInfo = (threadInfo *)sarg;
TAOS *taos = pThreadInfo->taos; TAOS *taos = pThreadInfo->taos;
setThreadName("readTable"); setThreadName("readTable");
char command[BUFFER_SIZE] = "\0"; char *command = calloc(1, BUFFER_SIZE);
assert(command);
uint64_t sTime = pThreadInfo->start_time; uint64_t sTime = pThreadInfo->start_time;
char *tb_prefix = pThreadInfo->tb_prefix; char *tb_prefix = pThreadInfo->tb_prefix;
FILE *fp = fopen(pThreadInfo->filePath, "a"); FILE *fp = fopen(pThreadInfo->filePath, "a");
if (NULL == fp) { if (NULL == fp) {
errorPrint( "fopen %s fail, reason:%s.\n", pThreadInfo->filePath, strerror(errno)); errorPrint( "fopen %s fail, reason:%s.\n", pThreadInfo->filePath, strerror(errno));
free(command);
return NULL; return NULL;
} }
...@@ -7316,6 +7322,7 @@ static void *readTable(void *sarg) { ...@@ -7316,6 +7322,7 @@ static void *readTable(void *sarg) {
taos_free_result(pSql); taos_free_result(pSql);
taos_close(taos); taos_close(taos);
fclose(fp); fclose(fp);
free(command);
return NULL; return NULL;
} }
...@@ -7336,6 +7343,7 @@ static void *readTable(void *sarg) { ...@@ -7336,6 +7343,7 @@ static void *readTable(void *sarg) {
} }
fprintf(fp, "\n"); fprintf(fp, "\n");
fclose(fp); fclose(fp);
free(command);
#endif #endif
return NULL; return NULL;
} }
...@@ -7345,10 +7353,13 @@ static void *readMetric(void *sarg) { ...@@ -7345,10 +7353,13 @@ static void *readMetric(void *sarg) {
threadInfo *pThreadInfo = (threadInfo *)sarg; threadInfo *pThreadInfo = (threadInfo *)sarg;
TAOS *taos = pThreadInfo->taos; TAOS *taos = pThreadInfo->taos;
setThreadName("readMetric"); setThreadName("readMetric");
char command[BUFFER_SIZE] = "\0"; char *command = calloc(1, BUFFER_SIZE);
assert(command);
FILE *fp = fopen(pThreadInfo->filePath, "a"); FILE *fp = fopen(pThreadInfo->filePath, "a");
if (NULL == fp) { if (NULL == fp) {
printf("fopen %s fail, reason:%s.\n", pThreadInfo->filePath, strerror(errno)); printf("fopen %s fail, reason:%s.\n", pThreadInfo->filePath, strerror(errno));
free(command);
return NULL; return NULL;
} }
...@@ -7393,6 +7404,7 @@ static void *readMetric(void *sarg) { ...@@ -7393,6 +7404,7 @@ static void *readMetric(void *sarg) {
taos_free_result(pSql); taos_free_result(pSql);
taos_close(taos); taos_close(taos);
fclose(fp); fclose(fp);
free(command);
return NULL; return NULL;
} }
int count = 0; int count = 0;
...@@ -7410,6 +7422,7 @@ static void *readMetric(void *sarg) { ...@@ -7410,6 +7422,7 @@ static void *readMetric(void *sarg) {
fprintf(fp, "\n"); fprintf(fp, "\n");
} }
fclose(fp); fclose(fp);
free(command);
#endif #endif
return NULL; return NULL;
} }
...@@ -7446,11 +7459,16 @@ static int insertTestProcess() { ...@@ -7446,11 +7459,16 @@ static int insertTestProcess() {
init_rand_data(); init_rand_data();
// create database and super tables // create database and super tables
if(createDatabasesAndStables() != 0) { char *cmdBuffer = calloc(1, BUFFER_SIZE);
assert(cmdBuffer);
if(createDatabasesAndStables(cmdBuffer) != 0) {
if (g_fpOfInsertResult) if (g_fpOfInsertResult)
fclose(g_fpOfInsertResult); fclose(g_fpOfInsertResult);
free(cmdBuffer);
return -1; return -1;
} }
free(cmdBuffer);
// pretreatement // pretreatement
if (prepareSampleData() != 0) { if (prepareSampleData() != 0) {
...@@ -7619,7 +7637,9 @@ static void replaceChildTblName(char* inSql, char* outSql, int tblIndex) { ...@@ -7619,7 +7637,9 @@ static void replaceChildTblName(char* inSql, char* outSql, int tblIndex) {
} }
static void *superTableQuery(void *sarg) { static void *superTableQuery(void *sarg) {
char sqlstr[BUFFER_SIZE]; char *sqlstr = calloc(1, BUFFER_SIZE);
assert(sqlstr);
threadInfo *pThreadInfo = (threadInfo *)sarg; threadInfo *pThreadInfo = (threadInfo *)sarg;
setThreadName("superTableQuery"); setThreadName("superTableQuery");
...@@ -7634,6 +7654,7 @@ static void *superTableQuery(void *sarg) { ...@@ -7634,6 +7654,7 @@ static void *superTableQuery(void *sarg) {
if (taos == NULL) { if (taos == NULL) {
errorPrint("[%d] Failed to connect to TDengine, reason:%s\n", errorPrint("[%d] Failed to connect to TDengine, reason:%s\n",
pThreadInfo->threadID, taos_errstr(NULL)); pThreadInfo->threadID, taos_errstr(NULL));
free(sqlstr);
return NULL; return NULL;
} else { } else {
pThreadInfo->taos = taos; pThreadInfo->taos = taos;
...@@ -7689,6 +7710,7 @@ static void *superTableQuery(void *sarg) { ...@@ -7689,6 +7710,7 @@ static void *superTableQuery(void *sarg) {
(double)(et - st)/1000.0); (double)(et - st)/1000.0);
} }
free(sqlstr);
return NULL; return NULL;
} }
...@@ -7922,7 +7944,9 @@ static TAOS_SUB* subscribeImpl( ...@@ -7922,7 +7944,9 @@ static TAOS_SUB* subscribeImpl(
static void *superSubscribe(void *sarg) { static void *superSubscribe(void *sarg) {
threadInfo *pThreadInfo = (threadInfo *)sarg; threadInfo *pThreadInfo = (threadInfo *)sarg;
char subSqlstr[BUFFER_SIZE]; char *subSqlStr = calloc(1, BUFFER_SIZE);
assert(subSqlStr);
TAOS_SUB* tsub[MAX_QUERY_SQL_COUNT] = {0}; TAOS_SUB* tsub[MAX_QUERY_SQL_COUNT] = {0};
uint64_t tsubSeq; uint64_t tsubSeq;
...@@ -7931,6 +7955,7 @@ static void *superSubscribe(void *sarg) { ...@@ -7931,6 +7955,7 @@ static void *superSubscribe(void *sarg) {
if (pThreadInfo->ntables > MAX_QUERY_SQL_COUNT) { if (pThreadInfo->ntables > MAX_QUERY_SQL_COUNT) {
errorPrint("The table number(%"PRId64") of the thread is more than max query sql count: %d\n", errorPrint("The table number(%"PRId64") of the thread is more than max query sql count: %d\n",
pThreadInfo->ntables, MAX_QUERY_SQL_COUNT); pThreadInfo->ntables, MAX_QUERY_SQL_COUNT);
free(subSqlStr);
exit(-1); exit(-1);
} }
...@@ -7943,6 +7968,7 @@ static void *superSubscribe(void *sarg) { ...@@ -7943,6 +7968,7 @@ static void *superSubscribe(void *sarg) {
if (pThreadInfo->taos == NULL) { if (pThreadInfo->taos == NULL) {
errorPrint("[%d] Failed to connect to TDengine, reason:%s\n", errorPrint("[%d] Failed to connect to TDengine, reason:%s\n",
pThreadInfo->threadID, taos_errstr(NULL)); pThreadInfo->threadID, taos_errstr(NULL));
free(subSqlStr);
return NULL; return NULL;
} }
} }
...@@ -7953,6 +7979,7 @@ static void *superSubscribe(void *sarg) { ...@@ -7953,6 +7979,7 @@ static void *superSubscribe(void *sarg) {
taos_close(pThreadInfo->taos); taos_close(pThreadInfo->taos);
errorPrint( "use database %s failed!\n\n", errorPrint( "use database %s failed!\n\n",
g_queryInfo.dbName); g_queryInfo.dbName);
free(subSqlStr);
return NULL; return NULL;
} }
...@@ -7967,25 +7994,26 @@ static void *superSubscribe(void *sarg) { ...@@ -7967,25 +7994,26 @@ static void *superSubscribe(void *sarg) {
pThreadInfo->end_table_to, i); pThreadInfo->end_table_to, i);
sprintf(topic, "taosdemo-subscribe-%"PRIu64"-%"PRIu64"", sprintf(topic, "taosdemo-subscribe-%"PRIu64"-%"PRIu64"",
i, pThreadInfo->querySeq); i, pThreadInfo->querySeq);
memset(subSqlstr, 0, sizeof(subSqlstr)); memset(subSqlStr, 0, sizeof(subSqlStr));
replaceChildTblName( replaceChildTblName(
g_queryInfo.superQueryInfo.sql[pThreadInfo->querySeq], g_queryInfo.superQueryInfo.sql[pThreadInfo->querySeq],
subSqlstr, i); subSqlStr, i);
if (g_queryInfo.superQueryInfo.result[pThreadInfo->querySeq][0] != 0) { if (g_queryInfo.superQueryInfo.result[pThreadInfo->querySeq][0] != 0) {
sprintf(pThreadInfo->filePath, "%s-%d", sprintf(pThreadInfo->filePath, "%s-%d",
g_queryInfo.superQueryInfo.result[pThreadInfo->querySeq], g_queryInfo.superQueryInfo.result[pThreadInfo->querySeq],
pThreadInfo->threadID); pThreadInfo->threadID);
} }
verbosePrint("%s() LN%d, [%d] subSqlstr: %s\n", verbosePrint("%s() LN%d, [%d] subSqlStr: %s\n",
__func__, __LINE__, pThreadInfo->threadID, subSqlstr); __func__, __LINE__, pThreadInfo->threadID, subSqlStr);
tsub[tsubSeq] = subscribeImpl( tsub[tsubSeq] = subscribeImpl(
STABLE_CLASS, STABLE_CLASS,
pThreadInfo, subSqlstr, topic, pThreadInfo, subSqlStr, topic,
g_queryInfo.superQueryInfo.subscribeRestart, g_queryInfo.superQueryInfo.subscribeRestart,
g_queryInfo.superQueryInfo.subscribeInterval); g_queryInfo.superQueryInfo.subscribeInterval);
if (NULL == tsub[tsubSeq]) { if (NULL == tsub[tsubSeq]) {
taos_close(pThreadInfo->taos); taos_close(pThreadInfo->taos);
free(subSqlStr);
return NULL; return NULL;
} }
} }
...@@ -8042,12 +8070,13 @@ static void *superSubscribe(void *sarg) { ...@@ -8042,12 +8070,13 @@ static void *superSubscribe(void *sarg) {
consumed[tsubSeq]= 0; consumed[tsubSeq]= 0;
tsub[tsubSeq] = subscribeImpl( tsub[tsubSeq] = subscribeImpl(
STABLE_CLASS, STABLE_CLASS,
pThreadInfo, subSqlstr, topic, pThreadInfo, subSqlStr, topic,
g_queryInfo.superQueryInfo.subscribeRestart, g_queryInfo.superQueryInfo.subscribeRestart,
g_queryInfo.superQueryInfo.subscribeInterval g_queryInfo.superQueryInfo.subscribeInterval
); );
if (NULL == tsub[tsubSeq]) { if (NULL == tsub[tsubSeq]) {
taos_close(pThreadInfo->taos); taos_close(pThreadInfo->taos);
free(subSqlStr);
return NULL; return NULL;
} }
} }
...@@ -8067,6 +8096,7 @@ static void *superSubscribe(void *sarg) { ...@@ -8067,6 +8096,7 @@ static void *superSubscribe(void *sarg) {
} }
taos_close(pThreadInfo->taos); taos_close(pThreadInfo->taos);
free(subSqlStr);
return NULL; return NULL;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册