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

Hotfix/sangshuduo/td 5306 taosdemo stmt autocreatetable (#6950)

* [TD-5300]<fix>: taosdemo stmt debug print.

* fix default iface is unknown.
上级 b538d580
...@@ -90,7 +90,7 @@ extern char configDir[]; ...@@ -90,7 +90,7 @@ extern char configDir[];
#define MAX_SUPER_TABLE_COUNT 200 #define MAX_SUPER_TABLE_COUNT 200
#define MAX_QUERY_SQL_COUNT 100 #define MAX_QUERY_SQL_COUNT 100
#define MAX_QUERY_SQL_LENGTH 1024 #define MAX_QUERY_SQL_LENGTH BUFFER_SIZE
#define MAX_DATABASE_COUNT 256 #define MAX_DATABASE_COUNT 256
#define INPUT_BUF_LEN 256 #define INPUT_BUF_LEN 256
...@@ -2367,7 +2367,25 @@ static char* getTagValueFromTagSample(SSuperTable* stbInfo, int tagUsePos) { ...@@ -2367,7 +2367,25 @@ static char* getTagValueFromTagSample(SSuperTable* stbInfo, int tagUsePos) {
return dataBuf; return dataBuf;
} }
static char* generateTagValuesForStb(SSuperTable* stbInfo, int32_t tableSeq) { static char *generateBinaryNCharTagValues(int64_t tableSeq, uint32_t len)
{
char* buf = (char*)calloc(len, 1);
if (NULL == buf) {
printf("calloc failed! size:%d\n", len);
return NULL;
}
if (tableSeq % 2) {
tstrncpy(buf, "beijing", len);
} else {
tstrncpy(buf, "shanghai", len);
}
//rand_string(buf, stbInfo->tags[i].dataLen);
return buf;
}
static char* generateTagValuesForStb(SSuperTable* stbInfo, int64_t tableSeq) {
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);
...@@ -2388,20 +2406,12 @@ static char* generateTagValuesForStb(SSuperTable* stbInfo, int32_t tableSeq) { ...@@ -2388,20 +2406,12 @@ static char* generateTagValuesForStb(SSuperTable* stbInfo, int32_t tableSeq) {
return NULL; return NULL;
} }
int tagBufLen = stbInfo->tags[i].dataLen + 1; int32_t tagBufLen = stbInfo->tags[i].dataLen + 1;
char* buf = (char*)calloc(tagBufLen, 1); char *buf = generateBinaryNCharTagValues(tableSeq, tagBufLen);
if (NULL == buf) { if (NULL == buf) {
printf("calloc failed! size:%d\n", stbInfo->tags[i].dataLen);
tmfree(dataBuf); tmfree(dataBuf);
return NULL; return NULL;
} }
if (tableSeq % 2) {
tstrncpy(buf, "beijing", tagBufLen);
} else {
tstrncpy(buf, "shanghai", tagBufLen);
}
//rand_string(buf, stbInfo->tags[i].dataLen);
dataLen += snprintf(dataBuf + dataLen, TSDB_MAX_SQL_LEN - dataLen, dataLen += snprintf(dataBuf + dataLen, TSDB_MAX_SQL_LEN - dataLen,
"\'%s\',", buf); "\'%s\',", buf);
tmfree(buf); tmfree(buf);
...@@ -2410,11 +2420,11 @@ static char* generateTagValuesForStb(SSuperTable* stbInfo, int32_t tableSeq) { ...@@ -2410,11 +2420,11 @@ static char* generateTagValuesForStb(SSuperTable* stbInfo, int32_t tableSeq) {
if ((g_args.demo_mode) && (i == 0)) { if ((g_args.demo_mode) && (i == 0)) {
dataLen += snprintf(dataBuf + dataLen, dataLen += snprintf(dataBuf + dataLen,
TSDB_MAX_SQL_LEN - dataLen, TSDB_MAX_SQL_LEN - dataLen,
"%d,", tableSeq % 10); "%"PRId64",", tableSeq % 10);
} else { } else {
dataLen += snprintf(dataBuf + dataLen, dataLen += snprintf(dataBuf + dataLen,
TSDB_MAX_SQL_LEN - dataLen, TSDB_MAX_SQL_LEN - dataLen,
"%d,", tableSeq); "%"PRId64",", tableSeq);
} }
} else if (0 == strncasecmp(stbInfo->tags[i].dataType, } else if (0 == strncasecmp(stbInfo->tags[i].dataType,
"bigint", strlen("bigint"))) { "bigint", strlen("bigint"))) {
...@@ -2445,7 +2455,7 @@ static char* generateTagValuesForStb(SSuperTable* stbInfo, int32_t tableSeq) { ...@@ -2445,7 +2455,7 @@ static char* generateTagValuesForStb(SSuperTable* stbInfo, int32_t tableSeq) {
dataLen += snprintf(dataBuf + dataLen, TSDB_MAX_SQL_LEN - dataLen, dataLen += snprintf(dataBuf + dataLen, TSDB_MAX_SQL_LEN - dataLen,
"%"PRId64",", rand_bigint()); "%"PRId64",", rand_bigint());
} else { } else {
printf("No support data type: %s\n", stbInfo->tags[i].dataType); errorPrint("No support data type: %s\n", stbInfo->tags[i].dataType);
tmfree(dataBuf); tmfree(dataBuf);
return NULL; return NULL;
} }
...@@ -2734,7 +2744,7 @@ static int createSuperTable( ...@@ -2734,7 +2744,7 @@ static int createSuperTable(
} else if (strcasecmp(dataType, "INT") == 0) { } else if (strcasecmp(dataType, "INT") == 0) {
if ((g_args.demo_mode) && (colIndex == 1)) { if ((g_args.demo_mode) && (colIndex == 1)) {
len += snprintf(cols + len, COL_BUFFER_LEN - len, len += snprintf(cols + len, COL_BUFFER_LEN - len,
",VOLTAGE INT"); ", VOLTAGE INT");
} else { } else {
len += snprintf(cols + len, COL_BUFFER_LEN - len, ",C%d %s", colIndex, "INT"); len += snprintf(cols + len, COL_BUFFER_LEN - len, ",C%d %s", colIndex, "INT");
} }
...@@ -2756,9 +2766,9 @@ static int createSuperTable( ...@@ -2756,9 +2766,9 @@ static int createSuperTable(
} else if (strcasecmp(dataType, "FLOAT") == 0) { } else if (strcasecmp(dataType, "FLOAT") == 0) {
if (g_args.demo_mode) { if (g_args.demo_mode) {
if (colIndex == 0) { if (colIndex == 0) {
len += snprintf(cols + len, COL_BUFFER_LEN - len, ",CURRENT FLOAT"); len += snprintf(cols + len, COL_BUFFER_LEN - len, ", CURRENT FLOAT");
} else if (colIndex == 2) { } else if (colIndex == 2) {
len += snprintf(cols + len, COL_BUFFER_LEN - len, ",PHASE FLOAT"); len += snprintf(cols + len, COL_BUFFER_LEN - len, ", PHASE FLOAT");
} }
} else { } else {
len += snprintf(cols + len, COL_BUFFER_LEN - len, ",C%d %s", colIndex, "FLOAT"); len += snprintf(cols + len, COL_BUFFER_LEN - len, ",C%d %s", colIndex, "FLOAT");
...@@ -5319,7 +5329,7 @@ static int generateSQLHeadWithoutStb(char *tableName, ...@@ -5319,7 +5329,7 @@ static int generateSQLHeadWithoutStb(char *tableName,
static int generateStbSQLHead( static int generateStbSQLHead(
SSuperTable* superTblInfo, SSuperTable* superTblInfo,
char *tableName, int32_t tableSeq, char *tableName, int64_t tableSeq,
char *dbName, char *dbName,
char *buffer, int remainderBufLen) char *buffer, int remainderBufLen)
{ {
...@@ -5651,8 +5661,7 @@ static int32_t prepareStmtBindArrayByType(TAOS_BIND *bind, ...@@ -5651,8 +5661,7 @@ static int32_t prepareStmtBindArrayByType(TAOS_BIND *bind,
*ptr += bind->buffer_length; *ptr += bind->buffer_length;
} else { } else {
errorPrint( "No support data type: %s\n", errorPrint( "No support data type: %s\n", dataType);
dataType);
return -1; return -1;
} }
...@@ -5738,64 +5747,40 @@ static int32_t prepareStmtWithoutStb( ...@@ -5738,64 +5747,40 @@ static int32_t prepareStmtWithoutStb(
return k; return k;
} }
static int32_t prepareStbStmt( static int32_t prepareStbStmtBind(
SSuperTable *stbInfo, char *bindArray, SSuperTable *stbInfo, bool sourceRand,
TAOS_STMT *stmt, int64_t startTime, int32_t recSeq,
char *tableName, uint32_t batch, bool isColumn)
uint64_t insertRows,
uint64_t recordFrom,
int64_t startTime,
int64_t *pSamplePos)
{ {
int ret = taos_stmt_set_tbname(stmt, tableName); char *bindBuffer = calloc(1, g_args.len_of_binary);
if (ret != 0) {
errorPrint("failed to execute taos_stmt_set_tbname(%s). return 0x%x. reason: %s\n",
tableName, ret, taos_errstr(NULL));
return ret;
}
char *bindArray = malloc(sizeof(TAOS_BIND) * (stbInfo->columnCount + 1));
if (bindArray == NULL) {
errorPrint("%s() LN%d, Failed to allocate %d bind params\n",
__func__, __LINE__, (stbInfo->columnCount + 1));
return -1;
}
bool sourceRand;
if (0 == strncasecmp(stbInfo->dataSource, "rand", strlen("rand"))) {
sourceRand = true;
} else {
sourceRand = false; // from sample data file
}
char *bindBuffer = malloc(g_args.len_of_binary);
if (bindBuffer == NULL) { if (bindBuffer == NULL) {
errorPrint("%s() LN%d, Failed to allocate %d bind buffer\n", errorPrint("%s() LN%d, Failed to allocate %d bind buffer\n",
__func__, __LINE__, g_args.len_of_binary); __func__, __LINE__, g_args.len_of_binary);
free(bindArray);
return -1; return -1;
} }
uint32_t k;
for (k = 0; k < batch;) {
/* columnCount + 1 (ts) */
char data[MAX_DATA_SIZE]; char data[MAX_DATA_SIZE];
memset(data, 0, MAX_DATA_SIZE); memset(data, 0, MAX_DATA_SIZE);
char *ptr = data; char *ptr = data;
TAOS_BIND *bind = (TAOS_BIND *)(bindArray + 0);
TAOS_BIND *bind;
if (isColumn) {
for (int i = 0; i < stbInfo->columnCount + 1; i ++) {
bind = (TAOS_BIND *)((char *)bindArray + (sizeof(TAOS_BIND) * i));
if (i == 0) {
int64_t *bind_ts; int64_t *bind_ts;
bind_ts = (int64_t *)ptr; bind_ts = (int64_t *)ptr;
bind->buffer_type = TSDB_DATA_TYPE_TIMESTAMP; bind->buffer_type = TSDB_DATA_TYPE_TIMESTAMP;
if (stbInfo->disorderRatio) { if (stbInfo->disorderRatio) {
*bind_ts = startTime + getTSRandTail( *bind_ts = startTime + getTSRandTail(
stbInfo->timeStampStep, k, stbInfo->timeStampStep, recSeq,
stbInfo->disorderRatio, stbInfo->disorderRatio,
stbInfo->disorderRange); stbInfo->disorderRange);
} else { } else {
*bind_ts = startTime + stbInfo->timeStampStep * k; *bind_ts = startTime + stbInfo->timeStampStep * recSeq;
} }
bind->buffer_length = sizeof(int64_t); bind->buffer_length = sizeof(int64_t);
bind->buffer = bind_ts; bind->buffer = bind_ts;
...@@ -5803,19 +5788,16 @@ static int32_t prepareStbStmt( ...@@ -5803,19 +5788,16 @@ static int32_t prepareStbStmt(
bind->is_null = NULL; bind->is_null = NULL;
ptr += bind->buffer_length; ptr += bind->buffer_length;
} else {
int cursor = 0; int cursor = 0;
for (int i = 0; i < stbInfo->columnCount; i ++) {
bind = (TAOS_BIND *)((char *)bindArray + (sizeof(TAOS_BIND) * (i + 1)));
if (sourceRand) { if (sourceRand) {
if ( -1 == prepareStmtBindArrayByType( if ( -1 == prepareStmtBindArrayByType(
bind, bind,
stbInfo->columns[i].dataType, stbInfo->columns[i-1].dataType,
stbInfo->columns[i].dataLen, stbInfo->columns[i-1].dataLen,
&ptr, &ptr,
NULL)) { NULL)) {
free(bindArray);
free(bindBuffer); free(bindBuffer);
return -1; return -1;
} }
...@@ -5836,16 +5818,120 @@ static int32_t prepareStbStmt( ...@@ -5836,16 +5818,120 @@ static int32_t prepareStbStmt(
if ( -1 == prepareStmtBindArrayByType( if ( -1 == prepareStmtBindArrayByType(
bind, bind,
stbInfo->columns[i].dataType, stbInfo->columns[i-1].dataType,
stbInfo->columns[i].dataLen, stbInfo->columns[i-1].dataLen,
&ptr, &ptr,
bindBuffer)) { bindBuffer)) {
free(bindArray);
free(bindBuffer); free(bindBuffer);
return -1; return -1;
} }
} }
} }
}
} else {
TAOS_BIND *tag;
for (int t = 0; t < stbInfo->tagCount; t ++) {
tag = (TAOS_BIND *)((char *)bindArray + (sizeof(TAOS_BIND) * t));
if ( -1 == prepareStmtBindArrayByType(
tag,
stbInfo->tags[t].dataType,
stbInfo->tags[t].dataLen,
&ptr,
NULL)) {
free(bindBuffer);
return -1;
}
}
}
return 0;
}
static int32_t prepareStbStmt(
SSuperTable *stbInfo,
TAOS_STMT *stmt,
char *tableName,
int64_t tableSeq,
uint32_t batch,
uint64_t insertRows,
uint64_t recordFrom,
int64_t startTime,
int64_t *pSamplePos)
{
int ret;
bool sourceRand;
if (0 == strncasecmp(stbInfo->dataSource, "rand", strlen("rand"))) {
sourceRand = true;
} else {
sourceRand = false; // from sample data file
}
if (AUTO_CREATE_SUBTBL == stbInfo->autoCreateTable) {
char* tagsValBuf = NULL;
bool tagRand;
if (0 == stbInfo->tagSource) {
tagRand = true;
tagsValBuf = generateTagValuesForStb(stbInfo, tableSeq);
} else {
tagRand = false;
tagsValBuf = getTagValueFromTagSample(
stbInfo,
tableSeq % stbInfo->tagSampleCount);
}
if (NULL == tagsValBuf) {
errorPrint("%s() LN%d, tag buf failed to allocate memory\n",
__func__, __LINE__);
return -1;
}
char *tagsArray = calloc(1, sizeof(TAOS_BIND) * stbInfo->tagCount);
if (NULL == tagsArray) {
tmfree(tagsValBuf);
errorPrint("%s() LN%d, tag buf failed to allocate memory\n",
__func__, __LINE__);
return -1;
}
if (-1 == prepareStbStmtBind(
tagsArray, stbInfo, tagRand, -1, -1, false /* is tag */)) {
free(tagsArray);
return -1;
}
ret = taos_stmt_set_tbname_tags(stmt, tableName, (TAOS_BIND *)tagsArray);
tmfree(tagsValBuf);
tmfree((char *)tagsArray);
} else {
ret = taos_stmt_set_tbname(stmt, tableName);
}
if (ret != 0) {
errorPrint("failed to execute taos_stmt_set_tbname(%s). return 0x%x. reason: %s\n",
tableName, ret, taos_errstr(NULL));
return ret;
}
char *bindArray = calloc(1, sizeof(TAOS_BIND) * (stbInfo->columnCount + 1));
if (bindArray == NULL) {
errorPrint("%s() LN%d, Failed to allocate %d bind params\n",
__func__, __LINE__, (stbInfo->columnCount + 1));
return -1;
}
uint32_t k;
for (k = 0; k < batch;) {
/* columnCount + 1 (ts) */
if (-1 == prepareStbStmtBind(bindArray, stbInfo, sourceRand,
startTime, k, true /* is column */)) {
free(bindArray);
return -1;
}
taos_stmt_bind_param(stmt, (TAOS_BIND *)bindArray); taos_stmt_bind_param(stmt, (TAOS_BIND *)bindArray);
// if msg > 3MB, break // if msg > 3MB, break
taos_stmt_add_batch(stmt); taos_stmt_add_batch(stmt);
...@@ -5862,7 +5948,6 @@ static int32_t prepareStbStmt( ...@@ -5862,7 +5948,6 @@ static int32_t prepareStbStmt(
} }
} }
free(bindBuffer);
free(bindArray); free(bindArray);
return k; return k;
} }
...@@ -5870,7 +5955,9 @@ static int32_t prepareStbStmt( ...@@ -5870,7 +5955,9 @@ static int32_t prepareStbStmt(
static int32_t prepareStbStmtInterlace( static int32_t prepareStbStmtInterlace(
SSuperTable *stbInfo, SSuperTable *stbInfo,
TAOS_STMT *stmt, TAOS_STMT *stmt,
char *tableName, uint32_t batch, char *tableName,
int64_t tableSeq,
uint32_t batch,
uint64_t insertRows, uint64_t insertRows,
uint64_t recordFrom, uint64_t recordFrom,
int64_t startTime, int64_t startTime,
...@@ -5880,6 +5967,7 @@ static int32_t prepareStbStmtInterlace( ...@@ -5880,6 +5967,7 @@ static int32_t prepareStbStmtInterlace(
stbInfo, stbInfo,
stmt, stmt,
tableName, tableName,
tableSeq,
batch, batch,
insertRows, 0, startTime, insertRows, 0, startTime,
pSamplePos); pSamplePos);
...@@ -5888,7 +5976,9 @@ static int32_t prepareStbStmtInterlace( ...@@ -5888,7 +5976,9 @@ static int32_t prepareStbStmtInterlace(
static int32_t prepareStbStmtProgressive( static int32_t prepareStbStmtProgressive(
SSuperTable *stbInfo, SSuperTable *stbInfo,
TAOS_STMT *stmt, TAOS_STMT *stmt,
char *tableName, uint32_t batch, char *tableName,
int64_t tableSeq,
uint32_t batch,
uint64_t insertRows, uint64_t insertRows,
uint64_t recordFrom, uint64_t recordFrom,
int64_t startTime, int64_t startTime,
...@@ -5898,6 +5988,7 @@ static int32_t prepareStbStmtProgressive( ...@@ -5898,6 +5988,7 @@ static int32_t prepareStbStmtProgressive(
stbInfo, stbInfo,
stmt, stmt,
tableName, tableName,
tableSeq,
g_args.num_of_RPR, g_args.num_of_RPR,
insertRows, recordFrom, startTime, insertRows, recordFrom, startTime,
pSamplePos); pSamplePos);
...@@ -6098,6 +6189,7 @@ static void* syncWriteInterlace(threadInfo *pThreadInfo) { ...@@ -6098,6 +6189,7 @@ static void* syncWriteInterlace(threadInfo *pThreadInfo) {
superTblInfo, superTblInfo,
pThreadInfo->stmt, pThreadInfo->stmt,
tableName, tableName,
tableSeq,
batchPerTbl, batchPerTbl,
insertRows, i, insertRows, i,
startTime, startTime,
...@@ -6327,6 +6419,7 @@ static void* syncWriteProgressive(threadInfo *pThreadInfo) { ...@@ -6327,6 +6419,7 @@ static void* syncWriteProgressive(threadInfo *pThreadInfo) {
superTblInfo, superTblInfo,
pThreadInfo->stmt, pThreadInfo->stmt,
tableName, tableName,
tableSeq,
g_args.num_of_RPR, g_args.num_of_RPR,
insertRows, i, start_time, insertRows, i, start_time,
&(pThreadInfo->samplePos)); &(pThreadInfo->samplePos));
...@@ -6759,7 +6852,7 @@ static void startMultiThreadInsertData(int threads, char* db_name, ...@@ -6759,7 +6852,7 @@ static void startMultiThreadInsertData(int threads, char* db_name,
exit(-1); exit(-1);
} }
char buffer[3000]; char buffer[BUFFER_SIZE];
char *pstr = buffer; char *pstr = buffer;
if ((superTblInfo) if ((superTblInfo)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册