Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
codyshao
TDengine
提交
11d1a829
T
TDengine
项目概览
codyshao
/
TDengine
与 Fork 源项目一致
Fork自
taosdata / TDengine
通知
2
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看板
体验新版 GitCode,发现更多精彩内容 >>
提交
11d1a829
编写于
4月 24, 2020
作者:
H
hzcheng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactor code
上级
0c23737d
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
24 addition
and
24 deletion
+24
-24
src/tsdb/inc/tsdbMain.h
src/tsdb/inc/tsdbMain.h
+1
-1
src/tsdb/src/tsdbRWHelper.c
src/tsdb/src/tsdbRWHelper.c
+20
-20
src/tsdb/src/tsdbRead.c
src/tsdb/src/tsdbRead.c
+3
-3
未找到文件。
src/tsdb/inc/tsdbMain.h
浏览文件 @
11d1a829
...
...
@@ -245,7 +245,7 @@ typedef struct {
int32_t
len
;
int32_t
offset
;
int32_t
hasLast
:
1
;
int32_t
numOf
Super
Blocks
:
31
;
int32_t
numOfBlocks
:
31
;
int32_t
checksum
;
TSKEY
maxKey
;
}
SCompIdx
;
/* sizeof(SCompIdx) = 24 */
...
...
src/tsdb/src/tsdbRWHelper.c
浏览文件 @
11d1a829
...
...
@@ -322,12 +322,12 @@ int tsdbWriteDataBlock(SRWHelper *pHelper, SDataCols *pDataCols) {
if
(
tsdbWriteBlockToFile
(
pHelper
,
pWFile
,
pDataCols
,
rowsToWrite
,
&
compBlock
,
isLast
,
true
)
<
0
)
goto
_err
;
if
(
tsdbInsertSuperBlock
(
pHelper
,
&
compBlock
,
pIdx
->
numOf
Super
Blocks
)
<
0
)
goto
_err
;
if
(
tsdbInsertSuperBlock
(
pHelper
,
&
compBlock
,
pIdx
->
numOfBlocks
)
<
0
)
goto
_err
;
}
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
->
numOf
Super
Blocks
,
sizeof
(
SCompBlock
),
compareKeyBlock
,
TD_GE
);
pIdx
->
numOfBlocks
,
sizeof
(
SCompBlock
),
compareKeyBlock
,
TD_GE
);
int
blkIdx
=
(
pCompBlock
==
NULL
)
?
(
pIdx
->
numOf
Super
Blocks
-
1
)
:
(
pCompBlock
-
pHelper
->
pCompInfo
->
blocks
);
int
blkIdx
=
(
pCompBlock
==
NULL
)
?
(
pIdx
->
numOfBlocks
-
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
);
...
...
@@ -362,18 +362,18 @@ int tsdbMoveLastBlockIfNeccessary(SRWHelper *pHelper) {
if
((
pHelper
->
files
.
nLastF
.
fd
>
0
)
&&
(
pHelper
->
hasOldLastBlock
))
{
if
(
tsdbLoadCompInfo
(
pHelper
,
NULL
)
<
0
)
return
-
1
;
SCompBlock
*
pCompBlock
=
pHelper
->
pCompInfo
->
blocks
+
pIdx
->
numOf
Super
Blocks
-
1
;
SCompBlock
*
pCompBlock
=
pHelper
->
pCompInfo
->
blocks
+
pIdx
->
numOfBlocks
-
1
;
ASSERT
(
pCompBlock
->
last
);
if
(
pCompBlock
->
numOfSubBlocks
>
1
)
{
if
(
tsdbLoadBlockData
(
pHelper
,
blockAtIdx
(
pHelper
,
pIdx
->
numOf
Super
Blocks
-
1
),
NULL
)
<
0
)
return
-
1
;
if
(
tsdbLoadBlockData
(
pHelper
,
blockAtIdx
(
pHelper
,
pIdx
->
numOfBlocks
-
1
),
NULL
)
<
0
)
return
-
1
;
ASSERT
(
pHelper
->
pDataCols
[
0
]
->
numOfPoints
>
0
&&
pHelper
->
pDataCols
[
0
]
->
numOfPoints
<
pHelper
->
config
.
minRowsPerFileBlock
);
if
(
tsdbWriteBlockToFile
(
pHelper
,
&
(
pHelper
->
files
.
nLastF
),
pHelper
->
pDataCols
[
0
],
pHelper
->
pDataCols
[
0
]
->
numOfPoints
,
&
compBlock
,
true
,
true
)
<
0
)
return
-
1
;
if
(
tsdbUpdateSuperBlock
(
pHelper
,
&
compBlock
,
pIdx
->
numOf
Super
Blocks
-
1
)
<
0
)
return
-
1
;
if
(
tsdbUpdateSuperBlock
(
pHelper
,
&
compBlock
,
pIdx
->
numOfBlocks
-
1
)
<
0
)
return
-
1
;
}
else
{
if
(
lseek
(
pHelper
->
files
.
lastF
.
fd
,
pCompBlock
->
offset
,
SEEK_SET
)
<
0
)
return
-
1
;
...
...
@@ -827,7 +827,7 @@ static int tsdbMergeDataWithBlock(SRWHelper *pHelper, int blkIdx, SDataCols *pDa
ASSERT
(
keyFirst
<=
blockAtIdx
(
pHelper
,
blkIdx
)
->
keyLast
);
TSKEY
keyLimit
=
(
blkIdx
==
pIdx
->
numOf
Super
Blocks
-
1
)
?
INT64_MAX
:
pHelper
->
pCompInfo
->
blocks
[
blkIdx
+
1
].
keyFirst
-
1
;
(
blkIdx
==
pIdx
->
numOfBlocks
-
1
)
?
INT64_MAX
:
pHelper
->
pCompInfo
->
blocks
[
blkIdx
+
1
].
keyFirst
-
1
;
// rows1: number of rows must merge in this block
int
rows1
=
tsdbGetRowsInRange
(
pDataCols
,
blockAtIdx
(
pHelper
,
blkIdx
)
->
keyFirst
,
blockAtIdx
(
pHelper
,
blkIdx
)
->
keyLast
);
...
...
@@ -969,7 +969,7 @@ static int tsdbInsertSuperBlock(SRWHelper *pHelper, SCompBlock *pCompBlock, int
if
(
tsdbAdjustInfoSizeIfNeeded
(
pHelper
,
pIdx
->
len
+
sizeof
(
SCompInfo
))
<
0
)
goto
_err
;
// Change the offset
for
(
int
i
=
0
;
i
<
pIdx
->
numOf
Super
Blocks
;
i
++
)
{
for
(
int
i
=
0
;
i
<
pIdx
->
numOfBlocks
;
i
++
)
{
SCompBlock
*
pTCompBlock
=
&
pHelper
->
pCompInfo
->
blocks
[
i
];
if
(
pTCompBlock
->
numOfSubBlocks
>
1
)
pTCompBlock
->
offset
+=
sizeof
(
SCompBlock
);
}
...
...
@@ -984,13 +984,13 @@ static int tsdbInsertSuperBlock(SRWHelper *pHelper, SCompBlock *pCompBlock, int
}
pHelper
->
pCompInfo
->
blocks
[
blkIdx
]
=
*
pCompBlock
;
pIdx
->
numOf
Super
Blocks
++
;
pIdx
->
numOfBlocks
++
;
pIdx
->
len
+=
sizeof
(
SCompBlock
);
ASSERT
(
pIdx
->
len
<=
tsizeof
(
pHelper
->
pCompInfo
));
pIdx
->
maxKey
=
pHelper
->
pCompInfo
->
blocks
[
pIdx
->
numOf
Super
Blocks
-
1
].
keyLast
;
pIdx
->
hasLast
=
pHelper
->
pCompInfo
->
blocks
[
pIdx
->
numOf
Super
Blocks
-
1
].
last
;
pIdx
->
maxKey
=
pHelper
->
pCompInfo
->
blocks
[
pIdx
->
numOfBlocks
-
1
].
keyLast
;
pIdx
->
hasLast
=
pHelper
->
pCompInfo
->
blocks
[
pIdx
->
numOfBlocks
-
1
].
last
;
if
(
pIdx
->
numOf
Super
Blocks
>
1
)
{
if
(
pIdx
->
numOfBlocks
>
1
)
{
ASSERT
(
pHelper
->
pCompInfo
->
blocks
[
0
].
keyLast
<
pHelper
->
pCompInfo
->
blocks
[
1
].
keyFirst
);
}
...
...
@@ -1022,7 +1022,7 @@ static int tsdbAddSubBlock(SRWHelper *pHelper, SCompBlock *pCompBlock, int blkId
memmove
((
void
*
)((
char
*
)(
pHelper
->
pCompInfo
)
+
pSCompBlock
->
offset
+
pSCompBlock
->
len
+
sizeof
(
SCompBlock
)),
(
void
*
)((
char
*
)(
pHelper
->
pCompInfo
)
+
pSCompBlock
->
offset
+
pSCompBlock
->
len
),
tsize
);
for
(
int
i
=
blkIdx
+
1
;
i
<
pIdx
->
numOf
Super
Blocks
;
i
++
)
{
for
(
int
i
=
blkIdx
+
1
;
i
<
pIdx
->
numOfBlocks
;
i
++
)
{
SCompBlock
*
pTCompBlock
=
&
pHelper
->
pCompInfo
->
blocks
[
i
];
if
(
pTCompBlock
->
numOfSubBlocks
>
1
)
pTCompBlock
->
offset
+=
sizeof
(
SCompBlock
);
}
...
...
@@ -1040,7 +1040,7 @@ static int tsdbAddSubBlock(SRWHelper *pHelper, SCompBlock *pCompBlock, int blkId
pIdx
->
len
+=
sizeof
(
SCompBlock
);
}
else
{
// Need to create two sub-blocks
void
*
ptr
=
NULL
;
for
(
int
i
=
blkIdx
+
1
;
i
<
pIdx
->
numOf
Super
Blocks
;
i
++
)
{
for
(
int
i
=
blkIdx
+
1
;
i
<
pIdx
->
numOfBlocks
;
i
++
)
{
SCompBlock
*
pTCompBlock
=
pHelper
->
pCompInfo
->
blocks
+
i
;
if
(
pTCompBlock
->
numOfSubBlocks
>
1
)
{
ptr
=
(
void
*
)((
char
*
)(
pHelper
->
pCompInfo
)
+
pTCompBlock
->
offset
+
pTCompBlock
->
len
);
...
...
@@ -1053,7 +1053,7 @@ static int tsdbAddSubBlock(SRWHelper *pHelper, SCompBlock *pCompBlock, int blkId
size_t
tsize
=
pIdx
->
len
-
((
char
*
)
ptr
-
(
char
*
)(
pHelper
->
pCompInfo
));
if
(
tsize
>
0
)
{
memmove
((
void
*
)((
char
*
)
ptr
+
sizeof
(
SCompBlock
)
*
2
),
ptr
,
tsize
);
for
(
int
i
=
blkIdx
+
1
;
i
<
pIdx
->
numOf
Super
Blocks
;
i
++
)
{
for
(
int
i
=
blkIdx
+
1
;
i
<
pIdx
->
numOfBlocks
;
i
++
)
{
SCompBlock
*
pTCompBlock
=
pHelper
->
pCompInfo
->
blocks
+
i
;
if
(
pTCompBlock
->
numOfSubBlocks
>
1
)
pTCompBlock
->
offset
+=
(
sizeof
(
SCompBlock
)
*
2
);
}
...
...
@@ -1074,8 +1074,8 @@ static int tsdbAddSubBlock(SRWHelper *pHelper, SCompBlock *pCompBlock, int blkId
pIdx
->
len
+=
(
sizeof
(
SCompBlock
)
*
2
);
}
pIdx
->
maxKey
=
pHelper
->
pCompInfo
->
blocks
[
pIdx
->
numOf
Super
Blocks
-
1
].
keyLast
;
pIdx
->
hasLast
=
pHelper
->
pCompInfo
->
blocks
[
pIdx
->
numOf
Super
Blocks
-
1
].
last
;
pIdx
->
maxKey
=
pHelper
->
pCompInfo
->
blocks
[
pIdx
->
numOfBlocks
-
1
].
keyLast
;
pIdx
->
hasLast
=
pHelper
->
pCompInfo
->
blocks
[
pIdx
->
numOfBlocks
-
1
].
last
;
return
0
;
...
...
@@ -1102,7 +1102,7 @@ static int tsdbUpdateSuperBlock(SRWHelper *pHelper, SCompBlock *pCompBlock, int
(
void
*
)((
char
*
)(
pHelper
->
pCompInfo
)
+
pSCompBlock
->
offset
+
pSCompBlock
->
len
),
tsize
);
}
for
(
int
i
=
blkIdx
+
1
;
i
<
pIdx
->
numOf
Super
Blocks
;
i
++
)
{
for
(
int
i
=
blkIdx
+
1
;
i
<
pIdx
->
numOfBlocks
;
i
++
)
{
SCompBlock
*
pTCompBlock
=
&
pHelper
->
pCompInfo
->
blocks
[
i
];
if
(
pTCompBlock
->
numOfSubBlocks
>
1
)
pTCompBlock
->
offset
-=
(
sizeof
(
SCompBlock
)
*
pSCompBlock
->
numOfSubBlocks
);
}
...
...
@@ -1112,8 +1112,8 @@ static int tsdbUpdateSuperBlock(SRWHelper *pHelper, SCompBlock *pCompBlock, int
*
pSCompBlock
=
*
pCompBlock
;
pIdx
->
maxKey
=
pHelper
->
pCompInfo
->
blocks
[
pIdx
->
numOf
Super
Blocks
-
1
].
keyLast
;
pIdx
->
hasLast
=
pHelper
->
pCompInfo
->
blocks
[
pIdx
->
numOf
Super
Blocks
-
1
].
last
;
pIdx
->
maxKey
=
pHelper
->
pCompInfo
->
blocks
[
pIdx
->
numOfBlocks
-
1
].
keyLast
;
pIdx
->
hasLast
=
pHelper
->
pCompInfo
->
blocks
[
pIdx
->
numOfBlocks
-
1
].
last
;
return
0
;
}
...
...
src/tsdb/src/tsdbRead.c
浏览文件 @
11d1a829
...
...
@@ -301,7 +301,7 @@ static int32_t getFileCompInfo(STsdbQueryHandle* pQueryHandle, int32_t* numOfBlo
STableCheckInfo
*
pCheckInfo
=
taosArrayGet
(
pQueryHandle
->
pTableCheckInfo
,
i
);
SCompIdx
*
compIndex
=
&
pQueryHandle
->
rhelper
.
pCompIdx
[
pCheckInfo
->
tableId
.
tid
];
if
(
compIndex
->
len
==
0
||
compIndex
->
numOf
Super
Blocks
==
0
)
{
// no data block in this file, try next file
if
(
compIndex
->
len
==
0
||
compIndex
->
numOfBlocks
==
0
)
{
// no data block in this file, try next file
continue
;
//no data blocks in the file belongs to pCheckInfo->pTable
}
else
{
if
(
pCheckInfo
->
compSize
<
compIndex
->
len
)
{
...
...
@@ -327,7 +327,7 @@ static int32_t getFileCompInfo(STsdbQueryHandle* pQueryHandle, int32_t* numOfBlo
TSKEY
e
=
MAX
(
pCheckInfo
->
lastKey
,
pQueryHandle
->
window
.
ekey
);
// discard the unqualified data block based on the query time window
int32_t
start
=
binarySearchForBlockImpl
(
pCompInfo
->
blocks
,
compIndex
->
numOf
Super
Blocks
,
s
,
TSDB_ORDER_ASC
);
int32_t
start
=
binarySearchForBlockImpl
(
pCompInfo
->
blocks
,
compIndex
->
numOfBlocks
,
s
,
TSDB_ORDER_ASC
);
int32_t
end
=
start
;
if
(
s
>
pCompInfo
->
blocks
[
start
].
keyLast
)
{
...
...
@@ -335,7 +335,7 @@ static int32_t getFileCompInfo(STsdbQueryHandle* pQueryHandle, int32_t* numOfBlo
}
// todo speedup the procedure of located end block
while
(
end
<
compIndex
->
numOf
Super
Blocks
&&
(
pCompInfo
->
blocks
[
end
].
keyFirst
<=
e
))
{
while
(
end
<
compIndex
->
numOfBlocks
&&
(
pCompInfo
->
blocks
[
end
].
keyFirst
<=
e
))
{
end
+=
1
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录