tsdb/cache: relayout cache row reader
This commit is contained in:
parent
8263c49c17
commit
9b0b4061e0
|
@ -833,9 +833,25 @@ void *destroyLastBlockLoadInfo(SSttBlockLoadInfo *pLoadInfo);
|
||||||
void *destroySttBlockReader(SArray *pLDataIterArray, int64_t *blocks, double *el);
|
void *destroySttBlockReader(SArray *pLDataIterArray, int64_t *blocks, double *el);
|
||||||
|
|
||||||
// tsdbCache ==============================================================================================
|
// tsdbCache ==============================================================================================
|
||||||
|
typedef enum {
|
||||||
|
READ_MODE_COUNT_ONLY = 0x1,
|
||||||
|
READ_MODE_ALL,
|
||||||
|
} EReadMode;
|
||||||
|
|
||||||
|
typedef struct STsdbReaderInfo {
|
||||||
|
uint64_t suid;
|
||||||
|
STSchema *pSchema;
|
||||||
|
EReadMode readMode;
|
||||||
|
uint64_t rowsNum;
|
||||||
|
STimeWindow window;
|
||||||
|
SVersionRange verRange;
|
||||||
|
int16_t order;
|
||||||
|
} STsdbReaderInfo;
|
||||||
|
|
||||||
typedef struct SCacheRowsReader {
|
typedef struct SCacheRowsReader {
|
||||||
STsdb *pTsdb;
|
STsdb *pTsdb;
|
||||||
SVersionRange verRange;
|
STsdbReaderInfo info;
|
||||||
|
// SVersionRange verRange;
|
||||||
TdThreadMutex readerMutex;
|
TdThreadMutex readerMutex;
|
||||||
SVnode *pVnode;
|
SVnode *pVnode;
|
||||||
STSchema *pSchema;
|
STSchema *pSchema;
|
||||||
|
|
|
@ -1720,6 +1720,42 @@ typedef struct {
|
||||||
SMergeTree *pMergeTree;
|
SMergeTree *pMergeTree;
|
||||||
} SFSLastIter;
|
} SFSLastIter;
|
||||||
|
|
||||||
|
static int32_t lastIterOpen(SFSLastIter *iter, STFileSet *pFileSet, STsdb *pTsdb, STSchema *pTSchema, tb_uid_t suid,
|
||||||
|
tb_uid_t uid, SCacheRowsReader *pr, int64_t lastTs, int16_t *aCols, int nCols) {
|
||||||
|
int32_t code = 0;
|
||||||
|
|
||||||
|
int64_t loadBlocks = 0;
|
||||||
|
double elapse = 0;
|
||||||
|
pr->pLDataIterArray = destroySttBlockReader(pr->pLDataIterArray, &loadBlocks, &elapse);
|
||||||
|
pr->pLDataIterArray = taosArrayInit(4, POINTER_BYTES);
|
||||||
|
|
||||||
|
SMergeTreeConf conf = {
|
||||||
|
.uid = uid,
|
||||||
|
.suid = suid,
|
||||||
|
.pTsdb = pTsdb,
|
||||||
|
.timewindow = (STimeWindow){.skey = lastTs, .ekey = TSKEY_MAX},
|
||||||
|
.verRange = (SVersionRange){.minVer = 0, .maxVer = UINT64_MAX},
|
||||||
|
.strictTimeRange = false,
|
||||||
|
.pSchema = pTSchema,
|
||||||
|
.pCurrentFileset = pFileSet,
|
||||||
|
.backward = 1,
|
||||||
|
.pSttFileBlockIterArray = pr->pLDataIterArray,
|
||||||
|
.pCols = aCols,
|
||||||
|
.numOfCols = nCols,
|
||||||
|
.pReader = pr,
|
||||||
|
.idstr = pr->idstr,
|
||||||
|
};
|
||||||
|
|
||||||
|
code = tMergeTreeOpen2(&iter->mergeTree, &conf);
|
||||||
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
iter->pMergeTree = &iter->mergeTree;
|
||||||
|
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
static int32_t lastIterClose(SFSLastIter **iter) {
|
static int32_t lastIterClose(SFSLastIter **iter) {
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
|
|
||||||
|
@ -1733,43 +1769,9 @@ static int32_t lastIterClose(SFSLastIter **iter) {
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t lastIterNext(SFSLastIter *iter, TSDBROW **ppRow, STsdb *pTsdb, STSchema *pTSchema, tb_uid_t suid,
|
static int32_t lastIterNext(SFSLastIter *iter, TSDBROW **ppRow) {
|
||||||
tb_uid_t uid, SCacheRowsReader *pr, int64_t lastTs, STFileSet *pFileSet, int16_t *aCols,
|
|
||||||
int nCols) {
|
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
|
|
||||||
if (!iter->pMergeTree) {
|
|
||||||
int64_t loadBlocks = 0;
|
|
||||||
double elapse = 0;
|
|
||||||
pr->pLDataIterArray = destroySttBlockReader(pr->pLDataIterArray, &loadBlocks, &elapse);
|
|
||||||
pr->pLDataIterArray = taosArrayInit(4, POINTER_BYTES);
|
|
||||||
|
|
||||||
SMergeTreeConf conf = {
|
|
||||||
.uid = uid,
|
|
||||||
.suid = suid,
|
|
||||||
.pTsdb = pTsdb,
|
|
||||||
.timewindow = (STimeWindow){.skey = lastTs, .ekey = TSKEY_MAX},
|
|
||||||
.verRange = (SVersionRange){.minVer = 0, .maxVer = UINT64_MAX},
|
|
||||||
.strictTimeRange = false,
|
|
||||||
.pSchema = pTSchema,
|
|
||||||
.pCurrentFileset = pFileSet,
|
|
||||||
.backward = 1,
|
|
||||||
.pSttFileBlockIterArray = pr->pLDataIterArray,
|
|
||||||
.pCols = aCols,
|
|
||||||
.numOfCols = nCols,
|
|
||||||
.pReader = pr,
|
|
||||||
.idstr = pr->idstr,
|
|
||||||
};
|
|
||||||
|
|
||||||
code = tMergeTreeOpen2(&iter->mergeTree, &conf);
|
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
iter->pMergeTree = &iter->mergeTree;
|
|
||||||
}
|
|
||||||
|
|
||||||
// retrieve next row
|
|
||||||
bool hasVal = tMergeTreeNext(iter->pMergeTree);
|
bool hasVal = tMergeTreeNext(iter->pMergeTree);
|
||||||
if (!hasVal) {
|
if (!hasVal) {
|
||||||
*ppRow = NULL;
|
*ppRow = NULL;
|
||||||
|
@ -1823,6 +1825,17 @@ typedef struct SFSNextRowIter {
|
||||||
struct CacheNextRowIter *pRowIter;
|
struct CacheNextRowIter *pRowIter;
|
||||||
} SFSNextRowIter;
|
} SFSNextRowIter;
|
||||||
|
|
||||||
|
static void clearLastFileSet(SFSNextRowIter *state) {
|
||||||
|
if (state->pLastIter) {
|
||||||
|
lastIterClose(&state->pLastIter);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (state->pBlockData) {
|
||||||
|
tBlockDataDestroy(state->pBlockData);
|
||||||
|
state->pBlockData = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static int32_t getNextRowFromFS(void *iter, TSDBROW **ppRow, bool *pIgnoreEarlierTs, bool isLast, int16_t *aCols,
|
static int32_t getNextRowFromFS(void *iter, TSDBROW **ppRow, bool *pIgnoreEarlierTs, bool isLast, int16_t *aCols,
|
||||||
int nCols) {
|
int nCols) {
|
||||||
SFSNextRowIter *state = (SFSNextRowIter *)iter;
|
SFSNextRowIter *state = (SFSNextRowIter *)iter;
|
||||||
|
@ -1837,8 +1850,11 @@ static int32_t getNextRowFromFS(void *iter, TSDBROW **ppRow, bool *pIgnoreEarlie
|
||||||
|
|
||||||
if (SFSNEXTROW_FILESET == state->state) {
|
if (SFSNEXTROW_FILESET == state->state) {
|
||||||
_next_fileset:
|
_next_fileset:
|
||||||
if (--state->iFileSet < 0) { // no fileset left, cleanup and return NULL row
|
if (--state->iFileSet < 0) {
|
||||||
|
clearLastFileSet(state);
|
||||||
|
|
||||||
|
*ppRow = NULL;
|
||||||
|
return code;
|
||||||
} else {
|
} else {
|
||||||
state->pFileSet = TARRAY2_GET(state->aDFileSet, state->iFileSet);
|
state->pFileSet = TARRAY2_GET(state->aDFileSet, state->iFileSet);
|
||||||
}
|
}
|
||||||
|
@ -1872,9 +1888,16 @@ static int32_t getNextRowFromFS(void *iter, TSDBROW **ppRow, bool *pIgnoreEarlie
|
||||||
goto _err;
|
goto _err;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: load tomb data from data and sttt
|
code = lastIterOpen(&state->lastIter, state->pFileSet, state->pTsdb, state->pTSchema, state->suid, state->uid,
|
||||||
|
state->pr, state->lastTs, aCols, nCols);
|
||||||
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
|
goto _err;
|
||||||
|
}
|
||||||
|
|
||||||
state->pLastIter = &state->lastIter;
|
state->pLastIter = &state->lastIter;
|
||||||
|
|
||||||
|
// TODO: load tomb data from data and stt
|
||||||
|
|
||||||
if (!state->pIndexList) {
|
if (!state->pIndexList) {
|
||||||
state->pIndexList = taosArrayInit(1, sizeof(SBrinBlk));
|
state->pIndexList = taosArrayInit(1, sizeof(SBrinBlk));
|
||||||
} else {
|
} else {
|
||||||
|
@ -1990,8 +2013,7 @@ static int32_t getNextRowFromFS(void *iter, TSDBROW **ppRow, bool *pIgnoreEarlie
|
||||||
|
|
||||||
if (!state->pLastRow) {
|
if (!state->pLastRow) {
|
||||||
// get next row from fslast and process with fs row, --state->Row if select fs row
|
// get next row from fslast and process with fs row, --state->Row if select fs row
|
||||||
code = lastIterNext(&state->lastIter, &state->pLastRow, state->pTsdb, state->pTSchema, state->suid, state->uid,
|
code = lastIterNext(&state->lastIter, &state->pLastRow);
|
||||||
state->pr, state->lastTs, state->pFileSet, aCols, nCols);
|
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
goto _err;
|
goto _err;
|
||||||
}
|
}
|
||||||
|
|
|
@ -143,7 +143,7 @@ int32_t tsdbCacherowsReaderOpen(void* pVnode, int32_t type, void* pTableIdList,
|
||||||
p->type = type;
|
p->type = type;
|
||||||
p->pVnode = pVnode;
|
p->pVnode = pVnode;
|
||||||
p->pTsdb = p->pVnode->pTsdb;
|
p->pTsdb = p->pVnode->pTsdb;
|
||||||
p->verRange = (SVersionRange){.minVer = 0, .maxVer = UINT64_MAX};
|
p->info.verRange = (SVersionRange){.minVer = 0, .maxVer = UINT64_MAX};
|
||||||
p->numOfCols = numOfCols;
|
p->numOfCols = numOfCols;
|
||||||
p->pCidList = pCidList;
|
p->pCidList = pCidList;
|
||||||
p->pSlotIds = pSlotIds;
|
p->pSlotIds = pSlotIds;
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
#include "tsdb.h"
|
#include "tsdb.h"
|
||||||
#include "tsimplehash.h"
|
#include "tsimplehash.h"
|
||||||
|
|
||||||
#define ASCENDING_TRAVERSE(o) (o == TSDB_ORDER_ASC)
|
#define ASCENDING_TRAVERSE(o) (o == TSDB_ORDER_ASC)
|
||||||
#define getCurrentKeyInLastBlock(_r) ((_r)->currentKey)
|
#define getCurrentKeyInLastBlock(_r) ((_r)->currentKey)
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
|
@ -30,12 +30,12 @@ typedef enum {
|
||||||
EXTERNAL_ROWS_MAIN = 0x2,
|
EXTERNAL_ROWS_MAIN = 0x2,
|
||||||
EXTERNAL_ROWS_NEXT = 0x3,
|
EXTERNAL_ROWS_NEXT = 0x3,
|
||||||
} EContentData;
|
} EContentData;
|
||||||
|
/*
|
||||||
typedef enum {
|
typedef enum {
|
||||||
READ_MODE_COUNT_ONLY = 0x1,
|
READ_MODE_COUNT_ONLY = 0x1,
|
||||||
READ_MODE_ALL,
|
READ_MODE_ALL,
|
||||||
} EReadMode;
|
} EReadMode;
|
||||||
|
*/
|
||||||
typedef struct {
|
typedef struct {
|
||||||
STbDataIter* iter;
|
STbDataIter* iter;
|
||||||
int32_t index;
|
int32_t index;
|
||||||
|
@ -166,7 +166,7 @@ typedef struct SReaderStatus {
|
||||||
SDataBlockIter blockIter;
|
SDataBlockIter blockIter;
|
||||||
SLDataIter* pLDataIter;
|
SLDataIter* pLDataIter;
|
||||||
SRowMerger merger;
|
SRowMerger merger;
|
||||||
SColumnInfoData* pPrimaryTsCol; // primary time stamp output col info data
|
SColumnInfoData* pPrimaryTsCol; // primary time stamp output col info data
|
||||||
} SReaderStatus;
|
} SReaderStatus;
|
||||||
|
|
||||||
typedef struct SBlockInfoBuf {
|
typedef struct SBlockInfoBuf {
|
||||||
|
@ -292,7 +292,7 @@ static int32_t updateBlockSMAInfo(STSchema* pSchema, SBlockLoadSuppInfo* pSupInf
|
||||||
if (j < pSupInfo->numOfCols && PRIMARYKEY_TIMESTAMP_COL_ID == pSupInfo->colId[j]) {
|
if (j < pSupInfo->numOfCols && PRIMARYKEY_TIMESTAMP_COL_ID == pSupInfo->colId[j]) {
|
||||||
j += 1;
|
j += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (i < pSchema->numOfCols && j < pSupInfo->numOfCols) {
|
while (i < pSchema->numOfCols && j < pSupInfo->numOfCols) {
|
||||||
STColumn* pTCol = &pSchema->columns[i];
|
STColumn* pTCol = &pSchema->columns[i];
|
||||||
if (pTCol->colId == pSupInfo->colId[j]) {
|
if (pTCol->colId == pSupInfo->colId[j]) {
|
||||||
|
@ -410,7 +410,7 @@ static int32_t uidComparFunc(const void* p1, const void* p2) {
|
||||||
|
|
||||||
// NOTE: speedup the whole processing by preparing the buffer for STableBlockScanInfo in batch model
|
// NOTE: speedup the whole processing by preparing the buffer for STableBlockScanInfo in batch model
|
||||||
static SSHashObj* createDataBlockScanInfo(STsdbReader* pTsdbReader, SBlockInfoBuf* pBuf, const STableKeyInfo* idList,
|
static SSHashObj* createDataBlockScanInfo(STsdbReader* pTsdbReader, SBlockInfoBuf* pBuf, const STableKeyInfo* idList,
|
||||||
STableUidList* pUidList, int32_t numOfTables) {
|
STableUidList* pUidList, int32_t numOfTables) {
|
||||||
// allocate buffer in order to load data blocks from file
|
// allocate buffer in order to load data blocks from file
|
||||||
// todo use simple hash instead, optimize the memory consumption
|
// todo use simple hash instead, optimize the memory consumption
|
||||||
SSHashObj* pTableMap = tSimpleHashInit(numOfTables, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT));
|
SSHashObj* pTableMap = tSimpleHashInit(numOfTables, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT));
|
||||||
|
@ -461,7 +461,7 @@ static SSHashObj* createDataBlockScanInfo(STsdbReader* pTsdbReader, SBlockInfoBu
|
||||||
}
|
}
|
||||||
|
|
||||||
static void resetAllDataBlockScanInfo(SSHashObj* pTableMap, int64_t ts, int32_t step) {
|
static void resetAllDataBlockScanInfo(SSHashObj* pTableMap, int64_t ts, int32_t step) {
|
||||||
void *p = NULL;
|
void* p = NULL;
|
||||||
int32_t iter = 0;
|
int32_t iter = 0;
|
||||||
|
|
||||||
while ((p = tSimpleHashIterate(pTableMap, p, &iter)) != NULL) {
|
while ((p = tSimpleHashIterate(pTableMap, p, &iter)) != NULL) {
|
||||||
|
@ -505,7 +505,7 @@ static void clearBlockScanInfo(STableBlockScanInfo* p) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static void destroyAllBlockScanInfo(SSHashObj* pTableMap) {
|
static void destroyAllBlockScanInfo(SSHashObj* pTableMap) {
|
||||||
void* p = NULL;
|
void* p = NULL;
|
||||||
int32_t iter = 0;
|
int32_t iter = 0;
|
||||||
|
|
||||||
while ((p = tSimpleHashIterate(pTableMap, p, &iter)) != NULL) {
|
while ((p = tSimpleHashIterate(pTableMap, p, &iter)) != NULL) {
|
||||||
|
@ -743,7 +743,8 @@ void tsdbReleaseDataBlock(STsdbReader* pReader) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t initResBlockInfo(SResultBlockInfo* pResBlockInfo, int64_t capacity, SSDataBlock* pResBlock, SQueryTableDataCond* pCond) {
|
static int32_t initResBlockInfo(SResultBlockInfo* pResBlockInfo, int64_t capacity, SSDataBlock* pResBlock,
|
||||||
|
SQueryTableDataCond* pCond) {
|
||||||
pResBlockInfo->capacity = capacity;
|
pResBlockInfo->capacity = capacity;
|
||||||
pResBlockInfo->pResBlock = pResBlock;
|
pResBlockInfo->pResBlock = pResBlock;
|
||||||
terrno = 0;
|
terrno = 0;
|
||||||
|
@ -921,9 +922,9 @@ static void cleanupTableScanInfo(SReaderStatus* pStatus) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
SSHashObj* pTableMap = pStatus->pTableMap;
|
SSHashObj* pTableMap = pStatus->pTableMap;
|
||||||
STableBlockScanInfo** px = NULL;
|
STableBlockScanInfo** px = NULL;
|
||||||
int32_t iter = 0;
|
int32_t iter = 0;
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
px = tSimpleHashIterate(pTableMap, px, &iter);
|
px = tSimpleHashIterate(pTableMap, px, &iter);
|
||||||
|
@ -937,9 +938,10 @@ static void cleanupTableScanInfo(SReaderStatus* pStatus) {
|
||||||
pStatus->mapDataCleaned = true;
|
pStatus->mapDataCleaned = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t doLoadFileBlock(STsdbReader* pReader, SArray* pIndexList, SBlockNumber* pBlockNum, SArray* pTableScanInfoList) {
|
static int32_t doLoadFileBlock(STsdbReader* pReader, SArray* pIndexList, SBlockNumber* pBlockNum,
|
||||||
size_t sizeInDisk = 0;
|
SArray* pTableScanInfoList) {
|
||||||
size_t numOfTables = taosArrayGetSize(pIndexList);
|
size_t sizeInDisk = 0;
|
||||||
|
size_t numOfTables = taosArrayGetSize(pIndexList);
|
||||||
|
|
||||||
int64_t st = taosGetTimestampUs();
|
int64_t st = taosGetTimestampUs();
|
||||||
cleanupTableScanInfo(&pReader->status);
|
cleanupTableScanInfo(&pReader->status);
|
||||||
|
@ -1125,18 +1127,18 @@ static int32_t getEndPosInDataBlock(STsdbReader* pReader, SBlockData* pBlockData
|
||||||
endPos = doBinarySearchKey(pBlockData->aTSKEY, pBlock->nRow, pos, key, pReader->order);
|
endPos = doBinarySearchKey(pBlockData->aTSKEY, pBlock->nRow, pos, key, pReader->order);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((pReader->verRange.maxVer >= pBlock->minVer && pReader->verRange.maxVer < pBlock->maxVer)||
|
if ((pReader->verRange.maxVer >= pBlock->minVer && pReader->verRange.maxVer < pBlock->maxVer) ||
|
||||||
(pReader->verRange.minVer <= pBlock->maxVer && pReader->verRange.minVer > pBlock->minVer)) {
|
(pReader->verRange.minVer <= pBlock->maxVer && pReader->verRange.minVer > pBlock->minVer)) {
|
||||||
int32_t i = endPos;
|
int32_t i = endPos;
|
||||||
|
|
||||||
if (asc) {
|
if (asc) {
|
||||||
for(; i >= 0; --i) {
|
for (; i >= 0; --i) {
|
||||||
if (pBlockData->aVersion[i] <= pReader->verRange.maxVer) {
|
if (pBlockData->aVersion[i] <= pReader->verRange.maxVer) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for(; i < pBlock->nRow; ++i) {
|
for (; i < pBlock->nRow; ++i) {
|
||||||
if (pBlockData->aVersion[i] >= pReader->verRange.minVer) {
|
if (pBlockData->aVersion[i] >= pReader->verRange.minVer) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -1309,17 +1311,17 @@ static int32_t copyBlockDataToSDataBlock(STsdbReader* pReader) {
|
||||||
ASSERT(pReader->verRange.minVer <= pBlock->maxVer && pReader->verRange.maxVer >= pBlock->minVer);
|
ASSERT(pReader->verRange.minVer <= pBlock->maxVer && pReader->verRange.maxVer >= pBlock->minVer);
|
||||||
|
|
||||||
// find the appropriate start position that satisfies the version requirement.
|
// find the appropriate start position that satisfies the version requirement.
|
||||||
if ((pReader->verRange.maxVer >= pBlock->minVer && pReader->verRange.maxVer < pBlock->maxVer)||
|
if ((pReader->verRange.maxVer >= pBlock->minVer && pReader->verRange.maxVer < pBlock->maxVer) ||
|
||||||
(pReader->verRange.minVer <= pBlock->maxVer && pReader->verRange.minVer > pBlock->minVer)) {
|
(pReader->verRange.minVer <= pBlock->maxVer && pReader->verRange.minVer > pBlock->minVer)) {
|
||||||
int32_t i = pDumpInfo->rowIndex;
|
int32_t i = pDumpInfo->rowIndex;
|
||||||
if (asc) {
|
if (asc) {
|
||||||
for(; i < pBlock->nRow; ++i) {
|
for (; i < pBlock->nRow; ++i) {
|
||||||
if (pBlockData->aVersion[i] >= pReader->verRange.minVer) {
|
if (pBlockData->aVersion[i] >= pReader->verRange.minVer) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for(; i >= 0; --i) {
|
for (; i >= 0; --i) {
|
||||||
if (pBlockData->aVersion[i] <= pReader->verRange.maxVer) {
|
if (pBlockData->aVersion[i] <= pReader->verRange.maxVer) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -1562,7 +1564,8 @@ static int32_t doSetCurrentBlock(SDataBlockIter* pBlockIter, const char* idStr)
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t initBlockIterator(STsdbReader* pReader, SDataBlockIter* pBlockIter, int32_t numOfBlocks, SArray* pTableList) {
|
static int32_t initBlockIterator(STsdbReader* pReader, SDataBlockIter* pBlockIter, int32_t numOfBlocks,
|
||||||
|
SArray* pTableList) {
|
||||||
bool asc = ASCENDING_TRAVERSE(pReader->order);
|
bool asc = ASCENDING_TRAVERSE(pReader->order);
|
||||||
|
|
||||||
SBlockOrderSupporter sup = {0};
|
SBlockOrderSupporter sup = {0};
|
||||||
|
@ -1967,13 +1970,14 @@ static bool nextRowFromLastBlocks(SLastBlockReader* pLastBlockReader, STableBloc
|
||||||
}
|
}
|
||||||
|
|
||||||
TSDBROW* pRow = tMergeTreeGetRow(&pLastBlockReader->mergeTree);
|
TSDBROW* pRow = tMergeTreeGetRow(&pLastBlockReader->mergeTree);
|
||||||
int64_t key = pRow->pBlockData->aTSKEY[pRow->iRow];
|
int64_t key = pRow->pBlockData->aTSKEY[pRow->iRow];
|
||||||
int64_t ver = pRow->pBlockData->aVersion[pRow->iRow];
|
int64_t ver = pRow->pBlockData->aVersion[pRow->iRow];
|
||||||
|
|
||||||
pLastBlockReader->currentKey = key;
|
pLastBlockReader->currentKey = key;
|
||||||
pScanInfo->lastKeyInStt = key;
|
pScanInfo->lastKeyInStt = key;
|
||||||
|
|
||||||
if (!hasBeenDropped(pScanInfo->delSkyline, &pScanInfo->lastBlockDelIndex, key, ver, pLastBlockReader->order, pVerRange)) {
|
if (!hasBeenDropped(pScanInfo->delSkyline, &pScanInfo->lastBlockDelIndex, key, ver, pLastBlockReader->order,
|
||||||
|
pVerRange)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2030,7 +2034,7 @@ static FORCE_INLINE STSchema* doGetSchemaForTSRow(int32_t sversion, STsdbReader*
|
||||||
}
|
}
|
||||||
|
|
||||||
STSchema* ptr = NULL;
|
STSchema* ptr = NULL;
|
||||||
int32_t code = metaGetTbTSchemaEx(pReader->pTsdb->pVnode->pMeta, pReader->suid, uid, sversion, &ptr);
|
int32_t code = metaGetTbTSchemaEx(pReader->pTsdb->pVnode->pMeta, pReader->suid, uid, sversion, &ptr);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
terrno = code;
|
terrno = code;
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -2153,7 +2157,7 @@ static int32_t doMergeBufAndFileRows(STsdbReader* pReader, STableBlockScanInfo*
|
||||||
return terrno;
|
return terrno;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t code = tsdbRowMergerAdd(pMerger, pRow, pSchema);
|
int32_t code = tsdbRowMergerAdd(pMerger, pRow, pSchema);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
@ -2208,7 +2212,7 @@ static int32_t doMergeBufAndFileRows(STsdbReader* pReader, STableBlockScanInfo*
|
||||||
static int32_t doMergeFileBlockAndLastBlock(SLastBlockReader* pLastBlockReader, STsdbReader* pReader,
|
static int32_t doMergeFileBlockAndLastBlock(SLastBlockReader* pLastBlockReader, STsdbReader* pReader,
|
||||||
STableBlockScanInfo* pBlockScanInfo, SBlockData* pBlockData,
|
STableBlockScanInfo* pBlockScanInfo, SBlockData* pBlockData,
|
||||||
bool mergeBlockData) {
|
bool mergeBlockData) {
|
||||||
SRowMerger* pMerger = &pReader->status.merger;
|
SRowMerger* pMerger = &pReader->status.merger;
|
||||||
SFileBlockDumpInfo* pDumpInfo = &pReader->status.fBlockDumpInfo;
|
SFileBlockDumpInfo* pDumpInfo = &pReader->status.fBlockDumpInfo;
|
||||||
|
|
||||||
int64_t tsLastBlock = getCurrentKeyInLastBlock(pLastBlockReader);
|
int64_t tsLastBlock = getCurrentKeyInLastBlock(pLastBlockReader);
|
||||||
|
@ -2218,9 +2222,10 @@ static int32_t doMergeFileBlockAndLastBlock(SLastBlockReader* pLastBlockReader,
|
||||||
TSDBROW* pRow = tMergeTreeGetRow(&pLastBlockReader->mergeTree);
|
TSDBROW* pRow = tMergeTreeGetRow(&pLastBlockReader->mergeTree);
|
||||||
|
|
||||||
// create local variable to hold the row value
|
// create local variable to hold the row value
|
||||||
TSDBROW fRow = {.iRow = pRow->iRow, .type = TSDBROW_COL_FMT, .pBlockData = pRow->pBlockData};
|
TSDBROW fRow = {.iRow = pRow->iRow, .type = TSDBROW_COL_FMT, .pBlockData = pRow->pBlockData};
|
||||||
|
|
||||||
tsdbTrace("fRow ptr:%p, %d, uid:%" PRIu64 ", %s", pRow->pBlockData, pRow->iRow, pLastBlockReader->uid, pReader->idStr);
|
tsdbTrace("fRow ptr:%p, %d, uid:%" PRIu64 ", %s", pRow->pBlockData, pRow->iRow, pLastBlockReader->uid,
|
||||||
|
pReader->idStr);
|
||||||
|
|
||||||
// only last block exists
|
// only last block exists
|
||||||
if ((!mergeBlockData) || (tsLastBlock != pBlockData->aTSKEY[pDumpInfo->rowIndex])) {
|
if ((!mergeBlockData) || (tsLastBlock != pBlockData->aTSKEY[pDumpInfo->rowIndex])) {
|
||||||
|
@ -2240,7 +2245,8 @@ static int32_t doMergeFileBlockAndLastBlock(SLastBlockReader* pLastBlockReader,
|
||||||
|
|
||||||
TSDBROW* pRow1 = tMergeTreeGetRow(&pLastBlockReader->mergeTree);
|
TSDBROW* pRow1 = tMergeTreeGetRow(&pLastBlockReader->mergeTree);
|
||||||
tsdbRowMergerAdd(pMerger, pRow1, NULL);
|
tsdbRowMergerAdd(pMerger, pRow1, NULL);
|
||||||
doMergeRowsInLastBlock(pLastBlockReader, pBlockScanInfo, tsLastBlock, pMerger, &pReader->verRange, pReader->idStr);
|
doMergeRowsInLastBlock(pLastBlockReader, pBlockScanInfo, tsLastBlock, pMerger, &pReader->verRange,
|
||||||
|
pReader->idStr);
|
||||||
|
|
||||||
code = tsdbRowMergerGetRow(pMerger, &pTSRow);
|
code = tsdbRowMergerGetRow(pMerger, &pTSRow);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
|
@ -2290,7 +2296,7 @@ static int32_t doMergeFileBlockAndLastBlock(SLastBlockReader* pLastBlockReader,
|
||||||
static int32_t mergeFileBlockAndLastBlock(STsdbReader* pReader, SLastBlockReader* pLastBlockReader, int64_t key,
|
static int32_t mergeFileBlockAndLastBlock(STsdbReader* pReader, SLastBlockReader* pLastBlockReader, int64_t key,
|
||||||
STableBlockScanInfo* pBlockScanInfo, SBlockData* pBlockData) {
|
STableBlockScanInfo* pBlockScanInfo, SBlockData* pBlockData) {
|
||||||
SFileBlockDumpInfo* pDumpInfo = &pReader->status.fBlockDumpInfo;
|
SFileBlockDumpInfo* pDumpInfo = &pReader->status.fBlockDumpInfo;
|
||||||
SRowMerger* pMerger = &pReader->status.merger;
|
SRowMerger* pMerger = &pReader->status.merger;
|
||||||
|
|
||||||
// merge is not initialized yet, due to the fact that the pReader->pSchema is not initialized
|
// merge is not initialized yet, due to the fact that the pReader->pSchema is not initialized
|
||||||
if (pMerger->pArray == NULL) {
|
if (pMerger->pArray == NULL) {
|
||||||
|
@ -2316,7 +2322,7 @@ static int32_t mergeFileBlockAndLastBlock(STsdbReader* pReader, SLastBlockReader
|
||||||
if (key < ts) { // imem, mem are all empty, file blocks (data blocks and last block) exist
|
if (key < ts) { // imem, mem are all empty, file blocks (data blocks and last block) exist
|
||||||
return mergeRowsInFileBlocks(pBlockData, pBlockScanInfo, key, pReader);
|
return mergeRowsInFileBlocks(pBlockData, pBlockScanInfo, key, pReader);
|
||||||
} else if (key == ts) {
|
} else if (key == ts) {
|
||||||
SRow* pTSRow = NULL;
|
SRow* pTSRow = NULL;
|
||||||
int32_t code = tsdbRowMergerAdd(pMerger, &fRow, pReader->pSchema);
|
int32_t code = tsdbRowMergerAdd(pMerger, &fRow, pReader->pSchema);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
return code;
|
return code;
|
||||||
|
@ -2723,7 +2729,7 @@ int32_t mergeRowsInFileBlocks(SBlockData* pBlockData, STableBlockScanInfo* pBloc
|
||||||
} else {
|
} else {
|
||||||
TSDBROW fRow = tsdbRowFromBlockData(pBlockData, pDumpInfo->rowIndex);
|
TSDBROW fRow = tsdbRowFromBlockData(pBlockData, pDumpInfo->rowIndex);
|
||||||
|
|
||||||
SRow* pTSRow = NULL;
|
SRow* pTSRow = NULL;
|
||||||
code = tsdbRowMergerAdd(pMerger, &fRow, pReader->pSchema);
|
code = tsdbRowMergerAdd(pMerger, &fRow, pReader->pSchema);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
return code;
|
return code;
|
||||||
|
@ -2837,11 +2843,11 @@ static int32_t buildComposedDataBlock(STsdbReader* pReader) {
|
||||||
SFileDataBlockInfo* pBlockInfo = getCurrentBlockInfo(&pReader->status.blockIter);
|
SFileDataBlockInfo* pBlockInfo = getCurrentBlockInfo(&pReader->status.blockIter);
|
||||||
SLastBlockReader* pLastBlockReader = pReader->status.fileIter.pLastBlockReader;
|
SLastBlockReader* pLastBlockReader = pReader->status.fileIter.pLastBlockReader;
|
||||||
|
|
||||||
bool asc = ASCENDING_TRAVERSE(pReader->order);
|
bool asc = ASCENDING_TRAVERSE(pReader->order);
|
||||||
int64_t st = taosGetTimestampUs();
|
int64_t st = taosGetTimestampUs();
|
||||||
int32_t step = asc ? 1 : -1;
|
int32_t step = asc ? 1 : -1;
|
||||||
double el = 0;
|
double el = 0;
|
||||||
SDataBlk* pBlock = getCurrentBlock(&pReader->status.blockIter);
|
SDataBlk* pBlock = getCurrentBlock(&pReader->status.blockIter);
|
||||||
SFileBlockDumpInfo* pDumpInfo = &pReader->status.fBlockDumpInfo;
|
SFileBlockDumpInfo* pDumpInfo = &pReader->status.fBlockDumpInfo;
|
||||||
|
|
||||||
STableBlockScanInfo* pBlockScanInfo = NULL;
|
STableBlockScanInfo* pBlockScanInfo = NULL;
|
||||||
|
@ -2874,7 +2880,8 @@ static int32_t buildComposedDataBlock(STsdbReader* pReader) {
|
||||||
}
|
}
|
||||||
} else { // file blocks not exist
|
} else { // file blocks not exist
|
||||||
pBlockScanInfo = *pReader->status.pTableIter;
|
pBlockScanInfo = *pReader->status.pTableIter;
|
||||||
if (pReader->pIgnoreTables && taosHashGet(*pReader->pIgnoreTables, &pBlockScanInfo->uid, sizeof(pBlockScanInfo->uid))) {
|
if (pReader->pIgnoreTables &&
|
||||||
|
taosHashGet(*pReader->pIgnoreTables, &pBlockScanInfo->uid, sizeof(pBlockScanInfo->uid))) {
|
||||||
setBlockAllDumped(pDumpInfo, pBlock->maxKey.ts, pReader->order);
|
setBlockAllDumped(pDumpInfo, pBlock->maxKey.ts, pReader->order);
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
@ -3238,7 +3245,7 @@ static int32_t doLoadLastBlockSequentially(STsdbReader* pReader) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t doBuildDataBlock(STsdbReader* pReader) {
|
static int32_t doBuildDataBlock(STsdbReader* pReader) {
|
||||||
int32_t code = TSDB_CODE_SUCCESS;
|
int32_t code = TSDB_CODE_SUCCESS;
|
||||||
|
|
||||||
SReaderStatus* pStatus = &pReader->status;
|
SReaderStatus* pStatus = &pReader->status;
|
||||||
SDataBlockIter* pBlockIter = &pStatus->blockIter;
|
SDataBlockIter* pBlockIter = &pStatus->blockIter;
|
||||||
|
@ -3261,7 +3268,6 @@ 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);
|
||||||
|
|
||||||
|
@ -3338,7 +3344,7 @@ static int32_t doBuildDataBlock(STsdbReader* pReader) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return (pReader->code != TSDB_CODE_SUCCESS)? pReader->code:code;
|
return (pReader->code != TSDB_CODE_SUCCESS) ? pReader->code : code;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t doSumFileBlockRows(STsdbReader* pReader, SDataFReader* pFileReader) {
|
static int32_t doSumFileBlockRows(STsdbReader* pReader, SDataFReader* pFileReader) {
|
||||||
|
@ -3493,14 +3499,15 @@ static int32_t buildBlockFromBufferSequentially(STsdbReader* pReader) {
|
||||||
}
|
}
|
||||||
|
|
||||||
STableBlockScanInfo** pBlockScanInfo = pStatus->pTableIter;
|
STableBlockScanInfo** pBlockScanInfo = pStatus->pTableIter;
|
||||||
if (pReader->pIgnoreTables && taosHashGet(*pReader->pIgnoreTables, &(*pBlockScanInfo)->uid, sizeof((*pBlockScanInfo)->uid))) {
|
if (pReader->pIgnoreTables &&
|
||||||
|
taosHashGet(*pReader->pIgnoreTables, &(*pBlockScanInfo)->uid, sizeof((*pBlockScanInfo)->uid))) {
|
||||||
bool hasNexTable = moveToNextTable(pUidList, pStatus);
|
bool hasNexTable = moveToNextTable(pUidList, pStatus);
|
||||||
if (!hasNexTable) {
|
if (!hasNexTable) {
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
pBlockScanInfo = pStatus->pTableIter;
|
pBlockScanInfo = pStatus->pTableIter;
|
||||||
}
|
}
|
||||||
|
|
||||||
initMemDataIterator(*pBlockScanInfo, pReader);
|
initMemDataIterator(*pBlockScanInfo, pReader);
|
||||||
|
|
||||||
int64_t endKey = (ASCENDING_TRAVERSE(pReader->order)) ? INT64_MAX : INT64_MIN;
|
int64_t endKey = (ASCENDING_TRAVERSE(pReader->order)) ? INT64_MAX : INT64_MIN;
|
||||||
|
@ -3544,7 +3551,7 @@ static void initBlockDumpInfo(STsdbReader* pReader, SDataBlockIter* pBlockIter)
|
||||||
|
|
||||||
static int32_t initForFirstBlockInFile(STsdbReader* pReader, SDataBlockIter* pBlockIter) {
|
static int32_t initForFirstBlockInFile(STsdbReader* pReader, SDataBlockIter* pBlockIter) {
|
||||||
SBlockNumber num = {0};
|
SBlockNumber num = {0};
|
||||||
SArray* pTableList = taosArrayInit(40, POINTER_BYTES);
|
SArray* pTableList = taosArrayInit(40, POINTER_BYTES);
|
||||||
|
|
||||||
int32_t code = moveToNextFile(pReader, &num, pTableList);
|
int32_t code = moveToNextFile(pReader, &num, pTableList);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
|
@ -3589,7 +3596,7 @@ static ERetrieveType doReadDataFromLastFiles(STsdbReader* pReader) {
|
||||||
SSDataBlock* pResBlock = pReader->resBlockInfo.pResBlock;
|
SSDataBlock* pResBlock = pReader->resBlockInfo.pResBlock;
|
||||||
SDataBlockIter* pBlockIter = &pReader->status.blockIter;
|
SDataBlockIter* pBlockIter = &pReader->status.blockIter;
|
||||||
|
|
||||||
while(1) {
|
while (1) {
|
||||||
terrno = 0;
|
terrno = 0;
|
||||||
|
|
||||||
code = doLoadLastBlockSequentially(pReader);
|
code = doLoadLastBlockSequentially(pReader);
|
||||||
|
@ -3612,7 +3619,7 @@ static ERetrieveType doReadDataFromLastFiles(STsdbReader* pReader) {
|
||||||
return TSDB_READ_RETURN;
|
return TSDB_READ_RETURN;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pBlockIter->numOfBlocks > 0) { // there are data blocks existed.
|
if (pBlockIter->numOfBlocks > 0) { // there are data blocks existed.
|
||||||
return TSDB_READ_CONTINUE;
|
return TSDB_READ_CONTINUE;
|
||||||
} else { // all blocks in data file are checked, let's check the data in last files
|
} else { // all blocks in data file are checked, let's check the data in last files
|
||||||
resetTableListIndex(&pReader->status);
|
resetTableListIndex(&pReader->status);
|
||||||
|
@ -3625,7 +3632,7 @@ static int32_t buildBlockFromFiles(STsdbReader* pReader) {
|
||||||
bool asc = ASCENDING_TRAVERSE(pReader->order);
|
bool asc = ASCENDING_TRAVERSE(pReader->order);
|
||||||
|
|
||||||
SDataBlockIter* pBlockIter = &pReader->status.blockIter;
|
SDataBlockIter* pBlockIter = &pReader->status.blockIter;
|
||||||
SSDataBlock* pResBlock = pReader->resBlockInfo.pResBlock;
|
SSDataBlock* pResBlock = pReader->resBlockInfo.pResBlock;
|
||||||
|
|
||||||
if (pBlockIter->numOfBlocks == 0) {
|
if (pBlockIter->numOfBlocks == 0) {
|
||||||
// let's try to extract data from stt files.
|
// let's try to extract data from stt files.
|
||||||
|
@ -3737,13 +3744,14 @@ SVersionRange getQueryVerRange(SVnode* pVnode, SQueryTableDataCond* pCond, const
|
||||||
endVer = (pCond->endVersion > pVnode->state.applied) ? pVnode->state.applied : pCond->endVersion;
|
endVer = (pCond->endVersion > pVnode->state.applied) ? pVnode->state.applied : pCond->endVersion;
|
||||||
}
|
}
|
||||||
|
|
||||||
tsdbDebug("queried verRange:%"PRId64"-%"PRId64", revised query verRange:%"PRId64"-%"PRId64", %s", pCond->startVersion,
|
tsdbDebug("queried verRange:%" PRId64 "-%" PRId64 ", revised query verRange:%" PRId64 "-%" PRId64 ", %s",
|
||||||
pCond->endVersion, startVer, endVer, id);
|
pCond->startVersion, pCond->endVersion, startVer, endVer, id);
|
||||||
|
|
||||||
return (SVersionRange){.minVer = startVer, .maxVer = endVer};
|
return (SVersionRange){.minVer = startVer, .maxVer = endVer};
|
||||||
}
|
}
|
||||||
|
|
||||||
bool hasBeenDropped(const SArray* pDelList, int32_t* index, int64_t key, int64_t ver, int32_t order, SVersionRange* pVerRange) {
|
bool hasBeenDropped(const SArray* pDelList, int32_t* index, int64_t key, int64_t ver, int32_t order,
|
||||||
|
SVersionRange* pVerRange) {
|
||||||
if (pDelList == NULL) {
|
if (pDelList == NULL) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -3761,8 +3769,7 @@ bool hasBeenDropped(const SArray* pDelList, int32_t* index, int64_t key, int64_t
|
||||||
return false;
|
return false;
|
||||||
} else if (key == last->ts) {
|
} else if (key == last->ts) {
|
||||||
TSDBKEY* prev = taosArrayGet(pDelList, num - 2);
|
TSDBKEY* prev = taosArrayGet(pDelList, num - 2);
|
||||||
return (prev->version >= ver && prev->version <= pVerRange->maxVer &&
|
return (prev->version >= ver && prev->version <= pVerRange->maxVer && prev->version >= pVerRange->minVer);
|
||||||
prev->version >= pVerRange->minVer);
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
TSDBKEY* pCurrent = taosArrayGet(pDelList, *index);
|
TSDBKEY* pCurrent = taosArrayGet(pDelList, *index);
|
||||||
|
@ -3971,9 +3978,9 @@ int32_t doMergeRowsInFileBlocks(SBlockData* pBlockData, STableBlockScanInfo* pSc
|
||||||
SFileBlockDumpInfo* pDumpInfo = &pReader->status.fBlockDumpInfo;
|
SFileBlockDumpInfo* pDumpInfo = &pReader->status.fBlockDumpInfo;
|
||||||
|
|
||||||
SRowMerger* pMerger = &pReader->status.merger;
|
SRowMerger* pMerger = &pReader->status.merger;
|
||||||
bool asc = ASCENDING_TRAVERSE(pReader->order);
|
bool asc = ASCENDING_TRAVERSE(pReader->order);
|
||||||
int64_t key = pBlockData->aTSKEY[pDumpInfo->rowIndex];
|
int64_t key = pBlockData->aTSKEY[pDumpInfo->rowIndex];
|
||||||
int32_t step = asc ? 1 : -1;
|
int32_t step = asc ? 1 : -1;
|
||||||
|
|
||||||
pDumpInfo->rowIndex += step;
|
pDumpInfo->rowIndex += step;
|
||||||
if ((pDumpInfo->rowIndex <= pBlockData->nRow - 1 && asc) || (pDumpInfo->rowIndex >= 0 && !asc)) {
|
if ((pDumpInfo->rowIndex <= pBlockData->nRow - 1 && asc) || (pDumpInfo->rowIndex >= 0 && !asc)) {
|
||||||
|
@ -4070,14 +4077,14 @@ int32_t doMergeMemTableMultiRows(TSDBROW* pRow, uint64_t uid, SIterInfo* pIter,
|
||||||
return terrno;
|
return terrno;
|
||||||
}
|
}
|
||||||
|
|
||||||
tsdbRowMergerAdd(&pReader->status.merger,pNextRow, pTSchema1);
|
tsdbRowMergerAdd(&pReader->status.merger, pNextRow, pTSchema1);
|
||||||
} else { // let's merge rows in file block
|
} else { // let's merge rows in file block
|
||||||
code = tsdbRowMergerAdd(&pReader->status.merger, ¤t, pReader->pSchema);
|
code = tsdbRowMergerAdd(&pReader->status.merger, ¤t, pReader->pSchema);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
tsdbRowMergerAdd(&pReader->status.merger,pNextRow, NULL);
|
tsdbRowMergerAdd(&pReader->status.merger, pNextRow, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
code = doMergeRowsInBuf(pIter, uid, TSDBROW_TS(¤t), pDelList, pReader);
|
code = doMergeRowsInBuf(pIter, uid, TSDBROW_TS(¤t), pDelList, pReader);
|
||||||
|
@ -4124,9 +4131,8 @@ int32_t doMergeMemIMemRows(TSDBROW* pRow, TSDBROW* piRow, STableBlockScanInfo* p
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
tsdbRowMergerAdd(&pReader->status.merger,pRow, pSchema);
|
tsdbRowMergerAdd(&pReader->status.merger, pRow, pSchema);
|
||||||
code =
|
code = doMergeRowsInBuf(&pBlockScanInfo->iter, pBlockScanInfo->uid, k.ts, pBlockScanInfo->delSkyline, pReader);
|
||||||
doMergeRowsInBuf(&pBlockScanInfo->iter, pBlockScanInfo->uid, k.ts, pBlockScanInfo->delSkyline, pReader);
|
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
@ -4365,7 +4371,7 @@ int32_t tsdbSetTableList(STsdbReader* pReader, const void* pTableList, int32_t n
|
||||||
int32_t size = tSimpleHashGetSize(pReader->status.pTableMap);
|
int32_t size = tSimpleHashGetSize(pReader->status.pTableMap);
|
||||||
|
|
||||||
STableBlockScanInfo** p = NULL;
|
STableBlockScanInfo** p = NULL;
|
||||||
int32_t iter = 0;
|
int32_t iter = 0;
|
||||||
|
|
||||||
while ((p = tSimpleHashIterate(pReader->status.pTableMap, p, &iter)) != NULL) {
|
while ((p = tSimpleHashIterate(pReader->status.pTableMap, p, &iter)) != NULL) {
|
||||||
clearBlockScanInfo(*p);
|
clearBlockScanInfo(*p);
|
||||||
|
@ -4452,15 +4458,16 @@ static int32_t doOpenReaderImpl(STsdbReader* pReader) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static void freeSchemaFunc(void* param) {
|
static void freeSchemaFunc(void* param) {
|
||||||
void **p = (void **)param;
|
void** p = (void**)param;
|
||||||
taosMemoryFreeClear(*p);
|
taosMemoryFreeClear(*p);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ====================================== EXPOSED APIs ======================================
|
// ====================================== EXPOSED APIs ======================================
|
||||||
int32_t tsdbReaderOpen(void* pVnode, SQueryTableDataCond* pCond, void* pTableList, int32_t numOfTables,
|
int32_t tsdbReaderOpen(void* pVnode, SQueryTableDataCond* pCond, void* pTableList, int32_t numOfTables,
|
||||||
SSDataBlock* pResBlock, void** ppReader, const char* idstr, bool countOnly, SHashObj** pIgnoreTables) {
|
SSDataBlock* pResBlock, void** ppReader, const char* idstr, bool countOnly,
|
||||||
|
SHashObj** pIgnoreTables) {
|
||||||
STimeWindow window = pCond->twindows;
|
STimeWindow window = pCond->twindows;
|
||||||
SVnodeCfg* pConf = &(((SVnode*)pVnode)->config);
|
SVnodeCfg* pConf = &(((SVnode*)pVnode)->config);
|
||||||
|
|
||||||
int32_t capacity = pConf->tsdbCfg.maxRows;
|
int32_t capacity = pConf->tsdbCfg.maxRows;
|
||||||
if (pResBlock != NULL) {
|
if (pResBlock != NULL) {
|
||||||
|
@ -4729,7 +4736,7 @@ int32_t tsdbReaderSuspend(STsdbReader* pReader) {
|
||||||
|
|
||||||
// resetDataBlockScanInfo excluding lastKey
|
// resetDataBlockScanInfo excluding lastKey
|
||||||
STableBlockScanInfo** p = NULL;
|
STableBlockScanInfo** p = NULL;
|
||||||
int32_t iter = 0;
|
int32_t iter = 0;
|
||||||
|
|
||||||
while ((p = tSimpleHashIterate(pStatus->pTableMap, p, &iter)) != NULL) {
|
while ((p = tSimpleHashIterate(pStatus->pTableMap, p, &iter)) != NULL) {
|
||||||
STableBlockScanInfo* pInfo = *(STableBlockScanInfo**)p;
|
STableBlockScanInfo* pInfo = *(STableBlockScanInfo**)p;
|
||||||
|
@ -4751,7 +4758,7 @@ int32_t tsdbReaderSuspend(STsdbReader* pReader) {
|
||||||
} else {
|
} else {
|
||||||
// resetDataBlockScanInfo excluding lastKey
|
// resetDataBlockScanInfo excluding lastKey
|
||||||
STableBlockScanInfo** p = NULL;
|
STableBlockScanInfo** p = NULL;
|
||||||
int32_t iter = 0;
|
int32_t iter = 0;
|
||||||
|
|
||||||
while ((p = tSimpleHashIterate(pStatus->pTableMap, p, &iter)) != NULL) {
|
while ((p = tSimpleHashIterate(pStatus->pTableMap, p, &iter)) != NULL) {
|
||||||
STableBlockScanInfo* pInfo = *(STableBlockScanInfo**)p;
|
STableBlockScanInfo* pInfo = *(STableBlockScanInfo**)p;
|
||||||
|
@ -4950,8 +4957,9 @@ int32_t tsdbNextDataBlock(STsdbReader* pReader, bool* hasNext) {
|
||||||
|
|
||||||
*hasNext = false;
|
*hasNext = false;
|
||||||
|
|
||||||
if (isEmptyQueryTimeWindow(&pReader->window) || pReader->step == EXTERNAL_ROWS_NEXT || pReader->code != TSDB_CODE_SUCCESS) {
|
if (isEmptyQueryTimeWindow(&pReader->window) || pReader->step == EXTERNAL_ROWS_NEXT ||
|
||||||
return (pReader->code != TSDB_CODE_SUCCESS)? pReader->code:code;
|
pReader->code != TSDB_CODE_SUCCESS) {
|
||||||
|
return (pReader->code != TSDB_CODE_SUCCESS) ? pReader->code : code;
|
||||||
}
|
}
|
||||||
|
|
||||||
SReaderStatus* pStatus = &pReader->status;
|
SReaderStatus* pStatus = &pReader->status;
|
||||||
|
@ -5087,7 +5095,7 @@ static bool doFillNullColSMA(SBlockLoadSuppInfo* pSup, int32_t numOfRows, int32_
|
||||||
return hasNullSMA;
|
return hasNullSMA;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t tsdbRetrieveDatablockSMA(STsdbReader* pReader, SSDataBlock* pDataBlock, bool* allHave, bool *hasNullSMA) {
|
int32_t tsdbRetrieveDatablockSMA(STsdbReader* pReader, SSDataBlock* pDataBlock, bool* allHave, bool* hasNullSMA) {
|
||||||
SColumnDataAgg*** pBlockSMA = &pDataBlock->pBlockAgg;
|
SColumnDataAgg*** pBlockSMA = &pDataBlock->pBlockAgg;
|
||||||
|
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
|
@ -5196,9 +5204,9 @@ STableBlockScanInfo* getTableBlockScanInfo(SSHashObj* pTableMap, uint64_t uid, c
|
||||||
}
|
}
|
||||||
|
|
||||||
static SSDataBlock* doRetrieveDataBlock(STsdbReader* pReader) {
|
static SSDataBlock* doRetrieveDataBlock(STsdbReader* pReader) {
|
||||||
SReaderStatus* pStatus = &pReader->status;
|
SReaderStatus* pStatus = &pReader->status;
|
||||||
int32_t code = TSDB_CODE_SUCCESS;
|
int32_t code = TSDB_CODE_SUCCESS;
|
||||||
SFileDataBlockInfo* pBlockInfo = getCurrentBlockInfo(&pStatus->blockIter);
|
SFileDataBlockInfo* pBlockInfo = getCurrentBlockInfo(&pStatus->blockIter);
|
||||||
|
|
||||||
if (pReader->code != TSDB_CODE_SUCCESS) {
|
if (pReader->code != TSDB_CODE_SUCCESS) {
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
|
@ -30,11 +30,6 @@ typedef enum {
|
||||||
READER_STATUS_NORMAL = 0x2,
|
READER_STATUS_NORMAL = 0x2,
|
||||||
} EReaderStatus;
|
} EReaderStatus;
|
||||||
|
|
||||||
typedef enum {
|
|
||||||
READ_MODE_COUNT_ONLY = 0x1,
|
|
||||||
READ_MODE_ALL,
|
|
||||||
} EReadMode;
|
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
EXTERNAL_ROWS_PREV = 0x1,
|
EXTERNAL_ROWS_PREV = 0x1,
|
||||||
EXTERNAL_ROWS_MAIN = 0x2,
|
EXTERNAL_ROWS_MAIN = 0x2,
|
||||||
|
@ -69,16 +64,6 @@ typedef struct STableBlockScanInfo {
|
||||||
bool iterInit; // whether to initialize the in-memory skip list iterator or not
|
bool iterInit; // whether to initialize the in-memory skip list iterator or not
|
||||||
} STableBlockScanInfo;
|
} STableBlockScanInfo;
|
||||||
|
|
||||||
typedef struct STsdbReaderInfo {
|
|
||||||
uint64_t suid;
|
|
||||||
STSchema* pSchema;
|
|
||||||
EReadMode readMode;
|
|
||||||
uint64_t rowsNum;
|
|
||||||
STimeWindow window;
|
|
||||||
SVersionRange verRange;
|
|
||||||
int16_t order;
|
|
||||||
} STsdbReaderInfo;
|
|
||||||
|
|
||||||
typedef struct SResultBlockInfo {
|
typedef struct SResultBlockInfo {
|
||||||
SSDataBlock* pResBlock;
|
SSDataBlock* pResBlock;
|
||||||
bool freeBlock;
|
bool freeBlock;
|
||||||
|
|
Loading…
Reference in New Issue