Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
哥们要飞
TDengine
提交
4c60448b
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,发现更多精彩内容 >>
提交
4c60448b
编写于
3月 27, 2020
作者:
陶建辉(Jeff)
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix the bug for code
add the code to handle idle timer
上级
eabc5511
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
68 addition
and
38 deletion
+68
-38
src/rpc/src/rpcMain.c
src/rpc/src/rpcMain.c
+55
-15
src/rpc/test/rserver.c
src/rpc/test/rserver.c
+13
-23
未找到文件。
src/rpc/src/rpcMain.c
浏览文件 @
4c60448b
...
...
@@ -182,6 +182,7 @@ static void rpcSendReqToServer(SRpcInfo *pRpc, SRpcReqContext *pContext);
static
void
rpcSendQuickRsp
(
SRpcConn
*
pConn
,
int32_t
code
);
static
void
rpcSendErrorMsgToPeer
(
SRecvInfo
*
pRecv
,
int32_t
code
);
static
void
rpcSendMsgToPeer
(
SRpcConn
*
pConn
,
void
*
data
,
int
dataLen
);
static
void
rpcSendReqHead
(
SRpcConn
*
pConn
);
static
void
*
rpcProcessMsgFromPeer
(
SRecvInfo
*
pRecv
);
static
void
rpcProcessIncomingMsg
(
SRpcConn
*
pConn
,
SRpcHead
*
pHead
);
...
...
@@ -412,12 +413,12 @@ void rpcSendResponse(SRpcMsg *pMsg) {
rpcFreeMsg
(
pConn
->
pRspMsg
);
pConn
->
pRspMsg
=
msg
;
pConn
->
rspMsgLen
=
msgLen
;
if
(
p
Head
->
content
[
0
]
==
TSDB_CODE_ACTION_IN_PROGRESS
)
pConn
->
inTranId
--
;
if
(
p
Msg
->
code
==
TSDB_CODE_ACTION_IN_PROGRESS
)
pConn
->
inTranId
--
;
rpcUnlockConn
(
pConn
);
taosTmrStopA
(
&
pConn
->
pTimer
);
taosTmrReset
(
rpcProcessIdleTimer
,
pRpc
->
idleTime
,
pConn
,
pRpc
->
tmrCtrl
,
&
pConn
->
pIdleTimer
);
//
taosTmrReset(rpcProcessIdleTimer, pRpc->idleTime, pConn, pRpc->tmrCtrl, &pConn->pIdleTimer);
rpcSendMsgToPeer
(
pConn
,
msg
,
msgLen
);
pConn
->
secured
=
1
;
// connection shall be secured
...
...
@@ -653,8 +654,12 @@ static int rpcProcessReqHead(SRpcConn *pConn, SRpcHead *pHead) {
if
(
pConn
->
inTranId
==
pHead
->
tranId
)
{
if
(
pConn
->
inType
==
pHead
->
msgType
)
{
tTrace
(
"%s %p, %s is retransmitted"
,
pRpc
->
label
,
pConn
,
taosMsg
[
pHead
->
msgType
]);
rpcSendQuickRsp
(
pConn
,
TSDB_CODE_ACTION_IN_PROGRESS
);
if
(
pHead
->
code
==
0
)
{
tTrace
(
"%s %p, %s is retransmitted"
,
pRpc
->
label
,
pConn
,
taosMsg
[
pHead
->
msgType
]);
rpcSendQuickRsp
(
pConn
,
TSDB_CODE_ACTION_IN_PROGRESS
);
}
else
{
// do nothing, it is heart beat from client
}
}
else
if
(
pConn
->
inType
==
0
)
{
tTrace
(
"%s %p, %s is already processed, tranId:%d"
,
pRpc
->
label
,
pConn
,
taosMsg
[
pHead
->
msgType
],
pConn
->
inTranId
);
...
...
@@ -695,22 +700,23 @@ static int rpcProcessRspHead(SRpcConn *pConn, SRpcHead *pHead) {
return
TSDB_CODE_INVALID_RESPONSE_TYPE
;
}
if
(
*
pHead
->
content
==
TSDB_CODE_NOT_READY
)
{
if
(
pHead
->
code
==
TSDB_CODE_NOT_READY
)
{
return
TSDB_CODE_ALREADY_PROCESSED
;
}
taosTmrStopA
(
&
pConn
->
pTimer
);
pConn
->
retry
=
0
;
if
(
*
pHead
->
content
==
TSDB_CODE_ACTION_IN_PROGRESS
)
{
if
(
pHead
->
code
==
TSDB_CODE_ACTION_IN_PROGRESS
)
{
if
(
pConn
->
tretry
<=
tsRpcMaxRetry
)
{
pConn
->
tretry
++
;
tTrace
(
"%s %p, peer is still processing the transaction"
,
pRpc
->
label
,
pConn
);
taosTmrReset
(
rpcProcessRetryTimer
,
tsRpcProgressTime
,
pConn
,
pRpc
->
tmrCtrl
,
&
pConn
->
pTimer
);
pConn
->
tretry
++
;
rpcSendReqHead
(
pConn
);
taosTmrReset
(
rpcProcessRetryTimer
,
tsRpcTimer
,
pConn
,
pRpc
->
tmrCtrl
,
&
pConn
->
pTimer
);
return
TSDB_CODE_ALREADY_PROCESSED
;
}
else
{
// peer still in processing, give up
*
pHead
->
content
=
TSDB_CODE_TOO_SLOW
;
return
TSDB_CODE_TOO_SLOW
;
}
}
...
...
@@ -771,6 +777,7 @@ static SRpcConn *rpcProcessMsgHead(SRpcInfo *pRpc, SRecvInfo *pRecv) {
if
(
rpcIsReq
(
pHead
->
msgType
)
)
{
terrno
=
rpcProcessReqHead
(
pConn
,
pHead
);
pConn
->
connType
=
pRecv
->
connType
;
taosTmrReset
(
rpcProcessIdleTimer
,
pRpc
->
idleTime
,
pConn
,
pRpc
->
tmrCtrl
,
&
pConn
->
pIdleTimer
);
}
else
{
terrno
=
rpcProcessRspHead
(
pConn
,
pHead
);
}
...
...
@@ -816,7 +823,7 @@ static void *rpcProcessMsgFromPeer(SRecvInfo *pRecv) {
pConn
=
rpcProcessMsgHead
(
pRpc
,
pRecv
);
if
(
pHead
->
msgType
<
TSDB_MSG_TYPE_CM_HEARTBEAT
||
(
rpcDebugFlag
&
16
))
{
tTrace
(
"%s %p, %s received from 0x%x:%hu, parse code:%x len:%d sig:0x%08x:0x%08x:%d"
,
tTrace
(
"%s %p, %s received from 0x%x:%hu, parse code:
0x
%x len:%d sig:0x%08x:0x%08x:%d"
,
pRpc
->
label
,
pConn
,
taosMsg
[
pHead
->
msgType
],
pRecv
->
ip
,
pRecv
->
port
,
terrno
,
pRecv
->
msgLen
,
pHead
->
sourceId
,
pHead
->
destId
,
pHead
->
tranId
,
pHead
->
port
);
}
...
...
@@ -825,7 +832,7 @@ static void *rpcProcessMsgFromPeer(SRecvInfo *pRecv) {
if
(
terrno
!=
0
)
{
// parsing error
if
(
rpcIsReq
(
pHead
->
msgType
)
)
{
rpcSendErrorMsgToPeer
(
pRecv
,
terrno
);
tTrace
(
"%s %p, %s is sent with error code:%x"
,
pRpc
->
label
,
pConn
,
taosMsg
[
pHead
->
msgType
+
1
],
terrno
);
tTrace
(
"%s %p, %s is sent with error code:
0x
%x"
,
pRpc
->
label
,
pConn
,
taosMsg
[
pHead
->
msgType
+
1
],
terrno
);
}
}
else
{
// parsing OK
rpcProcessIncomingMsg
(
pConn
,
pHead
);
...
...
@@ -885,7 +892,7 @@ static void rpcSendQuickRsp(SRpcConn *pConn, int32_t code) {
pHead
=
(
SRpcHead
*
)
msg
;
pHead
->
version
=
1
;
pHead
->
msgType
=
pConn
->
inType
+
1
;
pHead
->
spi
=
0
;
pHead
->
spi
=
pConn
->
spi
;
pHead
->
encrypt
=
0
;
pHead
->
tranId
=
pConn
->
inTranId
;
pHead
->
sourceId
=
pConn
->
ownId
;
...
...
@@ -894,7 +901,29 @@ static void rpcSendQuickRsp(SRpcConn *pConn, int32_t code) {
memcpy
(
pHead
->
user
,
pConn
->
user
,
tListLen
(
pHead
->
user
));
pHead
->
code
=
htonl
(
code
);
rpcSendMsgToPeer
(
pConn
,
msg
,
0
);
rpcSendMsgToPeer
(
pConn
,
msg
,
sizeof
(
SRpcHead
));
pConn
->
secured
=
1
;
// connection shall be secured
}
static
void
rpcSendReqHead
(
SRpcConn
*
pConn
)
{
char
msg
[
RPC_MSG_OVERHEAD
];
SRpcHead
*
pHead
;
// set msg header
memset
(
msg
,
0
,
sizeof
(
SRpcHead
));
pHead
=
(
SRpcHead
*
)
msg
;
pHead
->
version
=
1
;
pHead
->
msgType
=
pConn
->
outType
;
pHead
->
spi
=
pConn
->
spi
;
pHead
->
encrypt
=
0
;
pHead
->
tranId
=
pConn
->
outTranId
;
pHead
->
sourceId
=
pConn
->
ownId
;
pHead
->
destId
=
pConn
->
peerId
;
pHead
->
linkUid
=
pConn
->
linkUid
;
memcpy
(
pHead
->
user
,
pConn
->
user
,
tListLen
(
pHead
->
user
));
pHead
->
code
=
1
;
rpcSendMsgToPeer
(
pConn
,
msg
,
sizeof
(
SRpcHead
));
}
static
void
rpcSendErrorMsgToPeer
(
SRecvInfo
*
pRecv
,
int32_t
code
)
{
...
...
@@ -990,9 +1019,9 @@ static void rpcSendMsgToPeer(SRpcConn *pConn, void *msg, int msgLen) {
pConn
->
peerPort
,
msgLen
,
pHead
->
sourceId
,
pHead
->
destId
,
pHead
->
tranId
);
}
else
{
if
(
pHead
->
msgType
<
TSDB_MSG_TYPE_CM_HEARTBEAT
||
(
rpcDebugFlag
&
16
))
tTrace
(
"%s %p, %s is sent to %s:%hu, code:
%u
len:%d sig:0x%08x:0x%08x:%d"
,
tTrace
(
"%s %p, %s is sent to %s:%hu, code:
0x%x
len:%d sig:0x%08x:0x%08x:%d"
,
pRpc
->
label
,
pConn
,
taosMsg
[
pHead
->
msgType
],
pConn
->
peerIpstr
,
pConn
->
peerPort
,
(
uint8_t
)
pHead
->
content
[
0
]
,
msgLen
,
pHead
->
sourceId
,
pHead
->
destId
,
pHead
->
tranId
);
pHead
->
code
,
msgLen
,
pHead
->
sourceId
,
pHead
->
destId
,
pHead
->
tranId
);
}
writtenLen
=
(
*
taosSendData
[
pConn
->
connType
])(
pConn
->
peerIp
,
pConn
->
peerPort
,
pHead
,
msgLen
,
pConn
->
chandle
);
...
...
@@ -1070,6 +1099,17 @@ static void rpcProcessIdleTimer(void *param, void *tmrId) {
if
(
pConn
->
user
[
0
])
{
tTrace
(
"%s %p, close the connection since no activity"
,
pRpc
->
label
,
pConn
);
if
(
pConn
->
inType
&&
pRpc
->
cfp
)
{
// if there are pending request, notify the app
tTrace
(
"%s %p, notify the app, connection is gone"
,
pRpc
->
label
,
pConn
);
SRpcMsg
rpcMsg
;
rpcMsg
.
pCont
=
NULL
;
rpcMsg
.
contLen
=
0
;
rpcMsg
.
handle
=
pConn
;
rpcMsg
.
msgType
=
pConn
->
inType
;
rpcMsg
.
code
=
TSDB_CODE_NETWORK_UNAVAIL
;
(
*
(
pRpc
->
cfp
))(
&
rpcMsg
);
}
rpcCloseConn
(
pConn
);
}
else
{
tTrace
(
"%s %p, idle timer:%p not processed"
,
pRpc
->
label
,
pConn
,
tmrId
);
...
...
src/rpc/test/rserver.c
浏览文件 @
4c60448b
...
...
@@ -28,25 +28,23 @@ void *qhandle = NULL;
void
processShellMsg
()
{
static
int
num
=
0
;
taos_qall
qall
;
SRpcMsg
*
pRpcMsg
,
rpcMsg
;
int
type
;
qall
=
taosAllocateQall
();
SRpcMsg
rpcMsg
;
while
(
1
)
{
int
numOfMsgs
=
taosReadAllQitems
(
qhandle
,
qall
);
int
numOfMsgs
=
taosReadAllQitems
(
qhandle
,
&
qall
);
if
(
numOfMsgs
<=
0
)
{
usleep
(
1000
);
continue
;
}
tTrace
(
"%d shell msgs are received"
,
numOfMsgs
);
sleep
(
5
);
for
(
int
i
=
0
;
i
<
numOfMsgs
;
++
i
)
{
taosGetQitem
(
qall
,
&
type
,
(
void
**
)
&
pR
pcMsg
);
taosGetQitem
(
qall
,
&
r
pcMsg
);
if
(
dataFd
>=
0
)
{
if
(
write
(
dataFd
,
pRpcMsg
->
pCont
,
pRpcMsg
->
contLen
)
<
0
)
{
if
(
write
(
dataFd
,
rpcMsg
.
pCont
,
rpcMsg
.
contLen
)
<
0
)
{
tPrint
(
"failed to write data file, reason:%s"
,
strerror
(
errno
));
}
}
...
...
@@ -65,22 +63,19 @@ void processShellMsg() {
taosResetQitems
(
qall
);
for
(
int
i
=
0
;
i
<
numOfMsgs
;
++
i
)
{
taosGetQitem
(
qall
,
&
rpcMsg
);
taosGetQitem
(
qall
,
&
type
,
(
void
**
)
&
pRpcMsg
);
rpcFreeCont
(
pRpcMsg
->
pCont
);
rpcFreeCont
(
rpcMsg
.
pCont
);
rpcMsg
.
pCont
=
rpcMallocCont
(
msgSize
);
rpcMsg
.
contLen
=
msgSize
;
rpcMsg
.
handle
=
pRpcMsg
->
handle
;
rpcMsg
.
handle
=
rpcMsg
.
handle
;
rpcMsg
.
code
=
1
;
rpcSendResponse
(
&
rpcMsg
);
taosFreeQitem
(
pRpcMsg
);
}
taosFreeQitems
(
qall
);
}
taosFreeQall
(
qall
);
/*
SRpcIpSet ipSet;
ipSet.numOfIps = 1;
...
...
@@ -114,21 +109,17 @@ int retrieveAuthInfo(char *meterId, char *spi, char *encrypt, char *secret, char
}
void
processRequestMsg
(
SRpcMsg
*
pMsg
)
{
SRpcMsg
*
pTemp
;
pTemp
=
taosAllocateQitem
(
sizeof
(
SRpcMsg
));
memcpy
(
pTemp
,
pMsg
,
sizeof
(
SRpcMsg
));
tTrace
(
"request is received, type:%d, contLen:%d, item:%p"
,
pMsg
->
msgType
,
pMsg
->
contLen
,
pTemp
);
taosWriteQitem
(
qhandle
,
TAOS_QTYPE_RPC
,
pTemp
);
tTrace
(
"request is received, type:%d, contLen:%d"
,
pMsg
->
msgType
,
pMsg
->
contLen
);
taosWriteQitem
(
qhandle
,
pMsg
);
}
int
main
(
int
argc
,
char
*
argv
[])
{
SRpcInit
rpcInit
;
char
dataName
[
20
]
=
"server.data"
;
char
localIp
[
40
]
=
"0.0.0.0"
;
memset
(
&
rpcInit
,
0
,
sizeof
(
rpcInit
));
rpcInit
.
localIp
=
"0.0.0.0"
;
rpcInit
.
localIp
=
localIp
;
rpcInit
.
localPort
=
7000
;
rpcInit
.
label
=
"SER"
;
rpcInit
.
numOfThreads
=
1
;
...
...
@@ -154,7 +145,6 @@ int main(int argc, char *argv[]) {
commit
=
atoi
(
argv
[
++
i
]);
}
else
if
(
strcmp
(
argv
[
i
],
"-d"
)
==
0
&&
i
<
argc
-
1
)
{
rpcDebugFlag
=
atoi
(
argv
[
++
i
]);
ddebugFlag
=
rpcDebugFlag
;
uDebugFlag
=
rpcDebugFlag
;
}
else
{
printf
(
"
\n
usage: %s [options]
\n
"
,
argv
[
0
]);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录