Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
2d0c5ff5
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22017
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
2d0c5ff5
编写于
3月 19, 2022
作者:
dengyihao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
handle except
上级
9d12273a
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
54 addition
and
58 deletion
+54
-58
source/libs/transport/src/transCli.c
source/libs/transport/src/transCli.c
+10
-8
source/libs/transport/src/transSrv.c
source/libs/transport/src/transSrv.c
+16
-6
source/libs/transport/test/transUT.cc
source/libs/transport/test/transUT.cc
+28
-44
未找到文件。
source/libs/transport/src/transCli.c
浏览文件 @
2d0c5ff5
...
...
@@ -138,11 +138,12 @@ static void destroyThrdObj(SCliThrdObj* pThrd);
conn->status = ConnRelease; \
transClearBuffer(&conn->readBuf); \
transFreeMsg(transContFromHead((char*)head)); \
tDebug("cli conn %p receive release request", conn); \
if (T_REF_VAL_GET(conn) == 1) { \
SCliThrdObj* thrd = conn->hostThrd; \
addConnToPool(thrd->pool, conn); \
} \
goto _RETURN;
\
return;
\
} \
} while (0)
...
...
@@ -150,7 +151,7 @@ static void destroyThrdObj(SCliThrdObj* pThrd);
do { \
if (thrd->quit) { \
cliHandleExcept(conn); \
goto _RETURE;
\
return;
\
} \
} while (0)
...
...
@@ -158,9 +159,9 @@ static void destroyThrdObj(SCliThrdObj* pThrd);
do { \
if (conn->broken) { \
cliHandleExcept(conn); \
goto _RETURE;
\
return;
\
} \
} while (0)
;
} while (0)
#define CONN_SET_PERSIST_BY_APP(conn) \
do { \
...
...
@@ -389,12 +390,11 @@ static void addConnToPool(void* pool, SCliConn* conn) {
// list already create before
assert
(
plist
!=
NULL
);
QUEUE_PUSH
(
&
plist
->
conn
,
&
conn
->
conn
);
assert
(
!
QUEUE_IS_EMPTY
(
&
plist
->
conn
));
}
static
void
cliAllocRecvBufferCb
(
uv_handle_t
*
handle
,
size_t
suggested_size
,
uv_buf_t
*
buf
)
{
SCliConn
*
conn
=
handle
->
data
;
SConnBuffer
*
pBuf
=
&
conn
->
readBuf
;
// avoid conn
QUEUE_REMOVE
(
&
conn
->
conn
);
transAllocBuffer
(
pBuf
,
buf
);
}
static
void
cliRecvCb
(
uv_stream_t
*
handle
,
ssize_t
nread
,
const
uv_buf_t
*
buf
)
{
...
...
@@ -420,6 +420,7 @@ static void cliRecvCb(uv_stream_t* handle, ssize_t nread, const uv_buf_t* buf) {
// 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).
tTrace
(
"%s cli conn %p read empty"
,
CONN_GET_INST_LABEL
(
conn
),
conn
);
return
;
}
if
(
nread
<
0
)
{
...
...
@@ -555,8 +556,6 @@ void cliSend(SCliConn* pConn) {
pConn
->
writeReq
.
data
=
pConn
;
uv_write
(
&
pConn
->
writeReq
,
(
uv_stream_t
*
)
pConn
->
stream
,
&
wb
,
1
,
cliSendCb
);
return
;
_RETURE:
return
;
}
...
...
@@ -594,6 +593,7 @@ static void cliHandleRelease(SCliMsg* pMsg, SCliThrdObj* pThrd) {
SCliConn
*
conn
=
pMsg
->
msg
.
handle
;
tDebug
(
"%s cli conn %p start to release to inst"
,
CONN_GET_INST_LABEL
(
conn
),
conn
);
transUnrefCliHandle
(
conn
);
taosArrayPush
(
conn
->
cliMsgs
,
&
pMsg
);
if
(
taosArrayGetSize
(
conn
->
cliMsgs
)
>=
2
)
{
return
;
// send one by one
...
...
@@ -613,6 +613,8 @@ SCliConn* cliGetConn(SCliMsg* pMsg, SCliThrdObj* pThrd) {
conn
=
getConnFromPool
(
pThrd
->
pool
,
pCtx
->
ip
,
pCtx
->
port
);
if
(
conn
!=
NULL
)
{
tTrace
(
"%s cli conn %p get from conn pool"
,
CONN_GET_INST_LABEL
(
conn
),
conn
);
}
else
{
tTrace
(
"not found conn in conn pool %p"
,
pThrd
->
pool
);
}
}
return
conn
;
...
...
source/libs/transport/src/transSrv.c
浏览文件 @
2d0c5ff5
...
...
@@ -99,7 +99,19 @@ static const char* notify = "a";
conn->status = ConnRelease; \
transClearBuffer(&conn->readBuf); \
transFreeMsg(transContFromHead((char*)head)); \
goto _RETURE; \
tTrace("server conn %p received release request", conn); \
\
STransMsg tmsg = {.handle = (void*)conn, .code = 0}; \
SSrvMsg* srvMsg = calloc(1, sizeof(SSrvMsg)); \
srvMsg->msg = tmsg; \
srvMsg->type = Release; \
srvMsg->pConn = conn; \
taosArrayPush(conn->srvMsgs, &srvMsg); \
if (taosArrayGetSize(conn->srvMsgs) > 1) { \
return; \
} \
uvStartSendRespInternal(srvMsg); \
return; \
} \
} while (0)
// refactor later
...
...
@@ -242,6 +254,7 @@ static void uvHandleReq(SSrvConn* pConn) {
pHead
->
msgLen
-=
sizeof
(
STransUserMsg
);
}
}
CONN_SHOULD_RELEASE
(
pConn
,
pHead
);
STransMsg
transMsg
;
...
...
@@ -280,8 +293,6 @@ static void uvHandleReq(SSrvConn* pConn) {
(
*
pTransInst
->
cfp
)(
pTransInst
->
parent
,
&
transMsg
,
NULL
);
// uv_timer_start(&pConn->pTimer, uvHandleActivityTimeout, pRpc->idleTime * 10000, 0);
// auth
_RETURE:
return
;
}
void
uvOnRecvCb
(
uv_stream_t
*
cli
,
ssize_t
nread
,
const
uv_buf_t
*
buf
)
{
...
...
@@ -798,11 +809,10 @@ void uvHandleRelease(SSrvMsg* msg, SWorkThrdObj* thrd) {
// release handle to rpc init
SSrvConn
*
conn
=
msg
->
pConn
;
if
(
conn
->
status
==
ConnAcquire
)
{
if
(
taosArrayGetSize
(
conn
->
srvMsgs
)
>
0
)
{
taosArrayPush
(
conn
->
srvMsgs
,
&
msg
);
taosArrayPush
(
conn
->
srvMsgs
,
&
msg
);
if
(
taosArrayGetSize
(
conn
->
srvMsgs
)
>
1
)
{
return
;
}
taosArrayPush
(
conn
->
srvMsgs
,
&
msg
);
uvStartSendRespInternal
(
msg
);
return
;
}
else
if
(
conn
->
status
==
ConnRelease
)
{
...
...
source/libs/transport/test/transUT.cc
浏览文件 @
2d0c5ff5
...
...
@@ -30,24 +30,8 @@ const char *ckey = "ckey";
class
Server
;
int
port
=
7000
;
// server process
typedef
struct
CbArgs
{
tmsg_t
msgType
;
}
CbArgs
;
static
void
*
ConstructArgForSpecificMsgType
(
void
*
parent
,
tmsg_t
msgType
)
{
if
(
msgType
==
1
||
msgType
==
2
)
{
CbArgs
*
args
=
(
CbArgs
*
)
calloc
(
1
,
sizeof
(
CbArgs
));
args
->
msgType
=
msgType
;
return
args
;
}
return
NULL
;
}
// server except
static
bool
handleExcept
(
void
*
parent
,
tmsg_t
msgType
)
{
//
return
msgType
==
TDMT_VND_QUERY
||
msgType
==
TDMT_VND_FETCH_RSP
||
msgType
==
TDMT_VND_RES_READY_RSP
;
}
typedef
void
(
*
CB
)(
void
*
parent
,
SRpcMsg
*
pMsg
,
SEpSet
*
pEpSet
);
static
void
processContinueSend
(
void
*
parent
,
SRpcMsg
*
pMsg
,
SEpSet
*
pEpSet
);
...
...
@@ -86,10 +70,6 @@ class Client {
rpcClose
(
this
->
transCli
);
this
->
transCli
=
NULL
;
}
void
SetConstructFP
(
void
*
(
*
mfp
)(
void
*
parent
,
tmsg_t
msgType
))
{
rpcClose
(
this
->
transCli
);
this
->
transCli
=
rpcOpen
(
&
rpcInit_
);
}
void
SendAndRecv
(
SRpcMsg
*
req
,
SRpcMsg
*
resp
)
{
SEpSet
epSet
=
{
0
};
...
...
@@ -108,7 +88,6 @@ class Client {
SendAndRecv
(
req
,
resp
);
}
void
SendWithHandle
(
SRpcMsg
*
req
,
SRpcMsg
*
resp
)
{}
void
SemWait
()
{
tsem_wait
(
&
this
->
sem
);
}
void
SemPost
()
{
tsem_post
(
&
this
->
sem
);
}
void
Reset
()
{}
...
...
@@ -141,12 +120,17 @@ class Server {
this
->
transSrv
=
rpcOpen
(
&
this
->
rpcInit_
);
taosMsleep
(
1000
);
}
void
SetSrvContinueSend
(
CB
cb
)
{
this
->
Stop
();
rpcInit_
.
cfp
=
cb
;
this
->
Start
();
}
void
Stop
()
{
if
(
this
->
transSrv
==
NULL
)
return
;
rpcClose
(
this
->
transSrv
);
this
->
transSrv
=
NULL
;
}
void
SetSrv
Continue
Send
(
void
(
*
cfp
)(
void
*
parent
,
SRpcMsg
*
pMsg
,
SEpSet
*
pEpSet
))
{
void
SetSrvSend
(
void
(
*
cfp
)(
void
*
parent
,
SRpcMsg
*
pMsg
,
SEpSet
*
pEpSet
))
{
this
->
Stop
();
rpcInit_
.
cfp
=
cfp
;
this
->
Start
();
...
...
@@ -174,9 +158,6 @@ static void processReq(void *parent, SRpcMsg *pMsg, SEpSet *pEpSet) {
}
static
void
processContinueSend
(
void
*
parent
,
SRpcMsg
*
pMsg
,
SEpSet
*
pEpSet
)
{
for
(
int
i
=
0
;
i
<
9
;
i
++
)
{
rpcRefHandle
(
pMsg
->
handle
,
TAOS_CONN_SERVER
);
}
for
(
int
i
=
0
;
i
<
10
;
i
++
)
{
SRpcMsg
rpcMsg
=
{
0
};
rpcMsg
.
pCont
=
rpcMallocCont
(
100
);
...
...
@@ -238,10 +219,6 @@ class TransObj {
//
srv
->
Stop
();
}
void
SetCliMFp
(
void
*
(
*
mfp
)(
void
*
parent
,
tmsg_t
msgType
))
{
// do nothing
cli
->
SetConstructFP
(
mfp
);
}
// call when link broken, and notify query or fetch stop
void
SetSrvContinueSend
(
void
(
*
cfp
)(
void
*
parent
,
SRpcMsg
*
pMsg
,
SEpSet
*
pEpSet
))
{
///////
...
...
@@ -279,7 +256,7 @@ class TransEnv : public ::testing::Test {
};
TEST_F
(
TransEnv
,
01s
endAndRec
)
{
for
(
int
i
=
0
;
i
<
1
;
i
++
)
{
for
(
int
i
=
0
;
i
<
1
0
;
i
++
)
{
SRpcMsg
req
=
{
0
},
resp
=
{
0
};
req
.
msgType
=
0
;
req
.
pCont
=
rpcMallocCont
(
10
);
...
...
@@ -322,22 +299,33 @@ TEST_F(TransEnv, clientUserDefined) {
}
TEST_F
(
TransEnv
,
cliPersistHandle
)
{
// tr->SetCliPersistFp(cliPersistHandle);
SRpcMsg
resp
=
{
0
};
void
*
handle
=
NULL
;
for
(
int
i
=
0
;
i
<
10
;
i
++
)
{
SRpcMsg
req
=
{.
handle
=
resp
.
handle
,
.
persistHandle
=
1
};
req
.
msgType
=
1
;
req
.
pCont
=
rpcMallocCont
(
10
);
req
.
contLen
=
10
;
tr
->
cliSendAndRecv
(
&
req
,
&
resp
);
if
(
i
==
5
)
{
std
::
cout
<<
"stop server"
<<
std
::
endl
;
tr
->
StopSrv
();
}
if
(
i
>=
6
)
{
EXPECT_TRUE
(
resp
.
code
!=
0
);
}
// if (i == 5) {
// std::cout << "stop server" << std::endl;
// tr->StopSrv();
//}
// if (i >= 6) {
// EXPECT_TRUE(resp.code != 0);
//}
handle
=
resp
.
handle
;
}
rpcReleaseHandle
(
handle
,
TAOS_CONN_CLIENT
);
for
(
int
i
=
0
;
i
<
10
;
i
++
)
{
SRpcMsg
req
=
{
0
};
req
.
msgType
=
1
;
req
.
pCont
=
rpcMallocCont
(
10
);
req
.
contLen
=
10
;
tr
->
cliSendAndRecv
(
&
req
,
&
resp
);
}
taosMsleep
(
1000
);
//////////////////
}
...
...
@@ -425,11 +413,7 @@ TEST_F(TransEnv, cliPersistHandleExcept) {
TEST_F
(
TransEnv
,
multiCliPersistHandleExcept
)
{
// conn broken
}
TEST_F
(
TransEnv
,
queryExcept
)
{
// tr->SetSrvExceptFp(handleExcept);
// query and conn is broken
}
TEST_F
(
TransEnv
,
queryExcept
)
{}
TEST_F
(
TransEnv
,
noResp
)
{
SRpcMsg
resp
=
{
0
};
for
(
int
i
=
0
;
i
<
5
;
i
++
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录