Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
dc42544e
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22017
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看板
提交
dc42544e
编写于
8月 10, 2022
作者:
M
Minghao Li
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactor(sync): add leader, follower call back2
上级
b4c86857
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
35 addition
and
9 deletion
+35
-9
source/libs/sync/inc/syncInt.h
source/libs/sync/inc/syncInt.h
+1
-0
source/libs/sync/inc/syncRespMgr.h
source/libs/sync/inc/syncRespMgr.h
+4
-3
source/libs/sync/src/syncMain.c
source/libs/sync/src/syncMain.c
+12
-1
source/libs/sync/src/syncRespMgr.c
source/libs/sync/src/syncRespMgr.c
+18
-5
未找到文件。
source/libs/sync/inc/syncInt.h
浏览文件 @
dc42544e
...
...
@@ -163,6 +163,7 @@ typedef struct SSyncNode {
bool
changing
;
int64_t
startTime
;
int64_t
leaderTime
;
int64_t
lastReplicateTime
;
}
SSyncNode
;
...
...
source/libs/sync/inc/syncRespMgr.h
浏览文件 @
dc42544e
...
...
@@ -32,9 +32,9 @@ typedef struct SRespStub {
}
SRespStub
;
typedef
struct
SSyncRespMgr
{
SHashObj
*
pRespHash
;
SHashObj
*
pRespHash
;
int64_t
ttl
;
void
*
data
;
void
*
data
;
TdThreadMutex
mutex
;
uint64_t
seqNum
;
}
SSyncRespMgr
;
...
...
@@ -46,7 +46,8 @@ int32_t syncRespMgrDel(SSyncRespMgr *pObj, uint64_t index);
int32_t
syncRespMgrGet
(
SSyncRespMgr
*
pObj
,
uint64_t
index
,
SRespStub
*
pStub
);
int32_t
syncRespMgrGetAndDel
(
SSyncRespMgr
*
pObj
,
uint64_t
index
,
SRespStub
*
pStub
);
void
syncRespClean
(
SSyncRespMgr
*
pObj
);
void
syncRespCleanByTTL
(
SSyncRespMgr
*
pObj
,
int64_t
ttl
);
void
syncRespCleanRsp
(
SSyncRespMgr
*
pObj
);
void
syncRespCleanByTTL
(
SSyncRespMgr
*
pObj
,
int64_t
ttl
,
bool
rsp
);
#ifdef __cplusplus
}
...
...
source/libs/sync/src/syncMain.c
浏览文件 @
dc42544e
...
...
@@ -1100,6 +1100,7 @@ SSyncNode* syncNodeOpen(const SSyncInfo* pOldSyncInfo) {
int64_t
timeNow
=
taosGetTimestampMs
();
pSyncNode
->
startTime
=
timeNow
;
pSyncNode
->
leaderTime
=
timeNow
;
pSyncNode
->
lastReplicateTime
=
timeNow
;
syncNodeEventLog
(
pSyncNode
,
"sync open"
);
...
...
@@ -2015,6 +2016,8 @@ void syncNodeUpdateTermWithoutStepDown(SSyncNode* pSyncNode, SyncTerm term) {
}
}
void
syncNodeLeaderChangeRsp
(
SSyncNode
*
pSyncNode
)
{
syncRespCleanRsp
(
pSyncNode
->
pSyncRespMgr
);
}
void
syncNodeBecomeFollower
(
SSyncNode
*
pSyncNode
,
const
char
*
debugStr
)
{
// maybe clear leader cache
if
(
pSyncNode
->
state
==
TAOS_SYNC_STATE_LEADER
)
{
...
...
@@ -2028,6 +2031,9 @@ void syncNodeBecomeFollower(SSyncNode* pSyncNode, const char* debugStr) {
// reset elect timer
syncNodeResetElectTimer
(
pSyncNode
);
// send rsp to client
syncNodeLeaderChangeRsp
(
pSyncNode
);
// call back
if
(
pSyncNode
->
pFsm
!=
NULL
&&
pSyncNode
->
pFsm
->
FpBecomeFollowerCb
!=
NULL
)
{
pSyncNode
->
pFsm
->
FpBecomeFollowerCb
(
pSyncNode
->
pFsm
);
...
...
@@ -2068,6 +2074,8 @@ void syncNodeBecomeFollower(SSyncNode* pSyncNode, const char* debugStr) {
// /\ UNCHANGED <<messages, currentTerm, votedFor, candidateVars, logVars>>
//
void
syncNodeBecomeLeader
(
SSyncNode
*
pSyncNode
,
const
char
*
debugStr
)
{
pSyncNode
->
leaderTime
=
taosGetTimestampMs
();
// reset restoreFinish
pSyncNode
->
restoreFinish
=
false
;
...
...
@@ -2954,8 +2962,11 @@ int32_t syncNodeCommit(SSyncNode* ths, SyncIndex beginIndex, SyncIndex endIndex,
}
ths
->
restoreFinish
=
true
;
int64_t
restoreDelay
=
taosGetTimestampMs
()
-
ths
->
leaderTime
;
char
eventLog
[
128
];
snprintf
(
eventLog
,
sizeof
(
eventLog
),
"restore finish, index:%"
PRId64
,
pEntry
->
index
);
snprintf
(
eventLog
,
sizeof
(
eventLog
),
"restore finish, index:%ld, elapsed:%ld ms, "
,
pEntry
->
index
,
restoreDelay
);
syncNodeEventLog
(
ths
,
eventLog
);
}
}
...
...
source/libs/sync/src/syncRespMgr.c
浏览文件 @
dc42544e
...
...
@@ -108,13 +108,19 @@ int32_t syncRespMgrGetAndDel(SSyncRespMgr *pObj, uint64_t index, SRespStub *pStu
return
0
;
// get none object
}
void
syncRespCleanRsp
(
SSyncRespMgr
*
pObj
)
{
taosThreadMutexLock
(
&
(
pObj
->
mutex
));
syncRespCleanByTTL
(
pObj
,
-
1
,
true
);
taosThreadMutexUnlock
(
&
(
pObj
->
mutex
));
}
void
syncRespClean
(
SSyncRespMgr
*
pObj
)
{
taosThreadMutexLock
(
&
(
pObj
->
mutex
));
syncRespCleanByTTL
(
pObj
,
pObj
->
ttl
);
syncRespCleanByTTL
(
pObj
,
pObj
->
ttl
,
false
);
taosThreadMutexUnlock
(
&
(
pObj
->
mutex
));
}
void
syncRespCleanByTTL
(
SSyncRespMgr
*
pObj
,
int64_t
ttl
)
{
void
syncRespCleanByTTL
(
SSyncRespMgr
*
pObj
,
int64_t
ttl
,
bool
rsp
)
{
SRespStub
*
pStub
=
(
SRespStub
*
)
taosHashIterate
(
pObj
->
pRespHash
,
NULL
);
int
cnt
=
0
;
int
sum
=
0
;
...
...
@@ -126,12 +132,12 @@ void syncRespCleanByTTL(SSyncRespMgr *pObj, int64_t ttl) {
while
(
pStub
)
{
size_t
len
;
void
*
key
=
taosHashGetKey
(
pStub
,
&
len
);
void
*
key
=
taosHashGetKey
(
pStub
,
&
len
);
uint64_t
*
pSeqNum
=
(
uint64_t
*
)
key
;
sum
++
;
int64_t
nowMS
=
taosGetTimestampMs
();
if
(
nowMS
-
pStub
->
createTime
>
ttl
)
{
if
(
nowMS
-
pStub
->
createTime
>
ttl
||
-
1
==
ttl
)
{
taosArrayPush
(
delIndexArray
,
pSeqNum
);
cnt
++
;
...
...
@@ -148,7 +154,14 @@ void syncRespCleanByTTL(SSyncRespMgr *pObj, int64_t ttl) {
pStub
->
rpcMsg
.
pCont
=
NULL
;
pStub
->
rpcMsg
.
contLen
=
0
;
pSyncNode
->
pFsm
->
FpCommitCb
(
pSyncNode
->
pFsm
,
&
(
pStub
->
rpcMsg
),
cbMeta
);
// TODO: and make rpcMsg body, call commit cb
// pSyncNode->pFsm->FpCommitCb(pSyncNode->pFsm, &(pStub->rpcMsg), cbMeta);
pStub
->
rpcMsg
.
code
=
TSDB_CODE_SYN_NOT_LEADER
;
if
(
pStub
->
rpcMsg
.
info
.
handle
!=
NULL
)
{
tmsgSendRsp
(
&
(
pStub
->
rpcMsg
));
}
}
pStub
=
(
SRespStub
*
)
taosHashIterate
(
pObj
->
pRespHash
,
pStub
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录