more code

This commit is contained in:
Hongze Cheng 2023-04-07 16:52:30 +08:00
parent afbaeb0d2d
commit f100a328b4
2 changed files with 76 additions and 51 deletions

View File

@ -42,7 +42,8 @@ static int32_t destroy_file_system(struct STFileSystem **ppFS) {
} }
static int32_t get_current_json(STsdb *pTsdb, char fname[]) { static int32_t get_current_json(STsdb *pTsdb, char fname[]) {
return snprintf(fname, TSDB_FILENAME_LEN, "%s%s%s", pTsdb->path, TD_DIRSEP, "current.json"), 0; snprintf(fname, TSDB_FILENAME_LEN, "%s%s%s", pTsdb->path, TD_DIRSEP, "current.json");
return 0;
} }
static int32_t get_current_temp(STsdb *pTsdb, char fname[], EFsEditType etype) { static int32_t get_current_temp(STsdb *pTsdb, char fname[], EFsEditType etype) {
@ -69,12 +70,43 @@ static int32_t load_fs_from_file(const char *fname, struct STFileSystem *pFS) {
} }
static int32_t commit_edit(struct STFileSystem *pFS, EFsEditType etype) { static int32_t commit_edit(struct STFileSystem *pFS, EFsEditType etype) {
ASSERTS(0, "TODO: Not implemented yet"); int32_t code;
char ofname[TSDB_FILENAME_LEN];
char nfname[TSDB_FILENAME_LEN];
get_current_json(pFS->pTsdb, nfname);
get_current_temp(pFS->pTsdb, ofname, etype);
code = taosRenameFile(ofname, nfname);
if (code) {
code = TAOS_SYSTEM_ERROR(code);
return code;
}
ASSERTS(0, "TODO: Do changes to pFS");
return 0; return 0;
} }
static int32_t abort_edit(struct STFileSystem *pFS, EFsEditType etype) { static int32_t abort_edit(struct STFileSystem *pFS, EFsEditType etype) {
ASSERTS(0, "TODO: Not implemented yet"); int32_t code;
char fname[TSDB_FILENAME_LEN];
get_current_temp(pFS->pTsdb, fname, etype);
code = taosRemoveFile(fname);
if (code) code = TAOS_SYSTEM_ERROR(code);
return code;
}
static int32_t scan_file_system(struct STFileSystem *pFS) {
// ASSERTS(0, "TODO: Not implemented yet");
return 0;
}
static int32_t scan_and_schedule_merge(struct STFileSystem *pFS) {
// ASSERTS(0, "TODO: Not implemented yet");
return 0; return 0;
} }
@ -107,8 +139,6 @@ static int32_t open_file_system(struct STFileSystem *pFS, int8_t rollback) {
code = abort_edit(pFS, TSDB_FS_EDIT_COMMIT); code = abort_edit(pFS, TSDB_FS_EDIT_COMMIT);
TSDB_CHECK_CODE(code, lino, _exit); TSDB_CHECK_CODE(code, lino, _exit);
} }
} else {
ASSERTS(1, "Do nothing");
} }
// check current.json.t existence // check current.json.t existence
@ -122,6 +152,12 @@ static int32_t open_file_system(struct STFileSystem *pFS, int8_t rollback) {
} }
} }
code = scan_file_system(pFS);
TSDB_CHECK_CODE(code, lino, _exit);
code = scan_and_schedule_merge(pFS);
TSDB_CHECK_CODE(code, lino, _exit);
_exit: _exit:
if (code) { if (code) {
tsdbError("vgId:%d %s failed at line %d since %s", // tsdbError("vgId:%d %s failed at line %d since %s", //
@ -182,7 +218,6 @@ _exit:
int32_t tsdbCloseFileSystem(struct STFileSystem **ppFS) { int32_t tsdbCloseFileSystem(struct STFileSystem **ppFS) {
if (ppFS[0] == NULL) return 0; if (ppFS[0] == NULL) return 0;
close_file_system(ppFS[0]); close_file_system(ppFS[0]);
destroy_file_system(ppFS); destroy_file_system(ppFS);
return 0; return 0;
@ -207,55 +242,43 @@ _exit:
__func__, // __func__, //
lino, // lino, //
tstrerror(code)); tstrerror(code));
} else {
tsdbInfo("vgId:%d %s done, etype:%d", //
TD_VID(pFS->pTsdb->pVnode), //
__func__, //
etype);
} }
return code; return code;
} }
int32_t tsdbFileSystemEditCommit(struct STFileSystem *pFS, EFsEditType etype) { int32_t tsdbFileSystemEditCommit(struct STFileSystem *pFS, EFsEditType etype) {
int32_t code = 0; int32_t code = commit_edit(pFS, etype);
int32_t lino = 0;
char ofname[TSDB_FILENAME_LEN];
char nfname[TSDB_FILENAME_LEN];
get_current_json(pFS->pTsdb, nfname);
get_current_temp(pFS->pTsdb, ofname, etype);
code = taosRenameFile(ofname, nfname);
if (code) {
code = TAOS_SYSTEM_ERROR(errno);
TSDB_CHECK_CODE(code, lino, _exit);
}
_exit:
if (code) {
tsdbError("vgId:%d %s failed at line %d since %s", //
TD_VID(pFS->pTsdb->pVnode), //
__func__, //
lino, //
tstrerror(code));
}
tsem_post(&pFS->canEdit); tsem_post(&pFS->canEdit);
if (code) {
tsdbError("vgId:%d %s failed since %s", //
TD_VID(pFS->pTsdb->pVnode), //
__func__, //
tstrerror(code));
} else {
tsdbInfo("vgId:%d %s done, etype:%d", //
TD_VID(pFS->pTsdb->pVnode), //
__func__, //
etype);
}
return code; return code;
} }
int32_t tsdbFileSystemEditAbort(struct STFileSystem *pFS, EFsEditType etype) { int32_t tsdbFileSystemEditAbort(struct STFileSystem *pFS, EFsEditType etype) {
int32_t code = 0; int32_t code = abort_edit(pFS, etype);
int32_t lino = 0; tsem_post(&pFS->canEdit);
char fname[TSDB_FILENAME_LEN];
get_current_temp(pFS->pTsdb, fname, etype);
code = taosRemoveFile(fname);
TSDB_CHECK_CODE(code, lino, _exit);
_exit: _exit:
if (code) { if (code) {
tsdbError("vgId:%d %s failed at line %d since %s", // tsdbError("vgId:%d %s failed since %s, etype:%d", //
TD_VID(pFS->pTsdb->pVnode), // TD_VID(pFS->pTsdb->pVnode), //
__func__, // __func__, //
lino, // tstrerror(code), //
tstrerror(code)); etype);
} }
tsem_post(&pFS->canEdit);
return code; return code;
} }

View File

@ -24,11 +24,6 @@ extern "C" {
/* Exposed Handle */ /* Exposed Handle */
struct SFileSet; struct SFileSet;
struct SSttFileLayer {
int32_t level;
int32_t nFile;
struct STFile *fileList;
};
#define TSDB_STT_FILE_LEVEL_MAX 3 #define TSDB_STT_FILE_LEVEL_MAX 3
@ -36,10 +31,17 @@ struct SSttFileLayer {
/* Exposed Structs */ /* Exposed Structs */
struct SFileSet { struct SFileSet {
int32_t fid; int32_t fid;
int64_t nextid; int64_t nextid;
struct STFile *files[TSDB_FTYPE_MAX]; struct STFile *fHead; // .head
struct SSttFileLayer sttLayers[TSDB_STT_FILE_LEVEL_MAX]; struct STFile *fData; // .data
struct STFile *fSma; // .sma
struct STFile *fTomb; // .tomb
struct {
int32_t level;
int32_t nFile;
struct STFile *fileList;
} lStt[TSDB_STT_FILE_LEVEL_MAX];
}; };
#ifdef __cplusplus #ifdef __cplusplus