Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
976dc322
T
TDengine
项目概览
taosdata
/
TDengine
大约 2 年 前同步成功
通知
1192
Star
22018
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看板
提交
976dc322
编写于
6月 20, 2023
作者:
H
Haojun Liao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
enh(tsdb): support delete data read.
上级
a33ce92e
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
258 addition
and
190 deletion
+258
-190
source/dnode/vnode/src/tsdb/tsdbMergeTree.c
source/dnode/vnode/src/tsdb/tsdbMergeTree.c
+7
-2
source/dnode/vnode/src/tsdb/tsdbRead2.c
source/dnode/vnode/src/tsdb/tsdbRead2.c
+251
-188
未找到文件。
source/dnode/vnode/src/tsdb/tsdbMergeTree.c
浏览文件 @
976dc322
...
@@ -639,6 +639,11 @@ int32_t tMergeTreeOpen2(SMergeTree *pMTree, int8_t backward, STsdb* pTsdb, uint6
...
@@ -639,6 +639,11 @@ int32_t tMergeTreeOpen2(SMergeTree *pMTree, int8_t backward, STsdb* pTsdb, uint6
pMTree
->
ignoreEarlierTs
=
false
;
pMTree
->
ignoreEarlierTs
=
false
;
// todo handle other level of stt files, here only deal with the first level stt
// todo handle other level of stt files, here only deal with the first level stt
int32_t
size
=
((
STFileSet
*
)
pCurrentFileSet
)
->
lvlArr
[
0
].
size
;
if
(
size
==
0
)
{
goto
_end
;
}
SSttLvl
*
pSttLevel
=
((
STFileSet
*
)
pCurrentFileSet
)
->
lvlArr
[
0
].
data
[
0
];
SSttLvl
*
pSttLevel
=
((
STFileSet
*
)
pCurrentFileSet
)
->
lvlArr
[
0
].
data
[
0
];
ASSERT
(
pSttLevel
->
level
==
0
);
ASSERT
(
pSttLevel
->
level
==
0
);
...
...
source/dnode/vnode/src/tsdb/tsdbRead2.c
浏览文件 @
976dc322
...
@@ -18,6 +18,7 @@
...
@@ -18,6 +18,7 @@
#include "tsdbDataFileRW.h"
#include "tsdbDataFileRW.h"
#include "tsdbFS2.h"
#include "tsdbFS2.h"
#include "tsdbMerge.h"
#include "tsdbMerge.h"
#include "tsdbUtil2.h"
#include "tsimplehash.h"
#include "tsimplehash.h"
#define ASCENDING_TRAVERSE(o) (o == TSDB_ORDER_ASC)
#define ASCENDING_TRAVERSE(o) (o == TSDB_ORDER_ASC)
...
@@ -61,7 +62,8 @@ typedef struct STableBlockScanInfo {
...
@@ -61,7 +62,8 @@ typedef struct STableBlockScanInfo {
TSKEY lastKey;
TSKEY lastKey;
TSKEY lastKeyInStt; // last accessed key in stt
TSKEY lastKeyInStt; // last accessed key in stt
SMapData mapData; // block info (compressed)
SMapData mapData; // block info (compressed)
SArray
*
pBlockList
;
// block data index list, SArray<SBlockIndex>
SArray* pBlockList; // block data index list, SArray<SBrinRecord>
SArray* pDelData; // SArray<SDelData>
SIterInfo iter; // mem buffer skip list iterator
SIterInfo iter; // mem buffer skip list iterator
SIterInfo iiter; // imem buffer skip list iterator
SIterInfo iiter; // imem buffer skip list iterator
SArray* delSkyline; // delete info for this table
SArray* delSkyline; // delete info for this table
...
@@ -73,6 +75,7 @@ typedef struct STableBlockScanInfo {
...
@@ -73,6 +75,7 @@ typedef struct STableBlockScanInfo {
typedef struct SBlockOrderWrapper {
typedef struct SBlockOrderWrapper {
int64_t uid;
int64_t uid;
int64_t offset;
int64_t offset;
STableBlockScanInfo *pInfo;
} SBlockOrderWrapper;
} SBlockOrderWrapper;
typedef struct SBlockOrderSupporter {
typedef struct SBlockOrderSupporter {
...
@@ -123,8 +126,7 @@ typedef struct SLastBlockReader {
...
@@ -123,8 +126,7 @@ typedef struct SLastBlockReader {
typedef struct SFilesetIter {
typedef struct SFilesetIter {
int32_t numOfFiles; // number of total files
int32_t numOfFiles; // number of total files
int32_t index; // current accessed index in the list
int32_t index; // current accessed index in the list
TFileSetArray
*
pFilesetArray
;
// data file set list
TFileSetArray* pFilesetList;// data file set list
// SArray* pFileList; // data file list
int32_t order;
int32_t order;
SLastBlockReader* pLastBlockReader; // last file block reader
SLastBlockReader* pLastBlockReader; // last file block reader
} SFilesetIter;
} SFilesetIter;
...
@@ -133,6 +135,7 @@ typedef struct SFileDataBlockInfo {
...
@@ -133,6 +135,7 @@ typedef struct SFileDataBlockInfo {
// index position in STableBlockScanInfo in order to check whether neighbor block overlaps with it
// index position in STableBlockScanInfo in order to check whether neighbor block overlaps with it
uint64_t uid;
uint64_t uid;
int32_t tbBlockIdx;
int32_t tbBlockIdx;
SBrinRecord record;
} SFileDataBlockInfo;
} SFileDataBlockInfo;
typedef struct SDataBlockIter {
typedef struct SDataBlockIter {
...
@@ -218,7 +221,7 @@ struct STsdbReader {
...
@@ -218,7 +221,7 @@ struct STsdbReader {
STSchema* pSchema; // the newest version schema
STSchema* pSchema; // the newest version schema
SSHashObj* pSchemaMap; // keep the retrieved schema info, to avoid the overhead by repeatly load schema
SSHashObj* pSchemaMap; // keep the retrieved schema info, to avoid the overhead by repeatly load schema
SDataFileReader* pFileReader; // the file reader
SDataFileReader* pFileReader; // the file reader
SDelFReader
*
pDelFReader
;
// the del file reader
SDelFReader*
pDelFReader; // the del file reader, todo remove it
SArray* pDelIdx; // del file block index;
SArray* pDelIdx; // del file block index;
SBlockInfoBuf blockInfoBuf;
SBlockInfoBuf blockInfoBuf;
EContentData step;
EContentData step;
...
@@ -536,11 +539,11 @@ static STimeWindow updateQueryTimeWindow(STsdb* pTsdb, STimeWindow* pWindow) {
...
@@ -536,11 +539,11 @@ static STimeWindow updateQueryTimeWindow(STsdb* pTsdb, STimeWindow* pWindow) {
// init file iterator
// init file iterator
static int32_t initFilesetIterator(SFilesetIter* pIter, TFileSetArray* pFileSetArray, STsdbReader* pReader) {
static int32_t initFilesetIterator(SFilesetIter* pIter, TFileSetArray* pFileSetArray, STsdbReader* pReader) {
size_t
numOfFileset
=
pFileSetArray
->
size
;
size_t numOfFileset =
TARRAY2_SIZE(pFileSetArray)
;
pIter->index = ASCENDING_TRAVERSE(pReader->order) ? -1 : numOfFileset;
pIter->index = ASCENDING_TRAVERSE(pReader->order) ? -1 : numOfFileset;
pIter->order = pReader->order;
pIter->order = pReader->order;
pIter
->
pFileset
Array
=
pFileSetArray
;
pIter->pFileset
List
= pFileSetArray;
pIter->numOfFiles = numOfFileset;
pIter->numOfFiles = numOfFileset;
if (pIter->pLastBlockReader == NULL) {
if (pIter->pLastBlockReader == NULL) {
...
@@ -602,8 +605,7 @@ static int32_t filesetIteratorNext(SFilesetIter* pIter, STsdbReader* pReader, bo
...
@@ -602,8 +605,7 @@ static int32_t filesetIteratorNext(SFilesetIter* pIter, STsdbReader* pReader, bo
tsdbDataFileReaderClose(&pReader->pFileReader);
tsdbDataFileReaderClose(&pReader->pFileReader);
}
}
// pReader->status.pCurrentFileset = (SDFileSet*)taosArrayGet(pIter->pFilesetArray, pIter->index);
pReader->status.pCurrentFileset = pIter->pFilesetList->data[pIter->index];
pReader
->
status
.
pCurrentFileset
=
pIter
->
pFilesetArray
->
data
[
pIter
->
index
];
STFileObj** pFileObj = pReader->status.pCurrentFileset->farr;
STFileObj** pFileObj = pReader->status.pCurrentFileset->farr;
if (pFileObj[0] != NULL) {
if (pFileObj[0] != NULL) {
...
@@ -894,11 +896,17 @@ static int32_t doLoadBlockIndex(STsdbReader* pReader, SDataFileReader* pFileRead
...
@@ -894,11 +896,17 @@ static int32_t doLoadBlockIndex(STsdbReader* pReader, SDataFileReader* pFileRead
int32_t i = 0, j = 0;
int32_t i = 0, j = 0;
while (i < pBlkArray->size && j < numOfTables) {
while (i < pBlkArray->size && j < numOfTables) {
pBrinBlk = &pBlkArray->data[i];
pBrinBlk = &pBlkArray->data[i];
if
(
pBrinBlk
->
minTbid
.
suid
!=
pReader
->
suid
)
{
if (pBrinBlk->minTbid.suid > pReader->suid) { // not include the queried table/super table, quit the loop
break;
}
if (pBrinBlk->maxTbid.suid < pReader->suid) {
i += 1;
i += 1;
continue;
continue;
}
}
ASSERT(pBrinBlk->minTbid.suid >= pReader->suid && pBrinBlk->maxTbid.suid <= pReader->suid);
if (pBrinBlk->minTbid.uid < pList->tableUidList[j]) {
if (pBrinBlk->minTbid.uid < pList->tableUidList[j]) {
i += 1;
i += 1;
continue;
continue;
...
@@ -909,6 +917,7 @@ static int32_t doLoadBlockIndex(STsdbReader* pReader, SDataFileReader* pFileRead
...
@@ -909,6 +917,7 @@ static int32_t doLoadBlockIndex(STsdbReader* pReader, SDataFileReader* pFileRead
continue;
continue;
}
}
// todo maxTbid.uid == xxx?
if (pBrinBlk->minTbid.uid == pList->tableUidList[j]) {
if (pBrinBlk->minTbid.uid == pList->tableUidList[j]) {
// this block belongs to a table that is not queried.
// this block belongs to a table that is not queried.
STableBlockScanInfo* pScanInfo = getTableBlockScanInfo(pReader->status.pTableMap, pBrinBlk->minTbid.uid, pReader->idStr);
STableBlockScanInfo* pScanInfo = getTableBlockScanInfo(pReader->status.pTableMap, pBrinBlk->minTbid.uid, pReader->idStr);
...
@@ -929,7 +938,7 @@ static int32_t doLoadBlockIndex(STsdbReader* pReader, SDataFileReader* pFileRead
...
@@ -929,7 +938,7 @@ static int32_t doLoadBlockIndex(STsdbReader* pReader, SDataFileReader* pFileRead
}
}
int64_t et2 = taosGetTimestampUs();
int64_t et2 = taosGetTimestampUs();
tsdbDebug
(
"load block index for %d/%d tables completed, elapsed time:%.2f ms, set
blockIdx
:%.2f ms, size:%.2f Kb %s"
,
tsdbDebug("load block index for %d/%d tables completed, elapsed time:%.2f ms, set
BrinBlk
:%.2f ms, size:%.2f Kb %s",
numOfTables, (int32_t)pBlkArray->size, (et1 - st) / 1000.0, (et2 - et1) / 1000.0, pBlkArray->size * sizeof(SBrinBlk) / 1024.0,
numOfTables, (int32_t)pBlkArray->size, (et1 - st) / 1000.0, (et2 - et1) / 1000.0, pBlkArray->size * sizeof(SBrinBlk) / 1024.0,
pReader->idStr);
pReader->idStr);
...
@@ -969,20 +978,18 @@ static void cleanupTableScanInfo(SReaderStatus* pStatus) {
...
@@ -969,20 +978,18 @@ static void cleanupTableScanInfo(SReaderStatus* pStatus) {
static int32_t doLoadFileBlock(STsdbReader* pReader, SArray* pIndexList, SBlockNumber* pBlockNum, SArray* pTableScanInfoList) {
static int32_t doLoadFileBlock(STsdbReader* pReader, SArray* pIndexList, SBlockNumber* pBlockNum, SArray* pTableScanInfoList) {
size_t sizeInDisk = 0;
size_t sizeInDisk = 0;
size_t
numOf
Table
s
=
taosArrayGetSize
(
pIndexList
);
size_t numOf
Block
s = taosArrayGetSize(pIndexList);
int64_t st = taosGetTimestampUs();
int64_t st = taosGetTimestampUs();
cleanupTableScanInfo(&pReader->status);
cleanupTableScanInfo(&pReader->status);
// set the flag for the new file
// set the flag for the new file
// pReader->status.mapDataCleaned = false;
int32_t i = 0, k = 0;
for
(
int32_t
i
=
0
;
i
<
numOfTables
;
++
i
)
{
int32_t numOfTables = tSimpleHashGetSize(pReader->status.pTableMap);
SBrinBlk
*
pBlk
=
taosArrayGet
(
pIndexList
,
i
);
STableBlockScanInfo
*
pScanInfo
=
getTableBlockScanInfo
(
pReader
->
status
.
pTableMap
,
pBlk
->
minTbid
.
uid
,
pReader
->
idStr
);
while(i < numOfBlocks && k < numOfTables) {
if
(
pScanInfo
==
NULL
)
{
SBrinBlk* pBlk = taosArrayGet(pIndexList, i);
return
terrno
;
uint64_t uid = pReader->status.uidList.tableUidList[k];
}
SBrinBlock block = {0};
SBrinBlock block = {0};
tsdbDataFileReadBrinBlock(pReader->pFileReader, pBlk, &block);
tsdbDataFileReadBrinBlock(pReader->pFileReader, pBlk, &block);
...
@@ -991,27 +998,48 @@ static int32_t doLoadFileBlock(STsdbReader* pReader, SArray* pIndexList, SBlockN
...
@@ -991,27 +998,48 @@ static int32_t doLoadFileBlock(STsdbReader* pReader, SArray* pIndexList, SBlockN
// tsdbReadDataBlk(pReader->pFileReader, pBlockIdx, &pScanInfo->mapData);
// tsdbReadDataBlk(pReader->pFileReader, pBlockIdx, &pScanInfo->mapData);
// taosArrayEnsureCap(pScanInfo->pBlockList, pScanInfo->mapData.nItem);
// taosArrayEnsureCap(pScanInfo->pBlockList, pScanInfo->mapData.nItem);
// todo set the correct size
sizeInDisk += 0;//pScanInfo->mapData.nData;
sizeInDisk += 0;//pScanInfo->mapData.nData;
int32_t step = ASCENDING_TRAVERSE(pReader->order) ? 1 : -1;
int32_t step = ASCENDING_TRAVERSE(pReader->order) ? 1 : -1;
STimeWindow w = pReader->window;
STimeWindow w = pReader->window;
if (isEmptyQueryTimeWindow(&w)) {
continue;
}
STableBlockScanInfo* pScanInfo = getTableBlockScanInfo(pReader->status.pTableMap, uid, pReader->idStr);
if (ASCENDING_TRAVERSE(pReader->order)) {
if (ASCENDING_TRAVERSE(pReader->order)) {
w.skey = pScanInfo->lastKey + step;
w.skey = pScanInfo->lastKey + step;
} else {
} else {
w.ekey = pScanInfo->lastKey + step;
w.ekey = pScanInfo->lastKey + step;
}
}
if
(
isEmptyQueryTimeWindow
(
&
w
))
{
SBrinRecord record = {0};
for (int32_t j = 0; j < TARRAY2_SIZE(block.numRow); ++j) {
tBrinBlockGet(&block, j, &record);
{
while (record.uid > uid) {
k += 1;
uid = pReader->status.uidList.tableUidList[k];
pScanInfo = getTableBlockScanInfo(pReader->status.pTableMap, uid, pReader->idStr);
if (ASCENDING_TRAVERSE(pReader->order)) {
w.skey = pScanInfo->lastKey + step;
} else {
w.ekey = pScanInfo->lastKey + step;
}
}
if (record.uid < uid) {
continue;
continue;
}
}
}
for
(
int32_t
j
=
0
;
j
<
block
.
numRow
->
size
;
++
j
)
{
ASSERT(record.suid == pReader->suid);
SBrinRecord
record
=
{
0
};
tBrinBlockGet
(
&
block
,
j
,
&
record
);
// 1. time range check
// 1. time range check
if (record.firstKey > w.ekey || record.lastKey < w.skey) {
if (record.firstKey > w.ekey || record.lastKey < w.skey) {
// if (block.minKey.ts > w.ekey || block.maxKey.ts < w.skey) {
continue;
continue;
}
}
...
@@ -1022,7 +1050,6 @@ static int32_t doLoadFileBlock(STsdbReader* pReader, SArray* pIndexList, SBlockN
...
@@ -1022,7 +1050,6 @@ static int32_t doLoadFileBlock(STsdbReader* pReader, SArray* pIndexList, SBlockN
// SBlockIndex bIndex = {.ordinalIndex = j, .inFileOffset = record.blockOffset};
// SBlockIndex bIndex = {.ordinalIndex = j, .inFileOffset = record.blockOffset};
// bIndex.window = (STimeWindow){.skey = record.firstKey, .ekey = record.lastKey};
// bIndex.window = (STimeWindow){.skey = record.firstKey, .ekey = record.lastKey};
void* p1 = taosArrayPush(pScanInfo->pBlockList, &record);
void* p1 = taosArrayPush(pScanInfo->pBlockList, &record);
if (p1 == NULL) {
if (p1 == NULL) {
return TSDB_CODE_OUT_OF_MEMORY;
return TSDB_CODE_OUT_OF_MEMORY;
...
@@ -1031,7 +1058,10 @@ static int32_t doLoadFileBlock(STsdbReader* pReader, SArray* pIndexList, SBlockN
...
@@ -1031,7 +1058,10 @@ static int32_t doLoadFileBlock(STsdbReader* pReader, SArray* pIndexList, SBlockN
pBlockNum->numOfBlocks += 1;
pBlockNum->numOfBlocks += 1;
}
}
if
(
taosArrayGetSize
(
pScanInfo
->
pBlockList
)
>
0
)
{
i += 1;
STableBlockScanInfo** p = taosArrayGetLast(pTableScanInfoList);
if ((p == NULL || (*p)->uid != uid) && taosArrayGetSize(pScanInfo->pBlockList) > 0) {
taosArrayPush(pTableScanInfoList, &pScanInfo);
taosArrayPush(pTableScanInfoList, &pScanInfo);
}
}
}
}
...
@@ -1144,22 +1174,22 @@ static int doBinarySearchKey(TSKEY* keyList, int num, int pos, TSKEY key, int or
...
@@ -1144,22 +1174,22 @@ static int doBinarySearchKey(TSKEY* keyList, int num, int pos, TSKEY key, int or
}
}
}
}
static
int32_t
getEndPosInDataBlock
(
STsdbReader
*
pReader
,
SBlockData
*
pBlockData
,
S
DataBlk
*
pBlock
,
int32_t
pos
)
{
static int32_t getEndPosInDataBlock(STsdbReader* pReader, SBlockData* pBlockData, S
BrinRecord* pRecord
, int32_t pos) {
// NOTE: reverse the order to find the end position in data block
// NOTE: reverse the order to find the end position in data block
int32_t endPos = -1;
int32_t endPos = -1;
bool asc = ASCENDING_TRAVERSE(pReader->order);
bool asc = ASCENDING_TRAVERSE(pReader->order);
if
(
asc
&&
pReader
->
window
.
ekey
>=
p
Block
->
maxKey
.
ts
)
{
if (asc && pReader->window.ekey >= p
Record->lastKey
) {
endPos
=
p
Block
->
n
Row
-
1
;
endPos = p
Record->num
Row - 1;
}
else
if
(
!
asc
&&
pReader
->
window
.
skey
<=
p
Block
->
minKey
.
ts
)
{
} else if (!asc && pReader->window.skey <= p
Record->firstKey
) {
endPos = 0;
endPos = 0;
} else {
} else {
int64_t key = asc ? pReader->window.ekey : pReader->window.skey;
int64_t key = asc ? pReader->window.ekey : pReader->window.skey;
endPos
=
doBinarySearchKey
(
pBlockData
->
aTSKEY
,
p
Block
->
n
Row
,
pos
,
key
,
pReader
->
order
);
endPos = doBinarySearchKey(pBlockData->aTSKEY, p
Record->num
Row, pos, key, pReader->order);
}
}
if
((
pReader
->
verRange
.
maxVer
>=
p
Block
->
minVer
&&
pReader
->
verRange
.
maxVer
<
pBlock
->
max
Ver
)
||
if ((pReader->verRange.maxVer >= p
Record->firstKeyVer && pReader->verRange.maxVer < pRecord->lastKey
Ver)||
(
pReader
->
verRange
.
minVer
<=
p
Block
->
maxVer
&&
pReader
->
verRange
.
minVer
>
pBlock
->
min
Ver
))
{
(pReader->verRange.minVer <= p
Record->lastKeyVer && pReader->verRange.minVer > pRecord->firstKey
Ver)) {
int32_t i = endPos;
int32_t i = endPos;
if (asc) {
if (asc) {
...
@@ -1169,7 +1199,7 @@ static int32_t getEndPosInDataBlock(STsdbReader* pReader, SBlockData* pBlockData
...
@@ -1169,7 +1199,7 @@ static int32_t getEndPosInDataBlock(STsdbReader* pReader, SBlockData* pBlockData
}
}
}
}
} else {
} else {
for
(;
i
<
p
Block
->
n
Row
;
++
i
)
{
for(; i < p
Record->num
Row; ++i) {
if (pBlockData->aVersion[i] >= pReader->verRange.minVer) {
if (pBlockData->aVersion[i] >= pReader->verRange.minVer) {
break;
break;
}
}
...
@@ -1300,7 +1330,7 @@ static int32_t copyBlockDataToSDataBlock(STsdbReader* pReader) {
...
@@ -1300,7 +1330,7 @@ static int32_t copyBlockDataToSDataBlock(STsdbReader* pReader) {
SBlockData* pBlockData = &pStatus->fileBlockData;
SBlockData* pBlockData = &pStatus->fileBlockData;
SFileDataBlockInfo* pBlockInfo = getCurrentBlockInfo(pBlockIter);
SFileDataBlockInfo* pBlockInfo = getCurrentBlockInfo(pBlockIter);
SDataBlk
*
pBlock
=
getCurrentBlock
(
pBlockIter
);
//
SDataBlk* pBlock = getCurrentBlock(pBlockIter);
SSDataBlock* pResBlock = pReader->resBlockInfo.pResBlock;
SSDataBlock* pResBlock = pReader->resBlockInfo.pResBlock;
int32_t numOfOutputCols = pSupInfo->numOfCols;
int32_t numOfOutputCols = pSupInfo->numOfCols;
int32_t code = TSDB_CODE_SUCCESS;
int32_t code = TSDB_CODE_SUCCESS;
...
@@ -1310,6 +1340,8 @@ static int32_t copyBlockDataToSDataBlock(STsdbReader* pReader) {
...
@@ -1310,6 +1340,8 @@ static int32_t copyBlockDataToSDataBlock(STsdbReader* pReader) {
bool asc = ASCENDING_TRAVERSE(pReader->order);
bool asc = ASCENDING_TRAVERSE(pReader->order);
int32_t step = asc ? 1 : -1;
int32_t step = asc ? 1 : -1;
SBrinRecord* pRecord = &pBlockInfo->record;
// no data exists, return directly.
// no data exists, return directly.
if (pBlockData->nRow == 0 || pBlockData->aTSKEY == 0) {
if (pBlockData->nRow == 0 || pBlockData->aTSKEY == 0) {
tsdbWarn("%p no need to copy since no data in blockData, table uid:%" PRIu64 " has been dropped, %s", pReader,
tsdbWarn("%p no need to copy since no data in blockData, table uid:%" PRIu64 " has been dropped, %s", pReader,
...
@@ -1319,34 +1351,34 @@ static int32_t copyBlockDataToSDataBlock(STsdbReader* pReader) {
...
@@ -1319,34 +1351,34 @@ static int32_t copyBlockDataToSDataBlock(STsdbReader* pReader) {
}
}
// row index of dump info remain the initial position, let's find the appropriate start position.
// row index of dump info remain the initial position, let's find the appropriate start position.
if
((
pDumpInfo
->
rowIndex
==
0
&&
asc
)
||
(
pDumpInfo
->
rowIndex
==
p
Block
->
n
Row
-
1
&&
(
!
asc
)))
{
if ((pDumpInfo->rowIndex == 0 && asc) || (pDumpInfo->rowIndex == p
Record->num
Row - 1 && (!asc))) {
if
(
asc
&&
pReader
->
window
.
skey
<=
p
Block
->
minKey
.
ts
&&
pReader
->
verRange
.
minVer
<=
pBlock
->
min
Ver
)
{
if (asc && pReader->window.skey <= p
Record->firstKey && pReader->verRange.minVer <= pRecord->firstKey
Ver) {
// pDumpInfo->rowIndex = 0;
// pDumpInfo->rowIndex = 0;
}
else
if
(
!
asc
&&
pReader
->
window
.
ekey
>=
p
Block
->
maxKey
.
ts
&&
pReader
->
verRange
.
maxVer
>=
pBlock
->
max
Ver
)
{
} else if (!asc && pReader->window.ekey >= p
Record->lastKey && pReader->verRange.maxVer >= pRecord->lastKey
Ver) {
// pDumpInfo->rowIndex = p
Block->n
Row - 1;
// pDumpInfo->rowIndex = p
Record->num
Row - 1;
} else { // find the appropriate the start position in current block, and set it to be the current rowIndex
} else { // find the appropriate the start position in current block, and set it to be the current rowIndex
int32_t
pos
=
asc
?
p
Block
->
n
Row
-
1
:
0
;
int32_t pos = asc ? p
Record->num
Row - 1 : 0;
int32_t order = asc ? TSDB_ORDER_DESC : TSDB_ORDER_ASC;
int32_t order = asc ? TSDB_ORDER_DESC : TSDB_ORDER_ASC;
int64_t key = asc ? pReader->window.skey : pReader->window.ekey;
int64_t key = asc ? pReader->window.skey : pReader->window.ekey;
pDumpInfo
->
rowIndex
=
doBinarySearchKey
(
pBlockData
->
aTSKEY
,
p
Block
->
n
Row
,
pos
,
key
,
order
);
pDumpInfo->rowIndex = doBinarySearchKey(pBlockData->aTSKEY, p
Record->num
Row, pos, key, order);
if (pDumpInfo->rowIndex < 0) {
if (pDumpInfo->rowIndex < 0) {
tsdbError(
tsdbError(
"%p failed to locate the start position in current block, global index:%d, table index:%d, brange:%" PRId64
"%p failed to locate the start position in current block, global index:%d, table index:%d, brange:%" PRId64
"-%" PRId64 ", minVer:%" PRId64 ", maxVer:%" PRId64 " %s",
"-%" PRId64 ", minVer:%" PRId64 ", maxVer:%" PRId64 " %s",
pReader
,
pBlockIter
->
index
,
pBlockInfo
->
tbBlockIdx
,
p
Block
->
minKey
.
ts
,
pBlock
->
maxKey
.
ts
,
pBlock
->
min
Ver
,
pReader, pBlockIter->index, pBlockInfo->tbBlockIdx, p
Record->firstKey, pRecord->lastKey, pRecord->firstKey
Ver,
p
Block
->
max
Ver
,
pReader
->
idStr
);
p
Record->lastKey
Ver, pReader->idStr);
return TSDB_CODE_INVALID_PARA;
return TSDB_CODE_INVALID_PARA;
}
}
ASSERT
(
pReader
->
verRange
.
minVer
<=
p
Block
->
maxVer
&&
pReader
->
verRange
.
maxVer
>=
pBlock
->
min
Ver
);
ASSERT(pReader->verRange.minVer <= p
Record->lastKeyVer && pReader->verRange.maxVer >= pRecord->firstKey
Ver);
// find the appropriate start position that satisfies the version requirement.
// find the appropriate start position that satisfies the version requirement.
if
((
pReader
->
verRange
.
maxVer
>=
p
Block
->
minVer
&&
pReader
->
verRange
.
maxVer
<
pBlock
->
max
Ver
)
||
if ((pReader->verRange.maxVer >= p
Record->firstKeyVer && pReader->verRange.maxVer < pRecord->lastKey
Ver)||
(
pReader
->
verRange
.
minVer
<=
p
Block
->
maxVer
&&
pReader
->
verRange
.
minVer
>
pBlock
->
min
Ver
))
{
(pReader->verRange.minVer <= p
Record->lastKeyVer && pReader->verRange.minVer > pRecord->firstKey
Ver)) {
int32_t i = pDumpInfo->rowIndex;
int32_t i = pDumpInfo->rowIndex;
if (asc) {
if (asc) {
for
(;
i
<
p
Block
->
n
Row
;
++
i
)
{
for(; i < p
Record->num
Row; ++i) {
if (pBlockData->aVersion[i] >= pReader->verRange.minVer) {
if (pBlockData->aVersion[i] >= pReader->verRange.minVer) {
break;
break;
}
}
...
@@ -1365,7 +1397,7 @@ static int32_t copyBlockDataToSDataBlock(STsdbReader* pReader) {
...
@@ -1365,7 +1397,7 @@ static int32_t copyBlockDataToSDataBlock(STsdbReader* pReader) {
}
}
// time window check
// time window check
int32_t
endIndex
=
getEndPosInDataBlock
(
pReader
,
pBlockData
,
p
Block
,
pDumpInfo
->
rowIndex
);
int32_t endIndex = getEndPosInDataBlock(pReader, pBlockData, p
Record
, pDumpInfo->rowIndex);
if (endIndex == -1) {
if (endIndex == -1) {
setBlockAllDumped(pDumpInfo, pReader->window.ekey, pReader->order);
setBlockAllDumped(pDumpInfo, pReader->window.ekey, pReader->order);
return TSDB_CODE_SUCCESS;
return TSDB_CODE_SUCCESS;
...
@@ -1437,24 +1469,24 @@ static int32_t copyBlockDataToSDataBlock(STsdbReader* pReader) {
...
@@ -1437,24 +1469,24 @@ static int32_t copyBlockDataToSDataBlock(STsdbReader* pReader) {
pDumpInfo->rowIndex += step * dumpedRows;
pDumpInfo->rowIndex += step * dumpedRows;
// check if current block are all handled
// check if current block are all handled
if
(
pDumpInfo
->
rowIndex
>=
0
&&
pDumpInfo
->
rowIndex
<
p
Block
->
n
Row
)
{
if (pDumpInfo->rowIndex >= 0 && pDumpInfo->rowIndex < p
Record->num
Row) {
int64_t ts = pBlockData->aTSKEY[pDumpInfo->rowIndex];
int64_t ts = pBlockData->aTSKEY[pDumpInfo->rowIndex];
if (outOfTimeWindow(ts, &pReader->window)) { // the remain data has out of query time window, ignore current block
if (outOfTimeWindow(ts, &pReader->window)) { // the remain data has out of query time window, ignore current block
setBlockAllDumped(pDumpInfo, ts, pReader->order);
setBlockAllDumped(pDumpInfo, ts, pReader->order);
}
}
} else {
} else {
int64_t
ts
=
asc
?
p
Block
->
maxKey
.
ts
:
pBlock
->
minKey
.
ts
;
int64_t ts = asc ? p
Record->lastKey : pRecord->firstKey
;
setBlockAllDumped(pDumpInfo, ts, pReader->order);
setBlockAllDumped(pDumpInfo, ts, pReader->order);
}
}
double elapsedTime = (taosGetTimestampUs() - st) / 1000.0;
double elapsedTime = (taosGetTimestampUs() - st) / 1000.0;
pReader->cost.blockLoadTime += elapsedTime;
pReader->cost.blockLoadTime += elapsedTime;
int32_t
unDumpedRows
=
asc
?
p
Block
->
n
Row
-
pDumpInfo
->
rowIndex
:
pDumpInfo
->
rowIndex
+
1
;
int32_t unDumpedRows = asc ? p
Record->num
Row - pDumpInfo->rowIndex : pDumpInfo->rowIndex + 1;
tsdbDebug("%p copy file block to sdatablock, global index:%d, table index:%d, brange:%" PRId64 "-%" PRId64
tsdbDebug("%p copy file block to sdatablock, global index:%d, table index:%d, brange:%" PRId64 "-%" PRId64
", rows:%d, remain:%d, minVer:%" PRId64 ", maxVer:%" PRId64 ", uid:%" PRIu64 " elapsed time:%.2f ms, %s",
", rows:%d, remain:%d, minVer:%" PRId64 ", maxVer:%" PRId64 ", uid:%" PRIu64 " elapsed time:%.2f ms, %s",
pReader
,
pBlockIter
->
index
,
pBlockInfo
->
tbBlockIdx
,
p
Block
->
minKey
.
ts
,
pBlock
->
maxKey
.
ts
,
dumpedRows
,
pReader, pBlockIter->index, pBlockInfo->tbBlockIdx, p
Record->firstKey, pRecord->lastKey
, dumpedRows,
unDumpedRows
,
p
Block
->
minVer
,
pBlock
->
max
Ver
,
pBlockInfo
->
uid
,
elapsedTime
,
pReader
->
idStr
);
unDumpedRows, p
Record->firstKeyVer, pRecord->lastKey
Ver, pBlockInfo->uid, elapsedTime, pReader->idStr);
return TSDB_CODE_SUCCESS;
return TSDB_CODE_SUCCESS;
}
}
...
@@ -1505,22 +1537,23 @@ static int32_t doLoadFileBlockData(STsdbReader* pReader, SDataBlockIter* pBlockI
...
@@ -1505,22 +1537,23 @@ static int32_t doLoadFileBlockData(STsdbReader* pReader, SDataBlockIter* pBlockI
SFileDataBlockInfo* pBlockInfo = getCurrentBlockInfo(pBlockIter);
SFileDataBlockInfo* pBlockInfo = getCurrentBlockInfo(pBlockIter);
SFileBlockDumpInfo* pDumpInfo = &pReader->status.fBlockDumpInfo;
SFileBlockDumpInfo* pDumpInfo = &pReader->status.fBlockDumpInfo;
SDataBlk
*
pBlock
=
getCurrentBlock
(
pBlockIter
);
//
SDataBlk* pBlock = getCurrentBlock(pBlockIter);
// code = tsdbReadDataBlock(pReader->pFileReader, pBlock
, pBlockData);
code = tsdbDataFileReadBlockData(pReader->pFileReader, &pBlockInfo->record
, pBlockData);
if (code != TSDB_CODE_SUCCESS) {
if (code != TSDB_CODE_SUCCESS) {
tsdbError("%p error occurs in loading file block, global index:%d, table index:%d, brange:%" PRId64 "-%" PRId64
tsdbError("%p error occurs in loading file block, global index:%d, table index:%d, brange:%" PRId64 "-%" PRId64
", rows:%d, code:%s %s",
", rows:%d, code:%s %s",
pReader
,
pBlockIter
->
index
,
pBlockInfo
->
tbBlockIdx
,
pBlock
->
minKey
.
ts
,
pBlock
->
maxKey
.
ts
,
pBlock
->
nRow
,
pReader, pBlockIter->index, pBlockInfo->tbBlockIdx, pBlock
Info->record.firstKey
,
tstrerror
(
code
),
pReader
->
idStr
);
pBlockInfo->record.lastKey, pBlockInfo->record.numRow,
tstrerror(code), pReader->idStr);
return code;
return code;
}
}
double elapsedTime = (taosGetTimestampUs() - st) / 1000.0;
double elapsedTime = (taosGetTimestampUs() - st) / 1000.0;
SBrinRecord* pRecord = &pBlockInfo->record;
tsdbDebug("%p load file block into buffer, global index:%d, index in table block list:%d, brange:%" PRId64 "-%" PRId64
tsdbDebug("%p load file block into buffer, global index:%d, index in table block list:%d, brange:%" PRId64 "-%" PRId64
", rows:%d, minVer:%" PRId64 ", maxVer:%" PRId64 ", elapsed time:%.2f ms, %s",
", rows:%d, minVer:%" PRId64 ", maxVer:%" PRId64 ", elapsed time:%.2f ms, %s",
pReader
,
pBlockIter
->
index
,
pBlockInfo
->
tbBlockIdx
,
p
Block
->
minKey
.
ts
,
pBlock
->
maxKey
.
ts
,
pBlock
->
n
Row
,
pReader, pBlockIter->index, pBlockInfo->tbBlockIdx, p
Record->firstKey, pRecord->lastKey, pRecord->num
Row,
p
Block
->
minVer
,
pBlock
->
max
Ver
,
elapsedTime
,
pReader
->
idStr
);
p
Record->firstKeyVer, pRecord->lastKey
Ver, elapsedTime, pReader->idStr);
pReader->cost.blockLoadTime += elapsedTime;
pReader->cost.blockLoadTime += elapsedTime;
pDumpInfo->allDumped = false;
pDumpInfo->allDumped = false;
...
@@ -1603,6 +1636,7 @@ static int32_t initBlockIterator(STsdbReader* pReader, SDataBlockIter* pBlockIte
...
@@ -1603,6 +1636,7 @@ static int32_t initBlockIterator(STsdbReader* pReader, SDataBlockIter* pBlockIte
SBlockOrderSupporter sup = {0};
SBlockOrderSupporter sup = {0};
pBlockIter->numOfBlocks = numOfBlocks;
pBlockIter->numOfBlocks = numOfBlocks;
taosArrayClear(pBlockIter->blockList);
taosArrayClear(pBlockIter->blockList);
pBlockIter->pTableMap = pReader->status.pTableMap;
pBlockIter->pTableMap = pReader->status.pTableMap;
// access data blocks according to the offset of each block in asc/desc order.
// access data blocks according to the offset of each block in asc/desc order.
...
@@ -1632,9 +1666,9 @@ static int32_t initBlockIterator(STsdbReader* pReader, SDataBlockIter* pBlockIte
...
@@ -1632,9 +1666,9 @@ static int32_t initBlockIterator(STsdbReader* pReader, SDataBlockIter* pBlockIte
sup.pDataBlockInfo[sup.numOfTables] = (SBlockOrderWrapper*)buf;
sup.pDataBlockInfo[sup.numOfTables] = (SBlockOrderWrapper*)buf;
for (int32_t k = 0; k < num; ++k) {
for (int32_t k = 0; k < num; ++k) {
SB
lockIndex
*
pIndex
=
taosArrayGet
(
pTableScanInfo
->
pBlockList
,
k
);
SB
rinRecord* pRecord
= taosArrayGet(pTableScanInfo->pBlockList, k);
sup.pDataBlockInfo[sup.numOfTables][k] =
sup.pDataBlockInfo[sup.numOfTables][k] =
(
SBlockOrderWrapper
){.
uid
=
pTableScanInfo
->
uid
,
.
offset
=
p
Index
->
inFileOffset
};
(SBlockOrderWrapper){.uid = pTableScanInfo->uid, .offset = p
Record->blockOffset, .pInfo = pTableScanInfo
};
cnt++;
cnt++;
}
}
...
@@ -1650,6 +1684,8 @@ static int32_t initBlockIterator(STsdbReader* pReader, SDataBlockIter* pBlockIte
...
@@ -1650,6 +1684,8 @@ static int32_t initBlockIterator(STsdbReader* pReader, SDataBlockIter* pBlockIte
if (sup.numOfTables == 1) {
if (sup.numOfTables == 1) {
for (int32_t i = 0; i < numOfBlocks; ++i) {
for (int32_t i = 0; i < numOfBlocks; ++i) {
SFileDataBlockInfo blockInfo = {.uid = sup.pDataBlockInfo[0][i].uid, .tbBlockIdx = i};
SFileDataBlockInfo blockInfo = {.uid = sup.pDataBlockInfo[0][i].uid, .tbBlockIdx = i};
blockInfo.record = *(SBrinRecord*)taosArrayGet(sup.pDataBlockInfo[0][i].pInfo->pBlockList, i);
taosArrayPush(pBlockIter->blockList, &blockInfo);
taosArrayPush(pBlockIter->blockList, &blockInfo);
}
}
...
@@ -1720,15 +1756,15 @@ static bool blockIteratorNext(SDataBlockIter* pBlockIter, const char* idStr) {
...
@@ -1720,15 +1756,15 @@ static bool blockIteratorNext(SDataBlockIter* pBlockIter, const char* idStr) {
/**
/**
* This is an two rectangles overlap cases.
* This is an two rectangles overlap cases.
*/
*/
static
int32_t
dataBlockPartiallyRequired
(
STimeWindow
*
pWindow
,
SVersionRange
*
pVerRange
,
S
DataBlk
*
pBlock
)
{
static int32_t dataBlockPartiallyRequired(STimeWindow* pWindow, SVersionRange* pVerRange, S
FileDataBlockInfo
* pBlock) {
return
(
pWindow
->
ekey
<
pBlock
->
maxKey
.
ts
&&
pWindow
->
ekey
>=
pBlock
->
minKey
.
ts
)
||
return (pWindow->ekey < pBlock->
record.lastKey && pWindow->ekey >= pBlock->record.firstKey
) ||
(
pWindow
->
skey
>
pBlock
->
minKey
.
ts
&&
pWindow
->
skey
<=
pBlock
->
maxKey
.
ts
)
||
(pWindow->skey > pBlock->
record.firstKey && pWindow->skey <= pBlock->record.lastKey
) ||
(
pVerRange
->
minVer
>
pBlock
->
minVer
&&
pVerRange
->
minVer
<=
pBlock
->
max
Ver
)
||
(pVerRange->minVer > pBlock->
record.firstKeyVer && pVerRange->minVer <= pBlock->record.lastKey
Ver) ||
(
pVerRange
->
maxVer
<
pBlock
->
maxVer
&&
pVerRange
->
maxVer
>=
pBlock
->
min
Ver
);
(pVerRange->maxVer < pBlock->
record.lastKeyVer && pVerRange->maxVer >= pBlock->record.firstKey
Ver);
}
}
static bool getNeighborBlockOfSameTable(SFileDataBlockInfo* pBlockInfo, STableBlockScanInfo* pTableBlockScanInfo,
static bool getNeighborBlockOfSameTable(SFileDataBlockInfo* pBlockInfo, STableBlockScanInfo* pTableBlockScanInfo,
int32_t
*
nextIndex
,
int32_t
order
,
SB
lockIndex
*
pBlockIndex
)
{
int32_t* nextIndex, int32_t order, SB
rinRecord* pRecord
) {
bool asc = ASCENDING_TRAVERSE(order);
bool asc = ASCENDING_TRAVERSE(order);
if (asc && pBlockInfo->tbBlockIdx >= taosArrayGetSize(pTableBlockScanInfo->pBlockList) - 1) {
if (asc && pBlockInfo->tbBlockIdx >= taosArrayGetSize(pTableBlockScanInfo->pBlockList) - 1) {
return false;
return false;
...
@@ -1739,8 +1775,11 @@ static bool getNeighborBlockOfSameTable(SFileDataBlockInfo* pBlockInfo, STableBl
...
@@ -1739,8 +1775,11 @@ static bool getNeighborBlockOfSameTable(SFileDataBlockInfo* pBlockInfo, STableBl
}
}
int32_t step = asc ? 1 : -1;
int32_t step = asc ? 1 : -1;
*
nextIndex
=
pBlockInfo
->
tbBlockIdx
+
step
;
// *nextIndex = pBlockInfo->tbBlockIdx + step;
*
pBlockIndex
=
*
(
SBlockIndex
*
)
taosArrayGet
(
pTableBlockScanInfo
->
pBlockList
,
*
nextIndex
);
// *pBlockIndex = *(SBlockIndex*)taosArrayGet(pTableBlockScanInfo->pBlockList, *nextIndex);
SBrinRecord* p = taosArrayGet(pTableBlockScanInfo->pBlockList, pBlockInfo->tbBlockIdx + step);
memcpy(pRecord, p, sizeof(SBrinRecord));
// tMapDataGetItemByIdx(&pTableBlockScanInfo->mapData, pIndex->ordinalIndex, pBlock, tGetDataBlk);
// tMapDataGetItemByIdx(&pTableBlockScanInfo->mapData, pIndex->ordinalIndex, pBlock, tGetDataBlk);
return true;
return true;
}
}
...
@@ -1791,16 +1830,25 @@ static bool overlapWithNeighborBlock(SDataBlk* pBlock, SBlockIndex* pNeighborBlo
...
@@ -1791,16 +1830,25 @@ static bool overlapWithNeighborBlock(SDataBlk* pBlock, SBlockIndex* pNeighborBlo
}
}
}
}
static
bool
bufferDataInFileBlockGap
(
int32_t
order
,
TSDBKEY
key
,
SDataBlk
*
pBlock
)
{
static bool overlapWithNeighborBlock2(SFileDataBlockInfo* pBlock, SBrinRecord* pRec, int32_t order) {
// it is the last block in current file, no chance to overlap with neighbor blocks.
if (ASCENDING_TRAVERSE(order)) {
return pBlock->record.lastKey == pRec->firstKey;
} else {
return pBlock->record.firstKey == pRec->lastKey;
}
}
static bool bufferDataInFileBlockGap(int32_t order, TSDBKEY key, SFileDataBlockInfo* pBlock) {
bool ascScan = ASCENDING_TRAVERSE(order);
bool ascScan = ASCENDING_TRAVERSE(order);
return
(
ascScan
&&
(
key
.
ts
!=
TSKEY_INITIAL_VAL
&&
key
.
ts
<=
pBlock
->
minKey
.
ts
))
||
return (ascScan && (key.ts != TSKEY_INITIAL_VAL && key.ts <= pBlock->
record.firstKey
)) ||
(
!
ascScan
&&
(
key
.
ts
!=
TSKEY_INITIAL_VAL
&&
key
.
ts
>=
pBlock
->
maxKey
.
ts
));
(!ascScan && (key.ts != TSKEY_INITIAL_VAL && key.ts >= pBlock->
record.lastKey
));
}
}
static
bool
keyOverlapFileBlock
(
TSDBKEY
key
,
S
DataBlk
*
pBlock
,
SVersionRange
*
pVerRange
)
{
static bool keyOverlapFileBlock(TSDBKEY key, S
FileDataBlockInfo
* pBlock, SVersionRange* pVerRange) {
return
(
key
.
ts
>=
pBlock
->
minKey
.
ts
&&
key
.
ts
<=
pBlock
->
maxKey
.
ts
)
&&
(
pBlock
->
maxVer
>=
pVerRange
->
minVer
)
&&
return (key.ts >= pBlock->
record.firstKey && key.ts <= pBlock->record.lastKey
) &&
(
pBlock
->
min
Ver
<=
pVerRange
->
maxVer
);
(pBlock->
record.lastKeyVer >= pVerRange->minVer) && (pBlock->record.firstKey
Ver <= pVerRange->maxVer);
}
}
static bool doCheckforDatablockOverlap(STableBlockScanInfo* pBlockScanInfo, const SDataBlk* pBlock,
static bool doCheckforDatablockOverlap(STableBlockScanInfo* pBlockScanInfo, const SDataBlk* pBlock,
...
@@ -1875,31 +1923,33 @@ typedef struct {
...
@@ -1875,31 +1923,33 @@ typedef struct {
bool moreThanCapcity;
bool moreThanCapcity;
} SDataBlockToLoadInfo;
} SDataBlockToLoadInfo;
static
void
getBlockToLoadInfo
(
SDataBlockToLoadInfo
*
pInfo
,
SFileDataBlockInfo
*
pBlockInfo
,
SDataBlk
*
pBlock
,
static void getBlockToLoadInfo(SDataBlockToLoadInfo* pInfo, SFileDataBlockInfo* pBlockInfo,
STableBlockScanInfo* pScanInfo, TSDBKEY keyInBuf, SLastBlockReader* pLastBlockReader,
STableBlockScanInfo* pScanInfo, TSDBKEY keyInBuf, SLastBlockReader* pLastBlockReader,
STsdbReader* pReader) {
STsdbReader* pReader) {
int32_t neighborIndex = 0;
int32_t neighborIndex = 0;
SB
lockIndex
bIndex
=
{
0
};
SB
rinRecord rec
= {0};
bool
hasNeighbor
=
getNeighborBlockOfSameTable
(
pBlockInfo
,
pScanInfo
,
&
neighborIndex
,
pReader
->
order
,
&
bIndex
);
bool hasNeighbor = getNeighborBlockOfSameTable(pBlockInfo, pScanInfo, &neighborIndex, pReader->order, &
rec
);
// overlap with neighbor
// overlap with neighbor
if (hasNeighbor) {
if (hasNeighbor) {
pInfo
->
overlapWithNeighborBlock
=
overlapWithNeighborBlock
(
pBlock
,
&
bIndex
,
pReader
->
order
);
// pInfo->overlapWithNeighborBlock = overlapWithNeighborBlock(pBlock, &bIndex, pReader->order);
pInfo->overlapWithNeighborBlock = overlapWithNeighborBlock2(pBlockInfo, &rec, pReader->order);
}
}
// todo:
// has duplicated ts of different version in this block
// has duplicated ts of different version in this block
pInfo
->
hasDupTs
=
(
pBlock
->
nSubBlock
==
1
)
?
pBlock
->
hasDup
:
true
;
pInfo->hasDupTs =
0;//
(pBlock->nSubBlock == 1) ? pBlock->hasDup : true;
pInfo
->
overlapWithDelInfo
=
overlapWithDelSkyline
(
pScanInfo
,
pBlock
,
pReader
->
order
);
pInfo->overlapWithDelInfo =
false;//overlapWithDelSkyline(pScanInfo, pBlockInfo
, pReader->order);
if (hasDataInLastBlock(pLastBlockReader)) {
if (hasDataInLastBlock(pLastBlockReader)) {
int64_t tsLast = getCurrentKeyInLastBlock(pLastBlockReader);
int64_t tsLast = getCurrentKeyInLastBlock(pLastBlockReader);
pInfo
->
overlapWithLastBlock
=
!
(
pBlock
->
maxKey
.
ts
<
tsLast
||
pBlock
->
minKey
.
ts
>
tsLast
);
pInfo->overlapWithLastBlock = !(pBlock
Info->record.lastKey < tsLast || pBlockInfo->record.firstKey
> tsLast);
}
}
pInfo
->
moreThanCapcity
=
pBlock
->
n
Row
>
pReader
->
resBlockInfo
.
capacity
;
pInfo->moreThanCapcity = pBlock
Info->record.num
Row > pReader->resBlockInfo.capacity;
pInfo
->
partiallyRequired
=
dataBlockPartiallyRequired
(
&
pReader
->
window
,
&
pReader
->
verRange
,
pBlock
);
pInfo->partiallyRequired = dataBlockPartiallyRequired(&pReader->window, &pReader->verRange, pBlock
Info
);
pInfo
->
overlapWithKeyInBuf
=
keyOverlapFileBlock
(
keyInBuf
,
pBlock
,
&
pReader
->
verRange
);
pInfo->overlapWithKeyInBuf = keyOverlapFileBlock(keyInBuf, pBlock
Info
, &pReader->verRange);
}
}
// 1. the version of all rows should be less than the endVersion
// 1. the version of all rows should be less than the endVersion
...
@@ -1908,10 +1958,10 @@ static void getBlockToLoadInfo(SDataBlockToLoadInfo* pInfo, SFileDataBlockInfo*
...
@@ -1908,10 +1958,10 @@ static void getBlockToLoadInfo(SDataBlockToLoadInfo* pInfo, SFileDataBlockInfo*
// 4. output buffer should be large enough to hold all rows in current block
// 4. output buffer should be large enough to hold all rows in current block
// 5. delete info should not overlap with current block data
// 5. delete info should not overlap with current block data
// 6. current block should not contain the duplicated ts
// 6. current block should not contain the duplicated ts
static
bool
fileBlockShouldLoad
(
STsdbReader
*
pReader
,
SFileDataBlockInfo
*
pBlockInfo
,
SDataBlk
*
pBlock
,
static bool fileBlockShouldLoad(STsdbReader* pReader, SFileDataBlockInfo* pBlockInfo,
STableBlockScanInfo* pScanInfo, TSDBKEY keyInBuf, SLastBlockReader* pLastBlockReader) {
STableBlockScanInfo* pScanInfo, TSDBKEY keyInBuf, SLastBlockReader* pLastBlockReader) {
SDataBlockToLoadInfo info = {0};
SDataBlockToLoadInfo info = {0};
getBlockToLoadInfo
(
&
info
,
pBlockInfo
,
p
Block
,
p
ScanInfo
,
keyInBuf
,
pLastBlockReader
,
pReader
);
getBlockToLoadInfo(&info, pBlockInfo, pScanInfo, keyInBuf, pLastBlockReader, pReader);
bool loadDataBlock =
bool loadDataBlock =
(info.overlapWithNeighborBlock || info.hasDupTs || info.partiallyRequired || info.overlapWithKeyInBuf ||
(info.overlapWithNeighborBlock || info.hasDupTs || info.partiallyRequired || info.overlapWithKeyInBuf ||
...
@@ -1933,7 +1983,7 @@ static bool fileBlockShouldLoad(STsdbReader* pReader, SFileDataBlockInfo* pBlock
...
@@ -1933,7 +1983,7 @@ static bool fileBlockShouldLoad(STsdbReader* pReader, SFileDataBlockInfo* pBlock
static bool isCleanFileDataBlock(STsdbReader* pReader, SFileDataBlockInfo* pBlockInfo, SDataBlk* pBlock,
static bool isCleanFileDataBlock(STsdbReader* pReader, SFileDataBlockInfo* pBlockInfo, SDataBlk* pBlock,
STableBlockScanInfo* pScanInfo, TSDBKEY keyInBuf, SLastBlockReader* pLastBlockReader) {
STableBlockScanInfo* pScanInfo, TSDBKEY keyInBuf, SLastBlockReader* pLastBlockReader) {
SDataBlockToLoadInfo info = {0};
SDataBlockToLoadInfo info = {0};
getBlockToLoadInfo
(
&
info
,
pBlockInfo
,
p
Block
,
p
ScanInfo
,
keyInBuf
,
pLastBlockReader
,
pReader
);
getBlockToLoadInfo(&info, pBlockInfo, pScanInfo, keyInBuf, pLastBlockReader, pReader);
bool isCleanFileBlock = !(info.overlapWithNeighborBlock || info.hasDupTs || info.overlapWithKeyInBuf ||
bool isCleanFileBlock = !(info.overlapWithNeighborBlock || info.hasDupTs || info.overlapWithKeyInBuf ||
info.overlapWithDelInfo || info.overlapWithLastBlock);
info.overlapWithDelInfo || info.overlapWithLastBlock);
return isCleanFileBlock;
return isCleanFileBlock;
...
@@ -2594,13 +2644,41 @@ static int32_t doMergeMultiLevelRows(STsdbReader* pReader, STableBlockScanInfo*
...
@@ -2594,13 +2644,41 @@ static int32_t doMergeMultiLevelRows(STsdbReader* pReader, STableBlockScanInfo*
return code;
return code;
}
}
int32_t doInitMemDataIter(STsdbReader* pReader, STbData** pData, STableBlockScanInfo* pBlockScanInfo, TSDBKEY* pKey,
SMemTable* pMem, STbDataIter** pIter, const char* type) {
int32_t code = TSDB_CODE_SUCCESS;
int32_t backward = (!ASCENDING_TRAVERSE(pReader->order));
if (pMem != NULL) {
*pData = tsdbGetTbDataFromMemTable(pMem, pReader->suid, pBlockScanInfo->uid);
if ((*pData) != NULL) {
code = tsdbTbDataIterCreate((*pData), pKey, backward, pIter);
if (code == TSDB_CODE_SUCCESS) {
pBlockScanInfo->iter.hasVal = (tsdbTbDataIterGet(*pIter) != NULL);
tsdbDebug("%p uid:%" PRIu64 ", check data in %s from skey:%" PRId64 ", order:%d, ts range in buf:%" PRId64
"-%" PRId64 " %s",
pReader, pBlockScanInfo->uid, type, pKey->ts, pReader->order, (*pData)->minKey, (*pData)->maxKey,
pReader->idStr);
} else {
tsdbError("%p uid:%" PRIu64 ", failed to create iterator for %s, code:%s, %s", pReader, pBlockScanInfo->uid,
type, tstrerror(code), pReader->idStr);
return code;
}
}
} else {
tsdbDebug("%p uid:%" PRIu64 ", no data in %s, %s", pReader, pBlockScanInfo->uid, type, pReader->idStr);
}
return code;
}
static int32_t initMemDataIterator(STableBlockScanInfo* pBlockScanInfo, STsdbReader* pReader) {
static int32_t initMemDataIterator(STableBlockScanInfo* pBlockScanInfo, STsdbReader* pReader) {
if (pBlockScanInfo->iterInit) {
if (pBlockScanInfo->iterInit) {
return TSDB_CODE_SUCCESS;
return TSDB_CODE_SUCCESS;
}
}
int32_t
code
=
TSDB_CODE_SUCCESS
;
TSDBKEY startKey = {0};
TSDBKEY startKey = {0};
if (ASCENDING_TRAVERSE(pReader->order)) {
if (ASCENDING_TRAVERSE(pReader->order)) {
startKey = (TSDBKEY){.ts = pBlockScanInfo->lastKey + 1, .version = pReader->verRange.minVer};
startKey = (TSDBKEY){.ts = pBlockScanInfo->lastKey + 1, .version = pReader->verRange.minVer};
...
@@ -2608,52 +2686,22 @@ static int32_t initMemDataIterator(STableBlockScanInfo* pBlockScanInfo, STsdbRea
...
@@ -2608,52 +2686,22 @@ static int32_t initMemDataIterator(STableBlockScanInfo* pBlockScanInfo, STsdbRea
startKey = (TSDBKEY){.ts = pBlockScanInfo->lastKey - 1, .version = pReader->verRange.maxVer};
startKey = (TSDBKEY){.ts = pBlockScanInfo->lastKey - 1, .version = pReader->verRange.maxVer};
}
}
int32_t
backward
=
(
!
ASCENDING_TRAVERSE
(
pReader
->
order
));
int64_t
st
=
0
;
STbData* d = NULL;
STbData* d = NULL;
if
(
pReader
->
pReadSnap
->
pMem
!=
NULL
)
{
d
=
tsdbGetTbDataFromMemTable
(
pReader
->
pReadSnap
->
pMem
,
pReader
->
suid
,
pBlockScanInfo
->
uid
);
if
(
d
!=
NULL
)
{
code
=
tsdbTbDataIterCreate
(
d
,
&
startKey
,
backward
,
&
pBlockScanInfo
->
iter
.
iter
);
if
(
code
==
TSDB_CODE_SUCCESS
)
{
pBlockScanInfo
->
iter
.
hasVal
=
(
tsdbTbDataIterGet
(
pBlockScanInfo
->
iter
.
iter
)
!=
NULL
);
tsdbDebug
(
"%p uid:%"
PRIu64
", check data in mem from skey:%"
PRId64
", order:%d, ts range in buf:%"
PRId64
int32_t code = doInitMemDataIter(pReader, &d, pBlockScanInfo, &startKey, pReader->pReadSnap->pMem,
"-%"
PRId64
" %s"
,
&pBlockScanInfo->iter.iter, "mem");
pReader
,
pBlockScanInfo
->
uid
,
startKey
.
ts
,
pReader
->
order
,
d
->
minKey
,
d
->
maxKey
,
pReader
->
idStr
);
if (code != TSDB_CODE_SUCCESS) {
}
else
{
tsdbError
(
"%p uid:%"
PRIu64
", failed to create iterator for imem, code:%s, %s"
,
pReader
,
pBlockScanInfo
->
uid
,
tstrerror
(
code
),
pReader
->
idStr
);
return code;
return code;
}
}
}
}
else
{
tsdbDebug
(
"%p uid:%"
PRIu64
", no data in mem, %s"
,
pReader
,
pBlockScanInfo
->
uid
,
pReader
->
idStr
);
}
STbData* di = NULL;
STbData* di = NULL;
if
(
pReader
->
pReadSnap
->
pIMem
!=
NULL
)
{
code = doInitMemDataIter(pReader, &di, pBlockScanInfo, &startKey, pReader->pReadSnap->pIMem,
di
=
tsdbGetTbDataFromMemTable
(
pReader
->
pReadSnap
->
pIMem
,
pReader
->
suid
,
pBlockScanInfo
->
uid
);
&pBlockScanInfo->iiter.iter, "imem");
if
(
di
!=
NULL
)
{
if (code != TSDB_CODE_SUCCESS) {
code
=
tsdbTbDataIterCreate
(
di
,
&
startKey
,
backward
,
&
pBlockScanInfo
->
iiter
.
iter
);
if
(
code
==
TSDB_CODE_SUCCESS
)
{
pBlockScanInfo
->
iiter
.
hasVal
=
(
tsdbTbDataIterGet
(
pBlockScanInfo
->
iiter
.
iter
)
!=
NULL
);
tsdbDebug
(
"%p uid:%"
PRIu64
", check data in imem from skey:%"
PRId64
", order:%d, ts range in buf:%"
PRId64
"-%"
PRId64
" %s"
,
pReader
,
pBlockScanInfo
->
uid
,
startKey
.
ts
,
pReader
->
order
,
di
->
minKey
,
di
->
maxKey
,
pReader
->
idStr
);
}
else
{
tsdbError
(
"%p uid:%"
PRIu64
", failed to create iterator for mem, code:%s, %s"
,
pReader
,
pBlockScanInfo
->
uid
,
tstrerror
(
code
),
pReader
->
idStr
);
return code;
return code;
}
}
}
}
else
{
tsdbDebug
(
"%p uid:%"
PRIu64
", no data in imem, %s"
,
pReader
,
pBlockScanInfo
->
uid
,
pReader
->
idStr
);
}
st
=
taosGetTimestampUs
();
int64_t
st = taosGetTimestampUs();
initDelSkylineIterator(pBlockScanInfo, pReader, d, di);
initDelSkylineIterator(pBlockScanInfo, pReader, d, di);
pReader->cost.initDelSkylineIterTime += (taosGetTimestampUs() - st) / 1000.0;
pReader->cost.initDelSkylineIterTime += (taosGetTimestampUs() - st) / 1000.0;
...
@@ -2815,17 +2863,18 @@ static int32_t loadNeighborIfOverlap(SFileDataBlockInfo* pBlockInfo, STableBlock
...
@@ -2815,17 +2863,18 @@ static int32_t loadNeighborIfOverlap(SFileDataBlockInfo* pBlockInfo, STableBlock
int32_t code = TSDB_CODE_SUCCESS;
int32_t code = TSDB_CODE_SUCCESS;
int32_t step = ASCENDING_TRAVERSE(pReader->order) ? 1 : -1;
int32_t step = ASCENDING_TRAVERSE(pReader->order) ? 1 : -1;
int32_t nextIndex = -1;
int32_t nextIndex = -1;
SBlockIndex
nxtBIndex
=
{
0
};
//
SBlockIndex nxtBIndex = {0};
*loadNeighbor = false;
*loadNeighbor = false;
SDataBlk* pBlock = getCurrentBlock(&pReader->status.blockIter);
SDataBlk* pBlock = getCurrentBlock(&pReader->status.blockIter);
bool
hasNeighbor
=
getNeighborBlockOfSameTable
(
pBlockInfo
,
pBlockScanInfo
,
&
nextIndex
,
pReader
->
order
,
&
nxtBIndex
);
SBrinRecord rec = {0};
bool hasNeighbor = getNeighborBlockOfSameTable(pBlockInfo, pBlockScanInfo, &nextIndex, pReader->order, &rec);
if (!hasNeighbor) { // do nothing
if (!hasNeighbor) { // do nothing
return code;
return code;
}
}
if
(
overlapWithNeighborBlock
(
pBlock
,
&
nxtBIndex
,
pReader
->
order
))
{
// load next block
if (overlapWithNeighborBlock
2(pBlockInfo, &rec
, pReader->order)) { // load next block
SReaderStatus* pStatus = &pReader->status;
SReaderStatus* pStatus = &pReader->status;
SDataBlockIter* pBlockIter = &pStatus->blockIter;
SDataBlockIter* pBlockIter = &pStatus->blockIter;
...
@@ -2997,19 +3046,9 @@ int32_t initDelSkylineIterator(STableBlockScanInfo* pBlockScanInfo, STsdbReader*
...
@@ -2997,19 +3046,9 @@ int32_t initDelSkylineIterator(STableBlockScanInfo* pBlockScanInfo, STsdbReader*
}
}
int32_t code = 0;
int32_t code = 0;
SArray
*
pDelData
=
taosArrayInit
(
4
,
sizeof
(
SDelData
));
SDelFile
*
pDelFile
=
pReader
->
pReadSnap
->
fs
.
pDelFile
;
if (pBlockScanInfo->pDelData == NULL) {
if
(
pDelFile
&&
taosArrayGetSize
(
pReader
->
pDelIdx
)
>
0
)
{
pBlockScanInfo->pDelData = taosArrayInit(4, sizeof(SDelData));
SDelIdx
idx
=
{.
suid
=
pReader
->
suid
,
.
uid
=
pBlockScanInfo
->
uid
};
SDelIdx
*
pIdx
=
taosArraySearch
(
pReader
->
pDelIdx
,
&
idx
,
tCmprDelIdx
,
TD_EQ
);
if
(
pIdx
!=
NULL
)
{
code
=
tsdbReadDelDatav1
(
pReader
->
pDelFReader
,
pIdx
,
pDelData
,
pReader
->
verRange
.
maxVer
);
}
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
goto
_err
;
}
}
}
SDelData* p = NULL;
SDelData* p = NULL;
...
@@ -3017,7 +3056,7 @@ int32_t initDelSkylineIterator(STableBlockScanInfo* pBlockScanInfo, STsdbReader*
...
@@ -3017,7 +3056,7 @@ int32_t initDelSkylineIterator(STableBlockScanInfo* pBlockScanInfo, STsdbReader*
p = pMemTbData->pHead;
p = pMemTbData->pHead;
while (p) {
while (p) {
if (p->version <= pReader->verRange.maxVer) {
if (p->version <= pReader->verRange.maxVer) {
taosArrayPush
(
pDelData
,
p
);
taosArrayPush(p
BlockScanInfo->p
DelData, p);
}
}
p = p->pNext;
p = p->pNext;
...
@@ -3028,18 +3067,19 @@ int32_t initDelSkylineIterator(STableBlockScanInfo* pBlockScanInfo, STsdbReader*
...
@@ -3028,18 +3067,19 @@ int32_t initDelSkylineIterator(STableBlockScanInfo* pBlockScanInfo, STsdbReader*
p = piMemTbData->pHead;
p = piMemTbData->pHead;
while (p) {
while (p) {
if (p->version <= pReader->verRange.maxVer) {
if (p->version <= pReader->verRange.maxVer) {
taosArrayPush
(
pDelData
,
p
);
taosArrayPush(p
BlockScanInfo->p
DelData, p);
}
}
p = p->pNext;
p = p->pNext;
}
}
}
}
if
(
taosArrayGetSize
(
pDelData
)
>
0
)
{
int32_t numOfElems = taosArrayGetSize(pBlockScanInfo->pDelData);
if (numOfElems > 0) {
pBlockScanInfo->delSkyline = taosArrayInit(4, sizeof(TSDBKEY));
pBlockScanInfo->delSkyline = taosArrayInit(4, sizeof(TSDBKEY));
code
=
tsdbBuildDeleteSkyline
(
p
DelData
,
0
,
(
int32_t
)(
taosArrayGetSize
(
pDelData
)
-
1
)
,
pBlockScanInfo
->
delSkyline
);
code = tsdbBuildDeleteSkyline(p
BlockScanInfo->pDelData, 0, numOfElems - 1
, pBlockScanInfo->delSkyline);
}
}
taosArrayDestroy
(
pDelData
);
pBlockScanInfo->pDelData = taosArrayDestroy(pBlockScanInfo->
pDelData);
int32_t index = getInitialDelIndex(pBlockScanInfo->delSkyline, pReader->order);
int32_t index = getInitialDelIndex(pBlockScanInfo->delSkyline, pReader->order);
pBlockScanInfo->iter.index = index;
pBlockScanInfo->iter.index = index;
...
@@ -3049,9 +3089,9 @@ int32_t initDelSkylineIterator(STableBlockScanInfo* pBlockScanInfo, STsdbReader*
...
@@ -3049,9 +3089,9 @@ int32_t initDelSkylineIterator(STableBlockScanInfo* pBlockScanInfo, STsdbReader*
return code;
return code;
_err:
//
_err:
taosArrayDestroy
(
pDelData
);
// taosArrayDestroy(pBlockScanInfo->
pDelData);
return
code
;
//
return code;
}
}
TSDBKEY getCurrentKeyInBuf(STableBlockScanInfo* pScanInfo, STsdbReader* pReader) {
TSDBKEY getCurrentKeyInBuf(STableBlockScanInfo* pScanInfo, STsdbReader* pReader) {
...
@@ -3140,26 +3180,52 @@ static int32_t moveToNextFile(STsdbReader* pReader, SBlockNumber* pBlockNum, SAr
...
@@ -3140,26 +3180,52 @@ static int32_t moveToNextFile(STsdbReader* pReader, SBlockNumber* pBlockNum, SAr
taosArrayDestroy(pIndexList);
taosArrayDestroy(pIndexList);
if
(
pReader
->
pReadSnap
!=
NULL
)
{
STFileObj* pTombFileObj = pReader->status.pCurrentFileset->farr[3];
SDelFile
*
pDelFile
=
pReader
->
pReadSnap
->
fs
.
pDelFile
;
if (pTombFileObj!= NULL) {
if
(
pReader
->
pDelFReader
==
NULL
&&
pDelFile
!=
NULL
)
{
const TTombBlkArray* pBlkArray = NULL;
int32_t
code
=
tsdbDelFReaderOpen
(
&
pReader
->
pDelFReader
,
pDelFile
,
pReader
->
pTsdb
);
int32_t code = tsdbDataFileReadTombBlk(pReader->pFileReader, &pBlkArray);
int32_t i = 0, j = 0;
// todo find the correct start position.
while (i < pBlkArray->size && j < numOfTables) {
STombBlock block = {0};
code = tsdbDataFileReadTombBlock(pReader->pFileReader, &pBlkArray->data[i], &block);
if (code != TSDB_CODE_SUCCESS) {
if (code != TSDB_CODE_SUCCESS) {
return code;
return code;
}
}
pReader
->
pDelIdx
=
taosArrayInit
(
4
,
sizeof
(
SDelIdx
));
uint64_t uid = pReader->status.uidList.tableUidList[j];
if
(
pReader
->
pDelIdx
==
NULL
)
{
STableBlockScanInfo* pScanInfo = getTableBlockScanInfo(pReader->status.pTableMap, uid, pReader->idStr);
code
=
TSDB_CODE_OUT_OF_MEMORY
;
return
code
;
STombRecord record = {0};
for(int32_t k = 0; k < block.suid->size; ++k) {
code = tTombBlockGet(&block, k, &record);
{
while(record.uid > uid) {
j += 1;
uid = pReader->status.uidList.tableUidList[j];
pScanInfo = getTableBlockScanInfo(pReader->status.pTableMap, uid, pReader->idStr);
}
}
code
=
tsdbReadDelIdx
(
pReader
->
pDelFReader
,
pReader
->
pDelIdx
);
if (record.uid < uid) {
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
continue;
taosArrayDestroy
(
pReader
->
pDelIdx
);
return
code
;
}
}
}
}
ASSERT(record.suid == pReader->suid);
if (record.version <= pReader->verRange.maxVer) {
SDelData delData = {.version = record.version, .sKey = record.skey, .eKey = record.ekey};
taosArrayPush(pScanInfo->pDelData, &delData);
}
}
i += 1;
}
}
}
return TSDB_CODE_SUCCESS;
return TSDB_CODE_SUCCESS;
...
@@ -3278,10 +3344,9 @@ static int32_t doBuildDataBlock(STsdbReader* pReader) {
...
@@ -3278,10 +3344,9 @@ static int32_t doBuildDataBlock(STsdbReader* pReader) {
STableBlockScanInfo* pScanInfo = NULL;
STableBlockScanInfo* pScanInfo = NULL;
SFileDataBlockInfo* pBlockInfo = getCurrentBlockInfo(pBlockIter);
SFileDataBlockInfo* pBlockInfo = getCurrentBlockInfo(pBlockIter);
SLastBlockReader* pLastBlockReader = pReader->status.fileIter.pLastBlockReader;
SLastBlockReader* pLastBlockReader = pReader->status.fileIter.pLastBlockReader;
SDataBlk
*
pBlock
=
getCurrentBlock
(
pBlockIter
);
if (pReader->pIgnoreTables && taosHashGet(*pReader->pIgnoreTables, &pBlockInfo->uid, sizeof(pBlockInfo->uid))) {
if (pReader->pIgnoreTables && taosHashGet(*pReader->pIgnoreTables, &pBlockInfo->uid, sizeof(pBlockInfo->uid))) {
setBlockAllDumped
(
&
pStatus
->
fBlockDumpInfo
,
pBlock
->
maxKey
.
ts
,
pReader
->
order
);
setBlockAllDumped(&pStatus->fBlockDumpInfo, pBlock
Info->record.lastKey
, pReader->order);
return code;
return code;
}
}
...
@@ -3294,11 +3359,10 @@ static int32_t doBuildDataBlock(STsdbReader* pReader) {
...
@@ -3294,11 +3359,10 @@ static int32_t doBuildDataBlock(STsdbReader* pReader) {
return terrno;
return terrno;
}
}
initLastBlockReader(pLastBlockReader, pScanInfo, pReader);
initLastBlockReader(pLastBlockReader, pScanInfo, pReader);
TSDBKEY keyInBuf = getCurrentKeyInBuf(pScanInfo, pReader);
TSDBKEY keyInBuf = getCurrentKeyInBuf(pScanInfo, pReader);
if
(
fileBlockShouldLoad
(
pReader
,
pBlockInfo
,
p
Block
,
p
ScanInfo
,
keyInBuf
,
pLastBlockReader
))
{
if (fileBlockShouldLoad(pReader, pBlockInfo, pScanInfo, keyInBuf, pLastBlockReader)) {
code = doLoadFileBlockData(pReader, pBlockIter, &pStatus->fileBlockData, pScanInfo->uid);
code = doLoadFileBlockData(pReader, pBlockIter, &pStatus->fileBlockData, pScanInfo->uid);
if (code != TSDB_CODE_SUCCESS) {
if (code != TSDB_CODE_SUCCESS) {
return code;
return code;
...
@@ -3306,16 +3370,16 @@ static int32_t doBuildDataBlock(STsdbReader* pReader) {
...
@@ -3306,16 +3370,16 @@ static int32_t doBuildDataBlock(STsdbReader* pReader) {
// build composed data block
// build composed data block
code = buildComposedDataBlock(pReader);
code = buildComposedDataBlock(pReader);
}
else
if
(
bufferDataInFileBlockGap
(
pReader
->
order
,
keyInBuf
,
pBlock
))
{
} else if (bufferDataInFileBlockGap(pReader->order, keyInBuf, pBlock
Info
)) {
// data in memory that are earlier than current file block
// data in memory that are earlier than current file block
// rows in buffer should be less than the file block in asc, greater than file block in desc
// rows in buffer should be less than the file block in asc, greater than file block in desc
int64_t
endKey
=
(
ASCENDING_TRAVERSE
(
pReader
->
order
))
?
pBlock
->
minKey
.
ts
:
pBlock
->
maxKey
.
ts
;
int64_t endKey = (ASCENDING_TRAVERSE(pReader->order)) ? pBlock
Info->record.firstKey : pBlockInfo->record.lastKey
;
code = buildDataBlockFromBuf(pReader, pScanInfo, endKey);
code = buildDataBlockFromBuf(pReader, pScanInfo, endKey);
} else {
} else {
if (hasDataInLastBlock(pLastBlockReader) && !ASCENDING_TRAVERSE(pReader->order)) {
if (hasDataInLastBlock(pLastBlockReader) && !ASCENDING_TRAVERSE(pReader->order)) {
// only return the rows in last block
// only return the rows in last block
int64_t tsLast = getCurrentKeyInLastBlock(pLastBlockReader);
int64_t tsLast = getCurrentKeyInLastBlock(pLastBlockReader);
ASSERT
(
tsLast
>=
pBlock
->
maxKey
.
ts
);
ASSERT(tsLast >= pBlock
Info->record.lastKey
);
SBlockData* pBData = &pReader->status.fileBlockData;
SBlockData* pBData = &pReader->status.fileBlockData;
tBlockDataReset(pBData);
tBlockDataReset(pBData);
...
@@ -3354,20 +3418,20 @@ static int32_t doBuildDataBlock(STsdbReader* pReader) {
...
@@ -3354,20 +3418,20 @@ static int32_t doBuildDataBlock(STsdbReader* pReader) {
}
}
} else { // whole block is required, return it directly
} else { // whole block is required, return it directly
SDataBlockInfo* pInfo = &pReader->resBlockInfo.pResBlock->info;
SDataBlockInfo* pInfo = &pReader->resBlockInfo.pResBlock->info;
pInfo
->
rows
=
pBlock
->
n
Row
;
pInfo->rows = pBlock
Info->record.num
Row;
pInfo->id.uid = pScanInfo->uid;
pInfo->id.uid = pScanInfo->uid;
pInfo->dataLoad = 0;
pInfo->dataLoad = 0;
pInfo
->
window
=
(
STimeWindow
){.
skey
=
pBlock
->
minKey
.
ts
,
.
ekey
=
pBlock
->
maxKey
.
ts
};
pInfo->window = (STimeWindow){.skey = pBlock
Info->record.firstKey, .ekey = pBlockInfo->record.lastKey
};
setComposedBlockFlag(pReader, false);
setComposedBlockFlag(pReader, false);
setBlockAllDumped
(
&
pStatus
->
fBlockDumpInfo
,
pBlock
->
maxKey
.
ts
,
pReader
->
order
);
setBlockAllDumped(&pStatus->fBlockDumpInfo, pBlock
Info->record.lastKey
, pReader->order);
// update the last key for the corresponding table
// update the last key for the corresponding table
pScanInfo->lastKey = ASCENDING_TRAVERSE(pReader->order) ? pInfo->window.ekey : pInfo->window.skey;
pScanInfo->lastKey = ASCENDING_TRAVERSE(pReader->order) ? pInfo->window.ekey : pInfo->window.skey;
tsdbDebug("%p uid:%" PRIu64
tsdbDebug("%p uid:%" PRIu64
" clean file block retrieved from file, global index:%d, "
" clean file block retrieved from file, global index:%d, "
"table index:%d, rows:%d, brange:%" PRId64 "-%" PRId64 ", %s",
"table index:%d, rows:%d, brange:%" PRId64 "-%" PRId64 ", %s",
pReader
,
pScanInfo
->
uid
,
pBlockIter
->
index
,
pBlockInfo
->
tbBlockIdx
,
pBlock
->
nRow
,
pBlock
->
minKey
.
ts
,
pReader, pScanInfo->uid, pBlockIter->index, pBlockInfo->tbBlockIdx, pBlock
Info->record.numRow
,
pBlock
->
maxKey
.
ts
,
pReader
->
idStr
);
pBlock
Info->record.firstKey, pBlockInfo->record.lastKey
, pReader->idStr);
}
}
}
}
...
@@ -3405,7 +3469,6 @@ static int32_t doSumFileBlockRows(STsdbReader* pReader, SDataFReader* pFileReade
...
@@ -3405,7 +3469,6 @@ static int32_t doSumFileBlockRows(STsdbReader* pReader, SDataFReader* pFileReade
STableBlockScanInfo* pScanInfo = *p;
STableBlockScanInfo* pScanInfo = *p;
tMapDataReset(&pScanInfo->mapData);
tMapDataReset(&pScanInfo->mapData);
// tsdbReadDataBlk(pReader->pFileReader, pBlockIdx, &pScanInfo->mapData);
SDataBlk block = {0};
SDataBlk block = {0};
for (int32_t j = 0; j < pScanInfo->mapData.nItem; ++j) {
for (int32_t j = 0; j < pScanInfo->mapData.nItem; ++j) {
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录