Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
631c9668
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看板
未验证
提交
631c9668
编写于
4月 15, 2022
作者:
H
Hongze Cheng
提交者:
GitHub
4月 15, 2022
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #11526 from taosdata/feature/vnode_refact
refactor: vnode
上级
85496cbb
29c06246
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
141 addition
and
11 deletion
+141
-11
source/dnode/vnode/CMakeLists.txt
source/dnode/vnode/CMakeLists.txt
+1
-1
source/dnode/vnode/inc/vnode.h
source/dnode/vnode/inc/vnode.h
+3
-2
source/dnode/vnode/src/inc/vnd.h
source/dnode/vnode/src/inc/vnd.h
+8
-2
source/dnode/vnode/src/inc/vnodeInt.h
source/dnode/vnode/src/inc/vnodeInt.h
+6
-0
source/dnode/vnode/src/vnd/vnodeCfg.c
source/dnode/vnode/src/vnd/vnodeCfg.c
+6
-3
source/dnode/vnode/src/vnd/vnodeCommit.c
source/dnode/vnode/src/vnd/vnodeCommit.c
+86
-1
source/dnode/vnode/src/vnd/vnodeOpen.c
source/dnode/vnode/src/vnd/vnodeOpen.c
+31
-2
未找到文件。
source/dnode/vnode/CMakeLists.txt
浏览文件 @
631c9668
...
...
@@ -4,13 +4,13 @@ target_sources(
vnode
PRIVATE
# vnode
"src/vnd/vnodeOpen.c"
"src/vnd/vnodeArenaMAImpl.c"
"src/vnd/vnodeBufferPool.c"
# "src/vnd/vnodeBufferPool2.c"
"src/vnd/vnodeCfg.c"
"src/vnd/vnodeCommit.c"
"src/vnd/vnodeInt.c"
"src/vnd/vnodeMain.c"
"src/vnd/vnodeQuery.c"
"src/vnd/vnodeStateMgr.c"
"src/vnd/vnodeWrite.c"
...
...
source/dnode/vnode/inc/vnode.h
浏览文件 @
631c9668
...
...
@@ -42,11 +42,12 @@ typedef struct STsdbCfg STsdbCfg; // todo: remove
typedef
struct
STqCfg
STqCfg
;
// todo: remove
typedef
struct
SVnodeCfg
SVnodeCfg
;
int
vnodeInit
();
int
vnodeInit
(
int
nthreads
);
void
vnodeCleanup
();
int
vnodeCreate
(
const
char
*
path
,
SVnodeCfg
*
pCfg
,
STfs
*
pTfs
);
void
vnodeDestroy
(
const
char
*
path
);
SVnode
*
vnodeOpen
(
const
char
*
path
,
const
SVnodeCfg
*
pVnodeCfg
);
void
vnodeClose
(
SVnode
*
pVnode
);
void
vnodeDestroy
(
const
char
*
path
);
void
vnodePreprocessWriteReqs
(
SVnode
*
pVnode
,
SArray
*
pMsgs
);
int
vnodeProcessWriteReq
(
SVnode
*
pVnode
,
SRpcMsg
*
pMsg
,
SRpcMsg
**
pRsp
);
int
vnodeProcessCMsg
(
SVnode
*
pVnode
,
SRpcMsg
*
pMsg
,
SRpcMsg
**
pRsp
);
...
...
source/dnode/vnode/src/inc/vnd.h
浏览文件 @
631c9668
...
...
@@ -30,6 +30,8 @@ extern "C" {
#define vTrace(...) do { if (vDebugFlag & DEBUG_TRACE) { taosPrintLog("VND ", DEBUG_TRACE, vDebugFlag, __VA_ARGS__); }} while(0)
// clang-format on
// vnodeCfg ====================
// vnodeModule ====================
int
vnodeScheduleTask
(
int
(
*
execute
)(
void
*
),
void
*
arg
);
...
...
@@ -38,6 +40,10 @@ int vnodeQueryOpen(SVnode* pVnode);
void
vnodeQueryClose
(
SVnode
*
pVnode
);
int
vnodeGetTableMeta
(
SVnode
*
pVnode
,
SRpcMsg
*
pMsg
);
// vnodeCommit ====================
int
vnodeSaveInfo
(
const
char
*
dir
,
const
SVnodeInfo
*
pCfg
);
int
vnodeCommitInfo
(
const
char
*
dir
,
const
SVnodeInfo
*
pInfo
);
#if 1
// SVBufPool
int
vnodeOpenBufPool
(
SVnode
*
pVnode
);
...
...
@@ -75,9 +81,9 @@ void vmaFree(SVMemAllocator* pVMA, void* ptr);
bool
vmaIsFull
(
SVMemAllocator
*
pVMA
);
// vnodeCfg.h
extern
const
SVnodeCfg
defaultVnodeOptions
;
extern
const
SVnodeCfg
vnodeCfgDefault
;
int
vnode
ValidateOptions
(
const
SVnodeCfg
*
);
int
vnode
CheckCfg
(
const
SVnodeCfg
*
);
void
vnodeOptionsCopy
(
SVnodeCfg
*
pDest
,
const
SVnodeCfg
*
pSrc
);
// For commit
...
...
source/dnode/vnode/src/inc/vnodeInt.h
浏览文件 @
631c9668
...
...
@@ -43,6 +43,7 @@
extern
"C"
{
#endif
typedef
struct
SVnodeInfo
SVnodeInfo
;
typedef
struct
SMeta
SMeta
;
typedef
struct
STsdb
STsdb
;
typedef
struct
STQ
STQ
;
...
...
@@ -72,6 +73,11 @@ struct SVState {
int64_t
applied
;
};
struct
SVnodeInfo
{
SVnodeCfg
config
;
SVState
state
;
};
struct
SVnode
{
int32_t
vgId
;
char
*
path
;
...
...
source/dnode/vnode/src/vnd/vnodeCfg.c
浏览文件 @
631c9668
...
...
@@ -15,14 +15,15 @@
#include "vnodeInt.h"
const
SVnodeCfg
defaultVnodeOptions
=
{
.
wsize
=
96
*
1024
*
1024
,
.
ssize
=
1
*
1024
*
1024
,
.
lsize
=
1024
,
.
walCfg
=
{.
level
=
TAOS_WAL_WRITE
}};
/* TODO */
const
SVnodeCfg
vnodeCfgDefault
=
{
.
wsize
=
96
*
1024
*
1024
,
.
ssize
=
1
*
1024
*
1024
,
.
lsize
=
1024
,
.
walCfg
=
{.
level
=
TAOS_WAL_WRITE
}};
int
vnode
ValidateOptions
(
const
SVnodeCfg
*
pVnodeOptions
)
{
int
vnode
CheckCfg
(
const
SVnodeCfg
*
pCfg
)
{
// TODO
return
0
;
}
#if 1 //======================================================================
void
vnodeOptionsCopy
(
SVnodeCfg
*
pDest
,
const
SVnodeCfg
*
pSrc
)
{
memcpy
((
void
*
)
pDest
,
(
void
*
)
pSrc
,
sizeof
(
SVnodeCfg
));
}
...
...
@@ -46,3 +47,5 @@ int vnodeValidateTableHash(SVnodeCfg *pVnodeOptions, char *tableFName) {
return
TSDB_CODE_SUCCESS
;
}
#endif
\ No newline at end of file
source/dnode/vnode/src/vnd/vnodeCommit.c
浏览文件 @
631c9668
...
...
@@ -15,11 +15,86 @@
#include "vnodeInt.h"
#define VND_INFO_FNAME "vnode.json"
#define VND_INFO_FNAME_TMP "vnode_tmp.json"
static
int
vnodeEncodeInfo
(
const
SVnodeInfo
*
pInfo
,
uint8_t
**
ppData
,
int
*
len
);
static
int
vnodeDecodeInfo
(
uint8_t
*
pData
,
int
len
,
SVnodeInfo
*
pInfo
);
static
int
vnodeStartCommit
(
SVnode
*
pVnode
);
static
int
vnodeEndCommit
(
SVnode
*
pVnode
);
static
int
vnodeCommit
(
void
*
arg
);
static
void
vnodeWaitCommit
(
SVnode
*
pVnode
);
int
vnodeSaveInfo
(
const
char
*
dir
,
const
SVnodeInfo
*
pInfo
)
{
char
fname
[
TSDB_FILENAME_LEN
];
TdFilePtr
pFile
;
uint8_t
*
data
;
int
len
;
snprintf
(
fname
,
TSDB_FILENAME_LEN
,
"%s%s%s"
,
dir
,
TD_DIRSEP
,
VND_INFO_FNAME_TMP
);
// encode info
data
=
NULL
;
len
=
0
;
if
(
vnodeEncodeInfo
(
pInfo
,
&
data
,
&
len
)
<
0
)
{
return
-
1
;
}
// save info to a vnode_tmp.json
pFile
=
taosOpenFile
(
fname
,
TD_FILE_CREATE
|
TD_FILE_WRITE
|
TD_FILE_TRUNC
);
if
(
pFile
==
NULL
)
{
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
return
-
1
;
}
if
(
taosWriteFile
(
pFile
,
data
,
len
)
<
0
)
{
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
goto
_err
;
}
if
(
taosFsyncFile
(
pFile
)
<
0
)
{
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
goto
_err
;
}
taosCloseFile
(
&
pFile
);
// free info binary
taosMemoryFree
(
data
);
vInfo
(
"vgId: %d vnode info is saved, fname: %s"
,
pInfo
->
config
.
vgId
,
fname
);
return
0
;
_err:
taosCloseFile
(
&
pFile
);
taosMemoryFree
(
data
);
return
-
1
;
}
int
vnodeCommitInfo
(
const
char
*
dir
,
const
SVnodeInfo
*
pInfo
)
{
char
fname
[
TSDB_FILENAME_LEN
];
char
tfname
[
TSDB_FILENAME_LEN
];
snprintf
(
fname
,
TSDB_FILENAME_LEN
,
"%s%s%s"
,
dir
,
TD_DIRSEP
,
VND_INFO_FNAME
);
snprintf
(
tfname
,
TSDB_FILENAME_LEN
,
"%s%s%s"
,
dir
,
TD_DIRSEP
,
VND_INFO_FNAME_TMP
);
if
(
taosRenameFile
(
tfname
,
fname
)
<
0
)
{
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
return
-
1
;
}
vInfo
(
"vgId: %d vnode info is committed"
,
pInfo
->
config
.
vgId
);
return
0
;
}
int
vnodeLoadInfo
(
const
char
*
dir
)
{
// TODO
return
0
;
}
int
vnodeAsyncCommit
(
SVnode
*
pVnode
)
{
vnodeWaitCommit
(
pVnode
);
...
...
@@ -60,4 +135,14 @@ static int vnodeEndCommit(SVnode *pVnode) {
return
0
;
}
static
FORCE_INLINE
void
vnodeWaitCommit
(
SVnode
*
pVnode
)
{
tsem_wait
(
&
pVnode
->
canCommit
);
}
\ No newline at end of file
static
FORCE_INLINE
void
vnodeWaitCommit
(
SVnode
*
pVnode
)
{
tsem_wait
(
&
pVnode
->
canCommit
);
}
static
int
vnodeEncodeInfo
(
const
SVnodeInfo
*
pInfo
,
uint8_t
**
ppData
,
int
*
len
)
{
// TODO
return
0
;
}
static
int
vnodeDecodeInfo
(
uint8_t
*
pData
,
int
len
,
SVnodeInfo
*
pInfo
)
{
// TODO
return
0
;
}
source/dnode/vnode/src/vnd/vnode
Mai
n.c
→
source/dnode/vnode/src/vnd/vnode
Ope
n.c
浏览文件 @
631c9668
...
...
@@ -20,11 +20,40 @@ static void vnodeFree(SVnode *pVnode);
static
int
vnodeOpenImpl
(
SVnode
*
pVnode
);
static
void
vnodeCloseImpl
(
SVnode
*
pVnode
);
int
vnodeCreate
(
const
char
*
path
,
SVnodeCfg
*
pCfg
,
STfs
*
pTfs
)
{
SVnodeInfo
info
=
{
0
};
char
dir
[
TSDB_FILENAME_LEN
];
// TODO: check if directory exists
// check config
if
(
vnodeCheckCfg
(
pCfg
)
<
0
)
{
vError
(
"vgId: %d failed to create vnode since: %s"
,
pCfg
->
vgId
,
tstrerror
(
terrno
));
return
-
1
;
}
// create vnode env
if
(
tfsMkdir
(
pTfs
,
path
)
<
0
)
{
vError
(
"vgId: %d failed to create vnode since: %s"
,
pCfg
->
vgId
,
tstrerror
(
terrno
));
return
-
1
;
}
snprintf
(
dir
,
TSDB_FILENAME_LEN
,
"%s%s%s"
,
tfsGetPrimaryPath
(
pTfs
),
TD_DIRSEP
,
path
);
info
.
config
=
*
pCfg
;
if
(
vnodeSaveInfo
(
dir
,
&
info
)
<
0
||
vnodeCommitInfo
(
dir
,
&
info
)
<
0
)
{
vError
(
"vgId: %d failed to save vnode config since %s"
,
pCfg
->
vgId
,
tstrerror
(
terrno
));
return
-
1
;
}
return
0
;
}
SVnode
*
vnodeOpen
(
const
char
*
path
,
const
SVnodeCfg
*
pVnodeCfg
)
{
SVnode
*
pVnode
=
NULL
;
// Set default options
SVnodeCfg
cfg
=
defaultVnodeOptions
;
SVnodeCfg
cfg
=
vnodeCfgDefault
;
if
(
pVnodeCfg
!=
NULL
)
{
cfg
.
vgId
=
pVnodeCfg
->
vgId
;
cfg
.
msgCb
=
pVnodeCfg
->
msgCb
;
...
...
@@ -36,7 +65,7 @@ SVnode *vnodeOpen(const char *path, const SVnodeCfg *pVnodeCfg) {
}
// Validate options
if
(
vnode
ValidateOptions
(
&
cfg
)
<
0
)
{
if
(
vnode
CheckCfg
(
&
cfg
)
<
0
)
{
// TODO
return
NULL
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录