提交 58ed42b0 编写于 作者: H Hongze Cheng

more code

上级 3f8f7bb4
......@@ -368,6 +368,8 @@ static int32_t close_committer(SCommitter *pCommiter, int32_t eno) {
ASSERTS(0, "TODO: Not implemented yet");
}
// TODO: clear the committer
_exit:
if (code) {
tsdbError( //
......
......@@ -20,7 +20,10 @@ static int32_t create_file_system(STsdb *pTsdb, struct STFileSystem **ppFS) {
return TSDB_CODE_OUT_OF_MEMORY;
}
if ((ppFS[0]->aFileSet = taosArrayInit(16, sizeof(struct SFileSet))) == NULL) {
if ((ppFS[0]->aFileSet = taosArrayInit(16, sizeof(struct SFileSet))) == NULL ||
(ppFS[0]->nState = taosArrayInit(16, sizeof(struct SFileSet))) == NULL) {
taosArrayDestroy(ppFS[0]->nState);
taosArrayDestroy(ppFS[0]->aFileSet);
taosMemoryFree(ppFS[0]);
return TSDB_CODE_OUT_OF_MEMORY;
}
......@@ -351,12 +354,19 @@ static int32_t apply_edit(struct STFileSystem *pFS) {
return code;
}
static int32_t fset_cmpr_fn(const struct SFileSet *pSet1, const struct SFileSet *pSet2) {
if (pSet1->fid < pSet2->fid) {
return -1;
} else if (pSet1->fid > pSet2->fid) {
return 1;
}
return 0;
}
static int32_t edit_fs(struct STFileSystem *pFS, const SArray *aFileOp) {
int32_t code = 0;
int32_t lino;
ASSERTS(0, "TODO: Not implemented yet");
taosArrayClearEx(pFS->nState, NULL /* TODO */);
// TODO: copy current state to new state
......@@ -364,9 +374,38 @@ static int32_t edit_fs(struct STFileSystem *pFS, const SArray *aFileOp) {
for (int32_t iop = 0; iop < taosArrayGetSize(aFileOp); iop++) {
struct SFileOp *pOp = taosArrayGet(aFileOp, iop);
struct SFileSet *pSet = taosArraySearch(pFS->nState, NULL /* TODO */, NULL /* TODO */, TD_EQ);
struct SFileSet tmpSet = {.fid = pOp->fid};
int32_t idx = taosArraySearchIdx( //
pFS->nState, //
&tmpSet, //
(__compar_fn_t)fset_cmpr_fn, //
TD_GE);
struct SFileSet *pSet;
if (idx < 0) {
pSet = NULL;
idx = taosArrayGetSize(pFS->nState);
} else {
pSet = taosArrayGet(pFS->nState, idx);
}
if (pSet == NULL || pSet->fid != pOp->fid) {
ASSERTS(pOp->op == TSDB_FOP_CREATE, "BUG: Invalid file operation");
TSDB_CHECK_CODE( //
code = tsdbFileSetCreate(pOp->fid, &pSet), //
lino, //
_exit);
if (taosArrayInsert(pFS->nState, idx, pSet) == NULL) {
code = TSDB_CODE_OUT_OF_MEMORY;
TSDB_CHECK_CODE(code, lino, _exit);
}
}
// do opration on file set
TSDB_CHECK_CODE( //
code = tsdbEditFileSet(pSet, pOp), //
code = tsdbFileSetEdit(pSet, pOp), //
lino, //
_exit);
}
......
......@@ -15,6 +15,73 @@
#include "dev.h"
int32_t tsdbFileSetCreate(int32_t fid, struct SFileSet **ppSet) {
int32_t code = 0;
ppSet[0] = taosMemoryCalloc(1, sizeof(struct SFileSet));
if (ppSet[0] == NULL) {
code = TSDB_CODE_OUT_OF_MEMORY;
goto _exit;
}
ppSet[0]->fid = fid;
ppSet[0]->nextid = 1; // TODO
_exit:
return code;
}
int32_t tsdbFileSetEdit(struct SFileSet *pSet, struct SFileOp *pOp) {
int32_t code = 0;
int32_t lino;
switch (pOp->op) {
case TSDB_FOP_CREATE: {
struct STFile **ppFile;
switch (pOp->nState.type) {
case TSDB_FTYPE_HEAD: {
ppFile = &pSet->fHead;
} break;
case TSDB_FTYPE_DATA: {
ppFile = &pSet->fData;
} break;
case TSDB_FTYPE_SMA: {
ppFile = &pSet->fSma;
} break;
case TSDB_FTYPE_TOMB: {
ppFile = &pSet->fTomb;
} break;
case TSDB_FTYPE_STT: {
ppFile = &pSet->lStt[0].fStt;
} break;
default: {
ASSERTS(0, "Invalid file type");
} break;
}
TSDB_CHECK_CODE( //
code = tsdbTFileCreate(&pOp->nState, ppFile), //
lino, //
_exit);
} break;
case TSDB_FOP_DELETE: {
ASSERTS(0, "TODO: Not implemented yet");
} break;
case TSDB_FOP_TRUNCATE: {
ASSERTS(0, "TODO: Not implemented yet");
} break;
case TSDB_FOP_EXTEND: {
ASSERTS(0, "TODO: Not implemented yet");
} break;
default: {
ASSERTS(0, "Invalid file operation");
} break;
}
_exit:
return code;
}
int32_t tsdbFileSetToJson(SJson *pJson, const struct SFileSet *pSet) {
int32_t code = 0;
......
......@@ -34,6 +34,7 @@ typedef enum {
struct SFileOp {
tsdb_fop_t op;
int32_t fid;
struct STFile oState; // old file state
struct STFile nState; // new file state
};
......@@ -48,10 +49,12 @@ struct SFileSet {
struct {
int32_t level;
int32_t nFile;
struct STFile *fileList;
struct STFile *fStt;
} lStt[TSDB_STT_FILE_LEVEL_MAX];
};
int32_t tsdbFileSetCreate(int32_t fid, struct SFileSet **ppSet);
int32_t tsdbFileSetEdit(struct SFileSet *pSet, struct SFileOp *pOp);
int32_t tsdbFileSetToJson(SJson *pJson, const struct SFileSet *pSet);
int32_t tsdbEditFileSet(struct SFileSet *pFileSet, const struct SFileOp *pOp);
......
......@@ -24,6 +24,28 @@ const char *tsdb_ftype_suffix[] = {
".stt", // TSDB_FTYPE_STT
};
int32_t tsdbTFileCreate(const struct STFile *config, struct STFile **ppFile) {
int32_t code = 0;
int32_t lino;
ppFile[0] = (struct STFile *)taosMemoryCalloc(1, sizeof(struct STFile));
if (ppFile[0] == NULL) {
code = TSDB_CODE_OUT_OF_MEMORY;
goto _exit;
}
ppFile[0][0] = config[0];
_exit:
return code;
}
int32_t tsdbTFileDestroy(struct STFile *pFile) {
int32_t code = 0;
// TODO
return code;
}
int32_t tsdbTFileInit(STsdb *pTsdb, struct STFile *pFile) {
SVnode *pVnode = pTsdb->pVnode;
STfs *pTfs = pVnode->pTfs;
......
......@@ -42,6 +42,8 @@ struct STFile {
char fname[TSDB_FILENAME_LEN];
};
int32_t tsdbTFileCreate(const struct STFile *config, struct STFile **ppFile);
int32_t tsdbTFileDestroy(struct STFile *pFile);
int32_t tsdbTFileInit(STsdb *pTsdb, struct STFile *pFile);
int32_t tsdbTFileClear(struct STFile *pFile);
......
......@@ -538,6 +538,7 @@ int32_t tsdbSttFWriterClose(struct SSttFWriter **ppWriter, int8_t abort, struct
_exit);
if (op) {
op->fid = ppWriter[0]->config.file.fid;
op->oState = ppWriter[0]->config.file;
op->nState = ppWriter[0]->tFile;
if (op->oState.size == 0) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册