more code

This commit is contained in:
Hongze Cheng 2023-04-06 16:26:41 +08:00
parent e8e0e4976e
commit 4e8e3854a7
2 changed files with 109 additions and 1 deletions

View File

@ -31,6 +31,24 @@ static int32_t destroy_file_system(struct STFileSystem **ppFS) {
return 0; return 0;
} }
static int32_t get_current_file_name(STsdb *pTsdb, char fname[]) {
snprintf(fname, TSDB_FILENAME_LEN, "%s%s%s", pTsdb->path, TD_DIRSEP, "current.json");
return 0;
}
static int32_t get_temp_current_file_name(STsdb *pTsdb, char fname[], EFsEditType etype) {
switch (etype) {
case TSDB_FS_EDIT_COMMIT:
snprintf(fname, TSDB_FILENAME_LEN, "%s%s%s", pTsdb->path, TD_DIRSEP, "current.json.commit");
break;
default:
snprintf(fname, TSDB_FILENAME_LEN, "%s%s%s", pTsdb->path, TD_DIRSEP, "current.json.t");
break;
}
return 0;
}
static int32_t open_file_system(struct STFileSystem *pFS, int8_t rollback) { static int32_t open_file_system(struct STFileSystem *pFS, int8_t rollback) {
// TODO // TODO
return 0; return 0;
@ -41,6 +59,16 @@ static int32_t close_file_system(struct STFileSystem *pFS) {
return 0; return 0;
} }
static int32_t write_fs_to_file(struct STFileSystem *pFS, const char *fname) {
// TODO
return 0;
}
static int32_t read_fs_from_file(struct STFileSystem *pFS, const char *fname) {
// TODO
return 0;
}
int32_t tsdbOpenFileSystem(STsdb *pTsdb, struct STFileSystem **ppFS, int8_t rollback) { int32_t tsdbOpenFileSystem(STsdb *pTsdb, struct STFileSystem **ppFS, int8_t rollback) {
int32_t code; int32_t code;
int32_t lino; int32_t lino;
@ -68,3 +96,75 @@ int32_t tsdbCloseFileSystem(struct STFileSystem **ppFS) {
destroy_file_system(ppFS); destroy_file_system(ppFS);
return 0; return 0;
} }
int32_t tsdbFileSystemEditBegin(struct STFileSystem *pFS, const SArray *aFileOp, EFsEditType etype) {
int32_t code = 0;
int32_t lino = 0;
char fname[TSDB_FILENAME_LEN];
get_temp_current_file_name(pFS->pTsdb, fname, etype);
tsem_wait(&pFS->canEdit);
code = write_fs_to_file(pFS, fname);
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));
}
return code;
}
int32_t tsdbFileSystemEditCommit(struct STFileSystem *pFS, EFsEditType etype) {
int32_t code = 0;
int32_t lino = 0;
char ofname[TSDB_FILENAME_LEN];
char nfname[TSDB_FILENAME_LEN];
get_current_file_name(pFS->pTsdb, nfname);
get_temp_current_file_name(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);
return code;
}
int32_t tsdbFileSystemEditAbort(struct STFileSystem *pFS, EFsEditType etype) {
int32_t code = 0;
int32_t lino = 0;
char fname[TSDB_FILENAME_LEN];
get_temp_current_file_name(pFS->pTsdb, fname, etype);
code = taosRemoveFile(fname);
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);
return code;
}

View File

@ -25,16 +25,24 @@ extern "C" {
/* Exposed Handle */ /* Exposed Handle */
struct STFileSystem; struct STFileSystem;
typedef enum {
TSDB_FS_EDIT_COMMIT = 0,
TSDB_FS_EDIT_MERGE,
} EFsEditType;
/* Exposed APIs */ /* Exposed APIs */
// open/close // open/close
int32_t tsdbOpenFileSystem(STsdb *pTsdb, struct STFileSystem **ppFS, int8_t rollback); int32_t tsdbOpenFileSystem(STsdb *pTsdb, struct STFileSystem **ppFS, int8_t rollback);
int32_t tsdbCloseFileSystem(struct STFileSystem **ppFS); int32_t tsdbCloseFileSystem(struct STFileSystem **ppFS);
// txn // txn
// int32_t tsdb int32_t tsdbFileSystemEditBegin(struct STFileSystem *pFS, const SArray *aFileOp, EFsEditType etype);
int32_t tsdbFileSystemEditCommit(struct STFileSystem *pFS, EFsEditType etype);
int32_t tsdbFileSystemEditAbort(struct STFileSystem *pFS, EFsEditType etype);
/* Exposed Structs */ /* Exposed Structs */
struct STFileSystem { struct STFileSystem {
STsdb *pTsdb; STsdb *pTsdb;
tsem_t canEdit;
int32_t nFileSet; int32_t nFileSet;
struct SFileSet *aFileSet; struct SFileSet *aFileSet;
}; };