refactor
This commit is contained in:
parent
5b75528872
commit
dae3e2ec19
|
@ -63,8 +63,8 @@ int tfsopen(TFILE *pf, int flags);
|
||||||
int tfsclose(int fd);
|
int tfsclose(int fd);
|
||||||
int tfsremove(TFILE *pf);
|
int tfsremove(TFILE *pf);
|
||||||
int tfscopy(TFILE *sf, TFILE *df);
|
int tfscopy(TFILE *sf, TFILE *df);
|
||||||
void tfsbasename(TFILE *pf, char *dest);
|
void tfsbasename(const TFILE *pf, char *dest);
|
||||||
void tfsdirname(TFILE *pf, char *dest);
|
void tfsdirname(const TFILE *pf, char *dest);
|
||||||
|
|
||||||
// DIR APIs ====================================
|
// DIR APIs ====================================
|
||||||
int tfsMkdir(const char *rname);
|
int tfsMkdir(const char *rname);
|
||||||
|
|
|
@ -265,14 +265,14 @@ int tfscopy(TFILE *sf, TFILE *df) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void tfsbasename(TFILE *pf, char *dest) {
|
void tfsbasename(const TFILE *pf, char *dest) {
|
||||||
char tname[TSDB_FILENAME_LEN] = "\0";
|
char tname[TSDB_FILENAME_LEN] = "\0";
|
||||||
|
|
||||||
strncpy(tname, pf->aname, TSDB_FILENAME_LEN);
|
strncpy(tname, pf->aname, TSDB_FILENAME_LEN);
|
||||||
strncpy(dest, basename(tname), TSDB_FILENAME_LEN);
|
strncpy(dest, basename(tname), TSDB_FILENAME_LEN);
|
||||||
}
|
}
|
||||||
|
|
||||||
void tfsdirname(TFILE *pf, char *dest) {
|
void tfsdirname(const TFILE *pf, char *dest) {
|
||||||
char tname[TSDB_FILENAME_LEN] = "\0";
|
char tname[TSDB_FILENAME_LEN] = "\0";
|
||||||
|
|
||||||
strncpy(tname, pf->aname, TSDB_FILENAME_LEN);
|
strncpy(tname, pf->aname, TSDB_FILENAME_LEN);
|
||||||
|
|
|
@ -100,7 +100,7 @@ int tsdbOpenFileH(STsdbRepo *pRepo) {
|
||||||
int count = 0;
|
int count = 0;
|
||||||
|
|
||||||
TFILE *pf = taosArrayGet(pfArray, iter);
|
TFILE *pf = taosArrayGet(pfArray, iter);
|
||||||
tsdbParseFname(pf, bname);
|
tfsbasename(pf, bname);
|
||||||
tsdbParseFname(bname, &vid, &fid, suffix);
|
tsdbParseFname(bname, &vid, &fid, suffix);
|
||||||
count++;
|
count++;
|
||||||
iter++;
|
iter++;
|
||||||
|
@ -108,7 +108,7 @@ int tsdbOpenFileH(STsdbRepo *pRepo) {
|
||||||
while (true) {
|
while (true) {
|
||||||
int nfid = 0;
|
int nfid = 0;
|
||||||
TFILE *npf = taosArrayGet(pfArray, iter);
|
TFILE *npf = taosArrayGet(pfArray, iter);
|
||||||
tsdbParseFname(npf, bname);
|
tfsbasename(npf, bname);
|
||||||
tsdbParseFname(bname, &vid, &nfid, suffix);
|
tsdbParseFname(bname, &vid, &nfid, suffix);
|
||||||
|
|
||||||
if (nfid != fid) break;
|
if (nfid != fid) break;
|
||||||
|
@ -518,7 +518,6 @@ static void *tsdbScanAllFiles(STsdbRepo *pRepo) {
|
||||||
TDIR * tdir = NULL;
|
TDIR * tdir = NULL;
|
||||||
char dirName[TSDB_FILENAME_LEN] = "\0";
|
char dirName[TSDB_FILENAME_LEN] = "\0";
|
||||||
char bname[TSDB_FILENAME_LEN] = "\0";
|
char bname[TSDB_FILENAME_LEN] = "\0";
|
||||||
int arraySize = 0;
|
|
||||||
regex_t regex1 = {0};
|
regex_t regex1 = {0};
|
||||||
const TFILE *pf = NULL;
|
const TFILE *pf = NULL;
|
||||||
|
|
||||||
|
@ -535,7 +534,7 @@ static void *tsdbScanAllFiles(STsdbRepo *pRepo) {
|
||||||
tdir = tfsOpendir(dirName);
|
tdir = tfsOpendir(dirName);
|
||||||
|
|
||||||
while ((pf = tfsReaddir(tdir)) != NULL) {
|
while ((pf = tfsReaddir(tdir)) != NULL) {
|
||||||
fsbasename(pf, bname);
|
tfsbasename(pf, bname);
|
||||||
|
|
||||||
int code = regexec(®ex1, bname, 0, NULL, 0);
|
int code = regexec(®ex1, bname, 0, NULL, 0);
|
||||||
if (code != 0) {
|
if (code != 0) {
|
||||||
|
@ -569,14 +568,14 @@ static int tsdbCompareFile(const void *arg1, const void *arg2) {
|
||||||
if (fid1 < fid2) {
|
if (fid1 < fid2) {
|
||||||
return -1;
|
return -1;
|
||||||
} else if (fid1 == fid2) {
|
} else if (fid1 == fid2) {
|
||||||
return 0
|
return 0;
|
||||||
} else {
|
} else {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int tsdbRestoreFile(STsdbRepo *pRepo, TFILE *pfiles, int nfile) {
|
static int tsdbRestoreFile(STsdbRepo *pRepo, TFILE *pfiles, int nfile) {
|
||||||
char backname[TSDB_FILENAME_LEN] = "\0";
|
char backname[TSDB_FILENAME_LEN*2] = "\0";
|
||||||
char bname[TSDB_FILENAME_LEN] = "\0";
|
char bname[TSDB_FILENAME_LEN] = "\0";
|
||||||
STsdbFileH *pFileH = pRepo->tsdbFileH;
|
STsdbFileH *pFileH = pRepo->tsdbFileH;
|
||||||
TFILE * pfArray[TSDB_FILE_TYPE_MAX] = {0};
|
TFILE * pfArray[TSDB_FILE_TYPE_MAX] = {0};
|
||||||
|
@ -610,7 +609,7 @@ static int tsdbRestoreFile(STsdbRepo *pRepo, TFILE *pfiles, int nfile) {
|
||||||
|
|
||||||
if (pfArray[TSDB_FILE_TYPE_HEAD] == NULL || pfArray[TSDB_FILE_TYPE_DATA] == NULL || pfArray[TSDB_FILE_TYPE_LAST] == NULL) {
|
if (pfArray[TSDB_FILE_TYPE_HEAD] == NULL || pfArray[TSDB_FILE_TYPE_DATA] == NULL || pfArray[TSDB_FILE_TYPE_LAST] == NULL) {
|
||||||
for (int i = 0; i < nfile; i++) {
|
for (int i = 0; i < nfile; i++) {
|
||||||
snprintf(backname, TSDB_FILENAME_LEN, "%s_bak", (pfiles + i)->aname);
|
snprintf(backname, TSDB_FILENAME_LEN*2, "%s_bak", (pfiles + i)->aname);
|
||||||
rename((pfiles + i)->aname, backname);
|
rename((pfiles + i)->aname, backname);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -619,7 +618,7 @@ static int tsdbRestoreFile(STsdbRepo *pRepo, TFILE *pfiles, int nfile) {
|
||||||
|
|
||||||
if (pHf == NULL) {
|
if (pHf == NULL) {
|
||||||
if (pLf != NULL) {
|
if (pLf != NULL) {
|
||||||
rename(pLf->aname, pLastf->aname);
|
rename(pLf->aname, pfArray[TSDB_FILE_TYPE_LAST]->aname);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (pLf != NULL) {
|
if (pLf != NULL) {
|
||||||
|
@ -632,18 +631,19 @@ static int tsdbRestoreFile(STsdbRepo *pRepo, TFILE *pfiles, int nfile) {
|
||||||
fg.fileId = fid;
|
fg.fileId = fid;
|
||||||
|
|
||||||
for (int type = 0; type < TSDB_FILE_TYPE_MAX; type++) {
|
for (int type = 0; type < TSDB_FILE_TYPE_MAX; type++) {
|
||||||
SFile *pFile = fg.files + type;
|
SFile * pFile = fg.files + type;
|
||||||
|
uint32_t version = 0;
|
||||||
|
|
||||||
pFile->fd = -1;
|
pFile->fd = -1;
|
||||||
pFile->file = *pfArray[type]; // TODO
|
pFile->file = *pfArray[type]; // TODO
|
||||||
tsdbOpenFile(pFile, O_RDONLY);
|
tsdbOpenFile(pFile, O_RDONLY);
|
||||||
tsdbLoadFileHeader(pFile);
|
tsdbLoadFileHeader(pFile, &version);
|
||||||
tsdbCloseFile(pFile);
|
tsdbCloseFile(pFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
pFileH->pFGroup[pFileH->nFGroups++] = fg;
|
pFileH->pFGroup[pFileH->nFGroups++] = fg;
|
||||||
|
|
||||||
tfsIncDiskFile(pHeadf->level, pHeadf->id, TSDB_FILE_TYPE_MAX);
|
tfsIncDiskFile(pfArray[TSDB_FILE_TYPE_HEAD]->level, pfArray[TSDB_FILE_TYPE_HEAD]->id, TSDB_FILE_TYPE_MAX);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,7 +46,7 @@ void* taosArrayInit(size_t size, size_t elemSize);
|
||||||
* @param pData
|
* @param pData
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
void* taosArrayPush(SArray* pArray, void* pData);
|
void* taosArrayPush(SArray* pArray, const void* pData);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
|
|
@ -55,7 +55,7 @@ static int32_t taosArrayResize(SArray* pArray) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void* taosArrayPush(SArray* pArray, void* pData) {
|
void* taosArrayPush(SArray* pArray, const void* pData) {
|
||||||
if (pArray == NULL || pData == NULL) {
|
if (pArray == NULL || pData == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue