Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
d8f72ec0
TDengine
项目概览
taosdata
/
TDengine
12 个月 前同步成功
通知
1180
Star
22014
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看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
d8f72ec0
编写于
12月 02, 2022
作者:
S
Shengliang Guan
提交者:
GitHub
12月 02, 2022
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #18611 from taosdata/enh/refatorRetry
enh: refactor retry code
上级
8efb45ff
3378ff0f
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
33 addition
and
15 deletion
+33
-15
source/libs/transport/inc/transComm.h
source/libs/transport/inc/transComm.h
+2
-2
source/libs/transport/src/transCli.c
source/libs/transport/src/transCli.c
+31
-13
未找到文件。
source/libs/transport/inc/transComm.h
浏览文件 @
d8f72ec0
...
@@ -151,8 +151,8 @@ typedef struct {
...
@@ -151,8 +151,8 @@ typedef struct {
int64_t
retryNextInterval
;
int64_t
retryNextInterval
;
bool
retryInit
;
bool
retryInit
;
int32_t
retryStep
;
int32_t
retryStep
;
int8_t
epsetRetryCnt
;
int
8_t
epsetRetryCnt
;
int
32_t
retryCode
;
int
hThrdIdx
;
int
hThrdIdx
;
}
STransConnCtx
;
}
STransConnCtx
;
...
...
source/libs/transport/src/transCli.c
浏览文件 @
d8f72ec0
...
@@ -1020,7 +1020,6 @@ void cliHandleReq(SCliMsg* pMsg, SCliThrd* pThrd) {
...
@@ -1020,7 +1020,6 @@ void cliHandleReq(SCliMsg* pMsg, SCliThrd* pThrd) {
char
tbuf
[
256
]
=
{
0
};
char
tbuf
[
256
]
=
{
0
};
EPSET_DEBUG_STR
(
&
pCtx
->
epSet
,
tbuf
);
EPSET_DEBUG_STR
(
&
pCtx
->
epSet
,
tbuf
);
tDebug
(
"current epset %s"
,
tbuf
);
if
(
!
EPSET_IS_VALID
(
&
pCtx
->
epSet
))
{
if
(
!
EPSET_IS_VALID
(
&
pCtx
->
epSet
))
{
tError
(
"invalid epset"
);
tError
(
"invalid epset"
);
...
@@ -1500,34 +1499,46 @@ bool cliGenRetryRule(SCliConn* pConn, STransMsg* pResp, SCliMsg* pMsg) {
...
@@ -1500,34 +1499,46 @@ bool cliGenRetryRule(SCliConn* pConn, STransMsg* pResp, SCliMsg* pMsg) {
pCtx
->
retryNextInterval
=
pCtx
->
retryMinInterval
;
pCtx
->
retryNextInterval
=
pCtx
->
retryMinInterval
;
pCtx
->
retryStep
=
0
;
pCtx
->
retryStep
=
0
;
pCtx
->
retryInit
=
true
;
pCtx
->
retryInit
=
true
;
pCtx
->
retryCode
=
TSDB_CODE_SUCCESS
;
}
}
if
(
-
1
!=
pCtx
->
retryMaxTimeout
&&
taosGetTimestampMs
()
-
pCtx
->
retryInitTimestamp
>=
pCtx
->
retryMaxTimeout
)
{
if
(
-
1
!=
pCtx
->
retryMaxTimeout
&&
taosGetTimestampMs
()
-
pCtx
->
retryInitTimestamp
>=
pCtx
->
retryMaxTimeout
)
{
return
false
;
return
false
;
}
}
// code, msgType
// A: epset, leader, not self
// B: epset, not know leader
// C: no epset, leader but not serivce
bool
noDelay
=
false
;
bool
noDelay
=
false
;
if
(
code
==
TSDB_CODE_RPC_BROKEN_LINK
||
code
==
TSDB_CODE_RPC_NETWORK_UNAVAIL
)
{
if
(
code
==
TSDB_CODE_RPC_BROKEN_LINK
||
code
==
TSDB_CODE_RPC_NETWORK_UNAVAIL
)
{
t
Debug
(
"code str %s, contlen:%d 0"
,
tstrerror
(
code
),
pResp
->
contLen
);
t
Trace
(
"code str %s, contlen:%d 0"
,
tstrerror
(
code
),
pResp
->
contLen
);
noDelay
=
cliResetEpset
(
pCtx
,
pResp
,
false
);
noDelay
=
cliResetEpset
(
pCtx
,
pResp
,
false
);
transFreeMsg
(
pResp
->
pCont
);
transFreeMsg
(
pResp
->
pCont
);
transUnrefCliHandle
(
pConn
);
transUnrefCliHandle
(
pConn
);
}
else
if
(
code
==
TSDB_CODE_SYN_NOT_LEADER
||
code
==
TSDB_CODE_SYN_INTERNAL_ERROR
||
}
else
if
(
code
==
TSDB_CODE_SYN_NOT_LEADER
||
code
==
TSDB_CODE_SYN_INTERNAL_ERROR
||
code
==
TSDB_CODE_SYN_PROPOSE_NOT_READY
||
code
==
TSDB_CODE_RPC_REDIRECT
)
{
code
==
TSDB_CODE_SYN_PROPOSE_NOT_READY
||
code
==
TSDB_CODE_RPC_REDIRECT
)
{
t
Debug
(
"code str %s, contlen:%d 1"
,
tstrerror
(
code
),
pResp
->
contLen
);
t
Trace
(
"code str %s, contlen:%d 1"
,
tstrerror
(
code
),
pResp
->
contLen
);
noDelay
=
cliResetEpset
(
pCtx
,
pResp
,
true
);
noDelay
=
cliResetEpset
(
pCtx
,
pResp
,
true
);
transFreeMsg
(
pResp
->
pCont
);
transFreeMsg
(
pResp
->
pCont
);
addConnToPool
(
pThrd
->
pool
,
pConn
);
addConnToPool
(
pThrd
->
pool
,
pConn
);
}
else
if
(
code
==
TSDB_CODE_SYN_RESTORING
)
{
}
else
if
(
code
==
TSDB_CODE_SYN_RESTORING
)
{
t
Debug
(
"code str %s, contlen:%d 0"
,
tstrerror
(
code
),
pResp
->
contLen
);
t
Trace
(
"code str %s, contlen:%d 0"
,
tstrerror
(
code
),
pResp
->
contLen
);
noDelay
=
cliResetEpset
(
pCtx
,
pResp
,
false
);
noDelay
=
cliResetEpset
(
pCtx
,
pResp
,
false
);
addConnToPool
(
pThrd
->
pool
,
pConn
);
addConnToPool
(
pThrd
->
pool
,
pConn
);
transFreeMsg
(
pResp
->
pCont
);
transFreeMsg
(
pResp
->
pCont
);
}
else
{
}
else
{
t
Debug
(
"code str %s, contlen:%d 0"
,
tstrerror
(
code
),
pResp
->
contLen
);
t
Trace
(
"code str %s, contlen:%d 0"
,
tstrerror
(
code
),
pResp
->
contLen
);
noDelay
=
cliResetEpset
(
pCtx
,
pResp
,
false
);
noDelay
=
cliResetEpset
(
pCtx
,
pResp
,
false
);
addConnToPool
(
pThrd
->
pool
,
pConn
);
addConnToPool
(
pThrd
->
pool
,
pConn
);
transFreeMsg
(
pResp
->
pCont
);
transFreeMsg
(
pResp
->
pCont
);
}
}
if
(
code
!=
TSDB_CODE_RPC_BROKEN_LINK
&&
code
!=
TSDB_CODE_RPC_NETWORK_UNAVAIL
&&
code
!=
TSDB_CODE_SUCCESS
)
{
// save one internal code
pCtx
->
retryCode
=
code
;
}
if
(
noDelay
==
false
)
{
if
(
noDelay
==
false
)
{
pCtx
->
epsetRetryCnt
=
1
;
pCtx
->
epsetRetryCnt
=
1
;
...
@@ -1556,29 +1567,36 @@ int cliAppCb(SCliConn* pConn, STransMsg* pResp, SCliMsg* pMsg) {
...
@@ -1556,29 +1567,36 @@ int cliAppCb(SCliConn* pConn, STransMsg* pResp, SCliMsg* pMsg) {
STrans
*
pTransInst
=
pThrd
->
pTransInst
;
STrans
*
pTransInst
=
pThrd
->
pTransInst
;
if
(
pMsg
==
NULL
||
pMsg
->
ctx
==
NULL
)
{
if
(
pMsg
==
NULL
||
pMsg
->
ctx
==
NULL
)
{
t
Debug
(
"%s conn %p handle resp"
,
pTransInst
->
label
,
pConn
);
t
Trace
(
"%s conn %p handle resp"
,
pTransInst
->
label
,
pConn
);
pTransInst
->
cfp
(
pTransInst
->
parent
,
pResp
,
NULL
);
pTransInst
->
cfp
(
pTransInst
->
parent
,
pResp
,
NULL
);
return
0
;
return
0
;
}
}
STransConnCtx
*
pCtx
=
pMsg
->
ctx
;
STransConnCtx
*
pCtx
=
pMsg
->
ctx
;
int32_t
code
=
pResp
->
code
;
bool
retry
=
cliGenRetryRule
(
pConn
,
pResp
,
pMsg
);
bool
retry
=
cliGenRetryRule
(
pConn
,
pResp
,
pMsg
);
if
(
retry
==
true
)
{
if
(
retry
==
true
)
{
return
-
1
;
return
-
1
;
}
}
STraceId
*
trace
=
&
pResp
->
info
.
traceId
;
bool
hasEpSet
=
cliTryExtractEpSet
(
pResp
,
&
pCtx
->
epSet
);
if
(
pCtx
->
retryCode
!=
TSDB_CODE_SUCCESS
)
{
int32_t
code
=
pResp
->
code
;
// return internal code app
if
(
code
==
TSDB_CODE_RPC_NETWORK_UNAVAIL
||
code
==
TSDB_CODE_RPC_BROKEN_LINK
)
{
pResp
->
code
=
pCtx
->
retryCode
;
}
}
STraceId
*
trace
=
&
pResp
->
info
.
traceId
;
bool
hasEpSet
=
cliTryExtractEpSet
(
pResp
,
&
pCtx
->
epSet
);
if
(
hasEpSet
)
{
if
(
hasEpSet
)
{
char
tbuf
[
256
]
=
{
0
};
char
tbuf
[
256
]
=
{
0
};
EPSET_DEBUG_STR
(
&
pCtx
->
epSet
,
tbuf
);
EPSET_DEBUG_STR
(
&
pCtx
->
epSet
,
tbuf
);
tG
Debug
(
"%s conn %p extract epset from msg"
,
CONN_GET_INST_LABEL
(
pConn
),
pConn
);
tG
Trace
(
"%s conn %p extract epset from msg"
,
CONN_GET_INST_LABEL
(
pConn
),
pConn
);
}
}
if
(
pCtx
->
pSem
!=
NULL
)
{
if
(
pCtx
->
pSem
!=
NULL
)
{
tG
Debug
(
"%s conn %p(sync) handle resp"
,
CONN_GET_INST_LABEL
(
pConn
),
pConn
);
tG
Trace
(
"%s conn %p(sync) handle resp"
,
CONN_GET_INST_LABEL
(
pConn
),
pConn
);
if
(
pCtx
->
pRsp
==
NULL
)
{
if
(
pCtx
->
pRsp
==
NULL
)
{
tGTrace
(
"%s conn %p(sync) failed to resp, ignore"
,
CONN_GET_INST_LABEL
(
pConn
),
pConn
);
tGTrace
(
"%s conn %p(sync) failed to resp, ignore"
,
CONN_GET_INST_LABEL
(
pConn
),
pConn
);
}
else
{
}
else
{
...
@@ -1587,11 +1605,11 @@ int cliAppCb(SCliConn* pConn, STransMsg* pResp, SCliMsg* pMsg) {
...
@@ -1587,11 +1605,11 @@ int cliAppCb(SCliConn* pConn, STransMsg* pResp, SCliMsg* pMsg) {
tsem_post
(
pCtx
->
pSem
);
tsem_post
(
pCtx
->
pSem
);
pCtx
->
pRsp
=
NULL
;
pCtx
->
pRsp
=
NULL
;
}
else
{
}
else
{
tG
Debug
(
"%s conn %p handle resp"
,
CONN_GET_INST_LABEL
(
pConn
),
pConn
);
tG
Trace
(
"%s conn %p handle resp"
,
CONN_GET_INST_LABEL
(
pConn
),
pConn
);
if
(
retry
==
false
&&
hasEpSet
==
true
)
{
if
(
retry
==
false
&&
hasEpSet
==
true
)
{
pTransInst
->
cfp
(
pTransInst
->
parent
,
pResp
,
&
pCtx
->
epSet
);
pTransInst
->
cfp
(
pTransInst
->
parent
,
pResp
,
&
pCtx
->
epSet
);
}
else
{
}
else
{
if
(
!
cliIsEpsetUpdated
(
code
,
pCtx
))
{
if
(
!
cliIsEpsetUpdated
(
pResp
->
code
,
pCtx
))
{
pTransInst
->
cfp
(
pTransInst
->
parent
,
pResp
,
NULL
);
pTransInst
->
cfp
(
pTransInst
->
parent
,
pResp
,
NULL
);
}
else
{
}
else
{
pTransInst
->
cfp
(
pTransInst
->
parent
,
pResp
,
&
pCtx
->
epSet
);
pTransInst
->
cfp
(
pTransInst
->
parent
,
pResp
,
&
pCtx
->
epSet
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录