finish tsdbGetFileInfo function
This commit is contained in:
parent
095d5f8ddf
commit
300c0475bf
|
@ -515,6 +515,8 @@ void tsdbAdjustCacheBlocks(STsdbCache *pCache);
|
||||||
int32_t tsdbGetMetaFileName(char *rootDir, char *fname);
|
int32_t tsdbGetMetaFileName(char *rootDir, char *fname);
|
||||||
int tsdbUpdateFileHeader(SFile *pFile, uint32_t version);
|
int tsdbUpdateFileHeader(SFile *pFile, uint32_t version);
|
||||||
|
|
||||||
|
int compFGroupKey(const void *key, const void *fgroup);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -35,7 +35,6 @@ const char *tsdbFileSuffix[] = {
|
||||||
".last" // TSDB_FILE_TYPE_LAST
|
".last" // TSDB_FILE_TYPE_LAST
|
||||||
};
|
};
|
||||||
|
|
||||||
static int compFGroupKey(const void *key, const void *fgroup);
|
|
||||||
static int compFGroup(const void *arg1, const void *arg2);
|
static int compFGroup(const void *arg1, const void *arg2);
|
||||||
static int tsdbOpenFGroup(STsdbFileH *pFileH, char *dataDir, int fid);
|
static int tsdbOpenFGroup(STsdbFileH *pFileH, char *dataDir, int fid);
|
||||||
|
|
||||||
|
@ -285,7 +284,7 @@ int tsdbCopyBlockDataInFile(SFile *pOutFile, SFile *pInFile, SCompInfo *pCompInf
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int compFGroupKey(const void *key, const void *fgroup) {
|
int compFGroupKey(const void *key, const void *fgroup) {
|
||||||
int fid = *(int *)key;
|
int fid = *(int *)key;
|
||||||
SFileGroup *pFGroup = (SFileGroup *)fgroup;
|
SFileGroup *pFGroup = (SFileGroup *)fgroup;
|
||||||
return (fid - pFGroup->fileId);
|
return (fid - pFGroup->fileId);
|
||||||
|
|
|
@ -1179,9 +1179,8 @@ static void tsdbAlterMaxTables(STsdbRepo *pRepo, int32_t maxTables) {
|
||||||
tsdbTrace("vgId:%d, tsdb maxTables is changed from %d to %d!", pRepo->config.tsdbId, oldMaxTables, maxTables);
|
tsdbTrace("vgId:%d, tsdb maxTables is changed from %d to %d!", pRepo->config.tsdbId, oldMaxTables, maxTables);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define TSDB_META_FILE_INDEX 10000000
|
||||||
uint32_t tsdbGetFileInfo(TsdbRepoT *repo, char *name, uint32_t *index, uint32_t eindex, int32_t *size) {
|
uint32_t tsdbGetFileInfo(TsdbRepoT *repo, char *name, uint32_t *index, uint32_t eindex, int32_t *size) {
|
||||||
// TODO: need to refactor this function
|
|
||||||
|
|
||||||
STsdbRepo *pRepo = (STsdbRepo *)repo;
|
STsdbRepo *pRepo = (STsdbRepo *)repo;
|
||||||
// STsdbMeta *pMeta = pRepo->tsdbMeta;
|
// STsdbMeta *pMeta = pRepo->tsdbMeta;
|
||||||
STsdbFileH *pFileH = pRepo->tsdbFileH;
|
STsdbFileH *pFileH = pRepo->tsdbFileH;
|
||||||
|
@ -1189,33 +1188,74 @@ uint32_t tsdbGetFileInfo(TsdbRepoT *repo, char *name, uint32_t *index, uint32_t
|
||||||
char fname[256] = "\0";
|
char fname[256] = "\0";
|
||||||
|
|
||||||
struct stat fState;
|
struct stat fState;
|
||||||
char *spath = strdup(pRepo->rootDir);
|
|
||||||
char *prefixDir = dirname(spath);
|
|
||||||
|
|
||||||
if (name[0] == 0) {
|
tsdbTrace("vgId:%d name:%s index:%d eindex:%d", pRepo->config.tsdbId, name, *index, eindex);
|
||||||
// Map index to the file name
|
ASSERT(*index <= eindex);
|
||||||
int fid = (*index) / 3;
|
|
||||||
|
|
||||||
if (fid >= pFileH->numOfFGroups) {
|
if (name[0] == 0) { // get the file from index or after, but not larger than eindex
|
||||||
// return meta data file
|
if (*index == 0) { // need to return the first file and set the *index
|
||||||
if ((*index) % 3 > 0) { // it is finished
|
if (pFileH->numOfFGroups > 0) {
|
||||||
tfree(spath);
|
int fid = TSDB_MIN_FILE_ID(pFileH);
|
||||||
|
|
||||||
|
if (fid * 3 <= eindex) {
|
||||||
|
strcpy(fname, pFileH->fGroup[fid].files[0].fname);
|
||||||
|
*index = fid * 3;
|
||||||
|
strcpy(name, fname+strlen(pRepo->rootDir));
|
||||||
|
} else { // no file found
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (TSDB_META_FILE_INDEX <= eindex) {
|
||||||
|
*index = TSDB_META_FILE_INDEX;
|
||||||
|
tsdbGetMetaFileName(pRepo->rootDir, fname);
|
||||||
|
strcpy(name, fname+strlen(pRepo->rootDir));
|
||||||
|
} else { // no file found
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else { // return a file name at *index
|
||||||
|
if (*index == TSDB_META_FILE_INDEX) {
|
||||||
|
tsdbGetMetaFileName(pRepo->rootDir, fname);
|
||||||
|
} else { // to get a file in index or larger than index but
|
||||||
|
if (pFileH->numOfFGroups == 0) { // not found
|
||||||
return 0;
|
return 0;
|
||||||
} else {
|
} else {
|
||||||
|
int fid = (*index) / 3;
|
||||||
|
SFileGroup *pFGroup = taosbsearch(&fid, pFileH->fGroup, pFileH->numOfFGroups, sizeof(SFileGroup), compFGroupKey, TD_GE);
|
||||||
|
if (pFGroup == NULL) {
|
||||||
|
return 0;
|
||||||
|
} else {
|
||||||
|
if (pFGroup->fileId == fid) {
|
||||||
|
strcpy(fname, pFGroup->files[(*index)%3].fname);
|
||||||
|
} else {
|
||||||
|
if (pFGroup->fileId * 3 + 2 < eindex) {
|
||||||
|
strcpy(fname, pFGroup->files[(*index)%3].fname);
|
||||||
|
*index = pFGroup->fileId * 3 + (*index) % 3;
|
||||||
|
} else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
strcpy(name, fname);
|
||||||
|
}
|
||||||
|
} else { // get the named file at the specified index. If not there, return 0
|
||||||
|
if (*index == TSDB_META_FILE_INDEX) { // get meta file
|
||||||
tsdbGetMetaFileName(pRepo->rootDir, fname);
|
tsdbGetMetaFileName(pRepo->rootDir, fname);
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
// return data file name
|
int fid = (*index) / 3;
|
||||||
strcpy(fname, pFileH->fGroup[fid].files[(*index) % 3].fname);
|
SFileGroup *pFGroup = tsdbSearchFGroup(pFileH, fid);
|
||||||
|
if (pFGroup == NULL) { // not found
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
SFile *pFile = &pFGroup->files[(*index) % 3];
|
||||||
|
strcpy(fname, pFile->fname);
|
||||||
}
|
}
|
||||||
strcpy(name, fname + strlen(spath));
|
|
||||||
} else {
|
|
||||||
// Name is provided, need to get the file info
|
|
||||||
sprintf(fname, "%s/%s", prefixDir, name);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (stat(fname, &fState) < 0) {
|
if (stat(fname, &fState) < 0) {
|
||||||
tfree(spath);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue