Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
45a012bd
T
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1187
Star
22018
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看板
提交
45a012bd
编写于
2月 25, 2023
作者:
dengyihao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix: limit session num
上级
28db4c8a
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
150 addition
and
146 deletion
+150
-146
source/libs/transport/src/transCli.c
source/libs/transport/src/transCli.c
+150
-146
未找到文件。
source/libs/transport/src/transCli.c
浏览文件 @
45a012bd
...
...
@@ -14,9 +14,16 @@
#include "transComm.h"
typedef
struct
{
int32_t
numOfConn
;
queue
msgQ
;
}
SMsgList
;
typedef
struct
SConnList
{
queue
conns
;
int32_t
size
;
queue
conns
;
int32_t
size
;
SMsgList
*
list
;
void
*
pThrd
;
}
SConnList
;
typedef
struct
{
...
...
@@ -76,10 +83,6 @@ typedef struct SCliConn {
}
SCliConn
;
typedef
struct
{
int32_t
numOfConn
;
queue
msgQ
;
}
SMsgList
;
typedef
struct
SCliMsg
{
STransConnCtx
*
ctx
;
STransMsg
msg
;
...
...
@@ -115,7 +118,6 @@ typedef struct SCliThrd {
SCvtAddr
cvtAddr
;
SHashObj
*
failFastCache
;
SHashObj
*
connLimitCache
;
SHashObj
*
batchCache
;
SCliMsg
*
stopMsg
;
...
...
@@ -141,7 +143,7 @@ typedef struct {
// add expire timeout and capacity limit
static
void
*
createConnPool
(
int
size
);
static
void
*
destroyConnPool
(
void
*
pool
);
static
SCliConn
*
getConnFromPool
(
void
*
pool
,
char
*
addr
);
static
SCliConn
*
getConnFromPool
(
SCliThrd
*
thread
,
char
*
key
);
static
void
addConnToPool
(
void
*
pool
,
SCliConn
*
conn
);
static
void
doCloseIdleConn
(
void
*
param
);
...
...
@@ -181,8 +183,8 @@ static void cliSend(SCliConn* pConn);
static
void
cliSendBatch
(
SCliConn
*
pConn
);
static
void
cliDestroyConnMsgs
(
SCliConn
*
conn
,
bool
destroy
);
static
int32_t
cliPreCheckSessionLimit
(
SCliThrd
*
pThrd
,
char
*
addr
);
static
int32_t
cliPreCheckSessionLimitForMsg
(
SCliThrd
*
pThrd
,
char
*
addr
,
SCliMsg
*
pMsg
);
static
void
doFreeTimeoutMsg
(
void
*
param
);
static
int32_t
cliPreCheckSessionLimitForMsg
(
SCliThrd
*
pThrd
,
char
*
addr
,
SCliMsg
*
*
pMsg
);
// cli util func
static
FORCE_INLINE
bool
cliIsEpsetUpdated
(
int32_t
code
,
STransConnCtx
*
pCtx
);
...
...
@@ -200,6 +202,7 @@ static void cliHandleExcept(SCliConn* conn);
static
void
cliReleaseUnfinishedMsg
(
SCliConn
*
conn
);
static
void
cliHandleFastFail
(
SCliConn
*
pConn
,
int
status
);
static
void
doNotifyApp
(
SCliMsg
*
pMsg
,
SCliThrd
*
pThrd
);
// handle req from app
static
void
cliHandleReq
(
SCliMsg
*
pMsg
,
SCliThrd
*
pThrd
);
static
void
cliHandleQuit
(
SCliMsg
*
pMsg
,
SCliThrd
*
pThrd
);
...
...
@@ -546,20 +549,38 @@ void* createConnPool(int size) {
}
void
*
destroyConnPool
(
void
*
pool
)
{
SConnList
*
connList
=
taosHashIterate
((
SHashObj
*
)
pool
,
NULL
);
SCliThrd
*
pThrd
=
connList
->
pThrd
;
while
(
connList
!=
NULL
)
{
while
(
!
QUEUE_IS_EMPTY
(
&
connList
->
conns
))
{
queue
*
h
=
QUEUE_HEAD
(
&
connList
->
conns
);
SCliConn
*
c
=
QUEUE_DATA
(
h
,
SCliConn
,
q
);
cliDestroyConn
(
c
,
true
);
}
SMsgList
*
msglist
=
connList
->
list
;
while
(
!
QUEUE_IS_EMPTY
(
&
msglist
->
msgQ
))
{
queue
*
h
=
QUEUE_HEAD
(
&
msglist
->
msgQ
);
QUEUE_REMOVE
(
h
);
SCliMsg
*
pMsg
=
QUEUE_DATA
(
h
,
SCliMsg
,
q
);
transDQCancel
(
pThrd
->
waitConnQueue
,
pMsg
->
ctx
->
task
);
pMsg
->
ctx
->
task
=
NULL
;
doNotifyApp
(
pMsg
,
pThrd
);
}
taosMemoryFree
(
msglist
);
connList
=
taosHashIterate
((
SHashObj
*
)
pool
,
connList
);
}
taosHashCleanup
(
pool
);
return
NULL
;
}
static
SCliConn
*
getConnFromPool
(
void
*
pool
,
char
*
key
)
{
static
SCliConn
*
getConnFromPool
(
SCliThrd
*
pThrd
,
char
*
key
)
{
void
*
pool
=
pThrd
->
pool
;
SConnList
*
plist
=
taosHashGet
((
SHashObj
*
)
pool
,
key
,
strlen
(
key
));
STrans
*
pTranInst
=
pThrd
->
pTransInst
;
if
(
plist
==
NULL
)
{
SConnList
list
=
{
0
};
taosHashPut
((
SHashObj
*
)
pool
,
key
,
strlen
(
key
),
(
void
*
)
&
list
,
sizeof
(
list
));
...
...
@@ -568,7 +589,76 @@ static SCliConn* getConnFromPool(void* pool, char* key) {
QUEUE_INIT
(
&
plist
->
conns
);
}
SMsgList
*
msglist
=
plist
->
list
;
if
(
QUEUE_IS_EMPTY
(
&
plist
->
conns
)
&&
msglist
->
numOfConn
>=
pTranInst
->
connLimitNum
)
{
return
NULL
;
}
plist
->
size
-=
1
;
queue
*
h
=
QUEUE_HEAD
(
&
plist
->
conns
);
SCliConn
*
conn
=
QUEUE_DATA
(
h
,
SCliConn
,
q
);
conn
->
status
=
ConnNormal
;
QUEUE_REMOVE
(
&
conn
->
q
);
QUEUE_INIT
(
&
conn
->
q
);
if
(
conn
->
task
!=
NULL
)
{
transDQCancel
(((
SCliThrd
*
)
conn
->
hostThrd
)
->
timeoutQueue
,
conn
->
task
);
conn
->
task
=
NULL
;
}
return
conn
;
}
static
SCliConn
*
getConnFromPool2
(
SCliThrd
*
pThrd
,
char
*
key
,
SCliMsg
**
pMsg
)
{
void
*
pool
=
pThrd
->
pool
;
STrans
*
pTransInst
=
pThrd
->
pTransInst
;
SConnList
*
plist
=
taosHashGet
((
SHashObj
*
)
pool
,
key
,
strlen
(
key
));
if
(
plist
==
NULL
)
{
SConnList
list
=
{
0
};
SMsgList
*
nList
=
taosMemoryCalloc
(
1
,
sizeof
(
SMsgList
));
nList
->
numOfConn
++
;
QUEUE_INIT
(
&
nList
->
msgQ
);
list
.
list
=
nList
;
taosHashPut
((
SHashObj
*
)
pool
,
key
,
strlen
(
key
),
(
void
*
)
&
list
,
sizeof
(
list
));
plist
=
taosHashGet
((
SHashObj
*
)
pool
,
key
,
strlen
(
key
));
QUEUE_INIT
(
&
plist
->
conns
);
}
SMsgList
*
list
=
plist
->
list
;
// no avaliable conn in pool
if
(
QUEUE_IS_EMPTY
(
&
plist
->
conns
))
{
if
((
list
)
->
numOfConn
>=
pTransInst
->
connLimitNum
)
{
STraceId
*
trace
=
&
(
*
pMsg
)
->
msg
.
info
.
traceId
;
STaskArg
*
arg
=
taosMemoryMalloc
(
sizeof
(
STaskArg
));
arg
->
param1
=
*
pMsg
;
arg
->
param2
=
pThrd
;
(
*
pMsg
)
->
ctx
->
task
=
transDQSched
(
pThrd
->
waitConnQueue
,
doFreeTimeoutMsg
,
arg
,
pTransInst
->
timeToGetConn
);
tGTrace
(
"%s msg %s delay to send, wait for avaiable connect"
,
pTransInst
->
label
,
TMSG_INFO
((
*
pMsg
)
->
msg
.
msgType
));
QUEUE_PUSH
(
&
(
list
)
->
msgQ
,
&
(
*
pMsg
)
->
q
);
*
pMsg
=
NULL
;
}
else
{
// send msg in delay queue
if
(
!
(
QUEUE_IS_EMPTY
(
&
(
list
)
->
msgQ
)))
{
STaskArg
*
arg
=
taosMemoryMalloc
(
sizeof
(
STaskArg
));
arg
->
param1
=
*
pMsg
;
arg
->
param2
=
pThrd
;
(
*
pMsg
)
->
ctx
->
task
=
transDQSched
(
pThrd
->
waitConnQueue
,
doFreeTimeoutMsg
,
arg
,
pTransInst
->
timeToGetConn
);
QUEUE_PUSH
(
&
(
list
)
->
msgQ
,
&
(
*
pMsg
)
->
q
);
queue
*
h
=
QUEUE_HEAD
(
&
(
list
)
->
msgQ
);
QUEUE_REMOVE
(
h
);
SCliMsg
*
ans
=
QUEUE_DATA
(
h
,
SCliMsg
,
q
);
*
pMsg
=
ans
;
transDQCancel
(
pThrd
->
waitConnQueue
,
ans
->
ctx
->
task
);
}
list
->
numOfConn
++
;
}
return
NULL
;
}
...
...
@@ -604,29 +694,30 @@ static void addConnToPool(void* pool, SCliConn* conn) {
cliDestroyConnMsgs
(
conn
,
false
);
conn
->
status
=
ConnInPool
;
SMsgList
**
msglist
=
taosHashGet
(
thrd
->
connLimitCache
,
conn
->
ip
,
strlen
(
conn
->
ip
));
if
(
msglist
!=
NULL
&&
*
msglist
!=
NULL
)
{
if
(
!
QUEUE_IS_EMPTY
(
&
(
*
msglist
)
->
msgQ
))
{
queue
*
h
=
QUEUE_HEAD
(
&
(
*
msglist
)
->
msgQ
);
QUEUE_REMOVE
(
h
);
SCliMsg
*
pMsg
=
QUEUE_DATA
(
h
,
SCliMsg
,
q
);
conn
->
status
=
ConnNormal
;
transDQCancel
(
thrd
->
waitConnQueue
,
pMsg
->
ctx
->
task
);
transCtxMerge
(
&
conn
->
ctx
,
&
pMsg
->
ctx
->
appCtx
);
transQueuePush
(
&
conn
->
cliMsgs
,
pMsg
);
cliSend
(
conn
);
return
;
}
}
if
(
conn
->
list
==
NULL
)
{
tTrace
(
"%s conn %p added to conn pool, read buf cap:%d"
,
CONN_GET_INST_LABEL
(
conn
),
conn
,
conn
->
readBuf
.
cap
);
conn
->
list
=
taosHashGet
((
SHashObj
*
)
pool
,
conn
->
ip
,
strlen
(
conn
->
ip
));
}
else
{
tTrace
(
"%s conn %p added to conn pool, read buf cap:%d"
,
CONN_GET_INST_LABEL
(
conn
),
conn
,
conn
->
readBuf
.
cap
);
}
SConnList
*
pList
=
conn
->
list
;
SMsgList
*
msgList
=
pList
->
list
;
if
(
!
QUEUE_IS_EMPTY
(
&
msgList
->
msgQ
))
{
queue
*
h
=
QUEUE_HEAD
(
&
(
msgList
)
->
msgQ
);
QUEUE_REMOVE
(
h
);
SCliMsg
*
pMsg
=
QUEUE_DATA
(
h
,
SCliMsg
,
q
);
transDQCancel
(
thrd
->
waitConnQueue
,
pMsg
->
ctx
->
task
);
pMsg
->
ctx
->
task
=
NULL
;
transCtxMerge
(
&
conn
->
ctx
,
&
pMsg
->
ctx
->
appCtx
);
transQueuePush
(
&
conn
->
cliMsgs
,
pMsg
);
conn
->
status
=
ConnNormal
;
cliSend
(
conn
);
return
;
}
conn
->
status
=
ConnInPool
;
QUEUE_PUSH
(
&
conn
->
list
->
conns
,
&
conn
->
q
);
conn
->
list
->
size
+=
1
;
...
...
@@ -752,8 +843,19 @@ static SCliConn* cliCreateConn(SCliThrd* pThrd) {
static
void
cliDestroyConn
(
SCliConn
*
conn
,
bool
clear
)
{
SCliThrd
*
pThrd
=
conn
->
hostThrd
;
tTrace
(
"%s conn %p remove from conn pool"
,
CONN_GET_INST_LABEL
(
conn
),
conn
);
QUEUE_REMOVE
(
&
conn
->
q
);
QUEUE_INIT
(
&
conn
->
q
);
if
(
conn
->
list
!=
NULL
)
{
SConnList
*
connList
=
conn
->
list
;
connList
->
list
->
numOfConn
--
;
}
else
{
SConnList
*
connList
=
taosHashGet
((
SHashObj
*
)
pThrd
->
pool
,
conn
->
ip
,
strlen
(
conn
->
ip
));
connList
->
list
->
numOfConn
--
;
}
conn
->
list
=
NULL
;
transReleaseExHandle
(
transGetRefMgt
(),
conn
->
refId
);
transRemoveExHandle
(
transGetRefMgt
(),
conn
->
refId
);
conn
->
refId
=
-
1
;
...
...
@@ -788,10 +890,6 @@ static void cliDestroy(uv_handle_t* handle) {
conn
->
timer
->
data
=
NULL
;
conn
->
timer
=
NULL
;
}
SMsgList
**
list
=
taosHashGet
(
pThrd
->
connLimitCache
,
conn
->
ip
,
strlen
(
conn
->
ip
));
if
(
list
!=
NULL
&&
*
list
!=
NULL
)
{
(
*
list
)
->
numOfConn
--
;
}
atomic_sub_fetch_32
(
&
pThrd
->
connCount
,
1
);
...
...
@@ -1027,9 +1125,9 @@ static void cliHandleBatchReq(SCliBatch* pBatch, SCliThrd* pThrd) {
char
key
[
TSDB_FQDN_LEN
+
64
]
=
{
0
};
CONN_CONSTRUCT_HASH_KEY
(
key
,
pList
->
ip
,
pList
->
port
);
SCliConn
*
conn
=
getConnFromPool
(
pThrd
->
pool
,
key
);
SCliConn
*
conn
=
getConnFromPool
(
pThrd
,
key
);
if
(
conn
==
NULL
&&
0
!=
cliPreCheckSessionLimit
(
pThrd
,
key
)
)
{
if
(
conn
==
NULL
)
{
tError
(
"%s failed to send batch msg, batch size:%d, msgLen: %d"
,
pTransInst
->
label
,
pBatch
->
wLen
,
pBatch
->
batchSize
);
cliDestroyBatch
(
pBatch
);
...
...
@@ -1085,16 +1183,6 @@ static void cliHandleBatchReq(SCliBatch* pBatch, SCliThrd* pThrd) {
cliHandleFastFail
(
conn
,
-
1
);
return
;
}
SMsgList
**
list
=
taosHashGet
(
pThrd
->
connLimitCache
,
conn
->
ip
,
strlen
(
conn
->
ip
));
if
(
list
==
NULL
||
*
list
==
NULL
)
{
SMsgList
*
nList
=
taosMemoryCalloc
(
1
,
sizeof
(
SMsgList
));
nList
->
numOfConn
++
;
QUEUE_INIT
(
&
nList
->
msgQ
);
taosHashPut
(
pThrd
->
connLimitCache
,
conn
->
ip
,
strlen
(
conn
->
ip
),
&
nList
,
sizeof
(
void
*
));
}
else
{
(
*
list
)
->
numOfConn
++
;
}
uv_timer_start
(
conn
->
timer
,
cliConnTimeout
,
TRANS_CONN_TIMEOUT
,
0
);
return
;
}
...
...
@@ -1246,20 +1334,6 @@ static void cliHandleQuit(SCliMsg* pMsg, SCliThrd* pThrd) {
pThrd
->
stopMsg
=
pMsg
;
return
;
}
void
**
pIter
=
taosHashIterate
(
pThrd
->
connLimitCache
,
NULL
);
while
(
pIter
!=
NULL
)
{
SMsgList
*
list
=
(
SMsgList
*
)(
*
pIter
);
while
(
!
QUEUE_IS_EMPTY
(
&
list
->
msgQ
))
{
queue
*
h
=
QUEUE_HEAD
(
&
list
->
msgQ
);
QUEUE_REMOVE
(
h
);
SCliMsg
*
pMsg
=
QUEUE_DATA
(
h
,
SCliMsg
,
q
);
transDQCancel
(
pThrd
->
waitConnQueue
,
pMsg
->
ctx
->
task
);
doNotifyApp
(
pMsg
,
pThrd
);
}
pIter
=
(
void
**
)
taosHashIterate
(
pThrd
->
connLimitCache
,
pIter
);
}
pThrd
->
stopMsg
=
NULL
;
pThrd
->
quit
=
true
;
tDebug
(
"cli work thread %p start to quit"
,
pThrd
);
...
...
@@ -1298,11 +1372,11 @@ static void cliHandleUpdate(SCliMsg* pMsg, SCliThrd* pThrd) {
destroyCmsg
(
pMsg
);
}
SCliConn
*
cliGetConn
(
SCliMsg
*
pMsg
,
SCliThrd
*
pThrd
,
bool
*
ignore
,
char
*
addr
)
{
STransConnCtx
*
pCtx
=
pMsg
->
ctx
;
SCliConn
*
cliGetConn
(
SCliMsg
*
*
pMsg
,
SCliThrd
*
pThrd
,
bool
*
ignore
,
char
*
addr
)
{
STransConnCtx
*
pCtx
=
(
*
pMsg
)
->
ctx
;
SCliConn
*
conn
=
NULL
;
int64_t
refId
=
(
int64_t
)(
pMsg
->
msg
.
info
.
handle
);
int64_t
refId
=
(
int64_t
)(
(
*
pMsg
)
->
msg
.
info
.
handle
);
if
(
refId
!=
0
)
{
SExHandle
*
exh
=
transAcquireExHandle
(
transGetRefMgt
(),
refId
);
if
(
exh
==
NULL
)
{
...
...
@@ -1312,7 +1386,7 @@ SCliConn* cliGetConn(SCliMsg* pMsg, SCliThrd* pThrd, bool* ignore, char* addr) {
}
else
{
conn
=
exh
->
handle
;
if
(
conn
==
NULL
)
{
conn
=
getConnFromPool
(
pThrd
->
pool
,
addr
);
conn
=
getConnFromPool
2
(
pThrd
,
addr
,
pMsg
);
if
(
conn
!=
NULL
)
specifyConnRef
(
conn
,
true
,
refId
);
}
transReleaseExHandle
(
transGetRefMgt
(),
refId
);
...
...
@@ -1320,7 +1394,7 @@ SCliConn* cliGetConn(SCliMsg* pMsg, SCliThrd* pThrd, bool* ignore, char* addr) {
return
conn
;
};
conn
=
getConnFromPool
(
pThrd
->
pool
,
addr
);
conn
=
getConnFromPool
2
(
pThrd
,
addr
,
pMsg
);
if
(
conn
!=
NULL
)
{
tTrace
(
"%s conn %p get from conn pool:%p"
,
CONN_GET_INST_LABEL
(
conn
),
conn
,
pThrd
->
pool
);
}
else
{
...
...
@@ -1378,19 +1452,6 @@ static FORCE_INLINE void cliUpdateFqdnCache(SHashObj* cache, char* fqdn) {
return
;
}
static
int32_t
cliPreCheckSessionLimit
(
SCliThrd
*
pThrd
,
char
*
addr
)
{
STrans
*
pTransInst
=
pThrd
->
pTransInst
;
SMsgList
**
list
=
taosHashGet
(
pThrd
->
connLimitCache
,
addr
,
strlen
(
addr
));
if
(
list
==
NULL
||
*
list
==
NULL
)
{
return
0
;
}
if
((
*
list
)
->
numOfConn
>=
pTransInst
->
connLimitNum
)
{
return
-
1
;
}
return
0
;
}
static
void
doFreeTimeoutMsg
(
void
*
param
)
{
STaskArg
*
arg
=
param
;
SCliMsg
*
pMsg
=
arg
->
param1
;
...
...
@@ -1403,48 +1464,24 @@ static void doFreeTimeoutMsg(void* param) {
doNotifyApp
(
pMsg
,
pThrd
);
taosMemoryFree
(
arg
);
}
static
int32_t
cliPreCheckSessionLimitForMsg
(
SCliThrd
*
pThrd
,
char
*
addr
,
SCliMsg
*
pMsg
)
{
STrans
*
pTransInst
=
pThrd
->
pTransInst
;
SMsgList
**
list
=
taosHashGet
(
pThrd
->
connLimitCache
,
addr
,
strlen
(
addr
));
if
(
list
==
NULL
||
*
list
==
NULL
)
{
return
0
;
}
if
((
*
list
)
->
numOfConn
>=
pTransInst
->
connLimitNum
)
{
STraceId
*
trace
=
&
pMsg
->
msg
.
info
.
traceId
;
STaskArg
*
arg
=
taosMemoryMalloc
(
sizeof
(
STaskArg
));
arg
->
param1
=
pMsg
;
arg
->
param2
=
pThrd
;
pMsg
->
ctx
->
task
=
transDQSched
(
pThrd
->
waitConnQueue
,
doFreeTimeoutMsg
,
arg
,
pTransInst
->
timeToGetConn
);
tGTrace
(
"%s msg %s delay to send, wait for avaiable connect"
,
pTransInst
->
label
,
TMSG_INFO
(
pMsg
->
msg
.
msgType
));
QUEUE_PUSH
(
&
(
*
list
)
->
msgQ
,
&
pMsg
->
q
);
return
-
1
;
}
return
0
;
}
void
cliHandleReq
(
SCliMsg
*
pMsg
,
SCliThrd
*
pThrd
)
{
STrans
*
pTransInst
=
pThrd
->
pTransInst
;
STransConnCtx
*
pCtx
=
pMsg
->
ctx
;
STraceId
*
trace
=
&
pMsg
->
msg
.
info
.
traceId
;
STrans
*
pTransInst
=
pThrd
->
pTransInst
;
STraceId
*
trace
=
&
pMsg
->
msg
.
info
.
traceId
;
cliMayCvtFqdnToIp
(
&
p
C
tx
->
epSet
,
&
pThrd
->
cvtAddr
);
if
(
!
EPSET_IS_VALID
(
&
p
C
tx
->
epSet
))
{
cliMayCvtFqdnToIp
(
&
p
Msg
->
c
tx
->
epSet
,
&
pThrd
->
cvtAddr
);
if
(
!
EPSET_IS_VALID
(
&
p
Msg
->
c
tx
->
epSet
))
{
tGError
(
"%s, msg %s sent with invalid epset"
,
pTransInst
->
label
,
TMSG_INFO
(
pMsg
->
msg
.
msgType
));
destroyCmsg
(
pMsg
);
return
;
}
char
*
fqdn
=
EPSET_GET_INUSE_IP
(
&
p
C
tx
->
epSet
);
uint16_t
port
=
EPSET_GET_INUSE_PORT
(
&
p
C
tx
->
epSet
);
char
*
fqdn
=
EPSET_GET_INUSE_IP
(
&
p
Msg
->
c
tx
->
epSet
);
uint16_t
port
=
EPSET_GET_INUSE_PORT
(
&
p
Msg
->
c
tx
->
epSet
);
char
addr
[
TSDB_FQDN_LEN
+
64
]
=
{
0
};
CONN_CONSTRUCT_HASH_KEY
(
addr
,
fqdn
,
port
);
bool
ignore
=
false
;
SCliConn
*
conn
=
cliGetConn
(
pMsg
,
pThrd
,
&
ignore
,
addr
);
SCliConn
*
conn
=
cliGetConn
(
&
pMsg
,
pThrd
,
&
ignore
,
addr
);
if
(
ignore
==
true
)
{
// persist conn already release by server
STransMsg
resp
;
...
...
@@ -1455,12 +1492,12 @@ void cliHandleReq(SCliMsg* pMsg, SCliThrd* pThrd) {
destroyCmsg
(
pMsg
);
return
;
}
if
(
conn
==
NULL
&&
cliPreCheckSessionLimitForMsg
(
pThrd
,
addr
,
pMsg
)
!=
0
)
{
if
(
conn
==
NULL
&&
pMsg
==
NULL
)
{
return
;
}
if
(
conn
!=
NULL
)
{
transCtxMerge
(
&
conn
->
ctx
,
&
p
C
tx
->
appCtx
);
transCtxMerge
(
&
conn
->
ctx
,
&
p
Msg
->
c
tx
->
appCtx
);
transQueuePush
(
&
conn
->
cliMsgs
,
pMsg
);
cliSend
(
conn
);
}
else
{
...
...
@@ -1469,7 +1506,7 @@ void cliHandleReq(SCliMsg* pMsg, SCliThrd* pThrd) {
int64_t
refId
=
(
int64_t
)
pMsg
->
msg
.
info
.
handle
;
if
(
refId
!=
0
)
specifyConnRef
(
conn
,
true
,
refId
);
transCtxMerge
(
&
conn
->
ctx
,
&
p
C
tx
->
appCtx
);
transCtxMerge
(
&
conn
->
ctx
,
&
p
Msg
->
c
tx
->
appCtx
);
transQueuePush
(
&
conn
->
cliMsgs
,
pMsg
);
conn
->
ip
=
strdup
(
addr
);
...
...
@@ -1521,17 +1558,6 @@ void cliHandleReq(SCliMsg* pMsg, SCliThrd* pThrd) {
cliHandleFastFail
(
conn
,
ret
);
return
;
}
SMsgList
**
list
=
taosHashGet
(
pThrd
->
connLimitCache
,
conn
->
ip
,
strlen
(
conn
->
ip
));
if
(
list
==
NULL
||
*
list
==
NULL
)
{
SMsgList
*
nList
=
taosMemoryCalloc
(
1
,
sizeof
(
SMsgList
));
nList
->
numOfConn
++
;
QUEUE_INIT
(
&
nList
->
msgQ
);
taosHashPut
(
pThrd
->
connLimitCache
,
conn
->
ip
,
strlen
(
conn
->
ip
),
&
nList
,
sizeof
(
void
*
));
}
else
{
(
*
list
)
->
numOfConn
++
;
}
uv_timer_start
(
conn
->
timer
,
cliConnTimeout
,
TRANS_CONN_TIMEOUT
,
0
);
}
tGTrace
(
"%s conn %p ready"
,
pTransInst
->
label
,
conn
);
...
...
@@ -1914,7 +1940,6 @@ static SCliThrd* createThrdObj(void* trans) {
pThrd
->
destroyAhandleFp
=
pTransInst
->
destroyFp
;
pThrd
->
fqdn2ipCache
=
taosHashInit
(
4
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_BINARY
),
true
,
HASH_NO_LOCK
);
pThrd
->
failFastCache
=
taosHashInit
(
8
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_BINARY
),
true
,
HASH_NO_LOCK
);
pThrd
->
connLimitCache
=
taosHashInit
(
8
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_BINARY
),
true
,
HASH_NO_LOCK
);
pThrd
->
batchCache
=
taosHashInit
(
8
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_BINARY
),
true
,
HASH_NO_LOCK
);
...
...
@@ -1964,27 +1989,6 @@ static void destroyThrdObj(SCliThrd* pThrd) {
pIter
=
(
void
**
)
taosHashIterate
(
pThrd
->
batchCache
,
pIter
);
}
taosHashCleanup
(
pThrd
->
batchCache
);
pIter
=
taosHashIterate
(
pThrd
->
connLimitCache
,
NULL
);
while
(
pIter
!=
NULL
)
{
SMsgList
*
list
=
(
SMsgList
*
)(
*
pIter
);
while
(
!
QUEUE_IS_EMPTY
(
&
list
->
msgQ
))
{
queue
*
h
=
QUEUE_HEAD
(
&
list
->
msgQ
);
QUEUE_REMOVE
(
h
);
SCliMsg
*
pMsg
=
QUEUE_DATA
(
h
,
SCliMsg
,
q
);
if
(
pThrd
!=
NULL
&&
pThrd
->
destroyAhandleFp
!=
NULL
)
{
pThrd
->
destroyAhandleFp
(
pMsg
->
ctx
->
ahandle
);
}
destroyCmsg
(
pMsg
);
}
taosMemoryFree
(
list
);
pIter
=
(
void
**
)
taosHashIterate
(
pThrd
->
connLimitCache
,
pIter
);
}
taosHashCleanup
(
pThrd
->
connLimitCache
);
taosMemoryFree
(
pThrd
);
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录