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