提交 3e31cdbe 编写于 作者: H Hongze Cheng

refact

上级 a76580bc
...@@ -51,6 +51,7 @@ typedef struct { ...@@ -51,6 +51,7 @@ typedef struct {
#define FS_CURRENT_STATUS(pfs) ((pfs)->cstatus) #define FS_CURRENT_STATUS(pfs) ((pfs)->cstatus)
#define FS_NEW_STATUS(pfs) ((pfs)->nstatus) #define FS_NEW_STATUS(pfs) ((pfs)->nstatus)
#define FS_IN_TXN(pfs) (pfs)->intxn #define FS_IN_TXN(pfs) (pfs)->intxn
#define FS_VERSION(pfs) ((pfs)->cstatus->meta.version)
#define FS_TXN_VERSION(pfs) ((pfs)->nstatus->meta.version) #define FS_TXN_VERSION(pfs) ((pfs)->nstatus->meta.version)
typedef struct { typedef struct {
......
...@@ -159,27 +159,24 @@ static void tsdbResetFSStatus(SFSStatus *pStatus) { ...@@ -159,27 +159,24 @@ static void tsdbResetFSStatus(SFSStatus *pStatus) {
} }
static void tsdbSetStatusMFile(SFSStatus *pStatus, const SMFile *pMFile) { static void tsdbSetStatusMFile(SFSStatus *pStatus, const SMFile *pMFile) {
ASSERT(pStatus->pmf == NULL && TSDB_FILE_CLOSED(pMFile)); ASSERT(pStatus->pmf == NULL);
pStatus->pmf = &(pStatus->mf); pStatus->pmf = &(pStatus->mf);
*(pStatus->pmf) = *pMFile; tsdbInitMFileEx(pStatus->pmf, pMFile);
} }
static int tsdbAddDFileSetToStatus(SFSStatus *pStatus, const SDFileSet *pSet) { static int tsdbAddDFileSetToStatus(SFSStatus *pStatus, const SDFileSet *pSet) {
ASSERT(TSDB_FILE_CLOSED(&(pSet->files[0])));
ASSERT(TSDB_FILE_CLOSED(&(pSet->files[1])));
ASSERT(TSDB_FILE_CLOSED(&(pSet->files[2])));
if (taosArrayPush(pStatus->df, (void *)pSet) == NULL) { if (taosArrayPush(pStatus->df, (void *)pSet) == NULL) {
terrno = TSDB_CODE_TDB_OUT_OF_MEMORY; terrno = TSDB_CODE_TDB_OUT_OF_MEMORY;
return -1; return -1;
} }
TSDB_FSET_SET_CLOSED(((SDFileSet *)taosArrayGetLast(pStatus->df)));
return 0; return 0;
} }
// ================== STsdbFS // ================== STsdbFS
// TODO
STsdbFS *tsdbNewFS(STsdbCfg *pCfg) { STsdbFS *tsdbNewFS(STsdbCfg *pCfg) {
int keep = pCfg->keep; int keep = pCfg->keep;
int days = pCfg->daysPerFile; int days = pCfg->daysPerFile;
...@@ -221,7 +218,6 @@ STsdbFS *tsdbNewFS(STsdbCfg *pCfg) { ...@@ -221,7 +218,6 @@ STsdbFS *tsdbNewFS(STsdbCfg *pCfg) {
return pfs; return pfs;
} }
// TODO
void *tsdbFreeFS(STsdbFS *pfs) { void *tsdbFreeFS(STsdbFS *pfs) {
if (pfs) { if (pfs) {
pfs->nstatus = tsdbFreeFSStatus(pfs->nstatus); pfs->nstatus = tsdbFreeFSStatus(pfs->nstatus);
...@@ -235,7 +231,7 @@ void *tsdbFreeFS(STsdbFS *pfs) { ...@@ -235,7 +231,7 @@ void *tsdbFreeFS(STsdbFS *pfs) {
} }
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";
ASSERT(pfs != NULL); ASSERT(pfs != NULL);
...@@ -254,6 +250,11 @@ int tsdbOpenFS(STsdbRepo *pRepo) { ...@@ -254,6 +250,11 @@ int tsdbOpenFS(STsdbRepo *pRepo) {
} }
} }
if (tsdbScanAndTryFixFS(pRepo) < 0) {
tsdbError("vgId:%d failed to scan and fix FS since %s", REPO_ID(pRepo), tstrerror(terrno));
return -1;
}
// Load meta cache if has meta file // Load meta cache if has meta file
if ((!(pRepo->state & TSDB_STATE_BAD_META)) && tsdbLoadMetaCache(pRepo, true) < 0) { if ((!(pRepo->state & TSDB_STATE_BAD_META)) && tsdbLoadMetaCache(pRepo, true) < 0) {
tsdbError("vgId:%d failed to open FS while loading meta cache since %s", REPO_ID(pRepo), tstrerror(terrno)); tsdbError("vgId:%d failed to open FS while loading meta cache since %s", REPO_ID(pRepo), tstrerror(terrno));
...@@ -264,7 +265,7 @@ int tsdbOpenFS(STsdbRepo *pRepo) { ...@@ -264,7 +265,7 @@ int tsdbOpenFS(STsdbRepo *pRepo) {
} }
void tsdbCloseFS(STsdbRepo *pRepo) { void tsdbCloseFS(STsdbRepo *pRepo) {
// TODO // Do nothing
} }
// Start a new transaction to modify the file system // Start a new transaction to modify the file system
...@@ -651,10 +652,6 @@ static int tsdbOpenFSFromCurrent(STsdbRepo *pRepo) { ...@@ -651,10 +652,6 @@ static int tsdbOpenFSFromCurrent(STsdbRepo *pRepo) {
taosTZfree(buffer); taosTZfree(buffer);
close(fd); close(fd);
if (tsdbScanAndTryFixFS(pRepo) < 0) {
return -1;
}
return 0; return 0;
_err: _err:
...@@ -965,6 +962,7 @@ static int tsdbRestoreMeta(STsdbRepo *pRepo) { ...@@ -965,6 +962,7 @@ static int tsdbRestoreMeta(STsdbRepo *pRepo) {
if (tsdbLoadMFileHeader(pfs->cstatus->pmf, &(pfs->cstatus->pmf->info)) < 0) { if (tsdbLoadMFileHeader(pfs->cstatus->pmf, &(pfs->cstatus->pmf->info)) < 0) {
tsdbError("vgId:%d failed to restore meta since %s", REPO_ID(pRepo), tstrerror(terrno)); tsdbError("vgId:%d failed to restore meta since %s", REPO_ID(pRepo), tstrerror(terrno));
tsdbCloseMFile(pfs->cstatus->pmf);
tfsClosedir(tdir); tfsClosedir(tdir);
regfree(&regex); regfree(&regex);
return -1; return -1;
......
...@@ -581,6 +581,7 @@ void *tsdbDecodeDFileSet(void *buf, SDFileSet *pSet) { ...@@ -581,6 +581,7 @@ void *tsdbDecodeDFileSet(void *buf, SDFileSet *pSet) {
int32_t fid; int32_t fid;
buf = taosDecodeFixedI32(buf, &(fid)); buf = taosDecodeFixedI32(buf, &(fid));
pSet->state = 0;
pSet->fid = fid; pSet->fid = fid;
for (TSDB_FILE_T ftype = 0; ftype < TSDB_FILE_MAX; ftype++) { for (TSDB_FILE_T ftype = 0; ftype < TSDB_FILE_MAX; ftype++) {
buf = tsdbDecodeSDFile(buf, TSDB_DFILE_IN_SET(pSet, ftype)); buf = tsdbDecodeSDFile(buf, TSDB_DFILE_IN_SET(pSet, ftype));
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册