Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
7bdafa5f
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看板
未验证
提交
7bdafa5f
编写于
11月 16, 2022
作者:
S
Shengliang Guan
提交者:
GitHub
11月 16, 2022
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #18199 from taosdata/fix/TD-20439
fix(sync): fix timer memory leak
上级
a68f42f5
12f70227
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
28 addition
and
10 deletion
+28
-10
source/libs/sync/inc/syncInt.h
source/libs/sync/inc/syncInt.h
+4
-2
source/libs/sync/src/syncMain.c
source/libs/sync/src/syncMain.c
+20
-4
source/libs/sync/src/syncUtil.c
source/libs/sync/src/syncUtil.c
+4
-4
未找到文件。
source/libs/sync/inc/syncInt.h
浏览文件 @
7bdafa5f
...
...
@@ -73,11 +73,12 @@ typedef struct SSyncTimer {
SSyncHbTimerData
hbData
;
}
SSyncTimer
;
typedef
struct
SElectTimer
{
typedef
struct
SElectTimer
Param
{
uint64_t
logicClock
;
SSyncNode
*
pSyncNode
;
int64_t
executeTime
;
void
*
pData
;
}
SElectTimer
;
}
SElectTimer
Param
;
typedef
struct
SPeerState
{
SyncIndex
lastSendIndex
;
...
...
@@ -153,6 +154,7 @@ typedef struct SSyncNode {
uint64_t
electTimerLogicClock
;
TAOS_TMR_CALLBACK
FpElectTimerCB
;
// Timer Fp
uint64_t
electTimerCounter
;
SElectTimerParam
electTimerParam
;
// heartbeat timer
tmr_h
pHeartbeatTimer
;
...
...
source/libs/sync/src/syncMain.c
浏览文件 @
7bdafa5f
...
...
@@ -1104,8 +1104,16 @@ int32_t syncNodeStartElectTimer(SSyncNode* pSyncNode, int32_t ms) {
int32_t
ret
=
0
;
if
(
syncIsInit
())
{
pSyncNode
->
electTimerMS
=
ms
;
int64_t
execTime
=
taosGetTimestampMs
()
+
ms
;
atomic_store_64
(
&
(
pSyncNode
->
electTimerParam
.
executeTime
),
execTime
);
atomic_store_64
(
&
(
pSyncNode
->
electTimerParam
.
logicClock
),
pSyncNode
->
electTimerLogicClock
);
pSyncNode
->
electTimerParam
.
pSyncNode
=
pSyncNode
;
pSyncNode
->
electTimerParam
.
pData
=
NULL
;
taosTmrReset
(
pSyncNode
->
FpElectTimerCB
,
pSyncNode
->
electTimerMS
,
pSyncNode
,
syncEnv
()
->
pTimerManager
,
&
pSyncNode
->
pElectTimer
);
}
else
{
sError
(
"vgId:%d, start elect timer error, sync env is stop"
,
pSyncNode
->
vgId
);
}
...
...
@@ -1855,27 +1863,35 @@ static void syncNodeEqPingTimer(void* param, void* tmrId) {
}
static
void
syncNodeEqElectTimer
(
void
*
param
,
void
*
tmrId
)
{
SSyncNode
*
pNode
=
param
;
if
(
!
syncIsInit
())
return
;
SSyncNode
*
pNode
=
(
SSyncNode
*
)
param
;
if
(
pNode
==
NULL
)
return
;
if
(
pNode
->
syncEqMsg
==
NULL
)
return
;
int64_t
tsNow
=
taosGetTimestampMs
();
if
(
tsNow
<
pNode
->
electTimerParam
.
executeTime
)
return
;
SRpcMsg
rpcMsg
=
{
0
};
int32_t
code
=
syncBuildTimeout
(
&
rpcMsg
,
SYNC_TIMEOUT_ELECTION
,
pNode
->
electTimerLogicClock
,
pNode
->
electTimerMS
,
pNode
);
syncBuildTimeout
(
&
rpcMsg
,
SYNC_TIMEOUT_ELECTION
,
pNode
->
electTimerParam
.
logicClock
,
pNode
->
electTimerMS
,
pNode
);
if
(
code
!=
0
)
{
sError
(
"failed to build elect msg"
);
return
;
}
SyncTimeout
*
pTimeout
=
rpcMsg
.
pCont
;
s
Trace
(
"enqueue elect msg lc:%"
PRId64
,
pTimeout
->
logicClock
);
s
NTrace
(
pNode
,
"enqueue elect msg lc:%"
PRId64
,
pTimeout
->
logicClock
);
code
=
pNode
->
syncEqMsg
(
pNode
->
msgcb
,
&
rpcMsg
);
if
(
code
!=
0
)
{
sError
(
"failed to sync enqueue elect msg since %s"
,
terrstr
());
rpcFreeCont
(
rpcMsg
.
pCont
);
return
;
}
}
...
...
source/libs/sync/src/syncUtil.c
浏览文件 @
7bdafa5f
...
...
@@ -193,7 +193,7 @@ static void syncPeerState2Str(SSyncNode* pSyncNode, char* buf, int32_t bufLen) {
}
void
syncPrintNodeLog
(
const
char
*
flags
,
ELogLevel
level
,
int32_t
dflag
,
SSyncNode
*
pNode
,
const
char
*
format
,
...)
{
if
(
pNode
==
NULL
||
pNode
->
pRaftCfg
!=
NULL
&&
pNode
->
pRaftStore
==
NULL
||
pNode
->
pLogStore
==
NULL
)
return
;
if
(
pNode
==
NULL
||
pNode
->
pRaftCfg
==
NULL
||
pNode
->
pRaftStore
==
NULL
||
pNode
->
pLogStore
==
NULL
)
return
;
int64_t
currentTerm
=
pNode
->
pRaftStore
->
currentTerm
;
// save error code, otherwise it will be overwritten
...
...
@@ -252,7 +252,7 @@ void syncPrintNodeLog(const char* flags, ELogLevel level, int32_t dflag, SSyncNo
void
syncPrintSnapshotSenderLog
(
const
char
*
flags
,
ELogLevel
level
,
int32_t
dflag
,
SSyncSnapshotSender
*
pSender
,
const
char
*
format
,
...)
{
SSyncNode
*
pNode
=
pSender
->
pSyncNode
;
if
(
pNode
==
NULL
||
pNode
->
pRaftCfg
!=
NULL
&&
pNode
->
pRaftStore
==
NULL
||
pNode
->
pLogStore
==
NULL
)
return
;
if
(
pNode
==
NULL
||
pNode
->
pRaftCfg
==
NULL
||
pNode
->
pRaftStore
==
NULL
||
pNode
->
pLogStore
==
NULL
)
return
;
SSnapshot
snapshot
=
{.
data
=
NULL
,
.
lastApplyIndex
=
-
1
,
.
lastApplyTerm
=
0
};
if
(
pNode
->
pFsm
!=
NULL
&&
pNode
->
pFsm
->
FpGetSnapshotInfo
!=
NULL
)
{
...
...
@@ -304,7 +304,7 @@ void syncPrintSnapshotSenderLog(const char* flags, ELogLevel level, int32_t dfla
void
syncPrintSnapshotReceiverLog
(
const
char
*
flags
,
ELogLevel
level
,
int32_t
dflag
,
SSyncSnapshotReceiver
*
pReceiver
,
const
char
*
format
,
...)
{
SSyncNode
*
pNode
=
pReceiver
->
pSyncNode
;
if
(
pNode
==
NULL
||
pNode
->
pRaftCfg
!=
NULL
&&
pNode
->
pRaftStore
==
NULL
||
pNode
->
pLogStore
==
NULL
)
return
;
if
(
pNode
==
NULL
||
pNode
->
pRaftCfg
==
NULL
||
pNode
->
pRaftStore
==
NULL
||
pNode
->
pLogStore
==
NULL
)
return
;
SSnapshot
snapshot
=
{.
data
=
NULL
,
.
lastApplyIndex
=
-
1
,
.
lastApplyTerm
=
0
};
if
(
pNode
->
pFsm
!=
NULL
&&
pNode
->
pFsm
->
FpGetSnapshotInfo
!=
NULL
)
{
...
...
@@ -554,4 +554,4 @@ void syncLogSendRequestVoteReply(SSyncNode* pSyncNode, const SyncRequestVoteRepl
syncUtilU642Addr
(
pMsg
->
destId
.
addr
,
host
,
sizeof
(
host
),
&
port
);
sNTrace
(
pSyncNode
,
"send sync-request-vote-reply to %s:%d {term:%"
PRId64
", grant:%d}, %s"
,
host
,
port
,
pMsg
->
term
,
pMsg
->
voteGranted
,
s
);
}
\ No newline at end of file
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录