Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
136f99ed
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
136f99ed
编写于
4月 09, 2020
作者:
H
hzcheng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
TD-100
上级
bed8890f
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
56 addition
and
42 deletion
+56
-42
src/vnode/tsdb/src/tsdbRWHelper.c
src/vnode/tsdb/src/tsdbRWHelper.c
+56
-42
未找到文件。
src/vnode/tsdb/src/tsdbRWHelper.c
浏览文件 @
136f99ed
...
...
@@ -188,18 +188,17 @@ int tsdbWriteDataBlock(SRWHelper *pHelper, SDataCols *pDataCols) {
TSKEY
keyFirst
=
dataColsKeyFirst
(
pDataCols
);
ASSERT
(
helperHasState
(
pHelper
,
TSDB_HELPER_IDX_LOAD
));
SCompIdx
curIdx
=
pHelper
->
compIdx
;
// old table SCompIdx for sendfile usage
// SCompIdx curIdx = pHelper->compIdx;
// old table SCompIdx for sendfile usage
SCompIdx
*
pIdx
=
pHelper
->
pCompIdx
+
pHelper
->
tableInfo
.
tid
;
// for change purpose
// Load the SCompInfo part if neccessary
ASSERT
(
helperHasState
(
pHelper
,
TSDB_HELPER_TABLE_SET
));
if
((
!
helperHasState
(
pHelper
,
TSDB_HELPER_INFO_LOAD
))
&&
((
pIdx
->
offset
>
0
)
&&
(
pIdx
->
hasLast
||
dataColsKeyFirst
(
pDataCols
)
<=
pIdx
->
maxKey
))
&&
(
tsdbLoadCompInfo
(
pHelper
,
NULL
)
<
0
))
goto
_err
;
((
pIdx
->
offset
>
0
)
&&
(
pIdx
->
hasLast
||
keyFirst
<=
pIdx
->
maxKey
)))
{
if
(
tsdbLoadCompInfo
(
pHelper
,
NULL
)
<
0
)
goto
_err
;
}
if
(
!
pIdx
->
hasLast
&&
keyFirst
>
pIdx
->
maxKey
)
{
// Just need to append as a super block
if
(
pIdx
->
offset
==
0
||
(
!
pIdx
->
hasLast
&&
keyFirst
>
pIdx
->
maxKey
))
{
// Just append as a super block
rowsToWrite
=
pDataCols
->
numOfPoints
;
SFile
*
pWFile
=
NULL
;
bool
isLast
=
false
;
...
...
@@ -218,39 +217,48 @@ int tsdbWriteDataBlock(SRWHelper *pHelper, SDataCols *pDataCols) {
pIdx
->
hasLast
=
compBlock
.
last
;
pIdx
->
numOfSuperBlocks
++
;
pIdx
->
maxKey
=
dataColsKeyLast
(
pDataCols
);
// pIdx->len = ??????
}
else
{
// (pIdx->hasLast) OR (keyFirst <= pIdx->maxKey)
if
(
keyFirst
>
pIdx
->
maxKey
)
{
int
blkIdx
=
pIdx
->
numOfSuperBlocks
-
1
;
ASSERT
(
pIdx
->
hasLast
&&
pHelper
->
pCompInfo
->
blocks
[
blkIdx
].
last
);
// Need to merge with the last block
if
(
tsdbMergeDataWithBlock
(
pHelper
,
blkIdx
,
pDataCols
)
<
0
)
goto
_err
;
}
else
{
// Find the first block greater or equal to the block
pIdx
->
maxKey
=
compBlock
.
keyLast
;
ASSERT
(
compBlock
.
keyLast
==
dataColsKeyLast
(
pDataCols
));
pIdx
->
len
+=
sizeof
(
SCompBlock
);
}
else
{
// (Has old data) AND ((has last block) OR (key overlap)), need to merge the block
SCompBlock
*
pCompBlock
=
taosbsearch
((
void
*
)(
&
keyFirst
),
(
void
*
)(
pHelper
->
pCompInfo
->
blocks
),
pIdx
->
numOfSuperBlocks
,
sizeof
(
SCompBlock
),
compareKeyBlock
,
TD_GE
);
if
(
pCompBlock
==
NULL
)
{
if
(
tsdbMergeDataWithBlock
(
pHelper
,
pIdx
->
numOfSuperBlocks
-
1
,
pDataCols
)
<
0
)
goto
_err
;
}
else
{
if
(
compareKeyBlock
((
void
*
)(
&
keyFirst
),
(
void
*
)
pCompBlock
)
==
0
)
{
SCompBlock
*
pNextBlock
=
NULL
;
TSKEY
keyLimit
=
(
pNextBlock
==
NULL
)
?
INT_MAX
:
(
pNextBlock
->
keyFirst
-
1
);
rowsToWrite
=
MIN
(
nRowsLEThan
(
pDataCols
,
keyLimit
),
pHelper
->
config
.
maxRowsPerFileBlock
-
pCompBlock
->
numOfPoints
);
if
(
tsdbMergeDataWithBlock
(
pHelper
,
pCompBlock
-
pHelper
->
pCompInfo
->
blocks
,
pDataCols
)
<
0
)
goto
_err
;
}
else
{
// There options: 1. merge with previous block
// 2. commit as one block
// 3. merge with current block
int
nRows1
=
INT_MAX
;
int
nRows2
=
nRowsLEThan
(
pDataCols
,
pCompBlock
->
keyFirst
);
int
nRows3
=
MIN
(
nRowsLEThan
(
pDataCols
,
(
pCompBlock
+
1
)
->
keyFirst
),
(
pHelper
->
config
.
maxRowsPerFileBlock
-
pCompBlock
->
numOfPoints
));
int
blkIdx
=
(
pCompBlock
==
NULL
)
?
(
pIdx
->
numOfSuperBlocks
-
1
)
:
(
pCompBlock
-
pHelper
->
pCompInfo
->
blocks
);
if
(
pCompBlock
==
NULL
)
{
// No key overlap, must has last block, just merge with the last block
ASSERT
(
pIdx
->
hasLast
&&
pHelper
->
pCompInfo
->
blocks
[
pIdx
->
numOfSuperBlocks
-
1
].
last
);
rowsToWrite
=
tsdbMergeDataWithBlock
(
pHelper
,
blkIdx
,
pDataCols
);
if
(
rowsToWrite
<
0
)
goto
_err
;
}
else
{
// Has key overlap
if
(
compareKeyBlock
((
void
*
)(
&
keyFirst
),
(
void
*
)
pCompBlock
)
==
0
)
{
// Key overlap with the block
// TSKEY keyLimit =
// (blkIdx == pIdx->numOfSuperBlocks - 1) ? INT_MAX : (pHelper->pCompInfo->blocks[blkIdx + 1].keyFirst - 1);
rowsToWrite
=
tsdbMergeDataWithBlock
(
pHelper
,
blkIdx
,
pDataCols
);
if
(
rowsToWrite
<
0
)
goto
_err
;
ASSERT
(
rowsToWrite
==
MIN
(
rows1
,
rows2
));
}
else
{
// Either merge with the previous block or save as a super block in the middle
SCompBlock
*
prevBlock
=
(
blkIdx
==
0
)
?
NULL
:
(
pCompBlock
-
1
);
int
rows1
=
nRowsLEThan
(
pDataCols
,
pCompBlock
->
keyFirst
);
// rows write as a super block in the middle
int
rows2
=
(
prevBlock
)
?
(
pHelper
->
config
.
maxRowsPerFileBlock
-
prevBlock
->
numOfPoints
)
:
rows1
;
// rows can merge with the previous block
if
(
rows1
>=
rows2
)
{
rowsToWrite
=
tsdbWriteBlockToFile
(
pHelper
,
&
(
pHelper
->
files
.
dataF
),
pDataCols
,
rows1
,
&
compBlock
,
false
,
true
);
if
(
rowsToWrite
<
0
)
goto
_err
;
// TODO: find the block with max rows can merge
if
(
tsdbMergeDataWithBlock
(
pHelper
,
pCompBlock
,
pDataCols
)
<
0
)
goto
_err
;
ASSERT
(
rowsToWrite
==
rows1
);
// Add the super block to it
pIdx
->
len
+=
sizeof
(
SCompBlock
);
pIdx
->
numOfSuperBlocks
++
;
}
else
{
rowsToWrite
=
tsdbMergeDataWithBlock
(
pHelper
,
blkIdx
-
1
,
pDataCols
);
if
(
rowsToWrite
<
0
)
goto
_err
;
ASSERT
(
rowsToWrite
==
rows2
);
}
}
}
...
...
@@ -258,7 +266,7 @@ int tsdbWriteDataBlock(SRWHelper *pHelper, SDataCols *pDataCols) {
return
rowsToWrite
;
_err:
_err:
return
-
1
;
}
...
...
@@ -309,7 +317,7 @@ int tsdbLoadCompInfo(SRWHelper *pHelper, void *target) {
if
(
lseek
(
fd
,
curCompIdx
.
offset
,
SEEK_SET
)
<
0
)
return
-
1
;
adjustMem
(
pHelper
->
pCompInfo
,
pHelper
->
compInfoSize
,
curCompIdx
.
len
);
if
(
tread
(
fd
,
(
void
*
)(
pHelper
->
pCompInfo
),
pHelper
)
<
0
)
return
-
1
;
if
(
tread
(
fd
,
(
void
*
)(
pHelper
->
pCompInfo
),
pHelper
->
compIdx
.
len
)
<
pHelper
->
compIdx
.
len
)
return
-
1
;
// TODO: check the checksum
helperSetState
(
pHelper
,
TSDB_HELPER_INFO_LOAD
);
...
...
@@ -521,8 +529,14 @@ static int compareKeyBlock(const void *arg1, const void *arg2) {
return
0
;
}
static
FORCE_INLINE
int
compKeyFunc
(
const
void
*
arg1
,
const
void
*
arg2
)
{
return
((
*
(
TSKEY
*
)
arg1
)
-
(
*
(
TSKEY
*
)
arg2
));
}
static
int
nRowsLEThan
(
SDataCols
*
pDataCols
,
int
maxKey
)
{
return
0
;
void
*
ptr
=
taosbsearch
((
void
*
)
&
maxKey
,
pDataCols
->
cols
[
0
].
pData
,
pDataCols
->
numOfPoints
,
sizeof
(
TSKEY
),
compKeyFunc
,
TD_LE
);
if
(
ptr
==
NULL
)
return
0
;
return
((
TSKEY
*
)
ptr
-
(
TSKEY
*
)(
pDataCols
->
cols
[
0
].
pData
))
+
1
;
}
static
int
tsdbMergeDataWithBlock
(
SRWHelper
*
pHelper
,
int
blkIdx
,
SDataCols
*
pDataCols
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录