Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
3b3b8d4f
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看板
提交
3b3b8d4f
编写于
12月 27, 2022
作者:
H
Hongze Cheng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
more code
上级
f0dc9a82
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
54 addition
and
22 deletion
+54
-22
source/dnode/vnode/src/tsdb/tsdbCompact.c
source/dnode/vnode/src/tsdb/tsdbCompact.c
+54
-22
未找到文件。
source/dnode/vnode/src/tsdb/tsdbCompact.c
浏览文件 @
3b3b8d4f
...
...
@@ -54,8 +54,10 @@ typedef struct STsdbDataIter {
typedef
struct
{
STsdb
*
pTsdb
;
STsdbFS
fs
;
int64_t
cid
;
int32_t
maxRows
;
int32_t
minRows
;
STsdbFS
fs
;
int32_t
fid
;
SDFileSet
*
pDFileSet
;
SDataFReader
*
pReader
;
...
...
@@ -250,12 +252,18 @@ static int32_t tsdbBeginCompact(STsdb *pTsdb, STsdbCompactor *pCompactor) {
int32_t
lino
=
0
;
pCompactor
->
pTsdb
=
pTsdb
;
// pCompactor->cid = 0; (TODO)
pCompactor
->
maxRows
=
pTsdb
->
pVnode
->
config
.
tsdbCfg
.
maxRows
;
pCompactor
->
minRows
=
pTsdb
->
pVnode
->
config
.
tsdbCfg
.
minRows
;
code
=
tsdbFSCopy
(
pTsdb
,
&
pCompactor
->
fs
);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
pCompactor
->
fid
=
INT32_MIN
;
code
=
tBlockDataCreate
(
&
pCompactor
->
bData
);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
_exit:
if
(
code
)
{
tsdbError
(
"vgId:%d %s failed at line %d since %s"
,
TD_VID
(
pTsdb
->
pVnode
),
__func__
,
lino
,
tstrerror
(
code
));
...
...
@@ -360,7 +368,7 @@ _exit:
return
code
;
}
static
int32_t
tsdbCompactGetRow
(
STsdbCompactor
*
pCompactor
,
TSDBROW
**
ppRow
)
{
static
int32_t
tsdbCompactGetRow
(
STsdbCompactor
*
pCompactor
,
SRowInfo
**
ppRowInfo
,
STSchema
**
ppTSchema
)
{
int32_t
code
=
0
;
int32_t
lino
=
0
;
...
...
@@ -370,9 +378,11 @@ static int32_t tsdbCompactGetRow(STsdbCompactor *pCompactor, TSDBROW **ppRow) {
}
if
(
pCompactor
->
pIter
)
{
*
ppRow
=
&
pCompactor
->
pIter
->
rowInfo
.
row
;
*
ppRowInfo
=
&
pCompactor
->
pIter
->
rowInfo
;
*
ppTSchema
=
NULL
;
// TODO
}
else
{
*
ppRow
=
NULL
;
*
ppRowInfo
=
NULL
;
*
ppTSchema
=
NULL
;
}
_exit:
...
...
@@ -421,6 +431,7 @@ static int32_t tsdbOpenCompactor(STsdbCompactor *pCompactor) {
}
}
pCompactor
->
pIter
=
NULL
;
tBlockDataReset
(
&
pCompactor
->
bData
);
_exit:
if
(
code
)
{
...
...
@@ -454,49 +465,70 @@ int32_t tsdbCompact(STsdb *pTsdb, int32_t flag) {
// Check if can do compact (TODO)
// Do compact
STsdbCompactor
compactor
=
{
0
};
STsdbCompactor
*
pCompactor
=
&
(
STsdbCompactor
)
{
0
};
code
=
tsdbBeginCompact
(
pTsdb
,
&
c
ompactor
);
code
=
tsdbBeginCompact
(
pTsdb
,
pC
ompactor
);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
while
(
true
)
{
code
=
tsdbOpenCompactor
(
&
c
ompactor
);
code
=
tsdbOpenCompactor
(
pC
ompactor
);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
if
(
compactor
.
pDFileSet
==
NULL
)
break
;
if
(
pCompactor
->
pDFileSet
==
NULL
)
break
;
// loop to merge row by row
TSDBROW
*
pRow
=
NULL
;
int64_t
nRow
=
0
;
SRowInfo
*
pRowInfo
=
NULL
;
STSchema
*
pTSchema
=
NULL
;
int64_t
nRow
=
0
;
for
(;;)
{
code
=
tsdbCompactGetRow
(
&
compactor
,
&
pRow
);
code
=
tsdbCompactGetRow
(
pCompactor
,
&
pRowInfo
,
&
pTSchema
);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
if
(
pRow
==
NULL
)
break
;
if
(
pRow
Info
==
NULL
)
break
;
nRow
++
;
code
=
tsdbCompactNextRow
(
&
compactor
);
// write block data if schema changed
if
((
pCompactor
->
bData
.
suid
||
pCompactor
->
bData
.
uid
)
&&
!
TABLE_SAME_SCHEMA
(
pCompactor
->
bData
.
suid
,
pCompactor
->
bData
.
uid
,
pRowInfo
->
suid
,
pRowInfo
->
uid
))
{
// TODO: write block data
ASSERT
(
0
);
// set block data not initialized
tBlockDataReset
(
&
pCompactor
->
bData
);
}
// init the block data if not initialized yet
if
(
pCompactor
->
bData
.
suid
==
0
&&
pCompactor
->
bData
.
uid
==
0
)
{
code
=
tBlockDataInit
(
&
pCompactor
->
bData
,
&
(
TABLEID
){.
suid
=
pRowInfo
->
suid
,
.
uid
=
pRowInfo
->
uid
},
pTSchema
,
NULL
,
0
);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
}
// append row to block data
code
=
tBlockDataAppendRow
(
&
pCompactor
->
bData
,
&
pRowInfo
->
row
,
pTSchema
,
pRowInfo
->
uid
);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
// code = tBlockDataAppendRow(&compactor.bData, pRow, pRow, NULL, 0);
// TSDB_CHECK_CODE(code, lino, _exit);
// check if block data is full
if
(
pCompactor
->
bData
.
nRow
>=
pCompactor
->
maxRows
)
{
// TODO: write block data
ASSERT
(
0
);
}
// if (compactor.bData.nRows >= TSDB_MAX_ROWS_PER_BLOCK) {
// code = tsdbFlushBlock(&compactor);
// TSDB_CHECK_CODE(code, lino, _exit);
// }
// iterate to next row
code
=
tsdbCompactNextRow
(
pCompactor
);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
}
tsdbCloseCompactor
(
&
c
ompactor
);
tsdbCloseCompactor
(
pC
ompactor
);
}
_exit:
if
(
code
)
{
tsdbError
(
"vgId:%d %s failed at line %d since %s"
,
TD_VID
(
pTsdb
->
pVnode
),
__func__
,
lino
,
tstrerror
(
code
));
tsdbAbortCompact
(
&
c
ompactor
);
tsdbAbortCompact
(
pC
ompactor
);
}
else
{
tsdbCommitCompact
(
&
c
ompactor
);
tsdbCommitCompact
(
pC
ompactor
);
}
return
code
;
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录