more code
This commit is contained in:
parent
23ad540035
commit
68f07c4bec
|
@ -32,8 +32,8 @@ typedef enum {
|
|||
|
||||
/* Exposed APIs */
|
||||
// open/close
|
||||
int32_t tsdbOpenFS(STsdb *pTsdb, STFileSystem **ppFS, int8_t rollback);
|
||||
int32_t tsdbCloseFS(STFileSystem **ppFS);
|
||||
int32_t tsdbOpenFS(STsdb *pTsdb, STFileSystem **fs, int8_t rollback);
|
||||
int32_t tsdbCloseFS(STFileSystem **fs);
|
||||
// txn
|
||||
int32_t tsdbFSAllocEid(STFileSystem *pFS, int64_t *eid);
|
||||
int32_t tsdbFSEditBegin(STFileSystem *fs, int64_t eid, const SArray *aFileOp, EFEditT etype);
|
||||
|
@ -45,14 +45,14 @@ int32_t tsdbFSGetFSet(STFileSystem *fs, int32_t fid, const STFileSet **ppFSet);
|
|||
/* Exposed Structs */
|
||||
struct STFileSystem {
|
||||
STsdb *pTsdb;
|
||||
int32_t state;
|
||||
tsem_t canEdit;
|
||||
int32_t state;
|
||||
int64_t neid;
|
||||
SArray *cstate; // current state, SArray<STFileSet>
|
||||
// new state
|
||||
EFEditT etype;
|
||||
int64_t eid;
|
||||
SArray *nstate; // next state, SArray<STFileSet>
|
||||
SArray *nstate; // staging state, SArray<STFileSet>
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
|
@ -52,9 +52,9 @@ struct STFileOp {
|
|||
|
||||
typedef struct SSttLvl {
|
||||
SRBTreeNode rbtn;
|
||||
int32_t lvl; // level
|
||||
int32_t nstt; // number of .stt files on this level
|
||||
STFile *fstt; // .stt files
|
||||
int32_t lvl; // level
|
||||
int32_t nstt; // number of .stt files on this level
|
||||
SRBTree sttTree; // .stt file tree, sorted by cid
|
||||
} SSttLvl;
|
||||
|
||||
struct STFileSet {
|
||||
|
|
|
@ -47,12 +47,9 @@ int32_t tsdbTFileInit(STsdb *pTsdb, STFile *pFile);
|
|||
int32_t tsdbTFileClear(STFile *pFile);
|
||||
|
||||
struct STFile {
|
||||
LISTD(STFile) listNode;
|
||||
int32_t ref;
|
||||
|
||||
char fname[TSDB_FILENAME_LEN];
|
||||
tsdb_ftype_t type;
|
||||
SDiskID did;
|
||||
SDiskID did; // disk id
|
||||
int32_t fid; // file id
|
||||
int64_t cid; // commit id
|
||||
int64_t size;
|
||||
|
@ -64,6 +61,12 @@ struct STFile {
|
|||
};
|
||||
};
|
||||
|
||||
struct STFileObj {
|
||||
SRBTreeNode rbtn;
|
||||
int32_t ref;
|
||||
STFile f;
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -37,36 +37,34 @@ static const char *gCurrentFname[] = {
|
|||
[TSDB_FCURRENT_M] = "current.m.json",
|
||||
};
|
||||
|
||||
static int32_t create_fs(STsdb *pTsdb, STFileSystem **ppFS) {
|
||||
ppFS[0] = taosMemoryCalloc(1, sizeof(*ppFS[0]));
|
||||
if (ppFS[0] == NULL) {
|
||||
static int32_t create_fs(STsdb *pTsdb, STFileSystem **fs) {
|
||||
fs[0] = taosMemoryCalloc(1, sizeof(*fs[0]));
|
||||
if (fs[0] == NULL) return TSDB_CODE_OUT_OF_MEMORY;
|
||||
|
||||
fs[0]->cstate = taosArrayInit(16, sizeof(STFileSet));
|
||||
fs[0]->nstate = taosArrayInit(16, sizeof(STFileSet));
|
||||
if (fs[0]->cstate == NULL || fs[0]->nstate == NULL) {
|
||||
taosArrayDestroy(fs[0]->nstate);
|
||||
taosArrayDestroy(fs[0]->cstate);
|
||||
taosMemoryFree(fs[0]);
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
ppFS[0]->cstate = taosArrayInit(16, sizeof(STFileSet));
|
||||
ppFS[0]->nstate = taosArrayInit(16, sizeof(STFileSet));
|
||||
if (ppFS[0]->cstate == NULL || ppFS[0]->nstate == NULL) {
|
||||
taosArrayDestroy(ppFS[0]->nstate);
|
||||
taosArrayDestroy(ppFS[0]->cstate);
|
||||
taosMemoryFree(ppFS[0]);
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
ppFS[0]->pTsdb = pTsdb;
|
||||
ppFS[0]->state = TSDB_FS_STATE_NONE;
|
||||
tsem_init(&ppFS[0]->canEdit, 0, 1);
|
||||
ppFS[0]->neid = 0;
|
||||
fs[0]->pTsdb = pTsdb;
|
||||
fs[0]->state = TSDB_FS_STATE_NONE;
|
||||
tsem_init(&fs[0]->canEdit, 0, 1);
|
||||
fs[0]->neid = 0;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t destroy_fs(STFileSystem **ppFS) {
|
||||
if (ppFS[0] == NULL) return 0;
|
||||
taosArrayDestroy(ppFS[0]->nstate);
|
||||
taosArrayDestroy(ppFS[0]->cstate);
|
||||
tsem_destroy(&ppFS[0]->canEdit);
|
||||
taosMemoryFree(ppFS[0]);
|
||||
ppFS[0] = NULL;
|
||||
static int32_t destroy_fs(STFileSystem **fs) {
|
||||
if (fs[0] == NULL) return 0;
|
||||
taosArrayDestroy(fs[0]->nstate);
|
||||
taosArrayDestroy(fs[0]->cstate);
|
||||
tsem_destroy(&fs[0]->canEdit);
|
||||
taosMemoryFree(fs[0]);
|
||||
fs[0] = NULL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -398,7 +396,7 @@ static int32_t open_fs(STFileSystem *fs, int8_t rollback) {
|
|||
code = scan_and_fix_fs(fs);
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
} else {
|
||||
code = save_fs(0, fs->nstate, fCurrent);
|
||||
code = save_fs(0, fs->cstate, fCurrent);
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
}
|
||||
|
||||
|
@ -470,20 +468,20 @@ _exit:
|
|||
return 0;
|
||||
}
|
||||
|
||||
int32_t tsdbOpenFS(STsdb *pTsdb, STFileSystem **ppFS, int8_t rollback) {
|
||||
int32_t tsdbOpenFS(STsdb *pTsdb, STFileSystem **fs, int8_t rollback) {
|
||||
int32_t code;
|
||||
int32_t lino;
|
||||
|
||||
code = create_fs(pTsdb, ppFS);
|
||||
code = create_fs(pTsdb, fs);
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
|
||||
code = open_fs(ppFS[0], rollback);
|
||||
code = open_fs(fs[0], rollback);
|
||||
TSDB_CHECK_CODE(code, lino, _exit)
|
||||
|
||||
_exit:
|
||||
if (code) {
|
||||
tsdbError("vgId:%d %s failed at line %d since %s", TD_VID(pTsdb->pVnode), __func__, lino, tstrerror(code));
|
||||
destroy_fs(ppFS);
|
||||
destroy_fs(fs);
|
||||
} else {
|
||||
tsdbInfo("vgId:%d %s success", TD_VID(pTsdb->pVnode), __func__);
|
||||
}
|
||||
|
|
|
@ -47,8 +47,8 @@ static int32_t add_file(STFileSet *fset, STFile *f) {
|
|||
if (f->type == TSDB_FTYPE_STT) {
|
||||
SSttLvl *lvl = NULL; // TODO
|
||||
|
||||
lvl->nstt++;
|
||||
lvl->fstt = f;
|
||||
// lvl->nstt++;
|
||||
// lvl->fstt = f;
|
||||
} else {
|
||||
fset->farr[f->type] = f;
|
||||
}
|
||||
|
|
|
@ -193,7 +193,7 @@ int32_t tsdbTFileInit(STsdb *pTsdb, STFile *pFile) {
|
|||
pFile->cid, //
|
||||
g_tfile_info[pFile->type].suffix);
|
||||
}
|
||||
pFile->ref = 1;
|
||||
// pFile->ref = 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -235,7 +235,7 @@ int32_t tsdbTFileCreate(const STFile *pFile, STFile **f) {
|
|||
|
||||
*f[0] = *pFile;
|
||||
|
||||
f[0]->ref = 1;
|
||||
// f[0]->ref = 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue