Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
慢慢CG
TDengine
提交
471dc330
T
TDengine
项目概览
慢慢CG
/
TDengine
与 Fork 源项目一致
Fork自
taosdata / TDengine
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
471dc330
编写于
3月 05, 2021
作者:
sangshuduo
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[TD-3147] <fix>: support insert interval. refactor.
上级
17dc360f
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
164 addition
and
119 deletion
+164
-119
src/kit/taosdemo/taosdemo.c
src/kit/taosdemo/taosdemo.c
+164
-119
未找到文件。
src/kit/taosdemo/taosdemo.c
浏览文件 @
471dc330
...
@@ -458,9 +458,9 @@ void resetAfterAnsiEscape(void) {
...
@@ -458,9 +458,9 @@ void resetAfterAnsiEscape(void) {
}
}
#endif
#endif
static
int
createDatabases
();
int
createDatabases
();
static
void
createChildTables
();
void
createChildTables
();
static
int
queryDbExec
(
TAOS
*
taos
,
char
*
command
,
int
type
);
int
queryDbExec
(
TAOS
*
taos
,
char
*
command
,
int
type
);
/* ************ Global variables ************ */
/* ************ Global variables ************ */
...
@@ -774,7 +774,7 @@ void tmfree(char *buf) {
...
@@ -774,7 +774,7 @@ void tmfree(char *buf) {
}
}
}
}
static
int
queryDbExec
(
TAOS
*
taos
,
char
*
command
,
int
type
)
{
int
queryDbExec
(
TAOS
*
taos
,
char
*
command
,
int
type
)
{
int
i
;
int
i
;
TAOS_RES
*
res
=
NULL
;
TAOS_RES
*
res
=
NULL
;
int32_t
code
=
-
1
;
int32_t
code
=
-
1
;
...
@@ -1921,10 +1921,14 @@ static int createSuperTable(TAOS * taos, char* dbName, SSuperTable* superTbls,
...
@@ -1921,10 +1921,14 @@ static int createSuperTable(TAOS * taos, char* dbName, SSuperTable* superTbls,
char
*
dataType
=
superTbls
->
columns
[
colIndex
].
dataType
;
char
*
dataType
=
superTbls
->
columns
[
colIndex
].
dataType
;
if
(
strcasecmp
(
dataType
,
"BINARY"
)
==
0
)
{
if
(
strcasecmp
(
dataType
,
"BINARY"
)
==
0
)
{
len
+=
snprintf
(
cols
+
len
,
STRING_LEN
-
len
,
", col%d %s(%d)"
,
colIndex
,
"BINARY"
,
superTbls
->
columns
[
colIndex
].
dataLen
);
len
+=
snprintf
(
cols
+
len
,
STRING_LEN
-
len
,
", col%d %s(%d)"
,
colIndex
,
"BINARY"
,
superTbls
->
columns
[
colIndex
].
dataLen
);
lenOfOneRow
+=
superTbls
->
columns
[
colIndex
].
dataLen
+
3
;
lenOfOneRow
+=
superTbls
->
columns
[
colIndex
].
dataLen
+
3
;
}
else
if
(
strcasecmp
(
dataType
,
"NCHAR"
)
==
0
)
{
}
else
if
(
strcasecmp
(
dataType
,
"NCHAR"
)
==
0
)
{
len
+=
snprintf
(
cols
+
len
,
STRING_LEN
-
len
,
", col%d %s(%d)"
,
colIndex
,
"NCHAR"
,
superTbls
->
columns
[
colIndex
].
dataLen
);
len
+=
snprintf
(
cols
+
len
,
STRING_LEN
-
len
,
", col%d %s(%d)"
,
colIndex
,
"NCHAR"
,
superTbls
->
columns
[
colIndex
].
dataLen
);
lenOfOneRow
+=
superTbls
->
columns
[
colIndex
].
dataLen
+
3
;
lenOfOneRow
+=
superTbls
->
columns
[
colIndex
].
dataLen
+
3
;
}
else
if
(
strcasecmp
(
dataType
,
"INT"
)
==
0
)
{
}
else
if
(
strcasecmp
(
dataType
,
"INT"
)
==
0
)
{
len
+=
snprintf
(
cols
+
len
,
STRING_LEN
-
len
,
", col%d %s"
,
colIndex
,
"INT"
);
len
+=
snprintf
(
cols
+
len
,
STRING_LEN
-
len
,
", col%d %s"
,
colIndex
,
"INT"
);
...
@@ -2028,65 +2032,77 @@ static int createSuperTable(TAOS * taos, char* dbName, SSuperTable* superTbls,
...
@@ -2028,65 +2032,77 @@ static int createSuperTable(TAOS * taos, char* dbName, SSuperTable* superTbls,
}
}
static
int
createDatabases
()
{
int
createDatabases
()
{
TAOS
*
taos
=
NULL
;
TAOS
*
taos
=
NULL
;
int
ret
=
0
;
int
ret
=
0
;
taos
=
taos_connect
(
g_Dbs
.
host
,
g_Dbs
.
user
,
g_Dbs
.
password
,
NULL
,
g_Dbs
.
port
);
taos
=
taos_connect
(
g_Dbs
.
host
,
g_Dbs
.
user
,
g_Dbs
.
password
,
NULL
,
g_Dbs
.
port
);
if
(
taos
==
NULL
)
{
if
(
taos
==
NULL
)
{
fprintf
(
stderr
,
"Failed to connect to TDengine, reason:%s
\n
"
,
taos_errstr
(
NULL
));
fprintf
(
stderr
,
"Failed to connect to TDengine, reason:%s
\n
"
,
taos_errstr
(
NULL
));
exit
(
-
1
)
;
return
-
1
;
}
}
char
command
[
BUFFER_SIZE
]
=
"
\0
"
;
char
command
[
BUFFER_SIZE
]
=
"
\0
"
;
for
(
int
i
=
0
;
i
<
g_Dbs
.
dbCount
;
i
++
)
{
for
(
int
i
=
0
;
i
<
g_Dbs
.
dbCount
;
i
++
)
{
if
(
g_Dbs
.
db
[
i
].
drop
)
{
if
(
g_Dbs
.
db
[
i
].
drop
)
{
sprintf
(
command
,
"drop database if exists %s;"
,
g_Dbs
.
db
[
i
].
dbName
);
sprintf
(
command
,
"drop database if exists %s;"
,
g_Dbs
.
db
[
i
].
dbName
);
debugPrint
(
"DEBUG %s() %d
\n
"
,
__func__
,
__LINE__
);
debugPrint
(
"DEBUG %s() %d
\n
"
,
__func__
,
__LINE__
);
if
(
0
!=
queryDbExec
(
taos
,
command
,
NO_INSERT_TYPE
))
{
if
(
0
!=
queryDbExec
(
taos
,
command
,
NO_INSERT_TYPE
))
{
taos_close
(
taos
);
taos_close
(
taos
);
return
-
1
;
return
-
1
;
}
}
}
}
int
dataLen
=
0
;
int
dataLen
=
0
;
dataLen
+=
snprintf
(
command
+
dataLen
,
BUFFER_SIZE
-
dataLen
,
"create database if not exists %s "
,
g_Dbs
.
db
[
i
].
dbName
);
dataLen
+=
snprintf
(
command
+
dataLen
,
BUFFER_SIZE
-
dataLen
,
"create database if not exists %s "
,
g_Dbs
.
db
[
i
].
dbName
);
if
(
g_Dbs
.
db
[
i
].
dbCfg
.
blocks
>
0
)
{
if
(
g_Dbs
.
db
[
i
].
dbCfg
.
blocks
>
0
)
{
dataLen
+=
snprintf
(
command
+
dataLen
,
BUFFER_SIZE
-
dataLen
,
"blocks %d "
,
g_Dbs
.
db
[
i
].
dbCfg
.
blocks
);
dataLen
+=
snprintf
(
command
+
dataLen
,
BUFFER_SIZE
-
dataLen
,
"blocks %d "
,
g_Dbs
.
db
[
i
].
dbCfg
.
blocks
);
}
}
if
(
g_Dbs
.
db
[
i
].
dbCfg
.
cache
>
0
)
{
if
(
g_Dbs
.
db
[
i
].
dbCfg
.
cache
>
0
)
{
dataLen
+=
snprintf
(
command
+
dataLen
,
BUFFER_SIZE
-
dataLen
,
"cache %d "
,
g_Dbs
.
db
[
i
].
dbCfg
.
cache
);
dataLen
+=
snprintf
(
command
+
dataLen
,
BUFFER_SIZE
-
dataLen
,
"cache %d "
,
g_Dbs
.
db
[
i
].
dbCfg
.
cache
);
}
}
if
(
g_Dbs
.
db
[
i
].
dbCfg
.
days
>
0
)
{
if
(
g_Dbs
.
db
[
i
].
dbCfg
.
days
>
0
)
{
dataLen
+=
snprintf
(
command
+
dataLen
,
BUFFER_SIZE
-
dataLen
,
"days %d "
,
g_Dbs
.
db
[
i
].
dbCfg
.
days
);
dataLen
+=
snprintf
(
command
+
dataLen
,
BUFFER_SIZE
-
dataLen
,
"days %d "
,
g_Dbs
.
db
[
i
].
dbCfg
.
days
);
}
}
if
(
g_Dbs
.
db
[
i
].
dbCfg
.
keep
>
0
)
{
if
(
g_Dbs
.
db
[
i
].
dbCfg
.
keep
>
0
)
{
dataLen
+=
snprintf
(
command
+
dataLen
,
BUFFER_SIZE
-
dataLen
,
"keep %d "
,
g_Dbs
.
db
[
i
].
dbCfg
.
keep
);
dataLen
+=
snprintf
(
command
+
dataLen
,
BUFFER_SIZE
-
dataLen
,
"keep %d "
,
g_Dbs
.
db
[
i
].
dbCfg
.
keep
);
}
}
if
(
g_Dbs
.
db
[
i
].
dbCfg
.
replica
>
0
)
{
if
(
g_Dbs
.
db
[
i
].
dbCfg
.
replica
>
0
)
{
dataLen
+=
snprintf
(
command
+
dataLen
,
BUFFER_SIZE
-
dataLen
,
"replica %d "
,
g_Dbs
.
db
[
i
].
dbCfg
.
replica
);
dataLen
+=
snprintf
(
command
+
dataLen
,
BUFFER_SIZE
-
dataLen
,
"replica %d "
,
g_Dbs
.
db
[
i
].
dbCfg
.
replica
);
}
}
if
(
g_Dbs
.
db
[
i
].
dbCfg
.
update
>
0
)
{
if
(
g_Dbs
.
db
[
i
].
dbCfg
.
update
>
0
)
{
dataLen
+=
snprintf
(
command
+
dataLen
,
BUFFER_SIZE
-
dataLen
,
"update %d "
,
g_Dbs
.
db
[
i
].
dbCfg
.
update
);
dataLen
+=
snprintf
(
command
+
dataLen
,
BUFFER_SIZE
-
dataLen
,
"update %d "
,
g_Dbs
.
db
[
i
].
dbCfg
.
update
);
}
}
//if (g_Dbs.db[i].dbCfg.maxtablesPerVnode > 0) {
//if (g_Dbs.db[i].dbCfg.maxtablesPerVnode > 0) {
// dataLen += snprintf(command + dataLen, BUFFER_SIZE - dataLen, "tables %d ", g_Dbs.db[i].dbCfg.maxtablesPerVnode);
// dataLen += snprintf(command + dataLen,
// BUFFER_SIZE - dataLen, "tables %d ", g_Dbs.db[i].dbCfg.maxtablesPerVnode);
//}
//}
if
(
g_Dbs
.
db
[
i
].
dbCfg
.
minRows
>
0
)
{
if
(
g_Dbs
.
db
[
i
].
dbCfg
.
minRows
>
0
)
{
dataLen
+=
snprintf
(
command
+
dataLen
,
BUFFER_SIZE
-
dataLen
,
"minrows %d "
,
g_Dbs
.
db
[
i
].
dbCfg
.
minRows
);
dataLen
+=
snprintf
(
command
+
dataLen
,
BUFFER_SIZE
-
dataLen
,
"minrows %d "
,
g_Dbs
.
db
[
i
].
dbCfg
.
minRows
);
}
}
if
(
g_Dbs
.
db
[
i
].
dbCfg
.
maxRows
>
0
)
{
if
(
g_Dbs
.
db
[
i
].
dbCfg
.
maxRows
>
0
)
{
dataLen
+=
snprintf
(
command
+
dataLen
,
BUFFER_SIZE
-
dataLen
,
"maxrows %d "
,
g_Dbs
.
db
[
i
].
dbCfg
.
maxRows
);
dataLen
+=
snprintf
(
command
+
dataLen
,
BUFFER_SIZE
-
dataLen
,
"maxrows %d "
,
g_Dbs
.
db
[
i
].
dbCfg
.
maxRows
);
}
}
if
(
g_Dbs
.
db
[
i
].
dbCfg
.
comp
>
0
)
{
if
(
g_Dbs
.
db
[
i
].
dbCfg
.
comp
>
0
)
{
dataLen
+=
snprintf
(
command
+
dataLen
,
BUFFER_SIZE
-
dataLen
,
"comp %d "
,
g_Dbs
.
db
[
i
].
dbCfg
.
comp
);
dataLen
+=
snprintf
(
command
+
dataLen
,
BUFFER_SIZE
-
dataLen
,
"comp %d "
,
g_Dbs
.
db
[
i
].
dbCfg
.
comp
);
}
}
if
(
g_Dbs
.
db
[
i
].
dbCfg
.
walLevel
>
0
)
{
if
(
g_Dbs
.
db
[
i
].
dbCfg
.
walLevel
>
0
)
{
dataLen
+=
snprintf
(
command
+
dataLen
,
BUFFER_SIZE
-
dataLen
,
"wal %d "
,
g_Dbs
.
db
[
i
].
dbCfg
.
walLevel
);
dataLen
+=
snprintf
(
command
+
dataLen
,
BUFFER_SIZE
-
dataLen
,
"wal %d "
,
g_Dbs
.
db
[
i
].
dbCfg
.
walLevel
);
}
}
if
(
g_Dbs
.
db
[
i
].
dbCfg
.
cacheLast
>
0
)
{
if
(
g_Dbs
.
db
[
i
].
dbCfg
.
cacheLast
>
0
)
{
dataLen
+=
snprintf
(
command
+
dataLen
,
BUFFER_SIZE
-
dataLen
,
"cachelast %d "
,
g_Dbs
.
db
[
i
].
dbCfg
.
cacheLast
);
dataLen
+=
snprintf
(
command
+
dataLen
,
BUFFER_SIZE
-
dataLen
,
"cachelast %d "
,
g_Dbs
.
db
[
i
].
dbCfg
.
cacheLast
);
}
}
if
(
g_Dbs
.
db
[
i
].
dbCfg
.
fsync
>
0
)
{
if
(
g_Dbs
.
db
[
i
].
dbCfg
.
fsync
>
0
)
{
dataLen
+=
snprintf
(
command
+
dataLen
,
BUFFER_SIZE
-
dataLen
,
"fsync %d "
,
g_Dbs
.
db
[
i
].
dbCfg
.
fsync
);
dataLen
+=
snprintf
(
command
+
dataLen
,
BUFFER_SIZE
-
dataLen
,
"fsync %d "
,
g_Dbs
.
db
[
i
].
dbCfg
.
fsync
);
...
@@ -2100,6 +2116,7 @@ static int createDatabases() {
...
@@ -2100,6 +2116,7 @@ static int createDatabases() {
debugPrint
(
"DEBUG %s() %d
\n
"
,
__func__
,
__LINE__
);
debugPrint
(
"DEBUG %s() %d
\n
"
,
__func__
,
__LINE__
);
if
(
0
!=
queryDbExec
(
taos
,
command
,
NO_INSERT_TYPE
))
{
if
(
0
!=
queryDbExec
(
taos
,
command
,
NO_INSERT_TYPE
))
{
taos_close
(
taos
);
taos_close
(
taos
);
printf
(
"
\n
create database %s failed!
\n\n
"
,
g_Dbs
.
db
[
i
].
dbName
);
return
-
1
;
return
-
1
;
}
}
printf
(
"
\n
create database %s success!
\n\n
"
,
g_Dbs
.
db
[
i
].
dbName
);
printf
(
"
\n
create database %s success!
\n\n
"
,
g_Dbs
.
db
[
i
].
dbName
);
...
@@ -2108,7 +2125,7 @@ static int createDatabases() {
...
@@ -2108,7 +2125,7 @@ static int createDatabases() {
for
(
int
j
=
0
;
j
<
g_Dbs
.
db
[
i
].
superTblCount
;
j
++
)
{
for
(
int
j
=
0
;
j
<
g_Dbs
.
db
[
i
].
superTblCount
;
j
++
)
{
// describe super table, if exists
// describe super table, if exists
sprintf
(
command
,
"describe %s.%s;"
,
g_Dbs
.
db
[
i
].
dbName
,
g_Dbs
.
db
[
i
].
superTbls
[
j
].
sTblName
);
sprintf
(
command
,
"describe %s.%s;"
,
g_Dbs
.
db
[
i
].
dbName
,
g_Dbs
.
db
[
i
].
superTbls
[
j
].
sTblName
);
debugPrint
(
"DEBUG %s() %d
\n
"
,
__func__
,
__LINE__
);
debugPrint
(
"DEBUG %s() %d
\n
"
,
__func__
,
__LINE__
);
if
(
0
!=
queryDbExec
(
taos
,
command
,
NO_INSERT_TYPE
))
{
if
(
0
!=
queryDbExec
(
taos
,
command
,
NO_INSERT_TYPE
))
{
g_Dbs
.
db
[
i
].
superTbls
[
j
].
superTblExists
=
TBL_NO_EXISTS
;
g_Dbs
.
db
[
i
].
superTbls
[
j
].
superTblExists
=
TBL_NO_EXISTS
;
ret
=
createSuperTable
(
taos
,
g_Dbs
.
db
[
i
].
dbName
,
&
g_Dbs
.
db
[
i
].
superTbls
[
j
],
g_Dbs
.
use_metric
);
ret
=
createSuperTable
(
taos
,
g_Dbs
.
db
[
i
].
dbName
,
&
g_Dbs
.
db
[
i
].
superTbls
[
j
],
g_Dbs
.
use_metric
);
...
@@ -2118,8 +2135,11 @@ static int createDatabases() {
...
@@ -2118,8 +2135,11 @@ static int createDatabases() {
}
}
if
(
0
!=
ret
)
{
if
(
0
!=
ret
)
{
printf
(
"
\n
create super table %d failed!
\n\n
"
,
j
);
taos_close
(
taos
);
taos_close
(
taos
);
return
-
1
;
return
-
1
;
}
else
{
printf
(
"
\n
create super table %d success!
\n\n
"
,
j
);
}
}
}
}
}
}
...
@@ -2135,14 +2155,24 @@ void * createTable(void *sarg)
...
@@ -2135,14 +2155,24 @@ void * createTable(void *sarg)
int64_t
lastPrintTime
=
taosGetTimestampMs
();
int64_t
lastPrintTime
=
taosGetTimestampMs
();
char
*
buffer
=
calloc
(
superTblInfo
->
maxSqlLen
,
1
);
int
buff_len
;
if
(
superTblInfo
)
buff_len
=
superTblInfo
->
maxSqlLen
;
else
buff_len
=
BUFFER_SIZE
;
char
*
buffer
=
calloc
(
superTblInfo
->
maxSqlLen
,
1
);
if
(
buffer
==
NULL
)
{
fprintf
(
stderr
,
"Memory allocated failed!"
);
exit
(
-
1
);
}
int
len
=
0
;
int
len
=
0
;
int
batchNum
=
0
;
int
batchNum
=
0
;
//printf("Creating table from %d to %d\n", winfo->start_table_id, winfo->end_table_id);
//printf("Creating table from %d to %d\n", winfo->start_table_id, winfo->end_table_id);
for
(
int
i
=
winfo
->
start_table_id
;
i
<=
winfo
->
end_table_id
;
i
++
)
{
for
(
int
i
=
winfo
->
start_table_id
;
i
<=
winfo
->
end_table_id
;
i
++
)
{
if
(
0
==
g_Dbs
.
use_metric
)
{
if
(
0
==
g_Dbs
.
use_metric
)
{
snprintf
(
buffer
,
BUFFER_SIZE
,
snprintf
(
buffer
,
buff_len
,
"create table if not exists %s.%s%d %s;"
,
"create table if not exists %s.%s%d %s;"
,
winfo
->
db_name
,
winfo
->
db_name
,
superTblInfo
->
childTblPrefix
,
i
,
superTblInfo
->
childTblPrefix
,
i
,
...
@@ -2150,11 +2180,11 @@ void * createTable(void *sarg)
...
@@ -2150,11 +2180,11 @@ void * createTable(void *sarg)
}
else
{
}
else
{
if
(
0
==
len
)
{
if
(
0
==
len
)
{
batchNum
=
0
;
batchNum
=
0
;
memset
(
buffer
,
0
,
superTblInfo
->
maxSqlL
en
);
memset
(
buffer
,
0
,
buff_l
en
);
len
+=
snprintf
(
buffer
+
len
,
len
+=
snprintf
(
buffer
+
len
,
superTblInfo
->
maxSqlL
en
-
len
,
"create table "
);
buff_l
en
-
len
,
"create table "
);
}
}
char
*
tagsValBuf
=
NULL
;
char
*
tagsValBuf
=
NULL
;
if
(
0
==
superTblInfo
->
tagSource
)
{
if
(
0
==
superTblInfo
->
tagSource
)
{
tagsValBuf
=
generateTagVaulesForStb
(
superTblInfo
);
tagsValBuf
=
generateTagVaulesForStb
(
superTblInfo
);
...
@@ -2208,7 +2238,7 @@ void * createTable(void *sarg)
...
@@ -2208,7 +2238,7 @@ void * createTable(void *sarg)
return
NULL
;
return
NULL
;
}
}
void
startMultiThreadCreateChildTable
(
int
startMultiThreadCreateChildTable
(
char
*
cols
,
int
threads
,
int
ntables
,
char
*
cols
,
int
threads
,
int
ntables
,
char
*
db_name
,
SSuperTable
*
superTblInfo
)
{
char
*
db_name
,
SSuperTable
*
superTblInfo
)
{
pthread_t
*
pids
=
malloc
(
threads
*
sizeof
(
pthread_t
));
pthread_t
*
pids
=
malloc
(
threads
*
sizeof
(
pthread_t
));
...
@@ -2231,7 +2261,7 @@ void startMultiThreadCreateChildTable(
...
@@ -2231,7 +2261,7 @@ void startMultiThreadCreateChildTable(
int
b
=
0
;
int
b
=
0
;
b
=
ntables
%
threads
;
b
=
ntables
%
threads
;
int
last
=
0
;
int
last
=
0
;
for
(
int
i
=
0
;
i
<
threads
;
i
++
)
{
for
(
int
i
=
0
;
i
<
threads
;
i
++
)
{
threadInfo
*
t_info
=
infos
+
i
;
threadInfo
*
t_info
=
infos
+
i
;
...
@@ -2244,6 +2274,10 @@ void startMultiThreadCreateChildTable(
...
@@ -2244,6 +2274,10 @@ void startMultiThreadCreateChildTable(
g_Dbs
.
password
,
g_Dbs
.
password
,
db_name
,
db_name
,
g_Dbs
.
port
);
g_Dbs
.
port
);
if
(
t_info
->
taos
==
NULL
)
{
fprintf
(
stderr
,
"Failed to connect to TDengine, reason:%s
\n
"
,
taos_errstr
(
NULL
));
return
-
1
;
}
t_info
->
start_table_id
=
last
;
t_info
->
start_table_id
=
last
;
t_info
->
end_table_id
=
i
<
b
?
last
+
a
:
last
+
a
-
1
;
t_info
->
end_table_id
=
i
<
b
?
last
+
a
:
last
+
a
-
1
;
last
=
t_info
->
end_table_id
+
1
;
last
=
t_info
->
end_table_id
+
1
;
...
@@ -2264,23 +2298,35 @@ void startMultiThreadCreateChildTable(
...
@@ -2264,23 +2298,35 @@ void startMultiThreadCreateChildTable(
free
(
pids
);
free
(
pids
);
free
(
infos
);
free
(
infos
);
return
0
;
}
}
static
void
createChildTables
()
{
void
createChildTables
()
{
for
(
int
i
=
0
;
i
<
g_Dbs
.
dbCount
;
i
++
)
{
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
].
superTblCount
>
0
)
{
if
((
AUTO_CREATE_SUBTBL
==
g_Dbs
.
db
[
i
].
superTbls
[
j
].
autoCreateTable
)
for
(
int
j
=
0
;
j
<
g_Dbs
.
db
[
i
].
superTblCount
;
j
++
)
{
if
((
AUTO_CREATE_SUBTBL
==
g_Dbs
.
db
[
i
].
superTbls
[
j
].
autoCreateTable
)
||
(
TBL_ALREADY_EXISTS
==
g_Dbs
.
db
[
i
].
superTbls
[
j
].
childTblExists
))
{
||
(
TBL_ALREADY_EXISTS
==
g_Dbs
.
db
[
i
].
superTbls
[
j
].
childTblExists
))
{
continue
;
continue
;
}
}
startMultiThreadCreateChildTable
(
startMultiThreadCreateChildTable
(
g_Dbs
.
db
[
i
].
superTbls
[
j
].
colsOfCreatChildTable
,
g_Dbs
.
db
[
i
].
superTbls
[
j
].
colsOfCreatChildTable
,
g_Dbs
.
threadCountByCreateTbl
,
g_Dbs
.
threadCountByCreateTbl
,
g_Dbs
.
db
[
i
].
superTbls
[
j
].
childTblCount
,
g_Dbs
.
db
[
i
].
superTbls
[
j
].
childTblCount
,
g_Dbs
.
db
[
i
].
dbName
,
&
(
g_Dbs
.
db
[
i
].
superTbls
[
j
]));
g_Dbs
.
db
[
i
].
dbName
,
&
(
g_Dbs
.
db
[
i
].
superTbls
[
j
]));
g_totalChildTables
+=
g_Dbs
.
db
[
i
].
superTbls
[
j
].
childTblCount
;
g_totalChildTables
+=
g_Dbs
.
db
[
i
].
superTbls
[
j
].
childTblCount
;
}
}
}
else
{
startMultiThreadCreateChildTable
(
g_Dbs
.
db
[
i
].
superTbls
[
j
].
colsOfCreatChildTable
,
g_Dbs
.
threadCountByCreateTbl
,
g_args
.
num_of_DPT
,
g_Dbs
.
db
[
i
].
dbName
,
NULL
);
}
}
}
}
}
...
@@ -4524,14 +4570,6 @@ void *readMetric(void *sarg) {
...
@@ -4524,14 +4570,6 @@ void *readMetric(void *sarg) {
int
insertTestProcess
()
{
int
insertTestProcess
()
{
debugPrint
(
"DEBUG - %d result file: %s
\n
"
,
__LINE__
,
g_Dbs
.
resultFile
);
g_fpOfInsertResult
=
fopen
(
g_Dbs
.
resultFile
,
"a"
);
if
(
NULL
==
g_fpOfInsertResult
)
{
fprintf
(
stderr
,
"Failed to open %s for save result
\n
"
,
g_Dbs
.
resultFile
);
return
1
;
};
setupForAnsiEscape
();
setupForAnsiEscape
();
int
ret
=
printfInsertMeta
();
int
ret
=
printfInsertMeta
();
resetAfterAnsiEscape
();
resetAfterAnsiEscape
();
...
@@ -4539,7 +4577,14 @@ int insertTestProcess() {
...
@@ -4539,7 +4577,14 @@ int insertTestProcess() {
if
(
ret
==
-
1
)
if
(
ret
==
-
1
)
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
printfInsertMetaToFile
(
g_fpOfInsertResult
);
debugPrint
(
"DEBUG - %d result file: %s
\n
"
,
__LINE__
,
g_Dbs
.
resultFile
);
g_fpOfInsertResult
=
fopen
(
g_Dbs
.
resultFile
,
"a"
);
if
(
NULL
==
g_fpOfInsertResult
)
{
fprintf
(
stderr
,
"Failed to open %s for save result
\n
"
,
g_Dbs
.
resultFile
);
return
-
1
;
}
{
printfInsertMetaToFile
(
g_fpOfInsertResult
);
}
if
(
!
g_args
.
answer_yes
)
{
if
(
!
g_args
.
answer_yes
)
{
printf
(
"Press enter key to continue
\n\n
"
);
printf
(
"Press enter key to continue
\n\n
"
);
...
@@ -4549,7 +4594,10 @@ int insertTestProcess() {
...
@@ -4549,7 +4594,10 @@ int insertTestProcess() {
init_rand_data
();
init_rand_data
();
// create database and super tables
// create database and super tables
(
void
)
createDatabases
();
if
(
createDatabases
()
!=
0
)
{
fclose
(
g_fpOfInsertResult
);
return
-
1
;
}
// pretreatement
// pretreatement
prePareSampleData
();
prePareSampleData
();
...
@@ -4561,6 +4609,7 @@ int insertTestProcess() {
...
@@ -4561,6 +4609,7 @@ int insertTestProcess() {
start
=
getCurrentTime
();
start
=
getCurrentTime
();
createChildTables
();
createChildTables
();
end
=
getCurrentTime
();
end
=
getCurrentTime
();
if
(
g_totalChildTables
>
0
)
{
if
(
g_totalChildTables
>
0
)
{
printf
(
"Spent %.4f seconds to create %d tables with %d thread(s)
\n\n
"
,
printf
(
"Spent %.4f seconds to create %d tables with %d thread(s)
\n\n
"
,
end
-
start
,
g_totalChildTables
,
g_Dbs
.
threadCount
);
end
-
start
,
g_totalChildTables
,
g_Dbs
.
threadCount
);
...
@@ -4570,7 +4619,6 @@ int insertTestProcess() {
...
@@ -4570,7 +4619,6 @@ int insertTestProcess() {
}
}
taosMsleep
(
1000
);
taosMsleep
(
1000
);
// create sub threads for inserting data
// create sub threads for inserting data
//start = getCurrentTime();
//start = getCurrentTime();
for
(
int
i
=
0
;
i
<
g_Dbs
.
dbCount
;
i
++
)
{
for
(
int
i
=
0
;
i
<
g_Dbs
.
dbCount
;
i
++
)
{
...
@@ -4604,36 +4652,8 @@ int insertTestProcess() {
...
@@ -4604,36 +4652,8 @@ int insertTestProcess() {
// totalAffectedRows += g_Dbs.db[i].superTbls[j].totalAffectedRows;
// totalAffectedRows += g_Dbs.db[i].superTbls[j].totalAffectedRows;
//}
//}
//printf("Spent %.4f seconds to insert rows: %"PRId64", affected rows: %"PRId64" with %d thread(s)\n\n", end - start, totalRowsInserted, totalAffectedRows, g_Dbs.threadCount);
//printf("Spent %.4f seconds to insert rows: %"PRId64", affected rows: %"PRId64" with %d thread(s)\n\n", end - start, totalRowsInserted, totalAffectedRows, g_Dbs.threadCount);
if
(
NULL
==
g_args
.
metaFile
&&
false
==
g_Dbs
.
insert_only
)
{
// query data
pthread_t
read_id
;
threadInfo
*
rInfo
=
malloc
(
sizeof
(
threadInfo
));
rInfo
->
start_time
=
1500000000000
;
// 2017-07-14 10:40:00.000
rInfo
->
start_table_id
=
0
;
rInfo
->
end_table_id
=
g_Dbs
.
db
[
0
].
superTbls
[
0
].
childTblCount
-
1
;
//rInfo->do_aggreFunc = g_Dbs.do_aggreFunc;
//rInfo->nrecords_per_table = g_Dbs.db[0].superTbls[0].insertRows;
rInfo
->
superTblInfo
=
&
g_Dbs
.
db
[
0
].
superTbls
[
0
];
rInfo
->
taos
=
taos_connect
(
g_Dbs
.
host
,
g_Dbs
.
user
,
g_Dbs
.
password
,
g_Dbs
.
db
[
0
].
dbName
,
g_Dbs
.
port
);
strcpy
(
rInfo
->
tb_prefix
,
g_Dbs
.
db
[
0
].
superTbls
[
0
].
childTblPrefix
);
strcpy
(
rInfo
->
fp
,
g_Dbs
.
resultFile
);
if
(
!
g_Dbs
.
use_metric
)
{
pthread_create
(
&
read_id
,
NULL
,
readTable
,
rInfo
);
}
else
{
pthread_create
(
&
read_id
,
NULL
,
readMetric
,
rInfo
);
}
pthread_join
(
read_id
,
NULL
);
taos_close
(
rInfo
->
taos
);
}
postFreeResource
();
postFreeResource
();
return
0
;
return
0
;
}
}
...
@@ -5259,6 +5279,7 @@ void setParaFromArg(){
...
@@ -5259,6 +5279,7 @@ void setParaFromArg(){
g_Dbs
.
db
[
0
].
superTbls
[
0
].
tags
[
1
].
dataLen
=
g_args
.
len_of_binary
;
g_Dbs
.
db
[
0
].
superTbls
[
0
].
tags
[
1
].
dataLen
=
g_args
.
len_of_binary
;
g_Dbs
.
db
[
0
].
superTbls
[
0
].
tagCount
=
2
;
g_Dbs
.
db
[
0
].
superTbls
[
0
].
tagCount
=
2
;
}
else
{
}
else
{
g_Dbs
.
threadCountByCreateTbl
=
1
;
g_Dbs
.
db
[
0
].
superTbls
[
0
].
tagCount
=
0
;
g_Dbs
.
db
[
0
].
superTbls
[
0
].
tagCount
=
0
;
}
}
...
@@ -5306,7 +5327,7 @@ void querySqlFile(TAOS* taos, char* sqlFile)
...
@@ -5306,7 +5327,7 @@ void querySqlFile(TAOS* taos, char* sqlFile)
printf
(
"failed to open file %s, reason:%s
\n
"
,
sqlFile
,
strerror
(
errno
));
printf
(
"failed to open file %s, reason:%s
\n
"
,
sqlFile
,
strerror
(
errno
));
return
;
return
;
}
}
int
read_len
=
0
;
int
read_len
=
0
;
char
*
cmd
=
calloc
(
1
,
MAX_SQL_SIZE
);
char
*
cmd
=
calloc
(
1
,
MAX_SQL_SIZE
);
size_t
cmd_len
=
0
;
size_t
cmd_len
=
0
;
...
@@ -5314,7 +5335,7 @@ void querySqlFile(TAOS* taos, char* sqlFile)
...
@@ -5314,7 +5335,7 @@ void querySqlFile(TAOS* taos, char* sqlFile)
size_t
line_len
=
0
;
size_t
line_len
=
0
;
double
t
=
getCurrentTime
();
double
t
=
getCurrentTime
();
while
((
read_len
=
tgetline
(
&
line
,
&
line_len
,
fp
))
!=
-
1
)
{
while
((
read_len
=
tgetline
(
&
line
,
&
line_len
,
fp
))
!=
-
1
)
{
if
(
read_len
>=
MAX_SQL_SIZE
)
continue
;
if
(
read_len
>=
MAX_SQL_SIZE
)
continue
;
line
[
--
read_len
]
=
'\0'
;
line
[
--
read_len
]
=
'\0'
;
...
@@ -5346,23 +5367,12 @@ void querySqlFile(TAOS* taos, char* sqlFile)
...
@@ -5346,23 +5367,12 @@ void querySqlFile(TAOS* taos, char* sqlFile)
return
;
return
;
}
}
int
main
(
int
argc
,
char
*
argv
[])
{
parse_args
(
argc
,
argv
,
&
g_args
);
debugPrint
(
"DEBUG - meta file: %s
\n
"
,
g_args
.
metaFile
);
if
(
g_args
.
metaFile
)
{
initOfInsertMeta
();
initOfQueryMeta
();
if
(
false
==
getInfoFromJsonFile
(
g_args
.
metaFile
))
{
printf
(
"Failed to read %s
\n
"
,
g_args
.
metaFile
);
return
1
;
}
void
testMetaFile
()
{
if
(
INSERT_MODE
==
g_args
.
test_mode
)
{
if
(
INSERT_MODE
==
g_args
.
test_mode
)
{
if
(
g_Dbs
.
cfgDir
[
0
])
taos_options
(
TSDB_OPTION_CONFIGDIR
,
g_Dbs
.
cfgDir
);
if
(
g_Dbs
.
cfgDir
[
0
])
taos_options
(
TSDB_OPTION_CONFIGDIR
,
g_Dbs
.
cfgDir
);
(
void
)
insertTestProcess
();
insertTestProcess
();
}
else
if
(
QUERY_MODE
==
g_args
.
test_mode
)
{
}
else
if
(
QUERY_MODE
==
g_args
.
test_mode
)
{
if
(
g_queryInfo
.
cfgDir
[
0
])
if
(
g_queryInfo
.
cfgDir
[
0
])
taos_options
(
TSDB_OPTION_CONFIGDIR
,
g_queryInfo
.
cfgDir
);
taos_options
(
TSDB_OPTION_CONFIGDIR
,
g_queryInfo
.
cfgDir
);
...
@@ -5374,46 +5384,48 @@ int main(int argc, char *argv[]) {
...
@@ -5374,46 +5384,48 @@ int main(int argc, char *argv[]) {
}
else
{
}
else
{
;
;
}
}
}
else
{
}
memset
(
&
g_Dbs
,
0
,
sizeof
(
SDbs
));
g_args
.
test_mode
=
INSERT_MODE
;
setParaFromArg
();
if
(
NULL
!=
g_args
.
sqlFile
)
{
void
testCmdLine
()
{
TAOS
*
qtaos
=
taos_connect
(
g_Dbs
.
host
,
g_Dbs
.
user
,
g_Dbs
.
password
,
g_Dbs
.
db
[
0
].
dbName
,
g_Dbs
.
port
);
querySqlFile
(
qtaos
,
g_args
.
sqlFile
);
taos_close
(
qtaos
);
return
0
;
}
(
void
)
insertTestProcess
();
g_args
.
test_mode
=
INSERT_MODE
;
if
(
g_Dbs
.
insert_only
)
return
0
;
insertTestProcess
();
if
(
g_Dbs
.
insert_only
)
return
;
// select
// select
if
(
false
==
g_Dbs
.
insert_only
)
{
if
(
false
==
g_Dbs
.
insert_only
)
{
// query data
// query data
pthread_t
read_id
;
pthread_t
read_id
;
threadInfo
*
rInfo
=
malloc
(
sizeof
(
threadInfo
));
threadInfo
*
rInfo
=
malloc
(
sizeof
(
threadInfo
));
rInfo
->
start_time
=
1500000000000
;
// 2017-07-14 10:40:00.000
rInfo
->
start_time
=
1500000000000
;
// 2017-07-14 10:40:00.000
rInfo
->
start_table_id
=
0
;
rInfo
->
start_table_id
=
0
;
rInfo
->
end_table_id
=
g_Dbs
.
db
[
0
].
superTbls
[
0
].
childTblCount
-
1
;
//rInfo->do_aggreFunc = g_Dbs.do_aggreFunc;
//rInfo->do_aggreFunc = g_Dbs.do_aggreFunc;
//rInfo->nrecords_per_table = g_Dbs.db[0].superTbls[0].insertRows;
if
(
g_args
.
use_metric
)
{
rInfo
->
superTblInfo
=
&
g_Dbs
.
db
[
0
].
superTbls
[
0
];
rInfo
->
end_table_id
=
g_Dbs
.
db
[
0
].
superTbls
[
0
].
childTblCount
-
1
;
rInfo
->
superTblInfo
=
&
g_Dbs
.
db
[
0
].
superTbls
[
0
];
strcpy
(
rInfo
->
tb_prefix
,
g_Dbs
.
db
[
0
].
superTbls
[
0
].
childTblPrefix
);
}
else
{
rInfo
->
end_table_id
=
g_args
.
num_of_tables
-
1
;
strcpy
(
rInfo
->
tb_prefix
,
g_args
.
tb_prefix
);
}
rInfo
->
taos
=
taos_connect
(
rInfo
->
taos
=
taos_connect
(
g_Dbs
.
host
,
g_Dbs
.
host
,
g_Dbs
.
user
,
g_Dbs
.
user
,
g_Dbs
.
password
,
g_Dbs
.
password
,
g_Dbs
.
db
[
0
].
dbName
,
g_Dbs
.
db
[
0
].
dbName
,
g_Dbs
.
port
);
g_Dbs
.
port
);
strcpy
(
rInfo
->
tb_prefix
,
if
(
rInfo
->
taos
==
NULL
)
{
g_Dbs
.
db
[
0
].
superTbls
[
0
].
childTblPrefix
);
fprintf
(
stderr
,
"Failed to connect to TDengine, reason:%s
\n
"
,
taos_errstr
(
NULL
));
free
(
rInfo
);
exit
(
-
1
);
}
strcpy
(
rInfo
->
fp
,
g_Dbs
.
resultFile
);
strcpy
(
rInfo
->
fp
,
g_Dbs
.
resultFile
);
if
(
!
g_Dbs
.
use_metric
)
{
if
(
!
g_Dbs
.
use_metric
)
{
...
@@ -5425,9 +5437,42 @@ int main(int argc, char *argv[]) {
...
@@ -5425,9 +5437,42 @@ int main(int argc, char *argv[]) {
taos_close
(
rInfo
->
taos
);
taos_close
(
rInfo
->
taos
);
free
(
rInfo
);
free
(
rInfo
);
}
}
}
int
main
(
int
argc
,
char
*
argv
[])
{
parse_args
(
argc
,
argv
,
&
g_args
);
debugPrint
(
"DEBUG - meta file: %s
\n
"
,
g_args
.
metaFile
);
if
(
g_args
.
metaFile
)
{
initOfInsertMeta
();
initOfQueryMeta
();
if
(
false
==
getInfoFromJsonFile
(
g_args
.
metaFile
))
{
printf
(
"Failed to read %s
\n
"
,
g_args
.
metaFile
);
return
1
;
}
testMetaFile
();
}
else
{
memset
(
&
g_Dbs
,
0
,
sizeof
(
SDbs
));
setParaFromArg
();
if
(
NULL
!=
g_args
.
sqlFile
)
{
TAOS
*
qtaos
=
taos_connect
(
g_Dbs
.
host
,
g_Dbs
.
user
,
g_Dbs
.
password
,
g_Dbs
.
db
[
0
].
dbName
,
g_Dbs
.
port
);
querySqlFile
(
qtaos
,
g_args
.
sqlFile
);
taos_close
(
qtaos
);
}
else
{
testCmdLine
();
}
}
}
taos_cleanup
();
return
0
;
return
0
;
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录