Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
b1e42fd5
T
TDengine
项目概览
taosdata
/
TDengine
大约 2 年 前同步成功
通知
1192
Star
22018
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看板
提交
b1e42fd5
编写于
11月 11, 2021
作者:
C
Cary Xu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update
上级
f79c72d5
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
53 addition
and
73 deletion
+53
-73
src/tsdb/inc/tsdbCommit.h
src/tsdb/inc/tsdbCommit.h
+8
-0
src/tsdb/src/tsdbCommit.c
src/tsdb/src/tsdbCommit.c
+1
-7
src/tsdb/src/tsdbTruncate.c
src/tsdb/src/tsdbTruncate.c
+42
-64
src/vnode/src/vnodeMain.c
src/vnode/src/vnodeMain.c
+2
-2
未找到文件。
src/tsdb/inc/tsdbCommit.h
浏览文件 @
b1e42fd5
...
@@ -54,4 +54,12 @@ static FORCE_INLINE int tsdbGetFidLevel(int fid, SRtn *pRtn) {
...
@@ -54,4 +54,12 @@ static FORCE_INLINE int tsdbGetFidLevel(int fid, SRtn *pRtn) {
}
}
}
}
static
FORCE_INLINE
int
TSDB_KEY_FID
(
TSKEY
key
,
int32_t
days
,
int8_t
precision
)
{
if
(
key
<
0
)
{
return
(
int
)((
key
+
1
)
/
tsTickPerDay
[
precision
]
/
days
-
1
);
}
else
{
return
(
int
)((
key
/
tsTickPerDay
[
precision
]
/
days
));
}
}
#endif
/* _TD_TSDB_COMMIT_H_ */
#endif
/* _TD_TSDB_COMMIT_H_ */
\ No newline at end of file
src/tsdb/src/tsdbCommit.c
浏览文件 @
b1e42fd5
...
@@ -17,13 +17,7 @@
...
@@ -17,13 +17,7 @@
extern
int32_t
tsTsdbMetaCompactRatio
;
extern
int32_t
tsTsdbMetaCompactRatio
;
#define TSDB_MAX_SUBBLOCKS 8
#define TSDB_MAX_SUBBLOCKS 8
FORCE_INLINE
int
TSDB_KEY_FID
(
TSKEY
key
,
int32_t
days
,
int8_t
precision
)
{
if
(
key
<
0
)
{
return
(
int
)((
key
+
1
)
/
tsTickPerDay
[
precision
]
/
days
-
1
);
}
else
{
return
(
int
)((
key
/
tsTickPerDay
[
precision
]
/
days
));
}
}
typedef
struct
{
typedef
struct
{
SRtn
rtn
;
// retention snapshot
SRtn
rtn
;
// retention snapshot
SFSIter
fsIter
;
// tsdb file iterator
SFSIter
fsIter
;
// tsdb file iterator
...
...
src/tsdb/src/tsdbTruncate.c
浏览文件 @
b1e42fd5
...
@@ -49,7 +49,6 @@ static void tsdbEndTruncate(STsdbRepo *pRepo, int eno);
...
@@ -49,7 +49,6 @@ static void tsdbEndTruncate(STsdbRepo *pRepo, int eno);
static
int
tsdbTruncateMeta
(
STsdbRepo
*
pRepo
);
static
int
tsdbTruncateMeta
(
STsdbRepo
*
pRepo
);
static
int
tsdbTruncateTSData
(
STsdbRepo
*
pRepo
,
void
*
param
);
static
int
tsdbTruncateTSData
(
STsdbRepo
*
pRepo
,
void
*
param
);
static
int
tsdbTruncateFSet
(
STruncateH
*
pTruncateH
,
SDFileSet
*
pSet
);
static
int
tsdbTruncateFSet
(
STruncateH
*
pTruncateH
,
SDFileSet
*
pSet
);
static
bool
tsdbShouldTruncate
(
STsdbRepo
*
pRepo
,
STruncateH
*
pTruncateH
);
static
int
tsdbInitTruncateH
(
STruncateH
*
pTruncateH
,
STsdbRepo
*
pRepo
);
static
int
tsdbInitTruncateH
(
STruncateH
*
pTruncateH
,
STsdbRepo
*
pRepo
);
static
void
tsdbDestroyTruncateH
(
STruncateH
*
pTruncateH
);
static
void
tsdbDestroyTruncateH
(
STruncateH
*
pTruncateH
);
static
int
tsdbInitCompTbArray
(
STruncateH
*
pTruncateH
);
static
int
tsdbInitCompTbArray
(
STruncateH
*
pTruncateH
);
...
@@ -178,34 +177,38 @@ static int tsdbTruncateMeta(STsdbRepo *pRepo) {
...
@@ -178,34 +177,38 @@ static int tsdbTruncateMeta(STsdbRepo *pRepo) {
static
int
tsdbTruncateTSData
(
STsdbRepo
*
pRepo
,
void
*
param
)
{
static
int
tsdbTruncateTSData
(
STsdbRepo
*
pRepo
,
void
*
param
)
{
STsdbCfg
*
pCfg
=
REPO_CFG
(
pRepo
);
STsdbCfg
*
pCfg
=
REPO_CFG
(
pRepo
);
STruncateH
compact
H
;
STruncateH
truncate
H
;
SDFileSet
*
pSet
=
NULL
;
SDFileSet
*
pSet
=
NULL
;
STruncateTblMsg
*
pMsg
=
(
STruncateTblMsg
*
)
param
;
STruncateTblMsg
*
pMsg
=
(
STruncateTblMsg
*
)
param
;
ASSERT
(
pMsg
!=
NULL
);
ASSERT
(
pMsg
!=
NULL
);
tsdbDebug
(
"vgId:%d start to truncate TS data for %"
PRIu64
,
REPO_ID
(
pRepo
),
pMsg
->
uid
);
tsdbDebug
(
"vgId:%d start to truncate TS data for %"
PRIu64
,
REPO_ID
(
pRepo
),
pMsg
->
uid
);
if
(
tsdbInitTruncateH
(
&
compact
H
,
pRepo
)
<
0
)
{
if
(
tsdbInitTruncateH
(
&
truncate
H
,
pRepo
)
<
0
)
{
return
-
1
;
return
-
1
;
}
}
int
sFid
=
TSDB_KEY_FID
(
pMsg
->
span
[
0
].
skey
,
pCfg
->
daysPerFile
,
pCfg
->
precision
);
int
sFid
=
TSDB_KEY_FID
(
pMsg
->
span
[
0
].
skey
,
pCfg
->
daysPerFile
,
pCfg
->
precision
);
int
eFid
=
TSDB_KEY_FID
(
pMsg
->
span
[
0
].
ekey
,
pCfg
->
daysPerFile
,
pCfg
->
precision
);
int
eFid
=
TSDB_KEY_FID
(
pMsg
->
span
[
0
].
ekey
,
pCfg
->
daysPerFile
,
pCfg
->
precision
);
ASSERT
(
sFid
<=
eFid
);
while
((
pSet
=
tsdbFSIterNext
(
&
(
compact
H
.
fsIter
))))
{
while
((
pSet
=
tsdbFSIterNext
(
&
(
truncate
H
.
fsIter
))))
{
// remove expired files
// remove expired files
if
(
pSet
->
fid
<
compact
H
.
rtn
.
minFid
)
{
if
(
pSet
->
fid
<
truncate
H
.
rtn
.
minFid
)
{
tsdbInfo
(
"vgId:%d FSET %d on level %d disk id %d expires, remove it"
,
REPO_ID
(
pRepo
),
pSet
->
fid
,
tsdbInfo
(
"vgId:%d FSET %d on level %d disk id %d expires, remove it"
,
REPO_ID
(
pRepo
),
pSet
->
fid
,
TSDB_FSET_LEVEL
(
pSet
),
TSDB_FSET_ID
(
pSet
));
TSDB_FSET_LEVEL
(
pSet
),
TSDB_FSET_ID
(
pSet
));
continue
;
continue
;
}
}
if
((
pSet
->
fid
!=
sFid
)
&&
(
pSet
->
fid
!=
eFid
))
{
if
((
pSet
->
fid
<
sFid
)
||
(
pSet
->
fid
>
eFid
))
{
tsdbDebug
(
"vgId:%d no need to truncate FSET %d, sFid %d, eFid %d"
,
REPO_ID
(
pRepo
),
pSet
->
fid
,
sFid
,
eFid
);
if
(
tsdbApplyRtnOnFSet
(
pRepo
,
pSet
,
&
(
truncateH
.
rtn
))
<
0
)
{
return
-
1
;
}
continue
;
continue
;
}
}
#if 0
#if 0
// TODO: How to make the decision? The test case should cover this scenario.
if (TSDB_FSET_LEVEL(pSet) == TFS_MAX_LEVEL) {
if (TSDB_FSET_LEVEL(pSet) == TFS_MAX_LEVEL) {
tsdbDebug("vgId:%d FSET %d on level %d, should not truncate", REPO_ID(pRepo), pSet->fid, TFS_MAX_LEVEL);
tsdbDebug("vgId:%d FSET %d on level %d, should not truncate", REPO_ID(pRepo), pSet->fid, TFS_MAX_LEVEL);
tsdbUpdateDFileSet(REPO_FS(pRepo), pSet);
tsdbUpdateDFileSet(REPO_FS(pRepo), pSet);
...
@@ -213,14 +216,14 @@ static int tsdbTruncateTSData(STsdbRepo *pRepo, void *param) {
...
@@ -213,14 +216,14 @@ static int tsdbTruncateTSData(STsdbRepo *pRepo, void *param) {
}
}
#endif
#endif
if
(
tsdbTruncateFSet
(
&
compact
H
,
pSet
)
<
0
)
{
if
(
tsdbTruncateFSet
(
&
truncate
H
,
pSet
)
<
0
)
{
tsdbDestroyTruncateH
(
&
compact
H
);
tsdbDestroyTruncateH
(
&
truncate
H
);
tsdbError
(
"vgId:%d failed to truncate FSET %d since %s"
,
REPO_ID
(
pRepo
),
pSet
->
fid
,
tstrerror
(
terrno
));
tsdbError
(
"vgId:%d failed to truncate FSET %d since %s"
,
REPO_ID
(
pRepo
),
pSet
->
fid
,
tstrerror
(
terrno
));
return
-
1
;
return
-
1
;
}
}
}
}
tsdbDestroyTruncateH
(
&
compact
H
);
tsdbDestroyTruncateH
(
&
truncate
H
);
tsdbDebug
(
"vgId:%d truncate TS data over"
,
REPO_ID
(
pRepo
));
tsdbDebug
(
"vgId:%d truncate TS data over"
,
REPO_ID
(
pRepo
));
return
0
;
return
0
;
}
}
...
@@ -229,76 +232,51 @@ static int tsdbTruncateFSet(STruncateH *pTruncateH, SDFileSet *pSet) {
...
@@ -229,76 +232,51 @@ static int tsdbTruncateFSet(STruncateH *pTruncateH, SDFileSet *pSet) {
STsdbRepo
*
pRepo
=
TSDB_TRUNCATE_REPO
(
pTruncateH
);
STsdbRepo
*
pRepo
=
TSDB_TRUNCATE_REPO
(
pTruncateH
);
SDiskID
did
;
SDiskID
did
;
tsdbDebug
(
"vgId:%d start to
compact
FSET %d on level %d id %d"
,
REPO_ID
(
pRepo
),
pSet
->
fid
,
TSDB_FSET_LEVEL
(
pSet
),
tsdbDebug
(
"vgId:%d start to
truncate
FSET %d on level %d id %d"
,
REPO_ID
(
pRepo
),
pSet
->
fid
,
TSDB_FSET_LEVEL
(
pSet
),
TSDB_FSET_ID
(
pSet
));
TSDB_FSET_ID
(
pSet
));
if
(
tsdbTruncateFSetInit
(
pTruncateH
,
pSet
)
<
0
)
{
if
(
tsdbTruncateFSetInit
(
pTruncateH
,
pSet
)
<
0
)
{
return
-
1
;
return
-
1
;
}
}
if
(
!
tsdbShouldTruncate
(
pRepo
,
pTruncateH
))
{
// Create new fset as truncated fset
tsdbDebug
(
"vgId:%d no need to compact FSET %d"
,
REPO_ID
(
pRepo
),
pSet
->
fid
);
tfsAllocDisk
(
tsdbGetFidLevel
(
pSet
->
fid
,
&
(
pTruncateH
->
rtn
)),
&
(
did
.
level
),
&
(
did
.
id
));
if
(
tsdbApplyRtnOnFSet
(
TSDB_TRUNCATE_REPO
(
pTruncateH
),
pSet
,
&
(
pTruncateH
->
rtn
))
<
0
)
{
if
(
did
.
level
==
TFS_UNDECIDED_LEVEL
)
{
tsdbTruncateFSetEnd
(
pTruncateH
);
terrno
=
TSDB_CODE_TDB_NO_AVAIL_DISK
;
return
-
1
;
tsdbError
(
"vgId:%d failed to truncate FSET %d since %s"
,
REPO_ID
(
pRepo
),
pSet
->
fid
,
tstrerror
(
terrno
));
}
tsdbTruncateFSetEnd
(
pTruncateH
);
}
else
{
return
-
1
;
// Create new fset as compacted fset
}
tfsAllocDisk
(
tsdbGetFidLevel
(
pSet
->
fid
,
&
(
pTruncateH
->
rtn
)),
&
(
did
.
level
),
&
(
did
.
id
));
#if 1 // how to make the decision?
if
(
did
.
level
==
TFS_UNDECIDED_LEVEL
)
{
terrno
=
TSDB_CODE_TDB_NO_AVAIL_DISK
;
tsdbError
(
"vgId:%d failed to compact FSET %d since %s"
,
REPO_ID
(
pRepo
),
pSet
->
fid
,
tstrerror
(
terrno
));
tsdbTruncateFSetEnd
(
pTruncateH
);
return
-
1
;
}
#endif
tsdbInitDFileSet
(
TSDB_TRUNCATE_WSET
(
pTruncateH
),
did
,
REPO_ID
(
pRepo
),
TSDB_FSET_FID
(
pSet
),
FS_TXN_VERSION
(
REPO_FS
(
pRepo
)),
TSDB_LATEST_FSET_VER
);
if
(
tsdbCreateDFileSet
(
TSDB_TRUNCATE_WSET
(
pTruncateH
),
true
)
<
0
)
{
tsdbError
(
"vgId:%d failed to compact FSET %d since %s"
,
REPO_ID
(
pRepo
),
pSet
->
fid
,
tstrerror
(
terrno
));
tsdbTruncateFSetEnd
(
pTruncateH
);
return
-
1
;
}
if
(
tsdbTruncateFSetImpl
(
pTruncateH
)
<
0
)
{
tsdbInitDFileSet
(
TSDB_TRUNCATE_WSET
(
pTruncateH
),
did
,
REPO_ID
(
pRepo
),
TSDB_FSET_FID
(
pSet
),
tsdbCloseDFileSet
(
TSDB_TRUNCATE_WSET
(
pTruncateH
));
FS_TXN_VERSION
(
REPO_FS
(
pRepo
)),
TSDB_LATEST_FSET_VER
);
tsdbRemoveDFileSet
(
TSDB_TRUNCATE_WSET
(
pTruncateH
));
if
(
tsdbCreateDFileSet
(
TSDB_TRUNCATE_WSET
(
pTruncateH
),
true
)
<
0
)
{
tsdbTruncateFSetEnd
(
pTruncateH
);
tsdbError
(
"vgId:%d failed to truncate FSET %d since %s"
,
REPO_ID
(
pRepo
),
pSet
->
fid
,
tstrerror
(
terrno
));
return
-
1
;
tsdbTruncateFSetEnd
(
pTruncateH
);
}
return
-
1
;
}
if
(
tsdbTruncateFSetImpl
(
pTruncateH
)
<
0
)
{
tsdbCloseDFileSet
(
TSDB_TRUNCATE_WSET
(
pTruncateH
));
tsdbCloseDFileSet
(
TSDB_TRUNCATE_WSET
(
pTruncateH
));
tsdbUpdateDFileSet
(
REPO_FS
(
pRepo
),
TSDB_TRUNCATE_WSET
(
pTruncateH
));
tsdbRemoveDFileSet
(
TSDB_TRUNCATE_WSET
(
pTruncateH
));
tsdbDebug
(
"vgId:%d FSET %d compact over"
,
REPO_ID
(
pRepo
),
pSet
->
fid
);
tsdbTruncateFSetEnd
(
pTruncateH
);
return
-
1
;
}
}
tsdbCloseDFileSet
(
TSDB_TRUNCATE_WSET
(
pTruncateH
));
tsdbUpdateDFileSet
(
REPO_FS
(
pRepo
),
TSDB_TRUNCATE_WSET
(
pTruncateH
));
tsdbDebug
(
"vgId:%d FSET %d truncate over"
,
REPO_ID
(
pRepo
),
pSet
->
fid
);
tsdbTruncateFSetEnd
(
pTruncateH
);
tsdbTruncateFSetEnd
(
pTruncateH
);
return
0
;
return
0
;
}
}
static
bool
tsdbShouldTruncate
(
STsdbRepo
*
pRepo
,
STruncateH
*
pTruncateH
)
{
static
int
tsdbInitTruncateH
(
STruncateH
*
pTruncateH
,
STsdbRepo
*
pRepo
)
{
STsdbCfg
*
pCfg
=
REPO_CFG
(
pRepo
);
TSKEY
minKey
,
midKey
,
maxKey
,
now
;
now
=
taosGetTimestamp
(
pCfg
->
precision
);
minKey
=
now
-
pCfg
->
keep
*
tsTickPerDay
[
pCfg
->
precision
];
midKey
=
now
-
pCfg
->
keep2
*
tsTickPerDay
[
pCfg
->
precision
];
maxKey
=
now
-
pCfg
->
keep1
*
tsTickPerDay
[
pCfg
->
precision
];
pRtn
->
minKey
=
minKey
;
pRtn
->
minFid
=
(
int
)(
TSDB_KEY_FID
(
minKey
,
pCfg
->
daysPerFile
,
pCfg
->
precision
));
}
static
int
tsdbInitTruncateH
(
STruncateH
*
pTruncateH
,
STsdbRepo
*
pRepo
,
)
{
STsdbCfg
*
pCfg
=
REPO_CFG
(
pRepo
);
STsdbCfg
*
pCfg
=
REPO_CFG
(
pRepo
);
memset
(
pTruncateH
,
0
,
sizeof
(
*
pTruncateH
));
memset
(
pTruncateH
,
0
,
sizeof
(
*
pTruncateH
));
pTruncateH
->
TSDB_FSET_SET_CLOSED
(
TSDB_TRUNCATE_WSET
(
pTruncateH
));
TSDB_FSET_SET_CLOSED
(
TSDB_TRUNCATE_WSET
(
pTruncateH
));
tsdbGetRtnSnap
(
pRepo
,
&
(
pTruncateH
->
rtn
));
tsdbGetRtnSnap
(
pRepo
,
&
(
pTruncateH
->
rtn
));
tsdbFSIterInit
(
&
(
pTruncateH
->
fsIter
),
REPO_FS
(
pRepo
),
TSDB_FS_ITER_FORWARD
);
tsdbFSIterInit
(
&
(
pTruncateH
->
fsIter
),
REPO_FS
(
pRepo
),
TSDB_FS_ITER_FORWARD
);
...
@@ -470,7 +448,7 @@ static int tsdbTruncateFSetImpl(STruncateH *pTruncateH) {
...
@@ -470,7 +448,7 @@ static int tsdbTruncateFSetImpl(STruncateH *pTruncateH) {
}
}
tdFreeSchema
(
pSchema
);
tdFreeSchema
(
pSchema
);
// Loop to
compact
each block data
// Loop to
truncate
each block data
for
(
int
i
=
0
;
i
<
pTh
->
pBlkIdx
->
numOfBlocks
;
i
++
)
{
for
(
int
i
=
0
;
i
<
pTh
->
pBlkIdx
->
numOfBlocks
;
i
++
)
{
SBlock
*
pBlock
=
pTh
->
pInfo
->
blocks
+
i
;
SBlock
*
pBlock
=
pTh
->
pInfo
->
blocks
+
i
;
...
...
src/vnode/src/vnodeMain.c
浏览文件 @
b1e42fd5
...
@@ -145,8 +145,8 @@ int32_t vnodeTruncate(STruncateTblMsg *pMsg) {
...
@@ -145,8 +145,8 @@ int32_t vnodeTruncate(STruncateTblMsg *pMsg) {
param
->
vgId
=
2
;
param
->
vgId
=
2
;
param
->
uid
=
562949986978794
;
param
->
uid
=
562949986978794
;
param
->
nSpan
=
1
;
param
->
nSpan
=
1
;
param
->
span
[
0
].
skey
=
0
;
param
->
span
[
0
].
skey
=
163741767800
0
;
param
->
span
[
0
].
ekey
=
1
;
param
->
span
[
0
].
ekey
=
1
637417679000
;
if
(
tsdbTruncate
(((
SVnodeObj
*
)
pVnode
)
->
tsdb
,
param
)
<
0
)
{
if
(
tsdbTruncate
(((
SVnodeObj
*
)
pVnode
)
->
tsdb
,
param
)
<
0
)
{
tfree
(
param
);
tfree
(
param
);
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录