提交 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);
} }
}
// pStatus->mapDataCleaned = true; 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;
}
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,95 +1021,79 @@ static int32_t doLoadFileBlock(STsdbReader* pReader, SArray* pIndexList, SBlockN ...@@ -982,95 +1021,79 @@ 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];
SBrinBlock block = {0}; SBrinRecordIter iter = {0};
tsdbDataFileReadBrinBlock(pReader->pFileReader, pBlk, &block); initBrinRecordIter(&iter, pReader->pFileReader, pIndexList);
SBrinRecord* pRecord = NULL;
// tMapDataReset(&pScanInfo->mapData); while (k < numOfTables) {
// tsdbReadDataBlk(pReader->pFileReader, pBlockIdx, &pScanInfo->mapData); pRecord = getNextBrinRecord(&iter);
// taosArrayEnsureCap(pScanInfo->pBlockList, pScanInfo->mapData.nItem);
// todo set the correct size uint64_t uid = pReader->status.uidList.tableUidList[k];
sizeInDisk += 0;//pScanInfo->mapData.nData; if (pRecord == NULL || pRecord->suid > pReader->suid) {
break;
}
int32_t step = ASCENDING_TRAVERSE(pReader->order) ? 1 : -1; if (pRecord->suid < pReader->suid) {
STimeWindow w = pReader->window;
if (isEmptyQueryTimeWindow(&w)) {
continue; continue;
} }
STableBlockScanInfo* pScanInfo = getTableBlockScanInfo(pReader->status.pTableMap, uid, pReader->idStr); ASSERT(pRecord->suid == pReader->suid);
if (ASCENDING_TRAVERSE(pReader->order)) { if (pRecord->uid < uid) {
w.skey = pScanInfo->lastKey + step; continue;
} else {
w.ekey = pScanInfo->lastKey + step;
} }
SBrinRecord record = {0}; while (pRecord->uid > uid && k < numOfTables) {
for (int32_t j = 0; j < TARRAY2_SIZE(block.numRow); ++j) { k += 1;
tBrinBlockGet(&block, j, &record);
if (record.suid < pReader->suid) {
continue;
} }
if (record.suid > pReader->suid) { if (k >= numOfTables) {
break; break;
} }
{ ASSERT(pRecord->suid == pReader->suid && uid == pRecord->uid);
while (record.uid > uid && (k + 1) < numOfTables) {
k += 1;
uid = pReader->status.uidList.tableUidList[k];
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;
} else { } else {
w.ekey = pScanInfo->lastKey + step; w.ekey = pScanInfo->lastKey + step;
} }
}
if (k >= numOfTables) { if (isEmptyQueryTimeWindow(&w)) {
break; k += 1;
}
if (record.uid < uid) {
continue; continue;
} }
}
ASSERT(record.suid == pReader->suid);
// 1. time range check // 1. time range check
if (record.firstKey > w.ekey || record.lastKey < w.skey) { if (pRecord->firstKey > w.ekey || pRecord->lastKey < w.skey) {
continue; continue;
} }
// 2. version range check // 2. version range check
if (record.firstKeyVer > pReader->verRange.maxVer || record.lastKeyVer < pReader->verRange.minVer) { if (pRecord->firstKeyVer > pReader->verRange.maxVer || pRecord->lastKeyVer < pReader->verRange.minVer) {
continue; continue;
} }
// SBlockIndex bIndex = {.ordinalIndex = j, .inFileOffset = record.blockOffset}; void* p1 = taosArrayPush(pScanInfo->pBlockList, pRecord);
// bIndex.window = (STimeWindow){.skey = record.firstKey, .ekey = record.lastKey};
void* p1 = taosArrayPush(pScanInfo->pBlockList, &record);
if (p1 == NULL) { if (p1 == NULL) {
return TSDB_CODE_OUT_OF_MEMORY; return TSDB_CODE_OUT_OF_MEMORY;
} }
pBlockNum->numOfBlocks += 1; pBlockNum->numOfBlocks += 1;
} if (taosArrayGetSize(pTableScanInfoList) == 0) {
taosArrayPush(pTableScanInfoList, &pScanInfo);
i += 1; } else {
STableBlockScanInfo** p = taosArrayGetLast(pTableScanInfoList); STableBlockScanInfo** p = taosArrayGetLast(pTableScanInfoList);
if ((p == NULL || (*p)->uid != uid) && taosArrayGetSize(pScanInfo->pBlockList) > 0) { if ((*p)->uid != uid) {
taosArrayPush(pTableScanInfoList, &pScanInfo); 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.
先完成此消息的编辑!
想要评论请 注册