Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
ff91282b
T
TDengine
项目概览
taosdata
/
TDengine
12 个月 前同步成功
通知
1180
Star
22014
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看板
体验新版 GitCode,发现更多精彩内容 >>
提交
ff91282b
编写于
5月 20, 2022
作者:
S
Shengliang Guan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactor: adjust vnode sync
上级
f2a84eda
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
41 addition
and
51 deletion
+41
-51
source/dnode/vnode/src/vnd/vnodeOpen.c
source/dnode/vnode/src/vnd/vnodeOpen.c
+0
-1
source/dnode/vnode/src/vnd/vnodeSync.c
source/dnode/vnode/src/vnd/vnodeSync.c
+41
-50
未找到文件。
source/dnode/vnode/src/vnd/vnodeOpen.c
浏览文件 @
ff91282b
...
@@ -180,7 +180,6 @@ void vnodeClose(SVnode *pVnode) {
...
@@ -180,7 +180,6 @@ void vnodeClose(SVnode *pVnode) {
// start the sync timer after the queue is ready
// start the sync timer after the queue is ready
int32_t
vnodeStart
(
SVnode
*
pVnode
)
{
int32_t
vnodeStart
(
SVnode
*
pVnode
)
{
vnodeSyncSetMsgCb
(
pVnode
);
vnodeSyncStart
(
pVnode
);
vnodeSyncStart
(
pVnode
);
return
0
;
return
0
;
}
}
...
...
source/dnode/vnode/src/vnd/vnodeSync.c
浏览文件 @
ff91282b
...
@@ -13,71 +13,62 @@
...
@@ -13,71 +13,62 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
*/
#define _DEFAULT_SOURCE
#include "vnd.h"
#include "vnd.h"
int32_t
vnodeSyncOpen
(
SVnode
*
pVnode
,
char
*
path
)
{
static
int32_t
vnodeSyncEqMsg
(
const
SMsgCb
*
msgcb
,
SRpcMsg
*
pMsg
);
SSyncInfo
syncInfo
;
static
int32_t
vnodeSyncSendMsg
(
const
SEpSet
*
pEpSet
,
SRpcMsg
*
pMsg
);
syncInfo
.
vgId
=
pVnode
->
config
.
vgId
;
static
SSyncFSM
*
vnodeSyncMakeFsm
(
SVnode
*
pVnode
);
SSyncCfg
*
pCfg
=
&
(
syncInfo
.
syncCfg
);
static
void
vnodeSyncCommitMsg
(
SSyncFSM
*
pFsm
,
const
SRpcMsg
*
pMsg
,
SFsmCbMeta
cbMeta
);
pCfg
->
replicaNum
=
pVnode
->
config
.
syncCfg
.
replicaNum
;
static
void
vnodeSyncPreCommitMsg
(
SSyncFSM
*
pFsm
,
const
SRpcMsg
*
pMsg
,
SFsmCbMeta
cbMeta
);
pCfg
->
myIndex
=
pVnode
->
config
.
syncCfg
.
myIndex
;
static
void
vnodeSyncRollBackMsg
(
SSyncFSM
*
pFsm
,
const
SRpcMsg
*
pMsg
,
SFsmCbMeta
cbMeta
);
memcpy
(
pCfg
->
nodeInfo
,
pVnode
->
config
.
syncCfg
.
nodeInfo
,
sizeof
(
pCfg
->
nodeInfo
));
static
int32_t
vnodeSyncGetSnapshot
(
SSyncFSM
*
pFsm
,
SSnapshot
*
pSnapshot
);
snprintf
(
syncInfo
.
path
,
sizeof
(
syncInfo
.
path
),
"%s/sync"
,
path
);
syncInfo
.
pWal
=
pVnode
->
pWal
;
syncInfo
.
pFsm
=
syncVnodeMakeFsm
(
pVnode
);
int32_t
vnodeSyncOpen
(
SVnode
*
pVnode
,
char
*
path
)
{
syncInfo
.
msgcb
=
NULL
;
SSyncInfo
syncInfo
=
{
syncInfo
.
FpSendMsg
=
vnodeSyncSendMsg
;
.
vgId
=
pVnode
->
config
.
vgId
,
syncInfo
.
FpEqMsg
=
vnodeSyncEqMsg
;
.
syncCfg
=
pVnode
->
config
.
syncCfg
,
.
pWal
=
pVnode
->
pWal
,
.
msgcb
=
NULL
,
.
FpSendMsg
=
vnodeSyncSendMsg
,
.
FpEqMsg
=
vnodeSyncEqMsg
,
};
snprintf
(
syncInfo
.
path
,
sizeof
(
syncInfo
.
path
),
"%s%ssync"
,
path
,
TD_DIRSEP
);
syncInfo
.
pFsm
=
vnodeSyncMakeFsm
(
pVnode
);
pVnode
->
sync
=
syncOpen
(
&
syncInfo
);
pVnode
->
sync
=
syncOpen
(
&
syncInfo
);
assert
(
pVnode
->
sync
>
0
);
if
(
pVnode
->
sync
<=
0
)
{
vError
(
"vgId:%d, failed to open sync since %s"
,
pVnode
->
config
.
vgId
,
terrstr
());
return
-
1
;
}
// for test
setPingTimerMS
(
pVnode
->
sync
,
3000
);
setPingTimerMS
(
pVnode
->
sync
,
3000
);
setElectTimerMS
(
pVnode
->
sync
,
500
);
setElectTimerMS
(
pVnode
->
sync
,
500
);
setHeartbeatTimerMS
(
pVnode
->
sync
,
100
);
setHeartbeatTimerMS
(
pVnode
->
sync
,
100
);
return
0
;
return
0
;
}
}
int32_t
vnodeSyncStart
(
SVnode
*
pVnode
)
{
void
vnodeSyncStart
(
SVnode
*
pVnode
)
{
syncSetMsgCb
(
pVnode
->
sync
,
&
pVnode
->
msgCb
);
syncStart
(
pVnode
->
sync
);
syncStart
(
pVnode
->
sync
);
return
0
;
}
}
void
vnodeSyncClose
(
SVnode
*
pVnode
)
{
void
vnodeSyncClose
(
SVnode
*
pVnode
)
{
syncStop
(
pVnode
->
sync
);
}
// stop by ref id
syncStop
(
pVnode
->
sync
);
}
void
vnodeSyncSetMsgCb
(
SVnode
*
pVnode
)
{
syncSetMsgCb
(
pVnode
->
sync
,
&
pVnode
->
msgCb
);
}
int32_t
vnodeSyncEqMsg
(
const
SMsgCb
*
msgcb
,
SRpcMsg
*
pMsg
)
{
return
tmsgPutToQueue
(
msgcb
,
SYNC_QUEUE
,
pMsg
);
}
int32_t
vnodeSyncEqMsg
(
const
SMsgCb
*
msgcb
,
SRpcMsg
*
pMsg
)
{
return
tmsgPutToQueue
(
msgcb
,
SYNC_QUEUE
,
pMsg
);
}
int32_t
vnodeSyncSendMsg
(
const
SEpSet
*
pEpSet
,
SRpcMsg
*
pMsg
)
{
int32_t
vnodeSyncSendMsg
(
const
SEpSet
*
pEpSet
,
SRpcMsg
*
pMsg
)
{
return
tmsgSendReq
(
pEpSet
,
pMsg
);
}
pMsg
->
info
.
noResp
=
1
;
return
tmsgSendReq
(
pEpSet
,
pMsg
);
}
int32_t
vnodeSyncGetSnapshotCb
(
struct
SSyncFSM
*
pFsm
,
SSnapshot
*
pSnapshot
)
{
SVnode
*
pVnode
=
(
SVnode
*
)(
pFsm
->
data
);
vnodeGetSnapshot
(
pVnode
,
pSnapshot
);
/*
pSnapshot->data = NULL;
pSnapshot->lastApplyIndex = 0;
pSnapshot->lastApplyTerm = 0;
*/
int32_t
vnodeSyncGetSnapshot
(
SSyncFSM
*
pFsm
,
SSnapshot
*
pSnapshot
)
{
vnodeGetSnapshot
(
pFsm
->
data
,
pSnapshot
);
return
0
;
return
0
;
}
}
void
vnodeSyncCommit
Cb
(
struct
SSyncFSM
*
pFsm
,
const
SRpcMsg
*
pMsg
,
SFsmCbMeta
cbMeta
)
{
void
vnodeSyncCommit
Msg
(
SSyncFSM
*
pFsm
,
const
SRpcMsg
*
pMsg
,
SFsmCbMeta
cbMeta
)
{
SyncIndex
beginIndex
=
SYNC_INDEX_INVALID
;
SyncIndex
beginIndex
=
SYNC_INDEX_INVALID
;
if
(
pFsm
->
FpGetSnapshot
!=
NULL
)
{
if
(
pFsm
->
FpGetSnapshot
!=
NULL
)
{
SSnapshot
snapshot
;
SSnapshot
snapshot
=
{
0
}
;
pFsm
->
FpGetSnapshot
(
pFsm
,
&
snapshot
);
pFsm
->
FpGetSnapshot
(
pFsm
,
&
snapshot
);
beginIndex
=
snapshot
.
lastApplyIndex
;
beginIndex
=
snapshot
.
lastApplyIndex
;
}
}
...
@@ -128,7 +119,7 @@ void vnodeSyncCommitCb(struct SSyncFSM *pFsm, const SRpcMsg *pMsg, SFsmCbMeta cb
...
@@ -128,7 +119,7 @@ void vnodeSyncCommitCb(struct SSyncFSM *pFsm, const SRpcMsg *pMsg, SFsmCbMeta cb
}
}
}
}
void
vnodeSyncPreCommit
Cb
(
struct
SSyncFSM
*
pFsm
,
const
SRpcMsg
*
pMsg
,
SFsmCbMeta
cbMeta
)
{
void
vnodeSyncPreCommit
Msg
(
SSyncFSM
*
pFsm
,
const
SRpcMsg
*
pMsg
,
SFsmCbMeta
cbMeta
)
{
char
logBuf
[
256
];
char
logBuf
[
256
];
snprintf
(
logBuf
,
sizeof
(
logBuf
),
snprintf
(
logBuf
,
sizeof
(
logBuf
),
"==callback== ==PreCommitCb== pFsm:%p, index:%ld, isWeak:%d, code:%d, state:%d %s
\n
"
,
pFsm
,
cbMeta
.
index
,
"==callback== ==PreCommitCb== pFsm:%p, index:%ld, isWeak:%d, code:%d, state:%d %s
\n
"
,
pFsm
,
cbMeta
.
index
,
...
@@ -136,19 +127,19 @@ void vnodeSyncPreCommitCb(struct SSyncFSM *pFsm, const SRpcMsg *pMsg, SFsmCbMeta
...
@@ -136,19 +127,19 @@ void vnodeSyncPreCommitCb(struct SSyncFSM *pFsm, const SRpcMsg *pMsg, SFsmCbMeta
syncRpcMsgLog2
(
logBuf
,
(
SRpcMsg
*
)
pMsg
);
syncRpcMsgLog2
(
logBuf
,
(
SRpcMsg
*
)
pMsg
);
}
}
void
vnodeSyncRollBack
Cb
(
struct
SSyncFSM
*
pFsm
,
const
SRpcMsg
*
pMsg
,
SFsmCbMeta
cbMeta
)
{
void
vnodeSyncRollBack
Msg
(
SSyncFSM
*
pFsm
,
const
SRpcMsg
*
pMsg
,
SFsmCbMeta
cbMeta
)
{
char
logBuf
[
256
];
char
logBuf
[
256
];
snprintf
(
logBuf
,
sizeof
(
logBuf
),
"==callback== ==RollBackCb== pFsm:%p, index:%ld, isWeak:%d, code:%d, state:%d %s
\n
"
,
snprintf
(
logBuf
,
sizeof
(
logBuf
),
"==callback== ==RollBackCb== pFsm:%p, index:%ld, isWeak:%d, code:%d, state:%d %s
\n
"
,
pFsm
,
cbMeta
.
index
,
cbMeta
.
isWeak
,
cbMeta
.
code
,
cbMeta
.
state
,
syncUtilState2String
(
cbMeta
.
state
));
pFsm
,
cbMeta
.
index
,
cbMeta
.
isWeak
,
cbMeta
.
code
,
cbMeta
.
state
,
syncUtilState2String
(
cbMeta
.
state
));
syncRpcMsgLog2
(
logBuf
,
(
SRpcMsg
*
)
pMsg
);
syncRpcMsgLog2
(
logBuf
,
(
SRpcMsg
*
)
pMsg
);
}
}
SSyncFSM
*
syncVnode
MakeFsm
(
SVnode
*
pVnode
)
{
SSyncFSM
*
vnodeSync
MakeFsm
(
SVnode
*
pVnode
)
{
SSyncFSM
*
pFsm
=
(
SSyncFSM
*
)
taosMemoryMalloc
(
sizeof
(
SSyncFSM
));
SSyncFSM
*
pFsm
=
taosMemoryCalloc
(
1
,
sizeof
(
SSyncFSM
));
pFsm
->
data
=
pVnode
;
pFsm
->
data
=
pVnode
;
pFsm
->
FpCommitCb
=
vnodeSyncCommit
Cb
;
pFsm
->
FpCommitCb
=
vnodeSyncCommit
Msg
;
pFsm
->
FpPreCommitCb
=
vnodeSyncPreCommit
Cb
;
pFsm
->
FpPreCommitCb
=
vnodeSyncPreCommit
Msg
;
pFsm
->
FpRollBackCb
=
vnodeSyncRollBack
Cb
;
pFsm
->
FpRollBackCb
=
vnodeSyncRollBack
Msg
;
pFsm
->
FpGetSnapshot
=
vnodeSyncGetSnapshot
Cb
;
pFsm
->
FpGetSnapshot
=
vnodeSyncGetSnapshot
;
return
pFsm
;
return
pFsm
;
}
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录