提交 8c93f9d7 编写于 作者: H Hongze Cheng

more progress

上级 6628a47e
......@@ -74,6 +74,7 @@ void tfsbasename(const TFILE *pf, char *dest);
void tfsdirname(const TFILE *pf, char *dest);
// DIR APIs ====================================
int tfsMkdirAt(const char *rname, int level, int id);
int tfsMkdir(const char *rname);
int tfsRmdir(const char *rname);
int tfsRename(char *orname, char *nrname);
......
......@@ -237,18 +237,24 @@ void tfsdirname(const TFILE *pf, char *dest) {
}
// DIR APIs ====================================
int tfsMkdir(const char *rname) {
char aname[TSDB_FILENAME_LEN] = "\0";
int tfsMkdirAt(const char *rname, int level, int id) {
SDisk *pDisk = TFS_DISK_AT(level, id);
char aname[TSDB_FILENAME_LEN];
snprintf(aname, TSDB_FILENAME_LEN, "%s/%s", DISK_DIR(pDisk), rname);
if (taosMkDir(aname, 0755) != 0) {
terrno = TAOS_SYSTEM_ERROR(errno);
return -1;
}
return 0;
}
int tfsMkdir(const char *rname) {
for (int level = 0; level < TFS_NLEVEL(); level++) {
STier *pTier = TFS_TIER_AT(level);
for (int id = 0; id < TIER_NDISKS(pTier); id++) {
SDisk *pDisk = DISK_AT_TIER(pTier, id);
snprintf(aname, TSDB_FILENAME_LEN, "%s/%s", DISK_DIR(pDisk), rname);
if (mkdir(aname, 0755) != 0 && errno != EEXIST) {
fError("failed to create directory %s since %s", aname, strerror(errno));
terrno = TAOS_SYSTEM_ERROR(errno);
if (tfsMkdirAt(rname, level, id) < 0) {
return -1;
}
}
......
......@@ -29,6 +29,7 @@ static int tsdbScanAndTryFixFS(STsdbRepo *pRepo);
static int tsdbScanRootDir(STsdbRepo *pRepo);
static int tsdbScanDataDir(STsdbRepo *pRepo);
static bool tsdbIsTFileInFS(STsdbFS *pfs, const TFILE *pf);
static int tsdbRestoreCurrent(STsdbRepo *pRepo);
// ================== CURRENT file header info
static int tsdbEncodeFSHeader(void **buf, SFSHeader *pHeader) {
......@@ -232,7 +233,6 @@ void *tsdbFreeFS(STsdbFS *pfs) {
return NULL;
}
// TODO
int tsdbOpenFS(STsdbRepo *pRepo) {
STsdbFS * pfs = REPO_FS(pRepo);
char current[TSDB_FILENAME_LEN] = "\0";
......@@ -247,7 +247,10 @@ int tsdbOpenFS(STsdbRepo *pRepo) {
return -1;
}
} else {
// TODO: current file not exists, try to recover it
if (tsdbRestoreCurrent(pRepo) < 0) {
tsdbError("vgId:%d failed to restore current file since %s", REPO_ID(pRepo), tstrerror(terrno));
return -1;
}
}
// Load meta cache if has meta file
......@@ -259,7 +262,6 @@ int tsdbOpenFS(STsdbRepo *pRepo) {
return 0;
}
// TODO
void tsdbCloseFS(STsdbRepo *pRepo) {
// TODO
}
......@@ -896,4 +898,44 @@ static bool tsdbIsTFileInFS(STsdbFS *pfs, const TFILE *pf) {
}
return false;
}
static int tsdbRestoreCurrent(STsdbRepo *pRepo) {
char rootDir[TSDB_FILENAME_LEN];
char dataDir[TSDB_FILENAME_LEN];
TDIR * tdir = NULL;
const TFILE *pf = NULL;
char bname[TSDB_FILENAME_LEN];
// Loop to recover mfile
tsdbGetRootDir(REPO_ID(pRepo), rootDir);
tdir = tfsOpendir(rootDir);
if (tdir == NULL) {
tsdbError("vgId:%d failed to open dir %s since %s", REPO_ID(pRepo), rootDir, tstrerror(terrno));
return -1;
}
while ((pf = tfsReaddir(tdir))) {
tfsbasename(pf, bname);
if (strncmp(bname, "meta", sizeof("meta")) == 0) {
// TODO
break;
}
}
tfsClosedir(tdir);
// Loop to recover dfile set
tsdbGetDataDir(REPO_ID(pRepo), dataDir);
tdir = tfsOpendir(dataDir);
if (tdir == NULL) {
tsdbError("vgId:%d failed to open dir %s since %s", REPO_ID(pRepo), rootDir, tstrerror(terrno));
return -1;
}
// TODO
tfsClosedir(tdir);
return 0;
}
\ No newline at end of file
......@@ -308,6 +308,7 @@ int tsdbCreateDFile(SDFile *pDFile, bool updateHeader) {
ASSERT(pDFile->info.size == 0 && pDFile->info.magic == TSDB_FILE_INIT_MAGIC);
char buf[TSDB_FILE_HEAD_SIZE] = "\0";
// TODO: need to check if directory exists, if not, create the directory
pDFile->fd = open(TSDB_FILE_FULL_NAME(pDFile), O_WRONLY | O_CREAT | O_TRUNC, 0755);
if (pDFile->fd < 0) {
......
......@@ -655,6 +655,7 @@ static int32_t tsdbRecvDFileSetInfo(SSyncH *pSynch) {
}
static int tsdbReload(STsdbRepo *pRepo, bool isMfChanged) {
// TODO: may need to stop and restart stream
if (isMfChanged) {
tsdbCloseMeta(pRepo);
tsdbFreeMeta(pRepo->tsdbMeta);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册