Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
33cc6c28
T
TDengine
项目概览
taosdata
/
TDengine
接近 2 年 前同步成功
通知
1191
Star
22018
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看板
未验证
提交
33cc6c28
编写于
4月 28, 2022
作者:
dengyihao
提交者:
GitHub
4月 28, 2022
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #11971 from taosdata/feature/refator_retry
refactor(rpc): refactor rpc retry way
上级
c6162895
9af1206c
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
140 addition
and
9 deletion
+140
-9
source/libs/transport/inc/transComm.h
source/libs/transport/inc/transComm.h
+30
-0
source/libs/transport/src/transCli.c
source/libs/transport/src/transCli.c
+29
-9
source/libs/transport/src/transComm.c
source/libs/transport/src/transComm.c
+81
-0
未找到文件。
source/libs/transport/inc/transComm.h
浏览文件 @
33cc6c28
...
...
@@ -28,6 +28,7 @@ extern "C" {
#include "taoserror.h"
#include "tglobal.h"
#include "thash.h"
#include "theap.h"
#include "tidpool.h"
#include "tmd5.h"
#include "tmempool.h"
...
...
@@ -328,10 +329,39 @@ void transQueueClear(STransQueue* queue);
*/
void
transQueueDestroy
(
STransQueue
*
queue
);
/*
* delay queue based on uv loop and uv timer, and only used in retry
*/
typedef
struct
STaskArg
{
void
*
param1
;
void
*
param2
;
}
STaskArg
;
typedef
struct
SDelayTask
{
void
(
*
func
)(
void
*
arg
);
void
*
arg
;
uint64_t
execTime
;
HeapNode
node
;
}
SDelayTask
;
typedef
struct
SDelayQueue
{
uv_timer_t
*
timer
;
Heap
*
heap
;
uv_loop_t
*
loop
;
void
(
*
free
)(
void
*
arg
);
}
SDelayQueue
;
int
transCreateDelayQueue
(
uv_loop_t
*
loop
,
SDelayQueue
**
queue
);
void
transDestroyDelayQueue
(
SDelayQueue
*
queue
);
int
transPutTaskToDelayQueue
(
SDelayQueue
*
queue
,
void
(
*
func
)(
void
*
arg
),
void
*
arg
,
uint64_t
timeoutMs
);
/*
* init global func
*/
void
transThreadOnce
();
#ifdef __cplusplus
}
#endif
...
...
source/libs/transport/src/transCli.c
浏览文件 @
33cc6c28
...
...
@@ -60,10 +60,10 @@ typedef struct SCliThrdObj {
// msg queue
queue
msg
;
TdThreadMutex
msgMtx
;
uint64_t
nextTimeout
;
// next timeout
void
*
pTransInst
;
//
bool
quit
;
SDelayQueue
*
delayQueue
;
uint64_t
nextTimeout
;
// next timeout
void
*
pTransInst
;
//
bool
quit
;
}
SCliThrdObj
;
typedef
struct
SCliObj
{
...
...
@@ -837,12 +837,13 @@ static SCliThrdObj* createThrdObj() {
uv_loop_init
(
pThrd
->
loop
);
pThrd
->
asyncPool
=
transCreateAsyncPool
(
pThrd
->
loop
,
5
,
pThrd
,
cliAsyncCb
);
uv_timer_init
(
pThrd
->
loop
,
&
pThrd
->
timer
);
pThrd
->
timer
.
data
=
pThrd
;
pThrd
->
pool
=
createConnPool
(
4
);
transCreateDelayQueue
(
pThrd
->
loop
,
&
pThrd
->
delayQueue
);
pThrd
->
quit
=
false
;
return
pThrd
;
}
...
...
@@ -850,12 +851,13 @@ static void destroyThrdObj(SCliThrdObj* pThrd) {
if
(
pThrd
==
NULL
)
{
return
;
}
taosThreadJoin
(
pThrd
->
thread
,
NULL
);
CLI_RELEASE_UV
(
pThrd
->
loop
);
taosThreadMutexDestroy
(
&
pThrd
->
msgMtx
);
transDestroyAsyncPool
(
pThrd
->
asyncPool
);
uv_timer_stop
(
&
pThrd
->
timer
);
transDestroyDelayQueue
(
pThrd
->
delayQueue
);
taosMemoryFree
(
pThrd
->
loop
);
taosMemoryFree
(
pThrd
);
}
...
...
@@ -884,6 +886,16 @@ int cliRBChoseIdx(STrans* pTransInst) {
}
return
index
%
pTransInst
->
numOfThreads
;
}
static
void
doDelayTask
(
void
*
param
)
{
STaskArg
*
arg
=
param
;
SCliMsg
*
pMsg
=
arg
->
param1
;
SCliThrdObj
*
pThrd
=
arg
->
param2
;
cliHandleReq
(
pMsg
,
pThrd
);
taosMemoryFree
(
arg
);
}
int
cliAppCb
(
SCliConn
*
pConn
,
STransMsg
*
pResp
,
SCliMsg
*
pMsg
)
{
SCliThrdObj
*
pThrd
=
pConn
->
hostThrd
;
STrans
*
pTransInst
=
pThrd
->
pTransInst
;
...
...
@@ -907,7 +919,12 @@ int cliAppCb(SCliConn* pConn, STransMsg* pResp, SCliMsg* pMsg) {
if
(
msgType
==
TDMT_MND_CONNECT
&&
pResp
->
code
==
TSDB_CODE_RPC_NETWORK_UNAVAIL
)
{
if
(
pCtx
->
retryCount
<
pEpSet
->
numOfEps
)
{
pEpSet
->
inUse
=
(
++
pEpSet
->
inUse
)
%
pEpSet
->
numOfEps
;
cliHandleReq
(
pMsg
,
pThrd
);
STaskArg
*
arg
=
taosMemoryMalloc
(
sizeof
(
STaskArg
));
arg
->
param1
=
pMsg
;
arg
->
param2
=
pThrd
;
transPutTaskToDelayQueue
(
pThrd
->
delayQueue
,
doDelayTask
,
arg
,
TRANS_RETRY_INTERVAL
);
cliDestroy
((
uv_handle_t
*
)
pConn
->
stream
);
return
-
1
;
}
...
...
@@ -919,8 +936,11 @@ int cliAppCb(SCliConn* pConn, STransMsg* pResp, SCliMsg* pMsg) {
tDeserializeSMEpSet
(
pResp
->
pCont
,
pResp
->
contLen
,
&
emsg
);
pCtx
->
epSet
=
emsg
.
epSet
;
}
cliHandleReq
(
pMsg
,
pThrd
);
// release pConn
STaskArg
*
arg
=
taosMemoryMalloc
(
sizeof
(
STaskArg
));
arg
->
param1
=
pMsg
;
arg
->
param2
=
pThrd
;
transPutTaskToDelayQueue
(
pThrd
->
delayQueue
,
doDelayTask
,
arg
,
TRANS_RETRY_INTERVAL
);
addConnToPool
(
pThrd
,
pConn
);
return
-
1
;
}
...
...
source/libs/transport/src/transComm.c
浏览文件 @
33cc6c28
...
...
@@ -358,4 +358,85 @@ void transQueueDestroy(STransQueue* queue) {
transQueueClear
(
queue
);
taosArrayDestroy
(
queue
->
q
);
}
static
int32_t
timeCompare
(
const
HeapNode
*
a
,
const
HeapNode
*
b
)
{
SDelayTask
*
arg1
=
container_of
(
a
,
SDelayTask
,
node
);
SDelayTask
*
arg2
=
container_of
(
b
,
SDelayTask
,
node
);
if
(
arg1
->
execTime
>
arg2
->
execTime
)
{
return
0
;
}
else
{
return
1
;
}
}
static
void
transDelayQueueTimeout
(
uv_timer_t
*
timer
)
{
SDelayQueue
*
queue
=
timer
->
data
;
tTrace
(
"timer %p timeout"
,
timer
);
uint64_t
timeout
=
0
;
do
{
HeapNode
*
minNode
=
heapMin
(
queue
->
heap
);
if
(
minNode
==
NULL
)
break
;
SDelayTask
*
task
=
container_of
(
minNode
,
SDelayTask
,
node
);
if
(
task
->
execTime
<=
taosGetTimestampMs
())
{
heapRemove
(
queue
->
heap
,
minNode
);
task
->
func
(
task
->
arg
);
taosMemoryFree
(
task
);
timeout
=
0
;
}
else
{
timeout
=
task
->
execTime
-
taosGetTimestampMs
();
break
;
}
}
while
(
1
);
if
(
timeout
!=
0
)
{
uv_timer_start
(
queue
->
timer
,
transDelayQueueTimeout
,
timeout
,
0
);
}
}
int
transCreateDelayQueue
(
uv_loop_t
*
loop
,
SDelayQueue
**
queue
)
{
uv_timer_t
*
timer
=
taosMemoryCalloc
(
1
,
sizeof
(
uv_timer_t
));
uv_timer_init
(
loop
,
timer
);
Heap
*
heap
=
heapCreate
(
timeCompare
);
SDelayQueue
*
q
=
taosMemoryCalloc
(
1
,
sizeof
(
SDelayQueue
));
q
->
heap
=
heap
;
q
->
timer
=
timer
;
q
->
loop
=
loop
;
q
->
timer
->
data
=
q
;
*
queue
=
q
;
return
0
;
}
void
transDestroyDelayQueue
(
SDelayQueue
*
queue
)
{
taosMemoryFree
(
queue
->
timer
);
while
(
heapSize
(
queue
->
heap
)
>
0
)
{
HeapNode
*
minNode
=
heapMin
(
queue
->
heap
);
if
(
minNode
==
NULL
)
{
return
;
}
heapRemove
(
queue
->
heap
,
minNode
);
SDelayTask
*
task
=
container_of
(
minNode
,
SDelayTask
,
node
);
taosMemoryFree
(
task
);
}
heapDestroy
(
queue
->
heap
);
taosMemoryFree
(
queue
);
}
int
transPutTaskToDelayQueue
(
SDelayQueue
*
queue
,
void
(
*
func
)(
void
*
arg
),
void
*
arg
,
uint64_t
timeoutMs
)
{
SDelayTask
*
task
=
taosMemoryCalloc
(
1
,
sizeof
(
SDelayTask
));
task
->
func
=
func
;
task
->
arg
=
arg
;
task
->
execTime
=
taosGetTimestampMs
()
+
timeoutMs
;
tTrace
(
"timer %p put task into queue, timeoutMs: %"
PRIu64
""
,
queue
->
timer
,
timeoutMs
);
heapInsert
(
queue
->
heap
,
&
task
->
node
);
if
(
heapSize
(
queue
->
heap
)
==
1
)
{
uv_timer_start
(
queue
->
timer
,
transDelayQueueTimeout
,
timeoutMs
,
0
);
}
return
0
;
}
#endif
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录