Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
慢慢CG
TDengine
提交
ab039d7d
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看板
提交
ab039d7d
编写于
9月 08, 2020
作者:
H
Hongze Cheng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix TD-1362
上级
e5adfe51
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
39 addition
and
8 deletion
+39
-8
src/tsdb/src/tsdbFile.c
src/tsdb/src/tsdbFile.c
+39
-8
未找到文件。
src/tsdb/src/tsdbFile.c
浏览文件 @
ab039d7d
...
@@ -26,11 +26,13 @@
...
@@ -26,11 +26,13 @@
const
char
*
tsdbFileSuffix
[]
=
{
".head"
,
".data"
,
".last"
,
".stat"
,
".h"
,
".d"
,
".l"
,
".s"
};
const
char
*
tsdbFileSuffix
[]
=
{
".head"
,
".data"
,
".last"
,
".stat"
,
".h"
,
".d"
,
".l"
,
".s"
};
static
int
tsdbInitFile
(
SFile
*
pFile
,
STsdbRepo
*
pRepo
,
int
fid
,
int
type
);
static
int
tsdbInitFile
(
SFile
*
pFile
,
STsdbRepo
*
pRepo
,
int
fid
,
int
type
);
static
void
tsdbDestroyFile
(
SFile
*
pFile
);
static
void
tsdbDestroyFile
(
SFile
*
pFile
);
static
int
compFGroup
(
const
void
*
arg1
,
const
void
*
arg2
);
static
int
compFGroup
(
const
void
*
arg1
,
const
void
*
arg2
);
static
int
keyFGroupCompFunc
(
const
void
*
key
,
const
void
*
fgroup
);
static
int
keyFGroupCompFunc
(
const
void
*
key
,
const
void
*
fgroup
);
static
void
tsdbInitFileGroup
(
SFileGroup
*
pFGroup
,
STsdbRepo
*
pRepo
);
static
void
tsdbInitFileGroup
(
SFileGroup
*
pFGroup
,
STsdbRepo
*
pRepo
);
static
TSKEY
tsdbGetCurrMinKey
(
int8_t
precision
,
int32_t
keep
);
static
int
tsdbGetCurrMinFid
(
int8_t
precision
,
int32_t
keep
,
int32_t
days
);
// ---------------- INTERNAL FUNCTIONS ----------------
// ---------------- INTERNAL FUNCTIONS ----------------
STsdbFileH
*
tsdbNewFileH
(
STsdbCfg
*
pCfg
)
{
STsdbFileH
*
tsdbNewFileH
(
STsdbCfg
*
pCfg
)
{
...
@@ -79,9 +81,11 @@ int tsdbOpenFileH(STsdbRepo *pRepo) {
...
@@ -79,9 +81,11 @@ int tsdbOpenFileH(STsdbRepo *pRepo) {
int
vid
=
0
;
int
vid
=
0
;
regex_t
regex1
,
regex2
;
regex_t
regex1
,
regex2
;
int
code
=
0
;
int
code
=
0
;
char
fname
[
TSDB_FILENAME_LEN
]
=
"
\0
"
;
SFileGroup
fileGroup
=
{
0
};
SFileGroup
fileGroup
=
{
0
};
STsdbFileH
*
pFileH
=
pRepo
->
tsdbFileH
;
STsdbFileH
*
pFileH
=
pRepo
->
tsdbFileH
;
STsdbCfg
*
pCfg
=
&
(
pRepo
->
config
);
tDataDir
=
tsdbGetDataDirName
(
pRepo
->
rootDir
);
tDataDir
=
tsdbGetDataDirName
(
pRepo
->
rootDir
);
if
(
tDataDir
==
NULL
)
{
if
(
tDataDir
==
NULL
)
{
...
@@ -108,6 +112,8 @@ int tsdbOpenFileH(STsdbRepo *pRepo) {
...
@@ -108,6 +112,8 @@ int tsdbOpenFileH(STsdbRepo *pRepo) {
goto
_err
;
goto
_err
;
}
}
int
mfid
=
tsdbGetCurrMinFid
(
pCfg
->
precision
,
pCfg
->
keep
,
pCfg
->
daysPerFile
);
struct
dirent
*
dp
=
NULL
;
struct
dirent
*
dp
=
NULL
;
while
((
dp
=
readdir
(
dir
))
!=
NULL
)
{
while
((
dp
=
readdir
(
dir
))
!=
NULL
)
{
if
(
strcmp
(
dp
->
d_name
,
"."
)
==
0
||
strcmp
(
dp
->
d_name
,
".."
)
==
0
)
continue
;
if
(
strcmp
(
dp
->
d_name
,
"."
)
==
0
||
strcmp
(
dp
->
d_name
,
".."
)
==
0
)
continue
;
...
@@ -120,6 +126,14 @@ int tsdbOpenFileH(STsdbRepo *pRepo) {
...
@@ -120,6 +126,14 @@ int tsdbOpenFileH(STsdbRepo *pRepo) {
continue
;
continue
;
}
}
if
(
fid
<
mfid
)
{
for
(
int
type
=
0
;
type
<
TSDB_FILE_TYPE_MAX
;
type
++
)
{
tsdbGetDataFileName
(
pRepo
->
rootDir
,
pCfg
->
tsdbId
,
fid
,
type
,
fname
);
(
void
)
remove
(
fname
);
}
continue
;
}
if
(
tsdbSearchFGroup
(
pFileH
,
fid
,
TD_EQ
)
!=
NULL
)
continue
;
if
(
tsdbSearchFGroup
(
pFileH
,
fid
,
TD_EQ
)
!=
NULL
)
continue
;
memset
((
void
*
)(
&
fileGroup
),
0
,
sizeof
(
SFileGroup
));
memset
((
void
*
)(
&
fileGroup
),
0
,
sizeof
(
SFileGroup
));
fileGroup
.
fileId
=
fid
;
fileGroup
.
fileId
=
fid
;
...
@@ -179,8 +193,18 @@ void tsdbCloseFileH(STsdbRepo *pRepo) {
...
@@ -179,8 +193,18 @@ void tsdbCloseFileH(STsdbRepo *pRepo) {
SFileGroup
*
tsdbCreateFGroupIfNeed
(
STsdbRepo
*
pRepo
,
char
*
dataDir
,
int
fid
)
{
SFileGroup
*
tsdbCreateFGroupIfNeed
(
STsdbRepo
*
pRepo
,
char
*
dataDir
,
int
fid
)
{
STsdbFileH
*
pFileH
=
pRepo
->
tsdbFileH
;
STsdbFileH
*
pFileH
=
pRepo
->
tsdbFileH
;
STsdbCfg
*
pCfg
=
&
(
pRepo
->
config
);
if
(
pFileH
->
nFGroups
>=
pFileH
->
maxFGroups
)
{
int
mfid
=
tsdbGetCurrMinFid
(
pCfg
->
precision
,
pCfg
->
keep
,
pCfg
->
daysPerFile
);
if
(
pFileH
->
pFGroup
[
0
].
fileId
<
mfid
)
{
pthread_rwlock_wrlock
(
&
pFileH
->
fhlock
);
tsdbRemoveFileGroup
(
pRepo
,
&
(
pFileH
->
pFGroup
[
0
]));
pthread_rwlock_unlock
(
&
pFileH
->
fhlock
);
}
}
if
(
pFileH
->
nFGroups
>=
pFileH
->
maxFGroups
)
return
NULL
;
ASSERT
(
pFileH
->
nFGroups
<
pFileH
->
maxFGroups
)
;
SFileGroup
fGroup
;
SFileGroup
fGroup
;
SFileGroup
*
pFGroup
=
&
fGroup
;
SFileGroup
*
pFGroup
=
&
fGroup
;
...
@@ -342,8 +366,7 @@ void tsdbFitRetention(STsdbRepo *pRepo) {
...
@@ -342,8 +366,7 @@ void tsdbFitRetention(STsdbRepo *pRepo) {
STsdbFileH
*
pFileH
=
pRepo
->
tsdbFileH
;
STsdbFileH
*
pFileH
=
pRepo
->
tsdbFileH
;
SFileGroup
*
pGroup
=
pFileH
->
pFGroup
;
SFileGroup
*
pGroup
=
pFileH
->
pFGroup
;
int
mfid
=
(
int
)(
TSDB_KEY_FILEID
(
taosGetTimestamp
(
pCfg
->
precision
),
pCfg
->
daysPerFile
,
pCfg
->
precision
)
-
int
mfid
=
tsdbGetCurrMinFid
(
pCfg
->
precision
,
pCfg
->
keep
,
pCfg
->
daysPerFile
);
TSDB_MAX_FILE
(
pCfg
->
keep
,
pCfg
->
daysPerFile
));
pthread_rwlock_wrlock
(
&
(
pFileH
->
fhlock
));
pthread_rwlock_wrlock
(
&
(
pFileH
->
fhlock
));
...
@@ -547,3 +570,11 @@ static void tsdbInitFileGroup(SFileGroup *pFGroup, STsdbRepo *pRepo) {
...
@@ -547,3 +570,11 @@ static void tsdbInitFileGroup(SFileGroup *pFGroup, STsdbRepo *pRepo) {
}
}
}
}
}
}
static
TSKEY
tsdbGetCurrMinKey
(
int8_t
precision
,
int32_t
keep
)
{
return
(
TSKEY
)(
taosGetTimestamp
(
precision
)
-
keep
*
tsMsPerDay
[
precision
]);
}
static
int
tsdbGetCurrMinFid
(
int8_t
precision
,
int32_t
keep
,
int32_t
days
)
{
return
TSDB_KEY_FILEID
(
tsdbGetCurrMinKey
(
precision
,
keep
),
days
,
precision
);
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录