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

[TD-5702]<fix>: taosdemo remove memory operation. (#7114)

* [TD-5702]<fix>: taosdemo remove memory operation.

* add remainderBufLen to check row data generation.

* row data generation with remainder buffer length checking.
Co-authored-by: NShuduo Sang <sdsang@taosdata.com>
上级 aba07934
...@@ -5093,7 +5093,9 @@ static int getRowDataFromSample( ...@@ -5093,7 +5093,9 @@ static int getRowDataFromSample(
static int64_t generateStbRowData( static int64_t generateStbRowData(
SSuperTable* stbInfo, SSuperTable* stbInfo,
char* recBuf, int64_t timestamp) char* recBuf,
int64_t remainderBufLen,
int64_t timestamp)
{ {
int64_t dataLen = 0; int64_t dataLen = 0;
char *pstr = recBuf; char *pstr = recBuf;
...@@ -5121,6 +5123,7 @@ static int64_t generateStbRowData( ...@@ -5121,6 +5123,7 @@ static int64_t generateStbRowData(
rand_string(buf, stbInfo->columns[i].dataLen); rand_string(buf, stbInfo->columns[i].dataLen);
dataLen += snprintf(pstr + dataLen, maxLen - dataLen, "\'%s\',", buf); dataLen += snprintf(pstr + dataLen, maxLen - dataLen, "\'%s\',", buf);
tmfree(buf); tmfree(buf);
} else { } else {
char *tmp; char *tmp;
...@@ -5177,6 +5180,9 @@ static int64_t generateStbRowData( ...@@ -5177,6 +5180,9 @@ static int64_t generateStbRowData(
tstrncpy(pstr + dataLen, ",", 2); tstrncpy(pstr + dataLen, ",", 2);
dataLen += 1; dataLen += 1;
} }
if (dataLen > remainderBufLen)
return 0;
} }
dataLen -= 1; dataLen -= 1;
...@@ -5383,7 +5389,7 @@ static int32_t generateDataTailWithoutStb( ...@@ -5383,7 +5389,7 @@ static int32_t generateDataTailWithoutStb(
int32_t k = 0; int32_t k = 0;
for (k = 0; k < batch;) { for (k = 0; k < batch;) {
char data[MAX_DATA_SIZE]; char *data = pstr;
memset(data, 0, MAX_DATA_SIZE); memset(data, 0, MAX_DATA_SIZE);
int64_t retLen = 0; int64_t retLen = 0;
...@@ -5407,7 +5413,7 @@ static int32_t generateDataTailWithoutStb( ...@@ -5407,7 +5413,7 @@ static int32_t generateDataTailWithoutStb(
if (len > remainderBufLen) if (len > remainderBufLen)
break; break;
pstr += sprintf(pstr, "%s", data); pstr += retLen;
k++; k++;
len += retLen; len += retLen;
remainderBufLen -= retLen; remainderBufLen -= retLen;
...@@ -5463,14 +5469,14 @@ static int32_t generateStbDataTail( ...@@ -5463,14 +5469,14 @@ static int32_t generateStbDataTail(
int32_t k; int32_t k;
for (k = 0; k < batch;) { for (k = 0; k < batch;) {
char data[MAX_DATA_SIZE]; char *data = pstr;
memset(data, 0, MAX_DATA_SIZE);
int64_t lenOfRow = 0; int64_t lenOfRow = 0;
if (tsRand) { if (tsRand) {
if (superTblInfo->disorderRatio > 0) { if (superTblInfo->disorderRatio > 0) {
lenOfRow = generateStbRowData(superTblInfo, data, lenOfRow = generateStbRowData(superTblInfo, data,
remainderBufLen,
startTime + getTSRandTail( startTime + getTSRandTail(
superTblInfo->timeStampStep, k, superTblInfo->timeStampStep, k,
superTblInfo->disorderRatio, superTblInfo->disorderRatio,
...@@ -5478,6 +5484,7 @@ static int32_t generateStbDataTail( ...@@ -5478,6 +5484,7 @@ static int32_t generateStbDataTail(
); );
} else { } else {
lenOfRow = generateStbRowData(superTblInfo, data, lenOfRow = generateStbRowData(superTblInfo, data,
remainderBufLen,
startTime + superTblInfo->timeStampStep * k startTime + superTblInfo->timeStampStep * k
); );
} }
...@@ -5490,11 +5497,15 @@ static int32_t generateStbDataTail( ...@@ -5490,11 +5497,15 @@ static int32_t generateStbDataTail(
pSamplePos); pSamplePos);
} }
if (lenOfRow == 0) {
data[0] = '\0';
break;
}
if ((lenOfRow + 1) > remainderBufLen) { if ((lenOfRow + 1) > remainderBufLen) {
break; break;
} }
pstr += snprintf(pstr , lenOfRow + 1, "%s", data); pstr += lenOfRow;
k++; k++;
len += lenOfRow; len += lenOfRow;
remainderBufLen -= lenOfRow; remainderBufLen -= lenOfRow;
...@@ -6246,7 +6257,7 @@ static int32_t generateStbProgressiveData( ...@@ -6246,7 +6257,7 @@ static int32_t generateStbProgressiveData(
assert(buffer != NULL); assert(buffer != NULL);
char *pstr = buffer; char *pstr = buffer;
memset(buffer, 0, *pRemainderBufLen); memset(pstr, 0, *pRemainderBufLen);
int64_t headLen = generateStbSQLHead( int64_t headLen = generateStbSQLHead(
superTblInfo, superTblInfo,
...@@ -6640,7 +6651,7 @@ static void* syncWriteProgressive(threadInfo *pThreadInfo) { ...@@ -6640,7 +6651,7 @@ static void* syncWriteProgressive(threadInfo *pThreadInfo) {
return NULL; return NULL;
} }
int64_t remainderBufLen = maxSqlLen; int64_t remainderBufLen = maxSqlLen - 2000;
char *pstr = pThreadInfo->buffer; char *pstr = pThreadInfo->buffer;
int len = snprintf(pstr, int len = snprintf(pstr,
...@@ -6822,10 +6833,14 @@ static void callBack(void *param, TAOS_RES *res, int code) { ...@@ -6822,10 +6833,14 @@ static void callBack(void *param, TAOS_RES *res, int code) {
&& rand_num < pThreadInfo->superTblInfo->disorderRatio) { && rand_num < pThreadInfo->superTblInfo->disorderRatio) {
int64_t d = pThreadInfo->lastTs int64_t d = pThreadInfo->lastTs
- (taosRandom() % pThreadInfo->superTblInfo->disorderRange + 1); - (taosRandom() % pThreadInfo->superTblInfo->disorderRange + 1);
generateStbRowData(pThreadInfo->superTblInfo, data, d); generateStbRowData(pThreadInfo->superTblInfo, data,
MAX_DATA_SIZE,
d);
} else { } else {
generateStbRowData(pThreadInfo->superTblInfo, generateStbRowData(pThreadInfo->superTblInfo,
data, pThreadInfo->lastTs += 1000); data,
MAX_DATA_SIZE,
pThreadInfo->lastTs += 1000);
} }
pstr += sprintf(pstr, "%s", data); pstr += sprintf(pstr, "%s", data);
pThreadInfo->counter++; pThreadInfo->counter++;
...@@ -7050,6 +7065,7 @@ static void startMultiThreadInsertData(int threads, char* db_name, ...@@ -7050,6 +7065,7 @@ static void startMultiThreadInsertData(int threads, char* db_name,
for (int i = 0; i < threads; i++) { for (int i = 0; i < threads; i++) {
threadInfo *pThreadInfo = infos + i; threadInfo *pThreadInfo = infos + i;
pThreadInfo->threadID = i; pThreadInfo->threadID = i;
tstrncpy(pThreadInfo->db_name, db_name, TSDB_DB_NAME_LEN); tstrncpy(pThreadInfo->db_name, db_name, TSDB_DB_NAME_LEN);
pThreadInfo->time_precision = timePrec; pThreadInfo->time_precision = timePrec;
pThreadInfo->superTblInfo = superTblInfo; pThreadInfo->superTblInfo = superTblInfo;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册