提交 3ec26763 编写于 作者: H Hui Li

[TD-2658]<fix> memory overflow

上级 cbfd466d
...@@ -6,12 +6,12 @@ ...@@ -6,12 +6,12 @@
"user": "root", "user": "root",
"password": "taosdata", "password": "taosdata",
"databases": "db01", "databases": "db01",
"super_table_query": "specified_table_query":
{"rate":1, "concurrent":1, {"query_interval":1, "concurrent":1,
"sqls": [{"sql": "select count(*) from stb01", "result": "./query_res0.txt"}] "sqls": [{"sql": "select count(*) from stb01", "result": "./query_res0.txt"}]
}, },
"sub_table_query": "super_table_query":
{"stblname": "stb01", "rate":1, "threads":1, {"stblname": "stb01", "query_interval":1, "threads":1,
"sqls": [{"sql": "select count(*) from xxxx", "result": "./query_res1.txt"}] "sqls": [{"sql": "select count(*) from xxxx", "result": "./query_res1.txt"}]
} }
} }
...@@ -1441,11 +1441,12 @@ static int getAllChildNameOfSuperTable(TAOS * taos, char* dbName, char* sTblName ...@@ -1441,11 +1441,12 @@ static int getAllChildNameOfSuperTable(TAOS * taos, char* dbName, char* sTblName
strncpy(pTblName, (char *)row[0], TSDB_TABLE_NAME_LEN); strncpy(pTblName, (char *)row[0], TSDB_TABLE_NAME_LEN);
//printf("==== sub table name: %s\n", pTblName); //printf("==== sub table name: %s\n", pTblName);
count++; count++;
if (count == childTblCount) { if (count >= childTblCount - 1) {
char *tmp = realloc(childTblName, (size_t)count*1.5*TSDB_TABLE_NAME_LEN); char *tmp = realloc(childTblName, (size_t)childTblCount*1.5*TSDB_TABLE_NAME_LEN+1);
if (tmp != NULL) { if (tmp != NULL) {
childTblName = tmp; childTblName = tmp;
memset(childTblName + count*TSDB_TABLE_NAME_LEN, 0, (size_t)(count*0.5*TSDB_TABLE_NAME_LEN)); childTblCount = (int)(childTblCount*1.5);
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);
...@@ -3960,7 +3961,11 @@ void *superQueryProcess(void *sarg) { ...@@ -3960,7 +3961,11 @@ void *superQueryProcess(void *sarg) {
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();
selectAndGetResult(winfo->taos, g_queryInfo.superQueryInfo.sql[i], g_queryInfo.superQueryInfo.result[i]); char tmpFile[MAX_FILE_NAME_LEN] = {0};
if (g_queryInfo.superQueryInfo.result[i][0] != 0) {
sprintf(tmpFile, "%s-%d", g_queryInfo.superQueryInfo.result[i], winfo->threadID);
}
selectAndGetResult(winfo->taos, g_queryInfo.superQueryInfo.sql[i], tmpFile);
int64_t t2 = taosGetTimestampUs(); int64_t t2 = taosGetTimestampUs();
printf("taosc select sql return, Spent %f s\n", (t2 - t1)/1000000.0); printf("taosc select sql return, Spent %f s\n", (t2 - t1)/1000000.0);
} else { } else {
...@@ -4019,7 +4024,11 @@ void *subQueryProcess(void *sarg) { ...@@ -4019,7 +4024,11 @@ void *subQueryProcess(void *sarg) {
for (int i = 0; i < g_queryInfo.subQueryInfo.sqlCount; i++) { for (int i = 0; i < g_queryInfo.subQueryInfo.sqlCount; i++) {
memset(sqlstr,0,sizeof(sqlstr)); memset(sqlstr,0,sizeof(sqlstr));
replaceSubTblName(g_queryInfo.subQueryInfo.sql[i], sqlstr, i); replaceSubTblName(g_queryInfo.subQueryInfo.sql[i], sqlstr, i);
selectAndGetResult(winfo->taos, sqlstr, g_queryInfo.subQueryInfo.result[i]); char tmpFile[MAX_FILE_NAME_LEN] = {0};
if (g_queryInfo.subQueryInfo.result[i][0] != 0) {
sprintf(tmpFile, "%s-%d", g_queryInfo.subQueryInfo.result[i], winfo->threadID);
}
selectAndGetResult(winfo->taos, sqlstr, tmpFile);
} }
} }
et = taosGetTimestampMs(); et = taosGetTimestampMs();
...@@ -4193,7 +4202,11 @@ void *subSubscribeProcess(void *sarg) { ...@@ -4193,7 +4202,11 @@ void *subSubscribeProcess(void *sarg) {
sprintf(topic, "taosdemo-subscribe-%d", i); sprintf(topic, "taosdemo-subscribe-%d", i);
memset(subSqlstr,0,sizeof(subSqlstr)); memset(subSqlstr,0,sizeof(subSqlstr));
replaceSubTblName(g_queryInfo.subQueryInfo.sql[i], subSqlstr, i); replaceSubTblName(g_queryInfo.subQueryInfo.sql[i], subSqlstr, i);
g_queryInfo.subQueryInfo.tsub[i] = subscribeImpl(winfo->taos, subSqlstr, topic, g_queryInfo.subQueryInfo.result[i]); char tmpFile[MAX_FILE_NAME_LEN] = {0};
if (g_queryInfo.subQueryInfo.result[i][0] != 0) {
sprintf(tmpFile, "%s-%d", g_queryInfo.subQueryInfo.result[i], winfo->threadID);
}
g_queryInfo.subQueryInfo.tsub[i] = subscribeImpl(winfo->taos, subSqlstr, topic, tmpFile);
if (NULL == g_queryInfo.subQueryInfo.tsub[i]) { if (NULL == g_queryInfo.subQueryInfo.tsub[i]) {
return NULL; return NULL;
} }
...@@ -4211,7 +4224,11 @@ void *subSubscribeProcess(void *sarg) { ...@@ -4211,7 +4224,11 @@ void *subSubscribeProcess(void *sarg) {
TAOS_RES* res = taos_consume(g_queryInfo.subQueryInfo.tsub[i]); TAOS_RES* res = taos_consume(g_queryInfo.subQueryInfo.tsub[i]);
if (res) { if (res) {
getResult(res, g_queryInfo.subQueryInfo.result[i]); char tmpFile[MAX_FILE_NAME_LEN] = {0};
if (g_queryInfo.subQueryInfo.result[i][0] != 0) {
sprintf(tmpFile, "%s-%d", g_queryInfo.subQueryInfo.result[i], winfo->threadID);
}
getResult(res, tmpFile);
taos_free_result(res); taos_free_result(res);
} }
} }
...@@ -4244,7 +4261,11 @@ void *superSubscribeProcess(void *sarg) { ...@@ -4244,7 +4261,11 @@ void *superSubscribeProcess(void *sarg) {
char topic[32] = {0}; char topic[32] = {0};
for (int i = 0; i < g_queryInfo.superQueryInfo.sqlCount; i++) { for (int i = 0; i < g_queryInfo.superQueryInfo.sqlCount; i++) {
sprintf(topic, "taosdemo-subscribe-%d", i); sprintf(topic, "taosdemo-subscribe-%d", i);
g_queryInfo.superQueryInfo.tsub[i] = subscribeImpl(winfo->taos, g_queryInfo.superQueryInfo.sql[i], topic, g_queryInfo.superQueryInfo.result[i]); char tmpFile[MAX_FILE_NAME_LEN] = {0};
if (g_queryInfo.subQueryInfo.result[i][0] != 0) {
sprintf(tmpFile, "%s-%d", g_queryInfo.superQueryInfo.result[i], winfo->threadID);
}
g_queryInfo.superQueryInfo.tsub[i] = subscribeImpl(winfo->taos, g_queryInfo.superQueryInfo.sql[i], topic, tmpFile);
if (NULL == g_queryInfo.superQueryInfo.tsub[i]) { if (NULL == g_queryInfo.superQueryInfo.tsub[i]) {
return NULL; return NULL;
} }
...@@ -4262,7 +4283,11 @@ void *superSubscribeProcess(void *sarg) { ...@@ -4262,7 +4283,11 @@ void *superSubscribeProcess(void *sarg) {
TAOS_RES* res = taos_consume(g_queryInfo.superQueryInfo.tsub[i]); TAOS_RES* res = taos_consume(g_queryInfo.superQueryInfo.tsub[i]);
if (res) { if (res) {
getResult(res, g_queryInfo.superQueryInfo.result[i]); char tmpFile[MAX_FILE_NAME_LEN] = {0};
if (g_queryInfo.superQueryInfo.result[i][0] != 0) {
sprintf(tmpFile, "%s-%d", g_queryInfo.superQueryInfo.result[i], winfo->threadID);
}
getResult(res, tmpFile);
taos_free_result(res); taos_free_result(res);
} }
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册