Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
1592ea69
T
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22017
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看板
提交
1592ea69
编写于
4月 15, 2022
作者:
H
Hongze Cheng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refact vnod
上级
b0f4a396
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
106 addition
and
90 deletion
+106
-90
source/dnode/vnode/src/inc/vnd.h
source/dnode/vnode/src/inc/vnd.h
+4
-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
+0
-84
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
+10
-3
未找到文件。
source/dnode/vnode/src/inc/vnd.h
浏览文件 @
1592ea69
...
...
@@ -31,8 +31,6 @@ extern "C" {
// clang-format on
// vnodeCfg ====================
int
vnodeSaveCfg
(
const
char
*
dir
,
const
SVnodeCfg
*
pCfg
);
int
vnodeCommitCfg
(
const
char
*
dir
);
// vnodeModule ====================
int
vnodeScheduleTask
(
int
(
*
execute
)(
void
*
),
void
*
arg
);
...
...
@@ -42,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
);
...
...
source/dnode/vnode/src/inc/vnodeInt.h
浏览文件 @
1592ea69
...
...
@@ -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
浏览文件 @
1592ea69
...
...
@@ -15,12 +15,6 @@
#include "vnodeInt.h"
#define VND_INFO_FNAME "vnode.json"
#define VND_INFO_FNAME_TMP "vnode_tmp.json"
static
int
vnodeEncodeInfo
(
const
SVnodeCfg
*
pCfg
,
uint8_t
**
ppData
,
int
*
len
);
static
int
vnodeDecodeInfo
(
uint8_t
*
pData
,
int
len
,
SVnodeCfg
*
pCfg
);
const
SVnodeCfg
vnodeCfgDefault
=
{
.
wsize
=
96
*
1024
*
1024
,
.
ssize
=
1
*
1024
*
1024
,
.
lsize
=
1024
,
.
walCfg
=
{.
level
=
TAOS_WAL_WRITE
}};
...
...
@@ -29,84 +23,6 @@ int vnodeCheckCfg(const SVnodeCfg *pCfg) {
return
0
;
}
int
vnodeSaveCfg
(
const
char
*
dir
,
const
SVnodeCfg
*
pCfg
)
{
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
(
pCfg
,
&
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"
,
pCfg
->
vgId
,
fname
);
return
0
;
_err:
taosCloseFile
(
&
pFile
);
taosMemoryFree
(
data
);
return
-
1
;
}
int
vnodeCommitCfg
(
const
char
*
dir
)
{
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
;
}
return
0
;
}
int
vnodeLoadCfg
(
const
char
*
dir
)
{
// TODO
return
0
;
}
static
int
vnodeEncodeInfo
(
const
SVnodeCfg
*
pCfg
,
uint8_t
**
ppData
,
int
*
len
)
{
// TODO
return
0
;
}
static
int
vnodeDecodeInfo
(
uint8_t
*
pData
,
int
len
,
SVnodeCfg
*
pCfg
)
{
// TODO
return
0
;
}
#if 1 //======================================================================
void
vnodeOptionsCopy
(
SVnodeCfg
*
pDest
,
const
SVnodeCfg
*
pSrc
)
{
memcpy
((
void
*
)
pDest
,
(
void
*
)
pSrc
,
sizeof
(
SVnodeCfg
));
...
...
source/dnode/vnode/src/vnd/vnodeCommit.c
浏览文件 @
1592ea69
...
...
@@ -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/vnodeOpen.c
浏览文件 @
1592ea69
...
...
@@ -21,7 +21,8 @@ static int vnodeOpenImpl(SVnode *pVnode);
static
void
vnodeCloseImpl
(
SVnode
*
pVnode
);
int
vnodeCreate
(
const
char
*
path
,
SVnodeCfg
*
pCfg
,
STfs
*
pTfs
)
{
char
dir
[
TSDB_FILENAME_LEN
];
SVnodeInfo
info
=
{
0
};
char
dir
[
TSDB_FILENAME_LEN
];
// TODO: check if directory exists
...
...
@@ -32,9 +33,15 @@ int vnodeCreate(const char *path, SVnodeCfg *pCfg, STfs *pTfs) {
}
// create vnode env
tfsMkdir
(
pTfs
,
path
);
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
);
if
(
vnodeSaveCfg
(
dir
,
pCfg
)
<
0
||
vnodeCommitCfg
(
dir
)
<
0
)
{
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
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录