Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
慢慢CG
TDengine
提交
2013f85a
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看板
提交
2013f85a
编写于
11月 22, 2020
作者:
H
Hongze Cheng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refact
上级
65e388a5
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
112 addition
and
39 deletion
+112
-39
src/inc/tfs.h
src/inc/tfs.h
+15
-0
src/tfs/src/tfcntl.c
src/tfs/src/tfcntl.c
+55
-3
src/tfs/src/tfs.c
src/tfs/src/tfs.c
+39
-20
src/tsdb/inc/tsdbMain.h
src/tsdb/inc/tsdbMain.h
+1
-3
src/tsdb/src/tsdbFile.c
src/tsdb/src/tsdbFile.c
+2
-13
未找到文件。
src/inc/tfs.h
浏览文件 @
2013f85a
...
...
@@ -22,6 +22,11 @@
extern
"C"
{
#endif
typedef
struct
{
int
level
;
int
id
;
}
SDiskID
;
// tfs.c
int
tfsInit
(
SDiskCfg
*
pDiskCfg
,
int
ndisk
);
void
tfsDestroy
();
...
...
@@ -30,6 +35,11 @@ void tfsPrimaryPath(char *dst);
int
tfsCreateDir
(
char
*
dirname
);
int
tfsRemoveDir
(
char
*
dirname
);
int
tfsRename
(
char
*
oldpath
,
char
*
newpath
);
void
tfsIncFileAt
(
int
level
,
int
id
);
void
tfsDecFileAt
(
int
level
,
int
id
);
int
tfsLock
();
int
tfsUnLock
();
bool
tfsIsLocked
();
// tfcntl.c
typedef
struct
TFSFILE
TFSFILE
;
...
...
@@ -47,6 +57,11 @@ void tfsBaseName(TFSFILE *pfile, char dest[]);
int
tfsopen
(
TFSFILE
*
pfile
);
int
tfsclose
(
int
,
fd
);
TFSFILE
*
tfsCreateFiles
(
int
level
,
int
nfile
,
...);
int
tfsRemoveFiles
(
int
nfile
,
...);
SDiskID
tfsFileID
(
TFSFILE
*
pfile
);
const
char
*
tfsGetDiskName
(
int
level
,
int
id
);
#ifdef __cplusplus
...
...
src/tfs/src/tfcntl.c
浏览文件 @
2013f85a
...
...
@@ -67,7 +67,7 @@ const TFSFILE *tfsReadDir(TFSDIR *tdir) {
struct
dirent
*
dp
=
readdir
(
tdir
->
dir
);
if
(
dp
!=
NULL
)
{
snprintf
(
rname
,
TSDB_FILENAME_LEN
,
"%s/%s"
,
tdir
->
name
,
dp
->
d_name
);
t
sf
InitFile
(
&
(
tdir
->
tfsfile
),
tdir
->
level
,
tdir
->
id
,
rname
);
t
fs
InitFile
(
&
(
tdir
->
tfsfile
),
tdir
->
level
,
tdir
->
id
,
rname
);
return
&
(
tdir
->
tfsfile
);
}
...
...
@@ -125,6 +125,47 @@ int tfsclose(int fd) {
return
0
}
TFSFILE
*
tfsCreateFiles
(
int
level
,
int
nfile
,
...)
{
// TODO
return
NULL
;
}
int
tfsRemoveFiles
(
int
nfile
,
...)
{
va_list
valist
;
TFSFILE
*
pfile
=
NULL
;
int
code
=
0
;
va_start
(
valist
,
nfile
);
tfsLock
();
for
(
int
i
=
0
;
i
<
nfile
;
i
++
)
{
pfile
=
va_arg
(
valist
,
TFSFILE
*
);
code
=
remove
(
pfile
->
aname
);
if
(
code
!=
0
)
{
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
tfsUnLock
();
va_end
(
valist
);
return
-
1
;
}
tfsDecFileAt
(
pfile
->
level
,
pfile
->
id
);
}
tfsUnLock
();
va_end
(
valist
);
return
0
;
}
SDiskID
tfsFileID
(
TFSFILE
*
pfile
)
{
SDiskID
did
;
did
.
level
=
pfile
->
level
;
did
.
id
=
pfile
->
id
;
return
did
;
}
static
int
tfsOpenDirImpl
(
TFSDIR
*
tdir
)
{
char
dirName
[
TSDB_FILENAME_LEN
]
=
"
\0
"
;
...
...
@@ -154,9 +195,20 @@ static int tfsOpenDirImpl(TFSDIR *tdir) {
return
0
;
}
static
void
t
sf
InitFile
(
TFSFILE
*
pfile
,
int
level
,
int
id
,
char
*
rname
)
{
static
void
t
fs
InitFile
(
TFSFILE
*
pfile
,
int
level
,
int
id
,
char
*
rname
)
{
pfile
->
level
=
level
;
pfile
->
id
=
id
;
strncpy
(
pfile
->
rname
,
rname
,
TSDB_FILENAME_LEN
);
snprintf
(
pfile
->
aname
,
TSDB_FILENAME_LEN
,
"%s/%s"
,
tfsGetDiskName
(
level
,
id
),
rname
);
}
\ No newline at end of file
}
static
TFSFILE
*
tfsNewFile
(
int
level
,
int
id
,
char
*
rname
)
{
TFSFILE
*
pfile
=
(
TFSFILE
*
)
calloc
(
1
,
sizeof
(
*
pfile
));
if
(
pfile
==
NULL
)
{
terrno
=
TSDB_CODE_FS_OUT_OF_MEMORY
;
return
NULL
;
}
tfsInitFile
(
pfile
,
level
,
id
,
rname
);
return
pfile
;
}
src/tfs/src/tfs.c
浏览文件 @
2013f85a
...
...
@@ -35,6 +35,7 @@ typedef struct {
typedef
struct
{
pthread_mutex_t
lock
;
bool
locked
;
SFSMeta
meta
;
int
nlevel
;
STier
tiers
[
TSDB_MAX_TIER
];
...
...
@@ -171,6 +172,44 @@ int tfsRename(char *oldpath, char *newpath) {
return
0
;
}
void
tfsIncFileAt
(
int
level
,
int
id
)
{
ASSERT
(
tfsIsLocked
());
DISK_AT
(
level
,
id
)
->
dmeta
.
nfiles
++
;
ASSERT
(
DISK_AT
(
level
,
id
)
->
dmeta
.
nfiles
>
0
);
}
void
tfsDecFileAt
(
int
level
,
int
id
)
{
ASSERT
(
tfsIsLocked
());
DISK_AT
(
level
,
id
)
->
dmeta
.
nfiles
--
;
ASSERT
(
DISK_AT
(
level
,
id
)
->
dmeta
.
nfiles
>=
0
);
}
int
tfsLock
()
{
int
code
=
pthread_mutex_lock
(
&
(
pfs
->
lock
));
if
(
code
!=
0
)
{
terrno
=
TAOS_SYSTEM_ERROR
(
code
);
return
-
1
;
}
pfs
->
locked
=
true
;
return
0
;
}
int
tfsUnLock
()
{
pfs
->
locked
=
false
;
int
code
=
pthread_mutex_unlock
(
&
(
pfs
->
lock
));
if
(
code
!=
0
)
{
terrno
=
TAOS_SYSTEM_ERROR
(
code
);
return
-
1
;
}
return
0
;
}
bool
tfsIsLocked
()
{
return
pfs
->
locked
;
}
const
char
*
tfsGetDiskName
(
int
level
,
int
id
)
{
return
DISK_AT
(
level
,
id
)
->
dir
;
}
...
...
@@ -293,26 +332,6 @@ static int tfsCheck() {
return
0
;
}
static
int
tfsLock
()
{
int
code
=
pthread_mutex_lock
(
&
(
pfs
->
lock
));
if
(
code
!=
0
)
{
terrno
=
TAOS_SYSTEM_ERROR
(
code
);
return
-
1
;
}
return
0
;
}
static
tfsUnLock
()
{
int
code
=
pthread_mutex_unlock
(
&
(
pfs
->
lock
));
if
(
code
!=
0
)
{
terrno
=
TAOS_SYSTEM_ERROR
(
code
);
return
-
1
;
}
return
0
;
}
static
tfsGetDiskByName
(
char
*
dirName
)
{
}
...
...
src/tsdb/inc/tsdbMain.h
浏览文件 @
2013f85a
...
...
@@ -190,15 +190,13 @@ typedef struct {
typedef
struct
{
int
fd
;
TFSFILE
t
file
;
TFSFILE
file
;
STsdbFileInfo
info
;
}
SFile
;
typedef
struct
{
int
fileId
;
int
state
;
// 0 for health, 1 for problem
int
level
;
int
did
;
SFile
files
[
TSDB_FILE_TYPE_MAX
];
}
SFileGroup
;
...
...
src/tsdb/src/tsdbFile.c
浏览文件 @
2013f85a
...
...
@@ -365,13 +365,8 @@ void *tsdbDecodeSFileInfo(void *buf, STsdbFileInfo *pInfo) {
void
tsdbRemoveFileGroup
(
STsdbRepo
*
pRepo
,
SFileGroup
*
pFGroup
)
{
ASSERT
(
pFGroup
!=
NULL
);
STsdbFileH
*
pFileH
=
pRepo
->
tsdbFileH
;
SDisk
*
pDisk
=
NULL
;
char
baseDir
[
TSDB_FILENAME_LEN
]
=
"
\0
"
;
SFileGroup
fileGroup
=
*
pFGroup
;
tsdbGetBaseDirFromFile
(
fileGroup
.
files
[
0
].
fname
,
baseDir
);
pDisk
=
tdGetDiskByName
(
tsDnodeTier
,
baseDir
);
ASSERT
(
pDisk
!=
NULL
);
int
nFilesLeft
=
pFileH
->
nFGroups
-
(
int
)(
POINTER_DISTANCE
(
pFGroup
,
pFileH
->
pFGroup
)
/
sizeof
(
SFileGroup
)
+
1
);
if
(
nFilesLeft
>
0
)
{
...
...
@@ -381,14 +376,8 @@ void tsdbRemoveFileGroup(STsdbRepo *pRepo, SFileGroup *pFGroup) {
pFileH
->
nFGroups
--
;
ASSERT
(
pFileH
->
nFGroups
>=
0
);
for
(
int
type
=
0
;
type
<
TSDB_FILE_TYPE_MAX
;
type
++
)
{
if
(
remove
(
fileGroup
.
files
[
type
].
fname
)
<
0
)
{
tsdbError
(
"vgId:%d failed to remove file %s"
,
REPO_ID
(
pRepo
),
fileGroup
.
files
[
type
].
fname
);
}
tsdbDestroyFile
(
&
fileGroup
.
files
[
type
]);
}
tdDecDiskFiles
(
tsDnodeTier
,
pDisk
,
true
);
tfsRemoveFiles
(
TSDB_FILE_TYPE_MAX
,
&
fileGroup
.
files
[
TSDB_FILE_TYPE_HEAD
],
&
fileGroup
.
files
[
TSDB_FILE_TYPE_DATA
],
&
fileGroup
.
files
[
TSDB_FILE_TYPE_LAST
]);
}
int
tsdbLoadFileHeader
(
SFile
*
pFile
,
uint32_t
*
version
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录