Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
哥们要飞
TDengine
提交
34533dce
T
TDengine
项目概览
哥们要飞
/
TDengine
与 Fork 源项目一致
Fork自
taosdata / TDengine
通知
1
Star
1
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看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
34533dce
编写于
6月 06, 2020
作者:
S
Shengliang Guan
提交者:
GitHub
6月 06, 2020
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #2166 from taosdata/hotfix/rpcClose
add reference count for RpcInfo
上级
0b67ec8f
8f7c2713
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
29 addition
and
9 deletion
+29
-9
src/rpc/src/rpcMain.c
src/rpc/src/rpcMain.c
+29
-9
未找到文件。
src/rpc/src/rpcMain.c
浏览文件 @
34533dce
...
...
@@ -58,6 +58,7 @@ typedef struct {
void
(
*
cfp
)(
SRpcMsg
*
,
SRpcIpSet
*
);
int
(
*
afp
)(
char
*
user
,
char
*
spi
,
char
*
encrypt
,
char
*
secret
,
char
*
ckey
);
int
refCount
;
void
*
idPool
;
// handle to ID pool
void
*
tmrCtrl
;
// handle to timer
SHashObj
*
hash
;
// handle returned by hash utility
...
...
@@ -199,6 +200,8 @@ static int rpcAddAuthPart(SRpcConn *pConn, char *msg, int msgLen);
static
int
rpcCheckAuthentication
(
SRpcConn
*
pConn
,
char
*
msg
,
int
msgLen
);
static
void
rpcLockConn
(
SRpcConn
*
pConn
);
static
void
rpcUnlockConn
(
SRpcConn
*
pConn
);
static
void
rpcAddRef
(
SRpcInfo
*
pRpc
);
static
void
rpcDecRef
(
SRpcInfo
*
pRpc
);
void
*
rpcOpen
(
const
SRpcInit
*
pInit
)
{
SRpcInfo
*
pRpc
;
...
...
@@ -224,6 +227,7 @@ void *rpcOpen(const SRpcInit *pInit) {
pRpc
->
spi
=
pInit
->
spi
;
pRpc
->
cfp
=
pInit
->
cfp
;
pRpc
->
afp
=
pInit
->
afp
;
pRpc
->
refCount
=
1
;
size_t
size
=
sizeof
(
SRpcConn
)
*
pRpc
->
sessions
;
pRpc
->
connList
=
(
SRpcConn
*
)
calloc
(
1
,
size
);
...
...
@@ -293,15 +297,8 @@ void rpcClose(void *param) {
(
*
taosCleanUpConn
[
pRpc
->
connType
|
RPC_CONN_TCP
])(
pRpc
->
tcphandle
);
(
*
taosCleanUpConn
[
pRpc
->
connType
])(
pRpc
->
udphandle
);
taosHashCleanup
(
pRpc
->
hash
);
taosTmrCleanUp
(
pRpc
->
tmrCtrl
);
taosIdPoolCleanUp
(
pRpc
->
idPool
);
rpcCloseConnCache
(
pRpc
->
pCache
);
tfree
(
pRpc
->
connList
);
pthread_mutex_destroy
(
&
pRpc
->
mutex
);
tTrace
(
"%s rpc is closed"
,
pRpc
->
label
);
tfree
(
pRpc
);
rpcDecRef
(
pRpc
);
}
void
*
rpcMallocCont
(
int
contLen
)
{
...
...
@@ -378,6 +375,7 @@ void rpcSendResponse(const SRpcMsg *pRsp) {
SRpcConn
*
pConn
=
(
SRpcConn
*
)
pRsp
->
handle
;
SRpcMsg
rpcMsg
=
*
pRsp
;
SRpcMsg
*
pMsg
=
&
rpcMsg
;
SRpcInfo
*
pRpc
=
pConn
->
pRpc
;
if
(
pMsg
->
pCont
==
NULL
)
{
pMsg
->
pCont
=
rpcMallocCont
(
0
);
...
...
@@ -395,6 +393,7 @@ void rpcSendResponse(const SRpcMsg *pRsp) {
if
(
pConn
->
inType
==
0
||
pConn
->
user
[
0
]
==
0
)
{
tTrace
(
"%s, connection is already released, rsp wont be sent"
,
pConn
->
info
);
rpcUnlockConn
(
pConn
);
rpcDecRef
(
pRpc
);
return
;
}
...
...
@@ -420,7 +419,6 @@ void rpcSendResponse(const SRpcMsg *pRsp) {
pConn
->
rspMsgLen
=
msgLen
;
if
(
pMsg
->
code
==
TSDB_CODE_RPC_ACTION_IN_PROGRESS
)
pConn
->
inTranId
--
;
SRpcInfo
*
pRpc
=
pConn
->
pRpc
;
taosTmrStopA
(
&
pConn
->
pTimer
);
// set the idle timer to monitor the activity
...
...
@@ -429,6 +427,7 @@ void rpcSendResponse(const SRpcMsg *pRsp) {
pConn
->
secured
=
1
;
// connection shall be secured
rpcUnlockConn
(
pConn
);
rpcDecRef
(
pRpc
);
// decrease the referene count
return
;
}
...
...
@@ -951,6 +950,7 @@ static void rpcProcessIncomingMsg(SRpcConn *pConn, SRpcHead *pHead) {
if
(
rpcIsReq
(
pHead
->
msgType
)
)
{
rpcMsg
.
handle
=
pConn
;
rpcAddRef
(
pRpc
);
// add the refCount for requests
pConn
->
pTimer
=
taosTmrStart
(
rpcProcessProgressTimer
,
tsProgressTimer
,
pConn
,
pRpc
->
tmrCtrl
);
(
*
(
pRpc
->
cfp
))(
&
rpcMsg
,
NULL
);
}
else
{
...
...
@@ -1433,3 +1433,23 @@ static void rpcUnlockConn(SRpcConn *pConn) {
}
}
static
void
rpcAddRef
(
SRpcInfo
*
pRpc
)
{
atomic_add_fetch_8
(
&
pRpc
->
refCount
,
1
);
}
static
void
rpcDecRef
(
SRpcInfo
*
pRpc
)
{
if
(
atomic_sub_fetch_8
(
&
pRpc
->
refCount
,
1
)
==
0
)
{
taosHashCleanup
(
pRpc
->
hash
);
taosTmrCleanUp
(
pRpc
->
tmrCtrl
);
taosIdPoolCleanUp
(
pRpc
->
idPool
);
rpcCloseConnCache
(
pRpc
->
pCache
);
tfree
(
pRpc
->
connList
);
pthread_mutex_destroy
(
&
pRpc
->
mutex
);
tTrace
(
"%s rpc resources are released"
,
pRpc
->
label
);
tfree
(
pRpc
);
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录