refact
This commit is contained in:
parent
e96516ff5a
commit
65e388a584
|
@ -39,6 +39,14 @@ TFSDIR * tfsOpenDir(char *dir);
|
||||||
void tfsCloseDir(TFSDIR *tdir);
|
void tfsCloseDir(TFSDIR *tdir);
|
||||||
const TFSFILE *tfsReadDir(TFSDIR *tdir);
|
const TFSFILE *tfsReadDir(TFSDIR *tdir);
|
||||||
|
|
||||||
|
const char *tfsAbsName(TFSFILE *pfile, char dest[]);
|
||||||
|
const char *tfsRelName(TFSFILE *pfile, char dest[]);
|
||||||
|
void tfsDirName(TFSFILE *pfile, char dest[]);
|
||||||
|
void tfsBaseName(TFSFILE *pfile, char dest[]);
|
||||||
|
|
||||||
|
int tfsopen(TFSFILE *pfile);
|
||||||
|
int tfsclose(int, fd);
|
||||||
|
|
||||||
const char *tfsGetDiskName(int level, int id);
|
const char *tfsGetDiskName(int level, int id);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|
|
@ -21,7 +21,8 @@
|
||||||
struct TFSFILE {
|
struct TFSFILE {
|
||||||
int level;
|
int level;
|
||||||
int id;
|
int id;
|
||||||
char name[TSDB_FILENAME_LEN];
|
char rname[TSDB_FILENAME_LEN]; // REL name
|
||||||
|
char aname[TSDB_FILENAME_LEN]; // ABS name
|
||||||
};
|
};
|
||||||
|
|
||||||
struct TFSDIR {
|
struct TFSDIR {
|
||||||
|
@ -60,12 +61,13 @@ void tfsCloseDir(TFSDIR *tdir) {
|
||||||
const TFSFILE *tfsReadDir(TFSDIR *tdir) {
|
const TFSFILE *tfsReadDir(TFSDIR *tdir) {
|
||||||
if (tdir->dir == NULL) return NULL;
|
if (tdir->dir == NULL) return NULL;
|
||||||
|
|
||||||
|
char rname[TSDB_FILENAME_LEN] = "\0";
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
struct dirent *dp = readdir(tdir->dir);
|
struct dirent *dp = readdir(tdir->dir);
|
||||||
if (dp != NULL) {
|
if (dp != NULL) {
|
||||||
tdir->tfsfile.level = tdir->level;
|
snprintf(rname, TSDB_FILENAME_LEN, "%s/%s", tdir->name, dp->d_name);
|
||||||
tdir->tfsfile.id = tdir->id;
|
tsfInitFile(&(tdir->tfsfile), tdir->level, tdir->id, rname);
|
||||||
snprintf(tdir->tfsfile.name, TSDB_FILENAME_LEN, "%s/%s", tdir->name, dp->d_name);
|
|
||||||
|
|
||||||
return &(tdir->tfsfile);
|
return &(tdir->tfsfile);
|
||||||
}
|
}
|
||||||
|
@ -88,6 +90,41 @@ const TFSFILE *tfsReadDir(TFSDIR *tdir) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const char *tfsAbsName(TFSFILE *pfile, char dest[]) { return pfile->aname; }
|
||||||
|
const char *tfsRelName(TFSFILE *pfile, char dest[]) { return pfile->rname; }
|
||||||
|
|
||||||
|
void tfsDirName(TFSFILE *pfile, char dest[]) {
|
||||||
|
char fname[TSDB_FILENAME_LEN] = "\0";
|
||||||
|
|
||||||
|
tfsAbsFname(pfile, fname);
|
||||||
|
strncpy(dest, dirname(fname), TSDB_FILENAME_LEN);
|
||||||
|
}
|
||||||
|
|
||||||
|
void tfsBaseName(TFSFILE *pfile, char dest[]) {
|
||||||
|
char fname[TSDB_FILENAME_LEN] = "\0";
|
||||||
|
memcpy((void *)fname, (void *)pfile->rname, TSDB_FILENAME_LEN);
|
||||||
|
strncpy(dest, basename(fname), TSDB_FILENAME_LEN);
|
||||||
|
}
|
||||||
|
|
||||||
|
int tfsopen(TFSFILE *pfile, int flags) {
|
||||||
|
int fd = open(pfile->aname, flags);
|
||||||
|
if (fd < 0) {
|
||||||
|
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return fd;
|
||||||
|
}
|
||||||
|
|
||||||
|
int tfsclose(int fd) {
|
||||||
|
if (close(fd) < 0) {
|
||||||
|
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
static int tfsOpenDirImpl(TFSDIR *tdir) {
|
static int tfsOpenDirImpl(TFSDIR *tdir) {
|
||||||
char dirName[TSDB_FILENAME_LEN] = "\0";
|
char dirName[TSDB_FILENAME_LEN] = "\0";
|
||||||
|
|
||||||
|
@ -116,3 +153,10 @@ static int tfsOpenDirImpl(TFSDIR *tdir) {
|
||||||
ASSERT(tdir->dir == NULL);
|
ASSERT(tdir->dir == NULL);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void tsfInitFile(TFSFILE *pfile, int level, int id, char *rname) {
|
||||||
|
pfile->level = level;
|
||||||
|
pfile->id = id;
|
||||||
|
strncpy(pfile->rname, rname, TSDB_FILENAME_LEN);
|
||||||
|
snprintf(pfile->aname, TSDB_FILENAME_LEN, "%s/%s", tfsGetDiskName(level, id), rname);
|
||||||
|
}
|
|
@ -189,10 +189,8 @@ typedef struct {
|
||||||
} STsdbFileInfo;
|
} STsdbFileInfo;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
// char fname[TSDB_FILENAME_LEN];
|
int fd;
|
||||||
// int fd;
|
TFSFILE tfile;
|
||||||
|
|
||||||
STfsFile tfile;
|
|
||||||
STsdbFileInfo info;
|
STsdbFileInfo info;
|
||||||
} SFile;
|
} SFile;
|
||||||
|
|
||||||
|
|
|
@ -215,12 +215,6 @@ static int tsdbCommitToFile(STsdbRepo *pRepo, int fid, SCommitIter *iters, SRWHe
|
||||||
goto _err;
|
goto _err;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Open files for write/read
|
|
||||||
if (tsdbSetAndOpenHelperFile(pHelper, pGroup) < 0) {
|
|
||||||
tsdbError("vgId:%d failed to set helper file since %s", REPO_ID(pRepo), tstrerror(terrno));
|
|
||||||
goto _err;
|
|
||||||
}
|
|
||||||
|
|
||||||
newLast = TSDB_NLAST_FILE_OPENED(pHelper);
|
newLast = TSDB_NLAST_FILE_OPENED(pHelper);
|
||||||
|
|
||||||
if (tsdbLoadCompIdx(pHelper, NULL) < 0) {
|
if (tsdbLoadCompIdx(pHelper, NULL) < 0) {
|
||||||
|
|
|
@ -68,6 +68,61 @@ int tsdbOpenFileH(STsdbRepo *pRepo) {
|
||||||
ASSERT(pRepo != NULL && pRepo->tsdbFileH != NULL);
|
ASSERT(pRepo != NULL && pRepo->tsdbFileH != NULL);
|
||||||
char dataDir[TSDB_FILENAME_LEN] = "\0";
|
char dataDir[TSDB_FILENAME_LEN] = "\0";
|
||||||
|
|
||||||
|
// 1. scan and get all files corresponds
|
||||||
|
TFSDIR *tdir = NULL;
|
||||||
|
char fname[TSDB_FILENAME_LEN] = "\0";
|
||||||
|
regex_t regex = {0};
|
||||||
|
int code = 0;
|
||||||
|
int vid = 0;
|
||||||
|
int fid = 0;
|
||||||
|
|
||||||
|
const TFSFILE *pfile = NULL;
|
||||||
|
|
||||||
|
code = regcomp(®ex, "^v[0-9]+f[0-9]+\\.(head|data|last|h|d|l)$", REG_EXTENDED);
|
||||||
|
if (code != 0) {
|
||||||
|
// TODO: deal the error
|
||||||
|
}
|
||||||
|
|
||||||
|
snprintf(dataDir, TSDB_FILENAME_LEN, "vnode/vnode%d/tsdb/data", REPO_ID(pRepo));
|
||||||
|
tdir = tfsOpenDir(dataDir);
|
||||||
|
if (tdir == NULL) {
|
||||||
|
// TODO: deal the error
|
||||||
|
}
|
||||||
|
|
||||||
|
while ((pfile = tfsReadDir(tdir)) != NULL) {
|
||||||
|
tfsBaseName(pfile, fname);
|
||||||
|
|
||||||
|
if (strcmp(fname, ".") == 0 || strcmp(fname, "..") == 0) continue;
|
||||||
|
|
||||||
|
code = regexec(®ex, fname, 0, NULL, 0);
|
||||||
|
if (code == 0) {
|
||||||
|
sscanf(fname, "v%df%d", &vid, &fid);
|
||||||
|
|
||||||
|
if (vid != REPO_ID(pRepo)) {
|
||||||
|
tfsAbsName(pfile, fname);
|
||||||
|
tsdbError("vgId:%d invalid file %s exists, ignore", REPO_ID(pRepo), fname);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO
|
||||||
|
{}
|
||||||
|
} else if (code == REG_NOMATCH) {
|
||||||
|
tfsAbsName(pfile, fname);
|
||||||
|
tsdbWarn("vgId:%d unrecognizable file %s exists, ignore", REPO_ID(pRepo), fname);
|
||||||
|
continue;
|
||||||
|
} else {
|
||||||
|
tsdbError("vgId:%d regexec failed since %s", REPO_ID(pRepo), strerror(code));
|
||||||
|
// TODO: deal with error
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2. Sort all files according to fid
|
||||||
|
|
||||||
|
// 3. Recover all files of each fid
|
||||||
|
while (true) {
|
||||||
|
// TODO
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue