more tsdb snapshot writer

This commit is contained in:
Hongze Cheng 2022-07-06 12:03:08 +00:00
parent 9a90714ecc
commit be85e27234
1 changed files with 32 additions and 1 deletions

View File

@ -323,6 +323,7 @@ struct STsdbSnapWriter {
SDataFWriter* pDataFWriter; SDataFWriter* pDataFWriter;
SArray* aBlockIdxN; SArray* aBlockIdxN;
SMapData mBlockN; SMapData mBlockN;
SBlockData nBlockData;
// for del file // for del file
SDelFReader* pDelFReader; SDelFReader* pDelFReader;
SDelFWriter* pDelFWriter; SDelFWriter* pDelFWriter;
@ -368,6 +369,24 @@ _err:
return code; return code;
} }
static int32_t tsdbSnapWriteAppendData(STsdbSnapWriter* pWriter, uint8_t* pData, uint32_t nData) {
int32_t code = 0;
int32_t iRow = 0; // todo
int32_t nRow = 0; // todo
SBlockData* pBlockData = NULL; // todo
while (iRow < nRow) {
code = tBlockDataAppendRow(&pWriter->nBlockData, &tsdbRowFromBlockData(pBlockData, iRow), NULL);
if (code) goto _err;
}
return code;
_err:
tsdbError("vgId:%d tsdb snapshot write append data failed since %s", TD_VID(pWriter->pTsdb->pVnode), tstrerror(code));
return code;
}
static int32_t tsdbSnapWriteData(STsdbSnapWriter* pWriter, uint8_t* pData, uint32_t nData) { static int32_t tsdbSnapWriteData(STsdbSnapWriter* pWriter, uint8_t* pData, uint32_t nData) {
int32_t code = 0; int32_t code = 0;
STsdb* pTsdb = pWriter->pTsdb; STsdb* pTsdb = pWriter->pTsdb;
@ -428,9 +447,21 @@ static int32_t tsdbSnapWriteData(STsdbSnapWriter* pWriter, uint8_t* pData, uint3
if (c == 0) { if (c == 0) {
// merge // merge
} else if (c < 0) { } else if (c < 0) {
// write the block code = tsdbSnapWriteAppendData(pWriter, pData, nData);
if (code) goto _err;
} else { } else {
// commit the block // commit the block
code = tsdbReadBlock(pWriter->pDataFReader, pBlockIdx, &pWriter->mBlock, NULL);
if (code) goto _err;
SBlockIdx blockIdx = {.suid = pBlockIdx->suid, .uid = pBlockIdx->uid};
code = tsdbWriteBlock(pWriter->pDataFWriter, &pWriter->mBlock, NULL, &blockIdx);
if (code) goto _err;
if (taosArrayPush(pWriter->aBlockIdxN, &blockIdx) == NULL) {
code = TSDB_CODE_OUT_OF_MEMORY;
goto _err;
}
} }
} }
} }