Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
affa8a7e
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看板
提交
affa8a7e
编写于
1月 21, 2022
作者:
dengyihao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactor rpc
上级
f577c418
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
21 addition
and
14 deletion
+21
-14
source/libs/transport/src/transCli.c
source/libs/transport/src/transCli.c
+21
-14
未找到文件。
source/libs/transport/src/transCli.c
浏览文件 @
affa8a7e
...
...
@@ -17,6 +17,8 @@
#include "transComm.h"
#define CONN_PERSIST_TIME(para) (para * 1000 * 100)
typedef
struct
SCliConn
{
uv_connect_t
connReq
;
uv_stream_t
*
stream
;
...
...
@@ -102,6 +104,9 @@ static void clientProcessData(SCliConn* conn) {
SCliThrdObj
*
pThrd
=
conn
->
hostThrd
;
addConnToCache
(
pThrd
->
cache
,
pCtx
->
ip
,
pCtx
->
port
,
conn
);
if
(
!
uv_is_active
((
uv_handle_t
*
)
pThrd
->
pTimer
)
&&
pRpc
->
idleTime
>
0
)
{
uv_timer_start
((
uv_timer_t
*
)
pThrd
->
pTimer
,
clientTimeoutCb
,
CONN_PERSIST_TIME
(
pRpc
->
idleTime
)
/
2
,
0
);
}
free
(
pCtx
->
ip
);
free
(
pCtx
);
// impl
...
...
@@ -112,6 +117,7 @@ static void clientTimeoutCb(uv_timer_t* handle) {
SCliThrdObj
*
pThrd
=
handle
->
data
;
SRpcInfo
*
pRpc
=
pThrd
->
pTransInst
;
int64_t
currentTime
=
pThrd
->
nextTimeout
;
tDebug
(
"timeout, try to remove expire conn from connCache"
);
SConnList
*
p
=
taosHashIterate
((
SHashObj
*
)
pThrd
->
cache
,
NULL
);
while
(
p
!=
NULL
)
{
...
...
@@ -128,8 +134,8 @@ static void clientTimeoutCb(uv_timer_t* handle) {
p
=
taosHashIterate
((
SHashObj
*
)
pThrd
->
cache
,
p
);
}
pThrd
->
nextTimeout
=
taosGetTimestampMs
()
+
pRpc
->
idleTime
*
1000
*
10
;
uv_timer_start
(
handle
,
clientTimeoutCb
,
pRpc
->
idleTime
*
10
,
0
);
pThrd
->
nextTimeout
=
taosGetTimestampMs
()
+
CONN_PERSIST_TIME
(
pRpc
->
idleTime
)
;
uv_timer_start
(
handle
,
clientTimeoutCb
,
CONN_PERSIST_TIME
(
pRpc
->
idleTime
)
/
2
,
0
);
}
static
void
*
connCacheCreate
(
int
size
)
{
SHashObj
*
cache
=
taosHashInit
(
4
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_BINARY
),
false
,
HASH_NO_LOCK
);
...
...
@@ -158,8 +164,7 @@ static SCliConn* getConnFromCache(void* cache, char* ip, uint32_t port) {
SConnList
*
plist
=
taosHashGet
(
pCache
,
key
,
strlen
(
key
));
if
(
plist
==
NULL
)
{
SConnList
list
;
plist
=
&
list
;
taosHashPut
(
pCache
,
key
,
strlen
(
key
),
plist
,
sizeof
(
*
plist
));
taosHashPut
(
pCache
,
key
,
strlen
(
key
),
(
void
*
)
&
list
,
sizeof
(
list
));
plist
=
taosHashGet
(
pCache
,
key
,
strlen
(
key
));
QUEUE_INIT
(
&
plist
->
conn
);
}
...
...
@@ -177,7 +182,7 @@ static void addConnToCache(void* cache, char* ip, uint32_t port, SCliConn* conn)
tstrncpy
(
key
+
strlen
(
key
),
(
char
*
)(
&
port
),
sizeof
(
port
));
SRpcInfo
*
pRpc
=
((
SCliThrdObj
*
)
conn
->
hostThrd
)
->
pTransInst
;
conn
->
expireTime
=
taosGetTimestampMs
()
+
pRpc
->
idleTime
*
1000
*
10
;
conn
->
expireTime
=
taosGetTimestampMs
()
+
CONN_PERSIST_TIME
(
pRpc
->
idleTime
)
;
SConnList
*
plist
=
taosHashGet
((
SHashObj
*
)
cache
,
key
,
strlen
(
key
));
// list already create before
assert
(
plist
!=
NULL
);
...
...
@@ -374,14 +379,13 @@ static void clientAsyncCb(uv_async_t* handle) {
clientHandleReq
(
pMsg
,
pThrd
);
count
++
;
if
(
count
>=
2
)
{
t
Error
(
"send batch size: %d"
,
count
);
t
Debug
(
"send batch size: %d"
,
count
);
}
}
}
static
void
*
clientThread
(
void
*
arg
)
{
SCliThrdObj
*
pThrd
=
(
SCliThrdObj
*
)
arg
;
uv_run
(
pThrd
->
loop
,
UV_RUN_DEFAULT
);
}
...
...
@@ -409,8 +413,8 @@ void* taosInitClient(uint32_t ip, uint32_t port, char* label, int numOfThreads,
pThrd
->
pTimer
=
malloc
(
sizeof
(
uv_timer_t
));
uv_timer_init
(
pThrd
->
loop
,
pThrd
->
pTimer
);
pThrd
->
pTimer
->
data
=
pThrd
;
pThrd
->
nextTimeout
=
taosGetTimestampMs
()
+
pRpc
->
idleTime
*
1000
*
10
;
pThrd
->
nextTimeout
=
taosGetTimestampMs
()
+
CONN_PERSIST_TIME
(
pRpc
->
idleTime
);
pThrd
->
cache
=
connCacheCreate
(
1
);
pThrd
->
pTransInst
=
shandle
;
...
...
@@ -426,16 +430,19 @@ static void clientMsgDestroy(SCliMsg* pMsg) {
// impl later
free
(
pMsg
);
}
static
void
destroyThrdObj
(
SCliThrdObj
*
pThrd
)
{
pthread_join
(
pThrd
->
thread
,
NULL
);
pthread_mutex_destroy
(
&
pThrd
->
msgMtx
);
free
(
pThrd
->
cliAsync
);
free
(
pThrd
->
loop
);
free
(
pThrd
);
}
//
void
taosCloseClient
(
void
*
arg
)
{
// impl later
SClientObj
*
cli
=
arg
;
for
(
int
i
=
0
;
i
<
cli
->
numOfThreads
;
i
++
)
{
SCliThrdObj
*
pThrd
=
cli
->
pThreadObj
[
i
];
pthread_join
(
pThrd
->
thread
,
NULL
);
pthread_mutex_destroy
(
&
pThrd
->
msgMtx
);
free
(
pThrd
->
cliAsync
);
free
(
pThrd
->
loop
);
free
(
pThrd
);
destroyThrdObj
(
cli
->
pThreadObj
[
i
]);
}
free
(
cli
->
pThreadObj
);
free
(
cli
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录