Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
c35b9386
T
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
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看板
提交
c35b9386
编写于
2月 16, 2023
作者:
dengyihao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix invalid read/write
上级
a6a8daec
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
143 addition
and
126 deletion
+143
-126
source/libs/transport/src/transCli.c
source/libs/transport/src/transCli.c
+143
-126
未找到文件。
source/libs/transport/src/transCli.c
浏览文件 @
c35b9386
...
@@ -20,6 +20,15 @@ typedef struct SConnList {
...
@@ -20,6 +20,15 @@ typedef struct SConnList {
int32_t
size
;
int32_t
size
;
}
SConnList
;
}
SConnList
;
typedef
struct
{
queue
wq
;
int32_t
wLen
;
int32_t
batchSize
;
//
int32_t
batch
;
char
*
dst
;
char
*
ip
;
uint16_t
port
;
}
SCliBatch
;
typedef
struct
SCliConn
{
typedef
struct
SCliConn
{
T_REF_DECLARE
()
T_REF_DECLARE
()
uv_connect_t
connReq
;
uv_connect_t
connReq
;
...
@@ -64,16 +73,6 @@ typedef struct SCliMsg {
...
@@ -64,16 +73,6 @@ typedef struct SCliMsg {
int
sent
;
//(0: no send, 1: alread sent)
int
sent
;
//(0: no send, 1: alread sent)
}
SCliMsg
;
}
SCliMsg
;
typedef
struct
{
queue
wq
;
int32_t
wLen
;
int32_t
batchSize
;
//
int32_t
batch
;
char
*
dst
;
char
*
ip
;
uint16_t
port
;
}
SCliBatch
;
typedef
struct
SCliThrd
{
typedef
struct
SCliThrd
{
TdThread
thread
;
// tid
TdThread
thread
;
// tid
int64_t
pid
;
// pid
int64_t
pid
;
// pid
...
@@ -145,10 +144,12 @@ static void cliAsyncCb(uv_async_t* handle);
...
@@ -145,10 +144,12 @@ static void cliAsyncCb(uv_async_t* handle);
static
void
cliIdleCb
(
uv_idle_t
*
handle
);
static
void
cliIdleCb
(
uv_idle_t
*
handle
);
static
void
cliPrepareCb
(
uv_prepare_t
*
handle
);
static
void
cliPrepareCb
(
uv_prepare_t
*
handle
);
static
void
cliSendBatch
(
const
SCliBatch
*
pBatch
,
SCliThrd
*
pThrd
);
static
void
cliHandleBatchReq
(
SCliBatch
*
pBatch
,
SCliThrd
*
pThrd
);
// static void cliConnBatchCb(uv_connect_t* req, int status);
static
void
cliSendBatchCb
(
uv_write_t
*
req
,
int
status
);
static
void
cliSendBatchCb
(
uv_write_t
*
req
,
int
status
);
// callback after conn to server
// static void cliConnBatchCb(uv_connect_t* req, int status);
static
void
cliConnBatchCb
(
uv_connect_t
*
req
,
int
status
);
// callback after conn to server
// static void cliConnBatchCb(uv_connect_t* req, int status);
static
bool
cliRecvReleaseReq
(
SCliConn
*
conn
,
STransMsgHead
*
pHead
);
static
bool
cliRecvReleaseReq
(
SCliConn
*
conn
,
STransMsgHead
*
pHead
);
...
@@ -160,6 +161,7 @@ static SCliConn* cliCreateConn(SCliThrd* thrd);
...
@@ -160,6 +161,7 @@ static SCliConn* cliCreateConn(SCliThrd* thrd);
static
void
cliDestroyConn
(
SCliConn
*
pConn
,
bool
clear
/*clear tcp handle or not*/
);
static
void
cliDestroyConn
(
SCliConn
*
pConn
,
bool
clear
/*clear tcp handle or not*/
);
static
void
cliDestroy
(
uv_handle_t
*
handle
);
static
void
cliDestroy
(
uv_handle_t
*
handle
);
static
void
cliSend
(
SCliConn
*
pConn
);
static
void
cliSend
(
SCliConn
*
pConn
);
static
void
cliSendBatch
(
SCliConn
*
pConn
);
static
void
cliDestroyConnMsgs
(
SCliConn
*
conn
,
bool
destroy
);
static
void
cliDestroyConnMsgs
(
SCliConn
*
conn
,
bool
destroy
);
// cli util func
// cli util func
...
@@ -825,7 +827,63 @@ static void cliSendCb(uv_write_t* req, int status) {
...
@@ -825,7 +827,63 @@ static void cliSendCb(uv_write_t* req, int status) {
}
}
uv_read_start
((
uv_stream_t
*
)
pConn
->
stream
,
cliAllocRecvBufferCb
,
cliRecvCb
);
uv_read_start
((
uv_stream_t
*
)
pConn
->
stream
,
cliAllocRecvBufferCb
,
cliRecvCb
);
}
}
void
cliSendBatch
(
SCliConn
*
pConn
)
{
SCliThrd
*
pThrd
=
pConn
->
hostThrd
;
STrans
*
pTransInst
=
pThrd
->
pTransInst
;
SCliBatch
*
pBatch
=
pConn
->
pBatch
;
int32_t
wLen
=
pBatch
->
wLen
;
uv_buf_t
*
wb
=
taosMemoryCalloc
(
wLen
,
sizeof
(
uv_buf_t
));
int
i
=
0
;
while
(
!
QUEUE_IS_EMPTY
(
&
pBatch
->
wq
))
{
queue
*
h
=
QUEUE_HEAD
(
&
pBatch
->
wq
);
SCliMsg
*
pCliMsg
=
QUEUE_DATA
(
h
,
SCliMsg
,
q
);
QUEUE_REMOVE
(
&
pCliMsg
->
q
);
STransConnCtx
*
pCtx
=
pCliMsg
->
ctx
;
STransMsg
*
pMsg
=
(
STransMsg
*
)(
&
pCliMsg
->
msg
);
if
(
pMsg
->
pCont
==
0
)
{
pMsg
->
pCont
=
(
void
*
)
rpcMallocCont
(
0
);
pMsg
->
contLen
=
0
;
}
int
msgLen
=
transMsgLenFromCont
(
pMsg
->
contLen
);
STransMsgHead
*
pHead
=
transHeadFromCont
(
pMsg
->
pCont
);
if
(
pHead
->
comp
==
0
)
{
pHead
->
ahandle
=
pCtx
!=
NULL
?
(
uint64_t
)
pCtx
->
ahandle
:
0
;
pHead
->
noResp
=
REQUEST_NO_RESP
(
pMsg
)
?
1
:
0
;
pHead
->
persist
=
REQUEST_PERSIS_HANDLE
(
pMsg
)
?
1
:
0
;
pHead
->
msgType
=
pMsg
->
msgType
;
pHead
->
msgLen
=
(
int32_t
)
htonl
((
uint32_t
)
msgLen
);
pHead
->
release
=
REQUEST_RELEASE_HANDLE
(
pCliMsg
)
?
1
:
0
;
memcpy
(
pHead
->
user
,
pTransInst
->
user
,
strlen
(
pTransInst
->
user
));
pHead
->
traceId
=
pMsg
->
info
.
traceId
;
pHead
->
magicNum
=
htonl
(
TRANS_MAGIC_NUM
);
}
pHead
->
timestamp
=
taosHton64
(
taosGetTimestampUs
());
if
(
pHead
->
comp
==
0
)
{
if
(
pTransInst
->
compressSize
!=
-
1
&&
pTransInst
->
compressSize
<
pMsg
->
contLen
)
{
msgLen
=
transCompressMsg
(
pMsg
->
pCont
,
pMsg
->
contLen
)
+
sizeof
(
STransMsgHead
);
pHead
->
msgLen
=
(
int32_t
)
htonl
((
uint32_t
)
msgLen
);
}
}
else
{
msgLen
=
(
int32_t
)
ntohl
((
uint32_t
)(
pHead
->
msgLen
));
}
wb
[
i
++
]
=
uv_buf_init
((
char
*
)
pHead
,
msgLen
);
}
pBatch
->
wLen
=
0
;
uv_write_t
*
req
=
taosMemoryCalloc
(
1
,
sizeof
(
uv_write_t
));
req
->
data
=
pConn
;
uv_write
(
req
,
(
uv_stream_t
*
)
pConn
->
stream
,
wb
,
wLen
,
cliSendBatchCb
);
taosMemoryFree
(
wb
);
}
void
cliSend
(
SCliConn
*
pConn
)
{
void
cliSend
(
SCliConn
*
pConn
)
{
SCliThrd
*
pThrd
=
pConn
->
hostThrd
;
SCliThrd
*
pThrd
=
pConn
->
hostThrd
;
STrans
*
pTransInst
=
pThrd
->
pTransInst
;
STrans
*
pTransInst
=
pThrd
->
pTransInst
;
...
@@ -911,8 +969,8 @@ _RETURN:
...
@@ -911,8 +969,8 @@ _RETURN:
}
}
static
SCliBatch
*
cliDumpBatch
(
SCliBatch
*
pBatch
)
{
static
SCliBatch
*
cliDumpBatch
(
SCliBatch
*
pBatch
)
{
SCliBatch
*
pNewBatch
=
taosMem
Calloc
(
1
,
sizeof
(
SClic
Batch
));
SCliBatch
*
pNewBatch
=
taosMem
oryCalloc
(
1
,
sizeof
(
SCli
Batch
));
pNewBatch
->
wq
=
pBatch
->
wq
;
memcpy
(
pNewBatch
->
wq
,
pBatch
->
wq
,
sizeof
(
pBatch
->
wq
))
;
pNewBatch
->
batchSize
=
pBatch
->
batchSize
;
pNewBatch
->
batchSize
=
pBatch
->
batchSize
;
pNewBatch
->
batch
=
pBatch
->
batch
;
pNewBatch
->
batch
=
pBatch
->
batch
;
...
@@ -929,19 +987,19 @@ static SCliBatch* cliDumpBatch(SCliBatch* pBatch) {
...
@@ -929,19 +987,19 @@ static SCliBatch* cliDumpBatch(SCliBatch* pBatch) {
return
pNewBatch
;
return
pNewBatch
;
}
}
static
void
cliDestroyBatch
(
SCliBatch
*
pBatch
)
{
static
void
cliDestroyBatch
(
SCliBatch
*
pBatch
)
{
while
(
!
EMPTY
_IS_EMPTY
(
&
pBatch
->
wq
))
{
while
(
!
QUEUE
_IS_EMPTY
(
&
pBatch
->
wq
))
{
queue
*
h
=
QUEUE_HEAD
(
&
pBatch
->
wq
);
queue
*
h
=
QUEUE_HEAD
(
&
pBatch
->
wq
);
SCliMsg
*
p
Msg
=
QUEUE_DATA
(
h
,
SCliMsg
,
q
);
SCliMsg
*
p
=
QUEUE_DATA
(
h
,
SCliMsg
,
q
);
QUEUE_REMOVE
(
&
p
Msg
->
q
);
QUEUE_REMOVE
(
&
p
->
q
);
destroyCmsg
(
p
);
destroyCmsg
(
p
);
}
}
taosMemoryFree
(
pBatch
->
ip
);
taosMemoryFree
(
pBatch
->
ip
);
taosMemoryFree
(
pBatch
->
dst
);
taosMemoryFree
(
pBatch
->
dst
);
taosMemoryFree
(
pBatch
);
taosMemoryFree
(
pBatch
);
}
}
static
void
cli
SendBatch
(
SCliBatch
*
pBatch
,
SCliThrd
*
pThrd
)
{
static
void
cli
HandleBatchReq
(
SCliBatch
*
pBatch
,
SCliThrd
*
pThrd
)
{
if
(
pBatch
->
wLen
==
0
||
EMPTY
_IS_EMPTY
(
&
pBatch
->
wq
))
{
if
(
pBatch
->
wLen
==
0
||
QUEUE
_IS_EMPTY
(
&
pBatch
->
wq
))
{
return
;
return
;
}
}
STrans
*
pTransInst
=
pThrd
->
pTransInst
;
STrans
*
pTransInst
=
pThrd
->
pTransInst
;
...
@@ -961,33 +1019,32 @@ static void cliSendBatch(SCliBatch* pBatch, SCliThrd* pThrd) {
...
@@ -961,33 +1019,32 @@ static void cliSendBatch(SCliBatch* pBatch, SCliThrd* pThrd) {
taosArrayPush
(
pThrd
->
timerList
,
&
conn
->
timer
);
taosArrayPush
(
pThrd
->
timerList
,
&
conn
->
timer
);
conn
->
timer
=
NULL
;
conn
->
timer
=
NULL
;
cliHandle
Except
(
conn
);
cliHandle
FastFail
(
conn
,
-
1
);
return
;
return
;
}
}
struct
sockaddr_in
addr
;
struct
sockaddr_in
addr
;
addr
.
sin_family
=
AF_INET
;
addr
.
sin_family
=
AF_INET
;
addr
.
sin_addr
.
s_addr
=
ipaddr
;
addr
.
sin_addr
.
s_addr
=
ipaddr
;
addr
.
sin_port
=
(
uint16_t
)
htons
(
port
);
addr
.
sin_port
=
(
uint16_t
)
htons
(
p
Batch
->
p
ort
);
t
GTrace
(
"%s conn %p try to connect to %s"
,
pTransInst
->
label
,
conn
,
conn
->
ip
);
t
Trace
(
"%s conn %p try to connect to %s"
,
pTransInst
->
label
,
conn
,
pBatch
->
ip
);
int32_t
fd
=
taosCreateSocketWithTimeout
(
TRANS_CONN_TIMEOUT
*
4
);
int32_t
fd
=
taosCreateSocketWithTimeout
(
TRANS_CONN_TIMEOUT
*
4
);
if
(
fd
==
-
1
)
{
if
(
fd
==
-
1
)
{
tGError
(
"%s conn %p failed to create socket, reason:%s"
,
transLabel
(
pTransInst
),
conn
,
tError
(
"%s conn %p failed to create socket, reason:%s"
,
transLabel
(
pTransInst
),
conn
,
tstrerror
(
TAOS_SYSTEM_ERROR
(
errno
)));
tstrerror
(
TAOS_SYSTEM_ERROR
(
errno
)));
cliHandleExcept
(
conn
);
cliHandleFastFail
(
conn
,
-
1
);
errno
=
0
;
return
;
return
;
}
}
int
ret
=
uv_tcp_open
((
uv_tcp_t
*
)
conn
->
stream
,
fd
);
int
ret
=
uv_tcp_open
((
uv_tcp_t
*
)
conn
->
stream
,
fd
);
if
(
ret
!=
0
)
{
if
(
ret
!=
0
)
{
t
G
Error
(
"%s conn %p failed to set stream, reason:%s"
,
transLabel
(
pTransInst
),
conn
,
uv_err_name
(
ret
));
tError
(
"%s conn %p failed to set stream, reason:%s"
,
transLabel
(
pTransInst
),
conn
,
uv_err_name
(
ret
));
cliHandle
Except
(
conn
);
cliHandle
FastFail
(
conn
,
-
1
);
return
;
return
;
}
}
ret
=
transSetConnOption
((
uv_tcp_t
*
)
conn
->
stream
);
ret
=
transSetConnOption
((
uv_tcp_t
*
)
conn
->
stream
);
if
(
ret
!=
0
)
{
if
(
ret
!=
0
)
{
t
G
Error
(
"%s conn %p failed to set socket opt, reason:%s"
,
transLabel
(
pTransInst
),
conn
,
uv_err_name
(
ret
));
tError
(
"%s conn %p failed to set socket opt, reason:%s"
,
transLabel
(
pTransInst
),
conn
,
uv_err_name
(
ret
));
cliHandle
Except
(
conn
);
cliHandle
FastFail
(
conn
,
-
1
);
return
;
return
;
}
}
...
@@ -997,8 +1054,7 @@ static void cliSendBatch(SCliBatch* pBatch, SCliThrd* pThrd) {
...
@@ -997,8 +1054,7 @@ static void cliSendBatch(SCliBatch* pBatch, SCliThrd* pThrd) {
conn
->
timer
->
data
=
NULL
;
conn
->
timer
->
data
=
NULL
;
taosArrayPush
(
pThrd
->
timerList
,
&
conn
->
timer
);
taosArrayPush
(
pThrd
->
timerList
,
&
conn
->
timer
);
conn
->
timer
=
NULL
;
conn
->
timer
=
NULL
;
cliHandleFastFail
(
conn
,
-
1
);
cliHandleFastFail
(
conn
,
ret
);
return
;
return
;
}
}
uv_timer_start
(
conn
->
timer
,
cliConnTimeout
,
TRANS_CONN_TIMEOUT
,
0
);
uv_timer_start
(
conn
->
timer
,
cliConnTimeout
,
TRANS_CONN_TIMEOUT
,
0
);
...
@@ -1006,59 +1062,7 @@ static void cliSendBatch(SCliBatch* pBatch, SCliThrd* pThrd) {
...
@@ -1006,59 +1062,7 @@ static void cliSendBatch(SCliBatch* pBatch, SCliThrd* pThrd) {
}
}
conn
->
pBatch
=
pNewBatch
;
conn
->
pBatch
=
pNewBatch
;
cliSendBatch
(
conn
);
int32_t
wLen
=
pBatch
->
wLen
;
uv_buf_t
*
wb
=
taosMemoryCalloc
(
wLen
,
sizeof
(
uv_buf_t
));
int
i
=
0
;
while
(
!
EMPTY_IS_EMPTY
(
&
pBatch
->
wq
))
{
queue
*
h
=
QUEUE_HEAD
(
&
pBatch
->
wq
);
SCliMsg
*
pMsg
=
QUEUE_DATA
(
h
,
SCliMsg
,
q
);
QUEUE_REMOVE
(
&
pMsg
->
q
);
transQueuePush
(
conn
->
cliMsgs
,
pMsg
);
STransConnCtx
*
pCtx
=
pCliMsg
->
ctx
;
STransMsg
*
pMsg
=
(
STransMsg
*
)(
&
pCliMsg
->
msg
);
if
(
pMsg
->
pCont
==
0
)
{
pMsg
->
pCont
=
(
void
*
)
rpcMallocCont
(
0
);
pMsg
->
contLen
=
0
;
}
int
msgLen
=
transMsgLenFromCont
(
pMsg
->
contLen
);
STransMsgHead
*
pHead
=
transHeadFromCont
(
pMsg
->
pCont
);
if
(
pHead
->
comp
==
0
)
{
pHead
->
ahandle
=
pCtx
!=
NULL
?
(
uint64_t
)
pCtx
->
ahandle
:
0
;
pHead
->
noResp
=
REQUEST_NO_RESP
(
pMsg
)
?
1
:
0
;
pHead
->
persist
=
REQUEST_PERSIS_HANDLE
(
pMsg
)
?
1
:
0
;
pHead
->
msgType
=
pMsg
->
msgType
;
pHead
->
msgLen
=
(
int32_t
)
htonl
((
uint32_t
)
msgLen
);
pHead
->
release
=
REQUEST_RELEASE_HANDLE
(
pCliMsg
)
?
1
:
0
;
memcpy
(
pHead
->
user
,
pTransInst
->
user
,
strlen
(
pTransInst
->
user
));
pHead
->
traceId
=
pMsg
->
info
.
traceId
;
pHead
->
magicNum
=
htonl
(
TRANS_MAGIC_NUM
);
}
pHead
->
timestamp
=
taosHton64
(
taosGetTimestampUs
());
if
(
pHead
->
comp
==
0
)
{
if
(
pTransInst
->
compressSize
!=
-
1
&&
pTransInst
->
compressSize
<
pMsg
->
contLen
)
{
msgLen
=
transCompressMsg
(
pMsg
->
pCont
,
pMsg
->
contLen
)
+
sizeof
(
STransMsgHead
);
pHead
->
msgLen
=
(
int32_t
)
htonl
((
uint32_t
)
msgLen
);
}
}
else
{
msgLen
=
(
int32_t
)
ntohl
((
uint32_t
)(
pHead
->
msgLen
));
}
wb
[
i
++
]
=
uv_buf_init
((
char
*
)
pHead
,
msgLen
);
}
pBatch
->
wLen
=
0
;
uv_write_t
*
req
=
taosMemCalloc
(
1
,
sizeof
(
uv_write_t
));
req
->
data
=
pConn
;
uv_write
(
req
,
(
uv_stream_t
*
)
conn
->
stream
,
wb
,
wLen
,
cliSendBatchCb
);
taosMemoryFree
(
wb
);
}
}
static
void
cliSendBatchCb
(
uv_write_t
*
req
,
int
status
)
{
static
void
cliSendBatchCb
(
uv_write_t
*
req
,
int
status
)
{
SCliConn
*
conn
=
req
->
data
;
SCliConn
*
conn
=
req
->
data
;
...
@@ -1075,29 +1079,34 @@ static void cliSendBatchCb(uv_write_t* req, int status) {
...
@@ -1075,29 +1079,34 @@ static void cliSendBatchCb(uv_write_t* req, int status) {
static
void
cliHandleFastFail
(
SCliConn
*
pConn
,
int
status
)
{
static
void
cliHandleFastFail
(
SCliConn
*
pConn
,
int
status
)
{
SCliThrd
*
pThrd
=
pConn
->
hostThrd
;
SCliThrd
*
pThrd
=
pConn
->
hostThrd
;
STrans
*
pTransInst
=
pThrd
->
pTransInst
;
STrans
*
pTransInst
=
pThrd
->
pTransInst
;
tError
(
"conn %p free twice"
,
pConn
);
SCliMsg
*
pMsg
=
transQueueGet
(
&
pConn
->
cliMsgs
,
0
);
if
(
pConn
->
pBatch
==
NULL
)
{
SCliMsg
*
pMsg
=
transQueueGet
(
&
pConn
->
cliMsgs
,
0
);
STraceId
*
trace
=
&
pMsg
->
msg
.
info
.
traceId
;
tGError
(
"%s msg %s failed to send, conn %p failed to connect to %s, reason: %s"
,
CONN_GET_INST_LABEL
(
pConn
),
STraceId
*
trace
=
&
pMsg
->
msg
.
info
.
traceId
;
TMSG_INFO
(
pMsg
->
msg
.
msgType
),
pConn
,
pConn
->
ip
,
uv_strerror
(
status
));
tGError
(
"%s msg %s failed to send, conn %p failed to connect to %s, reason: %s"
,
CONN_GET_INST_LABEL
(
pConn
),
TMSG_INFO
(
pMsg
->
msg
.
msgType
),
pConn
,
pConn
->
ip
,
uv_strerror
(
status
));
if
(
pMsg
!=
NULL
&&
REQUEST_NO_RESP
(
&
pMsg
->
msg
)
&&
(
pTransInst
->
failFastFp
!=
NULL
&&
pTransInst
->
failFastFp
(
pMsg
->
msg
.
msgType
)))
{
if
(
pMsg
!=
NULL
&&
REQUEST_NO_RESP
(
&
pMsg
->
msg
)
&&
SFailFastItem
*
item
=
taosHashGet
(
pThrd
->
failFastCache
,
pConn
->
ip
,
strlen
(
pConn
->
ip
));
(
pTransInst
->
failFastFp
!=
NULL
&&
pTransInst
->
failFastFp
(
pMsg
->
msg
.
msgType
)))
{
int64_t
cTimestamp
=
taosGetTimestampMs
();
SFailFastItem
*
item
=
taosHashGet
(
pThrd
->
failFastCache
,
pConn
->
ip
,
strlen
(
pConn
->
ip
));
if
(
item
!=
NULL
)
{
int64_t
cTimestamp
=
taosGetTimestampMs
();
int32_t
elapse
=
cTimestamp
-
item
->
timestamp
;
if
(
item
!=
NULL
)
{
if
(
elapse
>=
0
&&
elapse
<=
pTransInst
->
failFastInterval
)
{
int32_t
elapse
=
cTimestamp
-
item
->
timestamp
;
item
->
count
++
;
if
(
elapse
>=
0
&&
elapse
<=
pTransInst
->
failFastInterval
)
{
item
->
count
++
;
}
else
{
item
->
count
=
1
;
item
->
timestamp
=
cTimestamp
;
}
}
else
{
}
else
{
item
->
count
=
1
;
SFailFastItem
item
=
{.
count
=
1
,
.
timestamp
=
cTimestamp
}
;
item
->
timestamp
=
cTimestamp
;
taosHashPut
(
pThrd
->
failFastCache
,
pConn
->
ip
,
strlen
(
pConn
->
ip
),
&
item
,
sizeof
(
SFailFastItem
))
;
}
}
}
else
{
SFailFastItem
item
=
{.
count
=
1
,
.
timestamp
=
cTimestamp
};
taosHashPut
(
pThrd
->
failFastCache
,
pConn
->
ip
,
strlen
(
pConn
->
ip
),
&
item
,
sizeof
(
SFailFastItem
));
}
}
}
else
{
cliDestroyBatch
(
pConn
->
pBatch
);
pConn
->
pBatch
=
NULL
;
}
}
cliHandleExcept
(
pConn
);
cliHandleExcept
(
pConn
);
}
}
...
@@ -1117,7 +1126,11 @@ void cliConnCb(uv_connect_t* req, int status) {
...
@@ -1117,7 +1126,11 @@ void cliConnCb(uv_connect_t* req, int status) {
}
}
if
(
status
!=
0
)
{
if
(
status
!=
0
)
{
if
(
timeout
==
false
)
cliHandleFastFail
(
pConn
,
status
);
if
(
timeout
==
false
)
{
cliHandleFastFail
(
pConn
,
status
);
}
else
if
(
timeout
==
true
)
{
// already deal by timeout
}
return
;
return
;
}
}
...
@@ -1135,8 +1148,11 @@ void cliConnCb(uv_connect_t* req, int status) {
...
@@ -1135,8 +1148,11 @@ void cliConnCb(uv_connect_t* req, int status) {
transSockInfo2Str
(
&
sockname
,
pConn
->
src
);
transSockInfo2Str
(
&
sockname
,
pConn
->
src
);
tTrace
(
"%s conn %p connect to server successfully"
,
CONN_GET_INST_LABEL
(
pConn
),
pConn
);
tTrace
(
"%s conn %p connect to server successfully"
,
CONN_GET_INST_LABEL
(
pConn
),
pConn
);
if
(
pConn
->
pBatch
!=
NULL
)
{
cliSend
(
pConn
);
cliSendBatch
(
pConn
);
}
else
{
cliSend
(
pConn
);
}
}
}
static
void
cliHandleQuit
(
SCliMsg
*
pMsg
,
SCliThrd
*
pThrd
)
{
static
void
cliHandleQuit
(
SCliMsg
*
pMsg
,
SCliThrd
*
pThrd
)
{
...
@@ -1403,11 +1419,11 @@ void cliHandleReq(SCliMsg* pMsg, SCliThrd* pThrd) {
...
@@ -1403,11 +1419,11 @@ void cliHandleReq(SCliMsg* pMsg, SCliThrd* pThrd) {
tGTrace
(
"%s conn %p ready"
,
pTransInst
->
label
,
conn
);
tGTrace
(
"%s conn %p ready"
,
pTransInst
->
label
,
conn
);
}
}
static
void
cliNoBatchDealReq
(
queue
wq
,
SCliThrd
*
pThrd
)
{
static
void
cliNoBatchDealReq
(
queue
*
wq
,
SCliThrd
*
pThrd
)
{
int
count
=
0
;
int
count
=
0
;
while
(
!
QUEUE_IS_EMPTY
(
&
wq
))
{
while
(
!
QUEUE_IS_EMPTY
(
wq
))
{
queue
*
h
=
QUEUE_HEAD
(
&
wq
);
queue
*
h
=
QUEUE_HEAD
(
wq
);
QUEUE_REMOVE
(
h
);
QUEUE_REMOVE
(
h
);
SCliMsg
*
pMsg
=
QUEUE_DATA
(
h
,
SCliMsg
,
q
);
SCliMsg
*
pMsg
=
QUEUE_DATA
(
h
,
SCliMsg
,
q
);
...
@@ -1420,10 +1436,10 @@ static void cliNoBatchDealReq(queue wq, SCliThrd* pThrd) {
...
@@ -1420,10 +1436,10 @@ static void cliNoBatchDealReq(queue wq, SCliThrd* pThrd) {
}
}
}
}
static
void
cli
HandleBatch
()
static
void
cliBatchDealReq
(
queue
wq
,
SCliThrd
*
pThrd
)
{
static
void
cli
BatchDealReq
(
queue
*
wq
,
SCliThrd
*
pThrd
)
{
int
count
=
0
;
int
count
=
0
;
while
(
!
QUEUE_IS_EMPTY
(
&
wq
))
{
while
(
!
QUEUE_IS_EMPTY
(
wq
))
{
queue
*
h
=
QUEUE_HEAD
(
&
wq
);
queue
*
h
=
QUEUE_HEAD
(
wq
);
QUEUE_REMOVE
(
h
);
QUEUE_REMOVE
(
h
);
SCliMsg
*
pMsg
=
QUEUE_DATA
(
h
,
SCliMsg
,
q
);
SCliMsg
*
pMsg
=
QUEUE_DATA
(
h
,
SCliMsg
,
q
);
...
@@ -1435,8 +1451,8 @@ static void cliHandleBatch() static void cliBatchDealReq(queue wq, SCliThrd* pTh
...
@@ -1435,8 +1451,8 @@ static void cliHandleBatch() static void cliBatchDealReq(queue wq, SCliThrd* pTh
char
key
[
TSDB_FQDN_LEN
+
64
]
=
{
0
};
char
key
[
TSDB_FQDN_LEN
+
64
]
=
{
0
};
CONN_CONSTRUCT_HASH_KEY
(
key
,
ip
,
port
);
CONN_CONSTRUCT_HASH_KEY
(
key
,
ip
,
port
);
SCliBatch
*
ppBatch
=
taosHashGet
(
pThrd
->
batchCache
,
key
,
sizeof
(
key
)
));
SCliBatch
**
ppBatch
=
taosHashGet
(
pThrd
->
batchCache
,
key
,
sizeof
(
key
));
if
(
*
ppBatch
==
NULL
)
{
if
(
ppBatch
==
NULL
||
*
ppBatch
==
NULL
)
{
SCliBatch
*
pBatch
=
taosMemoryCalloc
(
1
,
sizeof
(
SCliBatch
));
SCliBatch
*
pBatch
=
taosMemoryCalloc
(
1
,
sizeof
(
SCliBatch
));
QUEUE_INIT
(
&
pBatch
->
wq
);
QUEUE_INIT
(
&
pBatch
->
wq
);
QUEUE_PUSH
(
&
pBatch
->
wq
,
h
);
QUEUE_PUSH
(
&
pBatch
->
wq
,
h
);
...
@@ -1450,20 +1466,21 @@ static void cliHandleBatch() static void cliBatchDealReq(queue wq, SCliThrd* pTh
...
@@ -1450,20 +1466,21 @@ static void cliHandleBatch() static void cliBatchDealReq(queue wq, SCliThrd* pTh
taosHashPut
(
pThrd
->
batchCache
,
key
,
sizeof
(
key
),
&
pBatch
,
sizeof
(
void
*
));
taosHashPut
(
pThrd
->
batchCache
,
key
,
sizeof
(
key
),
&
pBatch
,
sizeof
(
void
*
));
}
else
{
}
else
{
QUEUE_PUSH
(
&
(
*
ppBatch
)
->
wq
,
h
);
QUEUE_PUSH
(
&
(
*
ppBatch
)
->
wq
,
h
);
(
*
pBatch
)
->
wLen
+=
1
;
(
*
p
p
Batch
)
->
wLen
+=
1
;
(
*
pBatch
)
->
batchSize
+=
pMsg
->
msg
.
contLen
;
(
*
p
p
Batch
)
->
batchSize
+=
pMsg
->
msg
.
contLen
;
}
}
return
;
}
}
(
*
cliAsyncHandle
[
pMsg
->
type
])(
pMsg
,
pThrd
);
(
*
cliAsyncHandle
[
pMsg
->
type
])(
pMsg
,
pThrd
);
count
++
;
count
++
;
}
}
void
**
pIter
=
taos
k
HashIterate
(
pThrd
->
batchCache
,
NULL
);
void
**
pIter
=
taosHashIterate
(
pThrd
->
batchCache
,
NULL
);
while
(
pIter
!=
NULL
)
{
while
(
pIter
!=
NULL
)
{
SCliBatch
*
batch
=
(
SCliBatch
*
)(
*
pIter
);
SCliBatch
*
batch
=
(
SCliBatch
*
)(
*
pIter
);
cli
SendBatch
(
batch
,
pThrd
);
cli
HandleBatchReq
(
batch
,
pThrd
);
pIter
=
(
void
**
)
taosHashIterate
(
info
,
pIter
);
pIter
=
(
void
**
)
taosHashIterate
(
pThrd
->
batchCache
,
pIter
);
}
}
if
(
count
>=
2
)
{
if
(
count
>=
2
)
{
...
@@ -1483,11 +1500,11 @@ static void cliAsyncCb(uv_async_t* handle) {
...
@@ -1483,11 +1500,11 @@ static void cliAsyncCb(uv_async_t* handle) {
QUEUE_MOVE
(
&
item
->
qmsg
,
&
wq
);
QUEUE_MOVE
(
&
item
->
qmsg
,
&
wq
);
taosThreadMutexUnlock
(
&
item
->
mtx
);
taosThreadMutexUnlock
(
&
item
->
mtx
);
int8_t
supportBatch
=
pTransInst
->
supprtBatch
;
int8_t
supportBatch
=
pTransInst
->
supp
o
rtBatch
;
if
(
supportBatch
==
0
)
{
if
(
supportBatch
==
0
)
{
cliNo
tBatchDealReq
(
wq
,
pThrd
);
cliNo
BatchDealReq
(
&
wq
,
pThrd
);
}
else
if
(
supportBatch
==
1
)
{
}
else
if
(
supportBatch
==
1
)
{
cliBatchDealReq
(
wq
,
pThrd
);
cliBatchDealReq
(
&
wq
,
pThrd
);
}
}
if
(
pThrd
->
stopMsg
!=
NULL
)
cliHandleQuit
(
pThrd
->
stopMsg
,
pThrd
);
if
(
pThrd
->
stopMsg
!=
NULL
)
cliHandleQuit
(
pThrd
->
stopMsg
,
pThrd
);
...
@@ -1704,7 +1721,7 @@ static SCliThrd* createThrdObj(void* trans) {
...
@@ -1704,7 +1721,7 @@ static SCliThrd* createThrdObj(void* trans) {
pThrd
->
connLimitCache
=
taosHashInit
(
8
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_BINARY
),
true
,
pThrd
->
connLimitCache
=
taosHashInit
(
8
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_BINARY
),
true
,
pTransInst
->
connLimitLock
==
0
?
HASH_NO_LOCK
:
HASH_ENTRY_LOCK
);
pTransInst
->
connLimitLock
==
0
?
HASH_NO_LOCK
:
HASH_ENTRY_LOCK
);
pThrd
->
batchCache
=
taosHashInit
(
8
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_BINARY
),
true
,
hash_no_lock
);
pThrd
->
batchCache
=
taosHashInit
(
8
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_BINARY
),
true
,
HASH_NO_LOCK
);
pThrd
->
quit
=
false
;
pThrd
->
quit
=
false
;
return
pThrd
;
return
pThrd
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录