Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
47d493e8
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看板
提交
47d493e8
编写于
12月 30, 2022
作者:
H
Hongze Cheng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
more code
上级
38b4c5c1
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
78 addition
and
76 deletion
+78
-76
source/dnode/vnode/src/inc/tsdb.h
source/dnode/vnode/src/inc/tsdb.h
+1
-0
source/dnode/vnode/src/tsdb/tsdbCompact.c
source/dnode/vnode/src/tsdb/tsdbCompact.c
+77
-76
未找到文件。
source/dnode/vnode/src/inc/tsdb.h
浏览文件 @
47d493e8
...
...
@@ -638,6 +638,7 @@ struct SDataFReader {
uint8_t
*
aBuf
[
3
];
};
// NOTE: do NOT change the order of the fields
typedef
struct
{
int64_t
suid
;
int64_t
uid
;
...
...
source/dnode/vnode/src/tsdb/tsdbCompact.c
浏览文件 @
47d493e8
...
...
@@ -688,13 +688,6 @@ static int32_t tsdbOpenCompactor(STsdbCompactor *pCompactor) {
STsdb
*
pTsdb
=
pCompactor
->
pTsdb
;
// next compact file
pCompactor
->
pDFileSet
=
(
SDFileSet
*
)
taosArraySearch
(
pCompactor
->
fs
.
aDFileSet
,
&
(
SDFileSet
){.
fid
=
pCompactor
->
fid
},
tDFileSetCmprFn
,
TD_GT
);
if
(
pCompactor
->
pDFileSet
==
NULL
)
goto
_exit
;
pCompactor
->
fid
=
pCompactor
->
pDFileSet
->
fid
;
// reader
code
=
tsdbDataFReaderOpen
(
&
pCompactor
->
pReader
,
pTsdb
,
pCompactor
->
pDFileSet
);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
...
...
@@ -841,111 +834,119 @@ _exit:
return
code
;
}
int32_t
tsdbCompact
(
STsdb
*
pTsdb
,
int32_t
flag
)
{
static
int32_t
tsdbCompactFileSet
(
STsdbCompactor
*
pCompactor
)
{
int32_t
code
=
0
;
int32_t
lino
=
0
;
// Check if can do compact (TODO)
// open compactor
code
=
tsdbOpenCompactor
(
pCompactor
);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
// Do compact
STsdbCompactor
*
pCompactor
=
&
(
STsdbCompactor
){
0
};
// do compact
SRowInfo
*
pRowInfo
;
STSchema
*
pTSchema
;
int64_t
nRow
=
0
;
code
=
tsdb
BeginCompact
(
pTsdb
,
pCompactor
);
code
=
tsdb
CompactGetRow
(
pCompactor
,
&
pRowInfo
,
&
pTSchema
);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
while
(
true
)
{
code
=
tsdbOpenCompactor
(
pCompactor
);
if
(
pRowInfo
&&
(
code
=
tBlockDataInit
(
&
pCompactor
->
bData
,
(
TABLEID
*
)
pRowInfo
,
pTSchema
,
NULL
,
0
)))
{
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
}
if
(
pCompactor
->
pDFileSet
==
NULL
)
break
;
while
(
pRowInfo
)
{
nRow
++
;
// loop to merge row by row
SRowInfo
*
pRowInfo
;
STSchema
*
pTSchema
;
int64_t
nRow
=
0
;
if
((
pCompactor
->
tableId
.
suid
!=
pRowInfo
->
suid
)
||
// different super table
(
pCompactor
->
tableId
.
uid
!=
pRowInfo
->
uid
&&
(
pRowInfo
->
suid
==
0
||
pCompactor
->
bData
.
uid
&&
pCompactor
->
bData
.
nRow
>=
pCompactor
->
minRows
))
// different table
)
{
code
=
tsdbCompactWriteBlockData
(
pCompactor
);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
code
=
tsdbCompactGetRow
(
pCompactor
,
&
pRowInfo
,
&
pTSchema
);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
code
=
tsdbCompactWriteDataBlk
(
pCompactor
);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
if
(
pRowInfo
&&
(
code
=
tBlockDataInit
(
&
pCompactor
->
bData
,
&
(
TABLEID
){.
suid
=
pRowInfo
->
suid
,
.
uid
=
pRowInfo
->
uid
},
pTSchema
,
NULL
,
0
)))
{
code
=
tBlockDataInit
(
&
pCompactor
->
bData
,
(
TABLEID
*
)
pRowInfo
,
pTSchema
,
NULL
,
0
);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
}
while
(
pRowInfo
)
{
nRow
++
;
// append row to block data
code
=
tBlockDataAppendRowEx
(
&
pCompactor
->
bData
,
&
pRowInfo
->
row
,
pTSchema
,
pRowInfo
->
uid
);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
if
(
pCompactor
->
bData
.
suid
==
0
&&
pCompactor
->
bData
.
uid
==
0
)
{
// init the block data if not initialized yet
code
=
tBlockDataInit
(
&
pCompactor
->
bData
,
&
(
TABLEID
){.
suid
=
pRowInfo
->
suid
,
.
uid
=
pRowInfo
->
uid
},
pTSchema
,
NULL
,
0
);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
}
else
{
if
((
pCompactor
->
tableId
.
suid
!=
pRowInfo
->
suid
)
||
// different super table
(
pCompactor
->
tableId
.
uid
!=
pRowInfo
->
uid
&&
(
pRowInfo
->
suid
==
0
||
pCompactor
->
bData
.
uid
&&
pCompactor
->
bData
.
nRow
>=
pCompactor
->
minRows
))
// different table
)
{
code
=
tsdbCompactWriteBlockData
(
pCompactor
);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
code
=
tsdbCompactWriteDataBlk
(
pCompactor
);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
code
=
tBlockDataInit
(
&
pCompactor
->
bData
,
&
(
TABLEID
){.
suid
=
pRowInfo
->
suid
,
.
uid
=
pRowInfo
->
uid
},
pTSchema
,
NULL
,
0
);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
}
}
pCompactor
->
tableId
.
suid
=
pRowInfo
->
suid
;
pCompactor
->
tableId
.
uid
=
pRowInfo
->
uid
;
// append row to block data
code
=
tBlockDataAppendRowEx
(
&
pCompactor
->
bData
,
&
pRowInfo
->
row
,
pTSchema
,
pRowInfo
->
uid
);
// check if block data is full
if
(
pCompactor
->
bData
.
nRow
>=
pCompactor
->
maxRows
)
{
code
=
tsdbCompactWriteBlockData
(
pCompactor
);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
}
pCompactor
->
tableId
.
suid
=
pRowInfo
->
suid
;
pCompactor
->
tableId
.
uid
=
pRowInfo
->
uid
;
// iterate to next row
code
=
tsdbCompactNextRow
(
pCompactor
);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
// check if block data is full
if
(
pCompactor
->
bData
.
nRow
>=
pCompactor
->
maxRows
)
{
code
=
tsdbCompactWriteBlockData
(
pCompactor
);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
}
code
=
tsdbCompactGetRow
(
pCompactor
,
&
pRowInfo
,
&
pTSchema
);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
}
// iterate to next row
code
=
tsdbCompactNextRow
(
pCompactor
);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
// handle remain data
code
=
tsdbCompactWriteBlockData
(
pCompactor
);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
code
=
tsdbCompactGetRow
(
pCompactor
,
&
pRowInfo
,
&
pTSchema
);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
}
code
=
tsdbCompactWriteDataBlk
(
pCompactor
);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
code
=
tsdbCompactWriteBlockData
(
pCompactor
);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
code
=
tsdbWriteBlockIdx
(
pCompactor
->
pWriter
,
pCompactor
->
aBlockIdx
);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
code
=
tsdbCompactWriteDataBlk
(
pCompactor
);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
code
=
tsdbWriteSttBlk
(
pCompactor
->
pWriter
,
pCompactor
->
aSttBlk
);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
code
=
tsdbWriteBlockIdx
(
pCompactor
->
pWriter
,
pCompactor
->
aBlockIdx
);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
code
=
tsdbUpdateDFileSetHeader
(
pCompactor
->
pWriter
);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
code
=
tsdbWriteSttBlk
(
pCompactor
->
pWriter
,
pCompactor
->
aSttBlk
);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
code
=
tsdbFSUpsertFSet
(
&
pCompactor
->
fs
,
&
pCompactor
->
pWriter
->
wSet
);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
code
=
tsdbUpdateDFileSetHeader
(
pCompactor
->
pWriter
);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
code
=
tsdbDataFWriterClose
(
&
pCompactor
->
pWriter
,
1
);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
code
=
tsdbFSUpsertFSet
(
&
pCompactor
->
fs
,
&
pCompactor
->
pWriter
->
wSet
);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
_exit:
// close compactor
tsdbCloseCompactor
(
pCompactor
);
return
code
;
}
code
=
tsdbDataFWriterClose
(
&
pCompactor
->
pWriter
,
1
);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
int32_t
tsdbCompact
(
STsdb
*
pTsdb
,
int32_t
flag
)
{
int32_t
code
=
0
;
int32_t
lino
=
0
;
STsdbCompactor
*
pCompactor
=
&
(
STsdbCompactor
){
0
};
tsdbCloseCompactor
(
pCompactor
);
// begin compact
code
=
tsdbBeginCompact
(
pTsdb
,
pCompactor
);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
// do compact each file set
while
(
true
)
{
pCompactor
->
pDFileSet
=
(
SDFileSet
*
)
taosArraySearch
(
pCompactor
->
fs
.
aDFileSet
,
&
(
SDFileSet
){.
fid
=
pCompactor
->
fid
},
tDFileSetCmprFn
,
TD_GT
);
if
(
pCompactor
->
pDFileSet
==
NULL
)
break
;
pCompactor
->
fid
=
pCompactor
->
pDFileSet
->
fid
;
code
=
tsdbCompactFileSet
(
pCompactor
);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
}
code
=
tsdbFSUpsertDelFile
(
&
pCompactor
->
fs
,
NULL
);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
_exit:
// commit/abort compact
if
(
code
)
{
tsdbError
(
"vgId:%d %s failed at line %d since %s"
,
TD_VID
(
pTsdb
->
pVnode
),
__func__
,
lino
,
tstrerror
(
code
));
tsdbAbortCompact
(
pCompactor
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录