Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
5b7261d6
T
TDengine
项目概览
taosdata
/
TDengine
大约 2 年 前同步成功
通知
1192
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看板
提交
5b7261d6
编写于
10月 29, 2021
作者:
L
lichuang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[TD-10645][raft]<feature>add sync node timer
上级
c319d1cb
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
50 addition
and
4 deletion
+50
-4
source/libs/sync/inc/raft.h
source/libs/sync/inc/raft.h
+1
-0
source/libs/sync/inc/raft_message.h
source/libs/sync/inc/raft_message.h
+2
-0
source/libs/sync/inc/syncInt.h
source/libs/sync/inc/syncInt.h
+5
-0
source/libs/sync/src/raft.c
source/libs/sync/src/raft.c
+5
-3
source/libs/sync/src/raft_message.c
source/libs/sync/src/raft_message.c
+5
-0
source/libs/sync/src/sync.c
source/libs/sync/src/sync.c
+32
-1
未找到文件。
source/libs/sync/inc/raft.h
浏览文件 @
5b7261d6
...
@@ -29,5 +29,6 @@ typedef struct SSyncRaft {
...
@@ -29,5 +29,6 @@ typedef struct SSyncRaft {
int32_t
syncRaftStart
(
SSyncRaft
*
pRaft
,
const
SSyncInfo
*
pInfo
);
int32_t
syncRaftStart
(
SSyncRaft
*
pRaft
,
const
SSyncInfo
*
pInfo
);
int32_t
syncRaftStep
(
SSyncRaft
*
pRaft
,
const
RaftMessage
*
pMsg
);
int32_t
syncRaftStep
(
SSyncRaft
*
pRaft
,
const
RaftMessage
*
pMsg
);
int32_t
syncRaftTick
(
SSyncRaft
*
pRaft
);
#endif
/* _TD_LIBS_SYNC_RAFT_H */
#endif
/* _TD_LIBS_SYNC_RAFT_H */
\ No newline at end of file
source/libs/sync/inc/raft_message.h
浏览文件 @
5b7261d6
...
@@ -73,4 +73,6 @@ static FORCE_INLINE bool syncIsInternalMsg(const RaftMessage* pMsg) {
...
@@ -73,4 +73,6 @@ static FORCE_INLINE bool syncIsInternalMsg(const RaftMessage* pMsg) {
return
pMsg
->
msgType
==
RAFT_MSG_INTERNAL_PROP
;
return
pMsg
->
msgType
==
RAFT_MSG_INTERNAL_PROP
;
}
}
void
syncFreeMessage
(
const
RaftMessage
*
pMsg
);
#endif
/* _TD_LIBS_SYNC_RAFT_MESSAGE_H */
#endif
/* _TD_LIBS_SYNC_RAFT_MESSAGE_H */
\ No newline at end of file
source/libs/sync/inc/syncInt.h
浏览文件 @
5b7261d6
...
@@ -30,8 +30,10 @@ typedef struct SSyncWorker {
...
@@ -30,8 +30,10 @@ typedef struct SSyncWorker {
struct
SSyncNode
{
struct
SSyncNode
{
pthread_mutex_t
mutex
;
pthread_mutex_t
mutex
;
int32_t
refCount
;
SyncGroupId
vgId
;
SyncGroupId
vgId
;
SSyncRaft
raft
;
SSyncRaft
raft
;
void
*
syncTimer
;
};
};
typedef
struct
SSyncManager
{
typedef
struct
SSyncManager
{
...
@@ -46,6 +48,9 @@ typedef struct SSyncManager {
...
@@ -46,6 +48,9 @@ typedef struct SSyncManager {
// vgroup hash table
// vgroup hash table
SHashObj
*
vgroupTable
;
SHashObj
*
vgroupTable
;
// timer manager
void
*
syncTimerManager
;
}
SSyncManager
;
}
SSyncManager
;
extern
SSyncManager
*
gSyncManager
;
extern
SSyncManager
*
gSyncManager
;
...
...
source/libs/sync/src/raft.c
浏览文件 @
5b7261d6
...
@@ -67,8 +67,10 @@ int32_t syncRaftStart(SSyncRaft* pRaft, const SSyncInfo* pInfo) {
...
@@ -67,8 +67,10 @@ int32_t syncRaftStart(SSyncRaft* pRaft, const SSyncInfo* pInfo) {
}
}
int32_t
syncRaftStep
(
SSyncRaft
*
pRaft
,
const
RaftMessage
*
pMsg
)
{
int32_t
syncRaftStep
(
SSyncRaft
*
pRaft
,
const
RaftMessage
*
pMsg
)
{
if
(
!
syncIsInternalMsg
(
pMsg
))
{
syncFreeMessage
(
pMsg
);
free
(
pMsg
);
return
0
;
}
}
int32_t
syncRaftTick
(
SSyncRaft
*
pRaft
)
{
return
0
;
return
0
;
}
}
\ No newline at end of file
source/libs/sync/src/raft_message.c
浏览文件 @
5b7261d6
...
@@ -15,3 +15,8 @@
...
@@ -15,3 +15,8 @@
#include "raft_message.h"
#include "raft_message.h"
void
syncFreeMessage
(
const
RaftMessage
*
pMsg
)
{
if
(
!
syncIsInternalMsg
(
pMsg
))
{
free
((
RaftMessage
*
)
pMsg
);
}
}
\ No newline at end of file
source/libs/sync/src/sync.c
浏览文件 @
5b7261d6
...
@@ -14,12 +14,16 @@
...
@@ -14,12 +14,16 @@
*/
*/
#include "syncInt.h"
#include "syncInt.h"
#include "ttimer.h"
SSyncManager
*
gSyncManager
=
NULL
;
SSyncManager
*
gSyncManager
=
NULL
;
#define SYNC_TICK_TIMER 50
static
int
syncOpenWorkerPool
(
SSyncManager
*
syncManager
);
static
int
syncOpenWorkerPool
(
SSyncManager
*
syncManager
);
static
int
syncCloseWorkerPool
(
SSyncManager
*
syncManager
);
static
int
syncCloseWorkerPool
(
SSyncManager
*
syncManager
);
static
void
*
syncWorkerMain
(
void
*
argv
);
static
void
*
syncWorkerMain
(
void
*
argv
);
static
void
syncNodeTick
(
void
*
param
,
void
*
tmrId
);
int32_t
syncInit
()
{
int32_t
syncInit
()
{
if
(
gSyncManager
!=
NULL
)
{
if
(
gSyncManager
!=
NULL
)
{
...
@@ -33,6 +37,14 @@ int32_t syncInit() {
...
@@ -33,6 +37,14 @@ int32_t syncInit() {
}
}
pthread_mutex_init
(
&
gSyncManager
->
mutex
,
NULL
);
pthread_mutex_init
(
&
gSyncManager
->
mutex
,
NULL
);
// init sync timer manager
gSyncManager
->
syncTimerManager
=
taosTmrInit
(
1000
,
50
,
10000
,
"SYNC"
);
if
(
gSyncManager
->
syncTimerManager
==
NULL
)
{
syncCleanUp
();
return
-
1
;
}
// init worker pool
// init worker pool
if
(
syncOpenWorkerPool
(
gSyncManager
)
!=
0
)
{
if
(
syncOpenWorkerPool
(
gSyncManager
)
!=
0
)
{
syncCleanUp
();
syncCleanUp
();
...
@@ -56,6 +68,7 @@ void syncCleanUp() {
...
@@ -56,6 +68,7 @@ void syncCleanUp() {
if
(
gSyncManager
->
vgroupTable
)
{
if
(
gSyncManager
->
vgroupTable
)
{
taosHashCleanup
(
gSyncManager
->
vgroupTable
);
taosHashCleanup
(
gSyncManager
->
vgroupTable
);
}
}
taosTmrCleanUp
(
gSyncManager
->
syncTimerManager
);
syncCloseWorkerPool
(
gSyncManager
);
syncCloseWorkerPool
(
gSyncManager
);
pthread_mutex_unlock
(
&
gSyncManager
->
mutex
);
pthread_mutex_unlock
(
&
gSyncManager
->
mutex
);
pthread_mutex_destroy
(
&
gSyncManager
->
mutex
);
pthread_mutex_destroy
(
&
gSyncManager
->
mutex
);
...
@@ -80,6 +93,8 @@ SSyncNode* syncStart(const SSyncInfo* pInfo) {
...
@@ -80,6 +93,8 @@ SSyncNode* syncStart(const SSyncInfo* pInfo) {
return
NULL
;
return
NULL
;
}
}
pNode
->
syncTimer
=
taosTmrStart
(
syncNodeTick
,
SYNC_TICK_TIMER
,
(
void
*
)
pInfo
->
vgId
,
gSyncManager
->
syncTimerManager
);
// start raft
// start raft
pNode
->
raft
.
pNode
=
pNode
;
pNode
->
raft
.
pNode
=
pNode
;
if
(
syncRaftStart
(
&
pNode
->
raft
,
pInfo
)
!=
0
)
{
if
(
syncRaftStart
(
&
pNode
->
raft
,
pInfo
)
!=
0
)
{
...
@@ -106,7 +121,8 @@ void syncStop(const SSyncNode* pNode) {
...
@@ -106,7 +121,8 @@ void syncStop(const SSyncNode* pNode) {
return
;
return
;
}
}
assert
(
*
ppNode
==
pNode
);
assert
(
*
ppNode
==
pNode
);
taosTmrStop
(
pNode
->
syncTimer
);
taosHashRemove
(
gSyncManager
->
vgroupTable
,
&
pNode
->
vgId
,
sizeof
(
SyncGroupId
));
taosHashRemove
(
gSyncManager
->
vgroupTable
,
&
pNode
->
vgId
,
sizeof
(
SyncGroupId
));
pthread_mutex_unlock
(
&
gSyncManager
->
mutex
);
pthread_mutex_unlock
(
&
gSyncManager
->
mutex
);
...
@@ -158,4 +174,19 @@ static void *syncWorkerMain(void *argv) {
...
@@ -158,4 +174,19 @@ static void *syncWorkerMain(void *argv) {
setThreadName
(
"syncWorker"
);
setThreadName
(
"syncWorker"
);
return
NULL
;
return
NULL
;
}
static
void
syncNodeTick
(
void
*
param
,
void
*
tmrId
)
{
SyncGroupId
vgId
=
(
SyncGroupId
)
param
;
SSyncNode
**
ppNode
=
taosHashGet
(
gSyncManager
->
vgroupTable
,
&
vgId
,
sizeof
(
SyncGroupId
));
if
(
ppNode
==
NULL
)
{
return
;
}
SSyncNode
*
pNode
=
*
ppNode
;
pthread_mutex_lock
(
&
pNode
->
mutex
);
syncRaftTick
(
&
pNode
->
raft
);
pthread_mutex_unlock
(
&
pNode
->
mutex
);
pNode
->
syncTimer
=
taosTmrStart
(
syncNodeTick
,
SYNC_TICK_TIMER
,
(
void
*
)
pNode
->
vgId
,
gSyncManager
->
syncTimerManager
);
}
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录