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

[TD-5852]<fix>: taosdemo data generation race. (#7533)

上级 bcf74ecd
......@@ -1336,7 +1336,7 @@ static char *rand_bool_str(){
static int cursor;
cursor++;
if (cursor > (MAX_PREPARED_RAND - 1)) cursor = 0;
return g_randbool_buff + (cursor * BOOL_BUFF_LEN);
return g_randbool_buff + ((cursor % MAX_PREPARED_RAND) * BOOL_BUFF_LEN);
}
static int32_t rand_bool(){
......@@ -1351,7 +1351,8 @@ static char *rand_tinyint_str()
static int cursor;
cursor++;
if (cursor > (MAX_PREPARED_RAND - 1)) cursor = 0;
return g_randtinyint_buff + (cursor * TINYINT_BUFF_LEN);
return g_randtinyint_buff +
((cursor % MAX_PREPARED_RAND) * TINYINT_BUFF_LEN);
}
static int32_t rand_tinyint()
......@@ -1367,7 +1368,8 @@ static char *rand_smallint_str()
static int cursor;
cursor++;
if (cursor > (MAX_PREPARED_RAND - 1)) cursor = 0;
return g_randsmallint_buff + (cursor * SMALLINT_BUFF_LEN);
return g_randsmallint_buff +
((cursor % MAX_PREPARED_RAND) * SMALLINT_BUFF_LEN);
}
static int32_t rand_smallint()
......@@ -1383,7 +1385,7 @@ static char *rand_int_str()
static int cursor;
cursor++;
if (cursor > (MAX_PREPARED_RAND - 1)) cursor = 0;
return g_randint_buff + (cursor * INT_BUFF_LEN);
return g_randint_buff + ((cursor % MAX_PREPARED_RAND) * INT_BUFF_LEN);
}
static int32_t rand_int()
......@@ -1399,7 +1401,8 @@ static char *rand_bigint_str()
static int cursor;
cursor++;
if (cursor > (MAX_PREPARED_RAND - 1)) cursor = 0;
return g_randbigint_buff + (cursor * BIGINT_BUFF_LEN);
return g_randbigint_buff +
((cursor % MAX_PREPARED_RAND) * BIGINT_BUFF_LEN);
}
static int64_t rand_bigint()
......@@ -1415,7 +1418,7 @@ static char *rand_float_str()
static int cursor;
cursor++;
if (cursor > (MAX_PREPARED_RAND - 1)) cursor = 0;
return g_randfloat_buff + (cursor * FLOAT_BUFF_LEN);
return g_randfloat_buff + ((cursor % MAX_PREPARED_RAND) * FLOAT_BUFF_LEN);
}
......@@ -1432,7 +1435,8 @@ static char *demo_current_float_str()
static int cursor;
cursor++;
if (cursor > (MAX_PREPARED_RAND - 1)) cursor = 0;
return g_rand_current_buff + (cursor * FLOAT_BUFF_LEN);
return g_rand_current_buff +
((cursor % MAX_PREPARED_RAND) * FLOAT_BUFF_LEN);
}
static float UNUSED_FUNC demo_current_float()
......@@ -1449,7 +1453,8 @@ static char *demo_voltage_int_str()
static int cursor;
cursor++;
if (cursor > (MAX_PREPARED_RAND - 1)) cursor = 0;
return g_rand_voltage_buff + (cursor * INT_BUFF_LEN);
return g_rand_voltage_buff +
((cursor % MAX_PREPARED_RAND) * INT_BUFF_LEN);
}
static int32_t UNUSED_FUNC demo_voltage_int()
......@@ -1464,7 +1469,7 @@ static char *demo_phase_float_str() {
static int cursor;
cursor++;
if (cursor > (MAX_PREPARED_RAND - 1)) cursor = 0;
return g_rand_phase_buff + (cursor * FLOAT_BUFF_LEN);
return g_rand_phase_buff + ((cursor % MAX_PREPARED_RAND) * FLOAT_BUFF_LEN);
}
static float UNUSED_FUNC demo_phase_float(){
......@@ -5199,7 +5204,8 @@ static int64_t generateStbRowData(
"SMALLINT", 8)) {
tmp = rand_smallint_str();
tmpLen = strlen(tmp);
tstrncpy(pstr + dataLen, tmp, min(tmpLen + 1, SMALLINT_BUFF_LEN));
tstrncpy(pstr + dataLen, tmp,
min(tmpLen + 1, SMALLINT_BUFF_LEN));
} else if (0 == strncasecmp(stbInfo->columns[i].dataType,
"TINYINT", 7)) {
tmp = rand_tinyint_str();
......@@ -5212,9 +5218,9 @@ static int64_t generateStbRowData(
tstrncpy(pstr + dataLen, tmp, min(tmpLen +1, BOOL_BUFF_LEN));
} else if (0 == strncasecmp(stbInfo->columns[i].dataType,
"TIMESTAMP", 9)) {
tmp = rand_int_str();
tmp = rand_bigint_str();
tmpLen = strlen(tmp);
tstrncpy(pstr + dataLen, tmp, min(tmpLen +1, INT_BUFF_LEN));
tstrncpy(pstr + dataLen, tmp, min(tmpLen +1, BIGINT_BUFF_LEN));
} else {
errorPrint( "Not support data type: %s\n",
stbInfo->columns[i].dataType);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册