more progress
This commit is contained in:
parent
6628a47ef1
commit
8c93f9d74c
|
@ -74,6 +74,7 @@ void tfsbasename(const TFILE *pf, char *dest);
|
||||||
void tfsdirname(const TFILE *pf, char *dest);
|
void tfsdirname(const TFILE *pf, char *dest);
|
||||||
|
|
||||||
// DIR APIs ====================================
|
// DIR APIs ====================================
|
||||||
|
int tfsMkdirAt(const char *rname, int level, int id);
|
||||||
int tfsMkdir(const char *rname);
|
int tfsMkdir(const char *rname);
|
||||||
int tfsRmdir(const char *rname);
|
int tfsRmdir(const char *rname);
|
||||||
int tfsRename(char *orname, char *nrname);
|
int tfsRename(char *orname, char *nrname);
|
||||||
|
|
|
@ -237,18 +237,24 @@ void tfsdirname(const TFILE *pf, char *dest) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// DIR APIs ====================================
|
// DIR APIs ====================================
|
||||||
int tfsMkdir(const char *rname) {
|
int tfsMkdirAt(const char *rname, int level, int id) {
|
||||||
char aname[TSDB_FILENAME_LEN] = "\0";
|
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++) {
|
for (int level = 0; level < TFS_NLEVEL(); level++) {
|
||||||
STier *pTier = TFS_TIER_AT(level);
|
STier *pTier = TFS_TIER_AT(level);
|
||||||
for (int id = 0; id < TIER_NDISKS(pTier); id++) {
|
for (int id = 0; id < TIER_NDISKS(pTier); id++) {
|
||||||
SDisk *pDisk = DISK_AT_TIER(pTier, id);
|
if (tfsMkdirAt(rname, level, id) < 0) {
|
||||||
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);
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,6 +29,7 @@ static int tsdbScanAndTryFixFS(STsdbRepo *pRepo);
|
||||||
static int tsdbScanRootDir(STsdbRepo *pRepo);
|
static int tsdbScanRootDir(STsdbRepo *pRepo);
|
||||||
static int tsdbScanDataDir(STsdbRepo *pRepo);
|
static int tsdbScanDataDir(STsdbRepo *pRepo);
|
||||||
static bool tsdbIsTFileInFS(STsdbFS *pfs, const TFILE *pf);
|
static bool tsdbIsTFileInFS(STsdbFS *pfs, const TFILE *pf);
|
||||||
|
static int tsdbRestoreCurrent(STsdbRepo *pRepo);
|
||||||
|
|
||||||
// ================== CURRENT file header info
|
// ================== CURRENT file header info
|
||||||
static int tsdbEncodeFSHeader(void **buf, SFSHeader *pHeader) {
|
static int tsdbEncodeFSHeader(void **buf, SFSHeader *pHeader) {
|
||||||
|
@ -232,7 +233,6 @@ void *tsdbFreeFS(STsdbFS *pfs) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO
|
|
||||||
int tsdbOpenFS(STsdbRepo *pRepo) {
|
int tsdbOpenFS(STsdbRepo *pRepo) {
|
||||||
STsdbFS * pfs = REPO_FS(pRepo);
|
STsdbFS * pfs = REPO_FS(pRepo);
|
||||||
char current[TSDB_FILENAME_LEN] = "\0";
|
char current[TSDB_FILENAME_LEN] = "\0";
|
||||||
|
@ -247,7 +247,10 @@ int tsdbOpenFS(STsdbRepo *pRepo) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
} else {
|
} 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
|
// Load meta cache if has meta file
|
||||||
|
@ -259,7 +262,6 @@ int tsdbOpenFS(STsdbRepo *pRepo) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO
|
|
||||||
void tsdbCloseFS(STsdbRepo *pRepo) {
|
void tsdbCloseFS(STsdbRepo *pRepo) {
|
||||||
// TODO
|
// TODO
|
||||||
}
|
}
|
||||||
|
@ -896,4 +898,44 @@ static bool tsdbIsTFileInFS(STsdbFS *pfs, const TFILE *pf) {
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
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;
|
||||||
}
|
}
|
|
@ -308,6 +308,7 @@ int tsdbCreateDFile(SDFile *pDFile, bool updateHeader) {
|
||||||
ASSERT(pDFile->info.size == 0 && pDFile->info.magic == TSDB_FILE_INIT_MAGIC);
|
ASSERT(pDFile->info.size == 0 && pDFile->info.magic == TSDB_FILE_INIT_MAGIC);
|
||||||
|
|
||||||
char buf[TSDB_FILE_HEAD_SIZE] = "\0";
|
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);
|
pDFile->fd = open(TSDB_FILE_FULL_NAME(pDFile), O_WRONLY | O_CREAT | O_TRUNC, 0755);
|
||||||
if (pDFile->fd < 0) {
|
if (pDFile->fd < 0) {
|
||||||
|
|
|
@ -655,6 +655,7 @@ static int32_t tsdbRecvDFileSetInfo(SSyncH *pSynch) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static int tsdbReload(STsdbRepo *pRepo, bool isMfChanged) {
|
static int tsdbReload(STsdbRepo *pRepo, bool isMfChanged) {
|
||||||
|
// TODO: may need to stop and restart stream
|
||||||
if (isMfChanged) {
|
if (isMfChanged) {
|
||||||
tsdbCloseMeta(pRepo);
|
tsdbCloseMeta(pRepo);
|
||||||
tsdbFreeMeta(pRepo->tsdbMeta);
|
tsdbFreeMeta(pRepo->tsdbMeta);
|
||||||
|
|
Loading…
Reference in New Issue