Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
2569e9d3
T
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
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看板
提交
2569e9d3
编写于
11月 23, 2020
作者:
H
Hongze Cheng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactor
上级
fd06497e
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
55 addition
and
82 deletion
+55
-82
src/inc/tfs.h
src/inc/tfs.h
+1
-1
src/tfs/src/tfcntl.c
src/tfs/src/tfcntl.c
+12
-0
src/tsdb/inc/tsdbMain.h
src/tsdb/inc/tsdbMain.h
+1
-2
src/tsdb/src/tsdbCommit.c
src/tsdb/src/tsdbCommit.c
+2
-2
src/tsdb/src/tsdbFile.c
src/tsdb/src/tsdbFile.c
+26
-73
src/tsdb/src/tsdbRWHelper.c
src/tsdb/src/tsdbRWHelper.c
+13
-4
未找到文件。
src/inc/tfs.h
浏览文件 @
2569e9d3
...
...
@@ -52,7 +52,7 @@ void tfsDirName(TFSFILE *pfile, char dest[]);
void
tfsBaseName
(
TFSFILE
*
pfile
,
char
dest
[]);
int
tfsopen
(
TFSFILE
*
pfile
,
int
flags
);
int
tfsclose
(
int
fd
);
int
tfs
RemoveFiles
(
int
nfile
,
...
);
int
tfs
remove
(
TFSFILE
*
pfile
);
SDiskID
tfsFileID
(
TFSFILE
*
pfile
);
typedef
struct
TFSDIR
TFSDIR
;
...
...
src/tfs/src/tfcntl.c
浏览文件 @
2569e9d3
...
...
@@ -150,6 +150,18 @@ int tfsclose(int fd) {
return
0
;
}
int
tfsremove
(
TFSFILE
*
pfile
)
{
int
code
=
remove
(
pfile
->
aname
);
if
(
code
!=
0
)
{
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
return
-
1
;
}
tfsLock
();
tfsDecFileAt
(
pfile
->
level
,
pfile
->
id
);
tfsUnLock
();
return
0
;
}
int
tfsRemoveFiles
(
int
nfile
,
...)
{
va_list
valist
;
TFSFILE
*
pfile
=
NULL
;
...
...
src/tsdb/inc/tsdbMain.h
浏览文件 @
2569e9d3
...
...
@@ -215,7 +215,7 @@ typedef struct {
int
index
;
}
SFileGroupIter
;
#define TSDB_FILE_NAME(pFile) (
tfsAbsName(pFile->file)
)
#define TSDB_FILE_NAME(pFile) (
(pFile)->file.aname
)
// ------------------ tsdbMain.c
typedef
struct
{
...
...
@@ -529,7 +529,6 @@ int tsdbLoadFileHeader(SFile* pFile, uint32_t* version);
void
tsdbGetFileInfoImpl
(
char
*
fname
,
uint32_t
*
magic
,
int64_t
*
size
);
void
tsdbGetFidGroup
(
STsdbCfg
*
pCfg
,
SFidGroup
*
pFidGroup
);
void
tsdbGetFidKeyRange
(
int
daysPerFile
,
int8_t
precision
,
int
fileId
,
TSKEY
*
minKey
,
TSKEY
*
maxKey
);
int
tsdbGetBaseDirFromFile
(
char
*
fname
,
char
*
baseDir
);
int
tsdbApplyRetention
(
STsdbRepo
*
pRepo
,
SFidGroup
*
pFidGroup
);
// ------------------ tsdbRWHelper.c
...
...
src/tsdb/src/tsdbCommit.c
浏览文件 @
2569e9d3
...
...
@@ -270,11 +270,11 @@ static int tsdbCommitToFile(STsdbRepo *pRepo, int fid, SCommitIter *iters, SRWHe
pthread_rwlock_wrlock
(
&
(
pFileH
->
fhlock
));
(
void
)
rename
(
helperNewHeadF
(
pHelper
)
->
fname
,
helperHeadF
(
pHelper
)
->
fname
);
(
void
)
rename
(
TSDB_FILE_NAME
(
helperNewHeadF
(
pHelper
)),
TSDB_FILE_NAME
(
helperHeadF
(
pHelper
))
);
pGroup
->
files
[
TSDB_FILE_TYPE_HEAD
].
info
=
helperNewHeadF
(
pHelper
)
->
info
;
if
(
newLast
)
{
(
void
)
rename
(
helperNewLastF
(
pHelper
)
->
fname
,
helperLastF
(
pHelper
)
->
fname
);
(
void
)
rename
(
TSDB_FILE_NAME
(
helperNewLastF
(
pHelper
)),
TSDB_FILE_NAME
(
helperLastF
(
pHelper
))
);
pGroup
->
files
[
TSDB_FILE_TYPE_LAST
].
info
=
helperNewLastF
(
pHelper
)
->
info
;
}
else
{
pGroup
->
files
[
TSDB_FILE_TYPE_LAST
].
info
=
helperLastF
(
pHelper
)
->
info
;
...
...
src/tsdb/src/tsdbFile.c
浏览文件 @
2569e9d3
...
...
@@ -130,9 +130,10 @@ void tsdbCloseFileH(STsdbRepo *pRepo) { // TODO
for
(
int
i
=
0
;
i
<
pFileH
->
nFGroups
;
i
++
)
{
SFileGroup
*
pFGroup
=
pFileH
->
pFGroup
+
i
;
for
(
int
type
=
0
;
type
<
TSDB_FILE_TYPE_MAX
;
type
++
)
{
tsdb
DestroyFile
(
&
pFGroup
->
files
[
type
]
);
tsdb
CloseFile
(
&
(
pFGroup
->
files
[
type
])
);
}
}
// TODO: delete each files
}
// SFileGroup ===========================================
...
...
@@ -141,34 +142,35 @@ SFileGroup *tsdbCreateFGroup(STsdbRepo *pRepo, int fid, int level) {
char
fname
[
TSDB_FILENAME_LEN
]
=
"
\0
"
;
SFileGroup
fg
=
{
0
};
SFileGroup
*
pfg
=
&
fg
;
SFile
*
p
f
ile
=
NULL
;
int
id
=
-
1
;
SFile
*
p
F
ile
=
NULL
;
int
id
=
TFS_UNDECIDED_ID
;
ASSERT
(
tsdbSearchFGroup
(
pFileH
,
fid
,
TD_EQ
)
==
NULL
&&
pFileH
->
nFGroups
<
pFileH
->
maxFGroups
);
// 1. Create each files
for
(
int
type
=
0
;
type
<
TSDB_FILE_TYPE_MAX
;
type
++
)
{
p
f
ile
=
&
(
pfg
->
files
[
type
]);
p
F
ile
=
&
(
pfg
->
files
[
type
]);
tsdbGetDataFileName
(
pRepo
->
rootDir
,
REPO_ID
(
pRepo
),
fid
,
type
,
fname
);
tsdbGetDataFileName
(
pRepo
->
rootDir
,
REPO_ID
(
pRepo
),
fid
,
type
,
pFile
->
file
.
rname
);
pFile
->
file
.
level
=
level
;
pFile
->
file
.
id
=
id
;
pfile
->
file
=
tfsCreateFiles
(
level
,
id
,
fname
);
if
(
pfile
->
file
==
NULL
)
{
// TODO :deal with error
if
(
tsdbOpenFile
(
pFile
,
O_WRONLY
|
O_CREAT
)
<
0
);
{
tsdbError
(
"vgId:%d failed to create file group %d since %s"
,
REPO_ID
(
pRepo
),
fid
,
tstrerror
(
terrno
));
return
NULL
;
}
if
(
tsdbOpenFile
(
pfile
,
O_WRONLY
)
<
0
);
{
// TODO: deal with the ERROR here
if
(
tsdbUpdateFileHeader
(
pFile
)
<
0
)
{
tsdbError
(
"vgId:%d failed to update file %s header since %s"
,
REPO_ID
(
pRepo
),
TSDB_FILE_NAME
(
pFile
),
tstrerror
(
terrno
));
tsdbCloseFile
(
pFile
);
return
NULL
;
}
if
(
tsdbUpdateFileHeader
(
pfile
)
<
0
)
{
// TODO: deal the error
}
tsdbCloseFile
(
pfile
);
tsdbCloseFile
(
pFile
);
level
=
TFS_FILE_LEVEL
(
pfile
->
file
)
;
id
=
TFS_FILE_ID
(
pfile
->
file
)
;
level
=
pFile
->
file
.
level
;
id
=
pFile
->
file
.
id
;
}
// Set fg
...
...
@@ -200,8 +202,10 @@ void tsdbRemoveFileGroup(STsdbRepo *pRepo, SFileGroup *pFGroup) {
pFileH
->
nFGroups
--
;
ASSERT
(
pFileH
->
nFGroups
>=
0
);
tfsRemoveFiles
(
TSDB_FILE_TYPE_MAX
,
&
fileGroup
.
files
[
TSDB_FILE_TYPE_HEAD
],
&
fileGroup
.
files
[
TSDB_FILE_TYPE_DATA
],
&
fileGroup
.
files
[
TSDB_FILE_TYPE_LAST
]);
for
(
int
type
=
0
;
type
<
TSDB_FILE_TYPE_MAX
;
type
++
)
{
SFile
*
pFile
=
&
(
pFGroup
->
files
[
type
]);
tfsremove
(
&
(
pFile
->
file
));
}
}
SFileGroup
*
tsdbSearchFGroup
(
STsdbFileH
*
pFileH
,
int
fid
,
int
flags
)
{
...
...
@@ -307,10 +311,9 @@ SFileGroup *tsdbGetFileGroupNext(SFileGroupIter *pIter) {
int
tsdbOpenFile
(
SFile
*
pFile
,
int
oflag
)
{
ASSERT
(
!
TSDB_IS_FILE_OPENED
(
pFile
));
pFile
->
fd
=
open
(
TSDB_FILE_NAME
(
pFile
),
oflag
,
0755
);
pFile
->
fd
=
tfsopen
(
&
(
pFile
->
file
),
oflag
);
if
(
pFile
->
fd
<
0
)
{
tsdbError
(
"failed to open file %s since %s"
,
TSDB_FILE_NAME
(
pFile
),
strerror
(
errno
));
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
tsdbError
(
"failed to open file %s since %s"
,
TSDB_FILE_NAME
(
pFile
),
tstrerror
(
terrno
));
return
-
1
;
}
...
...
@@ -327,38 +330,6 @@ void tsdbCloseFile(SFile *pFile) {
}
}
static
int
tsdbCreateFile
(
SFile
*
pFile
,
STsdbRepo
*
pRepo
,
int
fid
,
int
type
)
{
memset
((
void
*
)
pFile
,
0
,
sizeof
(
SFile
));
pFile
->
fd
=
-
1
;
tsdbGetDataFileName
(
pRepo
->
rootDir
,
REPO_ID
(
pRepo
),
fid
,
type
,
TSDB_FILE_NAME
(
pFile
));
if
(
access
(
TSDB_FILE_NAME
(
pFile
),
F_OK
)
==
0
)
{
tsdbError
(
"vgId:%d file %s already exists"
,
REPO_ID
(
pRepo
),
TSDB_FILE_NAME
(
pFile
));
terrno
=
TSDB_CODE_TDB_FILE_ALREADY_EXISTS
;
goto
_err
;
}
if
(
tsdbOpenFile
(
pFile
,
O_RDWR
|
O_CREAT
)
<
0
)
{
goto
_err
;
}
pFile
->
info
.
size
=
TSDB_FILE_HEAD_SIZE
;
pFile
->
info
.
magic
=
TSDB_FILE_INIT_MAGIC
;
if
(
tsdbUpdateFileHeader
(
pFile
)
<
0
)
{
tsdbCloseFile
(
pFile
);
return
-
1
;
}
tsdbCloseFile
(
pFile
);
return
0
;
_err:
return
-
1
;
}
int
tsdbUpdateFileHeader
(
SFile
*
pFile
)
{
char
buf
[
TSDB_FILE_HEAD_SIZE
]
=
"
\0
"
;
...
...
@@ -437,7 +408,7 @@ int tsdbLoadFileHeader(SFile *pFile, uint32_t *version) {
return
0
;
}
void
tsdbGetFileInfoImpl
(
char
*
fname
,
uint32_t
*
magic
,
int64_t
*
size
)
{
void
tsdbGetFileInfoImpl
(
char
*
fname
,
uint32_t
*
magic
,
int64_t
*
size
)
{
// TODO
uint32_t
version
=
0
;
SFile
file
;
SFile
*
pFile
=
&
file
;
...
...
@@ -463,8 +434,6 @@ _err:
*
size
=
0
;
}
static
void
tsdbDestroyFile
(
SFile
*
pFile
)
{
tsdbCloseFile
(
pFile
);
}
// Retention ===========================================
void
tsdbRemoveFilesBeyondRetention
(
STsdbRepo
*
pRepo
,
SFidGroup
*
pFidGroup
)
{
STsdbFileH
*
pFileH
=
pRepo
->
tsdbFileH
;
...
...
@@ -490,22 +459,6 @@ void tsdbGetFidGroup(STsdbCfg *pCfg, SFidGroup *pFidGroup) {
TSDB_KEY_FILEID
(
now
-
pCfg
->
keep1
*
tsMsPerDay
[
pCfg
->
precision
],
pCfg
->
daysPerFile
,
pCfg
->
precision
);
}
int
tsdbGetBaseDirFromFile
(
char
*
fname
,
char
*
baseDir
)
{
char
*
fdup
=
strdup
(
fname
);
if
(
fdup
==
NULL
)
{
terrno
=
TSDB_CODE_TDB_OUT_OF_MEMORY
;
return
-
1
;
}
for
(
size_t
i
=
0
;
i
<
5
;
i
++
)
{
dirname
(
fdup
);
}
strncpy
(
baseDir
,
fdup
,
TSDB_FILENAME_LEN
);
free
(
fdup
);
return
0
;
}
int
tsdbApplyRetention
(
STsdbRepo
*
pRepo
,
SFidGroup
*
pFidGroup
)
{
STsdbFileH
*
pFileH
=
pRepo
->
tsdbFileH
;
SFileGroup
*
pGroup
=
NULL
;
...
...
src/tsdb/src/tsdbRWHelper.c
浏览文件 @
2569e9d3
...
...
@@ -115,9 +115,14 @@ int tsdbSetAndOpenHelperFile(SRWHelper *pHelper, SFileGroup *pGroup) {
pHelper
->
files
.
fGroup
=
*
pGroup
;
if
(
helperType
(
pHelper
)
==
TSDB_WRITE_HELPER
)
{
tsdbGetDataFileName
(
tsdbRootDir
,
REPO_ID
(
pRepo
),
pGroup
->
fileId
,
TSDB_FILE_TYPE_NHEAD
,
helperNewHeadF
(
pHelper
)
->
fname
);
helperNewHeadF
(
pHelper
)
->
file
.
rname
);
helperNewHeadF
(
pHelper
)
->
file
.
level
=
pGroup
->
files
[
0
].
file
.
level
;
helperNewHeadF
(
pHelper
)
->
file
.
id
=
pGroup
->
files
[
0
].
file
.
id
;
tsdbGetDataFileName
(
tsdbRootDir
,
REPO_ID
(
pRepo
),
pGroup
->
fileId
,
TSDB_FILE_TYPE_NLAST
,
helperNewLastF
(
pHelper
)
->
fname
);
helperNewLastF
(
pHelper
)
->
file
.
rname
);
helperNewLastF
(
pHelper
)
->
file
.
level
=
pGroup
->
files
[
0
].
file
.
level
;
helperNewLastF
(
pHelper
)
->
file
.
id
=
pGroup
->
files
[
0
].
file
.
id
;
}
// Open the files
...
...
@@ -194,7 +199,9 @@ int tsdbCloseHelperFile(SRWHelper *pHelper, bool hasError, SFileGroup *pGroup) {
fsync
(
pFile
->
fd
);
}
tsdbCloseFile
(
pFile
);
if
(
hasError
)
(
void
)
remove
(
TSDB_FILE_NAME
(
pFile
));
if
(
hasError
)
{
tfsremove
(
&
(
pFile
->
file
));
}
}
pFile
=
helperNewLastF
(
pHelper
);
...
...
@@ -204,7 +211,9 @@ int tsdbCloseHelperFile(SRWHelper *pHelper, bool hasError, SFileGroup *pGroup) {
fsync
(
pFile
->
fd
);
}
tsdbCloseFile
(
pFile
);
if
(
hasError
)
(
void
)
remove
(
TSDB_FILE_NAME
(
pFile
));
if
(
hasError
)
{
tfsremove
(
&
(
pFile
->
file
));
}
}
}
return
0
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录