Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
8eb86676
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看板
提交
8eb86676
编写于
8月 18, 2022
作者:
H
Haojun Liao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix(query): support query last file.
上级
082d2093
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
156 addition
and
17 deletion
+156
-17
source/dnode/vnode/src/tsdb/tsdbRead.c
source/dnode/vnode/src/tsdb/tsdbRead.c
+156
-17
未找到文件。
source/dnode/vnode/src/tsdb/tsdbRead.c
浏览文件 @
8eb86676
...
...
@@ -1279,7 +1279,6 @@ static bool fileBlockShouldLoad(STsdbReader* pReader, SFileDataBlockInfo* pFBloc
bool
overlapWithlastBlock
=
false
;
if
(
hasDataInLastBlock
(
pLastBlockReader
))
{
SBlockL
*
pBlockL
=
taosArrayGet
(
pLastBlockReader
->
pBlockL
,
pLastBlockReader
->
currentBlockIndex
);
// int64_t ts = getCurrentKeyInLastBlock(pLastBlockReader);
overlapWithlastBlock
=
!
(
pBlock
->
maxKey
.
ts
<
pBlockL
->
minKey
||
pBlock
->
minKey
.
ts
>
pBlockL
->
maxKey
);
}
...
...
@@ -1358,8 +1357,71 @@ static FORCE_INLINE STSchema* doGetSchemaForTSRow(int32_t sversion, STsdbReader*
return
pReader
->
pMemSchema
;
}
// todo handle desc
static
int32_t
doMergeBufAndFileRows_Rv
(
STsdbReader
*
pReader
,
STableBlockScanInfo
*
pBlockScanInfo
,
TSDBROW
*
pRow
,
SIterInfo
*
pIter
,
int64_t
key
,
SLastBlockReader
*
pLastBlockReader
)
{
SRowMerger
merge
=
{
0
};
STSRow
*
pTSRow
=
NULL
;
SBlockData
*
pBlockData
=
&
pReader
->
status
.
fileBlockData
;
SFileBlockDumpInfo
*
pDumpInfo
=
&
pReader
->
status
.
fBlockDumpInfo
;
int64_t
tsLast
=
getCurrentKeyInLastBlock
(
pLastBlockReader
);
TSDBKEY
k
=
TSDBROW_KEY
(
pRow
);
TSDBROW
fRow
=
tsdbRowFromBlockData
(
pBlockData
,
pDumpInfo
->
rowIndex
);
SBlockData
*
pLastBlockData
=
&
pLastBlockReader
->
lastBlockData
;
int64_t
minKey
=
INT64_MAX
;
if
(
minKey
>
tsLast
)
{
minKey
=
tsLast
;
}
if
(
minKey
>
k
.
ts
)
{
minKey
=
k
.
ts
;
}
if
(
minKey
>
key
&&
pBlockData
->
nRow
>
0
)
{
minKey
=
key
;
}
// file block ---> last block -----> imem -----> mem
bool
init
=
false
;
if
(
minKey
==
key
)
{
init
=
true
;
tRowMergerInit
(
&
merge
,
&
fRow
,
pReader
->
pSchema
);
doMergeRowsInFileBlocks
(
pBlockData
,
pBlockScanInfo
,
pReader
,
&
merge
);
}
if
(
minKey
==
tsLast
)
{
if
(
!
init
)
{
init
=
true
;
TSDBROW
fRow1
=
tsdbRowFromBlockData
(
pLastBlockData
,
pLastBlockReader
->
rowIndex
);
tRowMergerInit
(
&
merge
,
&
fRow1
,
pReader
->
pSchema
);
}
doMergeRowsInLastBlock
(
pLastBlockReader
,
tsLast
,
&
merge
);
}
if
(
minKey
==
k
.
ts
)
{
if
(
!
init
)
{
STSchema
*
pSchema
=
doGetSchemaForTSRow
(
TSDBROW_SVERSION
(
pRow
),
pReader
,
pBlockScanInfo
->
uid
);
tRowMergerInit
(
&
merge
,
pRow
,
pSchema
);
}
doMergeRowsInBuf
(
pIter
,
pBlockScanInfo
->
uid
,
k
.
ts
,
pBlockScanInfo
->
delSkyline
,
&
merge
,
pReader
);
}
tRowMergerGetRow
(
&
merge
,
&
pTSRow
);
doAppendRowFromTSRow
(
pReader
->
pResBlock
,
pReader
,
pTSRow
,
pBlockScanInfo
->
uid
);
taosMemoryFree
(
pTSRow
);
tRowMergerClear
(
&
merge
);
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
doMergeBufAndFileRows
(
STsdbReader
*
pReader
,
STableBlockScanInfo
*
pBlockScanInfo
,
TSDBROW
*
pRow
,
SIterInfo
*
pIter
,
int64_t
key
)
{
SIterInfo
*
pIter
,
int64_t
key
,
SLastBlockReader
*
pLastBlockReader
)
{
SRowMerger
merge
=
{
0
};
STSRow
*
pTSRow
=
NULL
;
SBlockData
*
pBlockData
=
&
pReader
->
status
.
fileBlockData
;
...
...
@@ -1431,6 +1493,85 @@ static int32_t doMergeBufAndFileRows(STsdbReader* pReader, STableBlockScanInfo*
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
doMergeThreeLevelRowsRv
(
STsdbReader
*
pReader
,
STableBlockScanInfo
*
pBlockScanInfo
,
SBlockData
*
pBlockData
,
SLastBlockReader
*
pLastBlockReader
)
{
SRowMerger
merge
=
{
0
};
STSRow
*
pTSRow
=
NULL
;
SFileBlockDumpInfo
*
pDumpInfo
=
&
pReader
->
status
.
fBlockDumpInfo
;
SArray
*
pDelList
=
pBlockScanInfo
->
delSkyline
;
TSDBROW
*
pRow
=
getValidRow
(
&
pBlockScanInfo
->
iter
,
pDelList
,
pReader
);
TSDBROW
*
piRow
=
getValidRow
(
&
pBlockScanInfo
->
iiter
,
pDelList
,
pReader
);
ASSERT
(
pRow
!=
NULL
&&
piRow
!=
NULL
);
SBlockData
*
pLastBlockData
=
&
pLastBlockReader
->
lastBlockData
;
int64_t
tsLast
=
getCurrentKeyInLastBlock
(
pLastBlockReader
);
int64_t
key
=
pBlockData
->
aTSKEY
[
pDumpInfo
->
rowIndex
];
TSDBKEY
k
=
TSDBROW_KEY
(
pRow
);
TSDBKEY
ik
=
TSDBROW_KEY
(
piRow
);
int64_t
minKey
=
INT64_MAX
;
if
(
minKey
>
k
.
ts
)
{
minKey
=
k
.
ts
;
}
if
(
minKey
>
ik
.
ts
)
{
minKey
=
ik
.
ts
;
}
if
(
minKey
>
key
)
{
minKey
=
key
;
}
if
(
minKey
>
tsLast
)
{
minKey
=
tsLast
;
}
// file block ---> last block -----> imem -----> mem
bool
init
=
false
;
if
(
minKey
==
key
)
{
init
=
true
;
TSDBROW
fRow
=
tsdbRowFromBlockData
(
pBlockData
,
pDumpInfo
->
rowIndex
);
tRowMergerInit
(
&
merge
,
&
fRow
,
pReader
->
pSchema
);
doMergeRowsInFileBlocks
(
pBlockData
,
pBlockScanInfo
,
pReader
,
&
merge
);
}
if
(
minKey
==
tsLast
)
{
if
(
!
init
)
{
init
=
true
;
TSDBROW
fRow1
=
tsdbRowFromBlockData
(
pLastBlockData
,
pLastBlockReader
->
rowIndex
);
tRowMergerInit
(
&
merge
,
&
fRow1
,
pReader
->
pSchema
);
}
doMergeRowsInLastBlock
(
pLastBlockReader
,
tsLast
,
&
merge
);
}
if
(
minKey
==
ik
.
ts
)
{
if
(
!
init
)
{
init
=
true
;
STSchema
*
pSchema
=
doGetSchemaForTSRow
(
TSDBROW_SVERSION
(
piRow
),
pReader
,
pBlockScanInfo
->
uid
);
tRowMergerInit
(
&
merge
,
piRow
,
pSchema
);
}
doMergeRowsInBuf
(
&
pBlockScanInfo
->
iiter
,
pBlockScanInfo
->
uid
,
ik
.
ts
,
pBlockScanInfo
->
delSkyline
,
&
merge
,
pReader
);
}
if
(
minKey
==
k
.
ts
)
{
if
(
!
init
)
{
STSchema
*
pSchema
=
doGetSchemaForTSRow
(
TSDBROW_SVERSION
(
pRow
),
pReader
,
pBlockScanInfo
->
uid
);
tRowMergerInit
(
&
merge
,
pRow
,
pSchema
);
}
doMergeRowsInBuf
(
&
pBlockScanInfo
->
iter
,
pBlockScanInfo
->
uid
,
k
.
ts
,
pBlockScanInfo
->
delSkyline
,
&
merge
,
pReader
);
}
tRowMergerGetRow
(
&
merge
,
&
pTSRow
);
doAppendRowFromTSRow
(
pReader
->
pResBlock
,
pReader
,
pTSRow
,
pBlockScanInfo
->
uid
);
taosMemoryFree
(
pTSRow
);
tRowMergerClear
(
&
merge
);
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
doMergeThreeLevelRows
(
STsdbReader
*
pReader
,
STableBlockScanInfo
*
pBlockScanInfo
,
SBlockData
*
pBlockData
)
{
SRowMerger
merge
=
{
0
};
STSRow
*
pTSRow
=
NULL
;
...
...
@@ -1605,8 +1746,8 @@ static bool isValidFileBlockRow(SBlockData* pBlockData, SFileBlockDumpInfo* pDum
static
bool
outOfTimeWindow
(
int64_t
ts
,
STimeWindow
*
pWindow
)
{
return
(
ts
>
pWindow
->
ekey
)
||
(
ts
<
pWindow
->
skey
);
}
static
void
initLastBlockReader
(
SLastBlockReader
*
pLastBlockReader
,
uint64_t
uid
,
STimeWindow
*
pWin
,
SVersionRange
*
pVerRange
,
int16_t
startPos
)
{
static
void
initLastBlockReader
(
SLastBlockReader
*
pLastBlockReader
,
uint64_t
uid
,
STimeWindow
*
pWin
,
SVersionRange
*
pVerRange
,
int16_t
startPos
)
{
pLastBlockReader
->
uid
=
uid
;
pLastBlockReader
->
window
=
*
pWin
;
pLastBlockReader
->
verRange
=
*
pVerRange
;
...
...
@@ -1636,10 +1777,12 @@ static bool nextRowInLastBlock(SLastBlockReader *pLastBlockReader) {
// no data any more
if
(
pBlockData
->
aTSKEY
[
i
]
>
pLastBlockReader
->
window
.
ekey
)
{
pLastBlockReader
->
rowIndex
=
pBlockData
->
nRow
;
return
false
;
}
if
(
pBlockData
->
aVersion
[
i
]
>
pLastBlockReader
->
verRange
.
maxVer
)
{
pLastBlockReader
->
rowIndex
=
pBlockData
->
nRow
;
return
false
;
}
...
...
@@ -1676,25 +1819,21 @@ static bool hasDataInLastBlock(SLastBlockReader* pLastBlockReader) {
static
int32_t
buildComposedDataBlockImpl
(
STsdbReader
*
pReader
,
STableBlockScanInfo
*
pBlockScanInfo
,
SBlockData
*
pBlockData
,
SLastBlockReader
*
pLastBlockReader
)
{
SFileBlockDumpInfo
*
pDumpInfo
=
&
pReader
->
status
.
fBlockDumpInfo
;
int64_t
key
=
INT64_MIN
;
if
(
pBlockData
->
nRow
>
0
)
{
key
=
pBlockData
->
aTSKEY
[
pDumpInfo
->
rowIndex
];
}
int64_t
key
=
(
pBlockData
->
nRow
>
0
)
?
pBlockData
->
aTSKEY
[
pDumpInfo
->
rowIndex
]
:
INT64_MIN
;
TSDBROW
*
pRow
=
getValidRow
(
&
pBlockScanInfo
->
iter
,
pBlockScanInfo
->
delSkyline
,
pReader
);
TSDBROW
*
piRow
=
getValidRow
(
&
pBlockScanInfo
->
iiter
,
pBlockScanInfo
->
delSkyline
,
pReader
);
if
(
pBlockScanInfo
->
iter
.
hasVal
&&
pBlockScanInfo
->
iiter
.
hasVal
)
{
return
doMergeThreeLevelRows
(
pReader
,
pBlockScanInfo
,
pBlockData
);
return
doMergeThreeLevelRows
Rv
(
pReader
,
pBlockScanInfo
,
pBlockData
,
pLastBlockReader
);
}
else
{
// imem + file
// imem + file
+ last block
if
(
pBlockScanInfo
->
iiter
.
hasVal
)
{
return
doMergeBufAndFileRows
(
pReader
,
pBlockScanInfo
,
piRow
,
&
pBlockScanInfo
->
iiter
,
key
);
return
doMergeBufAndFileRows
_Rv
(
pReader
,
pBlockScanInfo
,
piRow
,
&
pBlockScanInfo
->
iiter
,
key
,
pLastBlockReader
);
}
// mem + file
if
(
pBlockScanInfo
->
iter
.
hasVal
)
{
return
doMergeBufAndFileRows
(
pReader
,
pBlockScanInfo
,
pRow
,
&
pBlockScanInfo
->
iter
,
key
);
return
doMergeBufAndFileRows
_Rv
(
pReader
,
pBlockScanInfo
,
pRow
,
&
pBlockScanInfo
->
iter
,
key
,
pLastBlockReader
);
}
if
(
pBlockData
->
nRow
>
0
)
{
...
...
@@ -1704,7 +1843,6 @@ static int32_t buildComposedDataBlockImpl(STsdbReader* pReader, STableBlockScanI
int64_t
ts
=
getCurrentKeyInLastBlock
(
pLastBlockReader
);
if
(
ts
<
key
)
{
// save rows in last block
SBlockData
*
pLastBlockData
=
&
pLastBlockReader
->
lastBlockData
;
int64_t
tsLastBlock
=
getCurrentKeyInLastBlock
(
pLastBlockReader
);
STSRow
*
pTSRow
=
NULL
;
SRowMerger
merge
=
{
0
};
...
...
@@ -1712,7 +1850,7 @@ static int32_t buildComposedDataBlockImpl(STsdbReader* pReader, STableBlockScanI
TSDBROW
fRow1
=
tsdbRowFromBlockData
(
pLastBlockData
,
pLastBlockReader
->
rowIndex
);
tRowMergerInit
(
&
merge
,
&
fRow1
,
pReader
->
pSchema
);
doMergeRowsInLastBlock
(
pLastBlockReader
,
ts
LastBlock
,
&
merge
);
doMergeRowsInLastBlock
(
pLastBlockReader
,
ts
,
&
merge
);
tRowMergerGetRow
(
&
merge
,
&
pTSRow
);
doAppendRowFromTSRow
(
pReader
->
pResBlock
,
pReader
,
pTSRow
,
pBlockScanInfo
->
uid
);
...
...
@@ -1753,6 +1891,7 @@ static int32_t buildComposedDataBlockImpl(STsdbReader* pReader, STableBlockScanI
}
}
}
else
{
// only last block exists
// only last block exits
SBlockData
*
pLastBlockData
=
&
pLastBlockReader
->
lastBlockData
;
int64_t
tsLastBlock
=
getCurrentKeyInLastBlock
(
pLastBlockReader
);
...
...
@@ -1820,10 +1959,10 @@ static int32_t buildComposedDataBlock(STsdbReader* pReader) {
}
buildComposedDataBlockImpl
(
pReader
,
pBlockScanInfo
,
pBlockData
,
pLastBlockReader
);
SBlock
*
pBlock
=
getCurrentBlock
(
&
pReader
->
status
.
blockIter
);
// currently loaded file data block is consumed
if
(
pBlockData
->
nRow
>
0
&&
(
pDumpInfo
->
rowIndex
>=
pBlock
->
nRow
||
pDumpInfo
->
rowIndex
<
0
))
{
if
(
pBlockData
->
nRow
>
0
&&
(
pDumpInfo
->
rowIndex
>=
pBlockData
->
nRow
||
pDumpInfo
->
rowIndex
<
0
))
{
SBlock
*
pBlock
=
getCurrentBlock
(
&
pReader
->
status
.
blockIter
);
setBlockAllDumped
(
pDumpInfo
,
pBlock
,
pReader
->
order
);
break
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录