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