Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
d95e8e1f
TDengine
项目概览
taosdata
/
TDengine
大约 1 年 前同步成功
通知
1184
Star
22015
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看板
体验新版 GitCode,发现更多精彩内容 >>
提交
d95e8e1f
编写于
10月 28, 2021
作者:
S
Shengliang Guan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Call wal and sync code in vnode
上级
8ad7c2fd
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
129 addition
and
67 deletion
+129
-67
include/libs/sync/sync.h
include/libs/sync/sync.h
+12
-12
include/libs/wal/wal.h
include/libs/wal/wal.h
+29
-29
source/libs/wal/src/wal.c
source/libs/wal/src/wal.c
+14
-2
source/server/vnode/inc/vnodeFile.h
source/server/vnode/inc/vnodeFile.h
+2
-2
source/server/vnode/inc/vnodeInt.h
source/server/vnode/inc/vnodeInt.h
+1
-1
source/server/vnode/src/vnodeFile.c
source/server/vnode/src/vnodeFile.c
+4
-4
source/server/vnode/src/vnodeMain.c
source/server/vnode/src/vnodeMain.c
+67
-17
未找到文件。
include/libs/sync/sync.h
浏览文件 @
d95e8e1f
...
...
@@ -46,14 +46,14 @@ typedef struct {
}
SNodeInfo
;
typedef
struct
{
int
selfIndex
;
int
replica
;
int
32_t
selfIndex
;
int
32_t
replica
;
SNodeInfo
nodeInfo
[
TSDB_MAX_REPLICA
];
}
SSyncCluster
;
typedef
struct
{
int32_t
selfIndex
;
int
replica
;
int
32_t
replica
;
SNodeInfo
node
[
TSDB_MAX_REPLICA
];
ESyncRole
role
[
TSDB_MAX_REPLICA
];
}
SNodesRole
;
...
...
@@ -62,20 +62,20 @@ typedef struct SSyncFSM {
void
*
pData
;
// apply committed log, bufs will be free by raft module
int
(
*
applyLog
)(
struct
SSyncFSM
*
fsm
,
SyncIndex
index
,
const
SSyncBuffer
*
buf
,
void
*
pData
);
int
32_t
(
*
applyLog
)(
struct
SSyncFSM
*
fsm
,
SyncIndex
index
,
const
SSyncBuffer
*
buf
,
void
*
pData
);
// cluster commit callback
int
(
*
onClusterChanged
)(
struct
SSyncFSM
*
fsm
,
const
SSyncCluster
*
cluster
,
void
*
pData
);
int
32_t
(
*
onClusterChanged
)(
struct
SSyncFSM
*
fsm
,
const
SSyncCluster
*
cluster
,
void
*
pData
);
// fsm return snapshot in ppBuf, bufs will be free by raft module
// TODO: getSnapshot SHOULD be async?
int
(
*
getSnapshot
)(
struct
SSyncFSM
*
fsm
,
SSyncBuffer
**
ppBuf
,
in
t
*
objId
,
bool
*
isLast
);
int
32_t
(
*
getSnapshot
)(
struct
SSyncFSM
*
fsm
,
SSyncBuffer
**
ppBuf
,
int32_
t
*
objId
,
bool
*
isLast
);
// fsm apply snapshot with pBuf data
int
(
*
applySnapshot
)(
struct
SSyncFSM
*
fsm
,
SSyncBuffer
*
pBuf
,
in
t
objId
,
bool
isLast
);
int
32_t
(
*
applySnapshot
)(
struct
SSyncFSM
*
fsm
,
SSyncBuffer
*
pBuf
,
int32_
t
objId
,
bool
isLast
);
// call when restore snapshot and log done
int
(
*
onRestoreDone
)(
struct
SSyncFSM
*
fsm
);
int
32_t
(
*
onRestoreDone
)(
struct
SSyncFSM
*
fsm
);
void
(
*
onRollback
)(
struct
SSyncFSM
*
fsm
,
SyncIndex
index
,
const
SSyncBuffer
*
buf
);
...
...
@@ -118,9 +118,9 @@ typedef struct SSyncClusterConfig {
typedef
struct
SStateManager
{
void
*
pData
;
void
(
*
saveServerState
)(
struct
SStateManager
*
stateMng
,
const
SSyncServerState
*
state
);
int32_t
(
*
saveServerState
)(
struct
SStateManager
*
stateMng
,
SSyncServerState
*
state
);
const
SSyncServerState
*
(
*
readServerState
)(
struct
SStateManager
*
stateMng
);
int32_t
(
*
readServerState
)(
struct
SStateManager
*
stateMng
,
SSyncServerState
*
state
);
// void (*saveCluster)(struct SStateManager* stateMng, const SSyncClusterConfig* cluster);
...
...
@@ -148,9 +148,9 @@ void syncStop(const SSyncNode*);
int32_t
syncPropose
(
SSyncNode
*
syncNode
,
SSyncBuffer
buffer
,
void
*
pData
,
bool
isWeak
);
//int32_t syncAddNode(SSyncNode syncNode, const SNodeInfo *pNode);
//
int32_t syncAddNode(SSyncNode syncNode, const SNodeInfo *pNode);
//int32_t syncRemoveNode(SSyncNode syncNode, const SNodeInfo *pNode);
//
int32_t syncRemoveNode(SSyncNode syncNode, const SNodeInfo *pNode);
extern
int32_t
syncDebugFlag
;
...
...
include/libs/wal/wal.h
浏览文件 @
d95e8e1f
...
...
@@ -44,41 +44,41 @@ typedef struct {
EWalType
walLevel
;
// wal level
}
SWalCfg
;
typedef
void
*
twalh
;
// WAL HANDLE
typedef
int32_t
FWalWrite
(
void
*
ahandle
,
void
*
pHead
,
int32_t
qtype
,
void
*
pMsg
);
struct
SWal
;
typedef
struct
SWal
SWal
;
// WAL HANDLE
typedef
int32_t
(
*
FWalWrite
)(
void
*
ahandle
,
void
*
pHead
,
int32_t
qtype
,
void
*
pMsg
);
//module initialization
int32_t
walInit
();
void
walCleanUp
();
//
module initialization
int32_t
walInit
();
void
walCleanUp
();
//handle open and ctl
twalh
walOpen
(
char
*
path
,
SWalCfg
*
pCfg
);
int32_t
walAlter
(
twalh
,
SWalCfg
*
pCfg
);
void
walStop
(
twalh
);
void
walClose
(
twalh
);
// handle open and ctl
SWal
*
walOpen
(
char
*
path
,
SWalCfg
*
pCfg
);
int32_t
walAlter
(
SWal
*
,
SWalCfg
*
pCfg
);
void
walClose
(
SWal
*
);
//write
//
int64_t walWriteWithMsgType(twalh
, int8_t msgType, void* body, int32_t bodyLen);
int64_t
walWrite
(
twalh
,
void
*
body
,
int32_t
bodyLen
);
int64_t
walWriteBatch
(
twalh
,
void
**
bodies
,
int32_t
*
bodyLen
,
int32_t
batchSize
);
//
write
//
int64_t walWriteWithMsgType(SWal*
, int8_t msgType, void* body, int32_t bodyLen);
int64_t
walWrite
(
SWal
*
,
int64_t
index
,
void
*
body
,
int32_t
bodyLen
);
int64_t
walWriteBatch
(
SWal
*
,
void
**
bodies
,
int32_t
*
bodyLen
,
int32_t
batchSize
);
//apis for lifecycle management
void
walFsync
(
twalh
,
bool
force
);
int32_t
walCommit
(
twalh
,
int64_t
ver
);
//truncate after
int32_t
walRollback
(
twalh
,
int64_t
ver
);
//notify that previous log can be pruned safely
int32_t
walPrune
(
twalh
,
int64_t
ver
);
//
apis for lifecycle management
void
walFsync
(
SWal
*
,
bool
force
);
int32_t
walCommit
(
SWal
*
,
int64_t
ver
);
//
truncate after
int32_t
walRollback
(
SWal
*
,
int64_t
ver
);
//
notify that previous log can be pruned safely
int32_t
walPrune
(
SWal
*
,
int64_t
ver
);
//read
int32_t
walRead
(
twalh
,
SWalHead
**
,
int64_t
ver
);
int32_t
walReadWithFp
(
twalh
,
FWalWrite
writeFp
,
int64_t
verStart
,
in
t
readNum
);
//
read
int32_t
walRead
(
SWal
*
,
SWalHead
**
,
int64_t
ver
);
int32_t
walReadWithFp
(
SWal
*
,
FWalWrite
writeFp
,
int64_t
verStart
,
int32_
t
readNum
);
//lifecycle check
int32_t
walFirstVer
(
twalh
);
int32_t
walPersistedVer
(
twalh
);
int32_t
walLastVer
(
twalh
);
//
int32_t walDataCorrupted(twalh
);
//
lifecycle check
int32_t
walFirstVer
(
SWal
*
);
int32_t
walPersistedVer
(
SWal
*
);
int32_t
walLastVer
(
SWal
*
);
//
int32_t walDataCorrupted(SWal*
);
#ifdef __cplusplus
}
...
...
source/libs/wal/src/wal.c
浏览文件 @
d95e8e1f
...
...
@@ -19,6 +19,18 @@ int32_t walInit() { return 0; }
void
walCleanUp
()
{}
twalh
walOpen
(
char
*
path
,
SWalCfg
*
pCfg
)
{
return
NULL
;
}
SWal
*
walOpen
(
char
*
path
,
SWalCfg
*
pCfg
)
{
return
NULL
;
}
int32_t
walAlter
(
twalh
pWal
,
SWalCfg
*
pCfg
)
{
return
0
;
}
\ No newline at end of file
int32_t
walAlter
(
SWal
*
pWal
,
SWalCfg
*
pCfg
)
{
return
0
;
}
void
walClose
(
SWal
*
pWal
)
{}
void
walFsync
(
SWal
*
pWal
,
bool
force
)
{}
int64_t
walWrite
(
SWal
*
pWal
,
int64_t
index
,
void
*
body
,
int32_t
bodyLen
)
{}
int32_t
walCommit
(
SWal
*
pWal
,
int64_t
ver
)
{
return
0
;
}
int32_t
walRollback
(
SWal
*
pWal
,
int64_t
ver
)
{
return
0
;
}
int32_t
walPrune
(
SWal
*
pWal
,
int64_t
ver
)
{
return
0
;
}
\ No newline at end of file
source/server/vnode/inc/vnodeFile.h
浏览文件 @
d95e8e1f
...
...
@@ -23,8 +23,8 @@ extern "C" {
int32_t
vnodeReadCfg
(
int32_t
vgId
,
SVnodeCfg
*
pCfg
);
int32_t
vnodeWriteCfg
(
int32_t
vgId
,
SVnodeCfg
*
pCfg
);
int32_t
vnodeRead
Term
(
int32_t
vgId
,
SSyncServerState
*
pState
);
int32_t
vnode
WriteTerm
(
int32_t
vgid
,
SSyncServerState
*
pState
);
int32_t
vnodeRead
State
(
int32_t
vgId
,
SSyncServerState
*
pState
);
int32_t
vnode
SaveState
(
int32_t
vgid
,
SSyncServerState
*
pState
);
#ifdef __cplusplus
}
...
...
source/server/vnode/inc/vnodeInt.h
浏览文件 @
d95e8e1f
...
...
@@ -79,7 +79,7 @@ typedef struct {
SMeta
*
pMeta
;
STsdb
*
pTsdb
;
STQ
*
pTQ
;
twalh
pWal
;
SWal
*
pWal
;
void
*
pQuery
;
SSyncNode
*
pSync
;
taos_queue
pWriteQ
;
// write queue
...
...
source/server/vnode/src/vnodeFile.c
浏览文件 @
d95e8e1f
...
...
@@ -296,7 +296,7 @@ int32_t vnodeWriteCfg(int32_t vgId, SVnodeCfg *pCfg) {
return
TSDB_CODE_SUCCESS
;
}
int32_t
vnodeRead
Term
(
int32_t
vgId
,
SSyncServerState
*
pState
)
{
int32_t
vnodeRead
State
(
int32_t
vgId
,
SSyncServerState
*
pState
)
{
int32_t
ret
=
TSDB_CODE_VND_APP_ERROR
;
int32_t
len
=
0
;
int32_t
maxLen
=
100
;
...
...
@@ -305,7 +305,7 @@ int32_t vnodeReadTerm(int32_t vgId, SSyncServerState *pState) {
FILE
*
fp
=
NULL
;
char
file
[
PATH_MAX
+
30
]
=
{
0
};
sprintf
(
file
,
"%s/vnode%d/
term
.json"
,
tsVnodeDir
,
vgId
);
sprintf
(
file
,
"%s/vnode%d/
state
.json"
,
tsVnodeDir
,
vgId
);
len
=
(
int32_t
)
fread
(
content
,
1
,
maxLen
,
fp
);
if
(
len
<=
0
)
{
...
...
@@ -343,9 +343,9 @@ PARSE_TERM_ERROR:
return
ret
;
}
int32_t
vnode
WriteTerm
(
int32_t
vgId
,
SSyncServerState
*
pState
)
{
int32_t
vnode
SaveState
(
int32_t
vgId
,
SSyncServerState
*
pState
)
{
char
file
[
PATH_MAX
+
30
]
=
{
0
};
sprintf
(
file
,
"%s/vnode%d/
term
.json"
,
tsVnodeDir
,
vgId
);
sprintf
(
file
,
"%s/vnode%d/
state
.json"
,
tsVnodeDir
,
vgId
);
FILE
*
fp
=
fopen
(
file
,
"w"
);
if
(
!
fp
)
{
...
...
source/server/vnode/src/vnodeMain.c
浏览文件 @
d95e8e1f
...
...
@@ -130,7 +130,8 @@ static void vnodeDestroyVnode(SVnode *pVnode) {
}
if
(
pVnode
->
pWal
)
{
// todo
walClose
(
pVnode
->
pWal
);
pVnode
->
pWal
=
NULL
;
}
if
(
pVnode
->
allocator
)
{
...
...
@@ -166,6 +167,56 @@ static void vnodeCleanupVnode(SVnode *pVnode) {
vnodeRelease
(
pVnode
);
}
static
inline
int32_t
vnodeLogWrite
(
struct
SSyncLogStore
*
logStore
,
SyncIndex
index
,
SSyncBuffer
*
pBuf
)
{
SVnode
*
pVnode
=
logStore
->
pData
;
// vnode status can be checked here
return
walWrite
(
pVnode
->
pWal
,
index
,
pBuf
->
data
,
(
int32_t
)
pBuf
->
len
);
}
static
inline
int32_t
vnodeLogCommit
(
struct
SSyncLogStore
*
logStore
,
SyncIndex
index
)
{
SVnode
*
pVnode
=
logStore
->
pData
;
// vnode status can be checked here
return
walCommit
(
pVnode
->
pWal
,
index
);
}
static
inline
int32_t
vnodeLogPrune
(
struct
SSyncLogStore
*
logStore
,
SyncIndex
index
)
{
SVnode
*
pVnode
=
logStore
->
pData
;
// vnode status can be checked here
return
walPrune
(
pVnode
->
pWal
,
index
);
}
static
inline
int32_t
vnodeLogRollback
(
struct
SSyncLogStore
*
logStore
,
SyncIndex
index
)
{
SVnode
*
pVnode
=
logStore
->
pData
;
// vnode status can be checked here
return
walRollback
(
pVnode
->
pWal
,
index
);
}
static
inline
int32_t
vnodeSaveServerState
(
struct
SStateManager
*
stateMng
,
SSyncServerState
*
pState
)
{
SVnode
*
pVnode
=
stateMng
->
pData
;
return
vnodeSaveState
(
pVnode
->
vgId
,
pState
);
}
static
inline
int32_t
vnodeReadServerState
(
struct
SStateManager
*
stateMng
,
SSyncServerState
*
pState
)
{
SVnode
*
pVnode
=
stateMng
->
pData
;
return
vnodeSaveState
(
pVnode
->
vgId
,
pState
);
}
static
inline
int32_t
vnodeApplyLog
(
struct
SSyncFSM
*
fsm
,
SyncIndex
index
,
const
SSyncBuffer
*
buf
,
void
*
pData
)
{
return
0
;
}
static
inline
int32_t
vnodeOnClusterChanged
(
struct
SSyncFSM
*
fsm
,
const
SSyncCluster
*
cluster
,
void
*
pData
)
{
return
0
;
}
static
inline
int32_t
vnodeGetSnapshot
(
struct
SSyncFSM
*
fsm
,
SSyncBuffer
**
ppBuf
,
int32_t
*
objId
,
bool
*
isLast
)
{
return
0
;
}
static
inline
int32_t
vnodeApplySnapshot
(
struct
SSyncFSM
*
fsm
,
SSyncBuffer
*
pBuf
,
int32_t
objId
,
bool
isLast
)
{
return
0
;
}
static
inline
int32_t
vnodeOnRestoreDone
(
struct
SSyncFSM
*
fsm
)
{
return
0
;
}
static
inline
void
vnodeOnRollback
(
struct
SSyncFSM
*
fsm
,
SyncIndex
index
,
const
SSyncBuffer
*
buf
)
{}
static
inline
void
vnodeOnRoleChanged
(
struct
SSyncFSM
*
fsm
,
const
SNodesRole
*
pRole
)
{}
static
int32_t
vnodeOpenVnode
(
int32_t
vgId
)
{
int32_t
code
=
0
;
...
...
@@ -193,7 +244,7 @@ static int32_t vnodeOpenVnode(int32_t vgId) {
return
0
;
}
code
=
vnode
ReadTerm
(
vgId
,
&
pVnode
->
term
);
code
=
vnode
SaveState
(
vgId
,
&
pVnode
->
term
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
vError
(
"vgId:%d, failed to read term file since %s"
,
pVnode
->
vgId
,
tstrerror
(
code
));
pVnode
->
cfg
.
dropped
=
1
;
...
...
@@ -220,25 +271,24 @@ static int32_t vnodeOpenVnode(int32_t vgId) {
// create sync node
SSyncInfo
syncInfo
=
{
0
};
syncInfo
.
vgId
=
vgId
;
syncInfo
.
snapshotIndex
=
0
;
// todo, from tsdb
syncInfo
.
snapshotIndex
=
0
;
// todo, from tsdb
memcpy
(
&
syncInfo
.
syncCfg
,
&
pVnode
->
cfg
.
sync
,
sizeof
(
SSyncCluster
));
syncInfo
.
fsm
.
pData
=
pVnode
;
syncInfo
.
fsm
.
applyLog
=
NULL
;
syncInfo
.
fsm
.
onClusterChanged
=
NULL
;
syncInfo
.
fsm
.
getSnapshot
=
NULL
;
syncInfo
.
fsm
.
applySnapshot
=
NULL
;
syncInfo
.
fsm
.
onRestoreDone
=
NULL
;
syncInfo
.
fsm
.
onRollback
=
NULL
;
syncInfo
.
fsm
.
applyLog
=
vnodeApplyLog
;
syncInfo
.
fsm
.
onClusterChanged
=
vnodeOnClusterChanged
;
syncInfo
.
fsm
.
getSnapshot
=
vnodeGetSnapshot
;
syncInfo
.
fsm
.
applySnapshot
=
vnodeApplySnapshot
;
syncInfo
.
fsm
.
onRestoreDone
=
vnodeOnRestoreDone
;
syncInfo
.
fsm
.
onRollback
=
vnodeOnRollback
;
syncInfo
.
fsm
.
onRoleChanged
=
vnodeOnRoleChanged
;
syncInfo
.
logStore
.
pData
=
pVnode
;
syncInfo
.
logStore
.
logWrite
=
NULL
;
syncInfo
.
logStore
.
logCommit
=
NULL
;
syncInfo
.
logStore
.
logPrune
=
NULL
;
syncInfo
.
logStore
.
logRollback
=
NULL
;
syncInfo
.
logStore
.
logWrite
=
vnodeLogWrite
;
syncInfo
.
logStore
.
logCommit
=
vnodeLogCommit
;
syncInfo
.
logStore
.
logPrune
=
vnodeLogPrune
;
syncInfo
.
logStore
.
logRollback
=
vnodeLogRollback
;
syncInfo
.
stateManager
.
pData
=
pVnode
;
syncInfo
.
stateManager
.
saveServerState
=
NULL
;
syncInfo
.
stateManager
.
readServerState
=
NULL
;
// syncInfo.stateManager.saveCluster = NULL;
// syncInfo.stateManager.readCluster = NULL;
syncInfo
.
stateManager
.
saveServerState
=
vnodeSaveServerState
;
syncInfo
.
stateManager
.
readServerState
=
vnodeReadServerState
;
pVnode
->
pSync
=
syncStart
(
&
syncInfo
);
if
(
pVnode
->
pSync
==
NULL
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录