提交 36b2495c 编写于 作者: H Hongze Cheng

more code

上级 5d5add3f
...@@ -29,14 +29,6 @@ typedef TARRAY2(STFileObj *) TFileObjArray; ...@@ -29,14 +29,6 @@ typedef TARRAY2(STFileObj *) TFileObjArray;
typedef TARRAY2(SSttLvl *) TSttLvlArray; typedef TARRAY2(SSttLvl *) TSttLvlArray;
typedef TARRAY2(STFileOp) TFileOpArray; typedef TARRAY2(STFileOp) TFileOpArray;
typedef enum {
TSDB_FOP_NONE = 0,
TSDB_FOP_EXTEND,
TSDB_FOP_CREATE,
TSDB_FOP_DELETE,
TSDB_FOP_TRUNCATE,
} tsdb_fop_t;
// init/clear // init/clear
int32_t tsdbTFileSetInit(int32_t fid, STFileSet **fset); int32_t tsdbTFileSetInit(int32_t fid, STFileSet **fset);
int32_t tsdbTFileSetInitEx(STsdb *pTsdb, const STFileSet *fset1, STFileSet **fset); int32_t tsdbTFileSetInitEx(STsdb *pTsdb, const STFileSet *fset1, STFileSet **fset);
...@@ -52,14 +44,16 @@ int32_t tsdbTFileSetEdit(STsdb *pTsdb, STFileSet *fset, const STFileOp *op); ...@@ -52,14 +44,16 @@ int32_t tsdbTFileSetEdit(STsdb *pTsdb, STFileSet *fset, const STFileOp *op);
int32_t tsdbTFileSetApplyEdit(STsdb *pTsdb, const STFileSet *fset1, STFileSet *fset); int32_t tsdbTFileSetApplyEdit(STsdb *pTsdb, const STFileSet *fset1, STFileSet *fset);
// max commit id // max commit id
int64_t tsdbTFileSetMaxCid(const STFileSet *fset); int64_t tsdbTFileSetMaxCid(const STFileSet *fset);
// get
SSttLvl *tsdbTFileSetGetLvl(STFileSet *fset, int32_t level); SSttLvl *tsdbTFileSetGetLvl(STFileSet *fset, int32_t level);
// is empty
bool tsdbTFileSetIsEmpty(const STFileSet *fset);
struct STFileOp { struct STFileOp {
tsdb_fop_t op;
int32_t fid; int32_t fid;
STFile oState; // old file state STFile *of; // old file
STFile nState; // new file state STFile *nf; // new file
STFile fArr[2];
}; };
struct SSttLvl { struct SSttLvl {
......
...@@ -326,7 +326,7 @@ static int32_t open_committer(STsdb *pTsdb, SCommitInfo *pInfo, SCommitter *pCom ...@@ -326,7 +326,7 @@ static int32_t open_committer(STsdb *pTsdb, SCommitInfo *pInfo, SCommitter *pCom
pCommitter->minRow = pInfo->info.config.tsdbCfg.minRows; pCommitter->minRow = pInfo->info.config.tsdbCfg.minRows;
pCommitter->maxRow = pInfo->info.config.tsdbCfg.maxRows; pCommitter->maxRow = pInfo->info.config.tsdbCfg.maxRows;
pCommitter->cmprAlg = pInfo->info.config.tsdbCfg.compression; pCommitter->cmprAlg = pInfo->info.config.tsdbCfg.compression;
pCommitter->sttTrigger = 1; // TODO pCommitter->sttTrigger = 4; // TODO
pCommitter->aTbDataP = tsdbMemTableGetTbDataArray(pTsdb->imem); pCommitter->aTbDataP = tsdbMemTableGetTbDataArray(pTsdb->imem);
if (pCommitter->aTbDataP == NULL) { if (pCommitter->aTbDataP == NULL) {
......
...@@ -496,8 +496,15 @@ static int32_t edit_fs(STFileSystem *fs, const TFileOpArray *opArray) { ...@@ -496,8 +496,15 @@ static int32_t edit_fs(STFileSystem *fs, const TFileOpArray *opArray) {
TSDB_CHECK_CODE(code, lino, _exit); TSDB_CHECK_CODE(code, lino, _exit);
} }
{ // remove empty file set
// TODO: check if a file set should be deleted int32_t i = 0;
while (i < TARRAY2_SIZE(fsetArray)) {
fset = TARRAY2_GET(fsetArray, i);
if (tsdbTFileSetIsEmpty(fset)) {
TARRAY2_REMOVE(fsetArray, i, tsdbTFileSetClear);
} else {
i++;
}
} }
_exit: _exit:
......
...@@ -259,35 +259,35 @@ int32_t tsdbJsonToTFileSet(STsdb *pTsdb, const cJSON *json, STFileSet **fset) { ...@@ -259,35 +259,35 @@ int32_t tsdbJsonToTFileSet(STsdb *pTsdb, const cJSON *json, STFileSet **fset) {
int32_t tsdbTFileSetEdit(STsdb *pTsdb, STFileSet *fset, const STFileOp *op) { int32_t tsdbTFileSetEdit(STsdb *pTsdb, STFileSet *fset, const STFileOp *op) {
int32_t code = 0; int32_t code = 0;
if (op->oState.size == 0 // // if (op->of.size == 0 //
|| 0 /* TODO*/ // || 0 /* TODO*/
) { // ) {
STFileObj *fobj; // STFileObj *fobj;
code = tsdbTFileObjInit(pTsdb, &op->nState, &fobj); // code = tsdbTFileObjInit(pTsdb, &op->nf, &fobj);
if (code) return code; // if (code) return code;
if (fobj->f.type == TSDB_FTYPE_STT) { // if (fobj->f.type == TSDB_FTYPE_STT) {
SSttLvl *lvl = tsdbTFileSetGetLvl(fset, fobj->f.stt.level); // SSttLvl *lvl = tsdbTFileSetGetLvl(fset, fobj->f.stt.level);
if (!lvl) { // if (!lvl) {
code = tsdbSttLvlInit(fobj->f.stt.level, &lvl); // code = tsdbSttLvlInit(fobj->f.stt.level, &lvl);
if (code) return code; // if (code) return code;
code = TARRAY2_SORT_INSERT(&fset->lvlArr, lvl, tsdbSttLvlCmprFn); // code = TARRAY2_SORT_INSERT(&fset->lvlArr, lvl, tsdbSttLvlCmprFn);
if (code) return code; // if (code) return code;
} // }
code = TARRAY2_SORT_INSERT(&lvl->farr, fobj, tsdbTFileObjCmpr); // code = TARRAY2_SORT_INSERT(&lvl->farr, fobj, tsdbTFileObjCmpr);
if (code) return code; // if (code) return code;
} else { // } else {
fset->farr[fobj->f.type] = fobj; // fset->farr[fobj->f.type] = fobj;
} // }
} else if (op->nState.size == 0) { // } else if (op->nf.size == 0) {
// delete // // delete
ASSERT(0); // ASSERT(0);
} else { // } else {
// modify // // modify
ASSERT(0); // ASSERT(0);
} // }
return 0; return 0;
} }
...@@ -458,3 +458,10 @@ int64_t tsdbTFileSetMaxCid(const STFileSet *fset) { ...@@ -458,3 +458,10 @@ int64_t tsdbTFileSetMaxCid(const STFileSet *fset) {
} }
return maxCid; return maxCid;
} }
bool tsdbTFileSetIsEmpty(const STFileSet *fset) {
for (tsdb_ftype_t ftype = TSDB_FTYPE_MIN; ftype < TSDB_FTYPE_MAX; ++ftype) {
if (fset->farr[ftype] != NULL) return false;
}
return TARRAY2_SIZE(&fset->lvlArr) == 0;
}
\ No newline at end of file
...@@ -570,14 +570,16 @@ int32_t tsdbSttFWriterClose(SSttFileWriter **ppWriter, int8_t abort, struct STFi ...@@ -570,14 +570,16 @@ int32_t tsdbSttFWriterClose(SSttFileWriter **ppWriter, int8_t abort, struct STFi
TSDB_CHECK_CODE(code, lino, _exit); TSDB_CHECK_CODE(code, lino, _exit);
if (op) { if (op) {
op->fid = ppWriter[0]->config.file.fid; STFile *f = &ppWriter[0]->config.file;
op->oState = ppWriter[0]->config.file; op->fid = f->fid;
op->nState = ppWriter[0]->tFile; if (f->size == 0) {
if (op->oState.size == 0) { op->of = NULL;
op->op = TSDB_FOP_CREATE;
} else { } else {
op->op = TSDB_FOP_EXTEND; op->of = &op->fArr[0];
op->of[0] = f[0];
} }
op->nf = &op->fArr[1];
op->nf[0] = ppWriter[0]->tFile;
} }
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册