Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
aafd7e1d
TDengine
项目概览
taosdata
/
TDengine
大约 2 年 前同步成功
通知
1192
Star
22018
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
aafd7e1d
编写于
11月 15, 2021
作者:
Z
zhaoyanggh
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
merge sml
上级
c9bf5339
变更
9
显示空白变更内容
内联
并排
Showing
9 changed file
with
2994 addition
and
2003 deletion
+2994
-2003
src/kit/taosdemo/inc/demo.h
src/kit/taosdemo/inc/demo.h
+44
-41
src/kit/taosdemo/inc/demoData.h
src/kit/taosdemo/inc/demoData.h
+49
-0
src/kit/taosdemo/insert.json
src/kit/taosdemo/insert.json
+1
-1
src/kit/taosdemo/src/demoCommandOpt.c
src/kit/taosdemo/src/demoCommandOpt.c
+8
-7
src/kit/taosdemo/src/demoData.c
src/kit/taosdemo/src/demoData.c
+2096
-1
src/kit/taosdemo/src/demoInsert.c
src/kit/taosdemo/src/demoInsert.c
+726
-1897
src/kit/taosdemo/src/demoMain.c
src/kit/taosdemo/src/demoMain.c
+29
-28
src/kit/taosdemo/src/demoOutput.c
src/kit/taosdemo/src/demoOutput.c
+41
-1
src/kit/taosdemo/src/demoUtil.c
src/kit/taosdemo/src/demoUtil.c
+0
-27
未找到文件。
src/kit/taosdemo/inc/demo.h
浏览文件 @
aafd7e1d
...
@@ -500,7 +500,6 @@ typedef struct SuperQueryInfo_S {
...
@@ -500,7 +500,6 @@ typedef struct SuperQueryInfo_S {
int
resubAfterConsume
;
int
resubAfterConsume
;
int
endAfterConsume
;
int
endAfterConsume
;
TAOS_SUB
*
tsub
[
MAX_QUERY_SQL_COUNT
];
TAOS_SUB
*
tsub
[
MAX_QUERY_SQL_COUNT
];
char
*
childTblName
;
char
*
childTblName
;
uint64_t
totalQueried
;
uint64_t
totalQueried
;
}
SuperQueryInfo
;
}
SuperQueryInfo
;
...
@@ -514,7 +513,6 @@ typedef struct SQueryMetaInfo_S {
...
@@ -514,7 +513,6 @@ typedef struct SQueryMetaInfo_S {
char
password
[
SHELL_MAX_PASSWORD_LEN
];
char
password
[
SHELL_MAX_PASSWORD_LEN
];
char
dbName
[
TSDB_DB_NAME_LEN
];
char
dbName
[
TSDB_DB_NAME_LEN
];
char
queryMode
[
SMALL_BUFF_LEN
];
// taosc, rest
char
queryMode
[
SMALL_BUFF_LEN
];
// taosc, rest
SpecifiedQueryInfo
specifiedQueryInfo
;
SpecifiedQueryInfo
specifiedQueryInfo
;
SuperQueryInfo
superQueryInfo
;
SuperQueryInfo
superQueryInfo
;
uint64_t
totalQueried
;
uint64_t
totalQueried
;
...
@@ -522,13 +520,11 @@ typedef struct SQueryMetaInfo_S {
...
@@ -522,13 +520,11 @@ typedef struct SQueryMetaInfo_S {
typedef
struct
SThreadInfo_S
{
typedef
struct
SThreadInfo_S
{
TAOS
*
taos
;
TAOS
*
taos
;
TAOS_STMT
*
stmt
;
TAOS_STMT
*
stmt
;
int64_t
*
bind_ts
;
int64_t
*
bind_ts
;
int64_t
*
bind_ts_array
;
int64_t
*
bind_ts_array
;
char
*
bindParams
;
char
*
bindParams
;
char
*
is_null
;
char
*
is_null
;
int
threadID
;
int
threadID
;
char
db_name
[
TSDB_DB_NAME_LEN
];
char
db_name
[
TSDB_DB_NAME_LEN
];
uint32_t
time_precision
;
uint32_t
time_precision
;
...
@@ -588,54 +584,61 @@ extern FILE * g_fpOfInsertResult;
...
@@ -588,54 +584,61 @@ extern FILE * g_fpOfInsertResult;
#define min(a, b) (((a) < (b)) ? (a) : (b))
#define min(a, b) (((a) < (b)) ? (a) : (b))
/* ************ Function declares ************ */
/* ************ Function declares ************ */
/* demoCommandOpt.c */
int
parse_args
(
int
argc
,
char
*
argv
[]);
int
parse_args
(
int
argc
,
char
*
argv
[]);
void
setParaFromArg
();
void
querySqlFile
(
TAOS
*
taos
,
char
*
sqlFile
);
void
testCmdLine
();
/* demoJsonOpt.c */
int
getInfoFromJsonFile
(
char
*
file
);
int
getInfoFromJsonFile
(
char
*
file
);
int
testMetaFile
();
/* demoUtil.c */
int
isCommentLine
(
char
*
line
);
void
replaceChildTblName
(
char
*
inSql
,
char
*
outSql
,
int
tblIndex
);
void
setupForAnsiEscape
(
void
);
void
setupForAnsiEscape
(
void
);
void
resetAfterAnsiEscape
(
void
);
int
taosRandom
();
int
taosRandom
();
int
testMetaFile
();
int
insertTestProcess
();
void
printfInsertMeta
();
void
printfInsertMetaToFile
(
FILE
*
fp
);
void
prompt
();
void
postFreeResource
();
void
setParaFromArg
();
void
printStatPerThread
(
threadInfo
*
pThreadInfo
);
void
tmfree
(
void
*
buf
);
void
tmfree
(
void
*
buf
);
void
tmfclose
(
FILE
*
fp
);
void
tmfclose
(
FILE
*
fp
);
void
fetchResult
(
TAOS_RES
*
res
,
threadInfo
*
pThreadInfo
);
void
fetchResult
(
TAOS_RES
*
res
,
threadInfo
*
pThreadInfo
);
void
prompt
();
void
ERROR_EXIT
(
const
char
*
msg
);
int
postProceSql
(
char
*
host
,
uint16_t
port
,
char
*
sqlstr
,
int
postProceSql
(
char
*
host
,
uint16_t
port
,
char
*
sqlstr
,
threadInfo
*
pThreadInfo
);
threadInfo
*
pThreadInfo
);
void
appendResultBufToFile
(
char
*
resultBuf
,
threadInfo
*
pThreadInfo
);
int
queryDbExec
(
TAOS
*
taos
,
char
*
command
,
QUERY_TYPE
type
,
bool
quiet
);
int
queryDbExec
(
TAOS
*
taos
,
char
*
command
,
QUERY_TYPE
type
,
bool
quiet
);
int
regexMatch
(
const
char
*
s
,
const
char
*
reg
,
int
cflags
);
int
regexMatch
(
const
char
*
s
,
const
char
*
reg
,
int
cflags
);
int
convertHostToServAddr
(
char
*
host
,
uint16_t
port
,
int
convertHostToServAddr
(
char
*
host
,
uint16_t
port
,
struct
sockaddr_in
*
serv_addr
);
struct
sockaddr_in
*
serv_addr
);
char
*
formatTimestamp
(
char
*
buf
,
int64_t
val
,
int
precision
);
char
*
formatTimestamp
(
char
*
buf
,
int64_t
val
,
int
precision
);
int
getChildNameOfSuperTableWithLimitAndOffset
(
TAOS
*
taos
,
char
*
dbName
,
char
*
stbName
,
char
**
childTblNameOfSuperTbl
,
int64_t
*
childTblCountOfSuperTbl
,
int64_t
limit
,
uint64_t
offset
,
bool
escapChar
);
void
errorWrongValue
(
char
*
program
,
char
*
wrong_arg
,
char
*
wrong_value
);
void
errorWrongValue
(
char
*
program
,
char
*
wrong_arg
,
char
*
wrong_value
);
void
errorUnrecognized
(
char
*
program
,
char
*
wrong_arg
);
void
errorUnrecognized
(
char
*
program
,
char
*
wrong_arg
);
void
errorPrintReqArg
(
char
*
program
,
char
*
wrong_arg
);
void
errorPrintReqArg
(
char
*
program
,
char
*
wrong_arg
);
void
errorPrintReqArg2
(
char
*
program
,
char
*
wrong_arg
);
void
errorPrintReqArg2
(
char
*
program
,
char
*
wrong_arg
);
void
errorPrintReqArg3
(
char
*
program
,
char
*
wrong_arg
);
void
errorPrintReqArg3
(
char
*
program
,
char
*
wrong_arg
);
bool
isStringNumber
(
char
*
input
);
bool
isStringNumber
(
char
*
input
);
void
printHelp
();
int
queryTestProcess
();
void
ERROR_EXIT
(
const
char
*
msg
);
void
querySqlFile
(
TAOS
*
taos
,
char
*
sqlFile
);
void
printVersion
();
int
subscribeTestProcess
();
void
testCmdLine
();
int
isCommentLine
(
char
*
line
);
void
replaceChildTblName
(
char
*
inSql
,
char
*
outSql
,
int
tblIndex
);
void
printfQueryMeta
();
int
getAllChildNameOfSuperTable
(
TAOS
*
taos
,
char
*
dbName
,
char
*
stbName
,
int
getAllChildNameOfSuperTable
(
TAOS
*
taos
,
char
*
dbName
,
char
*
stbName
,
char
**
childTblNameOfSuperTbl
,
char
**
childTblNameOfSuperTbl
,
int64_t
*
childTblCountOfSuperTbl
);
int64_t
*
childTblCountOfSuperTbl
);
void
resetAfterAnsiEscape
(
void
);
int
getChildNameOfSuperTableWithLimitAndOffset
(
TAOS
*
taos
,
char
*
dbName
,
char
*
stbName
,
char
**
childTblNameOfSuperTbl
,
int64_t
*
childTblCountOfSuperTbl
,
int64_t
limit
,
uint64_t
offset
,
bool
escapChar
);
/* demoInsert.c */
int
insertTestProcess
();
void
postFreeResource
();
/* demoOutput.c */
void
printVersion
();
void
printfInsertMeta
();
void
printfInsertMetaToFile
(
FILE
*
fp
);
void
printStatPerThread
(
threadInfo
*
pThreadInfo
);
void
appendResultBufToFile
(
char
*
resultBuf
,
threadInfo
*
pThreadInfo
);
void
printfQueryMeta
();
void
printHelp
();
void
printfQuerySystemInfo
(
TAOS
*
taos
);
void
printfQuerySystemInfo
(
TAOS
*
taos
);
/* demoQuery.c */
int
queryTestProcess
();
/* demoSubscribe.c */
int
subscribeTestProcess
();
#endif
#endif
\ No newline at end of file
src/kit/taosdemo/inc/demoData.h
浏览文件 @
aafd7e1d
...
@@ -15,6 +15,7 @@
...
@@ -15,6 +15,7 @@
#ifndef __DEMODATA__
#ifndef __DEMODATA__
#define __DEMODATA__
#define __DEMODATA__
#include "cJSON.h"
#include "demo.h"
#include "demo.h"
/***** Global variables ******/
/***** Global variables ******/
...
@@ -71,4 +72,52 @@ float UNUSED_FUNC demo_phase_float();
...
@@ -71,4 +72,52 @@ float UNUSED_FUNC demo_phase_float();
void
rand_string
(
char
*
str
,
int
size
);
void
rand_string
(
char
*
str
,
int
size
);
char
*
rand_double_str
();
char
*
rand_double_str
();
double
rand_double
();
double
rand_double
();
int
generateTagValuesForStb
(
SSuperTable
*
stbInfo
,
int64_t
tableSeq
,
char
*
tagsValBuf
);
int64_t
getTSRandTail
(
int64_t
timeStampStep
,
int32_t
seq
,
int
disorderRatio
,
int
disorderRange
);
int32_t
prepareStbStmtBindTag
(
char
*
bindArray
,
SSuperTable
*
stbInfo
,
char
*
tagsVal
,
int32_t
timePrec
);
int32_t
prepareStmtWithoutStb
(
threadInfo
*
pThreadInfo
,
char
*
tableName
,
uint32_t
batch
,
int64_t
insertRows
,
int64_t
recordFrom
,
int64_t
startTime
);
int32_t
generateStbInterlaceData
(
threadInfo
*
pThreadInfo
,
char
*
tableName
,
uint32_t
batchPerTbl
,
uint64_t
i
,
uint32_t
batchPerTblTimes
,
uint64_t
tableSeq
,
char
*
buffer
,
int64_t
insertRows
,
int64_t
startTime
,
uint64_t
*
pRemainderBufLen
);
int64_t
generateInterlaceDataWithoutStb
(
char
*
tableName
,
uint32_t
batch
,
uint64_t
tableSeq
,
char
*
dbName
,
char
*
buffer
,
int64_t
insertRows
,
int64_t
startTime
,
uint64_t
*
pRemainderBufLen
);
int32_t
generateStbProgressiveData
(
SSuperTable
*
stbInfo
,
char
*
tableName
,
int64_t
tableSeq
,
char
*
dbName
,
char
*
buffer
,
int64_t
insertRows
,
uint64_t
recordFrom
,
int64_t
startTime
,
int64_t
*
pSamplePos
,
int64_t
*
pRemainderBufLen
);
int32_t
generateProgressiveDataWithoutStb
(
char
*
tableName
,
threadInfo
*
pThreadInfo
,
char
*
buffer
,
int64_t
insertRows
,
uint64_t
recordFrom
,
int64_t
startTime
,
int64_t
*
pRemainderBufLen
);
int64_t
generateStbRowData
(
SSuperTable
*
stbInfo
,
char
*
recBuf
,
int64_t
remainderBufLen
,
int64_t
timestamp
);
int
prepareSampleForStb
(
SSuperTable
*
stbInfo
);
int
prepareSampleForNtb
();
int
parseSamplefileToStmtBatch
(
SSuperTable
*
stbInfo
);
int
parseStbSampleToStmtBatchForThread
(
threadInfo
*
pThreadInfo
,
SSuperTable
*
stbInfo
,
uint32_t
timePrec
,
uint32_t
batch
);
int
parseNtbSampleToStmtBatchForThread
(
threadInfo
*
pThreadInfo
,
uint32_t
timePrec
,
uint32_t
batch
);
int
prepareSampleData
();
int32_t
generateSmlConstPart
(
char
*
sml
,
SSuperTable
*
stbInfo
,
threadInfo
*
pThreadInfo
,
int
tbSeq
);
int32_t
generateSmlMutablePart
(
char
*
line
,
char
*
sml
,
SSuperTable
*
stbInfo
,
threadInfo
*
pThreadInfo
,
int64_t
timestamp
);
int32_t
generateSmlJsonTags
(
cJSON
*
tagsList
,
SSuperTable
*
stbInfo
,
threadInfo
*
pThreadInfo
,
int
tbSeq
);
int32_t
generateSmlJsonCols
(
cJSON
*
array
,
cJSON
*
tag
,
SSuperTable
*
stbInfo
,
threadInfo
*
pThreadInfo
,
int64_t
timestamp
);
#endif
#endif
\ No newline at end of file
src/kit/taosdemo/insert.json
浏览文件 @
aafd7e1d
...
@@ -21,7 +21,7 @@
...
@@ -21,7 +21,7 @@
"cache"
:
16
,
"cache"
:
16
,
"blocks"
:
8
,
"blocks"
:
8
,
"precision"
:
"ms"
,
"precision"
:
"ms"
,
"keep"
:
365
,
"keep"
:
365
00
,
"minRows"
:
100
,
"minRows"
:
100
,
"maxRows"
:
4096
,
"maxRows"
:
4096
,
"comp"
:
2
,
"comp"
:
2
,
...
...
src/kit/taosdemo/src/demoCommandOpt.c
浏览文件 @
aafd7e1d
...
@@ -458,12 +458,12 @@ int parse_args(int argc, char *argv[]) {
...
@@ -458,12 +458,12 @@ int parse_args(int argc, char *argv[]) {
errorPrintReqArg2
(
argv
[
0
],
"S"
);
errorPrintReqArg2
(
argv
[
0
],
"S"
);
goto
end_parse_command
;
goto
end_parse_command
;
}
}
g_args
.
async_mode
=
atoi
(
argv
[
++
i
]);
g_args
.
timestamp_step
=
atoi
(
argv
[
++
i
]);
}
else
if
(
0
==
strncmp
(
argv
[
i
],
}
else
if
(
0
==
strncmp
(
argv
[
i
],
"--time-step="
,
strlen
(
"--time-step="
)))
{
"--time-step="
,
strlen
(
"--time-step="
)))
{
if
(
isStringNumber
(
if
(
isStringNumber
(
(
char
*
)(
argv
[
i
]
+
strlen
(
"--time-step="
))))
{
(
char
*
)(
argv
[
i
]
+
strlen
(
"--time-step="
))))
{
g_args
.
async_mode
=
g_args
.
timestamp_step
=
atoi
((
char
*
)(
argv
[
i
]
+
strlen
(
"--time-step="
)));
atoi
((
char
*
)(
argv
[
i
]
+
strlen
(
"--time-step="
)));
}
else
{
}
else
{
errorPrintReqArg2
(
argv
[
0
],
"--time-step"
);
errorPrintReqArg2
(
argv
[
0
],
"--time-step"
);
...
@@ -471,7 +471,8 @@ int parse_args(int argc, char *argv[]) {
...
@@ -471,7 +471,8 @@ int parse_args(int argc, char *argv[]) {
}
}
}
else
if
(
0
==
strncmp
(
argv
[
i
],
"-S"
,
strlen
(
"-S"
)))
{
}
else
if
(
0
==
strncmp
(
argv
[
i
],
"-S"
,
strlen
(
"-S"
)))
{
if
(
isStringNumber
((
char
*
)(
argv
[
i
]
+
strlen
(
"-S"
))))
{
if
(
isStringNumber
((
char
*
)(
argv
[
i
]
+
strlen
(
"-S"
))))
{
g_args
.
async_mode
=
atoi
((
char
*
)(
argv
[
i
]
+
strlen
(
"-S"
)));
g_args
.
timestamp_step
=
atoi
((
char
*
)(
argv
[
i
]
+
strlen
(
"-S"
)));
}
else
{
}
else
{
errorPrintReqArg2
(
argv
[
0
],
"-S"
);
errorPrintReqArg2
(
argv
[
0
],
"-S"
);
goto
end_parse_command
;
goto
end_parse_command
;
...
@@ -484,7 +485,7 @@ int parse_args(int argc, char *argv[]) {
...
@@ -484,7 +485,7 @@ int parse_args(int argc, char *argv[]) {
errorPrintReqArg2
(
argv
[
0
],
"--time-step"
);
errorPrintReqArg2
(
argv
[
0
],
"--time-step"
);
goto
end_parse_command
;
goto
end_parse_command
;
}
}
g_args
.
async_mode
=
atoi
(
argv
[
++
i
]);
g_args
.
timestamp_step
=
atoi
(
argv
[
++
i
]);
}
else
{
}
else
{
errorUnrecognized
(
argv
[
0
],
argv
[
i
]);
errorUnrecognized
(
argv
[
0
],
argv
[
i
]);
goto
end_parse_command
;
goto
end_parse_command
;
...
@@ -1142,11 +1143,9 @@ int parse_args(int argc, char *argv[]) {
...
@@ -1142,11 +1143,9 @@ int parse_args(int argc, char *argv[]) {
}
else
if
((
strcmp
(
argv
[
i
],
"--version"
)
==
0
)
||
}
else
if
((
strcmp
(
argv
[
i
],
"--version"
)
==
0
)
||
(
strcmp
(
argv
[
i
],
"-V"
)
==
0
))
{
(
strcmp
(
argv
[
i
],
"-V"
)
==
0
))
{
printVersion
();
printVersion
();
return
0
;
}
else
if
((
strcmp
(
argv
[
i
],
"--help"
)
==
0
)
||
}
else
if
((
strcmp
(
argv
[
i
],
"--help"
)
==
0
)
||
(
strcmp
(
argv
[
i
],
"-?"
)
==
0
))
{
(
strcmp
(
argv
[
i
],
"-?"
)
==
0
))
{
printHelp
();
printHelp
();
return
0
;
}
else
if
(
strcmp
(
argv
[
i
],
"--usage"
)
==
0
)
{
}
else
if
(
strcmp
(
argv
[
i
],
"--usage"
)
==
0
)
{
printf
(
printf
(
" Usage: taosdemo [-f JSONFILE] [-u USER] [-p PASSWORD] [-c CONFIG_DIR]
\n
\
" Usage: taosdemo [-f JSONFILE] [-u USER] [-p PASSWORD] [-c CONFIG_DIR]
\n
\
...
@@ -1156,7 +1155,7 @@ int parse_args(int argc, char *argv[]) {
...
@@ -1156,7 +1155,7 @@ int parse_args(int argc, char *argv[]) {
[-i SLEEPTIME] [-S TIME_STEP] [-B INTERLACE_ROWS] [-t TABLES]
\n
\
[-i SLEEPTIME] [-S TIME_STEP] [-B INTERLACE_ROWS] [-t TABLES]
\n
\
[-n RECORDS] [-M] [-x] [-y] [-O ORDERMODE] [-R RANGE] [-a REPLIcA][-g]
\n
\
[-n RECORDS] [-M] [-x] [-y] [-O ORDERMODE] [-R RANGE] [-a REPLIcA][-g]
\n
\
[--help] [--usage] [--version]
\n
"
);
[--help] [--usage] [--version]
\n
"
);
return
0
;
exit
(
EXIT_SUCCESS
)
;
}
else
{
}
else
{
// to simulate argp_option output
// to simulate argp_option output
if
(
strlen
(
argv
[
i
])
>
2
)
{
if
(
strlen
(
argv
[
i
])
>
2
)
{
...
@@ -1374,6 +1373,8 @@ void setParaFromArg() {
...
@@ -1374,6 +1373,8 @@ void setParaFromArg() {
}
else
{
}
else
{
g_Dbs
.
db
[
0
].
superTbls
[
0
].
iface
=
g_args
.
iface
;
g_Dbs
.
db
[
0
].
superTbls
[
0
].
iface
=
g_args
.
iface
;
}
}
g_Dbs
.
db
[
0
].
superTbls
[
0
].
lineProtocol
=
TSDB_SML_LINE_PROTOCOL
;
g_Dbs
.
db
[
0
].
superTbls
[
0
].
tsPrecision
=
TSDB_SML_TIMESTAMP_MILLI_SECONDS
;
tstrncpy
(
g_Dbs
.
db
[
0
].
superTbls
[
0
].
startTimestamp
,
tstrncpy
(
g_Dbs
.
db
[
0
].
superTbls
[
0
].
startTimestamp
,
"2017-07-14 10:40:00.000"
,
MAX_TB_NAME_SIZE
);
"2017-07-14 10:40:00.000"
,
MAX_TB_NAME_SIZE
);
g_Dbs
.
db
[
0
].
superTbls
[
0
].
timeStampStep
=
g_args
.
timestamp_step
;
g_Dbs
.
db
[
0
].
superTbls
[
0
].
timeStampStep
=
g_args
.
timestamp_step
;
...
...
src/kit/taosdemo/src/demoData.c
浏览文件 @
aafd7e1d
...
@@ -413,3 +413,2098 @@ int init_rand_data() {
...
@@ -413,3 +413,2098 @@ int init_rand_data() {
end_init_rand_data:
end_init_rand_data:
return
code
;
return
code
;
}
}
static
void
generateBinaryNCharTagValues
(
int64_t
tableSeq
,
uint32_t
len
,
char
*
buf
)
{
if
(
tableSeq
%
2
)
{
tstrncpy
(
buf
,
"beijing"
,
len
);
}
else
{
tstrncpy
(
buf
,
"shanghai"
,
len
);
}
// rand_string(buf, stbInfo->tags[i].dataLen);
}
int
generateTagValuesForStb
(
SSuperTable
*
stbInfo
,
int64_t
tableSeq
,
char
*
tagsValBuf
)
{
int
dataLen
=
0
;
dataLen
+=
snprintf
(
tagsValBuf
+
dataLen
,
TSDB_MAX_SQL_LEN
-
dataLen
,
"("
);
for
(
int
i
=
0
;
i
<
stbInfo
->
tagCount
;
i
++
)
{
if
((
0
==
strncasecmp
(
stbInfo
->
tags
[
i
].
dataType
,
"binary"
,
strlen
(
"binary"
)))
||
(
0
==
strncasecmp
(
stbInfo
->
tags
[
i
].
dataType
,
"nchar"
,
strlen
(
"nchar"
))))
{
if
(
stbInfo
->
tags
[
i
].
dataLen
>
TSDB_MAX_BINARY_LEN
)
{
errorPrint
(
"binary or nchar length overflow, max size:%u
\n
"
,
(
uint32_t
)
TSDB_MAX_BINARY_LEN
);
return
-
1
;
}
int32_t
tagBufLen
=
stbInfo
->
tags
[
i
].
dataLen
+
1
;
char
*
buf
=
(
char
*
)
calloc
(
1
,
tagBufLen
);
if
(
NULL
==
buf
)
{
errorPrint
(
"%s"
,
"failed to allocate memory
\n
"
);
return
-
1
;
}
generateBinaryNCharTagValues
(
tableSeq
,
tagBufLen
,
buf
);
dataLen
+=
snprintf
(
tagsValBuf
+
dataLen
,
TSDB_MAX_SQL_LEN
-
dataLen
,
"
\'
%s
\'
,"
,
buf
);
tmfree
(
buf
);
}
else
if
(
0
==
strncasecmp
(
stbInfo
->
tags
[
i
].
dataType
,
"int"
,
strlen
(
"int"
)))
{
if
((
g_args
.
demo_mode
)
&&
(
i
==
0
))
{
dataLen
+=
snprintf
(
tagsValBuf
+
dataLen
,
TSDB_MAX_SQL_LEN
-
dataLen
,
"%"
PRId64
","
,
(
tableSeq
%
10
)
+
1
);
}
else
{
dataLen
+=
snprintf
(
tagsValBuf
+
dataLen
,
TSDB_MAX_SQL_LEN
-
dataLen
,
"%"
PRId64
","
,
tableSeq
);
}
}
else
if
(
0
==
strncasecmp
(
stbInfo
->
tags
[
i
].
dataType
,
"bigint"
,
strlen
(
"bigint"
)))
{
dataLen
+=
snprintf
(
tagsValBuf
+
dataLen
,
TSDB_MAX_SQL_LEN
-
dataLen
,
"%"
PRId64
","
,
rand_bigint
());
}
else
if
(
0
==
strncasecmp
(
stbInfo
->
tags
[
i
].
dataType
,
"float"
,
strlen
(
"float"
)))
{
dataLen
+=
snprintf
(
tagsValBuf
+
dataLen
,
TSDB_MAX_SQL_LEN
-
dataLen
,
"%f,"
,
rand_float
());
}
else
if
(
0
==
strncasecmp
(
stbInfo
->
tags
[
i
].
dataType
,
"double"
,
strlen
(
"double"
)))
{
dataLen
+=
snprintf
(
tagsValBuf
+
dataLen
,
TSDB_MAX_SQL_LEN
-
dataLen
,
"%f,"
,
rand_double
());
}
else
if
(
0
==
strncasecmp
(
stbInfo
->
tags
[
i
].
dataType
,
"smallint"
,
strlen
(
"smallint"
)))
{
dataLen
+=
snprintf
(
tagsValBuf
+
dataLen
,
TSDB_MAX_SQL_LEN
-
dataLen
,
"%d,"
,
rand_smallint
());
}
else
if
(
0
==
strncasecmp
(
stbInfo
->
tags
[
i
].
dataType
,
"tinyint"
,
strlen
(
"tinyint"
)))
{
dataLen
+=
snprintf
(
tagsValBuf
+
dataLen
,
TSDB_MAX_SQL_LEN
-
dataLen
,
"%d,"
,
rand_tinyint
());
}
else
if
(
0
==
strncasecmp
(
stbInfo
->
tags
[
i
].
dataType
,
"bool"
,
strlen
(
"bool"
)))
{
dataLen
+=
snprintf
(
tagsValBuf
+
dataLen
,
TSDB_MAX_SQL_LEN
-
dataLen
,
"%d,"
,
rand_bool
());
}
else
if
(
0
==
strncasecmp
(
stbInfo
->
tags
[
i
].
dataType
,
"timestamp"
,
strlen
(
"timestamp"
)))
{
dataLen
+=
snprintf
(
tagsValBuf
+
dataLen
,
TSDB_MAX_SQL_LEN
-
dataLen
,
"%"
PRId64
","
,
rand_ubigint
());
}
else
if
(
0
==
strncasecmp
(
stbInfo
->
tags
[
i
].
dataType
,
"utinyint"
,
strlen
(
"utinyint"
)))
{
dataLen
+=
snprintf
(
tagsValBuf
+
dataLen
,
TSDB_MAX_SQL_LEN
-
dataLen
,
"%d,"
,
rand_utinyint
());
}
else
if
(
0
==
strncasecmp
(
stbInfo
->
tags
[
i
].
dataType
,
"usmallint"
,
strlen
(
"usmallint"
)))
{
dataLen
+=
snprintf
(
tagsValBuf
+
dataLen
,
TSDB_MAX_SQL_LEN
-
dataLen
,
"%d,"
,
rand_usmallint
());
}
else
if
(
0
==
strncasecmp
(
stbInfo
->
tags
[
i
].
dataType
,
"uint"
,
strlen
(
"uint"
)))
{
dataLen
+=
snprintf
(
tagsValBuf
+
dataLen
,
TSDB_MAX_SQL_LEN
-
dataLen
,
"%d,"
,
rand_uint
());
}
else
if
(
0
==
strncasecmp
(
stbInfo
->
tags
[
i
].
dataType
,
"ubigint"
,
strlen
(
"ubigint"
)))
{
dataLen
+=
snprintf
(
tagsValBuf
+
dataLen
,
TSDB_MAX_SQL_LEN
-
dataLen
,
"%"
PRId64
","
,
rand_ubigint
());
}
else
{
errorPrint
(
"unsupport data type: %s
\n
"
,
stbInfo
->
tags
[
i
].
dataType
);
return
-
1
;
}
}
dataLen
-=
1
;
dataLen
+=
snprintf
(
tagsValBuf
+
dataLen
,
TSDB_MAX_SQL_LEN
-
dataLen
,
")"
);
return
0
;
}
static
int
readTagFromCsvFileToMem
(
SSuperTable
*
stbInfo
)
{
size_t
n
=
0
;
ssize_t
readLen
=
0
;
char
*
line
=
NULL
;
FILE
*
fp
=
fopen
(
stbInfo
->
tagsFile
,
"r"
);
if
(
fp
==
NULL
)
{
printf
(
"Failed to open tags file: %s, reason:%s
\n
"
,
stbInfo
->
tagsFile
,
strerror
(
errno
));
return
-
1
;
}
if
(
stbInfo
->
tagDataBuf
)
{
free
(
stbInfo
->
tagDataBuf
);
stbInfo
->
tagDataBuf
=
NULL
;
}
int
tagCount
=
MAX_SAMPLES
;
int
count
=
0
;
char
*
tagDataBuf
=
calloc
(
1
,
stbInfo
->
lenOfTagOfOneRow
*
tagCount
);
if
(
tagDataBuf
==
NULL
)
{
printf
(
"Failed to calloc, reason:%s
\n
"
,
strerror
(
errno
));
fclose
(
fp
);
return
-
1
;
}
while
((
readLen
=
tgetline
(
&
line
,
&
n
,
fp
))
!=
-
1
)
{
if
((
'\r'
==
line
[
readLen
-
1
])
||
(
'\n'
==
line
[
readLen
-
1
]))
{
line
[
--
readLen
]
=
0
;
}
if
(
readLen
==
0
)
{
continue
;
}
memcpy
(
tagDataBuf
+
count
*
stbInfo
->
lenOfTagOfOneRow
,
line
,
readLen
);
count
++
;
if
(
count
>=
tagCount
-
1
)
{
char
*
tmp
=
realloc
(
tagDataBuf
,
(
size_t
)(
tagCount
*
1
.
5
*
stbInfo
->
lenOfTagOfOneRow
));
if
(
tmp
!=
NULL
)
{
tagDataBuf
=
tmp
;
tagCount
=
(
int
)(
tagCount
*
1
.
5
);
memset
(
tagDataBuf
+
count
*
stbInfo
->
lenOfTagOfOneRow
,
0
,
(
size_t
)((
tagCount
-
count
)
*
stbInfo
->
lenOfTagOfOneRow
));
}
else
{
// exit, if allocate more memory failed
printf
(
"realloc fail for save tag val from %s
\n
"
,
stbInfo
->
tagsFile
);
tmfree
(
tagDataBuf
);
free
(
line
);
fclose
(
fp
);
return
-
1
;
}
}
}
stbInfo
->
tagDataBuf
=
tagDataBuf
;
stbInfo
->
tagSampleCount
=
count
;
free
(
line
);
fclose
(
fp
);
return
0
;
}
static
void
getAndSetRowsFromCsvFile
(
SSuperTable
*
stbInfo
)
{
FILE
*
fp
=
fopen
(
stbInfo
->
sampleFile
,
"r"
);
int
line_count
=
0
;
if
(
fp
==
NULL
)
{
errorPrint
(
"Failed to open sample file: %s, reason:%s
\n
"
,
stbInfo
->
sampleFile
,
strerror
(
errno
));
return
;
}
char
*
buf
=
calloc
(
1
,
stbInfo
->
maxSqlLen
);
if
(
buf
==
NULL
)
{
errorPrint
(
"%s"
,
"failed to allocate memory
\n
"
);
return
;
}
while
(
fgets
(
buf
,
(
int
)
stbInfo
->
maxSqlLen
,
fp
))
{
line_count
++
;
}
fclose
(
fp
);
tmfree
(
buf
);
stbInfo
->
insertRows
=
line_count
;
}
static
int
generateSampleFromCsvForStb
(
SSuperTable
*
stbInfo
)
{
size_t
n
=
0
;
ssize_t
readLen
=
0
;
char
*
line
=
NULL
;
int
getRows
=
0
;
FILE
*
fp
=
fopen
(
stbInfo
->
sampleFile
,
"r"
);
if
(
fp
==
NULL
)
{
errorPrint
(
"Failed to open sample file: %s, reason:%s
\n
"
,
stbInfo
->
sampleFile
,
strerror
(
errno
));
return
-
1
;
}
while
(
1
)
{
readLen
=
tgetline
(
&
line
,
&
n
,
fp
);
if
(
-
1
==
readLen
)
{
if
(
0
!=
fseek
(
fp
,
0
,
SEEK_SET
))
{
errorPrint
(
"Failed to fseek file: %s, reason:%s
\n
"
,
stbInfo
->
sampleFile
,
strerror
(
errno
));
fclose
(
fp
);
return
-
1
;
}
continue
;
}
if
((
'\r'
==
line
[
readLen
-
1
])
||
(
'\n'
==
line
[
readLen
-
1
]))
{
line
[
--
readLen
]
=
0
;
}
if
(
readLen
==
0
)
{
continue
;
}
if
(
readLen
>
stbInfo
->
lenOfOneRow
)
{
printf
(
"sample row len[%d] overflow define schema len[%"
PRIu64
"], so discard this row
\n
"
,
(
int32_t
)
readLen
,
stbInfo
->
lenOfOneRow
);
continue
;
}
memcpy
(
stbInfo
->
sampleDataBuf
+
getRows
*
stbInfo
->
lenOfOneRow
,
line
,
readLen
);
getRows
++
;
if
(
getRows
==
MAX_SAMPLES
)
{
break
;
}
}
fclose
(
fp
);
tmfree
(
line
);
return
0
;
}
int
prepareSampleData
()
{
for
(
int
i
=
0
;
i
<
g_Dbs
.
dbCount
;
i
++
)
{
for
(
int
j
=
0
;
j
<
g_Dbs
.
db
[
i
].
superTblCount
;
j
++
)
{
if
(
g_Dbs
.
db
[
i
].
superTbls
[
j
].
tagsFile
[
0
]
!=
0
)
{
if
(
readTagFromCsvFileToMem
(
&
g_Dbs
.
db
[
i
].
superTbls
[
j
])
!=
0
)
{
return
-
1
;
}
}
}
}
return
0
;
}
static
int
getRowDataFromSample
(
char
*
dataBuf
,
int64_t
maxLen
,
int64_t
timestamp
,
SSuperTable
*
stbInfo
,
int64_t
*
sampleUsePos
)
{
if
((
*
sampleUsePos
)
==
MAX_SAMPLES
)
{
*
sampleUsePos
=
0
;
}
int
dataLen
=
0
;
if
(
stbInfo
->
useSampleTs
)
{
dataLen
+=
snprintf
(
dataBuf
+
dataLen
,
maxLen
-
dataLen
,
"(%s"
,
stbInfo
->
sampleDataBuf
+
stbInfo
->
lenOfOneRow
*
(
*
sampleUsePos
));
}
else
{
dataLen
+=
snprintf
(
dataBuf
+
dataLen
,
maxLen
-
dataLen
,
"(%"
PRId64
", "
,
timestamp
);
dataLen
+=
snprintf
(
dataBuf
+
dataLen
,
maxLen
-
dataLen
,
"%s"
,
stbInfo
->
sampleDataBuf
+
stbInfo
->
lenOfOneRow
*
(
*
sampleUsePos
));
}
dataLen
+=
snprintf
(
dataBuf
+
dataLen
,
maxLen
-
dataLen
,
")"
);
(
*
sampleUsePos
)
++
;
return
dataLen
;
}
int64_t
generateStbRowData
(
SSuperTable
*
stbInfo
,
char
*
recBuf
,
int64_t
remainderBufLen
,
int64_t
timestamp
)
{
int64_t
dataLen
=
0
;
char
*
pstr
=
recBuf
;
int64_t
maxLen
=
MAX_DATA_SIZE
;
int
tmpLen
;
dataLen
+=
snprintf
(
pstr
+
dataLen
,
maxLen
-
dataLen
,
"(%"
PRId64
""
,
timestamp
);
for
(
int
i
=
0
;
i
<
stbInfo
->
columnCount
;
i
++
)
{
tstrncpy
(
pstr
+
dataLen
,
","
,
2
);
dataLen
+=
1
;
if
((
stbInfo
->
columns
[
i
].
data_type
==
TSDB_DATA_TYPE_BINARY
)
||
(
stbInfo
->
columns
[
i
].
data_type
==
TSDB_DATA_TYPE_NCHAR
))
{
if
(
stbInfo
->
columns
[
i
].
dataLen
>
TSDB_MAX_BINARY_LEN
)
{
errorPrint
(
"binary or nchar length overflow, max size:%u
\n
"
,
(
uint32_t
)
TSDB_MAX_BINARY_LEN
);
return
-
1
;
}
if
((
stbInfo
->
columns
[
i
].
dataLen
+
1
)
>
/* need count 3 extra chars \', \', and , */
(
remainderBufLen
-
dataLen
-
3
))
{
return
0
;
}
char
*
buf
=
(
char
*
)
calloc
(
stbInfo
->
columns
[
i
].
dataLen
+
1
,
1
);
if
(
NULL
==
buf
)
{
errorPrint
(
"%s"
,
"failed to allocate memory
\n
"
);
return
-
1
;
}
rand_string
(
buf
,
stbInfo
->
columns
[
i
].
dataLen
);
dataLen
+=
snprintf
(
pstr
+
dataLen
,
maxLen
-
dataLen
,
"
\'
%s
\'
"
,
buf
);
tmfree
(
buf
);
}
else
{
char
*
tmp
=
NULL
;
switch
(
stbInfo
->
columns
[
i
].
data_type
)
{
case
TSDB_DATA_TYPE_INT
:
if
((
g_args
.
demo_mode
)
&&
(
i
==
1
))
{
tmp
=
demo_voltage_int_str
();
}
else
{
tmp
=
rand_int_str
();
}
tmpLen
=
(
int
)
strlen
(
tmp
);
tstrncpy
(
pstr
+
dataLen
,
tmp
,
min
(
tmpLen
+
1
,
INT_BUFF_LEN
));
break
;
case
TSDB_DATA_TYPE_UINT
:
tmp
=
rand_uint_str
();
tmpLen
=
(
int
)
strlen
(
tmp
);
tstrncpy
(
pstr
+
dataLen
,
tmp
,
min
(
tmpLen
+
1
,
INT_BUFF_LEN
));
break
;
case
TSDB_DATA_TYPE_BIGINT
:
tmp
=
rand_bigint_str
();
tmpLen
=
(
int
)
strlen
(
tmp
);
tstrncpy
(
pstr
+
dataLen
,
tmp
,
min
(
tmpLen
+
1
,
BIGINT_BUFF_LEN
));
break
;
case
TSDB_DATA_TYPE_UBIGINT
:
tmp
=
rand_ubigint_str
();
tmpLen
=
(
int
)
strlen
(
tmp
);
tstrncpy
(
pstr
+
dataLen
,
tmp
,
min
(
tmpLen
+
1
,
BIGINT_BUFF_LEN
));
break
;
case
TSDB_DATA_TYPE_FLOAT
:
if
(
g_args
.
demo_mode
)
{
if
(
i
==
0
)
{
tmp
=
demo_current_float_str
();
}
else
{
tmp
=
demo_phase_float_str
();
}
}
else
{
tmp
=
rand_float_str
();
}
tmpLen
=
(
int
)
strlen
(
tmp
);
tstrncpy
(
pstr
+
dataLen
,
tmp
,
min
(
tmpLen
+
1
,
FLOAT_BUFF_LEN
));
break
;
case
TSDB_DATA_TYPE_DOUBLE
:
tmp
=
rand_double_str
();
tmpLen
=
(
int
)
strlen
(
tmp
);
tstrncpy
(
pstr
+
dataLen
,
tmp
,
min
(
tmpLen
+
1
,
DOUBLE_BUFF_LEN
));
break
;
case
TSDB_DATA_TYPE_SMALLINT
:
tmp
=
rand_smallint_str
();
tmpLen
=
(
int
)
strlen
(
tmp
);
tstrncpy
(
pstr
+
dataLen
,
tmp
,
min
(
tmpLen
+
1
,
SMALLINT_BUFF_LEN
));
break
;
case
TSDB_DATA_TYPE_USMALLINT
:
tmp
=
rand_usmallint_str
();
tmpLen
=
(
int
)
strlen
(
tmp
);
tstrncpy
(
pstr
+
dataLen
,
tmp
,
min
(
tmpLen
+
1
,
SMALLINT_BUFF_LEN
));
break
;
case
TSDB_DATA_TYPE_TINYINT
:
tmp
=
rand_tinyint_str
();
tmpLen
=
(
int
)
strlen
(
tmp
);
tstrncpy
(
pstr
+
dataLen
,
tmp
,
min
(
tmpLen
+
1
,
TINYINT_BUFF_LEN
));
break
;
case
TSDB_DATA_TYPE_UTINYINT
:
tmp
=
rand_utinyint_str
();
tmpLen
=
(
int
)
strlen
(
tmp
);
tstrncpy
(
pstr
+
dataLen
,
tmp
,
min
(
tmpLen
+
1
,
TINYINT_BUFF_LEN
));
break
;
case
TSDB_DATA_TYPE_BOOL
:
tmp
=
rand_bool_str
();
tmpLen
=
(
int
)
strlen
(
tmp
);
tstrncpy
(
pstr
+
dataLen
,
tmp
,
min
(
tmpLen
+
1
,
BOOL_BUFF_LEN
));
break
;
case
TSDB_DATA_TYPE_TIMESTAMP
:
tmp
=
rand_bigint_str
();
tmpLen
=
(
int
)
strlen
(
tmp
);
tstrncpy
(
pstr
+
dataLen
,
tmp
,
min
(
tmpLen
+
1
,
BIGINT_BUFF_LEN
));
break
;
case
TSDB_DATA_TYPE_NULL
:
break
;
default:
errorPrint
(
"Not support data type: %s
\n
"
,
stbInfo
->
columns
[
i
].
dataType
);
exit
(
EXIT_FAILURE
);
}
if
(
tmp
)
{
dataLen
+=
tmpLen
;
}
}
if
(
dataLen
>
(
remainderBufLen
-
(
128
)))
return
0
;
}
dataLen
+=
snprintf
(
pstr
+
dataLen
,
2
,
")"
);
verbosePrint
(
"%s() LN%d, dataLen:%"
PRId64
"
\n
"
,
__func__
,
__LINE__
,
dataLen
);
verbosePrint
(
"%s() LN%d, recBuf:
\n\t
%s
\n
"
,
__func__
,
__LINE__
,
recBuf
);
return
strlen
(
recBuf
);
}
static
int64_t
generateData
(
char
*
recBuf
,
char
*
data_type
,
int64_t
timestamp
,
int
lenOfBinary
)
{
memset
(
recBuf
,
0
,
MAX_DATA_SIZE
);
char
*
pstr
=
recBuf
;
pstr
+=
sprintf
(
pstr
,
"(%"
PRId64
""
,
timestamp
);
int
columnCount
=
g_args
.
columnCount
;
bool
b
;
char
*
s
;
for
(
int
i
=
0
;
i
<
columnCount
;
i
++
)
{
switch
(
data_type
[
i
])
{
case
TSDB_DATA_TYPE_TINYINT
:
pstr
+=
sprintf
(
pstr
,
",%d"
,
rand_tinyint
());
break
;
case
TSDB_DATA_TYPE_SMALLINT
:
pstr
+=
sprintf
(
pstr
,
",%d"
,
rand_smallint
());
break
;
case
TSDB_DATA_TYPE_INT
:
pstr
+=
sprintf
(
pstr
,
",%d"
,
rand_int
());
break
;
case
TSDB_DATA_TYPE_BIGINT
:
pstr
+=
sprintf
(
pstr
,
",%"
PRId64
""
,
rand_bigint
());
break
;
case
TSDB_DATA_TYPE_TIMESTAMP
:
pstr
+=
sprintf
(
pstr
,
",%"
PRId64
""
,
rand_bigint
());
break
;
case
TSDB_DATA_TYPE_FLOAT
:
pstr
+=
sprintf
(
pstr
,
",%10.4f"
,
rand_float
());
break
;
case
TSDB_DATA_TYPE_DOUBLE
:
pstr
+=
sprintf
(
pstr
,
",%20.8f"
,
rand_double
());
break
;
case
TSDB_DATA_TYPE_BOOL
:
b
=
rand_bool
()
&
1
;
pstr
+=
sprintf
(
pstr
,
",%s"
,
b
?
"true"
:
"false"
);
break
;
case
TSDB_DATA_TYPE_BINARY
:
case
TSDB_DATA_TYPE_NCHAR
:
s
=
calloc
(
1
,
lenOfBinary
+
1
);
if
(
NULL
==
s
)
{
errorPrint
(
"%s"
,
"failed to allocate memory
\n
"
);
return
-
1
;
}
rand_string
(
s
,
lenOfBinary
);
pstr
+=
sprintf
(
pstr
,
",
\"
%s
\"
"
,
s
);
free
(
s
);
break
;
case
TSDB_DATA_TYPE_UTINYINT
:
pstr
+=
sprintf
(
pstr
,
",%d"
,
rand_utinyint
());
break
;
case
TSDB_DATA_TYPE_USMALLINT
:
pstr
+=
sprintf
(
pstr
,
",%d"
,
rand_usmallint
());
break
;
case
TSDB_DATA_TYPE_UINT
:
pstr
+=
sprintf
(
pstr
,
",%d"
,
rand_uint
());
break
;
case
TSDB_DATA_TYPE_UBIGINT
:
pstr
+=
sprintf
(
pstr
,
",%"
PRId64
""
,
rand_ubigint
());
break
;
case
TSDB_DATA_TYPE_NULL
:
break
;
default:
errorPrint
(
"Unknown data type %d
\n
"
,
data_type
[
i
]);
return
-
1
;
}
if
(
strlen
(
recBuf
)
>
MAX_DATA_SIZE
)
{
errorPrint
(
"%s"
,
"column length too long, abort
\n
"
);
return
-
1
;
}
}
pstr
+=
sprintf
(
pstr
,
")"
);
verbosePrint
(
"%s() LN%d, recBuf:
\n\t
%s
\n
"
,
__func__
,
__LINE__
,
recBuf
);
return
(
int32_t
)
strlen
(
recBuf
);
}
static
int
generateSampleFromRand
(
char
*
sampleDataBuf
,
uint64_t
lenOfOneRow
,
int
columnCount
,
StrColumn
*
columns
)
{
char
data
[
MAX_DATA_SIZE
];
memset
(
data
,
0
,
MAX_DATA_SIZE
);
char
*
buff
=
calloc
(
lenOfOneRow
,
1
);
if
(
NULL
==
buff
)
{
errorPrint
(
"%s"
,
"failed to allocate memory
\n
"
);
return
-
1
;
}
for
(
int
i
=
0
;
i
<
MAX_SAMPLES
;
i
++
)
{
uint64_t
pos
=
0
;
memset
(
buff
,
0
,
lenOfOneRow
);
for
(
int
c
=
0
;
c
<
columnCount
;
c
++
)
{
char
*
tmp
=
NULL
;
uint32_t
dataLen
;
char
data_type
=
(
columns
)
?
(
columns
[
c
].
data_type
)
:
g_args
.
data_type
[
c
];
switch
(
data_type
)
{
case
TSDB_DATA_TYPE_BINARY
:
dataLen
=
(
columns
)
?
columns
[
c
].
dataLen
:
g_args
.
binwidth
;
rand_string
(
data
,
dataLen
);
pos
+=
sprintf
(
buff
+
pos
,
"%s,"
,
data
);
break
;
case
TSDB_DATA_TYPE_NCHAR
:
dataLen
=
(
columns
)
?
columns
[
c
].
dataLen
:
g_args
.
binwidth
;
rand_string
(
data
,
dataLen
-
1
);
pos
+=
sprintf
(
buff
+
pos
,
"%s,"
,
data
);
break
;
case
TSDB_DATA_TYPE_INT
:
if
((
g_args
.
demo_mode
)
&&
(
c
==
1
))
{
tmp
=
demo_voltage_int_str
();
}
else
{
tmp
=
rand_int_str
();
}
pos
+=
sprintf
(
buff
+
pos
,
"%s,"
,
tmp
);
break
;
case
TSDB_DATA_TYPE_UINT
:
pos
+=
sprintf
(
buff
+
pos
,
"%s,"
,
rand_uint_str
());
break
;
case
TSDB_DATA_TYPE_BIGINT
:
pos
+=
sprintf
(
buff
+
pos
,
"%s,"
,
rand_bigint_str
());
break
;
case
TSDB_DATA_TYPE_UBIGINT
:
pos
+=
sprintf
(
buff
+
pos
,
"%s,"
,
rand_ubigint_str
());
break
;
case
TSDB_DATA_TYPE_FLOAT
:
if
(
g_args
.
demo_mode
)
{
if
(
c
==
0
)
{
tmp
=
demo_current_float_str
();
}
else
{
tmp
=
demo_phase_float_str
();
}
}
else
{
tmp
=
rand_float_str
();
}
pos
+=
sprintf
(
buff
+
pos
,
"%s,"
,
tmp
);
break
;
case
TSDB_DATA_TYPE_DOUBLE
:
pos
+=
sprintf
(
buff
+
pos
,
"%s,"
,
rand_double_str
());
break
;
case
TSDB_DATA_TYPE_SMALLINT
:
pos
+=
sprintf
(
buff
+
pos
,
"%s,"
,
rand_smallint_str
());
break
;
case
TSDB_DATA_TYPE_USMALLINT
:
pos
+=
sprintf
(
buff
+
pos
,
"%s,"
,
rand_usmallint_str
());
break
;
case
TSDB_DATA_TYPE_TINYINT
:
pos
+=
sprintf
(
buff
+
pos
,
"%s,"
,
rand_tinyint_str
());
break
;
case
TSDB_DATA_TYPE_UTINYINT
:
pos
+=
sprintf
(
buff
+
pos
,
"%s,"
,
rand_utinyint_str
());
break
;
case
TSDB_DATA_TYPE_BOOL
:
pos
+=
sprintf
(
buff
+
pos
,
"%s,"
,
rand_bool_str
());
break
;
case
TSDB_DATA_TYPE_TIMESTAMP
:
pos
+=
sprintf
(
buff
+
pos
,
"%s,"
,
rand_bigint_str
());
break
;
case
TSDB_DATA_TYPE_NULL
:
break
;
default:
errorPrint
(
"%s() LN%d, Unknown data type %s
\n
"
,
__func__
,
__LINE__
,
(
columns
)
?
(
columns
[
c
].
dataType
)
:
g_args
.
dataType
[
c
]);
exit
(
EXIT_FAILURE
);
}
}
*
(
buff
+
pos
-
1
)
=
0
;
memcpy
(
sampleDataBuf
+
i
*
lenOfOneRow
,
buff
,
pos
);
}
free
(
buff
);
return
0
;
}
static
int
generateSampleFromRandForNtb
()
{
return
generateSampleFromRand
(
g_sampleDataBuf
,
g_args
.
lenOfOneRow
,
g_args
.
columnCount
,
NULL
);
}
static
int
generateSampleFromRandForStb
(
SSuperTable
*
stbInfo
)
{
return
generateSampleFromRand
(
stbInfo
->
sampleDataBuf
,
stbInfo
->
lenOfOneRow
,
stbInfo
->
columnCount
,
stbInfo
->
columns
);
}
int
prepareSampleForNtb
()
{
g_sampleDataBuf
=
calloc
(
g_args
.
lenOfOneRow
*
MAX_SAMPLES
,
1
);
if
(
NULL
==
g_sampleDataBuf
)
{
errorPrint
(
"%s"
,
"failed to allocate memory
\n
"
);
return
-
1
;
}
return
generateSampleFromRandForNtb
();
}
int
prepareSampleForStb
(
SSuperTable
*
stbInfo
)
{
stbInfo
->
sampleDataBuf
=
calloc
(
stbInfo
->
lenOfOneRow
*
MAX_SAMPLES
,
1
);
if
(
NULL
==
stbInfo
->
sampleDataBuf
)
{
errorPrint
(
"%s"
,
"failed to allocate memory
\n
"
);
return
-
1
;
}
int
ret
;
if
(
0
==
strncasecmp
(
stbInfo
->
dataSource
,
"sample"
,
strlen
(
"sample"
)))
{
if
(
stbInfo
->
useSampleTs
)
{
getAndSetRowsFromCsvFile
(
stbInfo
);
}
ret
=
generateSampleFromCsvForStb
(
stbInfo
);
}
else
{
ret
=
generateSampleFromRandForStb
(
stbInfo
);
}
if
(
0
!=
ret
)
{
errorPrint
(
"read sample from %s file failed.
\n
"
,
stbInfo
->
sampleFile
);
tmfree
(
stbInfo
->
sampleDataBuf
);
stbInfo
->
sampleDataBuf
=
NULL
;
return
-
1
;
}
return
0
;
}
int64_t
getTSRandTail
(
int64_t
timeStampStep
,
int32_t
seq
,
int
disorderRatio
,
int
disorderRange
)
{
int64_t
randTail
=
timeStampStep
*
seq
;
if
(
disorderRatio
>
0
)
{
int
rand_num
=
taosRandom
()
%
100
;
if
(
rand_num
<
disorderRatio
)
{
randTail
=
(
randTail
+
(
taosRandom
()
%
disorderRange
+
1
))
*
(
-
1
);
debugPrint
(
"rand data generated, back %"
PRId64
"
\n
"
,
randTail
);
}
}
return
randTail
;
}
static
int32_t
generateDataTailWithoutStb
(
uint32_t
batch
,
char
*
buffer
,
int64_t
remainderBufLen
,
int64_t
insertRows
,
uint64_t
recordFrom
,
int64_t
startTime
,
/* int64_t *pSamplePos, */
int64_t
*
dataLen
)
{
uint64_t
len
=
0
;
char
*
pstr
=
buffer
;
verbosePrint
(
"%s() LN%d batch=%d
\n
"
,
__func__
,
__LINE__
,
batch
);
int32_t
k
=
0
;
for
(
k
=
0
;
k
<
batch
;)
{
char
*
data
=
pstr
;
memset
(
data
,
0
,
MAX_DATA_SIZE
);
int64_t
retLen
=
0
;
char
*
data_type
=
g_args
.
data_type
;
int
lenOfBinary
=
g_args
.
binwidth
;
if
(
g_args
.
disorderRatio
)
{
retLen
=
generateData
(
data
,
data_type
,
startTime
+
getTSRandTail
(
g_args
.
timestamp_step
,
k
,
g_args
.
disorderRatio
,
g_args
.
disorderRange
),
lenOfBinary
);
}
else
{
retLen
=
generateData
(
data
,
data_type
,
startTime
+
g_args
.
timestamp_step
*
k
,
lenOfBinary
);
}
if
(
len
>
remainderBufLen
)
break
;
pstr
+=
retLen
;
k
++
;
len
+=
retLen
;
remainderBufLen
-=
retLen
;
verbosePrint
(
"%s() LN%d len=%"
PRIu64
" k=%d
\n
buffer=%s
\n
"
,
__func__
,
__LINE__
,
len
,
k
,
buffer
);
recordFrom
++
;
if
(
recordFrom
>=
insertRows
)
{
break
;
}
}
*
dataLen
=
len
;
return
k
;
}
static
int32_t
generateStbDataTail
(
SSuperTable
*
stbInfo
,
uint32_t
batch
,
char
*
buffer
,
int64_t
remainderBufLen
,
int64_t
insertRows
,
uint64_t
recordFrom
,
int64_t
startTime
,
int64_t
*
pSamplePos
,
int64_t
*
dataLen
)
{
uint64_t
len
=
0
;
char
*
pstr
=
buffer
;
bool
tsRand
;
if
(
0
==
strncasecmp
(
stbInfo
->
dataSource
,
"rand"
,
strlen
(
"rand"
)))
{
tsRand
=
true
;
}
else
{
tsRand
=
false
;
}
verbosePrint
(
"%s() LN%d batch=%u buflen=%"
PRId64
"
\n
"
,
__func__
,
__LINE__
,
batch
,
remainderBufLen
);
int32_t
k
;
for
(
k
=
0
;
k
<
batch
;)
{
char
*
data
=
pstr
;
int64_t
lenOfRow
=
0
;
if
(
tsRand
)
{
if
(
stbInfo
->
disorderRatio
>
0
)
{
lenOfRow
=
generateStbRowData
(
stbInfo
,
data
,
remainderBufLen
,
startTime
+
getTSRandTail
(
stbInfo
->
timeStampStep
,
k
,
stbInfo
->
disorderRatio
,
stbInfo
->
disorderRange
));
}
else
{
lenOfRow
=
generateStbRowData
(
stbInfo
,
data
,
remainderBufLen
,
startTime
+
stbInfo
->
timeStampStep
*
k
);
}
}
else
{
lenOfRow
=
getRowDataFromSample
(
data
,
(
remainderBufLen
<
MAX_DATA_SIZE
)
?
remainderBufLen
:
MAX_DATA_SIZE
,
startTime
+
stbInfo
->
timeStampStep
*
k
,
stbInfo
,
pSamplePos
);
}
if
(
lenOfRow
==
0
)
{
data
[
0
]
=
'\0'
;
break
;
}
if
((
lenOfRow
+
1
)
>
remainderBufLen
)
{
break
;
}
pstr
+=
lenOfRow
;
k
++
;
len
+=
lenOfRow
;
remainderBufLen
-=
lenOfRow
;
verbosePrint
(
"%s() LN%d len=%"
PRIu64
" k=%u
\n
buffer=%s
\n
"
,
__func__
,
__LINE__
,
len
,
k
,
buffer
);
recordFrom
++
;
if
(
recordFrom
>=
insertRows
)
{
break
;
}
}
*
dataLen
=
len
;
return
k
;
}
static
int
generateSQLHeadWithoutStb
(
char
*
tableName
,
char
*
dbName
,
char
*
buffer
,
int
remainderBufLen
)
{
int
len
;
char
headBuf
[
HEAD_BUFF_LEN
];
len
=
snprintf
(
headBuf
,
HEAD_BUFF_LEN
,
"%s.%s values"
,
dbName
,
tableName
);
if
(
len
>
remainderBufLen
)
return
-
1
;
tstrncpy
(
buffer
,
headBuf
,
len
+
1
);
return
len
;
}
static
int
generateStbSQLHead
(
SSuperTable
*
stbInfo
,
char
*
tableName
,
int64_t
tableSeq
,
char
*
dbName
,
char
*
buffer
,
int
remainderBufLen
)
{
int
len
;
char
headBuf
[
HEAD_BUFF_LEN
];
if
(
AUTO_CREATE_SUBTBL
==
stbInfo
->
autoCreateTable
)
{
char
*
tagsValBuf
=
(
char
*
)
calloc
(
TSDB_MAX_SQL_LEN
+
1
,
1
);
if
(
NULL
==
tagsValBuf
)
{
errorPrint
(
"%s"
,
"failed to allocate memory
\n
"
);
return
-
1
;
}
if
(
0
==
stbInfo
->
tagSource
)
{
if
(
generateTagValuesForStb
(
stbInfo
,
tableSeq
,
tagsValBuf
))
{
tmfree
(
tagsValBuf
);
return
-
1
;
}
}
else
{
snprintf
(
tagsValBuf
,
TSDB_MAX_SQL_LEN
,
"(%s)"
,
stbInfo
->
tagDataBuf
+
stbInfo
->
lenOfTagOfOneRow
*
(
tableSeq
%
stbInfo
->
tagSampleCount
));
}
len
=
snprintf
(
headBuf
,
HEAD_BUFF_LEN
,
"%s.%s using %s.%s TAGS%s values"
,
dbName
,
tableName
,
dbName
,
stbInfo
->
stbName
,
tagsValBuf
);
tmfree
(
tagsValBuf
);
}
else
if
(
TBL_ALREADY_EXISTS
==
stbInfo
->
childTblExists
)
{
len
=
snprintf
(
headBuf
,
HEAD_BUFF_LEN
,
"%s.%s values"
,
dbName
,
tableName
);
}
else
{
len
=
snprintf
(
headBuf
,
HEAD_BUFF_LEN
,
"%s.%s values"
,
dbName
,
tableName
);
}
if
(
len
>
remainderBufLen
)
return
-
1
;
tstrncpy
(
buffer
,
headBuf
,
len
+
1
);
return
len
;
}
int32_t
generateStbInterlaceData
(
threadInfo
*
pThreadInfo
,
char
*
tableName
,
uint32_t
batchPerTbl
,
uint64_t
i
,
uint32_t
batchPerTblTimes
,
uint64_t
tableSeq
,
char
*
buffer
,
int64_t
insertRows
,
int64_t
startTime
,
uint64_t
*
pRemainderBufLen
)
{
char
*
pstr
=
buffer
;
SSuperTable
*
stbInfo
=
pThreadInfo
->
stbInfo
;
int
headLen
=
generateStbSQLHead
(
stbInfo
,
tableName
,
tableSeq
,
pThreadInfo
->
db_name
,
pstr
,
(
int
)(
*
pRemainderBufLen
));
if
(
headLen
<=
0
)
{
return
0
;
}
// generate data buffer
verbosePrint
(
"[%d] %s() LN%d i=%"
PRIu64
" buffer:
\n
%s
\n
"
,
pThreadInfo
->
threadID
,
__func__
,
__LINE__
,
i
,
buffer
);
pstr
+=
headLen
;
*
pRemainderBufLen
-=
headLen
;
int64_t
dataLen
=
0
;
verbosePrint
(
"[%d] %s() LN%d i=%"
PRIu64
" batchPerTblTimes=%u batchPerTbl = %u
\n
"
,
pThreadInfo
->
threadID
,
__func__
,
__LINE__
,
i
,
batchPerTblTimes
,
batchPerTbl
);
if
(
0
==
strncasecmp
(
stbInfo
->
startTimestamp
,
"now"
,
3
))
{
startTime
=
taosGetTimestamp
(
pThreadInfo
->
time_precision
);
}
int32_t
k
=
generateStbDataTail
(
stbInfo
,
batchPerTbl
,
pstr
,
*
pRemainderBufLen
,
insertRows
,
0
,
startTime
,
&
(
pThreadInfo
->
samplePos
),
&
dataLen
);
if
(
k
==
batchPerTbl
)
{
pstr
+=
dataLen
;
*
pRemainderBufLen
-=
dataLen
;
}
else
{
debugPrint
(
"%s() LN%d, generated data tail: %u, not equal batch per table: "
"%u
\n
"
,
__func__
,
__LINE__
,
k
,
batchPerTbl
);
pstr
-=
headLen
;
pstr
[
0
]
=
'\0'
;
k
=
0
;
}
return
k
;
}
int64_t
generateInterlaceDataWithoutStb
(
char
*
tableName
,
uint32_t
batch
,
uint64_t
tableSeq
,
char
*
dbName
,
char
*
buffer
,
int64_t
insertRows
,
int64_t
startTime
,
uint64_t
*
pRemainderBufLen
)
{
char
*
pstr
=
buffer
;
int
headLen
=
generateSQLHeadWithoutStb
(
tableName
,
dbName
,
pstr
,
(
int
)(
*
pRemainderBufLen
));
if
(
headLen
<=
0
)
{
return
0
;
}
pstr
+=
headLen
;
*
pRemainderBufLen
-=
headLen
;
int64_t
dataLen
=
0
;
int32_t
k
=
generateDataTailWithoutStb
(
batch
,
pstr
,
*
pRemainderBufLen
,
insertRows
,
0
,
startTime
,
&
dataLen
);
if
(
k
==
batch
)
{
pstr
+=
dataLen
;
*
pRemainderBufLen
-=
dataLen
;
}
else
{
debugPrint
(
"%s() LN%d, generated data tail: %d, not equal batch per table: "
"%u
\n
"
,
__func__
,
__LINE__
,
k
,
batch
);
pstr
-=
headLen
;
pstr
[
0
]
=
'\0'
;
k
=
0
;
}
return
k
;
}
static
int32_t
prepareStmtBindArrayByType
(
TAOS_BIND
*
bind
,
char
data_type
,
int32_t
dataLen
,
int32_t
timePrec
,
char
*
value
)
{
int32_t
*
bind_int
;
uint32_t
*
bind_uint
;
int64_t
*
bind_bigint
;
uint64_t
*
bind_ubigint
;
float
*
bind_float
;
double
*
bind_double
;
int8_t
*
bind_bool
;
int64_t
*
bind_ts2
;
int16_t
*
bind_smallint
;
uint16_t
*
bind_usmallint
;
int8_t
*
bind_tinyint
;
uint8_t
*
bind_utinyint
;
switch
(
data_type
)
{
case
TSDB_DATA_TYPE_BINARY
:
if
(
dataLen
>
TSDB_MAX_BINARY_LEN
)
{
errorPrint
(
"binary length overflow, max size:%u
\n
"
,
(
uint32_t
)
TSDB_MAX_BINARY_LEN
);
return
-
1
;
}
char
*
bind_binary
;
bind
->
buffer_type
=
TSDB_DATA_TYPE_BINARY
;
if
(
value
)
{
bind_binary
=
calloc
(
1
,
strlen
(
value
)
+
1
);
strncpy
(
bind_binary
,
value
,
strlen
(
value
));
bind
->
buffer_length
=
strlen
(
bind_binary
);
}
else
{
bind_binary
=
calloc
(
1
,
dataLen
+
1
);
rand_string
(
bind_binary
,
dataLen
);
bind
->
buffer_length
=
dataLen
;
}
bind
->
length
=
&
bind
->
buffer_length
;
bind
->
buffer
=
bind_binary
;
bind
->
is_null
=
NULL
;
break
;
case
TSDB_DATA_TYPE_NCHAR
:
if
(
dataLen
>
TSDB_MAX_BINARY_LEN
)
{
errorPrint
(
"nchar length overflow, max size:%u
\n
"
,
(
uint32_t
)
TSDB_MAX_BINARY_LEN
);
return
-
1
;
}
char
*
bind_nchar
;
bind
->
buffer_type
=
TSDB_DATA_TYPE_NCHAR
;
if
(
value
)
{
bind_nchar
=
calloc
(
1
,
strlen
(
value
)
+
1
);
strncpy
(
bind_nchar
,
value
,
strlen
(
value
));
}
else
{
bind_nchar
=
calloc
(
1
,
dataLen
+
1
);
rand_string
(
bind_nchar
,
dataLen
);
}
bind
->
buffer_length
=
strlen
(
bind_nchar
);
bind
->
buffer
=
bind_nchar
;
bind
->
length
=
&
bind
->
buffer_length
;
bind
->
is_null
=
NULL
;
break
;
case
TSDB_DATA_TYPE_INT
:
bind_int
=
calloc
(
1
,
sizeof
(
int32_t
));
if
(
value
)
{
*
bind_int
=
atoi
(
value
);
}
else
{
*
bind_int
=
rand_int
();
}
bind
->
buffer_type
=
TSDB_DATA_TYPE_INT
;
bind
->
buffer_length
=
sizeof
(
int32_t
);
bind
->
buffer
=
bind_int
;
bind
->
length
=
&
bind
->
buffer_length
;
bind
->
is_null
=
NULL
;
break
;
case
TSDB_DATA_TYPE_UINT
:
bind_uint
=
malloc
(
sizeof
(
uint32_t
));
if
(
value
)
{
*
bind_uint
=
atoi
(
value
);
}
else
{
*
bind_uint
=
rand_int
();
}
bind
->
buffer_type
=
TSDB_DATA_TYPE_UINT
;
bind
->
buffer_length
=
sizeof
(
uint32_t
);
bind
->
buffer
=
bind_uint
;
bind
->
length
=
&
bind
->
buffer_length
;
bind
->
is_null
=
NULL
;
break
;
case
TSDB_DATA_TYPE_BIGINT
:
bind_bigint
=
malloc
(
sizeof
(
int64_t
));
if
(
value
)
{
*
bind_bigint
=
atoll
(
value
);
}
else
{
*
bind_bigint
=
rand_bigint
();
}
bind
->
buffer_type
=
TSDB_DATA_TYPE_BIGINT
;
bind
->
buffer_length
=
sizeof
(
int64_t
);
bind
->
buffer
=
bind_bigint
;
bind
->
length
=
&
bind
->
buffer_length
;
bind
->
is_null
=
NULL
;
break
;
case
TSDB_DATA_TYPE_UBIGINT
:
bind_ubigint
=
malloc
(
sizeof
(
uint64_t
));
if
(
value
)
{
*
bind_ubigint
=
atoll
(
value
);
}
else
{
*
bind_ubigint
=
rand_bigint
();
}
bind
->
buffer_type
=
TSDB_DATA_TYPE_UBIGINT
;
bind
->
buffer_length
=
sizeof
(
uint64_t
);
bind
->
buffer
=
bind_ubigint
;
bind
->
length
=
&
bind
->
buffer_length
;
bind
->
is_null
=
NULL
;
break
;
case
TSDB_DATA_TYPE_FLOAT
:
bind_float
=
malloc
(
sizeof
(
float
));
if
(
value
)
{
*
bind_float
=
(
float
)
atof
(
value
);
}
else
{
*
bind_float
=
rand_float
();
}
bind
->
buffer_type
=
TSDB_DATA_TYPE_FLOAT
;
bind
->
buffer_length
=
sizeof
(
float
);
bind
->
buffer
=
bind_float
;
bind
->
length
=
&
bind
->
buffer_length
;
bind
->
is_null
=
NULL
;
break
;
case
TSDB_DATA_TYPE_DOUBLE
:
bind_double
=
malloc
(
sizeof
(
double
));
if
(
value
)
{
*
bind_double
=
atof
(
value
);
}
else
{
*
bind_double
=
rand_double
();
}
bind
->
buffer_type
=
TSDB_DATA_TYPE_DOUBLE
;
bind
->
buffer_length
=
sizeof
(
double
);
bind
->
buffer
=
bind_double
;
bind
->
length
=
&
bind
->
buffer_length
;
bind
->
is_null
=
NULL
;
break
;
case
TSDB_DATA_TYPE_SMALLINT
:
bind_smallint
=
malloc
(
sizeof
(
int16_t
));
if
(
value
)
{
*
bind_smallint
=
(
int16_t
)
atoi
(
value
);
}
else
{
*
bind_smallint
=
rand_smallint
();
}
bind
->
buffer_type
=
TSDB_DATA_TYPE_SMALLINT
;
bind
->
buffer_length
=
sizeof
(
int16_t
);
bind
->
buffer
=
bind_smallint
;
bind
->
length
=
&
bind
->
buffer_length
;
bind
->
is_null
=
NULL
;
break
;
case
TSDB_DATA_TYPE_USMALLINT
:
bind_usmallint
=
malloc
(
sizeof
(
uint16_t
));
if
(
value
)
{
*
bind_usmallint
=
(
uint16_t
)
atoi
(
value
);
}
else
{
*
bind_usmallint
=
rand_smallint
();
}
bind
->
buffer_type
=
TSDB_DATA_TYPE_SMALLINT
;
bind
->
buffer_length
=
sizeof
(
uint16_t
);
bind
->
buffer
=
bind_usmallint
;
bind
->
length
=
&
bind
->
buffer_length
;
bind
->
is_null
=
NULL
;
break
;
case
TSDB_DATA_TYPE_TINYINT
:
bind_tinyint
=
malloc
(
sizeof
(
int8_t
));
if
(
value
)
{
*
bind_tinyint
=
(
int8_t
)
atoi
(
value
);
}
else
{
*
bind_tinyint
=
rand_tinyint
();
}
bind
->
buffer_type
=
TSDB_DATA_TYPE_TINYINT
;
bind
->
buffer_length
=
sizeof
(
int8_t
);
bind
->
buffer
=
bind_tinyint
;
bind
->
length
=
&
bind
->
buffer_length
;
bind
->
is_null
=
NULL
;
break
;
case
TSDB_DATA_TYPE_UTINYINT
:
bind_utinyint
=
malloc
(
sizeof
(
uint8_t
));
if
(
value
)
{
*
bind_utinyint
=
(
int8_t
)
atoi
(
value
);
}
else
{
*
bind_utinyint
=
rand_tinyint
();
}
bind
->
buffer_type
=
TSDB_DATA_TYPE_UTINYINT
;
bind
->
buffer_length
=
sizeof
(
uint8_t
);
bind
->
buffer
=
bind_utinyint
;
bind
->
length
=
&
bind
->
buffer_length
;
bind
->
is_null
=
NULL
;
break
;
case
TSDB_DATA_TYPE_BOOL
:
bind_bool
=
malloc
(
sizeof
(
int8_t
));
if
(
value
)
{
if
(
strncasecmp
(
value
,
"true"
,
4
))
{
*
bind_bool
=
true
;
}
else
{
*
bind_bool
=
false
;
}
}
else
{
*
bind_bool
=
rand_bool
();
}
bind
->
buffer_type
=
TSDB_DATA_TYPE_BOOL
;
bind
->
buffer_length
=
sizeof
(
int8_t
);
bind
->
buffer
=
bind_bool
;
bind
->
length
=
&
bind
->
buffer_length
;
bind
->
is_null
=
NULL
;
break
;
case
TSDB_DATA_TYPE_TIMESTAMP
:
bind_ts2
=
malloc
(
sizeof
(
int64_t
));
if
(
value
)
{
if
(
strchr
(
value
,
':'
)
&&
strchr
(
value
,
'-'
))
{
int
i
=
0
;
while
(
value
[
i
]
!=
'\0'
)
{
if
(
value
[
i
]
==
'\"'
||
value
[
i
]
==
'\''
)
{
value
[
i
]
=
' '
;
}
i
++
;
}
int64_t
tmpEpoch
;
if
(
TSDB_CODE_SUCCESS
!=
taosParseTime
(
value
,
&
tmpEpoch
,
(
int32_t
)
strlen
(
value
),
timePrec
,
0
))
{
free
(
bind_ts2
);
errorPrint
(
"Input %s, time format error!
\n
"
,
value
);
return
-
1
;
}
*
bind_ts2
=
tmpEpoch
;
}
else
{
*
bind_ts2
=
atoll
(
value
);
}
}
else
{
*
bind_ts2
=
rand_bigint
();
}
bind
->
buffer_type
=
TSDB_DATA_TYPE_TIMESTAMP
;
bind
->
buffer_length
=
sizeof
(
int64_t
);
bind
->
buffer
=
bind_ts2
;
bind
->
length
=
&
bind
->
buffer_length
;
bind
->
is_null
=
NULL
;
break
;
case
TSDB_DATA_TYPE_NULL
:
break
;
default:
errorPrint
(
"Not support data type: %d
\n
"
,
data_type
);
return
-
1
;
}
return
0
;
}
int32_t
prepareStmtWithoutStb
(
threadInfo
*
pThreadInfo
,
char
*
tableName
,
uint32_t
batch
,
int64_t
insertRows
,
int64_t
recordFrom
,
int64_t
startTime
)
{
TAOS_STMT
*
stmt
=
pThreadInfo
->
stmt
;
int
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_stmt_errstr
(
stmt
));
return
ret
;
}
char
*
data_type
=
g_args
.
data_type
;
char
*
bindArray
=
malloc
(
sizeof
(
TAOS_BIND
)
*
(
g_args
.
columnCount
+
1
));
if
(
bindArray
==
NULL
)
{
errorPrint
(
"Failed to allocate %d bind params
\n
"
,
(
g_args
.
columnCount
+
1
));
return
-
1
;
}
int32_t
k
=
0
;
for
(
k
=
0
;
k
<
batch
;)
{
/* columnCount + 1 (ts) */
TAOS_BIND
*
bind
=
(
TAOS_BIND
*
)(
bindArray
+
0
);
int64_t
*
bind_ts
=
pThreadInfo
->
bind_ts
;
bind
->
buffer_type
=
TSDB_DATA_TYPE_TIMESTAMP
;
if
(
g_args
.
disorderRatio
)
{
*
bind_ts
=
startTime
+
getTSRandTail
(
g_args
.
timestamp_step
,
k
,
g_args
.
disorderRatio
,
g_args
.
disorderRange
);
}
else
{
*
bind_ts
=
startTime
+
g_args
.
timestamp_step
*
k
;
}
bind
->
buffer_length
=
sizeof
(
int64_t
);
bind
->
buffer
=
bind_ts
;
bind
->
length
=
&
bind
->
buffer_length
;
bind
->
is_null
=
NULL
;
for
(
int
i
=
0
;
i
<
g_args
.
columnCount
;
i
++
)
{
bind
=
(
TAOS_BIND
*
)((
char
*
)
bindArray
+
(
sizeof
(
TAOS_BIND
)
*
(
i
+
1
)));
if
(
-
1
==
prepareStmtBindArrayByType
(
bind
,
data_type
[
i
],
g_args
.
binwidth
,
pThreadInfo
->
time_precision
,
NULL
))
{
free
(
bindArray
);
return
-
1
;
}
}
if
(
taos_stmt_bind_param
(
stmt
,
(
TAOS_BIND
*
)
bindArray
))
{
errorPrint
(
"taos_stmt_bind_param() failed! reason: %s
\n
"
,
taos_stmt_errstr
(
stmt
));
break
;
}
// if msg > 3MB, break
if
(
taos_stmt_add_batch
(
stmt
))
{
errorPrint
(
"taos_stmt_add_batch() failed! reason: %s
\n
"
,
taos_stmt_errstr
(
stmt
));
break
;
}
k
++
;
recordFrom
++
;
if
(
recordFrom
>=
insertRows
)
{
break
;
}
}
free
(
bindArray
);
return
k
;
}
int32_t
prepareStbStmtBindTag
(
char
*
bindArray
,
SSuperTable
*
stbInfo
,
char
*
tagsVal
,
int32_t
timePrec
)
{
TAOS_BIND
*
tag
;
for
(
int
t
=
0
;
t
<
stbInfo
->
tagCount
;
t
++
)
{
tag
=
(
TAOS_BIND
*
)((
char
*
)
bindArray
+
(
sizeof
(
TAOS_BIND
)
*
t
));
if
(
prepareStmtBindArrayByType
(
tag
,
stbInfo
->
tags
[
t
].
data_type
,
stbInfo
->
tags
[
t
].
dataLen
,
timePrec
,
NULL
))
{
return
-
1
;
}
}
return
0
;
}
int
parseSamplefileToStmtBatch
(
SSuperTable
*
stbInfo
)
{
int32_t
columnCount
=
(
stbInfo
)
?
stbInfo
->
columnCount
:
g_args
.
columnCount
;
char
*
sampleBindBatchArray
=
NULL
;
if
(
stbInfo
)
{
stbInfo
->
sampleBindBatchArray
=
calloc
(
1
,
sizeof
(
uintptr_t
*
)
*
columnCount
);
sampleBindBatchArray
=
stbInfo
->
sampleBindBatchArray
;
}
else
{
g_sampleBindBatchArray
=
calloc
(
1
,
sizeof
(
uintptr_t
*
)
*
columnCount
);
sampleBindBatchArray
=
g_sampleBindBatchArray
;
}
for
(
int
c
=
0
;
c
<
columnCount
;
c
++
)
{
char
data_type
=
(
stbInfo
)
?
stbInfo
->
columns
[
c
].
data_type
:
g_args
.
data_type
[
c
];
char
*
tmpP
=
NULL
;
switch
(
data_type
)
{
case
TSDB_DATA_TYPE_INT
:
case
TSDB_DATA_TYPE_UINT
:
tmpP
=
calloc
(
1
,
sizeof
(
int32_t
)
*
MAX_SAMPLES
);
*
(
uintptr_t
*
)(
sampleBindBatchArray
+
sizeof
(
uintptr_t
*
)
*
c
)
=
(
uintptr_t
)
tmpP
;
break
;
case
TSDB_DATA_TYPE_TINYINT
:
case
TSDB_DATA_TYPE_UTINYINT
:
tmpP
=
calloc
(
1
,
sizeof
(
char
)
*
MAX_SAMPLES
);
*
(
uintptr_t
*
)(
sampleBindBatchArray
+
sizeof
(
uintptr_t
*
)
*
c
)
=
(
uintptr_t
)
tmpP
;
break
;
case
TSDB_DATA_TYPE_SMALLINT
:
case
TSDB_DATA_TYPE_USMALLINT
:
tmpP
=
calloc
(
1
,
sizeof
(
int16_t
)
*
MAX_SAMPLES
);
*
(
uintptr_t
*
)(
sampleBindBatchArray
+
sizeof
(
uintptr_t
*
)
*
c
)
=
(
uintptr_t
)
tmpP
;
break
;
case
TSDB_DATA_TYPE_BIGINT
:
case
TSDB_DATA_TYPE_UBIGINT
:
tmpP
=
calloc
(
1
,
sizeof
(
int64_t
)
*
MAX_SAMPLES
);
*
(
uintptr_t
*
)(
sampleBindBatchArray
+
sizeof
(
uintptr_t
*
)
*
c
)
=
(
uintptr_t
)
tmpP
;
break
;
case
TSDB_DATA_TYPE_BOOL
:
tmpP
=
calloc
(
1
,
sizeof
(
char
)
*
MAX_SAMPLES
);
*
(
uintptr_t
*
)(
sampleBindBatchArray
+
sizeof
(
uintptr_t
*
)
*
c
)
=
(
uintptr_t
)
tmpP
;
break
;
case
TSDB_DATA_TYPE_FLOAT
:
tmpP
=
calloc
(
1
,
sizeof
(
float
)
*
MAX_SAMPLES
);
*
(
uintptr_t
*
)(
sampleBindBatchArray
+
sizeof
(
uintptr_t
*
)
*
c
)
=
(
uintptr_t
)
tmpP
;
break
;
case
TSDB_DATA_TYPE_DOUBLE
:
tmpP
=
calloc
(
1
,
sizeof
(
double
)
*
MAX_SAMPLES
);
*
(
uintptr_t
*
)(
sampleBindBatchArray
+
sizeof
(
uintptr_t
*
)
*
c
)
=
(
uintptr_t
)
tmpP
;
break
;
case
TSDB_DATA_TYPE_BINARY
:
case
TSDB_DATA_TYPE_NCHAR
:
tmpP
=
calloc
(
1
,
MAX_SAMPLES
*
(((
stbInfo
)
?
stbInfo
->
columns
[
c
].
dataLen
:
g_args
.
binwidth
)
+
1
));
*
(
uintptr_t
*
)(
sampleBindBatchArray
+
sizeof
(
uintptr_t
*
)
*
c
)
=
(
uintptr_t
)
tmpP
;
break
;
case
TSDB_DATA_TYPE_TIMESTAMP
:
tmpP
=
calloc
(
1
,
sizeof
(
int64_t
)
*
MAX_SAMPLES
);
*
(
uintptr_t
*
)(
sampleBindBatchArray
+
sizeof
(
uintptr_t
*
)
*
c
)
=
(
uintptr_t
)
tmpP
;
break
;
default:
errorPrint
(
"Unknown data type: %s
\n
"
,
(
stbInfo
)
?
stbInfo
->
columns
[
c
].
dataType
:
g_args
.
dataType
[
c
]);
exit
(
EXIT_FAILURE
);
}
}
char
*
sampleDataBuf
=
(
stbInfo
)
?
stbInfo
->
sampleDataBuf
:
g_sampleDataBuf
;
int64_t
lenOfOneRow
=
(
stbInfo
)
?
stbInfo
->
lenOfOneRow
:
g_args
.
lenOfOneRow
;
for
(
int
i
=
0
;
i
<
MAX_SAMPLES
;
i
++
)
{
int
cursor
=
0
;
for
(
int
c
=
0
;
c
<
columnCount
;
c
++
)
{
char
data_type
=
(
stbInfo
)
?
stbInfo
->
columns
[
c
].
data_type
:
g_args
.
data_type
[
c
];
char
*
restStr
=
sampleDataBuf
+
lenOfOneRow
*
i
+
cursor
;
int
lengthOfRest
=
(
int
)
strlen
(
restStr
);
int
index
=
0
;
for
(
index
=
0
;
index
<
lengthOfRest
;
index
++
)
{
if
(
restStr
[
index
]
==
','
)
{
break
;
}
}
char
*
tmpStr
=
calloc
(
1
,
index
+
1
);
if
(
NULL
==
tmpStr
)
{
errorPrint
(
"%s"
,
"failed to allocate memory
\n
"
);
return
-
1
;
}
strncpy
(
tmpStr
,
restStr
,
index
);
cursor
+=
index
+
1
;
// skip ',' too
char
*
tmpP
;
switch
(
data_type
)
{
case
TSDB_DATA_TYPE_INT
:
case
TSDB_DATA_TYPE_UINT
:
*
((
int32_t
*
)((
uintptr_t
)
*
(
uintptr_t
*
)(
sampleBindBatchArray
+
sizeof
(
char
*
)
*
c
)
+
sizeof
(
int32_t
)
*
i
))
=
atoi
(
tmpStr
);
break
;
case
TSDB_DATA_TYPE_FLOAT
:
*
(
float
*
)(((
uintptr_t
)
*
(
uintptr_t
*
)(
sampleBindBatchArray
+
sizeof
(
char
*
)
*
c
)
+
sizeof
(
float
)
*
i
))
=
(
float
)
atof
(
tmpStr
);
break
;
case
TSDB_DATA_TYPE_DOUBLE
:
*
(
double
*
)(((
uintptr_t
)
*
(
uintptr_t
*
)(
sampleBindBatchArray
+
sizeof
(
char
*
)
*
c
)
+
sizeof
(
double
)
*
i
))
=
atof
(
tmpStr
);
break
;
case
TSDB_DATA_TYPE_TINYINT
:
case
TSDB_DATA_TYPE_UTINYINT
:
*
((
int8_t
*
)((
uintptr_t
)
*
(
uintptr_t
*
)(
sampleBindBatchArray
+
sizeof
(
char
*
)
*
c
)
+
sizeof
(
int8_t
)
*
i
))
=
(
int8_t
)
atoi
(
tmpStr
);
break
;
case
TSDB_DATA_TYPE_SMALLINT
:
case
TSDB_DATA_TYPE_USMALLINT
:
*
((
int16_t
*
)((
uintptr_t
)
*
(
uintptr_t
*
)(
sampleBindBatchArray
+
sizeof
(
char
*
)
*
c
)
+
sizeof
(
int16_t
)
*
i
))
=
(
int16_t
)
atoi
(
tmpStr
);
break
;
case
TSDB_DATA_TYPE_BIGINT
:
case
TSDB_DATA_TYPE_UBIGINT
:
*
((
int64_t
*
)((
uintptr_t
)
*
(
uintptr_t
*
)(
sampleBindBatchArray
+
sizeof
(
char
*
)
*
c
)
+
sizeof
(
int64_t
)
*
i
))
=
(
int64_t
)
atol
(
tmpStr
);
break
;
case
TSDB_DATA_TYPE_BOOL
:
*
((
int8_t
*
)((
uintptr_t
)
*
(
uintptr_t
*
)(
sampleBindBatchArray
+
sizeof
(
char
*
)
*
c
)
+
sizeof
(
int8_t
)
*
i
))
=
(
int8_t
)
atoi
(
tmpStr
);
break
;
case
TSDB_DATA_TYPE_TIMESTAMP
:
*
((
int64_t
*
)((
uintptr_t
)
*
(
uintptr_t
*
)(
sampleBindBatchArray
+
sizeof
(
char
*
)
*
c
)
+
sizeof
(
int64_t
)
*
i
))
=
(
int64_t
)
atol
(
tmpStr
);
break
;
case
TSDB_DATA_TYPE_BINARY
:
case
TSDB_DATA_TYPE_NCHAR
:
tmpP
=
(
char
*
)(
*
(
uintptr_t
*
)(
sampleBindBatchArray
+
sizeof
(
char
*
)
*
c
));
strcpy
(
tmpP
+
i
*
(((
stbInfo
)
?
stbInfo
->
columns
[
c
].
dataLen
:
g_args
.
binwidth
)),
tmpStr
);
break
;
default:
break
;
}
free
(
tmpStr
);
}
}
return
0
;
}
static
int
parseSampleToStmtBatchForThread
(
threadInfo
*
pThreadInfo
,
SSuperTable
*
stbInfo
,
uint32_t
timePrec
,
uint32_t
batch
)
{
uint32_t
columnCount
=
(
stbInfo
)
?
stbInfo
->
columnCount
:
g_args
.
columnCount
;
pThreadInfo
->
bind_ts_array
=
calloc
(
1
,
sizeof
(
int64_t
)
*
batch
);
if
(
NULL
==
pThreadInfo
->
bind_ts_array
)
{
errorPrint
(
"%s"
,
"failed to allocate memory
\n
"
);
return
-
1
;
}
pThreadInfo
->
bindParams
=
calloc
(
1
,
sizeof
(
TAOS_MULTI_BIND
)
*
(
columnCount
+
1
));
if
(
NULL
==
pThreadInfo
->
bindParams
)
{
errorPrint
(
"%s"
,
"failed to allocate memory
\n
"
);
return
-
1
;
}
pThreadInfo
->
is_null
=
calloc
(
1
,
batch
);
if
(
NULL
==
pThreadInfo
->
is_null
)
{
errorPrint
(
"%s"
,
"failed to allocate memory
\n
"
);
return
-
1
;
}
return
0
;
}
int
parseStbSampleToStmtBatchForThread
(
threadInfo
*
pThreadInfo
,
SSuperTable
*
stbInfo
,
uint32_t
timePrec
,
uint32_t
batch
)
{
return
parseSampleToStmtBatchForThread
(
pThreadInfo
,
stbInfo
,
timePrec
,
batch
);
}
int
parseNtbSampleToStmtBatchForThread
(
threadInfo
*
pThreadInfo
,
uint32_t
timePrec
,
uint32_t
batch
)
{
return
parseSampleToStmtBatchForThread
(
pThreadInfo
,
NULL
,
timePrec
,
batch
);
}
int32_t
generateStbProgressiveData
(
SSuperTable
*
stbInfo
,
char
*
tableName
,
int64_t
tableSeq
,
char
*
dbName
,
char
*
buffer
,
int64_t
insertRows
,
uint64_t
recordFrom
,
int64_t
startTime
,
int64_t
*
pSamplePos
,
int64_t
*
pRemainderBufLen
)
{
char
*
pstr
=
buffer
;
memset
(
pstr
,
0
,
*
pRemainderBufLen
);
int64_t
headLen
=
generateStbSQLHead
(
stbInfo
,
tableName
,
tableSeq
,
dbName
,
buffer
,
(
int
)(
*
pRemainderBufLen
));
if
(
headLen
<=
0
)
{
return
0
;
}
pstr
+=
headLen
;
*
pRemainderBufLen
-=
headLen
;
int64_t
dataLen
;
return
generateStbDataTail
(
stbInfo
,
g_args
.
reqPerReq
,
pstr
,
*
pRemainderBufLen
,
insertRows
,
recordFrom
,
startTime
,
pSamplePos
,
&
dataLen
);
}
int32_t
generateProgressiveDataWithoutStb
(
char
*
tableName
,
threadInfo
*
pThreadInfo
,
char
*
buffer
,
int64_t
insertRows
,
uint64_t
recordFrom
,
int64_t
startTime
,
int64_t
*
pRemainderBufLen
)
{
char
*
pstr
=
buffer
;
memset
(
buffer
,
0
,
*
pRemainderBufLen
);
int64_t
headLen
=
generateSQLHeadWithoutStb
(
tableName
,
pThreadInfo
->
db_name
,
buffer
,
(
int
)(
*
pRemainderBufLen
));
if
(
headLen
<=
0
)
{
return
0
;
}
pstr
+=
headLen
;
*
pRemainderBufLen
-=
headLen
;
int64_t
dataLen
;
return
generateDataTailWithoutStb
(
g_args
.
reqPerReq
,
pstr
,
*
pRemainderBufLen
,
insertRows
,
recordFrom
,
startTime
,
/*pSamplePos, */
&
dataLen
);
}
int32_t
generateSmlConstPart
(
char
*
sml
,
SSuperTable
*
stbInfo
,
threadInfo
*
pThreadInfo
,
int
tbSeq
)
{
int64_t
dataLen
=
0
;
uint64_t
length
=
stbInfo
->
lenOfOneRow
;
if
(
stbInfo
->
lineProtocol
==
TSDB_SML_LINE_PROTOCOL
)
{
dataLen
+=
snprintf
(
sml
+
dataLen
,
length
-
dataLen
,
"%s,id=%s%"
PRIu64
""
,
stbInfo
->
stbName
,
stbInfo
->
childTblPrefix
,
tbSeq
+
pThreadInfo
->
start_table_from
);
}
else
if
(
stbInfo
->
lineProtocol
==
TSDB_SML_TELNET_PROTOCOL
)
{
dataLen
+=
snprintf
(
sml
+
dataLen
,
length
-
dataLen
,
"id=%s%"
PRIu64
""
,
stbInfo
->
childTblPrefix
,
tbSeq
+
pThreadInfo
->
start_table_from
);
}
else
{
errorPrint
(
"unsupport schemaless protocol (%d)
\n
"
,
stbInfo
->
lineProtocol
);
return
-
1
;
}
for
(
int
j
=
0
;
j
<
stbInfo
->
tagCount
;
j
++
)
{
tstrncpy
(
sml
+
dataLen
,
(
stbInfo
->
lineProtocol
==
TSDB_SML_LINE_PROTOCOL
)
?
","
:
" "
,
2
);
dataLen
+=
1
;
switch
(
stbInfo
->
tags
[
j
].
data_type
)
{
case
TSDB_DATA_TYPE_TIMESTAMP
:
errorPrint
(
"Does not support data type %s as tag
\n
"
,
stbInfo
->
tags
[
j
].
dataType
);
return
-
1
;
case
TSDB_DATA_TYPE_BOOL
:
dataLen
+=
snprintf
(
sml
+
dataLen
,
length
-
dataLen
,
"t%d=%s"
,
j
,
rand_bool_str
());
break
;
case
TSDB_DATA_TYPE_TINYINT
:
dataLen
+=
snprintf
(
sml
+
dataLen
,
length
-
dataLen
,
"t%d=%s"
,
j
,
rand_tinyint_str
());
break
;
case
TSDB_DATA_TYPE_UTINYINT
:
dataLen
+=
snprintf
(
sml
+
dataLen
,
length
-
dataLen
,
"t%d=%s"
,
j
,
rand_utinyint_str
());
break
;
case
TSDB_DATA_TYPE_SMALLINT
:
dataLen
+=
snprintf
(
sml
+
dataLen
,
length
-
dataLen
,
"t%d=%s"
,
j
,
rand_smallint_str
());
break
;
case
TSDB_DATA_TYPE_USMALLINT
:
dataLen
+=
snprintf
(
sml
+
dataLen
,
length
-
dataLen
,
"t%d=%s"
,
j
,
rand_usmallint_str
());
break
;
case
TSDB_DATA_TYPE_INT
:
dataLen
+=
snprintf
(
sml
+
dataLen
,
length
-
dataLen
,
"t%d=%s"
,
j
,
rand_int_str
());
break
;
case
TSDB_DATA_TYPE_UINT
:
dataLen
+=
snprintf
(
sml
+
dataLen
,
length
-
dataLen
,
"t%d=%s"
,
j
,
rand_uint_str
());
break
;
case
TSDB_DATA_TYPE_BIGINT
:
dataLen
+=
snprintf
(
sml
+
dataLen
,
length
-
dataLen
,
"t%d=%s"
,
j
,
rand_bigint_str
());
break
;
case
TSDB_DATA_TYPE_UBIGINT
:
dataLen
+=
snprintf
(
sml
+
dataLen
,
length
-
dataLen
,
"t%d=%s"
,
j
,
rand_ubigint_str
());
break
;
case
TSDB_DATA_TYPE_FLOAT
:
dataLen
+=
snprintf
(
sml
+
dataLen
,
length
-
dataLen
,
"t%d=%s"
,
j
,
rand_float_str
());
break
;
case
TSDB_DATA_TYPE_DOUBLE
:
dataLen
+=
snprintf
(
sml
+
dataLen
,
length
-
dataLen
,
"t%d=%s"
,
j
,
rand_double_str
());
break
;
case
TSDB_DATA_TYPE_BINARY
:
case
TSDB_DATA_TYPE_NCHAR
:
if
(
stbInfo
->
tags
[
j
].
dataLen
>
TSDB_MAX_BINARY_LEN
)
{
errorPrint
(
"binary or nchar length overflow, maxsize:%u
\n
"
,
(
uint32_t
)
TSDB_MAX_BINARY_LEN
);
return
-
1
;
}
char
*
buf
=
(
char
*
)
calloc
(
stbInfo
->
tags
[
j
].
dataLen
+
1
,
1
);
if
(
NULL
==
buf
)
{
errorPrint
(
"%s"
,
"failed to allocate memory
\n
"
);
return
-
1
;
}
rand_string
(
buf
,
stbInfo
->
tags
[
j
].
dataLen
);
dataLen
+=
snprintf
(
sml
+
dataLen
,
length
-
dataLen
,
"t%d=%s"
,
j
,
buf
);
tmfree
(
buf
);
break
;
default:
errorPrint
(
"Unsupport data type %s
\n
"
,
stbInfo
->
tags
[
j
].
dataType
);
return
-
1
;
}
}
return
0
;
}
int32_t
generateSmlMutablePart
(
char
*
line
,
char
*
sml
,
SSuperTable
*
stbInfo
,
threadInfo
*
pThreadInfo
,
int64_t
timestamp
)
{
int
dataLen
=
0
;
uint64_t
buffer
=
stbInfo
->
lenOfOneRow
;
if
(
stbInfo
->
lineProtocol
==
TSDB_SML_LINE_PROTOCOL
)
{
dataLen
=
snprintf
(
line
,
buffer
,
"%s "
,
sml
);
for
(
uint32_t
c
=
0
;
c
<
stbInfo
->
columnCount
;
c
++
)
{
if
(
c
!=
0
)
{
tstrncpy
(
line
+
dataLen
,
","
,
2
);
dataLen
+=
1
;
}
switch
(
stbInfo
->
columns
[
c
].
data_type
)
{
case
TSDB_DATA_TYPE_TIMESTAMP
:
errorPrint
(
"Does not support data type %s as tag
\n
"
,
stbInfo
->
columns
[
c
].
dataType
);
return
-
1
;
case
TSDB_DATA_TYPE_BOOL
:
dataLen
+=
snprintf
(
line
+
dataLen
,
buffer
-
dataLen
,
"c%d=%s"
,
c
,
rand_bool_str
());
break
;
case
TSDB_DATA_TYPE_TINYINT
:
dataLen
+=
snprintf
(
line
+
dataLen
,
buffer
-
dataLen
,
"c%d=%si8"
,
c
,
rand_tinyint_str
());
break
;
case
TSDB_DATA_TYPE_UTINYINT
:
dataLen
+=
snprintf
(
line
+
dataLen
,
buffer
-
dataLen
,
"c%d=%su8"
,
c
,
rand_utinyint_str
());
break
;
case
TSDB_DATA_TYPE_SMALLINT
:
dataLen
+=
snprintf
(
line
+
dataLen
,
buffer
-
dataLen
,
"c%d=%si16"
,
c
,
rand_smallint_str
());
break
;
case
TSDB_DATA_TYPE_USMALLINT
:
dataLen
+=
snprintf
(
line
+
dataLen
,
buffer
-
dataLen
,
"c%d=%su16"
,
c
,
rand_usmallint_str
());
break
;
case
TSDB_DATA_TYPE_INT
:
dataLen
+=
snprintf
(
line
+
dataLen
,
buffer
-
dataLen
,
"c%d=%si32"
,
c
,
rand_int_str
());
break
;
case
TSDB_DATA_TYPE_UINT
:
dataLen
+=
snprintf
(
line
+
dataLen
,
buffer
-
dataLen
,
"c%d=%su32"
,
c
,
rand_uint_str
());
break
;
case
TSDB_DATA_TYPE_BIGINT
:
dataLen
+=
snprintf
(
line
+
dataLen
,
buffer
-
dataLen
,
"c%d=%si64"
,
c
,
rand_bigint_str
());
break
;
case
TSDB_DATA_TYPE_UBIGINT
:
dataLen
+=
snprintf
(
line
+
dataLen
,
buffer
-
dataLen
,
"c%d=%su64"
,
c
,
rand_ubigint_str
());
break
;
case
TSDB_DATA_TYPE_FLOAT
:
dataLen
+=
snprintf
(
line
+
dataLen
,
buffer
-
dataLen
,
"c%d=%sf32"
,
c
,
rand_float_str
());
break
;
case
TSDB_DATA_TYPE_DOUBLE
:
dataLen
+=
snprintf
(
line
+
dataLen
,
buffer
-
dataLen
,
"c%d=%sf64"
,
c
,
rand_double_str
());
break
;
case
TSDB_DATA_TYPE_BINARY
:
case
TSDB_DATA_TYPE_NCHAR
:
if
(
stbInfo
->
columns
[
c
].
dataLen
>
TSDB_MAX_BINARY_LEN
)
{
errorPrint
(
"binary or nchar length overflow, maxsize:%u
\n
"
,
(
uint32_t
)
TSDB_MAX_BINARY_LEN
);
return
-
1
;
}
char
*
buf
=
(
char
*
)
calloc
(
stbInfo
->
columns
[
c
].
dataLen
+
1
,
1
);
if
(
NULL
==
buf
)
{
errorPrint
(
"%s"
,
"failed to allocate memory
\n
"
);
return
-
1
;
}
rand_string
(
buf
,
stbInfo
->
columns
[
c
].
dataLen
);
if
(
stbInfo
->
columns
[
c
].
data_type
==
TSDB_DATA_TYPE_BINARY
)
{
dataLen
+=
snprintf
(
line
+
dataLen
,
buffer
-
dataLen
,
"c%d=
\"
%s
\"
"
,
c
,
buf
);
}
else
{
dataLen
+=
snprintf
(
line
+
dataLen
,
buffer
-
dataLen
,
"c%d=L
\"
%s
\"
"
,
c
,
buf
);
}
tmfree
(
buf
);
break
;
default:
errorPrint
(
"Unsupport data type %s
\n
"
,
stbInfo
->
columns
[
c
].
dataType
);
return
-
1
;
}
}
dataLen
+=
snprintf
(
line
+
dataLen
,
buffer
-
dataLen
,
" %"
PRId64
""
,
timestamp
);
return
0
;
}
else
if
(
stbInfo
->
lineProtocol
==
TSDB_SML_TELNET_PROTOCOL
)
{
switch
(
stbInfo
->
columns
[
0
].
data_type
)
{
case
TSDB_DATA_TYPE_BOOL
:
snprintf
(
line
,
buffer
,
"%s %"
PRId64
" %s %s"
,
stbInfo
->
stbName
,
timestamp
,
rand_bool_str
(),
sml
);
break
;
case
TSDB_DATA_TYPE_TINYINT
:
snprintf
(
line
,
buffer
,
"%s %"
PRId64
" %si8 %s"
,
stbInfo
->
stbName
,
timestamp
,
rand_tinyint_str
(),
sml
);
break
;
case
TSDB_DATA_TYPE_UTINYINT
:
snprintf
(
line
,
buffer
,
"%s %"
PRId64
" %su8 %s"
,
stbInfo
->
stbName
,
timestamp
,
rand_utinyint_str
(),
sml
);
break
;
case
TSDB_DATA_TYPE_SMALLINT
:
snprintf
(
line
,
buffer
,
"%s %"
PRId64
" %si16 %s"
,
stbInfo
->
stbName
,
timestamp
,
rand_smallint_str
(),
sml
);
break
;
case
TSDB_DATA_TYPE_USMALLINT
:
snprintf
(
line
,
buffer
,
"%s %"
PRId64
" %su16 %s"
,
stbInfo
->
stbName
,
timestamp
,
rand_usmallint_str
(),
sml
);
break
;
case
TSDB_DATA_TYPE_INT
:
snprintf
(
line
,
buffer
,
"%s %"
PRId64
" %si32 %s"
,
stbInfo
->
stbName
,
timestamp
,
rand_int_str
(),
sml
);
break
;
case
TSDB_DATA_TYPE_UINT
:
snprintf
(
line
,
buffer
,
"%s %"
PRId64
" %su32 %s"
,
stbInfo
->
stbName
,
timestamp
,
rand_uint_str
(),
sml
);
break
;
case
TSDB_DATA_TYPE_BIGINT
:
snprintf
(
line
,
buffer
,
"%s %"
PRId64
" %si64 %s"
,
stbInfo
->
stbName
,
timestamp
,
rand_bigint_str
(),
sml
);
break
;
case
TSDB_DATA_TYPE_UBIGINT
:
snprintf
(
line
,
buffer
,
"%s %"
PRId64
" %su64 %s"
,
stbInfo
->
stbName
,
timestamp
,
rand_ubigint_str
(),
sml
);
break
;
case
TSDB_DATA_TYPE_FLOAT
:
snprintf
(
line
,
buffer
,
"%s %"
PRId64
" %sf32 %s"
,
stbInfo
->
stbName
,
timestamp
,
rand_float_str
(),
sml
);
break
;
case
TSDB_DATA_TYPE_DOUBLE
:
snprintf
(
line
,
buffer
,
"%s %"
PRId64
" %sf64 %s"
,
stbInfo
->
stbName
,
timestamp
,
rand_double_str
(),
sml
);
break
;
case
TSDB_DATA_TYPE_BINARY
:
case
TSDB_DATA_TYPE_NCHAR
:
if
(
stbInfo
->
columns
[
0
].
dataLen
>
TSDB_MAX_BINARY_LEN
)
{
errorPrint
(
"binary or nchar length overflow, maxsize:%u
\n
"
,
(
uint32_t
)
TSDB_MAX_BINARY_LEN
);
return
-
1
;
}
char
*
buf
=
(
char
*
)
calloc
(
stbInfo
->
columns
[
0
].
dataLen
+
1
,
1
);
if
(
NULL
==
buf
)
{
errorPrint
(
"%s"
,
"failed to allocate memory
\n
"
);
return
-
1
;
}
rand_string
(
buf
,
stbInfo
->
columns
[
0
].
dataLen
);
if
(
stbInfo
->
columns
[
0
].
data_type
==
TSDB_DATA_TYPE_BINARY
)
{
snprintf
(
line
,
buffer
,
"%s %"
PRId64
"
\"
%s
\"
%s"
,
stbInfo
->
stbName
,
timestamp
,
buf
,
sml
);
}
else
{
snprintf
(
line
,
buffer
,
"%s %"
PRId64
" L
\"
%s
\"
%s"
,
stbInfo
->
stbName
,
timestamp
,
buf
,
sml
);
}
tmfree
(
buf
);
break
;
default:
errorPrint
(
"Unsupport data type %s
\n
"
,
stbInfo
->
columns
[
0
].
dataType
);
return
-
1
;
}
return
0
;
}
else
{
errorPrint
(
"unsupport schemaless protocol(%d)
\n
"
,
stbInfo
->
lineProtocol
);
return
-
1
;
}
}
int32_t
generateSmlJsonTags
(
cJSON
*
tagsList
,
SSuperTable
*
stbInfo
,
threadInfo
*
pThreadInfo
,
int
tbSeq
)
{
cJSON
*
tags
=
cJSON_CreateObject
();
char
*
tbName
=
calloc
(
1
,
TSDB_TABLE_NAME_LEN
);
assert
(
tbName
);
snprintf
(
tbName
,
TSDB_TABLE_NAME_LEN
,
"%s%"
PRIu64
""
,
stbInfo
->
childTblPrefix
,
tbSeq
+
pThreadInfo
->
start_table_from
);
cJSON_AddStringToObject
(
tags
,
"id"
,
tbName
);
char
*
tagName
=
calloc
(
1
,
TSDB_MAX_TAGS
);
assert
(
tagName
);
for
(
int
i
=
0
;
i
<
stbInfo
->
tagCount
;
i
++
)
{
cJSON
*
tag
=
cJSON_CreateObject
();
snprintf
(
tagName
,
TSDB_MAX_TAGS
,
"t%d"
,
i
);
switch
(
stbInfo
->
tags
[
i
].
data_type
)
{
case
TSDB_DATA_TYPE_BOOL
:
cJSON_AddNumberToObject
(
tag
,
"value"
,
rand_bool
());
cJSON_AddStringToObject
(
tag
,
"type"
,
"bool"
);
break
;
case
TSDB_DATA_TYPE_TINYINT
:
cJSON_AddNumberToObject
(
tag
,
"value"
,
rand_tinyint
());
cJSON_AddStringToObject
(
tag
,
"type"
,
"tinyint"
);
break
;
case
TSDB_DATA_TYPE_SMALLINT
:
cJSON_AddNumberToObject
(
tag
,
"value"
,
rand_smallint
());
cJSON_AddStringToObject
(
tag
,
"type"
,
"smallint"
);
break
;
case
TSDB_DATA_TYPE_INT
:
cJSON_AddNumberToObject
(
tag
,
"value"
,
rand_int
());
cJSON_AddStringToObject
(
tag
,
"type"
,
"int"
);
break
;
case
TSDB_DATA_TYPE_BIGINT
:
cJSON_AddNumberToObject
(
tag
,
"value"
,
rand_bigint
());
cJSON_AddStringToObject
(
tag
,
"type"
,
"bigint"
);
break
;
case
TSDB_DATA_TYPE_FLOAT
:
cJSON_AddNumberToObject
(
tag
,
"value"
,
rand_float
());
cJSON_AddStringToObject
(
tag
,
"type"
,
"float"
);
break
;
case
TSDB_DATA_TYPE_DOUBLE
:
cJSON_AddNumberToObject
(
tag
,
"value"
,
rand_double
());
cJSON_AddStringToObject
(
tag
,
"type"
,
"double"
);
break
;
case
TSDB_DATA_TYPE_BINARY
:
case
TSDB_DATA_TYPE_NCHAR
:
if
(
stbInfo
->
tags
[
i
].
dataLen
>
TSDB_MAX_BINARY_LEN
)
{
errorPrint
(
"binary or nchar length overflow, maxsize:%u
\n
"
,
(
uint32_t
)
TSDB_MAX_BINARY_LEN
);
return
-
1
;
}
char
*
buf
=
(
char
*
)
calloc
(
stbInfo
->
tags
[
i
].
dataLen
+
1
,
1
);
if
(
NULL
==
buf
)
{
errorPrint
(
"%s"
,
"failed to allocate memory
\n
"
);
return
-
1
;
}
rand_string
(
buf
,
stbInfo
->
tags
[
i
].
dataLen
);
if
(
stbInfo
->
tags
[
i
].
data_type
==
TSDB_DATA_TYPE_BINARY
)
{
cJSON_AddStringToObject
(
tag
,
"value"
,
buf
);
cJSON_AddStringToObject
(
tag
,
"type"
,
"binary"
);
}
else
{
cJSON_AddStringToObject
(
tag
,
"value"
,
buf
);
cJSON_AddStringToObject
(
tag
,
"type"
,
"nchar"
);
}
tmfree
(
buf
);
break
;
default:
errorPrint
(
"unsupport data type (%s) for schemaless json protocol
\n
"
,
stbInfo
->
tags
[
i
].
dataType
);
return
-
1
;
}
cJSON_AddItemToObject
(
tags
,
tagName
,
tag
);
}
cJSON_AddItemToArray
(
tagsList
,
tags
);
tmfree
(
tagName
);
tmfree
(
tbName
);
return
0
;
}
int32_t
generateSmlJsonCols
(
cJSON
*
array
,
cJSON
*
tag
,
SSuperTable
*
stbInfo
,
threadInfo
*
pThreadInfo
,
int64_t
timestamp
)
{
cJSON
*
record
=
cJSON_CreateObject
();
cJSON
*
ts
=
cJSON_CreateObject
();
cJSON_AddNumberToObject
(
ts
,
"value"
,
timestamp
);
if
(
pThreadInfo
->
time_precision
==
TSDB_TIME_PRECISION_MILLI
)
{
cJSON_AddStringToObject
(
ts
,
"type"
,
"ms"
);
}
else
if
(
pThreadInfo
->
time_precision
==
TSDB_TIME_PRECISION_MICRO
)
{
cJSON_AddStringToObject
(
ts
,
"type"
,
"us"
);
}
else
if
(
pThreadInfo
->
time_precision
==
TSDB_TIME_PRECISION_NANO
)
{
cJSON_AddStringToObject
(
ts
,
"type"
,
"ns"
);
}
else
{
errorPrint
(
"unsupport time precision %d
\n
"
,
pThreadInfo
->
time_precision
);
return
-
1
;
}
cJSON
*
value
=
cJSON_CreateObject
();
switch
(
stbInfo
->
columns
[
0
].
data_type
)
{
case
TSDB_DATA_TYPE_BOOL
:
cJSON_AddNumberToObject
(
value
,
"value"
,
rand_bool
());
cJSON_AddStringToObject
(
value
,
"type"
,
"bool"
);
break
;
case
TSDB_DATA_TYPE_TINYINT
:
cJSON_AddNumberToObject
(
value
,
"value"
,
rand_tinyint
());
cJSON_AddStringToObject
(
value
,
"type"
,
"tinyint"
);
break
;
case
TSDB_DATA_TYPE_SMALLINT
:
cJSON_AddNumberToObject
(
value
,
"value"
,
rand_smallint
());
cJSON_AddStringToObject
(
value
,
"type"
,
"smallint"
);
break
;
case
TSDB_DATA_TYPE_INT
:
cJSON_AddNumberToObject
(
value
,
"value"
,
rand_int
());
cJSON_AddStringToObject
(
value
,
"type"
,
"int"
);
break
;
case
TSDB_DATA_TYPE_BIGINT
:
cJSON_AddNumberToObject
(
value
,
"value"
,
rand_bigint
());
cJSON_AddStringToObject
(
value
,
"type"
,
"bigint"
);
break
;
case
TSDB_DATA_TYPE_FLOAT
:
cJSON_AddNumberToObject
(
value
,
"value"
,
rand_float
());
cJSON_AddStringToObject
(
value
,
"type"
,
"float"
);
break
;
case
TSDB_DATA_TYPE_DOUBLE
:
cJSON_AddNumberToObject
(
value
,
"value"
,
rand_double
());
cJSON_AddStringToObject
(
value
,
"type"
,
"double"
);
break
;
case
TSDB_DATA_TYPE_BINARY
:
case
TSDB_DATA_TYPE_NCHAR
:
if
(
stbInfo
->
columns
[
0
].
dataLen
>
TSDB_MAX_BINARY_LEN
)
{
errorPrint
(
"binary or nchar length overflow, maxsize:%u
\n
"
,
(
uint32_t
)
TSDB_MAX_BINARY_LEN
);
return
-
1
;
}
char
*
buf
=
(
char
*
)
calloc
(
stbInfo
->
columns
[
0
].
dataLen
+
1
,
1
);
if
(
NULL
==
buf
)
{
errorPrint
(
"%s"
,
"failed to allocate memory
\n
"
);
return
-
1
;
}
rand_string
(
buf
,
stbInfo
->
columns
[
0
].
dataLen
);
if
(
stbInfo
->
columns
[
0
].
data_type
==
TSDB_DATA_TYPE_BINARY
)
{
cJSON_AddStringToObject
(
value
,
"value"
,
buf
);
cJSON_AddStringToObject
(
value
,
"type"
,
"binary"
);
}
else
{
cJSON_AddStringToObject
(
value
,
"value"
,
buf
);
cJSON_AddStringToObject
(
value
,
"type"
,
"nchar"
);
}
break
;
default:
errorPrint
(
"unsupport data type (%s) for schemaless json protocol
\n
"
,
stbInfo
->
columns
[
0
].
dataType
);
return
-
1
;
}
cJSON_AddItemToObject
(
record
,
"timestamp"
,
ts
);
cJSON_AddItemToObject
(
record
,
"value"
,
value
);
cJSON_AddItemToObject
(
record
,
"tags"
,
tag
);
cJSON_AddStringToObject
(
record
,
"metric"
,
stbInfo
->
stbName
);
cJSON_AddItemToArray
(
array
,
record
);
return
0
;
}
src/kit/taosdemo/src/demoInsert.c
浏览文件 @
aafd7e1d
...
@@ -13,119 +13,10 @@
...
@@ -13,119 +13,10 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
*/
#include "cJSON.h"
#include "demo.h"
#include "demo.h"
#include "demoData.h"
#include "demoData.h"
static
void
generateBinaryNCharTagValues
(
int64_t
tableSeq
,
uint32_t
len
,
char
*
buf
)
{
if
(
tableSeq
%
2
)
{
tstrncpy
(
buf
,
"beijing"
,
len
);
}
else
{
tstrncpy
(
buf
,
"shanghai"
,
len
);
}
// rand_string(buf, stbInfo->tags[i].dataLen);
}
static
int
generateTagValuesForStb
(
SSuperTable
*
stbInfo
,
int64_t
tableSeq
,
char
*
tagsValBuf
)
{
int
dataLen
=
0
;
dataLen
+=
snprintf
(
tagsValBuf
+
dataLen
,
TSDB_MAX_SQL_LEN
-
dataLen
,
"("
);
for
(
int
i
=
0
;
i
<
stbInfo
->
tagCount
;
i
++
)
{
if
((
0
==
strncasecmp
(
stbInfo
->
tags
[
i
].
dataType
,
"binary"
,
strlen
(
"binary"
)))
||
(
0
==
strncasecmp
(
stbInfo
->
tags
[
i
].
dataType
,
"nchar"
,
strlen
(
"nchar"
))))
{
if
(
stbInfo
->
tags
[
i
].
dataLen
>
TSDB_MAX_BINARY_LEN
)
{
errorPrint
(
"binary or nchar length overflow, max size:%u
\n
"
,
(
uint32_t
)
TSDB_MAX_BINARY_LEN
);
return
-
1
;
}
int32_t
tagBufLen
=
stbInfo
->
tags
[
i
].
dataLen
+
1
;
char
*
buf
=
(
char
*
)
calloc
(
1
,
tagBufLen
);
if
(
NULL
==
buf
)
{
errorPrint
(
"%s"
,
"failed to allocate memory
\n
"
);
return
-
1
;
}
generateBinaryNCharTagValues
(
tableSeq
,
tagBufLen
,
buf
);
dataLen
+=
snprintf
(
tagsValBuf
+
dataLen
,
TSDB_MAX_SQL_LEN
-
dataLen
,
"
\'
%s
\'
,"
,
buf
);
tmfree
(
buf
);
}
else
if
(
0
==
strncasecmp
(
stbInfo
->
tags
[
i
].
dataType
,
"int"
,
strlen
(
"int"
)))
{
if
((
g_args
.
demo_mode
)
&&
(
i
==
0
))
{
dataLen
+=
snprintf
(
tagsValBuf
+
dataLen
,
TSDB_MAX_SQL_LEN
-
dataLen
,
"%"
PRId64
","
,
(
tableSeq
%
10
)
+
1
);
}
else
{
dataLen
+=
snprintf
(
tagsValBuf
+
dataLen
,
TSDB_MAX_SQL_LEN
-
dataLen
,
"%"
PRId64
","
,
tableSeq
);
}
}
else
if
(
0
==
strncasecmp
(
stbInfo
->
tags
[
i
].
dataType
,
"bigint"
,
strlen
(
"bigint"
)))
{
dataLen
+=
snprintf
(
tagsValBuf
+
dataLen
,
TSDB_MAX_SQL_LEN
-
dataLen
,
"%"
PRId64
","
,
rand_bigint
());
}
else
if
(
0
==
strncasecmp
(
stbInfo
->
tags
[
i
].
dataType
,
"float"
,
strlen
(
"float"
)))
{
dataLen
+=
snprintf
(
tagsValBuf
+
dataLen
,
TSDB_MAX_SQL_LEN
-
dataLen
,
"%f,"
,
rand_float
());
}
else
if
(
0
==
strncasecmp
(
stbInfo
->
tags
[
i
].
dataType
,
"double"
,
strlen
(
"double"
)))
{
dataLen
+=
snprintf
(
tagsValBuf
+
dataLen
,
TSDB_MAX_SQL_LEN
-
dataLen
,
"%f,"
,
rand_double
());
}
else
if
(
0
==
strncasecmp
(
stbInfo
->
tags
[
i
].
dataType
,
"smallint"
,
strlen
(
"smallint"
)))
{
dataLen
+=
snprintf
(
tagsValBuf
+
dataLen
,
TSDB_MAX_SQL_LEN
-
dataLen
,
"%d,"
,
rand_smallint
());
}
else
if
(
0
==
strncasecmp
(
stbInfo
->
tags
[
i
].
dataType
,
"tinyint"
,
strlen
(
"tinyint"
)))
{
dataLen
+=
snprintf
(
tagsValBuf
+
dataLen
,
TSDB_MAX_SQL_LEN
-
dataLen
,
"%d,"
,
rand_tinyint
());
}
else
if
(
0
==
strncasecmp
(
stbInfo
->
tags
[
i
].
dataType
,
"bool"
,
strlen
(
"bool"
)))
{
dataLen
+=
snprintf
(
tagsValBuf
+
dataLen
,
TSDB_MAX_SQL_LEN
-
dataLen
,
"%d,"
,
rand_bool
());
}
else
if
(
0
==
strncasecmp
(
stbInfo
->
tags
[
i
].
dataType
,
"timestamp"
,
strlen
(
"timestamp"
)))
{
dataLen
+=
snprintf
(
tagsValBuf
+
dataLen
,
TSDB_MAX_SQL_LEN
-
dataLen
,
"%"
PRId64
","
,
rand_ubigint
());
}
else
if
(
0
==
strncasecmp
(
stbInfo
->
tags
[
i
].
dataType
,
"utinyint"
,
strlen
(
"utinyint"
)))
{
dataLen
+=
snprintf
(
tagsValBuf
+
dataLen
,
TSDB_MAX_SQL_LEN
-
dataLen
,
"%d,"
,
rand_utinyint
());
}
else
if
(
0
==
strncasecmp
(
stbInfo
->
tags
[
i
].
dataType
,
"usmallint"
,
strlen
(
"usmallint"
)))
{
dataLen
+=
snprintf
(
tagsValBuf
+
dataLen
,
TSDB_MAX_SQL_LEN
-
dataLen
,
"%d,"
,
rand_usmallint
());
}
else
if
(
0
==
strncasecmp
(
stbInfo
->
tags
[
i
].
dataType
,
"uint"
,
strlen
(
"uint"
)))
{
dataLen
+=
snprintf
(
tagsValBuf
+
dataLen
,
TSDB_MAX_SQL_LEN
-
dataLen
,
"%d,"
,
rand_uint
());
}
else
if
(
0
==
strncasecmp
(
stbInfo
->
tags
[
i
].
dataType
,
"ubigint"
,
strlen
(
"ubigint"
)))
{
dataLen
+=
snprintf
(
tagsValBuf
+
dataLen
,
TSDB_MAX_SQL_LEN
-
dataLen
,
"%"
PRId64
","
,
rand_ubigint
());
}
else
{
errorPrint
(
"unsupport data type: %s
\n
"
,
stbInfo
->
tags
[
i
].
dataType
);
return
-
1
;
}
}
dataLen
-=
1
;
dataLen
+=
snprintf
(
tagsValBuf
+
dataLen
,
TSDB_MAX_SQL_LEN
-
dataLen
,
")"
);
return
0
;
}
static
int
calcRowLen
(
SSuperTable
*
superTbls
)
{
static
int
calcRowLen
(
SSuperTable
*
superTbls
)
{
int
colIndex
;
int
colIndex
;
int
lenOfOneRow
=
0
;
int
lenOfOneRow
=
0
;
...
@@ -1202,171 +1093,6 @@ int createChildTables() {
...
@@ -1202,171 +1093,6 @@ int createChildTables() {
return
code
;
return
code
;
}
}
/*
Read 10000 lines at most. If more than 10000 lines, continue to read after
using
*/
static
int
readTagFromCsvFileToMem
(
SSuperTable
*
stbInfo
)
{
size_t
n
=
0
;
ssize_t
readLen
=
0
;
char
*
line
=
NULL
;
FILE
*
fp
=
fopen
(
stbInfo
->
tagsFile
,
"r"
);
if
(
fp
==
NULL
)
{
printf
(
"Failed to open tags file: %s, reason:%s
\n
"
,
stbInfo
->
tagsFile
,
strerror
(
errno
));
return
-
1
;
}
if
(
stbInfo
->
tagDataBuf
)
{
free
(
stbInfo
->
tagDataBuf
);
stbInfo
->
tagDataBuf
=
NULL
;
}
int
tagCount
=
MAX_SAMPLES
;
int
count
=
0
;
char
*
tagDataBuf
=
calloc
(
1
,
stbInfo
->
lenOfTagOfOneRow
*
tagCount
);
if
(
tagDataBuf
==
NULL
)
{
printf
(
"Failed to calloc, reason:%s
\n
"
,
strerror
(
errno
));
fclose
(
fp
);
return
-
1
;
}
while
((
readLen
=
tgetline
(
&
line
,
&
n
,
fp
))
!=
-
1
)
{
if
((
'\r'
==
line
[
readLen
-
1
])
||
(
'\n'
==
line
[
readLen
-
1
]))
{
line
[
--
readLen
]
=
0
;
}
if
(
readLen
==
0
)
{
continue
;
}
memcpy
(
tagDataBuf
+
count
*
stbInfo
->
lenOfTagOfOneRow
,
line
,
readLen
);
count
++
;
if
(
count
>=
tagCount
-
1
)
{
char
*
tmp
=
realloc
(
tagDataBuf
,
(
size_t
)(
tagCount
*
1
.
5
*
stbInfo
->
lenOfTagOfOneRow
));
if
(
tmp
!=
NULL
)
{
tagDataBuf
=
tmp
;
tagCount
=
(
int
)(
tagCount
*
1
.
5
);
memset
(
tagDataBuf
+
count
*
stbInfo
->
lenOfTagOfOneRow
,
0
,
(
size_t
)((
tagCount
-
count
)
*
stbInfo
->
lenOfTagOfOneRow
));
}
else
{
// exit, if allocate more memory failed
printf
(
"realloc fail for save tag val from %s
\n
"
,
stbInfo
->
tagsFile
);
tmfree
(
tagDataBuf
);
free
(
line
);
fclose
(
fp
);
return
-
1
;
}
}
}
stbInfo
->
tagDataBuf
=
tagDataBuf
;
stbInfo
->
tagSampleCount
=
count
;
free
(
line
);
fclose
(
fp
);
return
0
;
}
static
void
getAndSetRowsFromCsvFile
(
SSuperTable
*
stbInfo
)
{
FILE
*
fp
=
fopen
(
stbInfo
->
sampleFile
,
"r"
);
int
line_count
=
0
;
if
(
fp
==
NULL
)
{
errorPrint
(
"Failed to open sample file: %s, reason:%s
\n
"
,
stbInfo
->
sampleFile
,
strerror
(
errno
));
return
;
}
char
*
buf
=
calloc
(
1
,
stbInfo
->
maxSqlLen
);
if
(
buf
==
NULL
)
{
errorPrint
(
"%s"
,
"failed to allocate memory
\n
"
);
return
;
}
while
(
fgets
(
buf
,
(
int
)
stbInfo
->
maxSqlLen
,
fp
))
{
line_count
++
;
}
fclose
(
fp
);
tmfree
(
buf
);
stbInfo
->
insertRows
=
line_count
;
}
/*
Read 10000 lines at most. If more than 10000 lines, continue to read after
using
*/
static
int
generateSampleFromCsvForStb
(
SSuperTable
*
stbInfo
)
{
size_t
n
=
0
;
ssize_t
readLen
=
0
;
char
*
line
=
NULL
;
int
getRows
=
0
;
FILE
*
fp
=
fopen
(
stbInfo
->
sampleFile
,
"r"
);
if
(
fp
==
NULL
)
{
errorPrint
(
"Failed to open sample file: %s, reason:%s
\n
"
,
stbInfo
->
sampleFile
,
strerror
(
errno
));
return
-
1
;
}
while
(
1
)
{
readLen
=
tgetline
(
&
line
,
&
n
,
fp
);
if
(
-
1
==
readLen
)
{
if
(
0
!=
fseek
(
fp
,
0
,
SEEK_SET
))
{
errorPrint
(
"Failed to fseek file: %s, reason:%s
\n
"
,
stbInfo
->
sampleFile
,
strerror
(
errno
));
fclose
(
fp
);
return
-
1
;
}
continue
;
}
if
((
'\r'
==
line
[
readLen
-
1
])
||
(
'\n'
==
line
[
readLen
-
1
]))
{
line
[
--
readLen
]
=
0
;
}
if
(
readLen
==
0
)
{
continue
;
}
if
(
readLen
>
stbInfo
->
lenOfOneRow
)
{
printf
(
"sample row len[%d] overflow define schema len[%"
PRIu64
"], so discard this row
\n
"
,
(
int32_t
)
readLen
,
stbInfo
->
lenOfOneRow
);
continue
;
}
memcpy
(
stbInfo
->
sampleDataBuf
+
getRows
*
stbInfo
->
lenOfOneRow
,
line
,
readLen
);
getRows
++
;
if
(
getRows
==
MAX_SAMPLES
)
{
break
;
}
}
fclose
(
fp
);
tmfree
(
line
);
return
0
;
}
static
int
prepareSampleData
()
{
for
(
int
i
=
0
;
i
<
g_Dbs
.
dbCount
;
i
++
)
{
for
(
int
j
=
0
;
j
<
g_Dbs
.
db
[
i
].
superTblCount
;
j
++
)
{
if
(
g_Dbs
.
db
[
i
].
superTbls
[
j
].
tagsFile
[
0
]
!=
0
)
{
if
(
readTagFromCsvFileToMem
(
&
g_Dbs
.
db
[
i
].
superTbls
[
j
])
!=
0
)
{
return
-
1
;
}
}
}
}
return
0
;
}
void
postFreeResource
()
{
void
postFreeResource
()
{
tmfclose
(
g_fpOfInsertResult
);
tmfclose
(
g_fpOfInsertResult
);
tmfree
(
g_dupstr
);
tmfree
(
g_dupstr
);
...
@@ -1425,1244 +1151,139 @@ void postFreeResource() {
...
@@ -1425,1244 +1151,139 @@ void postFreeResource() {
tmfree
(
g_sampleBindBatchArray
);
tmfree
(
g_sampleBindBatchArray
);
}
}
static
int
getRowDataFromSample
(
char
*
dataBuf
,
int64_t
maxLen
,
static
int32_t
execInsert
(
threadInfo
*
pThreadInfo
,
uint32_t
k
)
{
int64_t
timestamp
,
SSuperTable
*
stbInfo
,
int32_t
affectedRows
;
int64_t
*
sampleUsePos
)
{
SSuperTable
*
stbInfo
=
pThreadInfo
->
stbInfo
;
if
((
*
sampleUsePos
)
==
MAX_SAMPLES
)
{
TAOS_RES
*
res
;
*
sampleUsePos
=
0
;
int32_t
code
;
}
uint16_t
iface
;
if
(
stbInfo
)
int
dataLen
=
0
;
iface
=
stbInfo
->
iface
;
if
(
stbInfo
->
useSampleTs
)
{
else
{
dataLen
+=
snprintf
(
if
(
g_args
.
iface
==
INTERFACE_BUT
)
dataBuf
+
dataLen
,
maxLen
-
dataLen
,
"(%s"
,
iface
=
TAOSC_IFACE
;
stbInfo
->
sampleDataBuf
+
stbInfo
->
lenOfOneRow
*
(
*
sampleUsePos
));
else
}
else
{
iface
=
g_args
.
iface
;
dataLen
+=
snprintf
(
dataBuf
+
dataLen
,
maxLen
-
dataLen
,
"(%"
PRId64
", "
,
timestamp
);
dataLen
+=
snprintf
(
dataBuf
+
dataLen
,
maxLen
-
dataLen
,
"%s"
,
stbInfo
->
sampleDataBuf
+
stbInfo
->
lenOfOneRow
*
(
*
sampleUsePos
));
}
}
dataLen
+=
snprintf
(
dataBuf
+
dataLen
,
maxLen
-
dataLen
,
")"
);
(
*
sampleUsePos
)
++
;
return
dataLen
;
}
static
int64_t
generateStbRowData
(
SSuperTable
*
stbInfo
,
char
*
recBuf
,
int64_t
remainderBufLen
,
int64_t
timestamp
)
{
int64_t
dataLen
=
0
;
char
*
pstr
=
recBuf
;
int64_t
maxLen
=
MAX_DATA_SIZE
;
int
tmpLen
;
dataLen
+=
debugPrint
(
"[%d] %s() LN%d %s
\n
"
,
pThreadInfo
->
threadID
,
__func__
,
__LINE__
,
snprintf
(
pstr
+
dataLen
,
maxLen
-
dataLen
,
"(%"
PRId64
""
,
timestamp
);
(
iface
==
TAOSC_IFACE
)
?
"taosc"
:
(
iface
==
REST_IFACE
)
?
"rest"
:
"stmt"
);
for
(
int
i
=
0
;
i
<
stbInfo
->
columnCount
;
i
++
)
{
switch
(
iface
)
{
tstrncpy
(
pstr
+
dataLen
,
","
,
2
);
case
TAOSC_IFACE
:
dataLen
+=
1
;
verbosePrint
(
"[%d] %s() LN%d %s
\n
"
,
pThreadInfo
->
threadID
,
__func__
,
__LINE__
,
pThreadInfo
->
buffer
);
if
((
stbInfo
->
columns
[
i
].
data_type
==
TSDB_DATA_TYPE_BINARY
)
||
affectedRows
=
queryDbExec
(
pThreadInfo
->
taos
,
pThreadInfo
->
buffer
,
(
stbInfo
->
columns
[
i
].
data_type
==
TSDB_DATA_TYPE_NCHAR
))
{
INSERT_TYPE
,
false
);
if
(
stbInfo
->
columns
[
i
].
dataLen
>
TSDB_MAX_BINARY_LEN
)
{
break
;
errorPrint
(
"binary or nchar length overflow, max size:%u
\n
"
,
(
uint32_t
)
TSDB_MAX_BINARY_LEN
);
return
-
1
;
}
if
((
stbInfo
->
columns
[
i
].
dataLen
+
1
)
>
case
REST_IFACE
:
/* need count 3 extra chars \', \', and , */
verbosePrint
(
"[%d] %s() LN%d %s
\n
"
,
pThreadInfo
->
threadID
,
__func__
,
(
remainderBufLen
-
dataLen
-
3
))
{
__LINE__
,
pThreadInfo
->
buffer
);
return
0
;
}
char
*
buf
=
(
char
*
)
calloc
(
stbInfo
->
columns
[
i
].
dataLen
+
1
,
1
);
if
(
NULL
==
buf
)
{
errorPrint
(
"%s"
,
"failed to allocate memory
\n
"
);
return
-
1
;
}
rand_string
(
buf
,
stbInfo
->
columns
[
i
].
dataLen
);
dataLen
+=
snprintf
(
pstr
+
dataLen
,
maxLen
-
dataLen
,
"
\'
%s
\'
"
,
buf
);
tmfree
(
buf
);
if
(
0
!=
postProceSql
(
g_Dbs
.
host
,
g_Dbs
.
port
,
pThreadInfo
->
buffer
,
pThreadInfo
))
{
affectedRows
=
-
1
;
printf
(
"========restful return fail, threadID[%d]
\n
"
,
pThreadInfo
->
threadID
);
}
else
{
}
else
{
char
*
tmp
=
NULL
;
affectedRows
=
k
;
switch
(
stbInfo
->
columns
[
i
].
data_type
)
{
case
TSDB_DATA_TYPE_INT
:
if
((
g_args
.
demo_mode
)
&&
(
i
==
1
))
{
tmp
=
demo_voltage_int_str
();
}
else
{
tmp
=
rand_int_str
();
}
}
tmpLen
=
(
int
)
strlen
(
tmp
);
tstrncpy
(
pstr
+
dataLen
,
tmp
,
min
(
tmpLen
+
1
,
INT_BUFF_LEN
));
break
;
break
;
case
TSDB_DATA_TYPE_UINT
:
case
STMT_IFACE
:
tmp
=
rand_uint_str
();
debugPrint
(
"%s() LN%d, stmt=%p"
,
__func__
,
__LINE__
,
tmpLen
=
(
int
)
strlen
(
tmp
);
pThreadInfo
->
stmt
);
tstrncpy
(
pstr
+
dataLen
,
tmp
,
if
(
0
!=
taos_stmt_execute
(
pThreadInfo
->
stmt
))
{
min
(
tmpLen
+
1
,
INT_BUFF_LEN
));
errorPrint
(
break
;
"%s() LN%d, failied to execute insert statement. reason: "
"%s
\n
"
,
__func__
,
__LINE__
,
taos_stmt_errstr
(
pThreadInfo
->
stmt
));
case
TSDB_DATA_TYPE_BIGINT
:
fprintf
(
stderr
,
tmp
=
rand_bigint_str
();
"
\n\033
[31m === Please reduce batch number if WAL size "
tmpLen
=
(
int
)
strlen
(
tmp
);
"exceeds limit. ===
\033
[0m
\n\n
"
);
tstrncpy
(
pstr
+
dataLen
,
tmp
,
exit
(
EXIT_FAILURE
);
min
(
tmpLen
+
1
,
BIGINT_BUFF_LEN
));
}
affectedRows
=
k
;
break
;
break
;
case
SML_IFACE
:
case
TSDB_DATA_TYPE_UBIGINT
:
res
=
taos_schemaless_insert
(
tmp
=
rand_ubigint_str
();
pThreadInfo
->
taos
,
pThreadInfo
->
lines
,
tmpLen
=
(
int
)
strlen
(
tmp
);
stbInfo
->
lineProtocol
==
TSDB_SML_JSON_PROTOCOL
?
0
:
k
,
tstrncpy
(
pstr
+
dataLen
,
tmp
,
stbInfo
->
lineProtocol
,
stbInfo
->
tsPrecision
);
min
(
tmpLen
+
1
,
BIGINT_BUFF_LEN
));
code
=
taos_errno
(
res
);
affectedRows
=
taos_affected_rows
(
res
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
errorPrint
(
"%s() LN%d, failed to execute schemaless insert. reason: "
"%s
\n
"
,
__func__
,
__LINE__
,
taos_errstr
(
res
));
exit
(
EXIT_FAILURE
);
}
break
;
break
;
default:
errorPrint
(
"Unknown insert mode: %d
\n
"
,
stbInfo
->
iface
);
affectedRows
=
0
;
}
case
TSDB_DATA_TYPE_FLOAT
:
return
affectedRows
;
if
(
g_args
.
demo_mode
)
{
}
if
(
i
==
0
)
{
tmp
=
demo_current_float_str
();
static
void
getTableName
(
char
*
pTblName
,
threadInfo
*
pThreadInfo
,
uint64_t
tableSeq
)
{
SSuperTable
*
stbInfo
=
pThreadInfo
->
stbInfo
;
if
(
stbInfo
)
{
if
(
AUTO_CREATE_SUBTBL
!=
stbInfo
->
autoCreateTable
)
{
if
(
stbInfo
->
childTblLimit
>
0
)
{
snprintf
(
pTblName
,
TSDB_TABLE_NAME_LEN
,
stbInfo
->
escapeChar
?
"`%s`"
:
"%s"
,
stbInfo
->
childTblName
+
(
tableSeq
-
stbInfo
->
childTblOffset
)
*
TSDB_TABLE_NAME_LEN
);
}
else
{
}
else
{
tmp
=
demo_phase_float_str
();
verbosePrint
(
"[%d] %s() LN%d: from=%"
PRIu64
" count=%"
PRId64
" seq=%"
PRIu64
"
\n
"
,
pThreadInfo
->
threadID
,
__func__
,
__LINE__
,
pThreadInfo
->
start_table_from
,
pThreadInfo
->
ntables
,
tableSeq
);
snprintf
(
pTblName
,
TSDB_TABLE_NAME_LEN
,
stbInfo
->
escapeChar
?
"`%s`"
:
"%s"
,
stbInfo
->
childTblName
+
tableSeq
*
TSDB_TABLE_NAME_LEN
);
}
}
}
else
{
}
else
{
tmp
=
rand_float_str
();
snprintf
(
pTblName
,
TSDB_TABLE_NAME_LEN
,
stbInfo
->
escapeChar
?
"`%s%"
PRIu64
"`"
:
"%s%"
PRIu64
""
,
stbInfo
->
childTblPrefix
,
tableSeq
);
}
}
tmpLen
=
(
int
)
strlen
(
tmp
);
}
else
{
tstrncpy
(
pstr
+
dataLen
,
tmp
,
snprintf
(
pTblName
,
TSDB_TABLE_NAME_LEN
,
min
(
tmpLen
+
1
,
FLOAT_BUFF_LEN
));
g_args
.
escapeChar
?
"`%s%"
PRIu64
"`"
:
"%s%"
PRIu64
""
,
break
;
g_args
.
tb_prefix
,
tableSeq
);
}
case
TSDB_DATA_TYPE_DOUBLE
:
}
tmp
=
rand_double_str
();
tmpLen
=
(
int
)
strlen
(
tmp
);
tstrncpy
(
pstr
+
dataLen
,
tmp
,
min
(
tmpLen
+
1
,
DOUBLE_BUFF_LEN
));
break
;
case
TSDB_DATA_TYPE_SMALLINT
:
static
int
execStbBindParamBatch
(
threadInfo
*
pThreadInfo
,
char
*
tableName
,
tmp
=
rand_smallint_str
();
int64_t
tableSeq
,
uint32_t
batch
,
tmpLen
=
(
int
)
strlen
(
tmp
);
uint64_t
insertRows
,
uint64_t
recordFrom
,
tstrncpy
(
pstr
+
dataLen
,
tmp
,
int64_t
startTime
,
int64_t
*
pSamplePos
)
{
min
(
tmpLen
+
1
,
SMALLINT_BUFF_LEN
));
TAOS_STMT
*
stmt
=
pThreadInfo
->
stmt
;
break
;
case
TSDB_DATA_TYPE_USMALLINT
:
SSuperTable
*
stbInfo
=
pThreadInfo
->
stbInfo
;
tmp
=
rand_usmallint_str
();
tmpLen
=
(
int
)
strlen
(
tmp
);
tstrncpy
(
pstr
+
dataLen
,
tmp
,
min
(
tmpLen
+
1
,
SMALLINT_BUFF_LEN
));
break
;
case
TSDB_DATA_TYPE_TINYINT
:
uint32_t
columnCount
=
pThreadInfo
->
stbInfo
->
columnCount
;
tmp
=
rand_tinyint_str
();
tmpLen
=
(
int
)
strlen
(
tmp
);
tstrncpy
(
pstr
+
dataLen
,
tmp
,
min
(
tmpLen
+
1
,
TINYINT_BUFF_LEN
));
break
;
case
TSDB_DATA_TYPE_UTINYINT
:
uint32_t
thisBatch
=
(
uint32_t
)(
MAX_SAMPLES
-
(
*
pSamplePos
));
tmp
=
rand_utinyint_str
();
tmpLen
=
(
int
)
strlen
(
tmp
);
tstrncpy
(
pstr
+
dataLen
,
tmp
,
min
(
tmpLen
+
1
,
TINYINT_BUFF_LEN
));
break
;
case
TSDB_DATA_TYPE_BOOL
:
if
(
thisBatch
>
batch
)
{
tmp
=
rand_bool_str
();
thisBatch
=
batch
;
tmpLen
=
(
int
)
strlen
(
tmp
);
}
tstrncpy
(
pstr
+
dataLen
,
tmp
,
verbosePrint
(
"%s() LN%d, batch=%d pos=%"
PRId64
" thisBatch=%d
\n
"
,
__func__
,
min
(
tmpLen
+
1
,
BOOL_BUFF_LEN
));
__LINE__
,
batch
,
*
pSamplePos
,
thisBatch
);
break
;
case
TSDB_DATA_TYPE_TIMESTAMP
:
tmp
=
rand_bigint_str
();
tmpLen
=
(
int
)
strlen
(
tmp
);
tstrncpy
(
pstr
+
dataLen
,
tmp
,
min
(
tmpLen
+
1
,
BIGINT_BUFF_LEN
));
break
;
case
TSDB_DATA_TYPE_NULL
:
break
;
default:
errorPrint
(
"Not support data type: %s
\n
"
,
stbInfo
->
columns
[
i
].
dataType
);
exit
(
EXIT_FAILURE
);
}
if
(
tmp
)
{
dataLen
+=
tmpLen
;
}
}
if
(
dataLen
>
(
remainderBufLen
-
(
128
)))
return
0
;
}
dataLen
+=
snprintf
(
pstr
+
dataLen
,
2
,
")"
);
verbosePrint
(
"%s() LN%d, dataLen:%"
PRId64
"
\n
"
,
__func__
,
__LINE__
,
dataLen
);
verbosePrint
(
"%s() LN%d, recBuf:
\n\t
%s
\n
"
,
__func__
,
__LINE__
,
recBuf
);
return
strlen
(
recBuf
);
}
static
int64_t
generateData
(
char
*
recBuf
,
char
*
data_type
,
int64_t
timestamp
,
int
lenOfBinary
)
{
memset
(
recBuf
,
0
,
MAX_DATA_SIZE
);
char
*
pstr
=
recBuf
;
pstr
+=
sprintf
(
pstr
,
"(%"
PRId64
""
,
timestamp
);
int
columnCount
=
g_args
.
columnCount
;
bool
b
;
char
*
s
;
for
(
int
i
=
0
;
i
<
columnCount
;
i
++
)
{
switch
(
data_type
[
i
])
{
case
TSDB_DATA_TYPE_TINYINT
:
pstr
+=
sprintf
(
pstr
,
",%d"
,
rand_tinyint
());
break
;
case
TSDB_DATA_TYPE_SMALLINT
:
pstr
+=
sprintf
(
pstr
,
",%d"
,
rand_smallint
());
break
;
case
TSDB_DATA_TYPE_INT
:
pstr
+=
sprintf
(
pstr
,
",%d"
,
rand_int
());
break
;
case
TSDB_DATA_TYPE_BIGINT
:
pstr
+=
sprintf
(
pstr
,
",%"
PRId64
""
,
rand_bigint
());
break
;
case
TSDB_DATA_TYPE_TIMESTAMP
:
pstr
+=
sprintf
(
pstr
,
",%"
PRId64
""
,
rand_bigint
());
break
;
case
TSDB_DATA_TYPE_FLOAT
:
pstr
+=
sprintf
(
pstr
,
",%10.4f"
,
rand_float
());
break
;
case
TSDB_DATA_TYPE_DOUBLE
:
pstr
+=
sprintf
(
pstr
,
",%20.8f"
,
rand_double
());
break
;
case
TSDB_DATA_TYPE_BOOL
:
b
=
rand_bool
()
&
1
;
pstr
+=
sprintf
(
pstr
,
",%s"
,
b
?
"true"
:
"false"
);
break
;
case
TSDB_DATA_TYPE_BINARY
:
case
TSDB_DATA_TYPE_NCHAR
:
s
=
calloc
(
1
,
lenOfBinary
+
1
);
if
(
NULL
==
s
)
{
errorPrint
(
"%s"
,
"failed to allocate memory
\n
"
);
return
-
1
;
}
rand_string
(
s
,
lenOfBinary
);
pstr
+=
sprintf
(
pstr
,
",
\"
%s
\"
"
,
s
);
free
(
s
);
break
;
case
TSDB_DATA_TYPE_UTINYINT
:
pstr
+=
sprintf
(
pstr
,
",%d"
,
rand_utinyint
());
break
;
case
TSDB_DATA_TYPE_USMALLINT
:
pstr
+=
sprintf
(
pstr
,
",%d"
,
rand_usmallint
());
break
;
case
TSDB_DATA_TYPE_UINT
:
pstr
+=
sprintf
(
pstr
,
",%d"
,
rand_uint
());
break
;
case
TSDB_DATA_TYPE_UBIGINT
:
pstr
+=
sprintf
(
pstr
,
",%"
PRId64
""
,
rand_ubigint
());
break
;
case
TSDB_DATA_TYPE_NULL
:
break
;
default:
errorPrint
(
"Unknown data type %d
\n
"
,
data_type
[
i
]);
return
-
1
;
}
if
(
strlen
(
recBuf
)
>
MAX_DATA_SIZE
)
{
errorPrint
(
"%s"
,
"column length too long, abort
\n
"
);
return
-
1
;
}
}
pstr
+=
sprintf
(
pstr
,
")"
);
verbosePrint
(
"%s() LN%d, recBuf:
\n\t
%s
\n
"
,
__func__
,
__LINE__
,
recBuf
);
return
(
int32_t
)
strlen
(
recBuf
);
}
static
int
generateSampleFromRand
(
char
*
sampleDataBuf
,
uint64_t
lenOfOneRow
,
int
columnCount
,
StrColumn
*
columns
)
{
char
data
[
MAX_DATA_SIZE
];
memset
(
data
,
0
,
MAX_DATA_SIZE
);
char
*
buff
=
calloc
(
lenOfOneRow
,
1
);
if
(
NULL
==
buff
)
{
errorPrint
(
"%s"
,
"failed to allocate memory
\n
"
);
return
-
1
;
}
for
(
int
i
=
0
;
i
<
MAX_SAMPLES
;
i
++
)
{
uint64_t
pos
=
0
;
memset
(
buff
,
0
,
lenOfOneRow
);
for
(
int
c
=
0
;
c
<
columnCount
;
c
++
)
{
char
*
tmp
=
NULL
;
uint32_t
dataLen
;
char
data_type
=
(
columns
)
?
(
columns
[
c
].
data_type
)
:
g_args
.
data_type
[
c
];
switch
(
data_type
)
{
case
TSDB_DATA_TYPE_BINARY
:
dataLen
=
(
columns
)
?
columns
[
c
].
dataLen
:
g_args
.
binwidth
;
rand_string
(
data
,
dataLen
);
pos
+=
sprintf
(
buff
+
pos
,
"%s,"
,
data
);
break
;
case
TSDB_DATA_TYPE_NCHAR
:
dataLen
=
(
columns
)
?
columns
[
c
].
dataLen
:
g_args
.
binwidth
;
rand_string
(
data
,
dataLen
-
1
);
pos
+=
sprintf
(
buff
+
pos
,
"%s,"
,
data
);
break
;
case
TSDB_DATA_TYPE_INT
:
if
((
g_args
.
demo_mode
)
&&
(
c
==
1
))
{
tmp
=
demo_voltage_int_str
();
}
else
{
tmp
=
rand_int_str
();
}
pos
+=
sprintf
(
buff
+
pos
,
"%s,"
,
tmp
);
break
;
case
TSDB_DATA_TYPE_UINT
:
pos
+=
sprintf
(
buff
+
pos
,
"%s,"
,
rand_uint_str
());
break
;
case
TSDB_DATA_TYPE_BIGINT
:
pos
+=
sprintf
(
buff
+
pos
,
"%s,"
,
rand_bigint_str
());
break
;
case
TSDB_DATA_TYPE_UBIGINT
:
pos
+=
sprintf
(
buff
+
pos
,
"%s,"
,
rand_ubigint_str
());
break
;
case
TSDB_DATA_TYPE_FLOAT
:
if
(
g_args
.
demo_mode
)
{
if
(
c
==
0
)
{
tmp
=
demo_current_float_str
();
}
else
{
tmp
=
demo_phase_float_str
();
}
}
else
{
tmp
=
rand_float_str
();
}
pos
+=
sprintf
(
buff
+
pos
,
"%s,"
,
tmp
);
break
;
case
TSDB_DATA_TYPE_DOUBLE
:
pos
+=
sprintf
(
buff
+
pos
,
"%s,"
,
rand_double_str
());
break
;
case
TSDB_DATA_TYPE_SMALLINT
:
pos
+=
sprintf
(
buff
+
pos
,
"%s,"
,
rand_smallint_str
());
break
;
case
TSDB_DATA_TYPE_USMALLINT
:
pos
+=
sprintf
(
buff
+
pos
,
"%s,"
,
rand_usmallint_str
());
break
;
case
TSDB_DATA_TYPE_TINYINT
:
pos
+=
sprintf
(
buff
+
pos
,
"%s,"
,
rand_tinyint_str
());
break
;
case
TSDB_DATA_TYPE_UTINYINT
:
pos
+=
sprintf
(
buff
+
pos
,
"%s,"
,
rand_utinyint_str
());
break
;
case
TSDB_DATA_TYPE_BOOL
:
pos
+=
sprintf
(
buff
+
pos
,
"%s,"
,
rand_bool_str
());
break
;
case
TSDB_DATA_TYPE_TIMESTAMP
:
pos
+=
sprintf
(
buff
+
pos
,
"%s,"
,
rand_bigint_str
());
break
;
case
TSDB_DATA_TYPE_NULL
:
break
;
default:
errorPrint
(
"%s() LN%d, Unknown data type %s
\n
"
,
__func__
,
__LINE__
,
(
columns
)
?
(
columns
[
c
].
dataType
)
:
g_args
.
dataType
[
c
]);
exit
(
EXIT_FAILURE
);
}
}
*
(
buff
+
pos
-
1
)
=
0
;
memcpy
(
sampleDataBuf
+
i
*
lenOfOneRow
,
buff
,
pos
);
}
free
(
buff
);
return
0
;
}
static
int
generateSampleFromRandForNtb
()
{
return
generateSampleFromRand
(
g_sampleDataBuf
,
g_args
.
lenOfOneRow
,
g_args
.
columnCount
,
NULL
);
}
static
int
generateSampleFromRandForStb
(
SSuperTable
*
stbInfo
)
{
return
generateSampleFromRand
(
stbInfo
->
sampleDataBuf
,
stbInfo
->
lenOfOneRow
,
stbInfo
->
columnCount
,
stbInfo
->
columns
);
}
static
int
prepareSampleForNtb
()
{
g_sampleDataBuf
=
calloc
(
g_args
.
lenOfOneRow
*
MAX_SAMPLES
,
1
);
if
(
NULL
==
g_sampleDataBuf
)
{
errorPrint
(
"%s"
,
"failed to allocate memory
\n
"
);
return
-
1
;
}
return
generateSampleFromRandForNtb
();
}
static
int
prepareSampleForStb
(
SSuperTable
*
stbInfo
)
{
stbInfo
->
sampleDataBuf
=
calloc
(
stbInfo
->
lenOfOneRow
*
MAX_SAMPLES
,
1
);
if
(
NULL
==
stbInfo
->
sampleDataBuf
)
{
errorPrint
(
"%s"
,
"failed to allocate memory
\n
"
);
return
-
1
;
}
int
ret
;
if
(
0
==
strncasecmp
(
stbInfo
->
dataSource
,
"sample"
,
strlen
(
"sample"
)))
{
if
(
stbInfo
->
useSampleTs
)
{
getAndSetRowsFromCsvFile
(
stbInfo
);
}
ret
=
generateSampleFromCsvForStb
(
stbInfo
);
}
else
{
ret
=
generateSampleFromRandForStb
(
stbInfo
);
}
if
(
0
!=
ret
)
{
errorPrint
(
"read sample from %s file failed.
\n
"
,
stbInfo
->
sampleFile
);
tmfree
(
stbInfo
->
sampleDataBuf
);
stbInfo
->
sampleDataBuf
=
NULL
;
return
-
1
;
}
return
0
;
}
static
int32_t
execInsert
(
threadInfo
*
pThreadInfo
,
uint32_t
k
)
{
int32_t
affectedRows
;
SSuperTable
*
stbInfo
=
pThreadInfo
->
stbInfo
;
TAOS_RES
*
res
;
int32_t
code
;
uint16_t
iface
;
if
(
stbInfo
)
iface
=
stbInfo
->
iface
;
else
{
if
(
g_args
.
iface
==
INTERFACE_BUT
)
iface
=
TAOSC_IFACE
;
else
iface
=
g_args
.
iface
;
}
debugPrint
(
"[%d] %s() LN%d %s
\n
"
,
pThreadInfo
->
threadID
,
__func__
,
__LINE__
,
(
iface
==
TAOSC_IFACE
)
?
"taosc"
:
(
iface
==
REST_IFACE
)
?
"rest"
:
"stmt"
);
switch
(
iface
)
{
case
TAOSC_IFACE
:
verbosePrint
(
"[%d] %s() LN%d %s
\n
"
,
pThreadInfo
->
threadID
,
__func__
,
__LINE__
,
pThreadInfo
->
buffer
);
affectedRows
=
queryDbExec
(
pThreadInfo
->
taos
,
pThreadInfo
->
buffer
,
INSERT_TYPE
,
false
);
break
;
case
REST_IFACE
:
verbosePrint
(
"[%d] %s() LN%d %s
\n
"
,
pThreadInfo
->
threadID
,
__func__
,
__LINE__
,
pThreadInfo
->
buffer
);
if
(
0
!=
postProceSql
(
g_Dbs
.
host
,
g_Dbs
.
port
,
pThreadInfo
->
buffer
,
pThreadInfo
))
{
affectedRows
=
-
1
;
printf
(
"========restful return fail, threadID[%d]
\n
"
,
pThreadInfo
->
threadID
);
}
else
{
affectedRows
=
k
;
}
break
;
case
STMT_IFACE
:
debugPrint
(
"%s() LN%d, stmt=%p"
,
__func__
,
__LINE__
,
pThreadInfo
->
stmt
);
if
(
0
!=
taos_stmt_execute
(
pThreadInfo
->
stmt
))
{
errorPrint
(
"%s() LN%d, failied to execute insert statement. reason: "
"%s
\n
"
,
__func__
,
__LINE__
,
taos_stmt_errstr
(
pThreadInfo
->
stmt
));
fprintf
(
stderr
,
"
\n\033
[31m === Please reduce batch number if WAL size "
"exceeds limit. ===
\033
[0m
\n\n
"
);
exit
(
EXIT_FAILURE
);
}
affectedRows
=
k
;
break
;
case
SML_IFACE
:
res
=
taos_schemaless_insert
(
pThreadInfo
->
taos
,
pThreadInfo
->
lines
,
stbInfo
->
lineProtocol
==
TSDB_SML_JSON_PROTOCOL
?
0
:
k
,
stbInfo
->
lineProtocol
,
stbInfo
->
tsPrecision
);
code
=
taos_errno
(
res
);
affectedRows
=
taos_affected_rows
(
res
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
errorPrint
(
"%s() LN%d, failed to execute schemaless insert. reason: "
"%s
\n
"
,
__func__
,
__LINE__
,
taos_errstr
(
res
));
exit
(
EXIT_FAILURE
);
}
break
;
default:
errorPrint
(
"Unknown insert mode: %d
\n
"
,
stbInfo
->
iface
);
affectedRows
=
0
;
}
return
affectedRows
;
}
static
void
getTableName
(
char
*
pTblName
,
threadInfo
*
pThreadInfo
,
uint64_t
tableSeq
)
{
SSuperTable
*
stbInfo
=
pThreadInfo
->
stbInfo
;
if
(
stbInfo
)
{
if
(
AUTO_CREATE_SUBTBL
!=
stbInfo
->
autoCreateTable
)
{
if
(
stbInfo
->
childTblLimit
>
0
)
{
snprintf
(
pTblName
,
TSDB_TABLE_NAME_LEN
,
stbInfo
->
escapeChar
?
"`%s`"
:
"%s"
,
stbInfo
->
childTblName
+
(
tableSeq
-
stbInfo
->
childTblOffset
)
*
TSDB_TABLE_NAME_LEN
);
}
else
{
verbosePrint
(
"[%d] %s() LN%d: from=%"
PRIu64
" count=%"
PRId64
" seq=%"
PRIu64
"
\n
"
,
pThreadInfo
->
threadID
,
__func__
,
__LINE__
,
pThreadInfo
->
start_table_from
,
pThreadInfo
->
ntables
,
tableSeq
);
snprintf
(
pTblName
,
TSDB_TABLE_NAME_LEN
,
stbInfo
->
escapeChar
?
"`%s`"
:
"%s"
,
stbInfo
->
childTblName
+
tableSeq
*
TSDB_TABLE_NAME_LEN
);
}
}
else
{
snprintf
(
pTblName
,
TSDB_TABLE_NAME_LEN
,
stbInfo
->
escapeChar
?
"`%s%"
PRIu64
"`"
:
"%s%"
PRIu64
""
,
stbInfo
->
childTblPrefix
,
tableSeq
);
}
}
else
{
snprintf
(
pTblName
,
TSDB_TABLE_NAME_LEN
,
g_args
.
escapeChar
?
"`%s%"
PRIu64
"`"
:
"%s%"
PRIu64
""
,
g_args
.
tb_prefix
,
tableSeq
);
}
}
static
int64_t
getTSRandTail
(
int64_t
timeStampStep
,
int32_t
seq
,
int
disorderRatio
,
int
disorderRange
)
{
int64_t
randTail
=
timeStampStep
*
seq
;
if
(
disorderRatio
>
0
)
{
int
rand_num
=
taosRandom
()
%
100
;
if
(
rand_num
<
disorderRatio
)
{
randTail
=
(
randTail
+
(
taosRandom
()
%
disorderRange
+
1
))
*
(
-
1
);
debugPrint
(
"rand data generated, back %"
PRId64
"
\n
"
,
randTail
);
}
}
return
randTail
;
}
static
int32_t
generateDataTailWithoutStb
(
uint32_t
batch
,
char
*
buffer
,
int64_t
remainderBufLen
,
int64_t
insertRows
,
uint64_t
recordFrom
,
int64_t
startTime
,
/* int64_t *pSamplePos, */
int64_t
*
dataLen
)
{
uint64_t
len
=
0
;
char
*
pstr
=
buffer
;
verbosePrint
(
"%s() LN%d batch=%d
\n
"
,
__func__
,
__LINE__
,
batch
);
int32_t
k
=
0
;
for
(
k
=
0
;
k
<
batch
;)
{
char
*
data
=
pstr
;
memset
(
data
,
0
,
MAX_DATA_SIZE
);
int64_t
retLen
=
0
;
char
*
data_type
=
g_args
.
data_type
;
int
lenOfBinary
=
g_args
.
binwidth
;
if
(
g_args
.
disorderRatio
)
{
retLen
=
generateData
(
data
,
data_type
,
startTime
+
getTSRandTail
(
g_args
.
timestamp_step
,
k
,
g_args
.
disorderRatio
,
g_args
.
disorderRange
),
lenOfBinary
);
}
else
{
retLen
=
generateData
(
data
,
data_type
,
startTime
+
g_args
.
timestamp_step
*
k
,
lenOfBinary
);
}
if
(
len
>
remainderBufLen
)
break
;
pstr
+=
retLen
;
k
++
;
len
+=
retLen
;
remainderBufLen
-=
retLen
;
verbosePrint
(
"%s() LN%d len=%"
PRIu64
" k=%d
\n
buffer=%s
\n
"
,
__func__
,
__LINE__
,
len
,
k
,
buffer
);
recordFrom
++
;
if
(
recordFrom
>=
insertRows
)
{
break
;
}
}
*
dataLen
=
len
;
return
k
;
}
static
int32_t
generateStbDataTail
(
SSuperTable
*
stbInfo
,
uint32_t
batch
,
char
*
buffer
,
int64_t
remainderBufLen
,
int64_t
insertRows
,
uint64_t
recordFrom
,
int64_t
startTime
,
int64_t
*
pSamplePos
,
int64_t
*
dataLen
)
{
uint64_t
len
=
0
;
char
*
pstr
=
buffer
;
bool
tsRand
;
if
(
0
==
strncasecmp
(
stbInfo
->
dataSource
,
"rand"
,
strlen
(
"rand"
)))
{
tsRand
=
true
;
}
else
{
tsRand
=
false
;
}
verbosePrint
(
"%s() LN%d batch=%u buflen=%"
PRId64
"
\n
"
,
__func__
,
__LINE__
,
batch
,
remainderBufLen
);
int32_t
k
;
for
(
k
=
0
;
k
<
batch
;)
{
char
*
data
=
pstr
;
int64_t
lenOfRow
=
0
;
if
(
tsRand
)
{
if
(
stbInfo
->
disorderRatio
>
0
)
{
lenOfRow
=
generateStbRowData
(
stbInfo
,
data
,
remainderBufLen
,
startTime
+
getTSRandTail
(
stbInfo
->
timeStampStep
,
k
,
stbInfo
->
disorderRatio
,
stbInfo
->
disorderRange
));
}
else
{
lenOfRow
=
generateStbRowData
(
stbInfo
,
data
,
remainderBufLen
,
startTime
+
stbInfo
->
timeStampStep
*
k
);
}
}
else
{
lenOfRow
=
getRowDataFromSample
(
data
,
(
remainderBufLen
<
MAX_DATA_SIZE
)
?
remainderBufLen
:
MAX_DATA_SIZE
,
startTime
+
stbInfo
->
timeStampStep
*
k
,
stbInfo
,
pSamplePos
);
}
if
(
lenOfRow
==
0
)
{
data
[
0
]
=
'\0'
;
break
;
}
if
((
lenOfRow
+
1
)
>
remainderBufLen
)
{
break
;
}
pstr
+=
lenOfRow
;
k
++
;
len
+=
lenOfRow
;
remainderBufLen
-=
lenOfRow
;
verbosePrint
(
"%s() LN%d len=%"
PRIu64
" k=%u
\n
buffer=%s
\n
"
,
__func__
,
__LINE__
,
len
,
k
,
buffer
);
recordFrom
++
;
if
(
recordFrom
>=
insertRows
)
{
break
;
}
}
*
dataLen
=
len
;
return
k
;
}
static
int
generateSQLHeadWithoutStb
(
char
*
tableName
,
char
*
dbName
,
char
*
buffer
,
int
remainderBufLen
)
{
int
len
;
char
headBuf
[
HEAD_BUFF_LEN
];
len
=
snprintf
(
headBuf
,
HEAD_BUFF_LEN
,
"%s.%s values"
,
dbName
,
tableName
);
if
(
len
>
remainderBufLen
)
return
-
1
;
tstrncpy
(
buffer
,
headBuf
,
len
+
1
);
return
len
;
}
static
int
generateStbSQLHead
(
SSuperTable
*
stbInfo
,
char
*
tableName
,
int64_t
tableSeq
,
char
*
dbName
,
char
*
buffer
,
int
remainderBufLen
)
{
int
len
;
char
headBuf
[
HEAD_BUFF_LEN
];
if
(
AUTO_CREATE_SUBTBL
==
stbInfo
->
autoCreateTable
)
{
char
*
tagsValBuf
=
(
char
*
)
calloc
(
TSDB_MAX_SQL_LEN
+
1
,
1
);
if
(
NULL
==
tagsValBuf
)
{
errorPrint
(
"%s"
,
"failed to allocate memory
\n
"
);
return
-
1
;
}
if
(
0
==
stbInfo
->
tagSource
)
{
if
(
generateTagValuesForStb
(
stbInfo
,
tableSeq
,
tagsValBuf
))
{
tmfree
(
tagsValBuf
);
return
-
1
;
}
}
else
{
snprintf
(
tagsValBuf
,
TSDB_MAX_SQL_LEN
,
"(%s)"
,
stbInfo
->
tagDataBuf
+
stbInfo
->
lenOfTagOfOneRow
*
(
tableSeq
%
stbInfo
->
tagSampleCount
));
}
len
=
snprintf
(
headBuf
,
HEAD_BUFF_LEN
,
"%s.%s using %s.%s TAGS%s values"
,
dbName
,
tableName
,
dbName
,
stbInfo
->
stbName
,
tagsValBuf
);
tmfree
(
tagsValBuf
);
}
else
if
(
TBL_ALREADY_EXISTS
==
stbInfo
->
childTblExists
)
{
len
=
snprintf
(
headBuf
,
HEAD_BUFF_LEN
,
"%s.%s values"
,
dbName
,
tableName
);
}
else
{
len
=
snprintf
(
headBuf
,
HEAD_BUFF_LEN
,
"%s.%s values"
,
dbName
,
tableName
);
}
if
(
len
>
remainderBufLen
)
return
-
1
;
tstrncpy
(
buffer
,
headBuf
,
len
+
1
);
return
len
;
}
static
int32_t
generateStbInterlaceData
(
threadInfo
*
pThreadInfo
,
char
*
tableName
,
uint32_t
batchPerTbl
,
uint64_t
i
,
uint32_t
batchPerTblTimes
,
uint64_t
tableSeq
,
char
*
buffer
,
int64_t
insertRows
,
int64_t
startTime
,
uint64_t
*
pRemainderBufLen
)
{
char
*
pstr
=
buffer
;
SSuperTable
*
stbInfo
=
pThreadInfo
->
stbInfo
;
int
headLen
=
generateStbSQLHead
(
stbInfo
,
tableName
,
tableSeq
,
pThreadInfo
->
db_name
,
pstr
,
(
int
)(
*
pRemainderBufLen
));
if
(
headLen
<=
0
)
{
return
0
;
}
// generate data buffer
verbosePrint
(
"[%d] %s() LN%d i=%"
PRIu64
" buffer:
\n
%s
\n
"
,
pThreadInfo
->
threadID
,
__func__
,
__LINE__
,
i
,
buffer
);
pstr
+=
headLen
;
*
pRemainderBufLen
-=
headLen
;
int64_t
dataLen
=
0
;
verbosePrint
(
"[%d] %s() LN%d i=%"
PRIu64
" batchPerTblTimes=%u batchPerTbl = %u
\n
"
,
pThreadInfo
->
threadID
,
__func__
,
__LINE__
,
i
,
batchPerTblTimes
,
batchPerTbl
);
if
(
0
==
strncasecmp
(
stbInfo
->
startTimestamp
,
"now"
,
3
))
{
startTime
=
taosGetTimestamp
(
pThreadInfo
->
time_precision
);
}
int32_t
k
=
generateStbDataTail
(
stbInfo
,
batchPerTbl
,
pstr
,
*
pRemainderBufLen
,
insertRows
,
0
,
startTime
,
&
(
pThreadInfo
->
samplePos
),
&
dataLen
);
if
(
k
==
batchPerTbl
)
{
pstr
+=
dataLen
;
*
pRemainderBufLen
-=
dataLen
;
}
else
{
debugPrint
(
"%s() LN%d, generated data tail: %u, not equal batch per table: "
"%u
\n
"
,
__func__
,
__LINE__
,
k
,
batchPerTbl
);
pstr
-=
headLen
;
pstr
[
0
]
=
'\0'
;
k
=
0
;
}
return
k
;
}
static
int64_t
generateInterlaceDataWithoutStb
(
char
*
tableName
,
uint32_t
batch
,
uint64_t
tableSeq
,
char
*
dbName
,
char
*
buffer
,
int64_t
insertRows
,
int64_t
startTime
,
uint64_t
*
pRemainderBufLen
)
{
char
*
pstr
=
buffer
;
int
headLen
=
generateSQLHeadWithoutStb
(
tableName
,
dbName
,
pstr
,
(
int
)(
*
pRemainderBufLen
));
if
(
headLen
<=
0
)
{
return
0
;
}
pstr
+=
headLen
;
*
pRemainderBufLen
-=
headLen
;
int64_t
dataLen
=
0
;
int32_t
k
=
generateDataTailWithoutStb
(
batch
,
pstr
,
*
pRemainderBufLen
,
insertRows
,
0
,
startTime
,
&
dataLen
);
if
(
k
==
batch
)
{
pstr
+=
dataLen
;
*
pRemainderBufLen
-=
dataLen
;
}
else
{
debugPrint
(
"%s() LN%d, generated data tail: %d, not equal batch per table: "
"%u
\n
"
,
__func__
,
__LINE__
,
k
,
batch
);
pstr
-=
headLen
;
pstr
[
0
]
=
'\0'
;
k
=
0
;
}
return
k
;
}
static
int32_t
prepareStmtBindArrayByType
(
TAOS_BIND
*
bind
,
char
data_type
,
int32_t
dataLen
,
int32_t
timePrec
,
char
*
value
)
{
int32_t
*
bind_int
;
uint32_t
*
bind_uint
;
int64_t
*
bind_bigint
;
uint64_t
*
bind_ubigint
;
float
*
bind_float
;
double
*
bind_double
;
int8_t
*
bind_bool
;
int64_t
*
bind_ts2
;
int16_t
*
bind_smallint
;
uint16_t
*
bind_usmallint
;
int8_t
*
bind_tinyint
;
uint8_t
*
bind_utinyint
;
switch
(
data_type
)
{
case
TSDB_DATA_TYPE_BINARY
:
if
(
dataLen
>
TSDB_MAX_BINARY_LEN
)
{
errorPrint
(
"binary length overflow, max size:%u
\n
"
,
(
uint32_t
)
TSDB_MAX_BINARY_LEN
);
return
-
1
;
}
char
*
bind_binary
;
bind
->
buffer_type
=
TSDB_DATA_TYPE_BINARY
;
if
(
value
)
{
bind_binary
=
calloc
(
1
,
strlen
(
value
)
+
1
);
strncpy
(
bind_binary
,
value
,
strlen
(
value
));
bind
->
buffer_length
=
strlen
(
bind_binary
);
}
else
{
bind_binary
=
calloc
(
1
,
dataLen
+
1
);
rand_string
(
bind_binary
,
dataLen
);
bind
->
buffer_length
=
dataLen
;
}
bind
->
length
=
&
bind
->
buffer_length
;
bind
->
buffer
=
bind_binary
;
bind
->
is_null
=
NULL
;
break
;
case
TSDB_DATA_TYPE_NCHAR
:
if
(
dataLen
>
TSDB_MAX_BINARY_LEN
)
{
errorPrint
(
"nchar length overflow, max size:%u
\n
"
,
(
uint32_t
)
TSDB_MAX_BINARY_LEN
);
return
-
1
;
}
char
*
bind_nchar
;
bind
->
buffer_type
=
TSDB_DATA_TYPE_NCHAR
;
if
(
value
)
{
bind_nchar
=
calloc
(
1
,
strlen
(
value
)
+
1
);
strncpy
(
bind_nchar
,
value
,
strlen
(
value
));
}
else
{
bind_nchar
=
calloc
(
1
,
dataLen
+
1
);
rand_string
(
bind_nchar
,
dataLen
);
}
bind
->
buffer_length
=
strlen
(
bind_nchar
);
bind
->
buffer
=
bind_nchar
;
bind
->
length
=
&
bind
->
buffer_length
;
bind
->
is_null
=
NULL
;
break
;
case
TSDB_DATA_TYPE_INT
:
bind_int
=
calloc
(
1
,
sizeof
(
int32_t
));
if
(
value
)
{
*
bind_int
=
atoi
(
value
);
}
else
{
*
bind_int
=
rand_int
();
}
bind
->
buffer_type
=
TSDB_DATA_TYPE_INT
;
bind
->
buffer_length
=
sizeof
(
int32_t
);
bind
->
buffer
=
bind_int
;
bind
->
length
=
&
bind
->
buffer_length
;
bind
->
is_null
=
NULL
;
break
;
case
TSDB_DATA_TYPE_UINT
:
bind_uint
=
malloc
(
sizeof
(
uint32_t
));
if
(
value
)
{
*
bind_uint
=
atoi
(
value
);
}
else
{
*
bind_uint
=
rand_int
();
}
bind
->
buffer_type
=
TSDB_DATA_TYPE_UINT
;
bind
->
buffer_length
=
sizeof
(
uint32_t
);
bind
->
buffer
=
bind_uint
;
bind
->
length
=
&
bind
->
buffer_length
;
bind
->
is_null
=
NULL
;
break
;
case
TSDB_DATA_TYPE_BIGINT
:
bind_bigint
=
malloc
(
sizeof
(
int64_t
));
if
(
value
)
{
*
bind_bigint
=
atoll
(
value
);
}
else
{
*
bind_bigint
=
rand_bigint
();
}
bind
->
buffer_type
=
TSDB_DATA_TYPE_BIGINT
;
bind
->
buffer_length
=
sizeof
(
int64_t
);
bind
->
buffer
=
bind_bigint
;
bind
->
length
=
&
bind
->
buffer_length
;
bind
->
is_null
=
NULL
;
break
;
case
TSDB_DATA_TYPE_UBIGINT
:
bind_ubigint
=
malloc
(
sizeof
(
uint64_t
));
if
(
value
)
{
*
bind_ubigint
=
atoll
(
value
);
}
else
{
*
bind_ubigint
=
rand_bigint
();
}
bind
->
buffer_type
=
TSDB_DATA_TYPE_UBIGINT
;
bind
->
buffer_length
=
sizeof
(
uint64_t
);
bind
->
buffer
=
bind_ubigint
;
bind
->
length
=
&
bind
->
buffer_length
;
bind
->
is_null
=
NULL
;
break
;
case
TSDB_DATA_TYPE_FLOAT
:
bind_float
=
malloc
(
sizeof
(
float
));
if
(
value
)
{
*
bind_float
=
(
float
)
atof
(
value
);
}
else
{
*
bind_float
=
rand_float
();
}
bind
->
buffer_type
=
TSDB_DATA_TYPE_FLOAT
;
bind
->
buffer_length
=
sizeof
(
float
);
bind
->
buffer
=
bind_float
;
bind
->
length
=
&
bind
->
buffer_length
;
bind
->
is_null
=
NULL
;
break
;
case
TSDB_DATA_TYPE_DOUBLE
:
bind_double
=
malloc
(
sizeof
(
double
));
if
(
value
)
{
*
bind_double
=
atof
(
value
);
}
else
{
*
bind_double
=
rand_double
();
}
bind
->
buffer_type
=
TSDB_DATA_TYPE_DOUBLE
;
bind
->
buffer_length
=
sizeof
(
double
);
bind
->
buffer
=
bind_double
;
bind
->
length
=
&
bind
->
buffer_length
;
bind
->
is_null
=
NULL
;
break
;
case
TSDB_DATA_TYPE_SMALLINT
:
bind_smallint
=
malloc
(
sizeof
(
int16_t
));
if
(
value
)
{
*
bind_smallint
=
(
int16_t
)
atoi
(
value
);
}
else
{
*
bind_smallint
=
rand_smallint
();
}
bind
->
buffer_type
=
TSDB_DATA_TYPE_SMALLINT
;
bind
->
buffer_length
=
sizeof
(
int16_t
);
bind
->
buffer
=
bind_smallint
;
bind
->
length
=
&
bind
->
buffer_length
;
bind
->
is_null
=
NULL
;
break
;
case
TSDB_DATA_TYPE_USMALLINT
:
bind_usmallint
=
malloc
(
sizeof
(
uint16_t
));
if
(
value
)
{
*
bind_usmallint
=
(
uint16_t
)
atoi
(
value
);
}
else
{
*
bind_usmallint
=
rand_smallint
();
}
bind
->
buffer_type
=
TSDB_DATA_TYPE_SMALLINT
;
bind
->
buffer_length
=
sizeof
(
uint16_t
);
bind
->
buffer
=
bind_usmallint
;
bind
->
length
=
&
bind
->
buffer_length
;
bind
->
is_null
=
NULL
;
break
;
case
TSDB_DATA_TYPE_TINYINT
:
bind_tinyint
=
malloc
(
sizeof
(
int8_t
));
if
(
value
)
{
*
bind_tinyint
=
(
int8_t
)
atoi
(
value
);
}
else
{
*
bind_tinyint
=
rand_tinyint
();
}
bind
->
buffer_type
=
TSDB_DATA_TYPE_TINYINT
;
bind
->
buffer_length
=
sizeof
(
int8_t
);
bind
->
buffer
=
bind_tinyint
;
bind
->
length
=
&
bind
->
buffer_length
;
bind
->
is_null
=
NULL
;
break
;
case
TSDB_DATA_TYPE_UTINYINT
:
bind_utinyint
=
malloc
(
sizeof
(
uint8_t
));
if
(
value
)
{
*
bind_utinyint
=
(
int8_t
)
atoi
(
value
);
}
else
{
*
bind_utinyint
=
rand_tinyint
();
}
bind
->
buffer_type
=
TSDB_DATA_TYPE_UTINYINT
;
bind
->
buffer_length
=
sizeof
(
uint8_t
);
bind
->
buffer
=
bind_utinyint
;
bind
->
length
=
&
bind
->
buffer_length
;
bind
->
is_null
=
NULL
;
break
;
case
TSDB_DATA_TYPE_BOOL
:
bind_bool
=
malloc
(
sizeof
(
int8_t
));
if
(
value
)
{
if
(
strncasecmp
(
value
,
"true"
,
4
))
{
*
bind_bool
=
true
;
}
else
{
*
bind_bool
=
false
;
}
}
else
{
*
bind_bool
=
rand_bool
();
}
bind
->
buffer_type
=
TSDB_DATA_TYPE_BOOL
;
bind
->
buffer_length
=
sizeof
(
int8_t
);
bind
->
buffer
=
bind_bool
;
bind
->
length
=
&
bind
->
buffer_length
;
bind
->
is_null
=
NULL
;
break
;
case
TSDB_DATA_TYPE_TIMESTAMP
:
bind_ts2
=
malloc
(
sizeof
(
int64_t
));
if
(
value
)
{
if
(
strchr
(
value
,
':'
)
&&
strchr
(
value
,
'-'
))
{
int
i
=
0
;
while
(
value
[
i
]
!=
'\0'
)
{
if
(
value
[
i
]
==
'\"'
||
value
[
i
]
==
'\''
)
{
value
[
i
]
=
' '
;
}
i
++
;
}
int64_t
tmpEpoch
;
if
(
TSDB_CODE_SUCCESS
!=
taosParseTime
(
value
,
&
tmpEpoch
,
(
int32_t
)
strlen
(
value
),
timePrec
,
0
))
{
free
(
bind_ts2
);
errorPrint
(
"Input %s, time format error!
\n
"
,
value
);
return
-
1
;
}
*
bind_ts2
=
tmpEpoch
;
}
else
{
*
bind_ts2
=
atoll
(
value
);
}
}
else
{
*
bind_ts2
=
rand_bigint
();
}
bind
->
buffer_type
=
TSDB_DATA_TYPE_TIMESTAMP
;
bind
->
buffer_length
=
sizeof
(
int64_t
);
bind
->
buffer
=
bind_ts2
;
bind
->
length
=
&
bind
->
buffer_length
;
bind
->
is_null
=
NULL
;
break
;
case
TSDB_DATA_TYPE_NULL
:
break
;
default:
errorPrint
(
"Not support data type: %d
\n
"
,
data_type
);
return
-
1
;
}
return
0
;
}
static
int32_t
prepareStmtWithoutStb
(
threadInfo
*
pThreadInfo
,
char
*
tableName
,
uint32_t
batch
,
int64_t
insertRows
,
int64_t
recordFrom
,
int64_t
startTime
)
{
TAOS_STMT
*
stmt
=
pThreadInfo
->
stmt
;
int
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_stmt_errstr
(
stmt
));
return
ret
;
}
char
*
data_type
=
g_args
.
data_type
;
char
*
bindArray
=
malloc
(
sizeof
(
TAOS_BIND
)
*
(
g_args
.
columnCount
+
1
));
if
(
bindArray
==
NULL
)
{
errorPrint
(
"Failed to allocate %d bind params
\n
"
,
(
g_args
.
columnCount
+
1
));
return
-
1
;
}
int32_t
k
=
0
;
for
(
k
=
0
;
k
<
batch
;)
{
/* columnCount + 1 (ts) */
TAOS_BIND
*
bind
=
(
TAOS_BIND
*
)(
bindArray
+
0
);
int64_t
*
bind_ts
=
pThreadInfo
->
bind_ts
;
bind
->
buffer_type
=
TSDB_DATA_TYPE_TIMESTAMP
;
if
(
g_args
.
disorderRatio
)
{
*
bind_ts
=
startTime
+
getTSRandTail
(
g_args
.
timestamp_step
,
k
,
g_args
.
disorderRatio
,
g_args
.
disorderRange
);
}
else
{
*
bind_ts
=
startTime
+
g_args
.
timestamp_step
*
k
;
}
bind
->
buffer_length
=
sizeof
(
int64_t
);
bind
->
buffer
=
bind_ts
;
bind
->
length
=
&
bind
->
buffer_length
;
bind
->
is_null
=
NULL
;
for
(
int
i
=
0
;
i
<
g_args
.
columnCount
;
i
++
)
{
bind
=
(
TAOS_BIND
*
)((
char
*
)
bindArray
+
(
sizeof
(
TAOS_BIND
)
*
(
i
+
1
)));
if
(
-
1
==
prepareStmtBindArrayByType
(
bind
,
data_type
[
i
],
g_args
.
binwidth
,
pThreadInfo
->
time_precision
,
NULL
))
{
free
(
bindArray
);
return
-
1
;
}
}
if
(
taos_stmt_bind_param
(
stmt
,
(
TAOS_BIND
*
)
bindArray
))
{
errorPrint
(
"taos_stmt_bind_param() failed! reason: %s
\n
"
,
taos_stmt_errstr
(
stmt
));
break
;
}
// if msg > 3MB, break
if
(
taos_stmt_add_batch
(
stmt
))
{
errorPrint
(
"taos_stmt_add_batch() failed! reason: %s
\n
"
,
taos_stmt_errstr
(
stmt
));
break
;
}
k
++
;
recordFrom
++
;
if
(
recordFrom
>=
insertRows
)
{
break
;
}
}
free
(
bindArray
);
return
k
;
}
static
int32_t
prepareStbStmtBindTag
(
char
*
bindArray
,
SSuperTable
*
stbInfo
,
char
*
tagsVal
,
int32_t
timePrec
)
{
TAOS_BIND
*
tag
;
for
(
int
t
=
0
;
t
<
stbInfo
->
tagCount
;
t
++
)
{
tag
=
(
TAOS_BIND
*
)((
char
*
)
bindArray
+
(
sizeof
(
TAOS_BIND
)
*
t
));
if
(
prepareStmtBindArrayByType
(
tag
,
stbInfo
->
tags
[
t
].
data_type
,
stbInfo
->
tags
[
t
].
dataLen
,
timePrec
,
NULL
))
{
return
-
1
;
}
}
return
0
;
}
static
int
execStbBindParamBatch
(
threadInfo
*
pThreadInfo
,
char
*
tableName
,
int64_t
tableSeq
,
uint32_t
batch
,
uint64_t
insertRows
,
uint64_t
recordFrom
,
int64_t
startTime
,
int64_t
*
pSamplePos
)
{
TAOS_STMT
*
stmt
=
pThreadInfo
->
stmt
;
SSuperTable
*
stbInfo
=
pThreadInfo
->
stbInfo
;
uint32_t
columnCount
=
pThreadInfo
->
stbInfo
->
columnCount
;
uint32_t
thisBatch
=
(
uint32_t
)(
MAX_SAMPLES
-
(
*
pSamplePos
));
if
(
thisBatch
>
batch
)
{
thisBatch
=
batch
;
}
verbosePrint
(
"%s() LN%d, batch=%d pos=%"
PRId64
" thisBatch=%d
\n
"
,
__func__
,
__LINE__
,
batch
,
*
pSamplePos
,
thisBatch
);
memset
(
pThreadInfo
->
bindParams
,
0
,
memset
(
pThreadInfo
->
bindParams
,
0
,
(
sizeof
(
TAOS_MULTI_BIND
)
*
(
columnCount
+
1
)));
(
sizeof
(
TAOS_MULTI_BIND
)
*
(
columnCount
+
1
)));
...
@@ -2890,250 +1511,6 @@ static int execStbBindParamBatch(threadInfo *pThreadInfo, char *tableName,
...
@@ -2890,250 +1511,6 @@ static int execStbBindParamBatch(threadInfo *pThreadInfo, char *tableName,
return
k
;
return
k
;
}
}
static
int
parseSamplefileToStmtBatch
(
SSuperTable
*
stbInfo
)
{
// char *sampleDataBuf = (stbInfo)?
// stbInfo->sampleDataBuf:g_sampleDataBuf;
int32_t
columnCount
=
(
stbInfo
)
?
stbInfo
->
columnCount
:
g_args
.
columnCount
;
char
*
sampleBindBatchArray
=
NULL
;
if
(
stbInfo
)
{
stbInfo
->
sampleBindBatchArray
=
calloc
(
1
,
sizeof
(
uintptr_t
*
)
*
columnCount
);
sampleBindBatchArray
=
stbInfo
->
sampleBindBatchArray
;
}
else
{
g_sampleBindBatchArray
=
calloc
(
1
,
sizeof
(
uintptr_t
*
)
*
columnCount
);
sampleBindBatchArray
=
g_sampleBindBatchArray
;
}
for
(
int
c
=
0
;
c
<
columnCount
;
c
++
)
{
char
data_type
=
(
stbInfo
)
?
stbInfo
->
columns
[
c
].
data_type
:
g_args
.
data_type
[
c
];
char
*
tmpP
=
NULL
;
switch
(
data_type
)
{
case
TSDB_DATA_TYPE_INT
:
case
TSDB_DATA_TYPE_UINT
:
tmpP
=
calloc
(
1
,
sizeof
(
int32_t
)
*
MAX_SAMPLES
);
*
(
uintptr_t
*
)(
sampleBindBatchArray
+
sizeof
(
uintptr_t
*
)
*
c
)
=
(
uintptr_t
)
tmpP
;
break
;
case
TSDB_DATA_TYPE_TINYINT
:
case
TSDB_DATA_TYPE_UTINYINT
:
tmpP
=
calloc
(
1
,
sizeof
(
char
)
*
MAX_SAMPLES
);
*
(
uintptr_t
*
)(
sampleBindBatchArray
+
sizeof
(
uintptr_t
*
)
*
c
)
=
(
uintptr_t
)
tmpP
;
break
;
case
TSDB_DATA_TYPE_SMALLINT
:
case
TSDB_DATA_TYPE_USMALLINT
:
tmpP
=
calloc
(
1
,
sizeof
(
int16_t
)
*
MAX_SAMPLES
);
*
(
uintptr_t
*
)(
sampleBindBatchArray
+
sizeof
(
uintptr_t
*
)
*
c
)
=
(
uintptr_t
)
tmpP
;
break
;
case
TSDB_DATA_TYPE_BIGINT
:
case
TSDB_DATA_TYPE_UBIGINT
:
tmpP
=
calloc
(
1
,
sizeof
(
int64_t
)
*
MAX_SAMPLES
);
*
(
uintptr_t
*
)(
sampleBindBatchArray
+
sizeof
(
uintptr_t
*
)
*
c
)
=
(
uintptr_t
)
tmpP
;
break
;
case
TSDB_DATA_TYPE_BOOL
:
tmpP
=
calloc
(
1
,
sizeof
(
char
)
*
MAX_SAMPLES
);
*
(
uintptr_t
*
)(
sampleBindBatchArray
+
sizeof
(
uintptr_t
*
)
*
c
)
=
(
uintptr_t
)
tmpP
;
break
;
case
TSDB_DATA_TYPE_FLOAT
:
tmpP
=
calloc
(
1
,
sizeof
(
float
)
*
MAX_SAMPLES
);
*
(
uintptr_t
*
)(
sampleBindBatchArray
+
sizeof
(
uintptr_t
*
)
*
c
)
=
(
uintptr_t
)
tmpP
;
break
;
case
TSDB_DATA_TYPE_DOUBLE
:
tmpP
=
calloc
(
1
,
sizeof
(
double
)
*
MAX_SAMPLES
);
*
(
uintptr_t
*
)(
sampleBindBatchArray
+
sizeof
(
uintptr_t
*
)
*
c
)
=
(
uintptr_t
)
tmpP
;
break
;
case
TSDB_DATA_TYPE_BINARY
:
case
TSDB_DATA_TYPE_NCHAR
:
tmpP
=
calloc
(
1
,
MAX_SAMPLES
*
(((
stbInfo
)
?
stbInfo
->
columns
[
c
].
dataLen
:
g_args
.
binwidth
)
+
1
));
*
(
uintptr_t
*
)(
sampleBindBatchArray
+
sizeof
(
uintptr_t
*
)
*
c
)
=
(
uintptr_t
)
tmpP
;
break
;
case
TSDB_DATA_TYPE_TIMESTAMP
:
tmpP
=
calloc
(
1
,
sizeof
(
int64_t
)
*
MAX_SAMPLES
);
*
(
uintptr_t
*
)(
sampleBindBatchArray
+
sizeof
(
uintptr_t
*
)
*
c
)
=
(
uintptr_t
)
tmpP
;
break
;
default:
errorPrint
(
"Unknown data type: %s
\n
"
,
(
stbInfo
)
?
stbInfo
->
columns
[
c
].
dataType
:
g_args
.
dataType
[
c
]);
exit
(
EXIT_FAILURE
);
}
}
char
*
sampleDataBuf
=
(
stbInfo
)
?
stbInfo
->
sampleDataBuf
:
g_sampleDataBuf
;
int64_t
lenOfOneRow
=
(
stbInfo
)
?
stbInfo
->
lenOfOneRow
:
g_args
.
lenOfOneRow
;
for
(
int
i
=
0
;
i
<
MAX_SAMPLES
;
i
++
)
{
int
cursor
=
0
;
for
(
int
c
=
0
;
c
<
columnCount
;
c
++
)
{
char
data_type
=
(
stbInfo
)
?
stbInfo
->
columns
[
c
].
data_type
:
g_args
.
data_type
[
c
];
char
*
restStr
=
sampleDataBuf
+
lenOfOneRow
*
i
+
cursor
;
int
lengthOfRest
=
(
int
)
strlen
(
restStr
);
int
index
=
0
;
for
(
index
=
0
;
index
<
lengthOfRest
;
index
++
)
{
if
(
restStr
[
index
]
==
','
)
{
break
;
}
}
char
*
tmpStr
=
calloc
(
1
,
index
+
1
);
if
(
NULL
==
tmpStr
)
{
errorPrint
(
"%s"
,
"failed to allocate memory
\n
"
);
return
-
1
;
}
strncpy
(
tmpStr
,
restStr
,
index
);
cursor
+=
index
+
1
;
// skip ',' too
char
*
tmpP
;
switch
(
data_type
)
{
case
TSDB_DATA_TYPE_INT
:
case
TSDB_DATA_TYPE_UINT
:
*
((
int32_t
*
)((
uintptr_t
)
*
(
uintptr_t
*
)(
sampleBindBatchArray
+
sizeof
(
char
*
)
*
c
)
+
sizeof
(
int32_t
)
*
i
))
=
atoi
(
tmpStr
);
break
;
case
TSDB_DATA_TYPE_FLOAT
:
*
(
float
*
)(((
uintptr_t
)
*
(
uintptr_t
*
)(
sampleBindBatchArray
+
sizeof
(
char
*
)
*
c
)
+
sizeof
(
float
)
*
i
))
=
(
float
)
atof
(
tmpStr
);
break
;
case
TSDB_DATA_TYPE_DOUBLE
:
*
(
double
*
)(((
uintptr_t
)
*
(
uintptr_t
*
)(
sampleBindBatchArray
+
sizeof
(
char
*
)
*
c
)
+
sizeof
(
double
)
*
i
))
=
atof
(
tmpStr
);
break
;
case
TSDB_DATA_TYPE_TINYINT
:
case
TSDB_DATA_TYPE_UTINYINT
:
*
((
int8_t
*
)((
uintptr_t
)
*
(
uintptr_t
*
)(
sampleBindBatchArray
+
sizeof
(
char
*
)
*
c
)
+
sizeof
(
int8_t
)
*
i
))
=
(
int8_t
)
atoi
(
tmpStr
);
break
;
case
TSDB_DATA_TYPE_SMALLINT
:
case
TSDB_DATA_TYPE_USMALLINT
:
*
((
int16_t
*
)((
uintptr_t
)
*
(
uintptr_t
*
)(
sampleBindBatchArray
+
sizeof
(
char
*
)
*
c
)
+
sizeof
(
int16_t
)
*
i
))
=
(
int16_t
)
atoi
(
tmpStr
);
break
;
case
TSDB_DATA_TYPE_BIGINT
:
case
TSDB_DATA_TYPE_UBIGINT
:
*
((
int64_t
*
)((
uintptr_t
)
*
(
uintptr_t
*
)(
sampleBindBatchArray
+
sizeof
(
char
*
)
*
c
)
+
sizeof
(
int64_t
)
*
i
))
=
(
int64_t
)
atol
(
tmpStr
);
break
;
case
TSDB_DATA_TYPE_BOOL
:
*
((
int8_t
*
)((
uintptr_t
)
*
(
uintptr_t
*
)(
sampleBindBatchArray
+
sizeof
(
char
*
)
*
c
)
+
sizeof
(
int8_t
)
*
i
))
=
(
int8_t
)
atoi
(
tmpStr
);
break
;
case
TSDB_DATA_TYPE_TIMESTAMP
:
*
((
int64_t
*
)((
uintptr_t
)
*
(
uintptr_t
*
)(
sampleBindBatchArray
+
sizeof
(
char
*
)
*
c
)
+
sizeof
(
int64_t
)
*
i
))
=
(
int64_t
)
atol
(
tmpStr
);
break
;
case
TSDB_DATA_TYPE_BINARY
:
case
TSDB_DATA_TYPE_NCHAR
:
tmpP
=
(
char
*
)(
*
(
uintptr_t
*
)(
sampleBindBatchArray
+
sizeof
(
char
*
)
*
c
));
strcpy
(
tmpP
+
i
*
(((
stbInfo
)
?
stbInfo
->
columns
[
c
].
dataLen
:
g_args
.
binwidth
)),
tmpStr
);
break
;
default:
break
;
}
free
(
tmpStr
);
}
}
return
0
;
}
static
int
parseSampleToStmtBatchForThread
(
threadInfo
*
pThreadInfo
,
SSuperTable
*
stbInfo
,
uint32_t
timePrec
,
uint32_t
batch
)
{
uint32_t
columnCount
=
(
stbInfo
)
?
stbInfo
->
columnCount
:
g_args
.
columnCount
;
pThreadInfo
->
bind_ts_array
=
calloc
(
1
,
sizeof
(
int64_t
)
*
batch
);
if
(
NULL
==
pThreadInfo
->
bind_ts_array
)
{
errorPrint
(
"%s"
,
"failed to allocate memory
\n
"
);
return
-
1
;
}
pThreadInfo
->
bindParams
=
calloc
(
1
,
sizeof
(
TAOS_MULTI_BIND
)
*
(
columnCount
+
1
));
if
(
NULL
==
pThreadInfo
->
bindParams
)
{
errorPrint
(
"%s"
,
"failed to allocate memory
\n
"
);
return
-
1
;
}
pThreadInfo
->
is_null
=
calloc
(
1
,
batch
);
if
(
NULL
==
pThreadInfo
->
is_null
)
{
errorPrint
(
"%s"
,
"failed to allocate memory
\n
"
);
return
-
1
;
}
return
0
;
}
static
int
parseStbSampleToStmtBatchForThread
(
threadInfo
*
pThreadInfo
,
SSuperTable
*
stbInfo
,
uint32_t
timePrec
,
uint32_t
batch
)
{
return
parseSampleToStmtBatchForThread
(
pThreadInfo
,
stbInfo
,
timePrec
,
batch
);
}
static
int
parseNtbSampleToStmtBatchForThread
(
threadInfo
*
pThreadInfo
,
uint32_t
timePrec
,
uint32_t
batch
)
{
return
parseSampleToStmtBatchForThread
(
pThreadInfo
,
NULL
,
timePrec
,
batch
);
}
int32_t
prepareStbStmt
(
threadInfo
*
pThreadInfo
,
char
*
tableName
,
int32_t
prepareStbStmt
(
threadInfo
*
pThreadInfo
,
char
*
tableName
,
int64_t
tableSeq
,
uint32_t
batch
,
uint64_t
insertRows
,
int64_t
tableSeq
,
uint32_t
batch
,
uint64_t
insertRows
,
uint64_t
recordFrom
,
int64_t
startTime
,
uint64_t
recordFrom
,
int64_t
startTime
,
...
@@ -3183,61 +1560,9 @@ int32_t prepareStbStmt(threadInfo *pThreadInfo, char *tableName,
...
@@ -3183,61 +1560,9 @@ int32_t prepareStbStmt(threadInfo *pThreadInfo, char *tableName,
}
}
}
}
tmfree
(
tagsValBuf
);
tmfree
(
tagsValBuf
);
tmfree
(
tagsArray
);
tmfree
(
tagsArray
);
return
execStbBindParamBatch
(
pThreadInfo
,
tableName
,
tableSeq
,
batch
,
return
execStbBindParamBatch
(
pThreadInfo
,
tableName
,
tableSeq
,
batch
,
insertRows
,
recordFrom
,
startTime
,
pSamplePos
);
insertRows
,
recordFrom
,
startTime
,
pSamplePos
);
}
int32_t
generateStbProgressiveData
(
SSuperTable
*
stbInfo
,
char
*
tableName
,
int64_t
tableSeq
,
char
*
dbName
,
char
*
buffer
,
int64_t
insertRows
,
uint64_t
recordFrom
,
int64_t
startTime
,
int64_t
*
pSamplePos
,
int64_t
*
pRemainderBufLen
)
{
char
*
pstr
=
buffer
;
memset
(
pstr
,
0
,
*
pRemainderBufLen
);
int64_t
headLen
=
generateStbSQLHead
(
stbInfo
,
tableName
,
tableSeq
,
dbName
,
buffer
,
(
int
)(
*
pRemainderBufLen
));
if
(
headLen
<=
0
)
{
return
0
;
}
pstr
+=
headLen
;
*
pRemainderBufLen
-=
headLen
;
int64_t
dataLen
;
return
generateStbDataTail
(
stbInfo
,
g_args
.
reqPerReq
,
pstr
,
*
pRemainderBufLen
,
insertRows
,
recordFrom
,
startTime
,
pSamplePos
,
&
dataLen
);
}
int32_t
generateProgressiveDataWithoutStb
(
char
*
tableName
,
threadInfo
*
pThreadInfo
,
char
*
buffer
,
int64_t
insertRows
,
uint64_t
recordFrom
,
int64_t
startTime
,
int64_t
*
pRemainderBufLen
)
{
char
*
pstr
=
buffer
;
memset
(
buffer
,
0
,
*
pRemainderBufLen
);
int64_t
headLen
=
generateSQLHeadWithoutStb
(
tableName
,
pThreadInfo
->
db_name
,
buffer
,
(
int
)(
*
pRemainderBufLen
));
if
(
headLen
<=
0
)
{
return
0
;
}
pstr
+=
headLen
;
*
pRemainderBufLen
-=
headLen
;
int64_t
dataLen
;
return
generateDataTailWithoutStb
(
g_args
.
reqPerReq
,
pstr
,
*
pRemainderBufLen
,
insertRows
,
recordFrom
,
startTime
,
/*pSamplePos, */
&
dataLen
);
}
}
// stmt sync write interlace data
// stmt sync write interlace data
...
@@ -3380,22 +1705,275 @@ static void *syncWriteInterlaceStmtBatch(threadInfo *pThreadInfo,
...
@@ -3380,22 +1705,275 @@ static void *syncWriteInterlaceStmtBatch(threadInfo *pThreadInfo,
"%s() LN%d, insert execution time is %10.2f ms
\n
"
,
__func__
,
"%s() LN%d, insert execution time is %10.2f ms
\n
"
,
__func__
,
__LINE__
,
delay
/
1000
.
0
);
__LINE__
,
delay
/
1000
.
0
);
verbosePrint
(
"[%d] %s() LN%d affectedRows=%"
PRId64
"
\n
"
,
verbosePrint
(
"[%d] %s() LN%d affectedRows=%"
PRId64
"
\n
"
,
pThreadInfo
->
threadID
,
__func__
,
__LINE__
,
pThreadInfo
->
threadID
,
__func__
,
__LINE__
,
affectedRows
);
affectedRows
);
if
(
delay
>
pThreadInfo
->
maxDelay
)
pThreadInfo
->
maxDelay
=
delay
;
if
(
delay
<
pThreadInfo
->
minDelay
)
pThreadInfo
->
minDelay
=
delay
;
pThreadInfo
->
cntDelay
++
;
pThreadInfo
->
totalDelay
+=
delay
;
if
(
generated
!=
affectedRows
)
{
errorPrint
(
"[%d] %s() LN%d execInsert() insert %"
PRId64
", affected rows: %"
PRId64
"
\n\n
"
,
pThreadInfo
->
threadID
,
__func__
,
__LINE__
,
generated
,
affectedRows
);
goto
free_of_interlace_stmt
;
}
pThreadInfo
->
totalAffectedRows
+=
affectedRows
;
int
currentPercent
=
(
int
)(
pThreadInfo
->
totalAffectedRows
*
100
/
totalRows
);
if
(
currentPercent
>
percentComplete
)
{
printf
(
"[%d]:%d%%
\n
"
,
pThreadInfo
->
threadID
,
currentPercent
);
percentComplete
=
currentPercent
;
}
int64_t
currentPrintTime
=
taosGetTimestampMs
();
if
(
currentPrintTime
-
lastPrintTime
>
30
*
1000
)
{
printf
(
"thread[%d] has currently inserted rows: %"
PRIu64
", affected rows: %"
PRIu64
"
\n
"
,
pThreadInfo
->
threadID
,
pThreadInfo
->
totalInsertRows
,
pThreadInfo
->
totalAffectedRows
);
lastPrintTime
=
currentPrintTime
;
}
startTime
+=
(
generated
*
timeStampStep
);
}
}
pThreadInfo
->
samplePos
=
samplePos
;
if
(
tableSeq
==
pThreadInfo
->
start_table_from
+
pThreadInfo
->
ntables
)
{
// turn to first table
tableSeq
=
pThreadInfo
->
start_table_from
;
flagSleep
=
true
;
}
if
((
insert_interval
)
&&
flagSleep
)
{
et
=
taosGetTimestampMs
();
if
(
insert_interval
>
(
et
-
st
))
{
uint64_t
sleepTime
=
insert_interval
-
(
et
-
st
);
performancePrint
(
"%s() LN%d sleep: %"
PRId64
" ms for insert interval
\n
"
,
__func__
,
__LINE__
,
sleepTime
);
taosMsleep
((
int32_t
)
sleepTime
);
// ms
sleepTimeTotal
+=
insert_interval
;
}
}
}
if
(
percentComplete
<
100
)
printf
(
"[%d]:%d%%
\n
"
,
pThreadInfo
->
threadID
,
percentComplete
);
free_of_interlace_stmt:
printStatPerThread
(
pThreadInfo
);
return
NULL
;
}
void
*
syncWriteInterlace
(
threadInfo
*
pThreadInfo
,
uint32_t
interlaceRows
)
{
debugPrint
(
"[%d] %s() LN%d: ### interlace write
\n
"
,
pThreadInfo
->
threadID
,
__func__
,
__LINE__
);
int64_t
insertRows
;
uint64_t
maxSqlLen
;
int64_t
timeStampStep
;
uint64_t
insert_interval
;
SSuperTable
*
stbInfo
=
pThreadInfo
->
stbInfo
;
if
(
stbInfo
)
{
insertRows
=
stbInfo
->
insertRows
;
maxSqlLen
=
stbInfo
->
maxSqlLen
;
timeStampStep
=
stbInfo
->
timeStampStep
;
insert_interval
=
stbInfo
->
insertInterval
;
}
else
{
insertRows
=
g_args
.
insertRows
;
maxSqlLen
=
g_args
.
max_sql_len
;
timeStampStep
=
g_args
.
timestamp_step
;
insert_interval
=
g_args
.
insert_interval
;
}
debugPrint
(
"[%d] %s() LN%d: start_table_from=%"
PRIu64
" ntables=%"
PRId64
" insertRows=%"
PRIu64
"
\n
"
,
pThreadInfo
->
threadID
,
__func__
,
__LINE__
,
pThreadInfo
->
start_table_from
,
pThreadInfo
->
ntables
,
insertRows
);
if
(
interlaceRows
>
g_args
.
reqPerReq
)
interlaceRows
=
g_args
.
reqPerReq
;
uint32_t
batchPerTbl
=
interlaceRows
;
uint32_t
batchPerTblTimes
;
if
((
interlaceRows
>
0
)
&&
(
pThreadInfo
->
ntables
>
1
))
{
batchPerTblTimes
=
g_args
.
reqPerReq
/
interlaceRows
;
}
else
{
batchPerTblTimes
=
1
;
}
pThreadInfo
->
buffer
=
calloc
(
maxSqlLen
,
1
);
if
(
NULL
==
pThreadInfo
->
buffer
)
{
errorPrint
(
"%s"
,
"failed to allocate memory
\n
"
);
return
NULL
;
}
pThreadInfo
->
totalInsertRows
=
0
;
pThreadInfo
->
totalAffectedRows
=
0
;
uint64_t
st
=
0
;
uint64_t
et
=
UINT64_MAX
;
uint64_t
lastPrintTime
=
taosGetTimestampMs
();
uint64_t
startTs
=
taosGetTimestampMs
();
uint64_t
endTs
;
uint64_t
tableSeq
=
pThreadInfo
->
start_table_from
;
int64_t
startTime
=
pThreadInfo
->
start_time
;
uint64_t
generatedRecPerTbl
=
0
;
bool
flagSleep
=
true
;
uint64_t
sleepTimeTotal
=
0
;
int
percentComplete
=
0
;
int64_t
totalRows
=
insertRows
*
pThreadInfo
->
ntables
;
while
(
pThreadInfo
->
totalInsertRows
<
pThreadInfo
->
ntables
*
insertRows
)
{
if
((
flagSleep
)
&&
(
insert_interval
))
{
st
=
taosGetTimestampMs
();
flagSleep
=
false
;
}
// generate data
memset
(
pThreadInfo
->
buffer
,
0
,
maxSqlLen
);
uint64_t
remainderBufLen
=
maxSqlLen
;
char
*
pstr
=
pThreadInfo
->
buffer
;
int
len
=
snprintf
(
pstr
,
strlen
(
STR_INSERT_INTO
)
+
1
,
"%s"
,
STR_INSERT_INTO
);
pstr
+=
len
;
remainderBufLen
-=
len
;
uint32_t
recOfBatch
=
0
;
int32_t
generated
;
for
(
uint64_t
i
=
0
;
i
<
batchPerTblTimes
;
i
++
)
{
char
tableName
[
TSDB_TABLE_NAME_LEN
];
getTableName
(
tableName
,
pThreadInfo
,
tableSeq
);
if
(
0
==
strlen
(
tableName
))
{
errorPrint
(
"[%d] %s() LN%d, getTableName return null
\n
"
,
pThreadInfo
->
threadID
,
__func__
,
__LINE__
);
free
(
pThreadInfo
->
buffer
);
return
NULL
;
}
uint64_t
oldRemainderLen
=
remainderBufLen
;
if
(
stbInfo
)
{
generated
=
generateStbInterlaceData
(
pThreadInfo
,
tableName
,
batchPerTbl
,
i
,
batchPerTblTimes
,
tableSeq
,
pstr
,
insertRows
,
startTime
,
&
remainderBufLen
);
}
else
{
generated
=
(
int32_t
)
generateInterlaceDataWithoutStb
(
tableName
,
batchPerTbl
,
tableSeq
,
pThreadInfo
->
db_name
,
pstr
,
insertRows
,
startTime
,
&
remainderBufLen
);
}
debugPrint
(
"[%d] %s() LN%d, generated records is %d
\n
"
,
pThreadInfo
->
threadID
,
__func__
,
__LINE__
,
generated
);
if
(
generated
<
0
)
{
errorPrint
(
"[%d] %s() LN%d, generated records is %d
\n
"
,
pThreadInfo
->
threadID
,
__func__
,
__LINE__
,
generated
);
goto
free_of_interlace
;
}
else
if
(
generated
==
0
)
{
break
;
}
tableSeq
++
;
recOfBatch
+=
batchPerTbl
;
pstr
+=
(
oldRemainderLen
-
remainderBufLen
);
pThreadInfo
->
totalInsertRows
+=
batchPerTbl
;
verbosePrint
(
"[%d] %s() LN%d batchPerTbl=%d recOfBatch=%d
\n
"
,
pThreadInfo
->
threadID
,
__func__
,
__LINE__
,
batchPerTbl
,
recOfBatch
);
if
(
tableSeq
==
pThreadInfo
->
start_table_from
+
pThreadInfo
->
ntables
)
{
// turn to first table
tableSeq
=
pThreadInfo
->
start_table_from
;
generatedRecPerTbl
+=
batchPerTbl
;
startTime
=
pThreadInfo
->
start_time
+
generatedRecPerTbl
*
timeStampStep
;
flagSleep
=
true
;
if
(
generatedRecPerTbl
>=
insertRows
)
break
;
int64_t
remainRows
=
insertRows
-
generatedRecPerTbl
;
if
((
remainRows
>
0
)
&&
(
batchPerTbl
>
remainRows
))
batchPerTbl
=
(
uint32_t
)
remainRows
;
if
(
pThreadInfo
->
ntables
*
batchPerTbl
<
g_args
.
reqPerReq
)
break
;
}
verbosePrint
(
"[%d] %s() LN%d generatedRecPerTbl=%"
PRId64
" insertRows=%"
PRId64
"
\n
"
,
pThreadInfo
->
threadID
,
__func__
,
__LINE__
,
generatedRecPerTbl
,
insertRows
);
if
((
g_args
.
reqPerReq
-
recOfBatch
)
<
batchPerTbl
)
break
;
}
verbosePrint
(
"[%d] %s() LN%d recOfBatch=%d totalInsertRows=%"
PRIu64
"
\n
"
,
pThreadInfo
->
threadID
,
__func__
,
__LINE__
,
recOfBatch
,
pThreadInfo
->
totalInsertRows
);
verbosePrint
(
"[%d] %s() LN%d, buffer=%s
\n
"
,
pThreadInfo
->
threadID
,
__func__
,
__LINE__
,
pThreadInfo
->
buffer
);
startTs
=
taosGetTimestampUs
();
if
(
recOfBatch
==
0
)
{
errorPrint
(
"[%d] %s() LN%d Failed to insert records of batch %d
\n
"
,
pThreadInfo
->
threadID
,
__func__
,
__LINE__
,
batchPerTbl
);
if
(
batchPerTbl
>
0
)
{
errorPrint
(
"
\t
If the batch is %d, the length of the SQL to insert a "
"row must be less then %"
PRId64
"
\n
"
,
batchPerTbl
,
maxSqlLen
/
batchPerTbl
);
}
errorPrint
(
"
\t
Please check if the buffer length(%"
PRId64
") or batch(%d) is set with proper value!
\n
"
,
maxSqlLen
,
batchPerTbl
);
goto
free_of_interlace
;
}
int64_t
affectedRows
=
execInsert
(
pThreadInfo
,
recOfBatch
);
endTs
=
taosGetTimestampUs
();
uint64_t
delay
=
endTs
-
startTs
;
performancePrint
(
"%s() LN%d, insert execution time is %10.2f ms
\n
"
,
__func__
,
__LINE__
,
delay
/
1000
.
0
);
verbosePrint
(
"[%d] %s() LN%d affectedRows=%"
PRId64
"
\n
"
,
pThreadInfo
->
threadID
,
__func__
,
__LINE__
,
affectedRows
);
if
(
delay
>
pThreadInfo
->
maxDelay
)
if
(
delay
>
pThreadInfo
->
maxDelay
)
pThreadInfo
->
maxDelay
=
delay
;
pThreadInfo
->
maxDelay
=
delay
;
if
(
delay
<
pThreadInfo
->
minDelay
)
pThreadInfo
->
minDelay
=
delay
;
if
(
delay
<
pThreadInfo
->
minDelay
)
pThreadInfo
->
minDelay
=
delay
;
pThreadInfo
->
cntDelay
++
;
pThreadInfo
->
cntDelay
++
;
pThreadInfo
->
totalDelay
+=
delay
;
pThreadInfo
->
totalDelay
+=
delay
;
if
(
generated
!=
affectedRows
)
{
if
(
recOfBatch
!=
affectedRows
)
{
errorPrint
(
"[%d] %s() LN%d execInsert() insert %"
PRId64
errorPrint
(
", affected rows: %"
PRId64
"
\n\n
"
,
"[%d] %s() LN%d execInsert insert %d, affected rows: %"
PRId64
pThreadInfo
->
threadID
,
__func__
,
__LINE__
,
"
\n
%s
\n
"
,
generated
,
affectedRows
);
pThreadInfo
->
threadID
,
__func__
,
__LINE__
,
recOfBatch
,
goto
free_of_interlace_stmt
;
affectedRows
,
pThreadInfo
->
buffer
);
goto
free_of_interlace
;
}
}
pThreadInfo
->
totalAffectedRows
+=
affectedRows
;
pThreadInfo
->
totalAffectedRows
+=
affectedRows
;
...
@@ -3403,8 +1981,7 @@ static void *syncWriteInterlaceStmtBatch(threadInfo *pThreadInfo,
...
@@ -3403,8 +1981,7 @@ static void *syncWriteInterlaceStmtBatch(threadInfo *pThreadInfo,
int
currentPercent
=
int
currentPercent
=
(
int
)(
pThreadInfo
->
totalAffectedRows
*
100
/
totalRows
);
(
int
)(
pThreadInfo
->
totalAffectedRows
*
100
/
totalRows
);
if
(
currentPercent
>
percentComplete
)
{
if
(
currentPercent
>
percentComplete
)
{
printf
(
"[%d]:%d%%
\n
"
,
pThreadInfo
->
threadID
,
printf
(
"[%d]:%d%%
\n
"
,
pThreadInfo
->
threadID
,
currentPercent
);
currentPercent
);
percentComplete
=
currentPercent
;
percentComplete
=
currentPercent
;
}
}
int64_t
currentPrintTime
=
taosGetTimestampMs
();
int64_t
currentPrintTime
=
taosGetTimestampMs
();
...
@@ -3416,18 +1993,6 @@ static void *syncWriteInterlaceStmtBatch(threadInfo *pThreadInfo,
...
@@ -3416,18 +1993,6 @@ static void *syncWriteInterlaceStmtBatch(threadInfo *pThreadInfo,
lastPrintTime
=
currentPrintTime
;
lastPrintTime
=
currentPrintTime
;
}
}
startTime
+=
(
generated
*
timeStampStep
);
}
}
pThreadInfo
->
samplePos
=
samplePos
;
if
(
tableSeq
==
pThreadInfo
->
start_table_from
+
pThreadInfo
->
ntables
)
{
// turn to first table
tableSeq
=
pThreadInfo
->
start_table_from
;
flagSleep
=
true
;
}
if
((
insert_interval
)
&&
flagSleep
)
{
if
((
insert_interval
)
&&
flagSleep
)
{
et
=
taosGetTimestampMs
();
et
=
taosGetTimestampMs
();
...
@@ -3444,19 +2009,21 @@ static void *syncWriteInterlaceStmtBatch(threadInfo *pThreadInfo,
...
@@ -3444,19 +2009,21 @@ static void *syncWriteInterlaceStmtBatch(threadInfo *pThreadInfo,
if
(
percentComplete
<
100
)
if
(
percentComplete
<
100
)
printf
(
"[%d]:%d%%
\n
"
,
pThreadInfo
->
threadID
,
percentComplete
);
printf
(
"[%d]:%d%%
\n
"
,
pThreadInfo
->
threadID
,
percentComplete
);
free_of_interlace_stmt:
free_of_interlace:
tmfree
(
pThreadInfo
->
buffer
);
printStatPerThread
(
pThreadInfo
);
printStatPerThread
(
pThreadInfo
);
return
NULL
;
return
NULL
;
}
}
void
*
syncWriteInterlace
(
threadInfo
*
pThreadInfo
,
uint32_t
interlaceRows
)
{
static
void
*
syncWriteInterlaceSml
(
threadInfo
*
pThreadInfo
,
debugPrint
(
"[%d] %s() LN%d: ### interlace write
\n
"
,
pThreadInfo
->
threadID
,
uint32_t
interlaceRows
)
{
__func__
,
__LINE__
);
debugPrint
(
"[%d] %s() LN%d: ### interlace schemaless write
\n
"
,
pThreadInfo
->
threadID
,
__func__
,
__LINE__
);
int64_t
insertRows
;
int64_t
insertRows
;
uint64_t
maxSqlLen
;
uint64_t
maxSqlLen
;
int64_t
timeStampStep
;
int64_t
timeStampStep
;
uint64_t
insert_interval
;
uint64_t
insert_interval
;
int32_t
code
=
0
;
SSuperTable
*
stbInfo
=
pThreadInfo
->
stbInfo
;
SSuperTable
*
stbInfo
=
pThreadInfo
->
stbInfo
;
...
@@ -3487,12 +2054,61 @@ void *syncWriteInterlace(threadInfo *pThreadInfo, uint32_t interlaceRows) {
...
@@ -3487,12 +2054,61 @@ void *syncWriteInterlace(threadInfo *pThreadInfo, uint32_t interlaceRows) {
}
else
{
}
else
{
batchPerTblTimes
=
1
;
batchPerTblTimes
=
1
;
}
}
pThreadInfo
->
buffer
=
calloc
(
maxSqlLen
,
1
);
if
(
NULL
==
pThreadInfo
->
buffer
)
{
char
**
smlList
;
cJSON
*
tagsList
;
cJSON
*
jsonArray
;
if
(
stbInfo
->
lineProtocol
==
TSDB_SML_LINE_PROTOCOL
||
stbInfo
->
lineProtocol
==
TSDB_SML_TELNET_PROTOCOL
)
{
smlList
=
(
char
**
)
calloc
(
pThreadInfo
->
ntables
,
sizeof
(
char
*
));
if
(
NULL
==
smlList
)
{
errorPrint
(
"%s"
,
"failed to allocate memory
\n
"
);
errorPrint
(
"%s"
,
"failed to allocate memory
\n
"
);
return
NULL
;
return
NULL
;
}
}
for
(
int
t
=
0
;
t
<
pThreadInfo
->
ntables
;
t
++
)
{
char
*
sml
=
(
char
*
)
calloc
(
1
,
stbInfo
->
lenOfOneRow
);
if
(
NULL
==
sml
)
{
errorPrint
(
"%s"
,
"failed to allocate memory
\n
"
);
goto
free_smlheadlist_interlace_sml
;
}
code
=
generateSmlConstPart
(
sml
,
stbInfo
,
pThreadInfo
,
t
);
if
(
code
)
{
goto
free_smlheadlist_interlace_sml
;
}
smlList
[
t
]
=
sml
;
}
pThreadInfo
->
lines
=
calloc
(
g_args
.
reqPerReq
,
sizeof
(
char
*
));
if
(
NULL
==
pThreadInfo
->
lines
)
{
errorPrint
(
"%s"
,
"failed to allocate memory
\n
"
);
goto
free_smlheadlist_interlace_sml
;
}
for
(
int
i
=
0
;
i
<
g_args
.
reqPerReq
;
i
++
)
{
pThreadInfo
->
lines
[
i
]
=
calloc
(
1
,
stbInfo
->
lenOfOneRow
);
if
(
NULL
==
pThreadInfo
->
lines
[
i
])
{
errorPrint
(
"%s"
,
"failed to allocate memory
\n
"
);
goto
free_lines_interlace_sml
;
}
}
}
else
{
jsonArray
=
cJSON_CreateArray
();
tagsList
=
cJSON_CreateArray
();
for
(
int
t
=
0
;
t
<
pThreadInfo
->
ntables
;
t
++
)
{
code
=
generateSmlJsonTags
(
tagsList
,
stbInfo
,
pThreadInfo
,
t
);
if
(
code
)
{
goto
free_json_interlace_sml
;
}
}
pThreadInfo
->
lines
=
(
char
**
)
calloc
(
1
,
sizeof
(
char
*
));
if
(
NULL
==
pThreadInfo
->
lines
)
{
errorPrint
(
"%s"
,
"failed to allocate memory
\n
"
);
goto
free_json_interlace_sml
;
}
}
pThreadInfo
->
totalInsertRows
=
0
;
pThreadInfo
->
totalInsertRows
=
0
;
pThreadInfo
->
totalAffectedRows
=
0
;
pThreadInfo
->
totalAffectedRows
=
0
;
...
@@ -3518,59 +2134,38 @@ void *syncWriteInterlace(threadInfo *pThreadInfo, uint32_t interlaceRows) {
...
@@ -3518,59 +2134,38 @@ void *syncWriteInterlace(threadInfo *pThreadInfo, uint32_t interlaceRows) {
st
=
taosGetTimestampMs
();
st
=
taosGetTimestampMs
();
flagSleep
=
false
;
flagSleep
=
false
;
}
}
// generate data
// generate data
memset
(
pThreadInfo
->
buffer
,
0
,
maxSqlLen
);
uint64_t
remainderBufLen
=
maxSqlLen
;
char
*
pstr
=
pThreadInfo
->
buffer
;
int
len
=
snprintf
(
pstr
,
strlen
(
STR_INSERT_INTO
)
+
1
,
"%s"
,
STR_INSERT_INTO
);
pstr
+=
len
;
remainderBufLen
-=
len
;
uint32_t
recOfBatch
=
0
;
uint32_t
recOfBatch
=
0
;
int32_t
generated
;
for
(
uint64_t
i
=
0
;
i
<
batchPerTblTimes
;
i
++
)
{
for
(
uint64_t
i
=
0
;
i
<
batchPerTblTimes
;
i
++
)
{
char
tableName
[
TSDB_TABLE_NAME_LEN
];
int64_t
timestamp
=
startTime
;
for
(
int
j
=
recOfBatch
;
j
<
recOfBatch
+
batchPerTbl
;
j
++
)
{
getTableName
(
tableName
,
pThreadInfo
,
tableSeq
);
if
(
stbInfo
->
lineProtocol
==
TSDB_SML_JSON_PROTOCOL
)
{
if
(
0
==
strlen
(
tableName
))
{
cJSON
*
tag
=
cJSON_Duplicate
(
errorPrint
(
"[%d] %s() LN%d, getTableName return null
\n
"
,
cJSON_GetArrayItem
(
pThreadInfo
->
threadID
,
__func__
,
__LINE__
);
tagsList
,
tableSeq
-
pThreadInfo
->
start_table_from
),
free
(
pThreadInfo
->
buffer
);
true
);
return
NULL
;
code
=
generateSmlJsonCols
(
jsonArray
,
tag
,
stbInfo
,
pThreadInfo
,
timestamp
);
if
(
code
)
{
goto
free_json_interlace_sml
;
}
}
uint64_t
oldRemainderLen
=
remainderBufLen
;
if
(
stbInfo
)
{
generated
=
generateStbInterlaceData
(
pThreadInfo
,
tableName
,
batchPerTbl
,
i
,
batchPerTblTimes
,
tableSeq
,
pstr
,
insertRows
,
startTime
,
&
remainderBufLen
);
}
else
{
}
else
{
generated
=
(
int32_t
)
generateInterlaceDataWithoutStb
(
code
=
generateSmlMutablePart
(
tableName
,
batchPerTbl
,
tableSeq
,
pThreadInfo
->
db_name
,
pThreadInfo
->
lines
[
j
],
pstr
,
insertRows
,
startTime
,
&
remainderBufLen
);
smlList
[
tableSeq
-
pThreadInfo
->
start_table_from
],
stbInfo
,
pThreadInfo
,
timestamp
);
if
(
code
)
{
goto
free_lines_interlace_sml
;
}
}
debugPrint
(
"[%d] %s() LN%d, generated records is %d
\n
"
,
pThreadInfo
->
threadID
,
__func__
,
__LINE__
,
generated
);
if
(
generated
<
0
)
{
errorPrint
(
"[%d] %s() LN%d, generated records is %d
\n
"
,
pThreadInfo
->
threadID
,
__func__
,
__LINE__
,
generated
);
goto
free_of_interlace
;
}
else
if
(
generated
==
0
)
{
break
;
}
}
timestamp
+=
timeStampStep
;
}
tableSeq
++
;
tableSeq
++
;
recOfBatch
+=
batchPerTbl
;
recOfBatch
+=
batchPerTbl
;
pstr
+=
(
oldRemainderLen
-
remainderBufLen
);
pThreadInfo
->
totalInsertRows
+=
batchPerTbl
;
pThreadInfo
->
totalInsertRows
+=
batchPerTbl
;
verbosePrint
(
"[%d] %s() LN%d batchPerTbl=%d recOfBatch=%d
\n
"
,
verbosePrint
(
"[%d] %s() LN%d batchPerTbl=%d recOfBatch=%d
\n
"
,
...
@@ -3587,22 +2182,28 @@ void *syncWriteInterlace(threadInfo *pThreadInfo, uint32_t interlaceRows) {
...
@@ -3587,22 +2182,28 @@ void *syncWriteInterlace(threadInfo *pThreadInfo, uint32_t interlaceRows) {
generatedRecPerTbl
*
timeStampStep
;
generatedRecPerTbl
*
timeStampStep
;
flagSleep
=
true
;
flagSleep
=
true
;
if
(
generatedRecPerTbl
>=
insertRows
)
break
;
if
(
generatedRecPerTbl
>=
insertRows
)
{
break
;
}
int64_t
remainRows
=
insertRows
-
generatedRecPerTbl
;
int64_t
remainRows
=
insertRows
-
generatedRecPerTbl
;
if
((
remainRows
>
0
)
&&
(
batchPerTbl
>
remainRows
))
if
((
remainRows
>
0
)
&&
(
batchPerTbl
>
remainRows
))
{
batchPerTbl
=
(
uint32_t
)
remainRows
;
batchPerTbl
=
remainRows
;
}
if
(
pThreadInfo
->
ntables
*
batchPerTbl
<
g_args
.
reqPerReq
)
if
(
pThreadInfo
->
ntables
*
batchPerTbl
<
g_args
.
reqPerReq
)
{
break
;
break
;
}
}
}
verbosePrint
(
"[%d] %s() LN%d generatedRecPerTbl=%"
PRId64
verbosePrint
(
"[%d] %s() LN%d generatedRecPerTbl=%"
PRId64
" insertRows=%"
PRId64
"
\n
"
,
" insertRows=%"
PRId64
"
\n
"
,
pThreadInfo
->
threadID
,
__func__
,
__LINE__
,
pThreadInfo
->
threadID
,
__func__
,
__LINE__
,
generatedRecPerTbl
,
insertRows
);
generatedRecPerTbl
,
insertRows
);
if
((
g_args
.
reqPerReq
-
recOfBatch
)
<
batchPerTbl
)
break
;
if
((
g_args
.
reqPerReq
-
recOfBatch
)
<
batchPerTbl
)
{
break
;
}
}
}
verbosePrint
(
"[%d] %s() LN%d recOfBatch=%d totalInsertRows=%"
PRIu64
verbosePrint
(
"[%d] %s() LN%d recOfBatch=%d totalInsertRows=%"
PRIu64
...
@@ -3612,11 +2213,14 @@ void *syncWriteInterlace(threadInfo *pThreadInfo, uint32_t interlaceRows) {
...
@@ -3612,11 +2213,14 @@ void *syncWriteInterlace(threadInfo *pThreadInfo, uint32_t interlaceRows) {
verbosePrint
(
"[%d] %s() LN%d, buffer=%s
\n
"
,
pThreadInfo
->
threadID
,
verbosePrint
(
"[%d] %s() LN%d, buffer=%s
\n
"
,
pThreadInfo
->
threadID
,
__func__
,
__LINE__
,
pThreadInfo
->
buffer
);
__func__
,
__LINE__
,
pThreadInfo
->
buffer
);
if
(
stbInfo
->
lineProtocol
==
TSDB_SML_JSON_PROTOCOL
)
{
pThreadInfo
->
lines
[
0
]
=
cJSON_Print
(
jsonArray
);
}
startTs
=
taosGetTimestampUs
();
startTs
=
taosGetTimestampUs
();
if
(
recOfBatch
==
0
)
{
if
(
recOfBatch
==
0
)
{
errorPrint
(
"[%d] %s() LN%d Failed to insert records of batch %d
\n
"
,
errorPrint
(
"Failed to insert records of batch %d
\n
"
,
batchPerTbl
);
pThreadInfo
->
threadID
,
__func__
,
__LINE__
,
batchPerTbl
);
if
(
batchPerTbl
>
0
)
{
if
(
batchPerTbl
>
0
)
{
errorPrint
(
errorPrint
(
"
\t
If the batch is %d, the length of the SQL to insert a "
"
\t
If the batch is %d, the length of the SQL to insert a "
...
@@ -3626,12 +2230,19 @@ void *syncWriteInterlace(threadInfo *pThreadInfo, uint32_t interlaceRows) {
...
@@ -3626,12 +2230,19 @@ void *syncWriteInterlace(threadInfo *pThreadInfo, uint32_t interlaceRows) {
errorPrint
(
"
\t
Please check if the buffer length(%"
PRId64
errorPrint
(
"
\t
Please check if the buffer length(%"
PRId64
") or batch(%d) is set with proper value!
\n
"
,
") or batch(%d) is set with proper value!
\n
"
,
maxSqlLen
,
batchPerTbl
);
maxSqlLen
,
batchPerTbl
);
goto
free_
of_interlace
;
goto
free_
lines_interlace_sml
;
}
}
int64_t
affectedRows
=
execInsert
(
pThreadInfo
,
recOfBatch
);
int64_t
affectedRows
=
execInsert
(
pThreadInfo
,
recOfBatch
);
endTs
=
taosGetTimestampUs
();
endTs
=
taosGetTimestampUs
();
uint64_t
delay
=
endTs
-
startTs
;
uint64_t
delay
=
endTs
-
startTs
;
if
(
stbInfo
->
lineProtocol
==
TSDB_SML_JSON_PROTOCOL
)
{
tmfree
(
pThreadInfo
->
lines
[
0
]);
cJSON_Delete
(
jsonArray
);
jsonArray
=
cJSON_CreateArray
();
}
performancePrint
(
"%s() LN%d, insert execution time is %10.2f ms
\n
"
,
performancePrint
(
"%s() LN%d, insert execution time is %10.2f ms
\n
"
,
__func__
,
__LINE__
,
delay
/
1000
.
0
);
__func__
,
__LINE__
,
delay
/
1000
.
0
);
verbosePrint
(
"[%d] %s() LN%d affectedRows=%"
PRId64
"
\n
"
,
verbosePrint
(
"[%d] %s() LN%d affectedRows=%"
PRId64
"
\n
"
,
...
@@ -3643,18 +2254,14 @@ void *syncWriteInterlace(threadInfo *pThreadInfo, uint32_t interlaceRows) {
...
@@ -3643,18 +2254,14 @@ void *syncWriteInterlace(threadInfo *pThreadInfo, uint32_t interlaceRows) {
pThreadInfo
->
totalDelay
+=
delay
;
pThreadInfo
->
totalDelay
+=
delay
;
if
(
recOfBatch
!=
affectedRows
)
{
if
(
recOfBatch
!=
affectedRows
)
{
errorPrint
(
errorPrint
(
"execInsert insert %d, affected rows: %"
PRId64
"
\n
%s
\n
"
,
"[%d] %s() LN%d execInsert insert %d, affected rows: %"
PRId64
recOfBatch
,
affectedRows
,
pThreadInfo
->
buffer
);
"
\n
%s
\n
"
,
goto
free_lines_interlace_sml
;
pThreadInfo
->
threadID
,
__func__
,
__LINE__
,
recOfBatch
,
affectedRows
,
pThreadInfo
->
buffer
);
goto
free_of_interlace
;
}
}
pThreadInfo
->
totalAffectedRows
+=
affectedRows
;
pThreadInfo
->
totalAffectedRows
+=
affectedRows
;
int
currentPercent
=
int
currentPercent
=
pThreadInfo
->
totalAffectedRows
*
100
/
totalRows
;
(
int
)(
pThreadInfo
->
totalAffectedRows
*
100
/
totalRows
);
if
(
currentPercent
>
percentComplete
)
{
if
(
currentPercent
>
percentComplete
)
{
printf
(
"[%d]:%d%%
\n
"
,
pThreadInfo
->
threadID
,
currentPercent
);
printf
(
"[%d]:%d%%
\n
"
,
pThreadInfo
->
threadID
,
currentPercent
);
percentComplete
=
currentPercent
;
percentComplete
=
currentPercent
;
...
@@ -3676,7 +2283,7 @@ void *syncWriteInterlace(threadInfo *pThreadInfo, uint32_t interlaceRows) {
...
@@ -3676,7 +2283,7 @@ void *syncWriteInterlace(threadInfo *pThreadInfo, uint32_t interlaceRows) {
performancePrint
(
"%s() LN%d sleep: %"
PRId64
performancePrint
(
"%s() LN%d sleep: %"
PRId64
" ms for insert interval
\n
"
,
" ms for insert interval
\n
"
,
__func__
,
__LINE__
,
sleepTime
);
__func__
,
__LINE__
,
sleepTime
);
taosMsleep
(
(
int32_t
)
sleepTime
);
// ms
taosMsleep
(
sleepTime
);
// ms
sleepTimeTotal
+=
insert_interval
;
sleepTimeTotal
+=
insert_interval
;
}
}
}
}
...
@@ -3684,9 +2291,28 @@ void *syncWriteInterlace(threadInfo *pThreadInfo, uint32_t interlaceRows) {
...
@@ -3684,9 +2291,28 @@ void *syncWriteInterlace(threadInfo *pThreadInfo, uint32_t interlaceRows) {
if
(
percentComplete
<
100
)
if
(
percentComplete
<
100
)
printf
(
"[%d]:%d%%
\n
"
,
pThreadInfo
->
threadID
,
percentComplete
);
printf
(
"[%d]:%d%%
\n
"
,
pThreadInfo
->
threadID
,
percentComplete
);
free_of_interlace:
tmfree
(
pThreadInfo
->
buffer
);
printStatPerThread
(
pThreadInfo
);
printStatPerThread
(
pThreadInfo
);
if
(
stbInfo
->
lineProtocol
==
TSDB_SML_JSON_PROTOCOL
)
{
tmfree
(
pThreadInfo
->
lines
);
free_json_interlace_sml:
if
(
jsonArray
!=
NULL
)
{
cJSON_Delete
(
jsonArray
);
}
if
(
tagsList
!=
NULL
)
{
cJSON_Delete
(
tagsList
);
}
}
else
{
free_lines_interlace_sml:
for
(
int
index
=
0
;
index
<
g_args
.
reqPerReq
;
index
++
)
{
tmfree
(
pThreadInfo
->
lines
[
index
]);
}
tmfree
(
pThreadInfo
->
lines
);
free_smlheadlist_interlace_sml:
for
(
int
index
=
0
;
index
<
pThreadInfo
->
ntables
;
index
++
)
{
tmfree
(
smlList
[
index
]);
}
tmfree
(
smlList
);
}
return
NULL
;
return
NULL
;
}
}
...
@@ -3979,6 +2605,184 @@ free_of_progressive:
...
@@ -3979,6 +2605,184 @@ free_of_progressive:
return
NULL
;
return
NULL
;
}
}
void
*
syncWriteProgressiveSml
(
threadInfo
*
pThreadInfo
)
{
debugPrint
(
"%s() LN%d: ### sml progressive write
\n
"
,
__func__
,
__LINE__
);
int32_t
code
=
0
;
SSuperTable
*
stbInfo
=
pThreadInfo
->
stbInfo
;
int64_t
timeStampStep
=
stbInfo
->
timeStampStep
;
int64_t
insertRows
=
stbInfo
->
insertRows
;
verbosePrint
(
"%s() LN%d insertRows=%"
PRId64
"
\n
"
,
__func__
,
__LINE__
,
insertRows
);
uint64_t
lastPrintTime
=
taosGetTimestampMs
();
pThreadInfo
->
totalInsertRows
=
0
;
pThreadInfo
->
totalAffectedRows
=
0
;
pThreadInfo
->
samplePos
=
0
;
char
**
smlList
;
cJSON
*
tagsList
;
cJSON
*
jsonArray
;
if
(
insertRows
<
g_args
.
reqPerReq
)
{
g_args
.
reqPerReq
=
insertRows
;
}
if
(
stbInfo
->
lineProtocol
==
TSDB_SML_LINE_PROTOCOL
||
stbInfo
->
lineProtocol
==
TSDB_SML_TELNET_PROTOCOL
)
{
smlList
=
(
char
**
)
calloc
(
pThreadInfo
->
ntables
,
sizeof
(
char
*
));
if
(
NULL
==
smlList
)
{
errorPrint
(
"%s"
,
"failed to allocate memory
\n
"
);
return
NULL
;
}
for
(
int
t
=
0
;
t
<
pThreadInfo
->
ntables
;
t
++
)
{
char
*
sml
=
(
char
*
)
calloc
(
1
,
stbInfo
->
lenOfOneRow
);
if
(
NULL
==
sml
)
{
errorPrint
(
"%s"
,
"failed to allocate memory
\n
"
);
goto
free_smlheadlist_progressive_sml
;
}
code
=
generateSmlConstPart
(
sml
,
stbInfo
,
pThreadInfo
,
t
);
if
(
code
)
{
goto
free_smlheadlist_progressive_sml
;
}
smlList
[
t
]
=
sml
;
}
pThreadInfo
->
lines
=
(
char
**
)
calloc
(
g_args
.
reqPerReq
,
sizeof
(
char
*
));
if
(
NULL
==
pThreadInfo
->
lines
)
{
errorPrint
(
"%s"
,
"failed to allocate memory
\n
"
);
goto
free_smlheadlist_progressive_sml
;
}
for
(
int
i
=
0
;
i
<
g_args
.
reqPerReq
;
i
++
)
{
pThreadInfo
->
lines
[
i
]
=
(
char
*
)
calloc
(
1
,
stbInfo
->
lenOfOneRow
);
if
(
NULL
==
pThreadInfo
->
lines
[
i
])
{
errorPrint
(
"%s"
,
"failed to allocate memory
\n
"
);
goto
free_lines_progressive_sml
;
}
}
}
else
{
jsonArray
=
cJSON_CreateArray
();
tagsList
=
cJSON_CreateArray
();
for
(
int
t
=
0
;
t
<
pThreadInfo
->
ntables
;
t
++
)
{
code
=
generateSmlJsonTags
(
tagsList
,
stbInfo
,
pThreadInfo
,
t
);
if
(
code
)
{
goto
free_json_progressive_sml
;
}
}
pThreadInfo
->
lines
=
(
char
**
)
calloc
(
1
,
sizeof
(
char
*
));
if
(
NULL
==
pThreadInfo
->
lines
)
{
errorPrint
(
"%s"
,
"failed to allocate memory
\n
"
);
goto
free_json_progressive_sml
;
}
}
int
currentPercent
=
0
;
int
percentComplete
=
0
;
for
(
uint64_t
i
=
0
;
i
<
pThreadInfo
->
ntables
;
i
++
)
{
int64_t
timestamp
=
pThreadInfo
->
start_time
;
for
(
uint64_t
j
=
0
;
j
<
insertRows
;)
{
for
(
int
k
=
0
;
k
<
g_args
.
reqPerReq
;
k
++
)
{
if
(
stbInfo
->
lineProtocol
==
TSDB_SML_JSON_PROTOCOL
)
{
cJSON
*
tag
=
cJSON_Duplicate
(
cJSON_GetArrayItem
(
tagsList
,
i
),
true
);
code
=
generateSmlJsonCols
(
jsonArray
,
tag
,
stbInfo
,
pThreadInfo
,
timestamp
);
if
(
code
)
{
goto
free_json_progressive_sml
;
}
}
else
{
code
=
generateSmlMutablePart
(
pThreadInfo
->
lines
[
k
],
smlList
[
i
],
stbInfo
,
pThreadInfo
,
timestamp
);
if
(
code
)
{
goto
free_lines_progressive_sml
;
}
}
timestamp
+=
timeStampStep
;
j
++
;
if
(
j
==
insertRows
)
{
break
;
}
}
if
(
stbInfo
->
lineProtocol
==
TSDB_SML_JSON_PROTOCOL
)
{
pThreadInfo
->
lines
[
0
]
=
cJSON_Print
(
jsonArray
);
}
uint64_t
startTs
=
taosGetTimestampUs
();
int32_t
affectedRows
=
execInsert
(
pThreadInfo
,
g_args
.
reqPerReq
);
uint64_t
endTs
=
taosGetTimestampUs
();
uint64_t
delay
=
endTs
-
startTs
;
if
(
stbInfo
->
lineProtocol
==
TSDB_SML_JSON_PROTOCOL
)
{
tmfree
(
pThreadInfo
->
lines
[
0
]);
cJSON_Delete
(
jsonArray
);
jsonArray
=
cJSON_CreateArray
();
}
performancePrint
(
"%s() LN%d, insert execution time is %10.f ms
\n
"
,
__func__
,
__LINE__
,
delay
/
1000
.
0
);
verbosePrint
(
"[%d] %s() LN%d affectedRows=%d
\n
"
,
pThreadInfo
->
threadID
,
__func__
,
__LINE__
,
affectedRows
);
if
(
delay
>
pThreadInfo
->
maxDelay
)
{
pThreadInfo
->
maxDelay
=
delay
;
}
if
(
delay
<
pThreadInfo
->
minDelay
)
{
pThreadInfo
->
minDelay
=
delay
;
}
pThreadInfo
->
cntDelay
++
;
pThreadInfo
->
totalDelay
+=
delay
;
pThreadInfo
->
totalAffectedRows
+=
affectedRows
;
pThreadInfo
->
totalInsertRows
+=
g_args
.
reqPerReq
;
currentPercent
=
pThreadInfo
->
totalAffectedRows
*
100
/
(
insertRows
*
pThreadInfo
->
ntables
);
if
(
currentPercent
>
percentComplete
)
{
printf
(
"[%d]:%d%%
\n
"
,
pThreadInfo
->
threadID
,
currentPercent
);
percentComplete
=
currentPercent
;
}
int64_t
currentPrintTime
=
taosGetTimestampMs
();
if
(
currentPrintTime
-
lastPrintTime
>
30
*
1000
)
{
printf
(
"thread[%d] has currently inserted rows: %"
PRId64
", affected rows: %"
PRId64
"
\n
"
,
pThreadInfo
->
threadID
,
pThreadInfo
->
totalInsertRows
,
pThreadInfo
->
totalAffectedRows
);
lastPrintTime
=
currentPrintTime
;
}
if
(
j
==
insertRows
)
{
break
;
}
}
}
if
(
stbInfo
->
lineProtocol
==
TSDB_SML_JSON_PROTOCOL
)
{
tmfree
(
pThreadInfo
->
lines
);
free_json_progressive_sml:
if
(
jsonArray
!=
NULL
)
{
cJSON_Delete
(
jsonArray
);
}
if
(
tagsList
!=
NULL
)
{
cJSON_Delete
(
tagsList
);
}
}
else
{
free_lines_progressive_sml:
for
(
int
index
=
0
;
index
<
g_args
.
reqPerReq
;
index
++
)
{
tmfree
(
pThreadInfo
->
lines
[
index
]);
}
tmfree
(
pThreadInfo
->
lines
);
free_smlheadlist_progressive_sml:
for
(
int
index
=
0
;
index
<
pThreadInfo
->
ntables
;
index
++
)
{
tmfree
(
smlList
[
index
]);
}
tmfree
(
smlList
);
}
return
NULL
;
}
void
*
syncWrite
(
void
*
sarg
)
{
void
*
syncWrite
(
void
*
sarg
)
{
threadInfo
*
pThreadInfo
=
(
threadInfo
*
)
sarg
;
threadInfo
*
pThreadInfo
=
(
threadInfo
*
)
sarg
;
SSuperTable
*
stbInfo
=
pThreadInfo
->
stbInfo
;
SSuperTable
*
stbInfo
=
pThreadInfo
->
stbInfo
;
...
@@ -4000,6 +2804,8 @@ void *syncWrite(void *sarg) {
...
@@ -4000,6 +2804,8 @@ void *syncWrite(void *sarg) {
if
(
stbInfo
)
{
if
(
stbInfo
)
{
if
(
STMT_IFACE
==
stbInfo
->
iface
)
{
if
(
STMT_IFACE
==
stbInfo
->
iface
)
{
return
syncWriteInterlaceStmtBatch
(
pThreadInfo
,
interlaceRows
);
return
syncWriteInterlaceStmtBatch
(
pThreadInfo
,
interlaceRows
);
}
else
if
(
SML_IFACE
==
stbInfo
->
iface
)
{
return
syncWriteInterlaceSml
(
pThreadInfo
,
interlaceRows
);
}
else
{
}
else
{
return
syncWriteInterlace
(
pThreadInfo
,
interlaceRows
);
return
syncWriteInterlace
(
pThreadInfo
,
interlaceRows
);
}
}
...
@@ -4009,6 +2815,9 @@ void *syncWrite(void *sarg) {
...
@@ -4009,6 +2815,9 @@ void *syncWrite(void *sarg) {
if
(((
stbInfo
)
&&
(
STMT_IFACE
==
stbInfo
->
iface
))
||
if
(((
stbInfo
)
&&
(
STMT_IFACE
==
stbInfo
->
iface
))
||
(
STMT_IFACE
==
g_args
.
iface
))
{
(
STMT_IFACE
==
g_args
.
iface
))
{
return
syncWriteProgressiveStmt
(
pThreadInfo
);
return
syncWriteProgressiveStmt
(
pThreadInfo
);
}
else
if
(((
stbInfo
)
&&
(
SML_IFACE
==
stbInfo
->
iface
))
||
(
SML_IFACE
==
g_args
.
iface
))
{
return
syncWriteProgressiveSml
(
pThreadInfo
);
}
else
{
}
else
{
return
syncWriteProgressive
(
pThreadInfo
);
return
syncWriteProgressive
(
pThreadInfo
);
}
}
...
@@ -4103,19 +2912,39 @@ void *asyncWrite(void *sarg) {
...
@@ -4103,19 +2912,39 @@ void *asyncWrite(void *sarg) {
int
startMultiThreadInsertData
(
int
threads
,
char
*
db_name
,
char
*
precision
,
int
startMultiThreadInsertData
(
int
threads
,
char
*
db_name
,
char
*
precision
,
SSuperTable
*
stbInfo
)
{
SSuperTable
*
stbInfo
)
{
int32_t
timePrec
=
TSDB_TIME_PRECISION_MILLI
;
int32_t
timePrec
=
TSDB_TIME_PRECISION_MILLI
;
stbInfo
->
tsPrecision
=
TSDB_SML_TIMESTAMP_MILLI_SECONDS
;
if
(
0
!=
precision
[
0
])
{
if
(
0
!=
precision
[
0
])
{
if
(
0
==
strncasecmp
(
precision
,
"ms"
,
2
))
{
if
(
0
==
strncasecmp
(
precision
,
"ms"
,
2
))
{
timePrec
=
TSDB_TIME_PRECISION_MILLI
;
timePrec
=
TSDB_TIME_PRECISION_MILLI
;
stbInfo
->
tsPrecision
=
TSDB_SML_TIMESTAMP_MILLI_SECONDS
;
}
else
if
(
0
==
strncasecmp
(
precision
,
"us"
,
2
))
{
}
else
if
(
0
==
strncasecmp
(
precision
,
"us"
,
2
))
{
timePrec
=
TSDB_TIME_PRECISION_MICRO
;
timePrec
=
TSDB_TIME_PRECISION_MICRO
;
stbInfo
->
tsPrecision
=
TSDB_SML_TIMESTAMP_MICRO_SECONDS
;
}
else
if
(
0
==
strncasecmp
(
precision
,
"ns"
,
2
))
{
}
else
if
(
0
==
strncasecmp
(
precision
,
"ns"
,
2
))
{
timePrec
=
TSDB_TIME_PRECISION_NANO
;
timePrec
=
TSDB_TIME_PRECISION_NANO
;
stbInfo
->
tsPrecision
=
TSDB_SML_TIMESTAMP_NANO_SECONDS
;
}
else
{
}
else
{
errorPrint
(
"Not support precision: %s
\n
"
,
precision
);
errorPrint
(
"Not support precision: %s
\n
"
,
precision
);
return
-
1
;
return
-
1
;
}
}
}
}
if
(
stbInfo
->
iface
==
SML_IFACE
)
{
if
(
stbInfo
->
lineProtocol
!=
TSDB_SML_LINE_PROTOCOL
)
{
if
(
stbInfo
->
columnCount
!=
1
)
{
errorPrint
(
"Schemaless telnet/json protocol can only have 1 column "
"instead of %d
\n
"
,
stbInfo
->
columnCount
);
return
-
1
;
}
stbInfo
->
tsPrecision
=
TSDB_SML_TIMESTAMP_NOT_CONFIGURED
;
}
if
(
stbInfo
->
lineProtocol
!=
TSDB_SML_JSON_PROTOCOL
)
{
calcRowLen
(
stbInfo
);
}
}
int64_t
startTime
;
int64_t
startTime
;
if
(
stbInfo
)
{
if
(
stbInfo
)
{
if
(
0
==
strncasecmp
(
stbInfo
->
startTimestamp
,
"now"
,
3
))
{
if
(
0
==
strncasecmp
(
stbInfo
->
startTimestamp
,
"now"
,
3
))
{
...
...
src/kit/taosdemo/src/demoMain.c
浏览文件 @
aafd7e1d
...
@@ -20,6 +20,7 @@ FILE * g_fpOfInsertResult = NULL;
...
@@ -20,6 +20,7 @@ FILE * g_fpOfInsertResult = NULL;
char
*
g_dupstr
=
NULL
;
char
*
g_dupstr
=
NULL
;
SDbs
g_Dbs
;
SDbs
g_Dbs
;
SQueryMetaInfo
g_queryInfo
;
SQueryMetaInfo
g_queryInfo
;
SArguments
g_args
=
{
SArguments
g_args
=
{
DEFAULT_METAFILE
,
// metaFile
DEFAULT_METAFILE
,
// metaFile
DEFAULT_TEST_MODE
,
// test_mode
DEFAULT_TEST_MODE
,
// test_mode
...
...
src/kit/taosdemo/src/demoOutput.c
浏览文件 @
aafd7e1d
...
@@ -301,7 +301,8 @@ void printHelp() {
...
@@ -301,7 +301,8 @@ void printHelp() {
printf
(
"%s%s%s%s
\n
"
,
indent
,
"-P, --port=PORT"
,
"
\t\t
"
,
printf
(
"%s%s%s%s
\n
"
,
indent
,
"-P, --port=PORT"
,
"
\t\t
"
,
"The TCP/IP port number to use for the connection."
);
"The TCP/IP port number to use for the connection."
);
printf
(
"%s%s%s%s
\n
"
,
indent
,
"-I, --interface=INTERFACE"
,
"
\t
"
,
printf
(
"%s%s%s%s
\n
"
,
indent
,
"-I, --interface=INTERFACE"
,
"
\t
"
,
"The interface (taosc, rest, and stmt) taosdemo uses. By default "
"The interface (taosc, rest, stmt, and sml(line protocol)) taosdemo "
"uses. By default "
"use 'taosc'."
);
"use 'taosc'."
);
printf
(
"%s%s%s%s
\n
"
,
indent
,
"-d, --database=DATABASE"
,
"
\t
"
,
printf
(
"%s%s%s%s
\n
"
,
indent
,
"-d, --database=DATABASE"
,
"
\t
"
,
"Destination database. By default is 'test'."
);
"Destination database. By default is 'test'."
);
...
@@ -374,6 +375,7 @@ void printHelp() {
...
@@ -374,6 +375,7 @@ void printHelp() {
for any corresponding short options.
\n
\
for any corresponding short options.
\n
\
\n
\
\n
\
Report bugs to <support@taosdata.com>.
\n
"
);
Report bugs to <support@taosdata.com>.
\n
"
);
exit
(
EXIT_SUCCESS
);
}
}
void
printfInsertMeta
()
{
void
printfInsertMeta
()
{
...
@@ -531,6 +533,17 @@ void printfInsertMeta() {
...
@@ -531,6 +533,17 @@ void printfInsertMeta() {
:
(
g_Dbs
.
db
[
i
].
superTbls
[
j
].
iface
==
STMT_IFACE
)
:
(
g_Dbs
.
db
[
i
].
superTbls
[
j
].
iface
==
STMT_IFACE
)
?
"stmt"
?
"stmt"
:
"sml"
);
:
"sml"
);
if
(
g_Dbs
.
db
[
i
].
superTbls
[
j
].
iface
==
SML_IFACE
)
{
printf
(
" lineProtocol:
\033
[33m%s
\033
[0m
\n
"
,
(
g_Dbs
.
db
[
i
].
superTbls
[
j
].
lineProtocol
==
TSDB_SML_LINE_PROTOCOL
)
?
"line"
:
(
g_Dbs
.
db
[
i
].
superTbls
[
j
].
lineProtocol
==
TSDB_SML_TELNET_PROTOCOL
)
?
"telnet"
:
"json"
);
}
if
(
g_Dbs
.
db
[
i
].
superTbls
[
j
].
childTblLimit
>
0
)
{
if
(
g_Dbs
.
db
[
i
].
superTbls
[
j
].
childTblLimit
>
0
)
{
printf
(
" childTblLimit:
\033
[33m%"
PRId64
printf
(
" childTblLimit:
\033
[33m%"
PRId64
"
\033
[0m
\n
"
,
"
\033
[0m
\n
"
,
...
@@ -1010,3 +1023,30 @@ void printfQuerySystemInfo(TAOS *taos) {
...
@@ -1010,3 +1023,30 @@ void printfQuerySystemInfo(TAOS *taos) {
free
(
dbInfos
);
free
(
dbInfos
);
resetAfterAnsiEscape
();
resetAfterAnsiEscape
();
}
}
void
printStatPerThread
(
threadInfo
*
pThreadInfo
)
{
if
(
0
==
pThreadInfo
->
totalDelay
)
pThreadInfo
->
totalDelay
=
1
;
fprintf
(
stderr
,
"====thread[%d] completed total inserted rows: %"
PRIu64
", total affected rows: %"
PRIu64
". %.2f records/second====
\n
"
,
pThreadInfo
->
threadID
,
pThreadInfo
->
totalInsertRows
,
pThreadInfo
->
totalAffectedRows
,
(
double
)(
pThreadInfo
->
totalAffectedRows
/
((
double
)
pThreadInfo
->
totalDelay
/
1000000
.
0
)));
}
void
appendResultBufToFile
(
char
*
resultBuf
,
threadInfo
*
pThreadInfo
)
{
pThreadInfo
->
fp
=
fopen
(
pThreadInfo
->
filePath
,
"at"
);
if
(
pThreadInfo
->
fp
==
NULL
)
{
errorPrint
(
"%s() LN%d, failed to open result file: %s, result will not save "
"to file
\n
"
,
__func__
,
__LINE__
,
pThreadInfo
->
filePath
);
return
;
}
fprintf
(
pThreadInfo
->
fp
,
"%s"
,
resultBuf
);
tmfclose
(
pThreadInfo
->
fp
);
pThreadInfo
->
fp
=
NULL
;
}
\ No newline at end of file
src/kit/taosdemo/src/demoUtil.c
浏览文件 @
aafd7e1d
...
@@ -282,18 +282,6 @@ int getAllChildNameOfSuperTable(TAOS *taos, char *dbName, char *stbName,
...
@@ -282,18 +282,6 @@ int getAllChildNameOfSuperTable(TAOS *taos, char *dbName, char *stbName,
-
1
,
0
,
false
);
-
1
,
0
,
false
);
}
}
void
printStatPerThread
(
threadInfo
*
pThreadInfo
)
{
if
(
0
==
pThreadInfo
->
totalDelay
)
pThreadInfo
->
totalDelay
=
1
;
fprintf
(
stderr
,
"====thread[%d] completed total inserted rows: %"
PRIu64
", total affected rows: %"
PRIu64
". %.2f records/second====
\n
"
,
pThreadInfo
->
threadID
,
pThreadInfo
->
totalInsertRows
,
pThreadInfo
->
totalAffectedRows
,
(
double
)(
pThreadInfo
->
totalAffectedRows
/
((
double
)
pThreadInfo
->
totalDelay
/
1000000
.
0
)));
}
int
convertHostToServAddr
(
char
*
host
,
uint16_t
port
,
int
convertHostToServAddr
(
char
*
host
,
uint16_t
port
,
struct
sockaddr_in
*
serv_addr
)
{
struct
sockaddr_in
*
serv_addr
)
{
uint16_t
rest_port
=
port
+
TSDB_PORT_HTTP
;
uint16_t
rest_port
=
port
+
TSDB_PORT_HTTP
;
...
@@ -406,21 +394,6 @@ int queryDbExec(TAOS *taos, char *command, QUERY_TYPE type, bool quiet) {
...
@@ -406,21 +394,6 @@ int queryDbExec(TAOS *taos, char *command, QUERY_TYPE type, bool quiet) {
return
0
;
return
0
;
}
}
void
appendResultBufToFile
(
char
*
resultBuf
,
threadInfo
*
pThreadInfo
)
{
pThreadInfo
->
fp
=
fopen
(
pThreadInfo
->
filePath
,
"at"
);
if
(
pThreadInfo
->
fp
==
NULL
)
{
errorPrint
(
"%s() LN%d, failed to open result file: %s, result will not save "
"to file
\n
"
,
__func__
,
__LINE__
,
pThreadInfo
->
filePath
);
return
;
}
fprintf
(
pThreadInfo
->
fp
,
"%s"
,
resultBuf
);
tmfclose
(
pThreadInfo
->
fp
);
pThreadInfo
->
fp
=
NULL
;
}
int
postProceSql
(
char
*
host
,
uint16_t
port
,
char
*
sqlstr
,
int
postProceSql
(
char
*
host
,
uint16_t
port
,
char
*
sqlstr
,
threadInfo
*
pThreadInfo
)
{
threadInfo
*
pThreadInfo
)
{
char
*
req_fmt
=
char
*
req_fmt
=
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录