Merge pull request #16746 from taosdata/refact/tsdb_new_snapshot
refact: tsdb new snapshot
This commit is contained in:
commit
856b50eb7b
|
@ -84,6 +84,8 @@ typedef struct SLDataIter SLDataIter;
|
||||||
#define TSDBKEY_MIN ((TSDBKEY){.ts = TSKEY_MIN, .version = VERSION_MIN})
|
#define TSDBKEY_MIN ((TSDBKEY){.ts = TSKEY_MIN, .version = VERSION_MIN})
|
||||||
#define TSDBKEY_MAX ((TSDBKEY){.ts = TSKEY_MAX, .version = VERSION_MAX})
|
#define TSDBKEY_MAX ((TSDBKEY){.ts = TSKEY_MAX, .version = VERSION_MAX})
|
||||||
|
|
||||||
|
#define TABLE_SAME_SCHEMA(SUID1, UID1, SUID2, UID2) ((SUID1) ? (SUID1) == (SUID2) : (UID1) == (UID2))
|
||||||
|
|
||||||
#define PAGE_CONTENT_SIZE(PAGE) ((PAGE) - sizeof(TSCKSUM))
|
#define PAGE_CONTENT_SIZE(PAGE) ((PAGE) - sizeof(TSCKSUM))
|
||||||
#define LOGIC_TO_FILE_OFFSET(LOFFSET, PAGE) \
|
#define LOGIC_TO_FILE_OFFSET(LOFFSET, PAGE) \
|
||||||
((LOFFSET) / PAGE_CONTENT_SIZE(PAGE) * (PAGE) + (LOFFSET) % PAGE_CONTENT_SIZE(PAGE))
|
((LOFFSET) / PAGE_CONTENT_SIZE(PAGE) * (PAGE) + (LOFFSET) % PAGE_CONTENT_SIZE(PAGE))
|
||||||
|
@ -262,7 +264,7 @@ int32_t tsdbDataFWriterOpen(SDataFWriter **ppWriter, STsdb *pTsdb, SDFileSet *pS
|
||||||
int32_t tsdbDataFWriterClose(SDataFWriter **ppWriter, int8_t sync);
|
int32_t tsdbDataFWriterClose(SDataFWriter **ppWriter, int8_t sync);
|
||||||
int32_t tsdbUpdateDFileSetHeader(SDataFWriter *pWriter);
|
int32_t tsdbUpdateDFileSetHeader(SDataFWriter *pWriter);
|
||||||
int32_t tsdbWriteBlockIdx(SDataFWriter *pWriter, SArray *aBlockIdx);
|
int32_t tsdbWriteBlockIdx(SDataFWriter *pWriter, SArray *aBlockIdx);
|
||||||
int32_t tsdbWriteBlock(SDataFWriter *pWriter, SMapData *pMapData, SBlockIdx *pBlockIdx);
|
int32_t tsdbWriteDataBlk(SDataFWriter *pWriter, SMapData *mDataBlk, SBlockIdx *pBlockIdx);
|
||||||
int32_t tsdbWriteSttBlk(SDataFWriter *pWriter, SArray *aSttBlk);
|
int32_t tsdbWriteSttBlk(SDataFWriter *pWriter, SArray *aSttBlk);
|
||||||
int32_t tsdbWriteBlockData(SDataFWriter *pWriter, SBlockData *pBlockData, SBlockInfo *pBlkInfo, SSmaInfo *pSmaInfo,
|
int32_t tsdbWriteBlockData(SDataFWriter *pWriter, SBlockData *pBlockData, SBlockInfo *pBlkInfo, SSmaInfo *pSmaInfo,
|
||||||
int8_t cmprAlg, int8_t toLast);
|
int8_t cmprAlg, int8_t toLast);
|
||||||
|
@ -272,7 +274,7 @@ int32_t tsdbDFileSetCopy(STsdb *pTsdb, SDFileSet *pSetFrom, SDFileSet *pSetTo);
|
||||||
int32_t tsdbDataFReaderOpen(SDataFReader **ppReader, STsdb *pTsdb, SDFileSet *pSet);
|
int32_t tsdbDataFReaderOpen(SDataFReader **ppReader, STsdb *pTsdb, SDFileSet *pSet);
|
||||||
int32_t tsdbDataFReaderClose(SDataFReader **ppReader);
|
int32_t tsdbDataFReaderClose(SDataFReader **ppReader);
|
||||||
int32_t tsdbReadBlockIdx(SDataFReader *pReader, SArray *aBlockIdx);
|
int32_t tsdbReadBlockIdx(SDataFReader *pReader, SArray *aBlockIdx);
|
||||||
int32_t tsdbReadBlock(SDataFReader *pReader, SBlockIdx *pBlockIdx, SMapData *pMapData);
|
int32_t tsdbReadDataBlk(SDataFReader *pReader, SBlockIdx *pBlockIdx, SMapData *mDataBlk);
|
||||||
int32_t tsdbReadSttBlk(SDataFReader *pReader, int32_t iStt, SArray *aSttBlk);
|
int32_t tsdbReadSttBlk(SDataFReader *pReader, int32_t iStt, SArray *aSttBlk);
|
||||||
int32_t tsdbReadBlockSma(SDataFReader *pReader, SDataBlk *pBlock, SArray *aColumnDataAgg);
|
int32_t tsdbReadBlockSma(SDataFReader *pReader, SDataBlk *pBlock, SArray *aColumnDataAgg);
|
||||||
int32_t tsdbReadDataBlock(SDataFReader *pReader, SDataBlk *pBlock, SBlockData *pBlockData);
|
int32_t tsdbReadDataBlock(SDataFReader *pReader, SDataBlk *pBlock, SBlockData *pBlockData);
|
||||||
|
@ -662,6 +664,12 @@ typedef struct SMergeTree {
|
||||||
const char *idStr;
|
const char *idStr;
|
||||||
} SMergeTree;
|
} SMergeTree;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
int64_t suid;
|
||||||
|
int64_t uid;
|
||||||
|
STSchema *pTSchema;
|
||||||
|
} SSkmInfo;
|
||||||
|
|
||||||
int32_t tMergeTreeOpen(SMergeTree *pMTree, int8_t backward, SDataFReader *pFReader, uint64_t suid, uint64_t uid,
|
int32_t tMergeTreeOpen(SMergeTree *pMTree, int8_t backward, SDataFReader *pFReader, uint64_t suid, uint64_t uid,
|
||||||
STimeWindow *pTimeWindow, SVersionRange *pVerRange, void *pLoadInfo, const char *idStr);
|
STimeWindow *pTimeWindow, SVersionRange *pVerRange, void *pLoadInfo, const char *idStr);
|
||||||
void tMergeTreeAddIter(SMergeTree *pMTree, SLDataIter *pIter);
|
void tMergeTreeAddIter(SMergeTree *pMTree, SLDataIter *pIter);
|
||||||
|
|
|
@ -589,7 +589,7 @@ static int32_t getNextRowFromFS(void *iter, TSDBROW **ppRow) {
|
||||||
}
|
}
|
||||||
|
|
||||||
tMapDataReset(&state->blockMap);
|
tMapDataReset(&state->blockMap);
|
||||||
code = tsdbReadBlock(state->pDataFReader, state->pBlockIdx, &state->blockMap);
|
code = tsdbReadDataBlk(state->pDataFReader, state->pBlockIdx, &state->blockMap);
|
||||||
if (code) goto _err;
|
if (code) goto _err;
|
||||||
|
|
||||||
state->nBlock = state->blockMap.nItem;
|
state->nBlock = state->blockMap.nItem;
|
||||||
|
|
|
@ -14,13 +14,8 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "tsdb.h"
|
#include "tsdb.h"
|
||||||
typedef struct {
|
|
||||||
int64_t suid;
|
|
||||||
int64_t uid;
|
|
||||||
STSchema *pTSchema;
|
|
||||||
} SSkmInfo;
|
|
||||||
|
|
||||||
typedef enum { MEMORY_DATA_ITER = 0, LAST_DATA_ITER } EDataIterT;
|
typedef enum { MEMORY_DATA_ITER = 0, STT_DATA_ITER } EDataIterT;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
SRBTreeNode n;
|
SRBTreeNode n;
|
||||||
|
@ -99,7 +94,7 @@ static int32_t tsdbCommitCache(SCommitter *pCommitter);
|
||||||
static int32_t tsdbEndCommit(SCommitter *pCommitter, int32_t eno);
|
static int32_t tsdbEndCommit(SCommitter *pCommitter, int32_t eno);
|
||||||
static int32_t tsdbNextCommitRow(SCommitter *pCommitter);
|
static int32_t tsdbNextCommitRow(SCommitter *pCommitter);
|
||||||
|
|
||||||
static int32_t tRowInfoCmprFn(const void *p1, const void *p2) {
|
int32_t tRowInfoCmprFn(const void *p1, const void *p2) {
|
||||||
SRowInfo *pInfo1 = (SRowInfo *)p1;
|
SRowInfo *pInfo1 = (SRowInfo *)p1;
|
||||||
SRowInfo *pInfo2 = (SRowInfo *)p2;
|
SRowInfo *pInfo2 = (SRowInfo *)p2;
|
||||||
|
|
||||||
|
@ -325,22 +320,22 @@ _err:
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t tsdbCommitterUpdateTableSchema(SCommitter *pCommitter, int64_t suid, int64_t uid) {
|
int32_t tsdbUpdateTableSchema(SMeta *pMeta, int64_t suid, int64_t uid, SSkmInfo *pSkmInfo) {
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
|
|
||||||
if (suid) {
|
if (suid) {
|
||||||
if (pCommitter->skmTable.suid == suid) {
|
if (pSkmInfo->suid == suid) {
|
||||||
pCommitter->skmTable.uid = uid;
|
pSkmInfo->uid = uid;
|
||||||
goto _exit;
|
goto _exit;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (pCommitter->skmTable.uid == uid) goto _exit;
|
if (pSkmInfo->uid == uid) goto _exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
pCommitter->skmTable.suid = suid;
|
pSkmInfo->suid = suid;
|
||||||
pCommitter->skmTable.uid = uid;
|
pSkmInfo->uid = uid;
|
||||||
tTSchemaDestroy(pCommitter->skmTable.pTSchema);
|
tTSchemaDestroy(pSkmInfo->pTSchema);
|
||||||
code = metaGetTbTSchemaEx(pCommitter->pTsdb->pVnode->pMeta, suid, uid, -1, &pCommitter->skmTable.pTSchema);
|
code = metaGetTbTSchemaEx(pMeta, suid, uid, -1, &pSkmInfo->pTSchema);
|
||||||
if (code) goto _exit;
|
if (code) goto _exit;
|
||||||
|
|
||||||
_exit:
|
_exit:
|
||||||
|
@ -382,7 +377,7 @@ static int32_t tsdbCommitterNextTableData(SCommitter *pCommitter) {
|
||||||
pCommitter->dReader.pBlockIdx =
|
pCommitter->dReader.pBlockIdx =
|
||||||
(SBlockIdx *)taosArrayGet(pCommitter->dReader.aBlockIdx, pCommitter->dReader.iBlockIdx);
|
(SBlockIdx *)taosArrayGet(pCommitter->dReader.aBlockIdx, pCommitter->dReader.iBlockIdx);
|
||||||
|
|
||||||
code = tsdbReadBlock(pCommitter->dReader.pReader, pCommitter->dReader.pBlockIdx, &pCommitter->dReader.mBlock);
|
code = tsdbReadDataBlk(pCommitter->dReader.pReader, pCommitter->dReader.pBlockIdx, &pCommitter->dReader.mBlock);
|
||||||
if (code) goto _exit;
|
if (code) goto _exit;
|
||||||
|
|
||||||
ASSERT(pCommitter->dReader.mBlock.nItem > 0);
|
ASSERT(pCommitter->dReader.mBlock.nItem > 0);
|
||||||
|
@ -432,7 +427,7 @@ static int32_t tsdbOpenCommitIter(SCommitter *pCommitter) {
|
||||||
int8_t iIter = 0;
|
int8_t iIter = 0;
|
||||||
for (int32_t iStt = 0; iStt < pReader->pSet->nSttF; iStt++) {
|
for (int32_t iStt = 0; iStt < pReader->pSet->nSttF; iStt++) {
|
||||||
pIter = &pCommitter->aDataIter[iIter];
|
pIter = &pCommitter->aDataIter[iIter];
|
||||||
pIter->type = LAST_DATA_ITER;
|
pIter->type = STT_DATA_ITER;
|
||||||
pIter->iStt = iStt;
|
pIter->iStt = iStt;
|
||||||
|
|
||||||
code = tsdbReadSttBlk(pCommitter->dReader.pReader, iStt, pIter->aSttBlk);
|
code = tsdbReadSttBlk(pCommitter->dReader.pReader, iStt, pIter->aSttBlk);
|
||||||
|
@ -498,7 +493,7 @@ static int32_t tsdbCommitFileDataStart(SCommitter *pCommitter) {
|
||||||
pCommitter->dReader.iBlockIdx = 0;
|
pCommitter->dReader.iBlockIdx = 0;
|
||||||
if (taosArrayGetSize(pCommitter->dReader.aBlockIdx) > 0) {
|
if (taosArrayGetSize(pCommitter->dReader.aBlockIdx) > 0) {
|
||||||
pCommitter->dReader.pBlockIdx = (SBlockIdx *)taosArrayGet(pCommitter->dReader.aBlockIdx, 0);
|
pCommitter->dReader.pBlockIdx = (SBlockIdx *)taosArrayGet(pCommitter->dReader.aBlockIdx, 0);
|
||||||
code = tsdbReadBlock(pCommitter->dReader.pReader, pCommitter->dReader.pBlockIdx, &pCommitter->dReader.mBlock);
|
code = tsdbReadDataBlk(pCommitter->dReader.pReader, pCommitter->dReader.pBlockIdx, &pCommitter->dReader.mBlock);
|
||||||
if (code) goto _err;
|
if (code) goto _err;
|
||||||
} else {
|
} else {
|
||||||
pCommitter->dReader.pBlockIdx = NULL;
|
pCommitter->dReader.pBlockIdx = NULL;
|
||||||
|
@ -556,46 +551,45 @@ _err:
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t tsdbCommitDataBlock(SCommitter *pCommitter) {
|
int32_t tsdbWriteDataBlock(SDataFWriter *pWriter, SBlockData *pBlockData, SMapData *mDataBlk, int8_t cmprAlg) {
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
SBlockData *pBlockData = &pCommitter->dWriter.bData;
|
|
||||||
SDataBlk block;
|
|
||||||
|
|
||||||
ASSERT(pBlockData->nRow > 0);
|
if (pBlockData->nRow == 0) return code;
|
||||||
|
|
||||||
tDataBlkReset(&block);
|
SDataBlk dataBlk;
|
||||||
|
tDataBlkReset(&dataBlk);
|
||||||
|
|
||||||
// info
|
// info
|
||||||
block.nRow += pBlockData->nRow;
|
dataBlk.nRow += pBlockData->nRow;
|
||||||
for (int32_t iRow = 0; iRow < pBlockData->nRow; iRow++) {
|
for (int32_t iRow = 0; iRow < pBlockData->nRow; iRow++) {
|
||||||
TSDBKEY key = {.ts = pBlockData->aTSKEY[iRow], .version = pBlockData->aVersion[iRow]};
|
TSDBKEY key = {.ts = pBlockData->aTSKEY[iRow], .version = pBlockData->aVersion[iRow]};
|
||||||
|
|
||||||
if (iRow == 0) {
|
if (iRow == 0) {
|
||||||
if (tsdbKeyCmprFn(&block.minKey, &key) > 0) {
|
if (tsdbKeyCmprFn(&dataBlk.minKey, &key) > 0) {
|
||||||
block.minKey = key;
|
dataBlk.minKey = key;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (pBlockData->aTSKEY[iRow] == pBlockData->aTSKEY[iRow - 1]) {
|
if (pBlockData->aTSKEY[iRow] == pBlockData->aTSKEY[iRow - 1]) {
|
||||||
block.hasDup = 1;
|
dataBlk.hasDup = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (iRow == pBlockData->nRow - 1 && tsdbKeyCmprFn(&block.maxKey, &key) < 0) {
|
if (iRow == pBlockData->nRow - 1 && tsdbKeyCmprFn(&dataBlk.maxKey, &key) < 0) {
|
||||||
block.maxKey = key;
|
dataBlk.maxKey = key;
|
||||||
}
|
}
|
||||||
|
|
||||||
block.minVer = TMIN(block.minVer, key.version);
|
dataBlk.minVer = TMIN(dataBlk.minVer, key.version);
|
||||||
block.maxVer = TMAX(block.maxVer, key.version);
|
dataBlk.maxVer = TMAX(dataBlk.maxVer, key.version);
|
||||||
}
|
}
|
||||||
|
|
||||||
// write
|
// write
|
||||||
block.nSubBlock++;
|
dataBlk.nSubBlock++;
|
||||||
code = tsdbWriteBlockData(pCommitter->dWriter.pWriter, pBlockData, &block.aSubBlock[block.nSubBlock - 1],
|
code = tsdbWriteBlockData(pWriter, pBlockData, &dataBlk.aSubBlock[dataBlk.nSubBlock - 1],
|
||||||
((block.nSubBlock == 1) && !block.hasDup) ? &block.smaInfo : NULL, pCommitter->cmprAlg, 0);
|
((dataBlk.nSubBlock == 1) && !dataBlk.hasDup) ? &dataBlk.smaInfo : NULL, cmprAlg, 0);
|
||||||
if (code) goto _err;
|
if (code) goto _err;
|
||||||
|
|
||||||
// put SDataBlk
|
// put SDataBlk
|
||||||
code = tMapDataPutItem(&pCommitter->dWriter.mBlock, &block, tPutDataBlk);
|
code = tMapDataPutItem(mDataBlk, &dataBlk, tPutDataBlk);
|
||||||
if (code) goto _err;
|
if (code) goto _err;
|
||||||
|
|
||||||
// clear
|
// clear
|
||||||
|
@ -604,39 +598,38 @@ static int32_t tsdbCommitDataBlock(SCommitter *pCommitter) {
|
||||||
return code;
|
return code;
|
||||||
|
|
||||||
_err:
|
_err:
|
||||||
tsdbError("vgId:%d tsdb commit data block failed since %s", TD_VID(pCommitter->pTsdb->pVnode), tstrerror(code));
|
tsdbError("vgId:%d tsdb commit data block failed since %s", TD_VID(pWriter->pTsdb->pVnode), tstrerror(code));
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t tsdbCommitLastBlock(SCommitter *pCommitter) {
|
int32_t tsdbWriteSttBlock(SDataFWriter *pWriter, SBlockData *pBlockData, SArray *aSttBlk, int8_t cmprAlg) {
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
SSttBlk blockL;
|
SSttBlk sstBlk;
|
||||||
SBlockData *pBlockData = &pCommitter->dWriter.bDatal;
|
|
||||||
|
|
||||||
ASSERT(pBlockData->nRow > 0);
|
if (pBlockData->nRow == 0) return code;
|
||||||
|
|
||||||
// info
|
// info
|
||||||
blockL.suid = pBlockData->suid;
|
sstBlk.suid = pBlockData->suid;
|
||||||
blockL.nRow = pBlockData->nRow;
|
sstBlk.nRow = pBlockData->nRow;
|
||||||
blockL.minKey = TSKEY_MAX;
|
sstBlk.minKey = TSKEY_MAX;
|
||||||
blockL.maxKey = TSKEY_MIN;
|
sstBlk.maxKey = TSKEY_MIN;
|
||||||
blockL.minVer = VERSION_MAX;
|
sstBlk.minVer = VERSION_MAX;
|
||||||
blockL.maxVer = VERSION_MIN;
|
sstBlk.maxVer = VERSION_MIN;
|
||||||
for (int32_t iRow = 0; iRow < pBlockData->nRow; iRow++) {
|
for (int32_t iRow = 0; iRow < pBlockData->nRow; iRow++) {
|
||||||
blockL.minKey = TMIN(blockL.minKey, pBlockData->aTSKEY[iRow]);
|
sstBlk.minKey = TMIN(sstBlk.minKey, pBlockData->aTSKEY[iRow]);
|
||||||
blockL.maxKey = TMAX(blockL.maxKey, pBlockData->aTSKEY[iRow]);
|
sstBlk.maxKey = TMAX(sstBlk.maxKey, pBlockData->aTSKEY[iRow]);
|
||||||
blockL.minVer = TMIN(blockL.minVer, pBlockData->aVersion[iRow]);
|
sstBlk.minVer = TMIN(sstBlk.minVer, pBlockData->aVersion[iRow]);
|
||||||
blockL.maxVer = TMAX(blockL.maxVer, pBlockData->aVersion[iRow]);
|
sstBlk.maxVer = TMAX(sstBlk.maxVer, pBlockData->aVersion[iRow]);
|
||||||
}
|
}
|
||||||
blockL.minUid = pBlockData->uid ? pBlockData->uid : pBlockData->aUid[0];
|
sstBlk.minUid = pBlockData->uid ? pBlockData->uid : pBlockData->aUid[0];
|
||||||
blockL.maxUid = pBlockData->uid ? pBlockData->uid : pBlockData->aUid[pBlockData->nRow - 1];
|
sstBlk.maxUid = pBlockData->uid ? pBlockData->uid : pBlockData->aUid[pBlockData->nRow - 1];
|
||||||
|
|
||||||
// write
|
// write
|
||||||
code = tsdbWriteBlockData(pCommitter->dWriter.pWriter, pBlockData, &blockL.bInfo, NULL, pCommitter->cmprAlg, 1);
|
code = tsdbWriteBlockData(pWriter, pBlockData, &sstBlk.bInfo, NULL, cmprAlg, 1);
|
||||||
if (code) goto _err;
|
if (code) goto _err;
|
||||||
|
|
||||||
// push SSttBlk
|
// push SSttBlk
|
||||||
if (taosArrayPush(pCommitter->dWriter.aSttBlk, &blockL) == NULL) {
|
if (taosArrayPush(aSttBlk, &sstBlk) == NULL) {
|
||||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
goto _err;
|
goto _err;
|
||||||
}
|
}
|
||||||
|
@ -647,7 +640,7 @@ static int32_t tsdbCommitLastBlock(SCommitter *pCommitter) {
|
||||||
return code;
|
return code;
|
||||||
|
|
||||||
_err:
|
_err:
|
||||||
tsdbError("vgId:%d tsdb commit last block failed since %s", TD_VID(pCommitter->pTsdb->pVnode), tstrerror(code));
|
tsdbError("vgId:%d tsdb commit last block failed since %s", TD_VID(pWriter->pTsdb->pVnode), tstrerror(code));
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -692,7 +685,7 @@ static int32_t tsdbMoveCommitData(SCommitter *pCommitter, TABLEID toTable) {
|
||||||
|
|
||||||
while (pCommitter->dReader.pBlockIdx && tTABLEIDCmprFn(pCommitter->dReader.pBlockIdx, &toTable) < 0) {
|
while (pCommitter->dReader.pBlockIdx && tTABLEIDCmprFn(pCommitter->dReader.pBlockIdx, &toTable) < 0) {
|
||||||
SBlockIdx blockIdx = *pCommitter->dReader.pBlockIdx;
|
SBlockIdx blockIdx = *pCommitter->dReader.pBlockIdx;
|
||||||
code = tsdbWriteBlock(pCommitter->dWriter.pWriter, &pCommitter->dReader.mBlock, &blockIdx);
|
code = tsdbWriteDataBlk(pCommitter->dWriter.pWriter, &pCommitter->dReader.mBlock, &blockIdx);
|
||||||
if (code) goto _err;
|
if (code) goto _err;
|
||||||
|
|
||||||
if (taosArrayPush(pCommitter->dWriter.aBlockIdx, &blockIdx) == NULL) {
|
if (taosArrayPush(pCommitter->dWriter.aBlockIdx, &blockIdx) == NULL) {
|
||||||
|
@ -1046,7 +1039,7 @@ static int32_t tsdbNextCommitRow(SCommitter *pCommitter) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (pCommitter->pIter->type == LAST_DATA_ITER) { // last file
|
} else if (pCommitter->pIter->type == STT_DATA_ITER) { // last file
|
||||||
pIter->iRow++;
|
pIter->iRow++;
|
||||||
if (pIter->iRow < pIter->bData.nRow) {
|
if (pIter->iRow < pIter->bData.nRow) {
|
||||||
pIter->r.uid = pIter->bData.uid ? pIter->bData.uid : pIter->bData.aUid[pIter->iRow];
|
pIter->r.uid = pIter->bData.uid ? pIter->bData.uid : pIter->bData.aUid[pIter->iRow];
|
||||||
|
@ -1124,15 +1117,14 @@ static int32_t tsdbCommitAheadBlock(SCommitter *pCommitter, SDataBlk *pDataBlk)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pBlockData->nRow >= pCommitter->maxRow) {
|
if (pBlockData->nRow >= pCommitter->maxRow) {
|
||||||
code = tsdbCommitDataBlock(pCommitter);
|
code =
|
||||||
|
tsdbWriteDataBlock(pCommitter->dWriter.pWriter, pBlockData, &pCommitter->dWriter.mBlock, pCommitter->cmprAlg);
|
||||||
if (code) goto _err;
|
if (code) goto _err;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pBlockData->nRow) {
|
code = tsdbWriteDataBlock(pCommitter->dWriter.pWriter, pBlockData, &pCommitter->dWriter.mBlock, pCommitter->cmprAlg);
|
||||||
code = tsdbCommitDataBlock(pCommitter);
|
|
||||||
if (code) goto _err;
|
if (code) goto _err;
|
||||||
}
|
|
||||||
|
|
||||||
return code;
|
return code;
|
||||||
|
|
||||||
|
@ -1193,7 +1185,7 @@ static int32_t tsdbCommitMergeBlock(SCommitter *pCommitter, SDataBlk *pDataBlk)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pBDataW->nRow >= pCommitter->maxRow) {
|
if (pBDataW->nRow >= pCommitter->maxRow) {
|
||||||
code = tsdbCommitDataBlock(pCommitter);
|
code = tsdbWriteDataBlock(pCommitter->dWriter.pWriter, pBDataW, &pCommitter->dWriter.mBlock, pCommitter->cmprAlg);
|
||||||
if (code) goto _err;
|
if (code) goto _err;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1210,15 +1202,13 @@ static int32_t tsdbCommitMergeBlock(SCommitter *pCommitter, SDataBlk *pDataBlk)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pBDataW->nRow >= pCommitter->maxRow) {
|
if (pBDataW->nRow >= pCommitter->maxRow) {
|
||||||
code = tsdbCommitDataBlock(pCommitter);
|
code = tsdbWriteDataBlock(pCommitter->dWriter.pWriter, pBDataW, &pCommitter->dWriter.mBlock, pCommitter->cmprAlg);
|
||||||
if (code) goto _err;
|
if (code) goto _err;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pBDataW->nRow) {
|
code = tsdbWriteDataBlock(pCommitter->dWriter.pWriter, pBDataW, &pCommitter->dWriter.mBlock, pCommitter->cmprAlg);
|
||||||
code = tsdbCommitDataBlock(pCommitter);
|
|
||||||
if (code) goto _err;
|
if (code) goto _err;
|
||||||
}
|
|
||||||
|
|
||||||
return code;
|
return code;
|
||||||
|
|
||||||
|
@ -1306,10 +1296,8 @@ static int32_t tsdbInitLastBlockIfNeed(SCommitter *pCommitter, TABLEID id) {
|
||||||
SBlockData *pBDatal = &pCommitter->dWriter.bDatal;
|
SBlockData *pBDatal = &pCommitter->dWriter.bDatal;
|
||||||
if (pBDatal->suid || pBDatal->uid) {
|
if (pBDatal->suid || pBDatal->uid) {
|
||||||
if ((pBDatal->suid != id.suid) || (id.suid == 0)) {
|
if ((pBDatal->suid != id.suid) || (id.suid == 0)) {
|
||||||
if (pBDatal->nRow) {
|
code = tsdbWriteSttBlock(pCommitter->dWriter.pWriter, pBDatal, pCommitter->dWriter.aSttBlk, pCommitter->cmprAlg);
|
||||||
code = tsdbCommitLastBlock(pCommitter);
|
|
||||||
if (code) goto _exit;
|
if (code) goto _exit;
|
||||||
}
|
|
||||||
tBlockDataReset(pBDatal);
|
tBlockDataReset(pBDatal);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1341,7 +1329,7 @@ static int32_t tsdbAppendLastBlock(SCommitter *pCommitter) {
|
||||||
if (code) goto _err;
|
if (code) goto _err;
|
||||||
|
|
||||||
if (pBDatal->nRow >= pCommitter->maxRow) {
|
if (pBDatal->nRow >= pCommitter->maxRow) {
|
||||||
code = tsdbCommitLastBlock(pCommitter);
|
code = tsdbWriteSttBlock(pCommitter->dWriter.pWriter, pBDatal, pCommitter->dWriter.aSttBlk, pCommitter->cmprAlg);
|
||||||
if (code) goto _err;
|
if (code) goto _err;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1393,10 +1381,11 @@ static int32_t tsdbCommitTableData(SCommitter *pCommitter, TABLEID id) {
|
||||||
|
|
||||||
if (pBData->nRow >= pCommitter->maxRow) {
|
if (pBData->nRow >= pCommitter->maxRow) {
|
||||||
if (pCommitter->toLastOnly) {
|
if (pCommitter->toLastOnly) {
|
||||||
code = tsdbCommitLastBlock(pCommitter);
|
code = tsdbWriteSttBlock(pCommitter->dWriter.pWriter, pBData, pCommitter->dWriter.aSttBlk, pCommitter->cmprAlg);
|
||||||
if (code) goto _err;
|
if (code) goto _err;
|
||||||
} else {
|
} else {
|
||||||
code = tsdbCommitDataBlock(pCommitter);
|
code =
|
||||||
|
tsdbWriteDataBlock(pCommitter->dWriter.pWriter, pBData, &pCommitter->dWriter.mBlock, pCommitter->cmprAlg);
|
||||||
if (code) goto _err;
|
if (code) goto _err;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1404,7 +1393,7 @@ static int32_t tsdbCommitTableData(SCommitter *pCommitter, TABLEID id) {
|
||||||
|
|
||||||
if (!pCommitter->toLastOnly && pBData->nRow) {
|
if (!pCommitter->toLastOnly && pBData->nRow) {
|
||||||
if (pBData->nRow > pCommitter->minRow) {
|
if (pBData->nRow > pCommitter->minRow) {
|
||||||
code = tsdbCommitDataBlock(pCommitter);
|
code = tsdbWriteDataBlock(pCommitter->dWriter.pWriter, pBData, &pCommitter->dWriter.mBlock, pCommitter->cmprAlg);
|
||||||
if (code) goto _err;
|
if (code) goto _err;
|
||||||
} else {
|
} else {
|
||||||
code = tsdbAppendLastBlock(pCommitter);
|
code = tsdbAppendLastBlock(pCommitter);
|
||||||
|
@ -1437,7 +1426,7 @@ static int32_t tsdbCommitFileDataImpl(SCommitter *pCommitter) {
|
||||||
tMapDataReset(&pCommitter->dWriter.mBlock);
|
tMapDataReset(&pCommitter->dWriter.mBlock);
|
||||||
|
|
||||||
// impl
|
// impl
|
||||||
code = tsdbCommitterUpdateTableSchema(pCommitter, id.suid, id.uid);
|
code = tsdbUpdateTableSchema(pCommitter->pTsdb->pVnode->pMeta, id.suid, id.uid, &pCommitter->skmTable);
|
||||||
if (code) goto _err;
|
if (code) goto _err;
|
||||||
code = tBlockDataInit(&pCommitter->dReader.bData, id.suid, id.uid, pCommitter->skmTable.pTSchema);
|
code = tBlockDataInit(&pCommitter->dReader.bData, id.suid, id.uid, pCommitter->skmTable.pTSchema);
|
||||||
if (code) goto _err;
|
if (code) goto _err;
|
||||||
|
@ -1455,7 +1444,7 @@ static int32_t tsdbCommitFileDataImpl(SCommitter *pCommitter) {
|
||||||
// end
|
// end
|
||||||
if (pCommitter->dWriter.mBlock.nItem > 0) {
|
if (pCommitter->dWriter.mBlock.nItem > 0) {
|
||||||
SBlockIdx blockIdx = {.suid = id.suid, .uid = id.uid};
|
SBlockIdx blockIdx = {.suid = id.suid, .uid = id.uid};
|
||||||
code = tsdbWriteBlock(pCommitter->dWriter.pWriter, &pCommitter->dWriter.mBlock, &blockIdx);
|
code = tsdbWriteDataBlk(pCommitter->dWriter.pWriter, &pCommitter->dWriter.mBlock, &blockIdx);
|
||||||
if (code) goto _err;
|
if (code) goto _err;
|
||||||
|
|
||||||
if (taosArrayPush(pCommitter->dWriter.aBlockIdx, &blockIdx) == NULL) {
|
if (taosArrayPush(pCommitter->dWriter.aBlockIdx, &blockIdx) == NULL) {
|
||||||
|
@ -1470,10 +1459,9 @@ static int32_t tsdbCommitFileDataImpl(SCommitter *pCommitter) {
|
||||||
code = tsdbMoveCommitData(pCommitter, id);
|
code = tsdbMoveCommitData(pCommitter, id);
|
||||||
if (code) goto _err;
|
if (code) goto _err;
|
||||||
|
|
||||||
if (pCommitter->dWriter.bDatal.nRow > 0) {
|
code = tsdbWriteSttBlock(pCommitter->dWriter.pWriter, &pCommitter->dWriter.bDatal, pCommitter->dWriter.aSttBlk,
|
||||||
code = tsdbCommitLastBlock(pCommitter);
|
pCommitter->cmprAlg);
|
||||||
if (code) goto _err;
|
if (code) goto _err;
|
||||||
}
|
|
||||||
|
|
||||||
return code;
|
return code;
|
||||||
|
|
||||||
|
|
|
@ -601,7 +601,7 @@ static int32_t doLoadFileBlock(STsdbReader* pReader, SArray* pIndexList, SBlockN
|
||||||
STableBlockScanInfo* pScanInfo = taosHashGet(pReader->status.pTableMap, &pBlockIdx->uid, sizeof(int64_t));
|
STableBlockScanInfo* pScanInfo = taosHashGet(pReader->status.pTableMap, &pBlockIdx->uid, sizeof(int64_t));
|
||||||
|
|
||||||
tMapDataReset(&pScanInfo->mapData);
|
tMapDataReset(&pScanInfo->mapData);
|
||||||
tsdbReadBlock(pReader->pFileReader, pBlockIdx, &pScanInfo->mapData);
|
tsdbReadDataBlk(pReader->pFileReader, pBlockIdx, &pScanInfo->mapData);
|
||||||
|
|
||||||
sizeInDisk += pScanInfo->mapData.nData;
|
sizeInDisk += pScanInfo->mapData.nData;
|
||||||
for (int32_t j = 0; j < pScanInfo->mapData.nItem; ++j) {
|
for (int32_t j = 0; j < pScanInfo->mapData.nItem; ++j) {
|
||||||
|
|
|
@ -418,21 +418,21 @@ _err:
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t tsdbWriteBlock(SDataFWriter *pWriter, SMapData *mBlock, SBlockIdx *pBlockIdx) {
|
int32_t tsdbWriteDataBlk(SDataFWriter *pWriter, SMapData *mDataBlk, SBlockIdx *pBlockIdx) {
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
SHeadFile *pHeadFile = &pWriter->fHead;
|
SHeadFile *pHeadFile = &pWriter->fHead;
|
||||||
int64_t size;
|
int64_t size;
|
||||||
int64_t n;
|
int64_t n;
|
||||||
|
|
||||||
ASSERT(mBlock->nItem > 0);
|
ASSERT(mDataBlk->nItem > 0);
|
||||||
|
|
||||||
// alloc
|
// alloc
|
||||||
size = tPutMapData(NULL, mBlock);
|
size = tPutMapData(NULL, mDataBlk);
|
||||||
code = tRealloc(&pWriter->aBuf[0], size);
|
code = tRealloc(&pWriter->aBuf[0], size);
|
||||||
if (code) goto _err;
|
if (code) goto _err;
|
||||||
|
|
||||||
// build
|
// build
|
||||||
n = tPutMapData(pWriter->aBuf[0], mBlock);
|
n = tPutMapData(pWriter->aBuf[0], mDataBlk);
|
||||||
|
|
||||||
// write
|
// write
|
||||||
code = tsdbWriteFile(pWriter->pHeadFD, pHeadFile->size, pWriter->aBuf[0], size);
|
code = tsdbWriteFile(pWriter->pHeadFD, pHeadFile->size, pWriter->aBuf[0], size);
|
||||||
|
@ -446,7 +446,7 @@ int32_t tsdbWriteBlock(SDataFWriter *pWriter, SMapData *mBlock, SBlockIdx *pBloc
|
||||||
tsdbTrace("vgId:%d, write block, file ID:%d commit ID:%d suid:%" PRId64 " uid:%" PRId64 " offset:%" PRId64
|
tsdbTrace("vgId:%d, write block, file ID:%d commit ID:%d suid:%" PRId64 " uid:%" PRId64 " offset:%" PRId64
|
||||||
" size:%" PRId64 " nItem:%d",
|
" size:%" PRId64 " nItem:%d",
|
||||||
TD_VID(pWriter->pTsdb->pVnode), pWriter->wSet.fid, pHeadFile->commitID, pBlockIdx->suid, pBlockIdx->uid,
|
TD_VID(pWriter->pTsdb->pVnode), pWriter->wSet.fid, pHeadFile->commitID, pBlockIdx->suid, pBlockIdx->uid,
|
||||||
pBlockIdx->offset, pBlockIdx->size, mBlock->nItem);
|
pBlockIdx->offset, pBlockIdx->size, mDataBlk->nItem);
|
||||||
return code;
|
return code;
|
||||||
|
|
||||||
_err:
|
_err:
|
||||||
|
@ -872,7 +872,7 @@ _err:
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t tsdbReadBlock(SDataFReader *pReader, SBlockIdx *pBlockIdx, SMapData *mBlock) {
|
int32_t tsdbReadDataBlk(SDataFReader *pReader, SBlockIdx *pBlockIdx, SMapData *mDataBlk) {
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
int64_t offset = pBlockIdx->offset;
|
int64_t offset = pBlockIdx->offset;
|
||||||
int64_t size = pBlockIdx->size;
|
int64_t size = pBlockIdx->size;
|
||||||
|
@ -886,7 +886,7 @@ int32_t tsdbReadBlock(SDataFReader *pReader, SBlockIdx *pBlockIdx, SMapData *mBl
|
||||||
if (code) goto _err;
|
if (code) goto _err;
|
||||||
|
|
||||||
// decode
|
// decode
|
||||||
int64_t n = tGetMapData(pReader->aBuf[0], mBlock);
|
int64_t n = tGetMapData(pReader->aBuf[0], mDataBlk);
|
||||||
if (n < 0) {
|
if (n < 0) {
|
||||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
goto _err;
|
goto _err;
|
||||||
|
@ -1053,6 +1053,29 @@ _err:
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int32_t tsdbReadDataBlockEx(SDataFReader *pReader, SDataBlk *pDataBlk, SBlockData *pBlockData) {
|
||||||
|
int32_t code = 0;
|
||||||
|
SBlockInfo *pBlockInfo = &pDataBlk->aSubBlock[0];
|
||||||
|
|
||||||
|
// alloc
|
||||||
|
code = tRealloc(&pReader->aBuf[0], pBlockInfo->szBlock);
|
||||||
|
if (code) goto _err;
|
||||||
|
|
||||||
|
// read
|
||||||
|
code = tsdbReadFile(pReader->pDataFD, pBlockInfo->offset, pReader->aBuf[0], pBlockInfo->szBlock);
|
||||||
|
if (code) goto _err;
|
||||||
|
|
||||||
|
// decmpr
|
||||||
|
code = tDecmprBlockData(pReader->aBuf[0], pBlockInfo->szBlock, pBlockData, &pReader->aBuf[1]);
|
||||||
|
if (code) goto _err;
|
||||||
|
|
||||||
|
return code;
|
||||||
|
|
||||||
|
_err:
|
||||||
|
tsdbError("vgId:%d tsdb read data block ex failed since %s", TD_VID(pReader->pTsdb->pVnode), tstrerror(code));
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
int32_t tsdbReadDataBlock(SDataFReader *pReader, SDataBlk *pDataBlk, SBlockData *pBlockData) {
|
int32_t tsdbReadDataBlock(SDataFReader *pReader, SDataBlk *pDataBlk, SBlockData *pBlockData) {
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
|
|
||||||
|
@ -1147,8 +1170,8 @@ int32_t tsdbDelFWriterOpen(SDelFWriter **ppWriter, SDelFile *pFile, STsdb *pTsdb
|
||||||
pDelFWriter->fDel = *pFile;
|
pDelFWriter->fDel = *pFile;
|
||||||
|
|
||||||
tsdbDelFileName(pTsdb, pFile, fname);
|
tsdbDelFileName(pTsdb, pFile, fname);
|
||||||
code =
|
int32_t flag = TD_FILE_READ | TD_FILE_WRITE | TD_FILE_CREATE;
|
||||||
tsdbOpenFile(fname, TSDB_DEFAULT_PAGE_SIZE, TD_FILE_READ | TD_FILE_WRITE | TD_FILE_CREATE, &pDelFWriter->pWriteH);
|
code = tsdbOpenFile(fname, TSDB_DEFAULT_PAGE_SIZE, flag, &pDelFWriter->pWriteH);
|
||||||
if (code) goto _err;
|
if (code) goto _err;
|
||||||
|
|
||||||
// update header
|
// update header
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -354,7 +354,8 @@ int32_t vnodeSnapWrite(SVSnapWriter *pWriter, uint8_t *pData, uint32_t nData) {
|
||||||
code = metaSnapWrite(pWriter->pMetaSnapWriter, pData, nData);
|
code = metaSnapWrite(pWriter->pMetaSnapWriter, pData, nData);
|
||||||
if (code) goto _err;
|
if (code) goto _err;
|
||||||
} break;
|
} break;
|
||||||
case SNAP_DATA_TSDB: {
|
case SNAP_DATA_TSDB:
|
||||||
|
case SNAP_DATA_DEL: {
|
||||||
// tsdb
|
// tsdb
|
||||||
if (pWriter->pTsdbSnapWriter == NULL) {
|
if (pWriter->pTsdbSnapWriter == NULL) {
|
||||||
code = tsdbSnapWriterOpen(pVnode->pTsdb, pWriter->sver, pWriter->ever, &pWriter->pTsdbSnapWriter);
|
code = tsdbSnapWriterOpen(pVnode->pTsdb, pWriter->sver, pWriter->ever, &pWriter->pTsdbSnapWriter);
|
||||||
|
|
Loading…
Reference in New Issue