more code
This commit is contained in:
parent
47b961018c
commit
a72633d715
|
@ -93,7 +93,7 @@ static FORCE_INLINE int32_t taosGetTbHashVal(const char *tbname, int32_t tblen,
|
||||||
}
|
}
|
||||||
|
|
||||||
#define TSDB_CHECK_CODE(CODE, LINO, LABEL) \
|
#define TSDB_CHECK_CODE(CODE, LINO, LABEL) \
|
||||||
if (CODE) { \
|
if ((CODE)) { \
|
||||||
LINO = __LINE__; \
|
LINO = __LINE__; \
|
||||||
goto LABEL; \
|
goto LABEL; \
|
||||||
}
|
}
|
||||||
|
|
|
@ -224,7 +224,7 @@ int32_t tsdbTbDataIterCreate(STbData *pTbData, TSDBKEY *pFrom, int8_t backward,
|
||||||
void *tsdbTbDataIterDestroy(STbDataIter *pIter);
|
void *tsdbTbDataIterDestroy(STbDataIter *pIter);
|
||||||
void tsdbTbDataIterOpen(STbData *pTbData, TSDBKEY *pFrom, int8_t backward, STbDataIter *pIter);
|
void tsdbTbDataIterOpen(STbData *pTbData, TSDBKEY *pFrom, int8_t backward, STbDataIter *pIter);
|
||||||
bool tsdbTbDataIterNext(STbDataIter *pIter);
|
bool tsdbTbDataIterNext(STbDataIter *pIter);
|
||||||
void tsdbMemTableCountRows(SMemTable *pMemTable, SHashObj* pTableMap, int64_t *rowsNum);
|
void tsdbMemTableCountRows(SMemTable *pMemTable, SHashObj *pTableMap, int64_t *rowsNum);
|
||||||
|
|
||||||
// STbData
|
// STbData
|
||||||
int32_t tsdbGetNRowsInTbData(STbData *pTbData);
|
int32_t tsdbGetNRowsInTbData(STbData *pTbData);
|
||||||
|
|
|
@ -27,20 +27,23 @@ typedef struct {
|
||||||
int8_t sttTrigger;
|
int8_t sttTrigger;
|
||||||
SArray *aTbDataP;
|
SArray *aTbDataP;
|
||||||
// context
|
// context
|
||||||
TSKEY nextKey;
|
TSKEY nextKey;
|
||||||
int32_t fid;
|
int32_t fid;
|
||||||
int32_t expLevel;
|
int32_t expLevel;
|
||||||
TSKEY minKey;
|
TSKEY minKey;
|
||||||
TSKEY maxKey;
|
TSKEY maxKey;
|
||||||
|
struct SFileSet *pFileSet;
|
||||||
// writer
|
// writer
|
||||||
SArray *aFileOp;
|
SArray *aFileOp;
|
||||||
struct SSttFWriter *pWriter;
|
struct SSttFWriter *pWriter;
|
||||||
} SCommitter;
|
} SCommitter;
|
||||||
|
|
||||||
static int32_t open_committer_writer(SCommitter *pCommitter) {
|
static int32_t open_committer_writer(SCommitter *pCommitter) {
|
||||||
int32_t code;
|
int32_t code = 0;
|
||||||
int32_t lino;
|
int32_t lino;
|
||||||
|
|
||||||
|
STsdb *pTsdb = pCommitter->pTsdb;
|
||||||
|
|
||||||
struct SSttFWriterConf conf = {
|
struct SSttFWriterConf conf = {
|
||||||
.pTsdb = pCommitter->pTsdb,
|
.pTsdb = pCommitter->pTsdb,
|
||||||
.maxRow = pCommitter->maxRow,
|
.maxRow = pCommitter->maxRow,
|
||||||
|
@ -51,20 +54,21 @@ static int32_t open_committer_writer(SCommitter *pCommitter) {
|
||||||
.aBuf = NULL,
|
.aBuf = NULL,
|
||||||
};
|
};
|
||||||
|
|
||||||
// pCommitter->pTsdb->pFS = NULL;
|
if (pCommitter->pFileSet) {
|
||||||
// taosbsearch(pCommitter->pTsdb->pFS->aFileSet, &pCommitter->fid, tsdbCompareFid, &lino);
|
ASSERTS(0, "TODO: Not implemented yet");
|
||||||
struct SFileSet *pSet = NULL;
|
|
||||||
if (pSet == NULL) {
|
|
||||||
conf.file = (struct STFile){
|
|
||||||
.cid = 1,
|
|
||||||
.fid = pCommitter->fid,
|
|
||||||
.diskId = (SDiskID){0},
|
|
||||||
.type = TSDB_FTYPE_STT,
|
|
||||||
};
|
|
||||||
tsdbTFileInit(pCommitter->pTsdb, &conf.file);
|
|
||||||
} else {
|
} else {
|
||||||
// TODO
|
conf.file.type = TSDB_FTYPE_STT;
|
||||||
ASSERT(0);
|
|
||||||
|
if (tfsAllocDisk(pTsdb->pVnode->pTfs, pCommitter->expLevel, &conf.file.diskId) < 0) {
|
||||||
|
code = TSDB_CODE_FS_NO_VALID_DISK;
|
||||||
|
TSDB_CHECK_CODE(code, lino, _exit);
|
||||||
|
}
|
||||||
|
|
||||||
|
conf.file.size = 0;
|
||||||
|
conf.file.cid = 1;
|
||||||
|
conf.file.fid = pCommitter->fid;
|
||||||
|
|
||||||
|
tsdbTFileInit(pTsdb, &conf.file);
|
||||||
}
|
}
|
||||||
|
|
||||||
code = tsdbSttFWriterOpen(&conf, &pCommitter->pWriter);
|
code = tsdbSttFWriterOpen(&conf, &pCommitter->pWriter);
|
||||||
|
@ -72,8 +76,13 @@ static int32_t open_committer_writer(SCommitter *pCommitter) {
|
||||||
|
|
||||||
_exit:
|
_exit:
|
||||||
if (code) {
|
if (code) {
|
||||||
tsdbError("vgId:%d %s failed at line %d since %s, fid:%d", TD_VID(pCommitter->pTsdb->pVnode), __func__, lino,
|
tsdbError( //
|
||||||
tstrerror(code), pCommitter->fid);
|
"vgId:%d %s failed at line %d since %s, fid:%d", //
|
||||||
|
TD_VID(pCommitter->pTsdb->pVnode), //
|
||||||
|
__func__, //
|
||||||
|
lino, //
|
||||||
|
tstrerror(code), //
|
||||||
|
pCommitter->fid);
|
||||||
}
|
}
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
@ -92,10 +101,19 @@ static int32_t tsdbCommitWriteTSData(SCommitter *pCommitter, TABLEID *tbid, TSDB
|
||||||
|
|
||||||
_exit:
|
_exit:
|
||||||
if (code) {
|
if (code) {
|
||||||
tsdbError("vgId:%d failed at line %d since %s", TD_VID(pCommitter->pTsdb->pVnode), lino, tstrerror(code));
|
tsdbError( //
|
||||||
|
"vgId:%d failed at line %d since %s", //
|
||||||
|
TD_VID(pCommitter->pTsdb->pVnode), //
|
||||||
|
lino, //
|
||||||
|
tstrerror(code));
|
||||||
} else {
|
} else {
|
||||||
tsdbTrace("vgId:%d %s done, fid:%d suid:%" PRId64 " uid:%" PRId64 " ts:%" PRId64 " version:%" PRId64,
|
tsdbTrace("vgId:%d %s done, fid:%d suid:%" PRId64 " uid:%" PRId64 " ts:%" PRId64 " version:%" PRId64, //
|
||||||
TD_VID(pCommitter->pTsdb->pVnode), __func__, pCommitter->fid, tbid->suid, tbid->uid, TSDBROW_KEY(pRow).ts,
|
TD_VID(pCommitter->pTsdb->pVnode), //
|
||||||
|
__func__, //
|
||||||
|
pCommitter->fid, //
|
||||||
|
tbid->suid, //
|
||||||
|
tbid->uid, //
|
||||||
|
TSDBROW_KEY(pRow).ts, //
|
||||||
TSDBROW_KEY(pRow).version);
|
TSDBROW_KEY(pRow).version);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -206,6 +224,8 @@ static int32_t start_commit_file_set(SCommitter *pCommitter) {
|
||||||
pCommitter->expLevel = tsdbFidLevel(pCommitter->fid, &pCommitter->pTsdb->keepCfg, taosGetTimestampSec());
|
pCommitter->expLevel = tsdbFidLevel(pCommitter->fid, &pCommitter->pTsdb->keepCfg, taosGetTimestampSec());
|
||||||
pCommitter->nextKey = TSKEY_MAX;
|
pCommitter->nextKey = TSKEY_MAX;
|
||||||
|
|
||||||
|
pCommitter->pFileSet = NULL; // TODO: need to search the file system
|
||||||
|
|
||||||
tsdbDebug( //
|
tsdbDebug( //
|
||||||
"vgId:%d %s done, fid:%d minKey:%" PRId64 " maxKey:%" PRId64 " expLevel:%d", //
|
"vgId:%d %s done, fid:%d minKey:%" PRId64 " maxKey:%" PRId64 " expLevel:%d", //
|
||||||
TD_VID(pCommitter->pTsdb->pVnode), //
|
TD_VID(pCommitter->pTsdb->pVnode), //
|
||||||
|
@ -219,13 +239,24 @@ static int32_t start_commit_file_set(SCommitter *pCommitter) {
|
||||||
|
|
||||||
static int32_t end_commit_file_set(SCommitter *pCommitter) {
|
static int32_t end_commit_file_set(SCommitter *pCommitter) {
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
int32_t lino = 0;
|
int32_t lino;
|
||||||
|
|
||||||
// TODO
|
if (pCommitter->pWriter == NULL) return 0;
|
||||||
|
|
||||||
|
struct SFileOp *pFileOp = taosArrayReserve(pCommitter->aFileOp, 1);
|
||||||
|
if (pFileOp == NULL) {
|
||||||
|
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
TSDB_CHECK_CODE(code, lino, _exit);
|
||||||
|
}
|
||||||
|
|
||||||
|
code = tsdbSttFWriterClose(&pCommitter->pWriter, 0, pFileOp);
|
||||||
|
TSDB_CHECK_CODE(code, lino, _exit);
|
||||||
|
|
||||||
_exit:
|
_exit:
|
||||||
if (code) {
|
if (code) {
|
||||||
tsdbError("vgId:%d failed at line %d since %s", TD_VID(pCommitter->pTsdb->pVnode), lino, tstrerror(code));
|
tsdbError("vgId:%d failed at line %d since %s", TD_VID(pCommitter->pTsdb->pVnode), lino, tstrerror(code));
|
||||||
|
} else {
|
||||||
|
tsdbDebug("vgId:%d %s done, fid:%d", TD_VID(pCommitter->pTsdb->pVnode), __func__, pCommitter->fid);
|
||||||
}
|
}
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,8 +34,8 @@ typedef enum {
|
||||||
|
|
||||||
struct SFileOp {
|
struct SFileOp {
|
||||||
tsdb_fop_t op;
|
tsdb_fop_t op;
|
||||||
struct STFile oFile; // old file state
|
struct STFile oState; // old file state
|
||||||
struct STFile nFile; // new file state
|
struct STFile nState; // new file state
|
||||||
};
|
};
|
||||||
|
|
||||||
struct SFileSet {
|
struct SFileSet {
|
||||||
|
|
|
@ -29,15 +29,17 @@ typedef struct {
|
||||||
|
|
||||||
struct SSttFWriter {
|
struct SSttFWriter {
|
||||||
struct SSttFWriterConf config;
|
struct SSttFWriterConf config;
|
||||||
|
// file
|
||||||
|
struct STFile tFile;
|
||||||
// data
|
// data
|
||||||
|
SFSttFooter footer;
|
||||||
SBlockData bData;
|
SBlockData bData;
|
||||||
SDelBlock dData;
|
SDelBlock dData;
|
||||||
STbStatisBlock sData;
|
STbStatisBlock sData;
|
||||||
SArray *aSttBlk; // SArray<SSttBlk>
|
SArray *aSttBlk; // SArray<SSttBlk>
|
||||||
SArray *aDelBlk; // SArray<SDelBlk>
|
SArray *aDelBlk; // SArray<SDelBlk>
|
||||||
SArray *aStatisBlk; // SArray<STbStatisBlk>
|
SArray *aStatisBlk; // SArray<STbStatisBlk>
|
||||||
void *bloomFilter;
|
void *bloomFilter; // TODO
|
||||||
SFSttFooter footer;
|
|
||||||
// helper data
|
// helper data
|
||||||
SSkmInfo skmTb;
|
SSkmInfo skmTb;
|
||||||
SSkmInfo skmRow;
|
SSkmInfo skmRow;
|
||||||
|
@ -71,20 +73,33 @@ static int32_t write_timeseries_block(struct SSttFWriter *pWriter) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// compress data block
|
// compress data block
|
||||||
code = tCmprBlockData(pBData, pWriter->config.cmprAlg, NULL, NULL, pWriter->config.aBuf, pWriter->aBufSize);
|
TSDB_CHECK_CODE( //
|
||||||
TSDB_CHECK_CODE(code, lino, _exit);
|
code = tCmprBlockData( //
|
||||||
|
pBData, //
|
||||||
|
pWriter->config.cmprAlg, //
|
||||||
|
NULL, //
|
||||||
|
NULL, //
|
||||||
|
pWriter->config.aBuf, //
|
||||||
|
pWriter->aBufSize), //
|
||||||
|
lino, //
|
||||||
|
_exit);
|
||||||
|
|
||||||
pSttBlk->bInfo.offset = pWriter->config.file.size;
|
pSttBlk->bInfo.offset = pWriter->tFile.size;
|
||||||
pSttBlk->bInfo.szKey = pWriter->aBufSize[2] + pWriter->aBufSize[3];
|
pSttBlk->bInfo.szKey = pWriter->aBufSize[2] + pWriter->aBufSize[3];
|
||||||
pSttBlk->bInfo.szBlock = pWriter->aBufSize[0] + pWriter->aBufSize[1] + pSttBlk->bInfo.szKey;
|
pSttBlk->bInfo.szBlock = pWriter->aBufSize[0] + pWriter->aBufSize[1] + pSttBlk->bInfo.szKey;
|
||||||
|
|
||||||
for (int32_t iBuf = 3; iBuf >= 0; iBuf--) {
|
for (int32_t iBuf = 3; iBuf >= 0; iBuf--) {
|
||||||
if (pWriter->aBufSize[iBuf]) {
|
if (pWriter->aBufSize[iBuf]) {
|
||||||
code =
|
TSDB_CHECK_CODE( //
|
||||||
tsdbWriteFile(pWriter->pFd, pWriter->config.file.size, pWriter->config.aBuf[iBuf], pWriter->aBufSize[iBuf]);
|
code = tsdbWriteFile( //
|
||||||
TSDB_CHECK_CODE(code, lino, _exit);
|
pWriter->pFd, //
|
||||||
|
pWriter->tFile.size, //
|
||||||
|
pWriter->config.aBuf[iBuf], //
|
||||||
|
pWriter->aBufSize[iBuf]), //
|
||||||
|
lino, //
|
||||||
|
_exit);
|
||||||
|
|
||||||
pWriter->config.file.size += pWriter->aBufSize[iBuf];
|
pWriter->tFile.size += pWriter->aBufSize[iBuf];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -92,8 +107,12 @@ static int32_t write_timeseries_block(struct SSttFWriter *pWriter) {
|
||||||
|
|
||||||
_exit:
|
_exit:
|
||||||
if (code) {
|
if (code) {
|
||||||
tsdbError("vgId:%d %s failed at line %d since %s", TD_VID(pWriter->config.pTsdb->pVnode), __func__, lino,
|
tsdbError( //
|
||||||
tstrerror(code));
|
"vgId:%d %s failed at line %d since %s", //
|
||||||
|
TD_VID(pWriter->config.pTsdb->pVnode), //
|
||||||
|
__func__, //
|
||||||
|
lino, //
|
||||||
|
tstrerror(code));
|
||||||
} else {
|
} else {
|
||||||
// tsdbTrace();
|
// tsdbTrace();
|
||||||
}
|
}
|
||||||
|
@ -106,8 +125,7 @@ static int32_t write_statistics_block(struct SSttFWriter *pWriter) {
|
||||||
|
|
||||||
STbStatisBlk *pStatisBlk = (STbStatisBlk *)taosArrayReserve(pWriter->aStatisBlk, 1);
|
STbStatisBlk *pStatisBlk = (STbStatisBlk *)taosArrayReserve(pWriter->aStatisBlk, 1);
|
||||||
if (pStatisBlk == NULL) {
|
if (pStatisBlk == NULL) {
|
||||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
TSDB_CHECK_CODE(code = TSDB_CODE_OUT_OF_MEMORY, lino, _exit);
|
||||||
TSDB_CHECK_CODE(code, lino, _exit);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pStatisBlk->nRow = pWriter->sData.nRow;
|
pStatisBlk->nRow = pWriter->sData.nRow;
|
||||||
|
@ -121,24 +139,35 @@ static int32_t write_statistics_block(struct SSttFWriter *pWriter) {
|
||||||
if (pStatisBlk->maxVer < pWriter->sData.aData[2][iRow]) pStatisBlk->maxVer = pWriter->sData.aData[2][iRow];
|
if (pStatisBlk->maxVer < pWriter->sData.aData[2][iRow]) pStatisBlk->maxVer = pWriter->sData.aData[2][iRow];
|
||||||
}
|
}
|
||||||
|
|
||||||
pStatisBlk->dp.offset = pWriter->config.file.size;
|
pStatisBlk->dp.offset = pWriter->tFile.size;
|
||||||
pStatisBlk->dp.size = 0; // TODO
|
pStatisBlk->dp.size = 0;
|
||||||
|
|
||||||
|
// TODO: add compression here
|
||||||
int64_t tsize = sizeof(int64_t) * pWriter->sData.nRow;
|
int64_t tsize = sizeof(int64_t) * pWriter->sData.nRow;
|
||||||
for (int32_t i = 0; i < ARRAY_SIZE(pWriter->sData.aData); i++) {
|
for (int32_t i = 0; i < ARRAY_SIZE(pWriter->sData.aData); i++) {
|
||||||
code = tsdbWriteFile(pWriter->pFd, pWriter->config.file.size, (const uint8_t *)pWriter->sData.aData[i], tsize);
|
TSDB_CHECK_CODE( //
|
||||||
TSDB_CHECK_CODE(code, lino, _exit);
|
code = tsdbWriteFile( //
|
||||||
|
pWriter->pFd, //
|
||||||
|
pWriter->tFile.size, //
|
||||||
|
(const uint8_t *)pWriter->sData.aData[i], //
|
||||||
|
tsize), //
|
||||||
|
lino, //
|
||||||
|
_exit);
|
||||||
|
|
||||||
pStatisBlk->dp.size += tsize;
|
pStatisBlk->dp.size += tsize;
|
||||||
pWriter->config.file.size += tsize;
|
pWriter->tFile.size += tsize;
|
||||||
}
|
}
|
||||||
|
|
||||||
tTbStatisBlockClear(&pWriter->sData);
|
tTbStatisBlockClear(&pWriter->sData);
|
||||||
|
|
||||||
_exit:
|
_exit:
|
||||||
if (code) {
|
if (code) {
|
||||||
tsdbError("vgId:%d %s failed at line %d since %s", TD_VID(pWriter->config.pTsdb->pVnode), __func__, lino,
|
tsdbError( //
|
||||||
tstrerror(code));
|
"vgId:%d %s failed at line %d since %s", //
|
||||||
|
TD_VID(pWriter->config.pTsdb->pVnode), //
|
||||||
|
__func__, //
|
||||||
|
lino, //
|
||||||
|
tstrerror(code));
|
||||||
} else {
|
} else {
|
||||||
// tsdbTrace();
|
// tsdbTrace();
|
||||||
}
|
}
|
||||||
|
@ -274,12 +303,27 @@ static int32_t write_file_header(struct SSttFWriter *pWriter) {
|
||||||
static int32_t create_stt_fwriter(const struct SSttFWriterConf *pConf, struct SSttFWriter **ppWriter) {
|
static int32_t create_stt_fwriter(const struct SSttFWriterConf *pConf, struct SSttFWriter **ppWriter) {
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
|
|
||||||
if ((ppWriter[0] = taosMemoryCalloc(1, sizeof(*ppWriter[0]))) == NULL) {
|
// alloc
|
||||||
|
if (((ppWriter[0] = taosMemoryCalloc(1, sizeof(*ppWriter[0]))) == NULL) //
|
||||||
|
|| ((ppWriter[0]->aSttBlk = taosArrayInit(64, sizeof(SSttBlk))) == NULL) //
|
||||||
|
|| ((ppWriter[0]->aDelBlk = taosArrayInit(64, sizeof(SDelBlk))) == NULL) //
|
||||||
|
|| ((ppWriter[0]->aStatisBlk = taosArrayInit(64, sizeof(STbStatisBlock))) == NULL) //
|
||||||
|
) {
|
||||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
goto _exit;
|
goto _exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ((code = tBlockDataCreate(&ppWriter[0]->bData)) //
|
||||||
|
|| (code = tDelBlockCreate(&ppWriter[0]->dData, pConf->maxRow)) //
|
||||||
|
|| (code = tTbStatisBlockCreate(&ppWriter[0]->sData, pConf->maxRow)) //
|
||||||
|
) {
|
||||||
|
goto _exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
// init
|
||||||
ppWriter[0]->config = pConf[0];
|
ppWriter[0]->config = pConf[0];
|
||||||
|
ppWriter[0]->tFile = pConf->file;
|
||||||
|
ppWriter[0]->footer.prevFooter = ppWriter[0]->tFile.size;
|
||||||
if (pConf->pSkmTb == NULL) {
|
if (pConf->pSkmTb == NULL) {
|
||||||
ppWriter[0]->config.pSkmTb = &ppWriter[0]->skmTb;
|
ppWriter[0]->config.pSkmTb = &ppWriter[0]->skmTb;
|
||||||
}
|
}
|
||||||
|
@ -290,40 +334,14 @@ static int32_t create_stt_fwriter(const struct SSttFWriterConf *pConf, struct SS
|
||||||
ppWriter[0]->config.aBuf = ppWriter[0]->aBuf;
|
ppWriter[0]->config.aBuf = ppWriter[0]->aBuf;
|
||||||
}
|
}
|
||||||
|
|
||||||
// time-series data block
|
|
||||||
tBlockDataCreate(&ppWriter[0]->bData);
|
|
||||||
if ((ppWriter[0]->aSttBlk = taosArrayInit(64, sizeof(SSttBlk))) == NULL) {
|
|
||||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
|
||||||
goto _exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
// deleted data block
|
|
||||||
if ((code = tDelBlockCreate(&ppWriter[0]->dData, pConf->maxRow))) goto _exit;
|
|
||||||
if ((ppWriter[0]->aDelBlk = taosArrayInit(64, sizeof(SDelBlk))) == NULL) {
|
|
||||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
|
||||||
goto _exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
// statistics data block
|
|
||||||
if ((code = tTbStatisBlockCreate(&ppWriter[0]->sData, pConf->maxRow))) goto _exit;
|
|
||||||
if ((ppWriter[0]->aStatisBlk = taosArrayInit(64, sizeof(STbStatisBlock))) == NULL) {
|
|
||||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
|
||||||
goto _exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: bloom filter
|
|
||||||
|
|
||||||
_exit:
|
_exit:
|
||||||
if (code && ppWriter[0]) {
|
if (code && ppWriter[0]) {
|
||||||
// statistics data block
|
|
||||||
taosArrayDestroy(ppWriter[0]->aStatisBlk);
|
|
||||||
tTbStatisBlockDestroy(&ppWriter[0]->sData);
|
tTbStatisBlockDestroy(&ppWriter[0]->sData);
|
||||||
// deleted data block
|
|
||||||
taosArrayDestroy(ppWriter[0]->aDelBlk);
|
|
||||||
tDelBlockDestroy(&ppWriter[0]->dData);
|
tDelBlockDestroy(&ppWriter[0]->dData);
|
||||||
// time-series data block
|
|
||||||
taosArrayDestroy(ppWriter[0]->aSttBlk);
|
|
||||||
tBlockDataDestroy(&ppWriter[0]->bData);
|
tBlockDataDestroy(&ppWriter[0]->bData);
|
||||||
|
taosArrayDestroy(ppWriter[0]->aStatisBlk);
|
||||||
|
taosArrayDestroy(ppWriter[0]->aDelBlk);
|
||||||
|
taosArrayDestroy(ppWriter[0]->aSttBlk);
|
||||||
taosMemoryFree(ppWriter[0]);
|
taosMemoryFree(ppWriter[0]);
|
||||||
ppWriter[0] = NULL;
|
ppWriter[0] = NULL;
|
||||||
}
|
}
|
||||||
|
@ -354,19 +372,48 @@ static int32_t open_stt_fwriter(struct SSttFWriter *pWriter) {
|
||||||
int32_t lino;
|
int32_t lino;
|
||||||
uint8_t hdr[TSDB_FHDR_SIZE] = {0};
|
uint8_t hdr[TSDB_FHDR_SIZE] = {0};
|
||||||
|
|
||||||
int32_t flag = TD_FILE_READ | TD_FILE_WRITE | TD_FILE_CREATE | TD_FILE_TRUNC;
|
int32_t flag = TD_FILE_READ | TD_FILE_WRITE;
|
||||||
|
if (pWriter->tFile.size == 0) {
|
||||||
|
flag |= TD_FILE_CREATE | TD_FILE_TRUNC;
|
||||||
|
}
|
||||||
|
|
||||||
code = tsdbOpenFile(pWriter->config.file.fname, pWriter->config.szPage, flag, &pWriter->pFd);
|
code = tsdbOpenFile( //
|
||||||
|
pWriter->config.file.fname, //
|
||||||
|
pWriter->config.szPage, //
|
||||||
|
flag, //
|
||||||
|
&pWriter->pFd);
|
||||||
TSDB_CHECK_CODE(code, lino, _exit);
|
TSDB_CHECK_CODE(code, lino, _exit);
|
||||||
|
|
||||||
code = tsdbWriteFile(pWriter->pFd, 0, hdr, sizeof(hdr));
|
if (pWriter->tFile.size == 0) {
|
||||||
TSDB_CHECK_CODE(code, lino, _exit);
|
code = tsdbWriteFile( //
|
||||||
|
pWriter->pFd, //
|
||||||
|
0, //
|
||||||
|
hdr, //
|
||||||
|
sizeof(hdr));
|
||||||
|
TSDB_CHECK_CODE(code, lino, _exit);
|
||||||
|
|
||||||
|
pWriter->tFile.size += sizeof(hdr);
|
||||||
|
}
|
||||||
|
|
||||||
_exit:
|
_exit:
|
||||||
if (code) {
|
if (code) {
|
||||||
if (pWriter->pFd) tsdbCloseFile(&pWriter->pFd);
|
if (pWriter->pFd) {
|
||||||
tsdbError("vgId:%d %s failed at line %d since %s", TD_VID(pWriter->config.pTsdb->pVnode), __func__, lino,
|
tsdbCloseFile(&pWriter->pFd);
|
||||||
tstrerror(code));
|
}
|
||||||
|
tsdbError( //
|
||||||
|
"vgId:%d %s failed at line %d since %s", //
|
||||||
|
TD_VID(pWriter->config.pTsdb->pVnode), //
|
||||||
|
__func__, //
|
||||||
|
lino, //
|
||||||
|
tstrerror(code));
|
||||||
|
} else {
|
||||||
|
tsdbDebug( //
|
||||||
|
"vgId:%d %s done, fname:%s size:%" PRId64, //
|
||||||
|
TD_VID(pWriter->config.pTsdb->pVnode), //
|
||||||
|
__func__, //
|
||||||
|
pWriter->config.file.fname, //
|
||||||
|
pWriter->config.file.size //
|
||||||
|
);
|
||||||
}
|
}
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
@ -388,8 +435,15 @@ int32_t tsdbSttFWriterOpen(const struct SSttFWriterConf *pConf, struct SSttFWrit
|
||||||
|
|
||||||
_exit:
|
_exit:
|
||||||
if (code) {
|
if (code) {
|
||||||
if (ppWriter[0]) destroy_stt_fwriter(ppWriter[0]);
|
if (ppWriter[0]) {
|
||||||
tsdbError("vgId:%d %s failed at line %d since %s", TD_VID(pConf->pTsdb->pVnode), __func__, lino, tstrerror(code));
|
destroy_stt_fwriter(ppWriter[0]);
|
||||||
|
}
|
||||||
|
tsdbError( //
|
||||||
|
"vgId:%d %s failed at line %d since %s", //
|
||||||
|
TD_VID(pConf->pTsdb->pVnode), //
|
||||||
|
__func__, //
|
||||||
|
lino, //
|
||||||
|
tstrerror(code));
|
||||||
}
|
}
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
@ -450,13 +504,17 @@ int32_t tsdbSttFWriteTSData(struct SSttFWriter *pWriter, TABLEID *tbid, TSDBROW
|
||||||
|
|
||||||
if (!TABLE_SAME_SCHEMA(pWriter->bData.suid, pWriter->bData.uid, tbid->suid, tbid->uid)) {
|
if (!TABLE_SAME_SCHEMA(pWriter->bData.suid, pWriter->bData.uid, tbid->suid, tbid->uid)) {
|
||||||
if (pWriter->bData.nRow > 0) {
|
if (pWriter->bData.nRow > 0) {
|
||||||
code = write_timeseries_block(pWriter);
|
TSDB_CHECK_CODE( //
|
||||||
TSDB_CHECK_CODE(code, lino, _exit);
|
code = write_timeseries_block(pWriter), //
|
||||||
|
lino, //
|
||||||
|
_exit);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pWriter->sData.nRow >= pWriter->config.maxRow) {
|
if (pWriter->sData.nRow >= pWriter->config.maxRow) {
|
||||||
code = write_statistics_block(pWriter);
|
TSDB_CHECK_CODE( //
|
||||||
TSDB_CHECK_CODE(code, lino, _exit);
|
code = write_statistics_block(pWriter), //
|
||||||
|
lino, //
|
||||||
|
_exit);
|
||||||
}
|
}
|
||||||
|
|
||||||
pWriter->sData.aData[0][pWriter->sData.nRow] = tbid->suid; // suid
|
pWriter->sData.aData[0][pWriter->sData.nRow] = tbid->suid; // suid
|
||||||
|
@ -468,25 +526,54 @@ int32_t tsdbSttFWriteTSData(struct SSttFWriter *pWriter, TABLEID *tbid, TSDBROW
|
||||||
pWriter->sData.aData[6][pWriter->sData.nRow] = 1; // count
|
pWriter->sData.aData[6][pWriter->sData.nRow] = 1; // count
|
||||||
pWriter->sData.nRow++;
|
pWriter->sData.nRow++;
|
||||||
|
|
||||||
code = tsdbUpdateSkmTb(pWriter->config.pTsdb, tbid, pWriter->config.pSkmTb);
|
TSDB_CHECK_CODE( //
|
||||||
TSDB_CHECK_CODE(code, lino, _exit);
|
code = tsdbUpdateSkmTb( //
|
||||||
|
pWriter->config.pTsdb, //
|
||||||
|
tbid, //
|
||||||
|
pWriter->config.pSkmTb), //
|
||||||
|
lino, //
|
||||||
|
_exit);
|
||||||
|
|
||||||
TABLEID id = {.suid = tbid->suid, .uid = tbid->suid ? 0 : tbid->uid};
|
TABLEID id = {.suid = tbid->suid, //
|
||||||
code = tBlockDataInit(&pWriter->bData, &id, pWriter->config.pSkmTb->pTSchema, NULL, 0);
|
.uid = tbid->suid //
|
||||||
TSDB_CHECK_CODE(code, lino, _exit);
|
? 0
|
||||||
|
: tbid->uid};
|
||||||
|
TSDB_CHECK_CODE( //
|
||||||
|
code = tBlockDataInit( //
|
||||||
|
&pWriter->bData, //
|
||||||
|
&id, //
|
||||||
|
pWriter->config.pSkmTb->pTSchema, //
|
||||||
|
NULL, //
|
||||||
|
0), //
|
||||||
|
lino, //
|
||||||
|
_exit);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pRow->type == TSDBROW_ROW_FMT) {
|
if (pRow->type == TSDBROW_ROW_FMT) {
|
||||||
code = tsdbUpdateSkmRow(pWriter->config.pTsdb, tbid, TSDBROW_SVERSION(pRow), pWriter->config.pSkmRow);
|
TSDB_CHECK_CODE( //
|
||||||
TSDB_CHECK_CODE(code, lino, _exit);
|
code = tsdbUpdateSkmRow( //
|
||||||
|
pWriter->config.pTsdb, //
|
||||||
|
tbid, //
|
||||||
|
TSDBROW_SVERSION(pRow), //
|
||||||
|
pWriter->config.pSkmRow), //
|
||||||
|
lino, //
|
||||||
|
_exit);
|
||||||
}
|
}
|
||||||
|
|
||||||
code = tBlockDataAppendRow(&pWriter->bData, pRow, pWriter->config.pSkmRow->pTSchema, tbid->uid);
|
TSDB_CHECK_CODE( //
|
||||||
TSDB_CHECK_CODE(code, lino, _exit);
|
code = tBlockDataAppendRow( //
|
||||||
|
&pWriter->bData, //
|
||||||
|
pRow, //
|
||||||
|
pWriter->config.pSkmRow->pTSchema, //
|
||||||
|
tbid->uid), //
|
||||||
|
lino, //
|
||||||
|
_exit);
|
||||||
|
|
||||||
if (pWriter->bData.nRow >= pWriter->config.maxRow) {
|
if (pWriter->bData.nRow >= pWriter->config.maxRow) {
|
||||||
code = write_timeseries_block(pWriter);
|
TSDB_CHECK_CODE( //
|
||||||
TSDB_CHECK_CODE(code, lino, _exit);
|
code = write_timeseries_block(pWriter), //
|
||||||
|
lino, //
|
||||||
|
_exit);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (key.ts > pWriter->sData.aData[4][pWriter->sData.nRow - 1]) {
|
if (key.ts > pWriter->sData.aData[4][pWriter->sData.nRow - 1]) {
|
||||||
|
@ -502,13 +589,19 @@ int32_t tsdbSttFWriteTSData(struct SSttFWriter *pWriter, TABLEID *tbid, TSDBROW
|
||||||
|
|
||||||
_exit:
|
_exit:
|
||||||
if (code) {
|
if (code) {
|
||||||
tsdbError("vgId:%d %s failed at line %d since %s", TD_VID(pWriter->config.pTsdb->pVnode), __func__, lino,
|
tsdbError( //
|
||||||
tstrerror(code));
|
"vgId:%d %s failed at line %d since %s", //
|
||||||
|
TD_VID(pWriter->config.pTsdb->pVnode), //
|
||||||
|
__func__, //
|
||||||
|
lino, //
|
||||||
|
tstrerror(code));
|
||||||
}
|
}
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t tsdbSttFWriteDLData(struct SSttFWriter *pWriter, TABLEID *tbid, SDelData *pDelData) {
|
int32_t tsdbSttFWriteDLData(struct SSttFWriter *pWriter, TABLEID *tbid, SDelData *pDelData) {
|
||||||
|
ASSERTS(0, "TODO: Not implemented yet");
|
||||||
|
|
||||||
pWriter->dData.aData[0][pWriter->dData.nRow] = tbid->suid; // suid
|
pWriter->dData.aData[0][pWriter->dData.nRow] = tbid->suid; // suid
|
||||||
pWriter->dData.aData[1][pWriter->dData.nRow] = tbid->uid; // uid
|
pWriter->dData.aData[1][pWriter->dData.nRow] = tbid->uid; // uid
|
||||||
pWriter->dData.aData[2][pWriter->dData.nRow] = pDelData->version; // version
|
pWriter->dData.aData[2][pWriter->dData.nRow] = pDelData->version; // version
|
||||||
|
|
|
@ -64,6 +64,7 @@ struct SDelBlk {
|
||||||
int64_t maxVer;
|
int64_t maxVer;
|
||||||
SFDataPtr dp;
|
SFDataPtr dp;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct STbStatisBlock {
|
struct STbStatisBlock {
|
||||||
int32_t capacity;
|
int32_t capacity;
|
||||||
int32_t nRow;
|
int32_t nRow;
|
||||||
|
|
Loading…
Reference in New Issue