more code
This commit is contained in:
parent
573a419183
commit
478d5ebb64
|
@ -262,7 +262,7 @@ int32_t tsdbDataFReaderOpen(SDataFReader **ppReader, STsdb *pTsdb, SDFileSet *pS
|
|||
int32_t tsdbDataFReaderClose(SDataFReader **ppReader);
|
||||
int32_t tsdbReadBlockIdx(SDataFReader *pReader, SArray *aBlockIdx);
|
||||
int32_t tsdbReadBlock(SDataFReader *pReader, SBlockIdx *pBlockIdx, SMapData *pMapData);
|
||||
int32_t tsdbReadBlockL(SDataFReader *pReader, SArray *aBlockL);
|
||||
int32_t tsdbReadBlockL(SDataFReader *pReader, int32_t iLast, SArray *aBlockL);
|
||||
int32_t tsdbReadBlockSma(SDataFReader *pReader, SBlock *pBlock, SArray *aColumnDataAgg);
|
||||
int32_t tsdbReadDataBlock(SDataFReader *pReader, SBlock *pBlock, SBlockData *pBlockData);
|
||||
int32_t tsdbReadLastBlock(SDataFReader *pReader, SBlockL *pBlockL, SBlockData *pBlockData);
|
||||
|
|
|
@ -481,7 +481,7 @@ static int32_t getNextRowFromFSLast(void *iter, TSDBROW **ppRow) {
|
|||
taosArrayClear(state->aBlockL);
|
||||
}
|
||||
|
||||
code = tsdbReadBlockL(state->pDataFReader, state->aBlockL);
|
||||
code = tsdbReadBlockL(state->pDataFReader, 0, state->aBlockL);
|
||||
if (code) goto _err;
|
||||
|
||||
// SBlockL *pBlockL = (SBlockL *)taosArrayGet(state->aBlockL, state->iBlockL);
|
||||
|
|
|
@ -35,6 +35,7 @@ typedef struct {
|
|||
int32_t minRow;
|
||||
int32_t maxRow;
|
||||
int8_t cmprAlg;
|
||||
int8_t maxLast;
|
||||
SArray *aTbDataP; // memory
|
||||
STsdbFS fs; // disk
|
||||
// --------------
|
||||
|
@ -45,19 +46,11 @@ typedef struct {
|
|||
// commit file data
|
||||
struct {
|
||||
SDataFReader *pReader;
|
||||
// data
|
||||
SArray *aBlockIdx; // SArray<SBlockIdx>
|
||||
int32_t iBlockIdx;
|
||||
SBlockIdx *pBlockIdx;
|
||||
SMapData mBlock; // SMapData<SBlock>
|
||||
SBlockData bData;
|
||||
// last
|
||||
SArray *aBlockL; // SArray<SBlockL>
|
||||
int32_t iBlockL;
|
||||
SBlockData bDatal;
|
||||
int32_t iRow;
|
||||
SRowInfo *pRowInfo;
|
||||
SRowInfo rowInfo;
|
||||
} dReader;
|
||||
struct {
|
||||
SDataFWriter *pWriter;
|
||||
|
@ -437,20 +430,8 @@ static int32_t tsdbCommitFileDataStart(SCommitter *pCommitter) {
|
|||
pCommitter->dReader.pBlockIdx = NULL;
|
||||
}
|
||||
tBlockDataReset(&pCommitter->dReader.bData);
|
||||
|
||||
// last
|
||||
code = tsdbReadBlockL(pCommitter->dReader.pReader, pCommitter->dReader.aBlockL);
|
||||
if (code) goto _err;
|
||||
|
||||
pCommitter->dReader.iBlockL = -1;
|
||||
pCommitter->dReader.iRow = -1;
|
||||
pCommitter->dReader.pRowInfo = &pCommitter->dReader.rowInfo;
|
||||
tBlockDataReset(&pCommitter->dReader.bDatal);
|
||||
code = tsdbCommitterNextLastRow(pCommitter);
|
||||
if (code) goto _err;
|
||||
} else {
|
||||
pCommitter->dReader.pBlockIdx = NULL;
|
||||
pCommitter->dReader.pRowInfo = NULL;
|
||||
}
|
||||
|
||||
// Writer
|
||||
|
@ -1273,6 +1254,7 @@ static int32_t tsdbStartCommit(STsdb *pTsdb, SCommitter *pCommitter) {
|
|||
pCommitter->minRow = pTsdb->pVnode->config.tsdbCfg.minRows;
|
||||
pCommitter->maxRow = pTsdb->pVnode->config.tsdbCfg.maxRows;
|
||||
pCommitter->cmprAlg = pTsdb->pVnode->config.tsdbCfg.compression;
|
||||
pCommitter->maxLast = TSDB_DEFAULT_LAST_FILE; // TODO: make it as a config
|
||||
pCommitter->aTbDataP = tsdbMemTableGetTbDataArray(pTsdb->imem);
|
||||
if (pCommitter->aTbDataP == NULL) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
|
@ -1301,15 +1283,6 @@ static int32_t tsdbCommitDataStart(SCommitter *pCommitter) {
|
|||
code = tBlockDataCreate(&pCommitter->dReader.bData);
|
||||
if (code) goto _exit;
|
||||
|
||||
pCommitter->dReader.aBlockL = taosArrayInit(0, sizeof(SBlockL));
|
||||
if (pCommitter->dReader.aBlockL == NULL) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto _exit;
|
||||
}
|
||||
|
||||
code = tBlockDataCreate(&pCommitter->dReader.bDatal);
|
||||
if (code) goto _exit;
|
||||
|
||||
// Writer
|
||||
pCommitter->dWriter.aBlockIdx = taosArrayInit(0, sizeof(SBlockIdx));
|
||||
if (pCommitter->dWriter.aBlockIdx == NULL) {
|
||||
|
@ -1338,8 +1311,6 @@ static void tsdbCommitDataEnd(SCommitter *pCommitter) {
|
|||
taosArrayDestroy(pCommitter->dReader.aBlockIdx);
|
||||
tMapDataClear(&pCommitter->dReader.mBlock);
|
||||
tBlockDataDestroy(&pCommitter->dReader.bData, 1);
|
||||
taosArrayDestroy(pCommitter->dReader.aBlockL);
|
||||
tBlockDataDestroy(&pCommitter->dReader.bDatal, 1);
|
||||
|
||||
// Writer
|
||||
taosArrayDestroy(pCommitter->dWriter.aBlockIdx);
|
||||
|
|
|
@ -544,7 +544,7 @@ int32_t tsdbFSCopy(STsdb *pTsdb, STsdbFS *pFS) {
|
|||
|
||||
for (int32_t iSet = 0; iSet < taosArrayGetSize(pTsdb->fs.aDFileSet); iSet++) {
|
||||
SDFileSet *pSet = (SDFileSet *)taosArrayGet(pTsdb->fs.aDFileSet, iSet);
|
||||
SDFileSet fSet = {.diskId = pSet->diskId, .fid = pSet->fid, .nLastF = 1};
|
||||
SDFileSet fSet = {.diskId = pSet->diskId, .fid = pSet->fid};
|
||||
|
||||
// head
|
||||
fSet.pHeadF = (SHeadFile *)taosMemoryMalloc(sizeof(SHeadFile));
|
||||
|
@ -576,13 +576,13 @@ int32_t tsdbFSCopy(STsdb *pTsdb, STsdbFS *pFS) {
|
|||
}
|
||||
|
||||
// last
|
||||
for (int32_t iLast = 0; iLast < pSet->nLastF; iLast++) {
|
||||
fSet.aLastF[iLast] = (SLastFile *)taosMemoryMalloc(sizeof(SLastFile));
|
||||
if (fSet.aLastF[iLast] == NULL) {
|
||||
for (fSet.nLastF = 0; fSet.nLastF < pSet->nLastF; fSet.nLastF++) {
|
||||
fSet.aLastF[fSet.nLastF] = (SLastFile *)taosMemoryMalloc(sizeof(SLastFile));
|
||||
if (fSet.aLastF[fSet.nLastF] == NULL) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto _exit;
|
||||
}
|
||||
*fSet.aLastF[iLast] = *pSet->aLastF[iLast];
|
||||
*fSet.aLastF[fSet.nLastF] = *pSet->aLastF[fSet.nLastF];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -981,12 +981,14 @@ int32_t tsdbFSRef(STsdb *pTsdb, STsdbFS *pFS) {
|
|||
nRef = atomic_fetch_add_32(&pSet->pDataF->nRef, 1);
|
||||
ASSERT(nRef > 0);
|
||||
|
||||
nRef = atomic_fetch_add_32(&pSet->aLastF[0]->nRef, 1);
|
||||
ASSERT(nRef > 0);
|
||||
|
||||
nRef = atomic_fetch_add_32(&pSet->pSmaF->nRef, 1);
|
||||
ASSERT(nRef > 0);
|
||||
|
||||
for (int32_t iLast = 0; iLast < pSet->nLastF; iLast++) {
|
||||
nRef = atomic_fetch_add_32(&pSet->aLastF[iLast]->nRef, 1);
|
||||
ASSERT(nRef > 0);
|
||||
}
|
||||
|
||||
if (taosArrayPush(pFS->aDFileSet, &fSet) == NULL) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto _exit;
|
||||
|
@ -1032,15 +1034,6 @@ void tsdbFSUnref(STsdb *pTsdb, STsdbFS *pFS) {
|
|||
taosMemoryFree(pSet->pDataF);
|
||||
}
|
||||
|
||||
// last
|
||||
nRef = atomic_sub_fetch_32(&pSet->aLastF[0]->nRef, 1);
|
||||
ASSERT(nRef >= 0);
|
||||
if (nRef == 0) {
|
||||
tsdbLastFileName(pTsdb, pSet->diskId, pSet->fid, pSet->aLastF[0], fname);
|
||||
taosRemoveFile(fname);
|
||||
taosMemoryFree(pSet->aLastF[0]);
|
||||
}
|
||||
|
||||
// sma
|
||||
nRef = atomic_sub_fetch_32(&pSet->pSmaF->nRef, 1);
|
||||
ASSERT(nRef >= 0);
|
||||
|
@ -1049,6 +1042,18 @@ void tsdbFSUnref(STsdb *pTsdb, STsdbFS *pFS) {
|
|||
taosRemoveFile(fname);
|
||||
taosMemoryFree(pSet->pSmaF);
|
||||
}
|
||||
|
||||
// last
|
||||
for (int32_t iLast = 0; iLast < pSet->nLastF; iLast++) {
|
||||
nRef = atomic_sub_fetch_32(&pSet->aLastF[iLast]->nRef, 1);
|
||||
ASSERT(nRef >= 0);
|
||||
if (nRef == 0) {
|
||||
tsdbLastFileName(pTsdb, pSet->diskId, pSet->fid, pSet->aLastF[iLast], fname);
|
||||
taosRemoveFile(fname);
|
||||
taosMemoryFree(pSet->aLastF[iLast]);
|
||||
/* code */
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
taosArrayDestroy(pFS->aDFileSet);
|
||||
|
|
|
@ -169,7 +169,8 @@ static int buildDataBlockFromBufImpl(STableBlockScanInfo* pBlockScanInfo, i
|
|||
static TSDBROW* getValidRow(SIterInfo* pIter, const SArray* pDelList, STsdbReader* pReader);
|
||||
static int32_t doMergeRowsInFileBlocks(SBlockData* pBlockData, STableBlockScanInfo* pScanInfo, STsdbReader* pReader,
|
||||
SRowMerger* pMerger);
|
||||
static int32_t doMergeRowsInLastBlock(SLastBlockReader* pLastBlockReader, STableBlockScanInfo* pScanInfo, int64_t ts, SRowMerger* pMerger);
|
||||
static int32_t doMergeRowsInLastBlock(SLastBlockReader* pLastBlockReader, STableBlockScanInfo* pScanInfo, int64_t ts,
|
||||
SRowMerger* pMerger);
|
||||
static int32_t doMergeRowsInBuf(SIterInfo* pIter, uint64_t uid, int64_t ts, SArray* pDelList, SRowMerger* pMerger,
|
||||
STsdbReader* pReader);
|
||||
static int32_t doAppendRowFromTSRow(SSDataBlock* pBlock, STsdbReader* pReader, STSRow* pTSRow, uint64_t uid);
|
||||
|
@ -320,7 +321,8 @@ static void limitOutputBufferSize(const SQueryTableDataCond* pCond, int32_t* cap
|
|||
}
|
||||
|
||||
// init file iterator
|
||||
static int32_t initFilesetIterator(SFilesetIter* pIter, SArray* aDFileSet, STsdbReader* pReader/*int32_t order, const char* idstr*/) {
|
||||
static int32_t initFilesetIterator(SFilesetIter* pIter, SArray* aDFileSet,
|
||||
STsdbReader* pReader /*int32_t order, const char* idstr*/) {
|
||||
size_t numOfFileset = taosArrayGetSize(aDFileSet);
|
||||
|
||||
pIter->index = ASCENDING_TRAVERSE(pReader->order) ? -1 : numOfFileset;
|
||||
|
@ -729,9 +731,10 @@ static int32_t doLoadFileBlock(STsdbReader* pReader, SArray* pIndexList, SArray*
|
|||
int32_t total = pBlockNum->numOfLastBlocks + pBlockNum->numOfBlocks;
|
||||
|
||||
double el = (taosGetTimestampUs() - st) / 1000.0;
|
||||
tsdbDebug("load block of %d tables completed, blocks:%d in %d tables, lastBlock:%d, size:%.2f Kb, elapsed time:%.2f ms %s",
|
||||
numOfTables, pBlockNum->numOfBlocks, numOfQTable, pBlockNum->numOfLastBlocks, sizeInDisk
|
||||
/ 1000.0, el, pReader->idStr);
|
||||
tsdbDebug(
|
||||
"load block of %d tables completed, blocks:%d in %d tables, lastBlock:%d, size:%.2f Kb, elapsed time:%.2f ms %s",
|
||||
numOfTables, pBlockNum->numOfBlocks, numOfQTable, pBlockNum->numOfLastBlocks, sizeInDisk / 1000.0, el,
|
||||
pReader->idStr);
|
||||
|
||||
pReader->cost.numOfBlocks += total;
|
||||
pReader->cost.headFileLoadTime += el;
|
||||
|
@ -1097,8 +1100,8 @@ static int32_t initBlockIterator(STsdbReader* pReader, SDataBlockIter* pBlockIte
|
|||
}
|
||||
|
||||
int64_t et = taosGetTimestampUs();
|
||||
tsdbDebug("%p %d data blocks access order completed, elapsed time:%.2f ms %s", pReader, numOfBlocks, (et - st) / 1000.0,
|
||||
pReader->idStr);
|
||||
tsdbDebug("%p %d data blocks access order completed, elapsed time:%.2f ms %s", pReader, numOfBlocks,
|
||||
(et - st) / 1000.0, pReader->idStr);
|
||||
cleanupBlockOrderSupporter(&sup);
|
||||
taosMemoryFree(pTree);
|
||||
|
||||
|
@ -1583,7 +1586,8 @@ static int32_t doMergeBufAndFileRows(STsdbReader* pReader, STableBlockScanInfo*
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t doMergeMultiLevelRowsRv(STsdbReader* pReader, STableBlockScanInfo* pBlockScanInfo, SBlockData* pBlockData, SLastBlockReader* pLastBlockReader) {
|
||||
static int32_t doMergeMultiLevelRowsRv(STsdbReader* pReader, STableBlockScanInfo* pBlockScanInfo,
|
||||
SBlockData* pBlockData, SLastBlockReader* pLastBlockReader) {
|
||||
SRowMerger merge = {0};
|
||||
STSRow* pTSRow = NULL;
|
||||
|
||||
|
@ -1734,7 +1738,8 @@ static int32_t doMergeMultiLevelRowsRv(STsdbReader* pReader, STableBlockScanInfo
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t doMergeThreeLevelRows(STsdbReader* pReader, STableBlockScanInfo* pBlockScanInfo, SBlockData* pBlockData) {
|
||||
static int32_t doMergeThreeLevelRows(STsdbReader* pReader, STableBlockScanInfo* pBlockScanInfo,
|
||||
SBlockData* pBlockData) {
|
||||
SRowMerger merge = {0};
|
||||
STSRow* pTSRow = NULL;
|
||||
|
||||
|
@ -2178,7 +2183,8 @@ static int32_t buildComposedDataBlock(STsdbReader* pReader) {
|
|||
setComposedBlockFlag(pReader, true);
|
||||
int64_t et = taosGetTimestampUs();
|
||||
|
||||
tsdbDebug("%p uid:%" PRIu64 ", composed data block created, brange:%" PRIu64 "-%" PRIu64 " rows:%d, elapsed time:%.2f ms %s",
|
||||
tsdbDebug("%p uid:%" PRIu64 ", composed data block created, brange:%" PRIu64 "-%" PRIu64
|
||||
" rows:%d, elapsed time:%.2f ms %s",
|
||||
pReader, pBlockScanInfo->uid, pResBlock->info.window.skey, pResBlock->info.window.ekey,
|
||||
pResBlock->info.rows, (et - st) / 1000.0, pReader->idStr);
|
||||
|
||||
|
@ -2376,7 +2382,7 @@ static int32_t moveToNextFile(STsdbReader* pReader, SBlockNumber* pBlockNum) {
|
|||
return code;
|
||||
}
|
||||
|
||||
code = tsdbReadBlockL(pReader->pFileReader, pLastBlocks);
|
||||
code = tsdbReadBlockL(pReader->pFileReader, 0, pLastBlocks);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
taosArrayDestroy(pIndexList);
|
||||
return code;
|
||||
|
@ -2411,7 +2417,8 @@ static int32_t moveToNextFile(STsdbReader* pReader, SBlockNumber* pBlockNum) {
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t doLoadRelatedLastBlock(SLastBlockReader* pLastBlockReader, STableBlockScanInfo *pBlockScanInfo, STsdbReader* pReader) {
|
||||
static int32_t doLoadRelatedLastBlock(SLastBlockReader* pLastBlockReader, STableBlockScanInfo* pBlockScanInfo,
|
||||
STsdbReader* pReader) {
|
||||
SArray* pBlocks = pLastBlockReader->pBlockL;
|
||||
SBlockL* pBlock = NULL;
|
||||
|
||||
|
@ -2443,7 +2450,8 @@ static int32_t doLoadRelatedLastBlock(SLastBlockReader* pLastBlockReader, STable
|
|||
}
|
||||
|
||||
int64_t st = taosGetTimestampUs();
|
||||
int32_t code = tBlockDataInit(&pLastBlockReader->lastBlockData, pReader->suid, pReader->suid ? 0 : uid, pReader->pSchema);
|
||||
int32_t code =
|
||||
tBlockDataInit(&pLastBlockReader->lastBlockData, pReader->suid, pReader->suid ? 0 : uid, pReader->pSchema);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
tsdbError("%p init block data failed, code:%s %s", pReader, tstrerror(code), pReader->idStr);
|
||||
return code;
|
||||
|
@ -2560,7 +2568,8 @@ static int32_t doBuildDataBlock(STsdbReader* pReader) {
|
|||
|
||||
// note: the lastblock may be null here
|
||||
initLastBlockReader(pLastBlockReader, pScanInfo->uid, &pScanInfo->indexInBlockL);
|
||||
if (pScanInfo->indexInBlockL == DEFAULT_ROW_INDEX_VAL || pScanInfo->indexInBlockL == pLastBlockReader->lastBlockData.nRow) {
|
||||
if (pScanInfo->indexInBlockL == DEFAULT_ROW_INDEX_VAL ||
|
||||
pScanInfo->indexInBlockL == pLastBlockReader->lastBlockData.nRow) {
|
||||
bool hasData = nextRowInLastBlock(pLastBlockReader, pScanInfo);
|
||||
}
|
||||
}
|
||||
|
@ -2742,7 +2751,8 @@ static int32_t buildBlockFromFiles(STsdbReader* pReader) {
|
|||
bool hasNext = blockIteratorNext(&pReader->status.blockIter);
|
||||
if (hasNext) { // check for the next block in the block accessed order list
|
||||
initBlockDumpInfo(pReader, pBlockIter);
|
||||
} else if (taosArrayGetSize(pReader->status.fileIter.pLastBlockReader->pBlockL) > 0) { // data blocks in current file are exhausted, let's try the next file now
|
||||
} else if (taosArrayGetSize(pReader->status.fileIter.pLastBlockReader->pBlockL) >
|
||||
0) { // data blocks in current file are exhausted, let's try the next file now
|
||||
tBlockDataReset(&pReader->status.fileBlockData);
|
||||
resetDataBlockIterator(pBlockIter, pReader->order, pReader->status.pTableMap);
|
||||
goto _begin;
|
||||
|
@ -3101,7 +3111,8 @@ int32_t doMergeRowsInFileBlocks(SBlockData* pBlockData, STableBlockScanInfo* pSc
|
|||
}
|
||||
|
||||
// todo check if the rows are dropped or not
|
||||
int32_t doMergeRowsInLastBlock(SLastBlockReader* pLastBlockReader, STableBlockScanInfo* pScanInfo, int64_t ts, SRowMerger* pMerger) {
|
||||
int32_t doMergeRowsInLastBlock(SLastBlockReader* pLastBlockReader, STableBlockScanInfo* pScanInfo, int64_t ts,
|
||||
SRowMerger* pMerger) {
|
||||
while (nextRowInLastBlock(pLastBlockReader, pScanInfo)) {
|
||||
int64_t next1 = getCurrentKeyInLastBlock(pLastBlockReader);
|
||||
if (next1 == ts) {
|
||||
|
@ -3287,7 +3298,8 @@ int32_t doAppendRowFromTSRow(SSDataBlock* pBlock, STsdbReader* pReader, STSRow*
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t doAppendRowFromFileBlock(SSDataBlock* pResBlock, STsdbReader* pReader, SBlockData* pBlockData, int32_t rowIndex) {
|
||||
int32_t doAppendRowFromFileBlock(SSDataBlock* pResBlock, STsdbReader* pReader, SBlockData* pBlockData,
|
||||
int32_t rowIndex) {
|
||||
int32_t i = 0, j = 0;
|
||||
int32_t outputRowIndex = pResBlock->info.rows;
|
||||
|
||||
|
@ -3385,7 +3397,6 @@ void* tsdbGetIvtIdx(SMeta* pMeta) {
|
|||
|
||||
uint64_t getReaderMaxVersion(STsdbReader* pReader) { return pReader->verRange.maxVer; }
|
||||
|
||||
|
||||
// ====================================== EXPOSED APIs ======================================
|
||||
int32_t tsdbReaderOpen(SVnode* pVnode, SQueryTableDataCond* pCond, SArray* pTableList, STsdbReader** ppReader,
|
||||
const char* idstr) {
|
||||
|
|
|
@ -399,8 +399,8 @@ struct SDataFReader {
|
|||
SDFileSet *pSet;
|
||||
TdFilePtr pHeadFD;
|
||||
TdFilePtr pDataFD;
|
||||
TdFilePtr pLastFD;
|
||||
TdFilePtr pSmaFD;
|
||||
TdFilePtr aLastFD[TSDB_MAX_LAST_FILE];
|
||||
|
||||
uint8_t *aBuf[3];
|
||||
};
|
||||
|
@ -445,12 +445,14 @@ int32_t tsdbDataFReaderOpen(SDataFReader **ppReader, STsdb *pTsdb, SDFileSet *pS
|
|||
}
|
||||
|
||||
// last
|
||||
tsdbLastFileName(pTsdb, pSet->diskId, pSet->fid, pSet->aLastF[0], fname);
|
||||
pReader->pLastFD = taosOpenFile(fname, TD_FILE_READ);
|
||||
if (pReader->pLastFD == NULL) {
|
||||
for (int32_t iLast = 0; iLast < pSet->nLastF; iLast++) {
|
||||
tsdbLastFileName(pTsdb, pSet->diskId, pSet->fid, pSet->aLastF[iLast], fname);
|
||||
pReader->aLastFD[iLast] = taosOpenFile(fname, TD_FILE_READ);
|
||||
if (pReader->aLastFD[iLast] == NULL) {
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
goto _err;
|
||||
}
|
||||
}
|
||||
|
||||
*ppReader = pReader;
|
||||
return code;
|
||||
|
@ -465,30 +467,35 @@ int32_t tsdbDataFReaderClose(SDataFReader **ppReader) {
|
|||
int32_t code = 0;
|
||||
if (*ppReader == NULL) goto _exit;
|
||||
|
||||
// head
|
||||
if (taosCloseFile(&(*ppReader)->pHeadFD) < 0) {
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
goto _err;
|
||||
}
|
||||
|
||||
// data
|
||||
if (taosCloseFile(&(*ppReader)->pDataFD) < 0) {
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
goto _err;
|
||||
}
|
||||
|
||||
if (taosCloseFile(&(*ppReader)->pLastFD) < 0) {
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
goto _err;
|
||||
}
|
||||
|
||||
// sma
|
||||
if (taosCloseFile(&(*ppReader)->pSmaFD) < 0) {
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
goto _err;
|
||||
}
|
||||
|
||||
// last
|
||||
for (int32_t iLast = 0; iLast < (*ppReader)->pSet->nLastF; iLast++) {
|
||||
if (taosCloseFile(&(*ppReader)->aLastFD[iLast]) < 0) {
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
goto _err;
|
||||
}
|
||||
}
|
||||
|
||||
for (int32_t iBuf = 0; iBuf < sizeof((*ppReader)->aBuf) / sizeof(uint8_t *); iBuf++) {
|
||||
tFree((*ppReader)->aBuf[iBuf]);
|
||||
}
|
||||
|
||||
taosMemoryFree(*ppReader);
|
||||
|
||||
_exit:
|
||||
|
@ -563,10 +570,10 @@ _err:
|
|||
return code;
|
||||
}
|
||||
|
||||
int32_t tsdbReadBlockL(SDataFReader *pReader, SArray *aBlockL) {
|
||||
int32_t tsdbReadBlockL(SDataFReader *pReader, int32_t iLast, SArray *aBlockL) {
|
||||
int32_t code = 0;
|
||||
int64_t offset = pReader->pSet->aLastF[0]->offset;
|
||||
int64_t size = pReader->pSet->aLastF[0]->size - offset;
|
||||
int64_t offset = pReader->pSet->aLastF[iLast]->offset;
|
||||
int64_t size = pReader->pSet->aLastF[iLast]->size - offset;
|
||||
int64_t n;
|
||||
uint32_t delimiter;
|
||||
|
||||
|
@ -580,13 +587,13 @@ int32_t tsdbReadBlockL(SDataFReader *pReader, SArray *aBlockL) {
|
|||
if (code) goto _err;
|
||||
|
||||
// seek
|
||||
if (taosLSeekFile(pReader->pLastFD, offset, SEEK_SET) < 0) {
|
||||
if (taosLSeekFile(pReader->aLastFD[iLast], offset, SEEK_SET) < 0) {
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
goto _err;
|
||||
}
|
||||
|
||||
// read
|
||||
n = taosReadFile(pReader->pLastFD, pReader->aBuf[0], size);
|
||||
n = taosReadFile(pReader->aLastFD[iLast], pReader->aBuf[0], size);
|
||||
if (n < 0) {
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
goto _err;
|
||||
|
@ -745,7 +752,7 @@ static int32_t tsdbReadBlockDataImpl(SDataFReader *pReader, SBlockInfo *pBlkInfo
|
|||
|
||||
tBlockDataClear(pBlockData);
|
||||
|
||||
TdFilePtr pFD = fromLast ? pReader->pLastFD : pReader->pDataFD;
|
||||
TdFilePtr pFD = fromLast ? pReader->aLastFD[0] : pReader->pDataFD; // (todo)
|
||||
|
||||
// uid + version + tskey
|
||||
code = tsdbReadAndCheck(pFD, pBlkInfo->offset, &pReader->aBuf[0], pBlkInfo->szKey, 1);
|
||||
|
|
|
@ -64,7 +64,7 @@ static int32_t tsdbSnapReadData(STsdbSnapReader* pReader, uint8_t** ppData) {
|
|||
code = tsdbReadBlockIdx(pReader->pDataFReader, pReader->aBlockIdx);
|
||||
if (code) goto _err;
|
||||
|
||||
code = tsdbReadBlockL(pReader->pDataFReader, pReader->aBlockL);
|
||||
code = tsdbReadBlockL(pReader->pDataFReader, 0, pReader->aBlockL);
|
||||
if (code) goto _err;
|
||||
|
||||
// init
|
||||
|
@ -911,7 +911,7 @@ static int32_t tsdbSnapWriteData(STsdbSnapWriter* pWriter, uint8_t* pData, uint3
|
|||
code = tsdbReadBlockIdx(pWriter->pDataFReader, pWriter->aBlockIdx);
|
||||
if (code) goto _err;
|
||||
|
||||
code = tsdbReadBlockL(pWriter->pDataFReader, pWriter->aBlockL);
|
||||
code = tsdbReadBlockL(pWriter->pDataFReader, 0, pWriter->aBlockL);
|
||||
if (code) goto _err;
|
||||
} else {
|
||||
ASSERT(pWriter->pDataFReader == NULL);
|
||||
|
|
Loading…
Reference in New Issue