Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
288f3600
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看板
未验证
提交
288f3600
编写于
1月 26, 2022
作者:
dengyihao
提交者:
GitHub
1月 26, 2022
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #10028 from taosdata/feature/trans
refactor rpc
上级
3dd00978
cea06000
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
54 addition
and
30 deletion
+54
-30
source/libs/transport/src/transCli.c
source/libs/transport/src/transCli.c
+44
-21
source/libs/transport/src/transSrv.c
source/libs/transport/src/transSrv.c
+9
-8
source/libs/transport/test/rserver.c
source/libs/transport/test/rserver.c
+1
-1
未找到文件。
source/libs/transport/src/transCli.c
浏览文件 @
288f3600
...
...
@@ -95,8 +95,10 @@ static void clientHandleExcept(SCliConn* conn);
// handle req from app
static
void
clientHandleReq
(
SCliMsg
*
pMsg
,
SCliThrdObj
*
pThrd
);
static
void
clientMsgDestroy
(
SCliMsg
*
pMsg
);
static
void
destroyTransConnCtx
(
STransConnCtx
*
ctx
);
static
void
destroyUserdata
(
SRpcMsg
*
userdata
);
static
void
destroyCmsg
(
SCliMsg
*
cmsg
);
static
void
transDestroyConnCtx
(
STransConnCtx
*
ctx
);
// thread obj
static
SCliThrdObj
*
createThrdObj
();
static
void
destroyThrdObj
(
SCliThrdObj
*
pThrd
);
...
...
@@ -104,7 +106,8 @@ static void destroyThrdObj(SCliThrdObj* pThrd);
static
void
*
clientThread
(
void
*
arg
);
static
void
clientHandleResp
(
SCliConn
*
conn
)
{
STransConnCtx
*
pCtx
=
((
SCliMsg
*
)
conn
->
data
)
->
ctx
;
SCliMsg
*
pMsg
=
conn
->
data
;
STransConnCtx
*
pCtx
=
pMsg
->
ctx
;
SRpcInfo
*
pRpc
=
pCtx
->
pTransInst
;
STransMsgHead
*
pHead
=
(
STransMsgHead
*
)(
conn
->
readBuf
.
buf
);
...
...
@@ -122,41 +125,44 @@ static void clientHandleResp(SCliConn* conn) {
(
pRpc
->
cfp
)(
NULL
,
&
rpcMsg
,
NULL
);
conn
->
notifyCount
+=
1
;
SCliThrdObj
*
pThrd
=
conn
->
hostThrd
;
tfree
(
conn
->
data
);
// buf alread translated to rpcMsg.pCont
// buf's mem alread translated to rpcMsg.pCont
transClearBuffer
(
&
conn
->
readBuf
);
uv_read_start
((
uv_stream_t
*
)
conn
->
stream
,
clientAllocBufferCb
,
clientReadCb
);
SCliThrdObj
*
pThrd
=
conn
->
hostThrd
;
addConnToPool
(
pThrd
->
pool
,
pCtx
->
ip
,
pCtx
->
port
,
conn
);
destroyCmsg
(
pMsg
);
conn
->
data
=
NULL
;
// start thread's timer of conn pool if not active
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
);
}
destroyTransConnCtx
(
pCtx
);
}
static
void
clientHandleExcept
(
SCliConn
*
pConn
)
{
if
(
pConn
->
data
==
NULL
)
{
// handle conn except in conn pool
clientConnDestroy
(
pConn
,
true
);
return
;
}
tDebug
(
"conn %p destroy"
,
pConn
);
tDebug
(
"conn %p
start to
destroy"
,
pConn
);
SCliMsg
*
pMsg
=
pConn
->
data
;
transFreeMsg
((
pMsg
->
msg
.
pCont
));
pMsg
->
msg
.
pCont
=
NULL
;
destroyUserdata
(
&
pMsg
->
msg
)
;
STransConnCtx
*
pCtx
=
pMsg
->
ctx
;
SRpcInfo
*
pRpc
=
pCtx
->
pTransInst
;
SRpcMsg
rpcMsg
=
{
0
};
rpcMsg
.
ahandle
=
pCtx
->
ahandle
;
rpcMsg
.
code
=
-
1
;
// SRpcInfo* pRpc = pMsg->ctx->pRpc;
(
pRpc
->
cfp
)(
NULL
,
&
rpcMsg
,
NULL
);
tfree
(
pConn
->
data
);
(
pCtx
->
pTransInst
->
cfp
)(
NULL
,
&
rpcMsg
,
NULL
);
pConn
->
notifyCount
+=
1
;
destroyTransConnCtx
(
pCtx
);
destroyCmsg
(
pMsg
);
pConn
->
data
=
NULL
;
// transDestroyConnCtx(pCtx);
clientConnDestroy
(
pConn
,
true
);
}
...
...
@@ -236,6 +242,7 @@ static void addConnToPool(void* pool, char* ip, uint32_t port, SCliConn* conn) {
tDebug
(
"conn %p added to conn pool, read buf cap: %d"
,
conn
,
conn
->
readBuf
.
cap
);
SRpcInfo
*
pRpc
=
((
SCliThrdObj
*
)
conn
->
hostThrd
)
->
pTransInst
;
conn
->
expireTime
=
taosGetTimestampMs
()
+
CONN_PERSIST_TIME
(
pRpc
->
idleTime
);
SConnList
*
plist
=
taosHashGet
((
SHashObj
*
)
pool
,
key
,
strlen
(
key
));
conn
->
notifyCount
=
0
;
...
...
@@ -282,6 +289,9 @@ static void clientReadCb(uv_stream_t* handle, ssize_t nread, const uv_buf_t* buf
}
assert
(
nread
<=
0
);
if
(
nread
==
0
)
{
// ref http://docs.libuv.org/en/v1.x/stream.html?highlight=uv_read_start#c.uv_read_cb
// nread might be 0, which does not indicate an error or EOF. This is equivalent to EAGAIN or EWOULDBLOCK under
// read(2).
return
;
}
if
(
nread
<
0
||
nread
==
UV_EOF
)
{
...
...
@@ -321,11 +331,12 @@ static void clientWriteCb(uv_write_t* req, int status) {
if
(
status
==
0
)
{
tDebug
(
"conn %p data already was written out"
,
pConn
);
SCliMsg
*
pMsg
=
pConn
->
data
;
if
(
pMsg
!=
NULL
)
{
transFreeMsg
((
pMsg
->
msg
.
pCont
));
pMsg
->
msg
.
pCont
=
NULL
;
if
(
pMsg
==
NULL
)
{
destroy
// handle
return
;
}
destroyUserdata
(
&
pMsg
->
msg
);
}
else
{
tError
(
"conn %p failed to write: %s"
,
pConn
,
uv_err_name
(
status
));
clientHandleExcept
(
pConn
);
...
...
@@ -453,8 +464,20 @@ void* taosInitClient(uint32_t ip, uint32_t port, char* label, int numOfThreads,
}
return
cli
;
}
static
void
clientMsgDestroy
(
SCliMsg
*
pMsg
)
{
// impl later
static
void
destroyUserdata
(
SRpcMsg
*
userdata
)
{
if
(
userdata
->
pCont
==
NULL
)
{
return
;
}
transFreeMsg
(
userdata
->
pCont
);
userdata
->
pCont
=
NULL
;
}
static
void
destroyCmsg
(
SCliMsg
*
pMsg
)
{
if
(
pMsg
==
NULL
)
{
return
;
}
transDestroyConnCtx
(
pMsg
->
ctx
);
destroyUserdata
(
&
pMsg
->
msg
);
free
(
pMsg
);
}
static
SCliThrdObj
*
createThrdObj
()
{
...
...
@@ -487,7 +510,7 @@ static void destroyThrdObj(SCliThrdObj* pThrd) {
free
(
pThrd
);
}
static
void
destroyTrans
ConnCtx
(
STransConnCtx
*
ctx
)
{
static
void
transDestroy
ConnCtx
(
STransConnCtx
*
ctx
)
{
if
(
ctx
!=
NULL
)
{
free
(
ctx
->
ip
);
}
...
...
source/libs/transport/src/transSrv.c
浏览文件 @
288f3600
...
...
@@ -91,7 +91,7 @@ static void uvWorkerAsyncCb(uv_async_t* handle);
static
void
uvPrepareSendData
(
SSrvMsg
*
msg
,
uv_buf_t
*
wb
);
static
void
uvStartSendResp
(
SSrvMsg
*
msg
);
static
void
destroyS
rvMsg
(
SSrvConn
*
conn
);
static
void
destroyS
msg
(
SSrvMsg
*
smsg
);
// check whether already read complete packet
static
bool
readComplete
(
SConnBuffer
*
buf
);
static
SSrvConn
*
createConn
();
...
...
@@ -305,8 +305,10 @@ void uvOnTimeoutCb(uv_timer_t* handle) {
void
uvOnWriteCb
(
uv_write_t
*
req
,
int
status
)
{
SSrvConn
*
conn
=
req
->
data
;
SSrvMsg
*
smsg
=
conn
->
pSrvMsg
;
destroySrvMsg
(
conn
);
SSrvMsg
*
smsg
=
conn
->
pSrvMsg
;
destroySmsg
(
smsg
);
conn
->
pSrvMsg
=
NULL
;
transClearBuffer
(
&
conn
->
readBuf
);
if
(
status
==
0
)
{
...
...
@@ -362,14 +364,12 @@ static void uvStartSendResp(SSrvMsg* smsg) {
return
;
}
static
void
destroySrvMsg
(
SSrvConn
*
conn
)
{
SSrvMsg
*
smsg
=
conn
->
pSrvMsg
;
static
void
destroySmsg
(
SSrvMsg
*
smsg
)
{
if
(
smsg
==
NULL
)
{
return
;
}
transFreeMsg
(
smsg
->
msg
.
pCont
);
free
(
conn
->
pSrvMsg
);
conn
->
pSrvMsg
=
NULL
;
free
(
smsg
);
}
void
uvWorkerAsyncCb
(
uv_async_t
*
handle
)
{
SWorkThrdObj
*
pThrd
=
handle
->
data
;
...
...
@@ -555,7 +555,8 @@ static void destroyConn(SSrvConn* conn, bool clear) {
return
;
}
transDestroyBuffer
(
&
conn
->
readBuf
);
destroySrvMsg
(
conn
);
destroySmsg
(
conn
->
pSrvMsg
);
conn
->
pSrvMsg
=
NULL
;
if
(
clear
)
{
uv_close
((
uv_handle_t
*
)
conn
->
pTcp
,
uvDestroyConn
);
...
...
source/libs/transport/test/rserver.c
浏览文件 @
288f3600
...
...
@@ -165,6 +165,7 @@ int main(int argc, char *argv[]) {
tError
(
"failed to start RPC server"
);
return
-
1
;
}
// sleep(5);
tInfo
(
"RPC server is running, ctrl-c to exit"
);
...
...
@@ -172,7 +173,6 @@ int main(int argc, char *argv[]) {
dataFd
=
open
(
dataName
,
O_APPEND
|
O_CREAT
|
O_WRONLY
,
S_IRWXU
|
S_IRWXG
|
S_IRWXO
);
if
(
dataFd
<
0
)
tInfo
(
"failed to open data file, reason:%s"
,
strerror
(
errno
));
}
qhandle
=
taosOpenQueue
();
qset
=
taosOpenQset
();
taosAddIntoQset
(
qset
,
qhandle
,
NULL
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录