Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
慢慢CG
TDengine
提交
702ec72e
T
TDengine
项目概览
慢慢CG
/
TDengine
与 Fork 源项目一致
Fork自
taosdata / TDengine
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
702ec72e
编写于
11月 20, 2020
作者:
H
Hongze Cheng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactor more
上级
bf33887d
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
77 addition
and
58 deletion
+77
-58
src/inc/tfs.h
src/inc/tfs.h
+3
-1
src/tfs/src/tfs.c
src/tfs/src/tfs.c
+51
-11
src/vnode/src/vnodeMain.c
src/vnode/src/vnodeMain.c
+23
-46
未找到文件。
src/inc/tfs.h
浏览文件 @
702ec72e
...
...
@@ -36,7 +36,9 @@ int tfsInit(SDiskCfg *pDiskCfg, int ndisk);
void
tfsDestroy
();
int
tfsUpdateInfo
();
void
tfsPrimaryPath
(
char
*
dst
);
int
tfsCreateDir
(
char
*
name
);
int
tfsCreateDir
(
char
*
dirname
);
int
tfsRemoveDir
(
char
*
dirname
);
int
tfsRename
(
char
*
oldpath
,
char
*
newpath
);
#ifdef __cplusplus
}
...
...
src/tfs/src/tfs.c
浏览文件 @
702ec72e
...
...
@@ -104,7 +104,7 @@ void tfsPrimaryPath(char *dst) {
strncpy
(
dst
,
DISK_AT
(
0
,
0
)
->
dir
,
TSDB_FILENAME_LEN
);
}
int
tfsCreateDir
(
char
*
name
)
{
int
tfsCreateDir
(
char
*
dir
name
)
{
char
dirName
[
TSDB_FILENAME_LEN
]
=
"
\0
"
;
for
(
int
level
=
0
;
level
<
pfs
->
nlevel
;
level
++
)
{
...
...
@@ -114,7 +114,7 @@ int tfsCreateDir(char *name) {
ASSERT
(
pDisk
!=
NULL
);
snprintf
(
dirName
,
TSDB_FILENAME_LEN
,
"%s/%s"
,
pDisk
->
dir
,
name
);
snprintf
(
dirName
,
TSDB_FILENAME_LEN
,
"%s/%s"
,
pDisk
->
dir
,
dir
name
);
if
(
mkdir
(
dirName
,
0755
)
!=
0
&&
errno
!=
EEXIST
)
{
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
...
...
@@ -126,6 +126,46 @@ int tfsCreateDir(char *name) {
return
0
;
}
int
tfsRemoveDir
(
char
*
dirname
)
{
char
dirName
[
TSDB_FILENAME_LEN
]
=
"
\0
"
;
for
(
int
level
=
0
;
level
<
pfs
->
nlevel
;
level
++
)
{
STier
*
pTier
=
TIER_AT
(
level
);
for
(
int
id
=
0
;
id
<
pTier
->
ndisk
;
id
++
)
{
SDisk
*
pDisk
=
DISK_AT_TIER
(
pTier
,
id
);
ASSERT
(
pDisk
!=
NULL
);
snprintf
(
dirName
,
TSDB_FILENAME_LEN
,
"%s/%s"
,
pDisk
->
dir
,
dirname
);
taosRemoveDir
(
dirName
);
}
}
return
0
;
}
int
tfsRename
(
char
*
oldpath
,
char
*
newpath
)
{
char
oldName
[
TSDB_FILENAME_LEN
]
=
"
\0
"
;
char
newName
[
TSDB_FILENAME_LEN
]
=
"
\0
"
;
for
(
int
level
=
0
;
level
<
pfs
->
nlevel
;
level
++
)
{
STier
*
pTier
=
TIER_AT
(
level
);
for
(
int
id
=
0
;
id
<
pTier
->
ndisk
;
id
++
)
{
SDisk
*
pDisk
=
DISK_AT_TIER
(
pTier
,
id
);
ASSERT
(
pDisk
!=
NULL
);
snprintf
(
oldName
,
TSDB_FILENAME_LEN
,
"%s/%s"
,
pDisk
->
dir
,
oldpath
);
snprintf
(
newName
,
TSDB_FILENAME_LEN
,
"%s/%s"
,
pDisk
->
dir
,
newpath
);
taosRename
(
oldName
,
newName
);
}
}
return
0
;
}
static
int
tfsMount
(
SDiskCfg
*
pCfg
)
{
SDiskID
did
;
...
...
@@ -134,7 +174,7 @@ static int tfsMount(SDiskCfg *pCfg) {
did
.
level
=
pCfg
->
level
;
did
.
id
=
tdAddDiskToTier
(
TIER_AT
(
pCfg
->
level
),
pCfg
);
if
(
did
.
id
<
0
)
{
fError
(
"failed to
add disk
%s to FS since %s"
,
pCfg
->
dir
,
tstrerror
(
terrno
));
fError
(
"failed to
mount
%s to FS since %s"
,
pCfg
->
dir
,
tstrerror
(
terrno
));
return
-
1
;
}
...
...
@@ -151,51 +191,51 @@ static int tfsCheckAndFormatCfg(SDiskCfg *pCfg) {
struct
stat
pstat
;
if
(
pCfg
->
level
<
0
||
pCfg
->
level
>=
TSDB_MAX_TIER
)
{
fError
(
"failed to
add disk
%s to FS since invalid level %d"
,
pCfg
->
dir
,
pCfg
->
level
);
fError
(
"failed to
mount
%s to FS since invalid level %d"
,
pCfg
->
dir
,
pCfg
->
level
);
terrno
=
TSDB_CODE_FS_INVLD_CFG
;
return
-
1
;
}
if
(
pCfg
->
primary
)
{
if
(
pCfg
->
level
!=
0
)
{
fError
(
"failed to
add disk
%s to FS since disk is primary but level %d not 0"
,
pCfg
->
dir
,
pCfg
->
level
);
fError
(
"failed to
mount
%s to FS since disk is primary but level %d not 0"
,
pCfg
->
dir
,
pCfg
->
level
);
terrno
=
TSDB_CODE_FS_INVLD_CFG
;
return
-
1
;
}
if
(
DISK_AT
(
0
,
0
)
!=
NULL
)
{
fError
(
"failed to
add disk
%s to FS since duplicate primary mount"
,
pCfg
->
dir
,
pCfg
->
level
);
fError
(
"failed to
mount
%s to FS since duplicate primary mount"
,
pCfg
->
dir
,
pCfg
->
level
);
terrno
=
TSDB_CODE_FS_DUP_PRIMARY
;
return
-
1
;
}
}
if
(
tfsFormatDir
(
pCfg
->
dir
,
dirName
)
<
0
)
{
fError
(
"failed to
add disk
%s to FS since invalid dir format"
,
pCfg
->
dir
);
fError
(
"failed to
mount
%s to FS since invalid dir format"
,
pCfg
->
dir
);
terrno
=
TSDB_CODE_FS_INVLD_CFG
;
return
-
1
;
}
if
(
tfsGetDiskByName
(
dirName
)
!=
NULL
)
{
fError
(
"failed to
add disk
%s to FS since duplicate mount"
,
pCfg
->
dir
);
fError
(
"failed to
mount
%s to FS since duplicate mount"
,
pCfg
->
dir
);
terrno
=
TSDB_CODE_FS_INVLD_CFG
;
return
-
1
;
}
if
(
access
(
dirName
,
W_OK
|
R_OK
|
F_OK
)
!=
0
)
{
fError
(
"failed to
add disk
%s to FS since no R/W access rights"
,
pCfg
->
dir
);
fError
(
"failed to
mount
%s to FS since no R/W access rights"
,
pCfg
->
dir
);
terrno
=
TSDB_CODE_FS_INVLD_CFG
;
return
-
1
;
}
if
(
stat
(
dirName
,
&
pstat
)
<
0
)
{
fError
(
"failed to
add disk
%s to FS since %s"
,
pCfg
->
dir
,
strerror
(
errno
));
fError
(
"failed to
mount
%s to FS since %s"
,
pCfg
->
dir
,
strerror
(
errno
));
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
return
-
1
;
}
if
(
!
S_ISDIR
(
pstat
.
st_mode
))
{
fError
(
"failed to
add disk
%s to FS since not a directory"
,
pCfg
->
dir
);
fError
(
"failed to
mount
%s to FS since not a directory"
,
pCfg
->
dir
);
terrno
=
TSDB_CODE_FS_INVLD_CFG
;
return
-
1
;
}
...
...
src/vnode/src/vnodeMain.c
浏览文件 @
702ec72e
...
...
@@ -21,14 +21,15 @@
#include "trpc.h"
#include "tsdb.h"
#include "tutil.h"
#include "dnode.h"
#include "vnode.h"
#include "vnodeInt.h"
#include "query.h"
#include "dnode.h"
#include "vnodeCfg.h"
#include "vnodeVersion.h"
#include "dnodeVWrite.h"
#include "dnodeVRead.h"
#include "
query
.h"
#include "
tfs
.h"
static
SHashObj
*
tsVnodesHash
;
static
void
vnodeCleanUp
(
SVnodeObj
*
pVnode
);
...
...
@@ -99,32 +100,19 @@ int32_t vnodeCreate(SCreateVnodeMsg *pVnodeCfg) {
return
TSDB_CODE_SUCCESS
;
}
if
(
mkdir
(
tsVnodeDir
,
0755
)
!=
0
&&
errno
!=
EEXIST
)
{
vError
(
"vgId:%d, failed to create vnode, reason:%s dir:%s"
,
pVnodeCfg
->
cfg
.
vgId
,
strerror
(
errno
),
tsVnodeDir
);
if
(
errno
==
EACCES
)
{
return
TSDB_CODE_VND_NO_DISK_PERMISSIONS
;
}
else
if
(
errno
==
ENOSPC
)
{
return
TSDB_CODE_VND_NO_DISKSPACE
;
}
else
if
(
errno
==
ENOENT
)
{
return
TSDB_CODE_VND_NO_SUCH_FILE_OR_DIR
;
}
else
{
return
TSDB_CODE_VND_INIT_FAILED
;
}
if
(
tfsCreateDir
(
"vnode"
)
<
0
)
{
vError
(
"vgId:%d, failed to create vnode dir, reason:%s"
,
pVnodeCfg
->
cfg
.
vgId
,
tstrerror
(
terrno
));
return
terrno
;
}
char
rootDir
[
TSDB_FILENAME_LEN
]
=
{
0
};
tdGetVnodeDir
(
tsDataDir
,
pVnodeCfg
->
cfg
.
vgId
,
rootDir
);
if
(
mkdir
(
rootDir
,
0755
)
!=
0
&&
errno
!=
EEXIST
)
{
vError
(
"vgId:%d, failed to create vnode, reason:%s dir:%s"
,
pVnodeCfg
->
cfg
.
vgId
,
strerror
(
errno
),
rootDir
);
if
(
errno
==
EACCES
)
{
return
TSDB_CODE_VND_NO_DISK_PERMISSIONS
;
}
else
if
(
errno
==
ENOSPC
)
{
return
TSDB_CODE_VND_NO_DISKSPACE
;
}
else
if
(
errno
==
ENOENT
)
{
return
TSDB_CODE_VND_NO_SUCH_FILE_OR_DIR
;
}
else
{
return
TSDB_CODE_VND_INIT_FAILED
;
}
sprintf
(
rootDir
,
"%s/vnode%d"
,
tsVnodeDir
,
pVnodeCfg
->
cfg
.
vgId
);
char
vnodeDir
[
TSDB_FILENAME_LEN
]
=
"
\0
"
;
snprintf
(
vnodeDir
,
TSDB_FILENAME_LEN
,
"vnode%d"
,
pVnodeCfg
->
cfg
.
vgId
);
if
(
tfsCreateDir
(
vnodeDir
)
<
0
)
{
vError
(
"vgId:%d, failed to create vnode %d dir, reason:%s"
,
pVnodeCfg
->
cfg
.
vgId
,
strerror
(
errno
));
return
terrno
;
}
code
=
vnodeWriteCfg
(
pVnodeCfg
);
...
...
@@ -146,7 +134,7 @@ int32_t vnodeCreate(SCreateVnodeMsg *pVnodeCfg) {
tsdbCfg
.
update
=
pVnodeCfg
->
cfg
.
update
;
char
tsdbDir
[
TSDB_FILENAME_LEN
]
=
{
0
};
tdGetTsdbRootDir
(
tsDataDir
,
pVnodeCfg
->
cfg
.
vgId
,
tsdbDir
);
sprintf
(
tsdbDir
,
"%s/vnode%d/tsdb"
,
tsVnodeDir
,
pVnodeCfg
->
cfg
.
vgId
);
if
(
tsdbCreateRepo
(
tsdbDir
,
&
tsdbCfg
)
<
0
)
{
vError
(
"vgId:%d, failed to create tsdb in vnode, reason:%s"
,
pVnodeCfg
->
cfg
.
vgId
,
tstrerror
(
terrno
));
return
TSDB_CODE_VND_INIT_FAILED
;
...
...
@@ -445,28 +433,17 @@ void vnodeRelease(void *vparam) {
if
(
pVnode
->
dropped
)
{
char
rootDir
[
TSDB_FILENAME_LEN
]
=
{
0
};
char
newDir
[
TSDB_FILENAME_LEN
]
=
{
0
};
sprintf
(
rootDir
,
"%s/vnode%d"
,
"vnode"
,
vgId
);
sprintf
(
newDir
,
"%s/vnode%d"
,
"vnode_bak"
,
vgId
);
for
(
int
i
=
0
;
i
<
tsDnodeTier
->
nTiers
;
i
++
)
{
STier
*
pTier
=
tsDnodeTier
->
tiers
+
i
;
for
(
int
j
=
0
;
j
<
pTier
->
nDisks
;
j
++
)
{
SDisk
*
pDisk
=
pTier
->
disks
[
j
];
tdGetVnodeDir
(
pDisk
->
dir
,
vgId
,
rootDir
);
tdGetVnodeBackDir
(
pDisk
->
dir
,
vgId
,
newDir
);
if
(
access
(
rootDir
,
F_OK
)
==
0
)
{
if
(
0
==
tsEnableVnodeBak
)
{
vInfo
(
"vgId:%d, vnode backup not enabled"
,
pVnode
->
vgId
);
}
else
{
taosRemoveDir
(
newDir
);
taosRename
(
rootDir
,
newDir
);
}
taosRemoveDir
(
rootDir
);
}
}
if
(
0
==
tsEnableVnodeBak
)
{
vInfo
(
"vgId:%d, vnode backup not enabled"
,
pVnode
->
vgId
);
}
else
{
tfsRemoveDir
(
newDir
);
tfsRename
(
rootDir
,
newDir
);
}
tfsRemoveDir
(
rootDir
);
dnodeSendStatusMsgToMnode
();
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录