more code
This commit is contained in:
parent
1c4abc62c3
commit
b75aca7538
|
@ -24,6 +24,7 @@ extern "C" {
|
|||
|
||||
/* Exposed Handle */
|
||||
typedef struct STFileSystem STFileSystem;
|
||||
typedef TARRAY2(STFileOp) TFileOpArray;
|
||||
|
||||
typedef enum {
|
||||
TSDB_FEDIT_COMMIT = 1, //
|
||||
|
@ -36,7 +37,7 @@ 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);
|
||||
int32_t tsdbFSEditBegin(STFileSystem *fs, const SArray *aFileOp, EFEditT etype);
|
||||
int32_t tsdbFSEditCommit(STFileSystem *pFS);
|
||||
int32_t tsdbFSEditAbort(STFileSystem *pFS);
|
||||
// other
|
||||
|
@ -49,7 +50,6 @@ struct STFileSystem {
|
|||
int32_t state;
|
||||
int64_t neid;
|
||||
EFEditT etype;
|
||||
int64_t eid;
|
||||
TFileSetArray cstate;
|
||||
TFileSetArray nstate;
|
||||
};
|
||||
|
|
|
@ -363,7 +363,7 @@ static int32_t close_committer(SCommitter *pCommiter, int32_t eno) {
|
|||
int32_t vid = TD_VID(pCommiter->pTsdb->pVnode);
|
||||
|
||||
if (eno == 0) {
|
||||
code = tsdbFSEditBegin(pCommiter->pTsdb->pFS, pCommiter->eid, pCommiter->aFileOp, TSDB_FEDIT_COMMIT);
|
||||
code = tsdbFSEditBegin(pCommiter->pTsdb->pFS, pCommiter->aFileOp, TSDB_FEDIT_COMMIT);
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
} else {
|
||||
// TODO
|
||||
|
|
|
@ -190,7 +190,7 @@ static int32_t load_fs(const char *fname, TFileSetArray *arr) {
|
|||
int32_t code = 0;
|
||||
int32_t lino = 0;
|
||||
|
||||
TARRAY2_CLEAR(arr, NULL);
|
||||
TARRAY2_CLEAR(arr, tsdbTFileSetClear);
|
||||
|
||||
// load json
|
||||
cJSON *json = NULL;
|
||||
|
@ -352,7 +352,7 @@ _exit:
|
|||
if (code) {
|
||||
tsdbError("vgId:%d %s failed at line %d since %s", TD_VID(fs->pTsdb->pVnode), __func__, lino, tstrerror(code));
|
||||
} else {
|
||||
tsdbInfo("vgId:%d %s success, eid:%" PRId64 " etype:%d", TD_VID(fs->pTsdb->pVnode), __func__, fs->eid, fs->etype);
|
||||
tsdbInfo("vgId:%d %s success, etype:%d", TD_VID(fs->pTsdb->pVnode), __func__, fs->etype);
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
@ -387,7 +387,7 @@ _exit:
|
|||
if (code) {
|
||||
tsdbError("vgId:%d %s failed since %s", TD_VID(fs->pTsdb->pVnode), __func__, tstrerror(code));
|
||||
} else {
|
||||
tsdbInfo("vgId:%d %s success, eid:%" PRId64 " etype:%d", TD_VID(fs->pTsdb->pVnode), __func__, fs->eid, fs->etype);
|
||||
tsdbInfo("vgId:%d %s success, etype:%d", TD_VID(fs->pTsdb->pVnode), __func__, fs->etype);
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
@ -402,6 +402,23 @@ static int32_t update_fs_if_needed(STFileSystem *pFS) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int32_t tsdbFSDupState(const TFileSetArray *src, TFileSetArray *dst) {
|
||||
TARRAY2_CLEAR(dst, tsdbTFileSetClear);
|
||||
|
||||
const STFileSet *fset1;
|
||||
TARRAY2_FOREACH(src, fset1) {
|
||||
STFileSet *fset;
|
||||
|
||||
int32_t code = tsdbTFileSetInitEx(fset1, &fset);
|
||||
if (code) return code;
|
||||
|
||||
code = TARRAY2_APPEND(dst, fset);
|
||||
if (code) return code;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t open_fs(STFileSystem *fs, int8_t rollback) {
|
||||
int32_t code = 0;
|
||||
int32_t lino = 0;
|
||||
|
@ -430,8 +447,8 @@ static int32_t open_fs(STFileSystem *fs, int8_t rollback) {
|
|||
code = abort_edit(fs);
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
} else {
|
||||
// code = load_fs(cCurrent, fs->nstate);
|
||||
// TSDB_CHECK_CODE(code, lino, _exit);
|
||||
code = load_fs(cCurrent, &fs->nstate);
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
|
||||
code = commit_edit(fs);
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
|
@ -443,6 +460,9 @@ static int32_t open_fs(STFileSystem *fs, int8_t rollback) {
|
|||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
}
|
||||
|
||||
code = tsdbFSDupState(&fs->cstate, &fs->nstate);
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
|
||||
code = scan_and_fix_fs(fs);
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
} else {
|
||||
|
@ -546,36 +566,41 @@ int32_t tsdbFSAllocEid(STFileSystem *pFS, int64_t *eid) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
int32_t tsdbFSEditBegin(STFileSystem *fs, int64_t eid, const SArray *aFileOp, EFEditT etype) {
|
||||
// TODO: remove eid
|
||||
int32_t tsdbFSEditBegin(STFileSystem *fs, const SArray *aFileOp, EFEditT etype) {
|
||||
int32_t code = 0;
|
||||
int32_t lino;
|
||||
char current_t[TSDB_FILENAME_LEN];
|
||||
|
||||
if (etype == TSDB_FEDIT_COMMIT) {
|
||||
current_fname(fs->pTsdb, current_t, TSDB_FCURRENT_C);
|
||||
} else {
|
||||
current_fname(fs->pTsdb, current_t, TSDB_FCURRENT_M);
|
||||
switch (etype) {
|
||||
case TSDB_FEDIT_COMMIT:
|
||||
current_fname(fs->pTsdb, current_t, TSDB_FCURRENT_C);
|
||||
break;
|
||||
case TSDB_FEDIT_MERGE:
|
||||
current_fname(fs->pTsdb, current_t, TSDB_FCURRENT_M);
|
||||
break;
|
||||
default:
|
||||
ASSERT(0);
|
||||
}
|
||||
|
||||
tsem_wait(&fs->canEdit);
|
||||
|
||||
fs->etype = etype;
|
||||
fs->eid = eid;
|
||||
|
||||
// edit
|
||||
code = edit_fs(fs, aFileOp);
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
|
||||
// save fs
|
||||
// code = save_fs(fs->nstate, current_t);
|
||||
// TSDB_CHECK_CODE(code, lino, _exit);
|
||||
code = save_fs(&fs->nstate, current_t);
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
|
||||
_exit:
|
||||
if (code) {
|
||||
tsdbError("vgId:%d %s failed at line %d since %s, eid:%" PRId64 " etype:%d", TD_VID(fs->pTsdb->pVnode), __func__,
|
||||
lino, tstrerror(code), fs->eid, etype);
|
||||
tsdbError("vgId:%d %s failed at line %d since %s, etype:%d", TD_VID(fs->pTsdb->pVnode), __func__, lino,
|
||||
tstrerror(code), etype);
|
||||
} else {
|
||||
tsdbInfo("vgId:%d %s done, eid:%" PRId64 " etype:%d", TD_VID(fs->pTsdb->pVnode), __func__, fs->eid, etype);
|
||||
tsdbInfo("vgId:%d %s done, etype:%d", TD_VID(fs->pTsdb->pVnode), __func__, etype);
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue