TD-353
This commit is contained in:
parent
ab64511bea
commit
3041354e8d
|
@ -111,6 +111,7 @@ typedef struct {
|
||||||
} SMemTable;
|
} SMemTable;
|
||||||
|
|
||||||
// ------------------ tsdbFile.c
|
// ------------------ tsdbFile.c
|
||||||
|
extern const char* tsdbFileSuffix[];
|
||||||
typedef enum {
|
typedef enum {
|
||||||
TSDB_FILE_TYPE_HEAD = 0,
|
TSDB_FILE_TYPE_HEAD = 0,
|
||||||
TSDB_FILE_TYPE_DATA,
|
TSDB_FILE_TYPE_DATA,
|
||||||
|
@ -340,6 +341,7 @@ void tsdbFreeFileH(STsdbFileH* pFileH);
|
||||||
#define IS_REPO_LOCKED(r) (r)->repoLocked
|
#define IS_REPO_LOCKED(r) (r)->repoLocked
|
||||||
|
|
||||||
char* tsdbGetMetaFileName(char* rootDir);
|
char* tsdbGetMetaFileName(char* rootDir);
|
||||||
|
char* tsdbGetDataFileName(STsdbRepo* pRepo, int fid, int type);
|
||||||
int tsdbLockRepo(STsdbRepo* pRepo);
|
int tsdbLockRepo(STsdbRepo* pRepo);
|
||||||
int tsdbUnlockRepo(STsdbRepo* pRepo);
|
int tsdbUnlockRepo(STsdbRepo* pRepo);
|
||||||
|
|
||||||
|
|
|
@ -99,7 +99,13 @@ int *tsdbOpenFileH(STsdbRepo *pRepo) {
|
||||||
SFileGroup fileGroup = {0};
|
SFileGroup fileGroup = {0};
|
||||||
|
|
||||||
if (tsdbSearchFGroup(pFileH, fid, TD_EQ) != NULL) continue;
|
if (tsdbSearchFGroup(pFileH, fid, TD_EQ) != NULL) continue;
|
||||||
|
fileGroup.fileId = fid;
|
||||||
for (int type = TSDB_FILE_TYPE_HEAD; type <= TSDB_FILE_TYPE_LAST; type++) {
|
for (int type = TSDB_FILE_TYPE_HEAD; type <= TSDB_FILE_TYPE_LAST; type++) {
|
||||||
|
fileGroup.headF.fname = tsdbGetDataFileName(pRepo, fid, type);
|
||||||
|
if (fileGroup.headF.fname == NULL) goto _err;
|
||||||
|
if (tsdbInitFile(fileGroup.headF))
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
for (int type = TSDB_FILE_TYPE_NHEAD; type <= TSDB_FILE_TYPE_NLAST; type++) {
|
for (int type = TSDB_FILE_TYPE_NHEAD; type <= TSDB_FILE_TYPE_NLAST; type++) {
|
||||||
|
|
||||||
|
@ -238,20 +244,6 @@ SFileGroup *tsdbGetFileGroupNext(SFileGroupIter *pIter) {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *tsdbGetFileName(char *dataDir, int fileId, int type) {
|
|
||||||
int tlen = strlen(dataDir) + strlen(tsdbFileSuffix[type]) + 24;
|
|
||||||
|
|
||||||
char *fname = (char *)malloc(tlen);
|
|
||||||
if (fname == NULL) {
|
|
||||||
terrno = TSDB_CODE_TDB_OUT_OF_MEMORY;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
sprintf(fname, "%s/v%df%d%s", dataDir, fileId, tsdbFileSuffix[type]);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int tsdbOpenFile(SFile *pFile, int oflag) {
|
int tsdbOpenFile(SFile *pFile, int oflag) {
|
||||||
ASSERT(!TSDB_IS_FILE_OPENED(pFile));
|
ASSERT(!TSDB_IS_FILE_OPENED(pFile));
|
||||||
|
|
||||||
|
|
|
@ -296,6 +296,19 @@ char *tsdbGetMetaFileName(char *rootDir) {
|
||||||
return fname;
|
return fname;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char *tsdbGetDataFileName(STsdbRepo *pRepo, int fid, int type) {
|
||||||
|
int tlen = strlen(pRepo->rootDir) + strlen(tsdbFileSuffix[type]) + 24;
|
||||||
|
|
||||||
|
char *fname = malloc(tlen);
|
||||||
|
if (fname == NULL) {
|
||||||
|
terrno = TSDB_CODE_TDB_OUT_OF_MEMORY;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
sprintf(fname, "%s/%s/v%df%d.%s", pRepo->rootDir, TSDB_DATA_DIR_NAME, REPO_ID(pRepo), fid, tsdbFileSuffix[type]);
|
||||||
|
return fname;
|
||||||
|
}
|
||||||
|
|
||||||
int tsdbLockRepo(STsdbRepo *pRepo) {
|
int tsdbLockRepo(STsdbRepo *pRepo) {
|
||||||
int code = pthread_mutex_lock(&pRepo->mutex);
|
int code = pthread_mutex_lock(&pRepo->mutex);
|
||||||
if (code != 0) {
|
if (code != 0) {
|
||||||
|
|
Loading…
Reference in New Issue