Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
4395c55e
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看板
未验证
提交
4395c55e
编写于
11月 17, 2022
作者:
S
Shengliang Guan
提交者:
GitHub
11月 17, 2022
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #18232 from taosdata/fix/asan-timer-memory-error
fix(sync): fix asan error, use rid in hbdata and syncnode
上级
58f854a1
effc38d2
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
84 addition
and
8 deletion
+84
-8
source/libs/sync/inc/syncEnv.h
source/libs/sync/inc/syncEnv.h
+5
-0
source/libs/sync/inc/syncInt.h
source/libs/sync/inc/syncInt.h
+6
-2
source/libs/sync/src/syncEnv.c
source/libs/sync/src/syncEnv.c
+34
-0
source/libs/sync/src/syncMain.c
source/libs/sync/src/syncMain.c
+39
-6
未找到文件。
source/libs/sync/inc/syncEnv.h
浏览文件 @
4395c55e
...
...
@@ -57,6 +57,11 @@ void syncNodeRemove(int64_t rid);
SSyncNode
*
syncNodeAcquire
(
int64_t
rid
);
void
syncNodeRelease
(
SSyncNode
*
pNode
);
int64_t
syncHbTimerDataAdd
(
SSyncHbTimerData
*
pData
);
void
syncHbTimerDataRemove
(
int64_t
rid
);
SSyncHbTimerData
*
syncHbTimerDataAcquire
(
int64_t
rid
);
void
syncHbTimerDataRelease
(
SSyncHbTimerData
*
pData
);
#ifdef __cplusplus
}
#endif
...
...
source/libs/sync/inc/syncInt.h
浏览文件 @
4395c55e
...
...
@@ -57,10 +57,11 @@ typedef struct SRaftId {
}
SRaftId
;
typedef
struct
SSyncHbTimerData
{
SSyncNode
*
pSyncNode
;
int64_t
syncNodeRid
;
SSyncTimer
*
pTimer
;
SRaftId
destId
;
uint64_t
logicClock
;
int64_t
rid
;
}
SSyncHbTimerData
;
typedef
struct
SSyncTimer
{
...
...
@@ -70,7 +71,7 @@ typedef struct SSyncTimer {
uint64_t
counter
;
int32_t
timerMS
;
SRaftId
destId
;
SSyncHbTimerData
hbData
;
int64_t
hbDataRid
;
}
SSyncTimer
;
typedef
struct
SElectTimerParam
{
...
...
@@ -189,6 +190,8 @@ typedef struct SSyncNode {
int64_t
leaderTime
;
int64_t
lastReplicateTime
;
bool
isStart
;
}
SSyncNode
;
// open/close --------------
...
...
@@ -198,6 +201,7 @@ void syncNodeStartStandBy(SSyncNode* pSyncNode);
void
syncNodeClose
(
SSyncNode
*
pSyncNode
);
void
syncNodePreClose
(
SSyncNode
*
pSyncNode
);
int32_t
syncNodePropose
(
SSyncNode
*
pSyncNode
,
SRpcMsg
*
pMsg
,
bool
isWeak
);
void
syncHbTimerDataFree
(
SSyncHbTimerData
*
pData
);
// on message ---------------------
int32_t
syncNodeOnTimeout
(
SSyncNode
*
ths
,
const
SRpcMsg
*
pMsg
);
...
...
source/libs/sync/src/syncEnv.c
浏览文件 @
4395c55e
...
...
@@ -20,6 +20,7 @@
static
SSyncEnv
gSyncEnv
=
{
0
};
static
int32_t
gNodeRefId
=
-
1
;
static
int32_t
gHbDataRefId
=
-
1
;
static
void
syncEnvTick
(
void
*
param
,
void
*
tmrId
);
SSyncEnv
*
syncEnv
()
{
return
&
gSyncEnv
;
}
...
...
@@ -50,6 +51,13 @@ int32_t syncInit() {
return
-
1
;
}
gHbDataRefId
=
taosOpenRef
(
200
,
(
RefFp
)
syncHbTimerDataFree
);
if
(
gHbDataRefId
<
0
)
{
sError
(
"failed to init hb-data ref"
);
syncCleanUp
();
return
-
1
;
}
sDebug
(
"sync rsetId:%d is open"
,
gNodeRefId
);
return
0
;
}
...
...
@@ -64,6 +72,12 @@ void syncCleanUp() {
taosCloseRef
(
gNodeRefId
);
gNodeRefId
=
-
1
;
}
if
(
gHbDataRefId
!=
-
1
)
{
sDebug
(
"sync rsetId:%d is closed"
,
gHbDataRefId
);
taosCloseRef
(
gHbDataRefId
);
gHbDataRefId
=
-
1
;
}
}
int64_t
syncNodeAdd
(
SSyncNode
*
pNode
)
{
...
...
@@ -88,6 +102,26 @@ SSyncNode *syncNodeAcquire(int64_t rid) {
void
syncNodeRelease
(
SSyncNode
*
pNode
)
{
taosReleaseRef
(
gNodeRefId
,
pNode
->
rid
);
}
int64_t
syncHbTimerDataAdd
(
SSyncHbTimerData
*
pData
)
{
pData
->
rid
=
taosAddRef
(
gHbDataRefId
,
pData
);
if
(
pData
->
rid
<
0
)
return
-
1
;
return
pData
->
rid
;
}
void
syncHbTimerDataRemove
(
int64_t
rid
)
{
taosRemoveRef
(
gHbDataRefId
,
rid
);
}
SSyncHbTimerData
*
syncHbTimerDataAcquire
(
int64_t
rid
)
{
SSyncHbTimerData
*
pData
=
taosAcquireRef
(
gHbDataRefId
,
rid
);
if
(
pData
==
NULL
)
{
sError
(
"failed to acquire hb-timer-data from refId:%"
PRId64
,
rid
);
terrno
=
TSDB_CODE_SYN_INTERNAL_ERROR
;
}
return
pData
;
}
void
syncHbTimerDataRelease
(
SSyncHbTimerData
*
pData
)
{
taosReleaseRef
(
gHbDataRefId
,
pData
->
rid
);
}
#if 0
void syncEnvStartTimer() {
taosTmrReset(gSyncEnv.FpEnvTickTimer, gSyncEnv.envTickTimerMS, &gSyncEnv, gSyncEnv.pTimerManager,
...
...
source/libs/sync/src/syncMain.c
浏览文件 @
4395c55e
...
...
@@ -91,6 +91,7 @@ void syncStart(int64_t rid) {
void
syncStop
(
int64_t
rid
)
{
SSyncNode
*
pSyncNode
=
syncNodeAcquire
(
rid
);
if
(
pSyncNode
!=
NULL
)
{
pSyncNode
->
isStart
=
false
;
syncNodeRelease
(
pSyncNode
);
syncNodeRemove
(
rid
);
}
...
...
@@ -665,13 +666,20 @@ static int32_t syncHbTimerInit(SSyncNode* pSyncNode, SSyncTimer* pSyncTimer, SRa
static
int32_t
syncHbTimerStart
(
SSyncNode
*
pSyncNode
,
SSyncTimer
*
pSyncTimer
)
{
int32_t
ret
=
0
;
if
(
syncIsInit
())
{
SSyncHbTimerData
*
pData
=
&
pSyncTimer
->
hbData
;
pData
->
pSyncNode
=
pSyncNode
;
SSyncHbTimerData
*
pData
=
syncHbTimerDataAcquire
(
pSyncTimer
->
hbDataRid
);
if
(
pData
==
NULL
)
{
pData
=
taosMemoryMalloc
(
sizeof
(
SSyncHbTimerData
));
pData
->
rid
=
syncHbTimerDataAdd
(
pData
);
}
pSyncTimer
->
hbDataRid
=
pData
->
rid
;
pData
->
syncNodeRid
=
pSyncNode
->
rid
;
pData
->
pTimer
=
pSyncTimer
;
pData
->
destId
=
pSyncTimer
->
destId
;
pData
->
logicClock
=
pSyncTimer
->
logicClock
;
taosTmrReset
(
pSyncTimer
->
timerCb
,
pSyncTimer
->
timerMS
,
pData
,
syncEnv
()
->
pTimerManager
,
&
pSyncTimer
->
pTimer
);
taosTmrReset
(
pSyncTimer
->
timerCb
,
pSyncTimer
->
timerMS
,
(
void
*
)(
pData
->
rid
),
syncEnv
()
->
pTimerManager
,
&
pSyncTimer
->
pTimer
);
}
else
{
sError
(
"vgId:%d, start ctrl hb timer error, sync env is stop"
,
pSyncNode
->
vgId
);
}
...
...
@@ -683,6 +691,8 @@ static int32_t syncHbTimerStop(SSyncNode* pSyncNode, SSyncTimer* pSyncTimer) {
atomic_add_fetch_64
(
&
pSyncTimer
->
logicClock
,
1
);
taosTmrStop
(
pSyncTimer
->
pTimer
);
pSyncTimer
->
pTimer
=
NULL
;
syncHbTimerDataRemove
(
pSyncTimer
->
hbDataRid
);
pSyncTimer
->
hbDataRid
=
-
1
;
return
ret
;
}
...
...
@@ -960,6 +970,7 @@ SSyncNode* syncNodeOpen(SSyncInfo* pSyncInfo) {
// snapshotting
atomic_store_64
(
&
pSyncNode
->
snapshottingIndex
,
SYNC_INDEX_INVALID
);
pSyncNode
->
isStart
=
true
;
sNTrace
(
pSyncNode
,
"sync open"
);
return
pSyncNode
;
...
...
@@ -1027,6 +1038,8 @@ void syncNodePreClose(SSyncNode* pSyncNode) {
syncNodeStopHeartbeatTimer
(
pSyncNode
);
}
void
syncHbTimerDataFree
(
SSyncHbTimerData
*
pData
)
{
taosMemoryFree
(
pData
);
}
void
syncNodeClose
(
SSyncNode
*
pSyncNode
)
{
if
(
pSyncNode
==
NULL
)
{
return
;
...
...
@@ -1929,19 +1942,36 @@ static void syncNodeEqHeartbeatTimer(void* param, void* tmrId) {
}
static
void
syncNodeEqPeerHeartbeatTimer
(
void
*
param
,
void
*
tmrId
)
{
SSyncHbTimerData
*
pData
=
(
SSyncHbTimerData
*
)
param
;
SSyncNode
*
pSyncNode
=
pData
->
pSyncNode
;
SSyncTimer
*
pSyncTimer
=
pData
->
pTimer
;
int64_t
hbDataRid
=
(
int64_t
)
param
;
SSyncHbTimerData
*
pData
=
syncHbTimerDataAcquire
(
hbDataRid
);
if
(
pData
==
NULL
)
{
return
;
}
SSyncNode
*
pSyncNode
=
syncNodeAcquire
(
pData
->
syncNodeRid
);
if
(
pSyncNode
==
NULL
)
{
syncHbTimerDataRelease
(
pData
);
return
;
}
SSyncTimer
*
pSyncTimer
=
pData
->
pTimer
;
if
(
!
pSyncNode
->
isStart
)
{
syncNodeRelease
(
pSyncNode
);
syncHbTimerDataRelease
(
pData
);
return
;
}
if
(
pSyncNode
->
state
!=
TAOS_SYNC_STATE_LEADER
)
{
syncNodeRelease
(
pSyncNode
);
syncHbTimerDataRelease
(
pData
);
return
;
}
if
(
pSyncNode
->
pRaftStore
==
NULL
)
{
syncNodeRelease
(
pSyncNode
);
syncHbTimerDataRelease
(
pData
);
return
;
}
...
...
@@ -1978,6 +2008,9 @@ static void syncNodeEqPeerHeartbeatTimer(void* param, void* tmrId) {
msgLogicClock
);
}
}
syncHbTimerDataRelease
(
pData
);
syncNodeRelease
(
pSyncNode
);
}
static
int32_t
syncNodeEqNoop
(
SSyncNode
*
pNode
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录