提交 e76ae4ff 编写于 作者: H Haojun Liao

fix(tsdb) : fix memory leak.

上级 84bd2fb7
...@@ -967,14 +967,53 @@ static void cleanupTableScanInfo(SReaderStatus* pStatus) { ...@@ -967,14 +967,53 @@ static void cleanupTableScanInfo(SReaderStatus* pStatus) {
doCleanupTableScanInfo(*px); doCleanupTableScanInfo(*px);
} }
}
typedef struct SBrinRecordIter {
SArray* pBrinBlockList;
SBrinBlk* pCurrentBlk;
int32_t blockIndex;
int32_t recordIndex;
SDataFileReader* pReader;
SBrinBlock block;
SBrinRecord record;
} SBrinRecordIter;
void initBrinRecordIter(SBrinRecordIter* pIter, SDataFileReader* pReader, SArray* pList) {
memset(&pIter->block, 0, sizeof(SBrinBlock));
memset(&pIter->record, 0, sizeof(SBrinRecord));
pIter->blockIndex = -1;
pIter->recordIndex = -1;
pIter->pReader = pReader;
pIter->pBrinBlockList = pList;
}
SBrinRecord* getNextBrinRecord(SBrinRecordIter* pIter) {
if (pIter->blockIndex == -1 || (pIter->recordIndex + 1) >= TARRAY2_SIZE(pIter->block.numRow)) {
pIter->blockIndex += 1;
if (pIter->blockIndex >= taosArrayGetSize(pIter->pBrinBlockList)) {
return NULL;
}
pIter->pCurrentBlk = taosArrayGet(pIter->pBrinBlockList, pIter->blockIndex);
tBrinBlockClear(&pIter->block);
tsdbDataFileReadBrinBlock(pIter->pReader, pIter->pCurrentBlk, &pIter->block);
pIter->recordIndex = -1;
}
// pStatus->mapDataCleaned = true; pIter->recordIndex += 1;
tBrinBlockGet(&pIter->block, pIter->recordIndex, &pIter->record);
return &pIter->record;
}
void clearBrinBlockIter(SBrinRecordIter* pIter) {
tBrinBlockDestroy(&pIter->block);
} }
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 numOfBlocks = taosArrayGetSize(pIndexList);
int64_t st = taosGetTimestampUs(); int64_t st = taosGetTimestampUs();
cleanupTableScanInfo(&pReader->status); cleanupTableScanInfo(&pReader->status);
...@@ -982,26 +1021,40 @@ static int32_t doLoadFileBlock(STsdbReader* pReader, SArray* pIndexList, SBlockN ...@@ -982,26 +1021,40 @@ static int32_t doLoadFileBlock(STsdbReader* pReader, SArray* pIndexList, SBlockN
int32_t i = 0, k = 0; int32_t i = 0, k = 0;
int32_t numOfTables = tSimpleHashGetSize(pReader->status.pTableMap); int32_t numOfTables = tSimpleHashGetSize(pReader->status.pTableMap);
while(i < numOfBlocks && k < numOfTables) { int32_t step = ASCENDING_TRAVERSE(pReader->order) ? 1 : -1;
SBrinBlk* pBlk = taosArrayGet(pIndexList, i); STimeWindow w = pReader->window;
uint64_t uid = pReader->status.uidList.tableUidList[k];
SBrinRecordIter iter = {0};
initBrinRecordIter(&iter, pReader->pFileReader, pIndexList);
SBrinRecord* pRecord = NULL;
SBrinBlock block = {0}; while (k < numOfTables) {
tsdbDataFileReadBrinBlock(pReader->pFileReader, pBlk, &block); pRecord = getNextBrinRecord(&iter);
// tMapDataReset(&pScanInfo->mapData); uint64_t uid = pReader->status.uidList.tableUidList[k];
// tsdbReadDataBlk(pReader->pFileReader, pBlockIdx, &pScanInfo->mapData); if (pRecord == NULL || pRecord->suid > pReader->suid) {
// taosArrayEnsureCap(pScanInfo->pBlockList, pScanInfo->mapData.nItem); break;
}
// todo set the correct size if (pRecord->suid < pReader->suid) {
sizeInDisk += 0;//pScanInfo->mapData.nData; continue;
}
int32_t step = ASCENDING_TRAVERSE(pReader->order) ? 1 : -1; ASSERT(pRecord->suid == pReader->suid);
STimeWindow w = pReader->window; if (pRecord->uid < uid) {
if (isEmptyQueryTimeWindow(&w)) {
continue; continue;
} }
while (pRecord->uid > uid && k < numOfTables) {
k += 1;
}
if (k >= numOfTables) {
break;
}
ASSERT(pRecord->suid == pReader->suid && uid == pRecord->uid);
STableBlockScanInfo* pScanInfo = getTableBlockScanInfo(pReader->status.pTableMap, uid, pReader->idStr); 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;
...@@ -1009,69 +1062,39 @@ static int32_t doLoadFileBlock(STsdbReader* pReader, SArray* pIndexList, SBlockN ...@@ -1009,69 +1062,39 @@ static int32_t doLoadFileBlock(STsdbReader* pReader, SArray* pIndexList, SBlockN
w.ekey = pScanInfo->lastKey + step; w.ekey = pScanInfo->lastKey + step;
} }
SBrinRecord record = {0}; if (isEmptyQueryTimeWindow(&w)) {
for (int32_t j = 0; j < TARRAY2_SIZE(block.numRow); ++j) { k += 1;
tBrinBlockGet(&block, j, &record); continue;
if (record.suid < pReader->suid) { }
continue;
}
if (record.suid > pReader->suid) {
break;
}
{
while (record.uid > uid && (k + 1) < numOfTables) {
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 (k >= numOfTables) {
break;
}
if (record.uid < uid) {
continue;
}
}
ASSERT(record.suid == pReader->suid);
// 1. time range check
if (record.firstKey > w.ekey || record.lastKey < w.skey) {
continue;
}
// 2. version range check
if (record.firstKeyVer > pReader->verRange.maxVer || record.lastKeyVer < pReader->verRange.minVer) {
continue;
}
// SBlockIndex bIndex = {.ordinalIndex = j, .inFileOffset = record.blockOffset}; // 1. time range check
// bIndex.window = (STimeWindow){.skey = record.firstKey, .ekey = record.lastKey}; if (pRecord->firstKey > w.ekey || pRecord->lastKey < w.skey) {
void* p1 = taosArrayPush(pScanInfo->pBlockList, &record); continue;
if (p1 == NULL) { }
return TSDB_CODE_OUT_OF_MEMORY;
}
pBlockNum->numOfBlocks += 1; // 2. version range check
if (pRecord->firstKeyVer > pReader->verRange.maxVer || pRecord->lastKeyVer < pReader->verRange.minVer) {
continue;
} }
i += 1; void* p1 = taosArrayPush(pScanInfo->pBlockList, pRecord);
if (p1 == NULL) {
return TSDB_CODE_OUT_OF_MEMORY;
}
STableBlockScanInfo** p = taosArrayGetLast(pTableScanInfoList); pBlockNum->numOfBlocks += 1;
if ((p == NULL || (*p)->uid != uid) && taosArrayGetSize(pScanInfo->pBlockList) > 0) { if (taosArrayGetSize(pTableScanInfoList) == 0) {
taosArrayPush(pTableScanInfoList, &pScanInfo); taosArrayPush(pTableScanInfoList, &pScanInfo);
} else {
STableBlockScanInfo** p = taosArrayGetLast(pTableScanInfoList);
if ((*p)->uid != uid) {
taosArrayPush(pTableScanInfoList, &pScanInfo);
}
} }
} }
clearBrinBlockIter(&iter);
pBlockNum->numOfLastFiles = pReader->status.pCurrentFileset->lvlArr->size; pBlockNum->numOfLastFiles = pReader->status.pCurrentFileset->lvlArr->size;
int32_t total = pBlockNum->numOfLastFiles + pBlockNum->numOfBlocks; int32_t total = pBlockNum->numOfLastFiles + pBlockNum->numOfBlocks;
...@@ -1336,7 +1359,6 @@ static int32_t copyBlockDataToSDataBlock(STsdbReader* pReader) { ...@@ -1336,7 +1359,6 @@ 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);
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;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册