Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
bdc9acbf
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看板
提交
bdc9acbf
编写于
5月 30, 2022
作者:
M
Minghao Li
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
enh(sync): add snapshotEnable
上级
cd2e8fe7
变更
10
隐藏空白更改
内联
并排
Showing
10 changed file
with
32 addition
and
8 deletion
+32
-8
include/libs/sync/sync.h
include/libs/sync/sync.h
+2
-1
source/dnode/mnode/impl/src/mndSync.c
source/dnode/mnode/impl/src/mndSync.c
+1
-0
source/dnode/vnode/src/vnd/vnodeSync.c
source/dnode/vnode/src/vnd/vnodeSync.c
+2
-0
source/libs/sync/inc/syncElection.h
source/libs/sync/inc/syncElection.h
+1
-0
source/libs/sync/inc/syncRaftCfg.h
source/libs/sync/inc/syncRaftCfg.h
+7
-1
source/libs/sync/src/syncElection.c
source/libs/sync/src/syncElection.c
+2
-0
source/libs/sync/src/syncMain.c
source/libs/sync/src/syncMain.c
+5
-2
source/libs/sync/src/syncRaftCfg.c
source/libs/sync/src/syncRaftCfg.c
+7
-2
source/libs/sync/test/syncConfigChangeTest.cpp
source/libs/sync/test/syncConfigChangeTest.cpp
+0
-1
source/libs/sync/test/syncRaftCfgTest.cpp
source/libs/sync/test/syncRaftCfgTest.cpp
+5
-1
未找到文件。
include/libs/sync/sync.h
浏览文件 @
bdc9acbf
...
...
@@ -88,7 +88,7 @@ typedef struct SReConfigCbMeta {
}
SReConfigCbMeta
;
typedef
struct
SSnapshot
{
void
*
data
;
void
*
data
;
SyncIndex
lastApplyIndex
;
SyncTerm
lastApplyTerm
;
}
SSnapshot
;
...
...
@@ -145,6 +145,7 @@ typedef struct SSyncLogStore {
typedef
struct
SSyncInfo
{
bool
isStandBy
;
bool
snapshotEnable
;
SyncGroupId
vgId
;
SSyncCfg
syncCfg
;
char
path
[
TSDB_FILENAME_LEN
];
...
...
source/dnode/mnode/impl/src/mndSync.c
浏览文件 @
bdc9acbf
...
...
@@ -146,6 +146,7 @@ int32_t mndInitSync(SMnode *pMnode) {
syncInfo
.
pWal
=
pMgmt
->
pWal
;
syncInfo
.
pFsm
=
mndSyncMakeFsm
(
pMnode
);
syncInfo
.
isStandBy
=
pMgmt
->
standby
;
syncInfo
.
snapshotEnable
=
true
;
SSyncCfg
*
pCfg
=
&
syncInfo
.
syncCfg
;
pCfg
->
replicaNum
=
pMnode
->
replica
;
...
...
source/dnode/vnode/src/vnd/vnodeSync.c
浏览文件 @
bdc9acbf
...
...
@@ -26,6 +26,8 @@ static int32_t vnodeSyncGetSnapshot(SSyncFSM *pFsm, SSnapshot *pSnapshot);
int32_t
vnodeSyncOpen
(
SVnode
*
pVnode
,
char
*
path
)
{
SSyncInfo
syncInfo
=
{
.
isStandBy
=
false
,
.
snapshotEnable
=
false
,
.
vgId
=
pVnode
->
config
.
vgId
,
.
syncCfg
=
pVnode
->
config
.
syncCfg
,
.
pWal
=
pVnode
->
pWal
,
...
...
source/libs/sync/inc/syncElection.h
浏览文件 @
bdc9acbf
...
...
@@ -39,6 +39,7 @@ extern "C" {
// /\ UNCHANGED <<serverVars, candidateVars, leaderVars, logVars>>
//
int32_t
syncNodeRequestVotePeers
(
SSyncNode
*
pSyncNode
);
int32_t
syncNodeRequestVotePeersSnapshot
(
SSyncNode
*
pSyncNode
);
int32_t
syncNodeElect
(
SSyncNode
*
pSyncNode
);
int32_t
syncNodeRequestVote
(
SSyncNode
*
pSyncNode
,
const
SRaftId
*
destRaftId
,
const
SyncRequestVote
*
pMsg
);
...
...
source/libs/sync/inc/syncRaftCfg.h
浏览文件 @
bdc9acbf
...
...
@@ -34,6 +34,7 @@ typedef struct SRaftCfg {
TdFilePtr
pFile
;
char
path
[
TSDB_FILENAME_LEN
*
2
];
int8_t
isStandBy
;
int8_t
snapshotEnable
;
}
SRaftCfg
;
SRaftCfg
*
raftCfgOpen
(
const
char
*
path
);
...
...
@@ -50,7 +51,12 @@ char * raftCfg2Str(SRaftCfg *pRaftCfg);
int32_t
raftCfgFromJson
(
const
cJSON
*
pRoot
,
SRaftCfg
*
pRaftCfg
);
int32_t
raftCfgFromStr
(
const
char
*
s
,
SRaftCfg
*
pRaftCfg
);
int32_t
raftCfgCreateFile
(
SSyncCfg
*
pCfg
,
int8_t
isStandBy
,
const
char
*
path
);
typedef
struct
SRaftCfgMeta
{
int8_t
isStandBy
;
int8_t
snapshotEnable
;
}
SRaftCfgMeta
;
int32_t
raftCfgCreateFile
(
SSyncCfg
*
pCfg
,
SRaftCfgMeta
meta
,
const
char
*
path
);
// for debug ----------------------
void
syncCfgPrint
(
SSyncCfg
*
pCfg
);
...
...
source/libs/sync/src/syncElection.c
浏览文件 @
bdc9acbf
...
...
@@ -49,6 +49,8 @@ int32_t syncNodeRequestVotePeers(SSyncNode* pSyncNode) {
return
ret
;
}
int32_t
syncNodeRequestVotePeersSnapshot
(
SSyncNode
*
pSyncNode
)
{
return
0
;
}
int32_t
syncNodeElect
(
SSyncNode
*
pSyncNode
)
{
int32_t
ret
=
0
;
if
(
pSyncNode
->
state
==
TAOS_SYNC_STATE_FOLLOWER
)
{
...
...
source/libs/sync/src/syncMain.c
浏览文件 @
bdc9acbf
...
...
@@ -411,8 +411,11 @@ SSyncNode* syncNodeOpen(const SSyncInfo* pOldSyncInfo) {
snprintf
(
pSyncNode
->
configPath
,
sizeof
(
pSyncNode
->
configPath
),
"%s/raft_config.json"
,
pSyncInfo
->
path
);
if
(
!
taosCheckExistFile
(
pSyncNode
->
configPath
))
{
// create raft config file
ret
=
raftCfgCreateFile
((
SSyncCfg
*
)
&
(
pSyncInfo
->
syncCfg
),
pSyncInfo
->
isStandBy
,
pSyncNode
->
configPath
);
// create a new raft config file
SRaftCfgMeta
meta
;
meta
.
isStandBy
=
pSyncInfo
->
isStandBy
;
meta
.
snapshotEnable
=
pSyncInfo
->
snapshotEnable
;
ret
=
raftCfgCreateFile
((
SSyncCfg
*
)
&
(
pSyncInfo
->
syncCfg
),
meta
,
pSyncNode
->
configPath
);
assert
(
ret
==
0
);
}
else
{
...
...
source/libs/sync/src/syncRaftCfg.c
浏览文件 @
bdc9acbf
...
...
@@ -148,6 +148,7 @@ cJSON *raftCfg2Json(SRaftCfg *pRaftCfg) {
cJSON
*
pRoot
=
cJSON_CreateObject
();
cJSON_AddItemToObject
(
pRoot
,
"SSyncCfg"
,
syncCfg2Json
(
&
(
pRaftCfg
->
cfg
)));
cJSON_AddNumberToObject
(
pRoot
,
"isStandBy"
,
pRaftCfg
->
isStandBy
);
cJSON_AddNumberToObject
(
pRoot
,
"snapshotEnable"
,
pRaftCfg
->
snapshotEnable
);
cJSON
*
pJson
=
cJSON_CreateObject
();
cJSON_AddItemToObject
(
pJson
,
"RaftCfg"
,
pRoot
);
...
...
@@ -161,7 +162,7 @@ char *raftCfg2Str(SRaftCfg *pRaftCfg) {
return
serialized
;
}
int32_t
raftCfgCreateFile
(
SSyncCfg
*
pCfg
,
int8_t
isStandBy
,
const
char
*
path
)
{
int32_t
raftCfgCreateFile
(
SSyncCfg
*
pCfg
,
SRaftCfgMeta
meta
,
const
char
*
path
)
{
assert
(
pCfg
!=
NULL
);
TdFilePtr
pFile
=
taosOpenFile
(
path
,
TD_FILE_CREATE
|
TD_FILE_WRITE
);
...
...
@@ -169,7 +170,8 @@ int32_t raftCfgCreateFile(SSyncCfg *pCfg, int8_t isStandBy, const char *path) {
SRaftCfg
raftCfg
;
raftCfg
.
cfg
=
*
pCfg
;
raftCfg
.
isStandBy
=
isStandBy
;
raftCfg
.
isStandBy
=
meta
.
isStandBy
;
raftCfg
.
snapshotEnable
=
meta
.
snapshotEnable
;
char
*
s
=
raftCfg2Str
(
&
raftCfg
);
char
buf
[
CONFIG_FILE_LEN
];
...
...
@@ -194,6 +196,9 @@ int32_t raftCfgFromJson(const cJSON *pRoot, SRaftCfg *pRaftCfg) {
cJSON
*
pJsonIsStandBy
=
cJSON_GetObjectItem
(
pJson
,
"isStandBy"
);
pRaftCfg
->
isStandBy
=
cJSON_GetNumberValue
(
pJsonIsStandBy
);
cJSON
*
pJsonSnapshotEnable
=
cJSON_GetObjectItem
(
pJson
,
"snapshotEnable"
);
pRaftCfg
->
snapshotEnable
=
cJSON_GetNumberValue
(
pJsonSnapshotEnable
);
cJSON
*
pJsonSyncCfg
=
cJSON_GetObjectItem
(
pJson
,
"SSyncCfg"
);
int32_t
code
=
syncCfgFromJson
(
pJsonSyncCfg
,
&
(
pRaftCfg
->
cfg
));
ASSERT
(
code
==
0
);
...
...
source/libs/sync/test/syncConfigChangeTest.cpp
浏览文件 @
bdc9acbf
...
...
@@ -93,7 +93,6 @@ SSyncFSM* createFsm() {
pFsm
->
FpGetSnapshot
=
GetSnapshotCb
;
pFsm
->
FpRestoreFinishCb
=
RestoreFinishCb
;
pFsm
->
FpReConfigCb
=
ReConfigCb
;
return
pFsm
;
...
...
source/libs/sync/test/syncRaftCfgTest.cpp
浏览文件 @
bdc9acbf
...
...
@@ -71,7 +71,10 @@ void test3() {
if
(
taosCheckExistFile
(
s
))
{
printf
(
"%s file: %s already exist!
\n
"
,
(
char
*
)
__FUNCTION__
,
s
);
}
else
{
raftCfgCreateFile
(
pCfg
,
7
,
s
);
SRaftCfgMeta
meta
;
meta
.
isStandBy
=
7
;
meta
.
snapshotEnable
=
9
;
raftCfgCreateFile
(
pCfg
,
meta
,
s
);
printf
(
"%s create json file: %s
\n
"
,
(
char
*
)
__FUNCTION__
,
s
);
}
...
...
@@ -94,6 +97,7 @@ void test5() {
pCfg
->
cfg
.
myIndex
=
taosGetTimestampSec
();
pCfg
->
isStandBy
+=
2
;
pCfg
->
snapshotEnable
+=
3
;
raftCfgPersist
(
pCfg
);
printf
(
"%s update json file: %s myIndex->%d
\n
"
,
(
char
*
)
__FUNCTION__
,
"./test3_raft_cfg.json"
,
pCfg
->
cfg
.
myIndex
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录