提交 47d493e8 编写于 作者: H Hongze Cheng

more code

上级 38b4c5c1
......@@ -638,6 +638,7 @@ struct SDataFReader {
uint8_t *aBuf[3];
};
// NOTE: do NOT change the order of the fields
typedef struct {
int64_t suid;
int64_t uid;
......
......@@ -688,13 +688,6 @@ static int32_t tsdbOpenCompactor(STsdbCompactor *pCompactor) {
STsdb *pTsdb = pCompactor->pTsdb;
// next compact file
pCompactor->pDFileSet = (SDFileSet *)taosArraySearch(pCompactor->fs.aDFileSet, &(SDFileSet){.fid = pCompactor->fid},
tDFileSetCmprFn, TD_GT);
if (pCompactor->pDFileSet == NULL) goto _exit;
pCompactor->fid = pCompactor->pDFileSet->fid;
// reader
code = tsdbDataFReaderOpen(&pCompactor->pReader, pTsdb, pCompactor->pDFileSet);
TSDB_CHECK_CODE(code, lino, _exit);
......@@ -841,25 +834,15 @@ _exit:
return code;
}
int32_t tsdbCompact(STsdb *pTsdb, int32_t flag) {
static int32_t tsdbCompactFileSet(STsdbCompactor *pCompactor) {
int32_t code = 0;
int32_t lino = 0;
// Check if can do compact (TODO)
// Do compact
STsdbCompactor *pCompactor = &(STsdbCompactor){0};
code = tsdbBeginCompact(pTsdb, pCompactor);
TSDB_CHECK_CODE(code, lino, _exit);
while (true) {
// open compactor
code = tsdbOpenCompactor(pCompactor);
TSDB_CHECK_CODE(code, lino, _exit);
if (pCompactor->pDFileSet == NULL) break;
// loop to merge row by row
// do compact
SRowInfo *pRowInfo;
STSchema *pTSchema;
int64_t nRow = 0;
......@@ -867,19 +850,13 @@ int32_t tsdbCompact(STsdb *pTsdb, int32_t flag) {
code = tsdbCompactGetRow(pCompactor, &pRowInfo, &pTSchema);
TSDB_CHECK_CODE(code, lino, _exit);
if (pRowInfo && (code = tBlockDataInit(&pCompactor->bData, &(TABLEID){.suid = pRowInfo->suid, .uid = pRowInfo->uid},
pTSchema, NULL, 0))) {
if (pRowInfo && (code = tBlockDataInit(&pCompactor->bData, (TABLEID *)pRowInfo, pTSchema, NULL, 0))) {
TSDB_CHECK_CODE(code, lino, _exit);
}
while (pRowInfo) {
nRow++;
if (pCompactor->bData.suid == 0 && pCompactor->bData.uid == 0) { // init the block data if not initialized yet
code = tBlockDataInit(&pCompactor->bData, &(TABLEID){.suid = pRowInfo->suid, .uid = pRowInfo->uid}, pTSchema,
NULL, 0);
TSDB_CHECK_CODE(code, lino, _exit);
} else {
if ((pCompactor->tableId.suid != pRowInfo->suid) || // different super table
(pCompactor->tableId.uid != pRowInfo->uid &&
(pRowInfo->suid == 0 ||
......@@ -891,11 +868,9 @@ int32_t tsdbCompact(STsdb *pTsdb, int32_t flag) {
code = tsdbCompactWriteDataBlk(pCompactor);
TSDB_CHECK_CODE(code, lino, _exit);
code = tBlockDataInit(&pCompactor->bData, &(TABLEID){.suid = pRowInfo->suid, .uid = pRowInfo->uid}, pTSchema,
NULL, 0);
code = tBlockDataInit(&pCompactor->bData, (TABLEID *)pRowInfo, pTSchema, NULL, 0);
TSDB_CHECK_CODE(code, lino, _exit);
}
}
// append row to block data
code = tBlockDataAppendRowEx(&pCompactor->bData, &pRowInfo->row, pTSchema, pRowInfo->uid);
......@@ -918,6 +893,7 @@ int32_t tsdbCompact(STsdb *pTsdb, int32_t flag) {
TSDB_CHECK_CODE(code, lino, _exit);
}
// handle remain data
code = tsdbCompactWriteBlockData(pCompactor);
TSDB_CHECK_CODE(code, lino, _exit);
......@@ -939,13 +915,38 @@ int32_t tsdbCompact(STsdb *pTsdb, int32_t flag) {
code = tsdbDataFWriterClose(&pCompactor->pWriter, 1);
TSDB_CHECK_CODE(code, lino, _exit);
_exit:
// close compactor
tsdbCloseCompactor(pCompactor);
return code;
}
int32_t tsdbCompact(STsdb *pTsdb, int32_t flag) {
int32_t code = 0;
int32_t lino = 0;
STsdbCompactor *pCompactor = &(STsdbCompactor){0};
// begin compact
code = tsdbBeginCompact(pTsdb, pCompactor);
TSDB_CHECK_CODE(code, lino, _exit);
// do compact each file set
while (true) {
pCompactor->pDFileSet = (SDFileSet *)taosArraySearch(pCompactor->fs.aDFileSet, &(SDFileSet){.fid = pCompactor->fid},
tDFileSetCmprFn, TD_GT);
if (pCompactor->pDFileSet == NULL) break;
pCompactor->fid = pCompactor->pDFileSet->fid;
code = tsdbCompactFileSet(pCompactor);
TSDB_CHECK_CODE(code, lino, _exit);
}
code = tsdbFSUpsertDelFile(&pCompactor->fs, NULL);
TSDB_CHECK_CODE(code, lino, _exit);
_exit:
// commit/abort compact
if (code) {
tsdbError("vgId:%d %s failed at line %d since %s", TD_VID(pTsdb->pVnode), __func__, lino, tstrerror(code));
tsdbAbortCompact(pCompactor);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册