TD-34
This commit is contained in:
parent
0dde6985dc
commit
66af9af1ff
|
@ -61,7 +61,8 @@ typedef struct {
|
||||||
#define IS_VALID_TSDB_FILE_TYPE(type) ((type) >= TSDB_FILE_TYPE_HEAD && (type) < TSDB_FILE_TYPE_MAX)
|
#define IS_VALID_TSDB_FILE_TYPE(type) ((type) >= TSDB_FILE_TYPE_HEAD && (type) < TSDB_FILE_TYPE_MAX)
|
||||||
|
|
||||||
STsdbFileH *tsdbInitFile(char *dataDir, int32_t daysPerFile, int32_t keep, int32_t minRowsPerFBlock,
|
STsdbFileH *tsdbInitFile(char *dataDir, int32_t daysPerFile, int32_t keep, int32_t minRowsPerFBlock,
|
||||||
int32_t maxRowsPerFBlock);
|
int32_t maxRowsPerFBlock, int32_t maxTables);
|
||||||
|
|
||||||
void tsdbCloseFile(STsdbFileH *pFileH);
|
void tsdbCloseFile(STsdbFileH *pFileH);
|
||||||
int tsdbCreateFileGroup(char *dataDir, int fileId, SFileGroup *pFGroup, int maxTables);
|
int tsdbCreateFileGroup(char *dataDir, int fileId, SFileGroup *pFGroup, int maxTables);
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|
|
@ -161,9 +161,10 @@ static int tsdbCreateFile(char *dataDir, int fileId, int8_t type, int maxTables,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
static int tsdbRemoveFile(SFile *pFile) {
|
||||||
*
|
if (pFile == NULL) return -1;
|
||||||
*/
|
return remove(pFile->fname);
|
||||||
|
}
|
||||||
|
|
||||||
// Create a file group with fileId and return a SFileGroup object
|
// Create a file group with fileId and return a SFileGroup object
|
||||||
int tsdbCreateFileGroup(char *dataDir, int fileId, SFileGroup *pFGroup, int maxTables) {
|
int tsdbCreateFileGroup(char *dataDir, int fileId, SFileGroup *pFGroup, int maxTables) {
|
||||||
|
@ -187,7 +188,7 @@ int tsdbCreateFileGroup(char *dataDir, int fileId, SFileGroup *pFGroup, int maxT
|
||||||
* Initialize the TSDB file handle
|
* Initialize the TSDB file handle
|
||||||
*/
|
*/
|
||||||
STsdbFileH *tsdbInitFile(char *dataDir, int32_t daysPerFile, int32_t keep, int32_t minRowsPerFBlock,
|
STsdbFileH *tsdbInitFile(char *dataDir, int32_t daysPerFile, int32_t keep, int32_t minRowsPerFBlock,
|
||||||
int32_t maxRowsPerFBlock) {
|
int32_t maxRowsPerFBlock, int32_t maxTables) {
|
||||||
STsdbFileH *pTsdbFileH =
|
STsdbFileH *pTsdbFileH =
|
||||||
(STsdbFileH *)calloc(1, sizeof(STsdbFileH) + sizeof(SFileGroup) * tsdbGetMaxNumOfFiles(keep, daysPerFile));
|
(STsdbFileH *)calloc(1, sizeof(STsdbFileH) + sizeof(SFileGroup) * tsdbGetMaxNumOfFiles(keep, daysPerFile));
|
||||||
if (pTsdbFileH == NULL) return NULL;
|
if (pTsdbFileH == NULL) return NULL;
|
||||||
|
@ -225,13 +226,6 @@ STsdbFileH *tsdbInitFile(char *dataDir, int32_t daysPerFile, int32_t keep, int32
|
||||||
return pTsdbFileH;
|
return pTsdbFileH;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Closet the file handle
|
|
||||||
*/
|
|
||||||
void tsdbCloseFile(STsdbFileH *pFileH) {
|
|
||||||
// TODO
|
|
||||||
}
|
|
||||||
|
|
||||||
static void tsdbGetKeyRangeOfFileId(int32_t daysPerFile, int8_t precision, int32_t fileId, TSKEY *minKey,
|
static void tsdbGetKeyRangeOfFileId(int32_t daysPerFile, int8_t precision, int32_t fileId, TSKEY *minKey,
|
||||||
TSKEY *maxKey) {
|
TSKEY *maxKey) {
|
||||||
*minKey = fileId * daysPerFile * tsMsPerDay[precision];
|
*minKey = fileId * daysPerFile * tsMsPerDay[precision];
|
||||||
|
|
|
@ -58,12 +58,12 @@ typedef struct _tsdb_repo {
|
||||||
// The cache Handle
|
// The cache Handle
|
||||||
STsdbCache *tsdbCache;
|
STsdbCache *tsdbCache;
|
||||||
|
|
||||||
|
// The TSDB file handle
|
||||||
|
STsdbFileH *tsdbFileH;
|
||||||
|
|
||||||
// Disk tier handle for multi-tier storage
|
// Disk tier handle for multi-tier storage
|
||||||
void *diskTier;
|
void *diskTier;
|
||||||
|
|
||||||
// File Store
|
|
||||||
void *tsdbFiles;
|
|
||||||
|
|
||||||
pthread_mutex_t tsdbMutex;
|
pthread_mutex_t tsdbMutex;
|
||||||
|
|
||||||
// A limiter to monitor the resources used by tsdb
|
// A limiter to monitor the resources used by tsdb
|
||||||
|
@ -79,6 +79,7 @@ static int32_t tsdbDestroyRepoEnv(STsdbRepo *pRepo);
|
||||||
static int tsdbOpenMetaFile(char *tsdbDir);
|
static int tsdbOpenMetaFile(char *tsdbDir);
|
||||||
static int32_t tsdbInsertDataToTable(tsdb_repo_t *repo, SSubmitBlk *pBlock);
|
static int32_t tsdbInsertDataToTable(tsdb_repo_t *repo, SSubmitBlk *pBlock);
|
||||||
static int32_t tsdbRestoreCfg(STsdbRepo *pRepo, STsdbCfg *pCfg);
|
static int32_t tsdbRestoreCfg(STsdbRepo *pRepo, STsdbCfg *pCfg);
|
||||||
|
static int32_t tsdbGetDataDirName(STsdbRepo *pRepo, char *fname);
|
||||||
|
|
||||||
#define TSDB_GET_TABLE_BY_ID(pRepo, sid) (((STSDBRepo *)pRepo)->pTableList)[sid]
|
#define TSDB_GET_TABLE_BY_ID(pRepo, sid) (((STSDBRepo *)pRepo)->pTableList)[sid]
|
||||||
#define TSDB_GET_TABLE_BY_NAME(pRepo, name)
|
#define TSDB_GET_TABLE_BY_NAME(pRepo, name)
|
||||||
|
@ -171,6 +172,19 @@ tsdb_repo_t *tsdbCreateRepo(char *rootDir, STsdbCfg *pCfg, void *limiter /* TODO
|
||||||
}
|
}
|
||||||
pRepo->tsdbCache = pCache;
|
pRepo->tsdbCache = pCache;
|
||||||
|
|
||||||
|
// Initialize file handle
|
||||||
|
char dataDir[128] = "\0";
|
||||||
|
tsdbGetDataDirName(pRepo, dataDir);
|
||||||
|
pRepo->tsdbFileH =
|
||||||
|
tsdbInitFile(dataDir, pCfg->daysPerFile, pCfg->keep, pCfg->minRowsPerFileBlock, pCfg->maxRowsPerFileBlock, pCfg->maxTables);
|
||||||
|
if (pRepo->tsdbFileH == NULL) {
|
||||||
|
free(pRepo->rootDir);
|
||||||
|
tsdbFreeCache(pRepo->tsdbCache);
|
||||||
|
tsdbFreeMeta(pRepo->tsdbMeta);
|
||||||
|
free(pRepo);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
pRepo->state = TSDB_REPO_STATE_ACTIVE;
|
pRepo->state = TSDB_REPO_STATE_ACTIVE;
|
||||||
|
|
||||||
return (tsdb_repo_t *)pRepo;
|
return (tsdb_repo_t *)pRepo;
|
||||||
|
|
Loading…
Reference in New Issue