Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
3793640e
T
TDengine
项目概览
taosdata
/
TDengine
大约 1 年 前同步成功
通知
1184
Star
22015
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
3793640e
编写于
3月 11, 2021
作者:
S
Shuduo Sang
浏览文件
操作
浏览文件
下载
差异文件
[TD-3147] <fix>: support insert interval. merge develop.
上级
c58c50ab
de11cdd8
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
141 addition
and
54 deletion
+141
-54
src/kit/taosdemo/taosdemo.c
src/kit/taosdemo/taosdemo.c
+141
-54
未找到文件。
src/kit/taosdemo/taosdemo.c
浏览文件 @
3793640e
...
...
@@ -46,10 +46,11 @@
#include <stdio.h>
#include "os.h"
#ifdef TD_WINDOWS
#ifdef WINDOWS
#include <winsock2.h>
typedef
unsigned
__int32
uint32_t
;
#pragma comment ( lib, "ws2_32.lib" )
#pragma comment ( lib, "winmm.lib" )
#pragma comment ( lib, "wldap32.lib" )
#endif
#endif
...
...
@@ -95,6 +96,7 @@ extern char configDir[];
#define MAX_QUERY_SQL_LENGTH 256
#define MAX_DATABASE_COUNT 256
#define INPUT_BUF_LEN 256
typedef
enum
CREATE_SUB_TALBE_MOD_EN
{
PRE_CREATE_SUBTBL
,
...
...
@@ -1598,18 +1600,17 @@ static void printfQuerySystemInfo(TAOS * taos) {
}
void
ERROR_EXIT
(
const
char
*
msg
)
{
perror
(
msg
);
exit
(
0
);
}
void
ERROR_EXIT
(
const
char
*
msg
)
{
perror
(
msg
);
exit
(
-
1
);
}
int
postProceSql
(
char
*
host
,
uint16_t
port
,
char
*
sqlstr
)
{
char
*
req_fmt
=
"POST %s HTTP/1.1
\r\n
Host: %s:%d
\r\n
Accept: */*
\r\n
%s
\r\n
Content-Length: %d
\r\n
Content-Type: application/x-www-form-urlencoded
\r\n\r\n
%s"
;
char
*
req_fmt
=
"POST %s HTTP/1.1
\r\n
Host: %s:%d
\r\n
Accept: */*
\r\n
Authorization: Basic
%s
\r\n
Content-Length: %d
\r\n
Content-Type: application/x-www-form-urlencoded
\r\n\r\n
%s"
;
char
*
url
=
"/rest/sql"
;
char
*
auth
=
"Authorization: Basic cm9vdDp0YW9zZGF0YQ=="
;
struct
hostent
*
server
;
struct
sockaddr_in
serv_addr
;
int
sockfd
,
bytes
,
sent
,
received
,
req_str_len
,
resp_len
;
int
bytes
,
sent
,
received
,
req_str_len
,
resp_len
;
char
*
request_buf
;
char
response_buf
[
RESP_BUF_LEN
];
uint16_t
rest_port
=
port
+
TSDB_PORT_HTTP
;
...
...
@@ -1620,18 +1621,37 @@ int postProceSql(char* host, uint16_t port, char* sqlstr)
if
(
NULL
==
request_buf
)
ERROR_EXIT
(
"ERROR, cannot allocate memory."
);
int
r
=
snprintf
(
request_buf
,
req_buf_len
,
req_fmt
,
url
,
host
,
rest_port
,
auth
,
strlen
(
sqlstr
),
sqlstr
);
if
(
r
>=
req_buf_len
)
{
free
(
request_buf
);
ERROR_EXIT
(
"ERROR too long request"
);
}
printf
(
"Request:
\n
%s
\n
"
,
request_buf
);
char
userpass_buf
[
INPUT_BUF_LEN
];
int
mod_table
[]
=
{
0
,
2
,
1
};
static
char
base64
[]
=
{
'A'
,
'B'
,
'C'
,
'D'
,
'E'
,
'F'
,
'G'
,
'H'
,
'I'
,
'J'
,
'K'
,
'L'
,
'M'
,
'N'
,
'O'
,
'P'
,
'Q'
,
'R'
,
'S'
,
'T'
,
'U'
,
'V'
,
'W'
,
'X'
,
'Y'
,
'Z'
,
'a'
,
'b'
,
'c'
,
'd'
,
'e'
,
'f'
,
'g'
,
'h'
,
'i'
,
'j'
,
'k'
,
'l'
,
'm'
,
'n'
,
'o'
,
'p'
,
'q'
,
'r'
,
's'
,
't'
,
'u'
,
'v'
,
'w'
,
'x'
,
'y'
,
'z'
,
'0'
,
'1'
,
'2'
,
'3'
,
'4'
,
'5'
,
'6'
,
'7'
,
'8'
,
'9'
,
'+'
,
'/'
};
snprintf
(
userpass_buf
,
INPUT_BUF_LEN
,
"%s:%s"
,
g_Dbs
.
user
,
g_Dbs
.
password
);
size_t
userpass_buf_len
=
strlen
(
userpass_buf
);
size_t
encoded_len
=
4
*
((
userpass_buf_len
+
2
)
/
3
);
char
base64_buf
[
INPUT_BUF_LEN
];
#ifdef WINDOWS
WSADATA
wsaData
;
WSAStartup
(
MAKEWORD
(
2
,
2
),
&
wsaData
);
SOCKET
sockfd
;
#else
int
sockfd
;
#endif
sockfd
=
socket
(
AF_INET
,
SOCK_STREAM
,
0
);
if
(
sockfd
<
0
)
{
#ifdef WINDOWS
fprintf
(
stderr
,
"Could not create socket : %d"
,
WSAGetLastError
());
#endif
debugPrint
(
"%s() LN%d sockfd=%d
\n
"
,
__func__
,
__LINE__
,
sockfd
);
free
(
request_buf
);
ERROR_EXIT
(
"ERROR opening socket"
);
}
...
...
@@ -1642,20 +1662,68 @@ int postProceSql(char* host, uint16_t port, char* sqlstr)
ERROR_EXIT
(
"ERROR, no such host"
);
}
debugPrint
(
"h_name: %s
\n
h_addretype: %s
\n
h_length: %d
\n
"
,
server
->
h_name
,
(
server
->
h_addrtype
==
AF_INET
)
?
"ipv4"
:
"ipv6"
,
server
->
h_length
);
memset
(
&
serv_addr
,
0
,
sizeof
(
serv_addr
));
serv_addr
.
sin_family
=
AF_INET
;
serv_addr
.
sin_port
=
htons
(
rest_port
);
#ifdef WINDOWS
serv_addr
.
sin_addr
.
s_addr
=
inet_addr
(
host
);
#else
memcpy
(
&
serv_addr
.
sin_addr
.
s_addr
,
server
->
h_addr
,
server
->
h_length
);
#endif
if
(
connect
(
sockfd
,(
struct
sockaddr
*
)
&
serv_addr
,
sizeof
(
serv_addr
))
<
0
)
{
int
retConn
=
connect
(
sockfd
,(
struct
sockaddr
*
)
&
serv_addr
,
sizeof
(
serv_addr
));
debugPrint
(
"%s() LN%d connect() return %d
\n
"
,
__func__
,
__LINE__
,
retConn
);
if
(
retConn
<
0
)
{
free
(
request_buf
);
ERROR_EXIT
(
"ERROR connecting"
);
}
memset
(
base64_buf
,
0
,
INPUT_BUF_LEN
);
for
(
int
n
=
0
,
m
=
0
;
n
<
userpass_buf_len
;)
{
uint32_t
oct_a
=
n
<
userpass_buf_len
?
(
unsigned
char
)
userpass_buf
[
n
++
]
:
0
;
uint32_t
oct_b
=
n
<
userpass_buf_len
?
(
unsigned
char
)
userpass_buf
[
n
++
]
:
0
;
uint32_t
oct_c
=
n
<
userpass_buf_len
?
(
unsigned
char
)
userpass_buf
[
n
++
]
:
0
;
uint32_t
triple
=
(
oct_a
<<
0x10
)
+
(
oct_b
<<
0x08
)
+
oct_c
;
base64_buf
[
m
++
]
=
base64
[(
triple
>>
3
*
6
)
&
0x3f
];
base64_buf
[
m
++
]
=
base64
[(
triple
>>
2
*
6
)
&
0x3f
];
base64_buf
[
m
++
]
=
base64
[(
triple
>>
1
*
6
)
&
0x3f
];
base64_buf
[
m
++
]
=
base64
[(
triple
>>
0
*
6
)
&
0x3f
];
}
for
(
int
l
=
0
;
l
<
mod_table
[
userpass_buf_len
%
3
];
l
++
)
base64_buf
[
encoded_len
-
1
-
l
]
=
'='
;
debugPrint
(
"%s() LN%d: auth string base64 encoded: %s
\n
"
,
__func__
,
__LINE__
,
base64_buf
);
char
*
auth
=
base64_buf
;
int
r
=
snprintf
(
request_buf
,
req_buf_len
,
req_fmt
,
url
,
host
,
rest_port
,
auth
,
strlen
(
sqlstr
),
sqlstr
);
if
(
r
>=
req_buf_len
)
{
free
(
request_buf
);
ERROR_EXIT
(
"ERROR too long request"
);
}
verbosePrint
(
"%s() LN%d: Request:
\n
%s
\n
"
,
__func__
,
__LINE__
,
request_buf
);
req_str_len
=
strlen
(
request_buf
);
sent
=
0
;
do
{
#ifdef WINDOWS
bytes
=
send
(
sockfd
,
request_buf
+
sent
,
req_str_len
-
sent
,
0
);
#else
bytes
=
write
(
sockfd
,
request_buf
+
sent
,
req_str_len
-
sent
);
#endif
if
(
bytes
<
0
)
ERROR_EXIT
(
"ERROR writing message to socket"
);
if
(
bytes
==
0
)
...
...
@@ -1667,7 +1735,11 @@ int postProceSql(char* host, uint16_t port, char* sqlstr)
resp_len
=
sizeof
(
response_buf
)
-
1
;
received
=
0
;
do
{
#ifdef WINDOWS
bytes
=
recv
(
sockfd
,
response_buf
+
received
,
resp_len
-
received
,
0
);
#else
bytes
=
read
(
sockfd
,
response_buf
+
received
,
resp_len
-
received
);
#endif
if
(
bytes
<
0
)
{
free
(
request_buf
);
ERROR_EXIT
(
"ERROR reading response from socket"
);
...
...
@@ -1686,7 +1758,12 @@ int postProceSql(char* host, uint16_t port, char* sqlstr)
printf
(
"Response:
\n
%s
\n
"
,
response_buf
);
free
(
request_buf
);
#ifdef WINDOWS
closesocket
(
sockfd
);
WSACleanup
();
#else
close
(
sockfd
);
#endif
return
0
;
}
...
...
@@ -2146,7 +2223,7 @@ static int createDatabases() {
debugPrint
(
"%s() %d command: %s
\n
"
,
__func__
,
__LINE__
,
command
);
if
(
0
!=
queryDbExec
(
taos
,
command
,
NO_INSERT_TYPE
))
{
taos_close
(
taos
);
printf
(
"
\n
create database %s failed!
\n\n
"
,
g_Dbs
.
db
[
i
].
dbName
);
fprintf
(
stderr
,
"
\n
create database %s failed!
\n\n
"
,
g_Dbs
.
db
[
i
].
dbName
);
return
-
1
;
}
printf
(
"
\n
create database %s success!
\n\n
"
,
g_Dbs
.
db
[
i
].
dbName
);
...
...
@@ -2245,6 +2322,7 @@ static void* createTable(void *sarg)
len
=
0
;
verbosePrint
(
"%s() LN%d %s
\n
"
,
__func__
,
__LINE__
,
buffer
);
if
(
0
!=
queryDbExec
(
winfo
->
taos
,
buffer
,
NO_INSERT_TYPE
)){
fprintf
(
stderr
,
"queryDbExec() failed. buffer:
\n
%s
\n
"
,
buffer
);
free
(
buffer
);
return
NULL
;
}
...
...
@@ -2259,7 +2337,9 @@ static void* createTable(void *sarg)
if
(
0
!=
len
)
{
verbosePrint
(
"%s() %d buffer: %s
\n
"
,
__func__
,
__LINE__
,
buffer
);
(
void
)
queryDbExec
(
winfo
->
taos
,
buffer
,
NO_INSERT_TYPE
);
if
(
0
!=
queryDbExec
(
winfo
->
taos
,
buffer
,
NO_INSERT_TYPE
))
{
fprintf
(
stderr
,
"queryDbExec() failed. buffer:
\n
%s
\n
"
,
buffer
);
}
}
free
(
buffer
);
...
...
@@ -3961,9 +4041,7 @@ send_to_server:
int
affectedRows
=
queryDbExec
(
winfo
->
taos
,
buffer
,
INSERT_TYPE
);
if
(
0
>
affectedRows
)
{
goto
free_and_statistics
;
}
else
{
if
(
0
<
affectedRows
)
{
endTs
=
taosGetTimestampUs
();
int64_t
delay
=
endTs
-
startTs
;
if
(
delay
>
winfo
->
maxDelay
)
winfo
->
maxDelay
=
delay
;
...
...
@@ -3972,6 +4050,9 @@ send_to_server:
winfo
->
totalDelay
+=
delay
;
winfo
->
avgDelay
=
(
double
)
winfo
->
totalDelay
/
winfo
->
cntDelay
;
winfo
->
totalAffectedRows
+=
affectedRows
;
}
else
{
fprintf
(
stderr
,
"queryDbExec() buffer:
\n
%s
\n
affected rows is %d"
,
buffer
,
affectedRows
);
goto
free_and_statistics
;
}
int64_t
currentPrintTime
=
taosGetTimestampMs
();
...
...
@@ -4114,10 +4195,11 @@ static void* syncWrite(void *sarg) {
winfo
->
totalAffectedRows
=
0
;
for
(
int
tID
=
winfo
->
start_table_id
;
tID
<=
winfo
->
end_table_id
;
tID
++
)
{
int64_t
tmp_time
=
time_counter
;
for
(
int
i
=
0
;
i
<
g_args
.
num_of_DPT
;)
{
int
tblInserted
=
i
;
int64_t
tmp_time
=
time_counter
;
char
*
pstr
=
buffer
;
pstr
+=
sprintf
(
pstr
,
...
...
@@ -4172,8 +4254,7 @@ static void* syncWrite(void *sarg) {
verbosePrint
(
"%s() LN%d %s
\n
"
,
__func__
,
__LINE__
,
buffer
);
int
affectedRows
=
queryDbExec
(
winfo
->
taos
,
buffer
,
1
);
verbosePrint
(
"%s() LN%d: affectedRows:%d
\n
"
,
__func__
,
__LINE__
,
affectedRows
);
if
(
0
<=
affectedRows
){
if
(
0
<
affectedRows
){
endTs
=
taosGetTimestampUs
();
int64_t
delay
=
endTs
-
startTs
;
if
(
delay
>
winfo
->
maxDelay
)
...
...
@@ -4184,9 +4265,11 @@ static void* syncWrite(void *sarg) {
winfo
->
totalDelay
+=
delay
;
winfo
->
totalAffectedRows
+=
affectedRows
;
winfo
->
avgDelay
=
(
double
)
winfo
->
totalDelay
/
winfo
->
cntDelay
;
}
else
{
fprintf
(
stderr
,
"queryDbExec() buffer:
\n
%s
\n
affected rows is %d"
,
buffer
,
affectedRows
);
}
verbosePrint
(
"%s() LN%d: totalaffectedRows:%"
PRId64
"
\n
"
,
__func__
,
__LINE__
,
winfo
->
totalAffectedRows
);
verbosePrint
(
"%s() LN%d: totalaffectedRows:%"
PRId64
"
tblInserted=%d
\n
"
,
__func__
,
__LINE__
,
winfo
->
totalAffectedRows
,
tblInserted
);
if
(
g_args
.
insert_interval
)
{
et
=
taosGetTimestampMs
();
}
...
...
@@ -4270,7 +4353,7 @@ static void* syncWriteWithStb(void *sarg) {
int
sampleUsePos
;
debug
Print
(
"%s() LN%d insertRows=%"
PRId64
"
\n
"
,
__func__
,
__LINE__
,
superTblInfo
->
insertRows
);
verbose
Print
(
"%s() LN%d insertRows=%"
PRId64
"
\n
"
,
__func__
,
__LINE__
,
superTblInfo
->
insertRows
);
for
(
uint32_t
tID
=
winfo
->
start_table_id
;
tID
<=
winfo
->
end_table_id
;
tID
++
)
{
...
...
@@ -4376,7 +4459,7 @@ static void* syncWriteWithStb(void *sarg) {
}
len
+=
retLen
;
verbosePrint
(
"%s() LN%d retLen=%d len=%d k=%d buffer=%s
\n
"
,
__func__
,
__LINE__
,
retLen
,
len
,
k
,
buffer
);
verbosePrint
(
"%s() LN%d retLen=%d len=%d k=%d
\n
buffer=%s
\n
"
,
__func__
,
__LINE__
,
retLen
,
len
,
k
,
buffer
);
tblInserted
++
;
k
++
;
...
...
@@ -4388,24 +4471,35 @@ static void* syncWriteWithStb(void *sarg) {
winfo
->
totalRowsInserted
+=
k
;
if
(
0
==
strncasecmp
(
superTblInfo
->
insertMode
,
"taosc"
,
strlen
(
"taosc"
)))
{
int64_t
startTs
;
int64_t
startTs
=
taosGetTimestampUs
();
int64_t
endTs
;
startTs
=
taosGetTimestampUs
()
;
int
affectedRows
;
if
(
0
==
strncasecmp
(
superTblInfo
->
insertMode
,
"taosc"
,
strlen
(
"taosc"
)))
{
verbosePrint
(
"%s() LN%d %s
\n
"
,
__func__
,
__LINE__
,
buffer
);
int
affectedRows
=
queryDbExec
(
winfo
->
taos
,
buffer
,
INSERT_TYPE
);
affectedRows
=
queryDbExec
(
winfo
->
taos
,
buffer
,
INSERT_TYPE
);
if
(
0
>
affectedRows
){
goto
free_and_statistics_2
;
}
}
else
{
verbosePrint
(
"%s() LN%d %s
\n
"
,
__func__
,
__LINE__
,
buffer
);
int
retCode
=
postProceSql
(
g_Dbs
.
host
,
g_Dbs
.
port
,
buffer
);
if
(
0
!=
retCode
)
{
printf
(
"========restful return fail, threadID[%d]
\n
"
,
winfo
->
threadID
);
goto
free_and_statistics_2
;
}
affectedRows
=
k
;
}
endTs
=
taosGetTimestampUs
();
int64_t
delay
=
endTs
-
startTs
;
if
(
delay
>
winfo
->
maxDelay
)
winfo
->
maxDelay
=
delay
;
if
(
delay
<
winfo
->
minDelay
)
winfo
->
minDelay
=
delay
;
winfo
->
cntDelay
++
;
winfo
->
totalDelay
+=
delay
;
}
winfo
->
totalAffectedRows
+=
affectedRows
;
int64_t
currentPrintTime
=
taosGetTimestampMs
();
...
...
@@ -4416,14 +4510,7 @@ static void* syncWriteWithStb(void *sarg) {
winfo
->
totalAffectedRows
);
lastPrintTime
=
currentPrintTime
;
}
}
else
{
int
retCode
=
postProceSql
(
g_Dbs
.
host
,
g_Dbs
.
port
,
buffer
);
if
(
0
!=
retCode
)
{
printf
(
"========restful return fail, threadID[%d]
\n
"
,
winfo
->
threadID
);
goto
free_and_statistics_2
;
}
}
if
(
superTblInfo
->
insertInterval
)
{
et
=
taosGetTimestampMs
();
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录