提交 a4ee9d7c 编写于 作者: H hzcheng

refactor

上级 9f0c0151
......@@ -37,7 +37,6 @@ typedef struct {
// the TSDB repository configuration
typedef struct {
char * rootDir; // TSDB repository root directory, TODO: need to adjust here
int32_t tsdbId;
int32_t maxTables; // maximum number of tables this repository can have
int32_t daysPerFile; // day per file sharding policy
......@@ -45,7 +44,6 @@ typedef struct {
int32_t maxRowsPerFileBlock; // maximum rows per file block
int32_t keep; // day of data to keep
int64_t maxCacheSize; // maximum cache size this TSDB can use
void * cachePool; // the cache pool the repository to use
} STsdbCfg;
// the TSDB repository info
......@@ -89,7 +87,7 @@ typedef struct {
*
* @return a TSDB repository handle on success, NULL for failure and the error number is set
*/
tsdb_repo_t *tsdbCreateRepo(STsdbCfg *pCfg);
tsdb_repo_t *tsdbCreateRepo(char *rootDir, STsdbCfg *pCfg, void *limiter);
/**
* Close and free all resources taken by the repository
......
......@@ -62,7 +62,7 @@ typedef struct {
// A map of tableName->tableId
// TODO: May use hash table
void *pNameTableMap;
} SMetaHandle;
} STsdbMeta;
// ---- Operation on STable
#define TSDB_TABLE_ID(pTable) ((pTable)->tableId)
......@@ -84,7 +84,7 @@ SSchema *tsdbGetTableSchema(STable *pTable);
#define TSDB_GET_TABLE_OF_NAME(pHandle, name) /* TODO */
// Create a new meta handle with configuration
SMetaHandle * tsdbCreateMetaHandle (int32_t numOfTables);
SMetaHandle * tsdbCreateMeta (int32_t numOfTables);
int32_t tsdbFreeMetaHandle(SMetaHandle *pMetaHandle);
// Recover the meta handle from the file
......
#include <fcntl.h>
#include <pthread.h>
#include <stdint.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/types.h>
#include <unistd.h>
// #include "taosdef.h"
// #include "disk.h"
#include "tsdbFile.h"
#include "tsdb.h"
#include "tsdbCache.h"
#include "tsdbFile.h"
#include "tsdbMeta.h"
enum {
TSDB_REPO_STATE_ACTIVE,
TSDB_REPO_STATE_CLOSED,
TSDB_REPO_STATE_CONFIGURING
};
enum { TSDB_REPO_STATE_ACTIVE, TSDB_REPO_STATE_CLOSED, TSDB_REPO_STATE_CONFIGURING };
typedef struct _tsdb_repo {
// TSDB configuration
STsdbCfg *pCfg;
STsdbCfg config;
// The meter meta handle of this TSDB repository
SMetaHandle *tsdbMeta;
......@@ -37,31 +33,40 @@ typedef struct _tsdb_repo {
pthread_mutex_t tsdbMutex;
// A limiter to monitor the resources used by tsdb
void *limiter;
int8_t state;
} STsdbRepo;
static int32_t tsdbCheckAndSetDefaultCfg(STsdbCfg *pCfg);
static int32_t tsdbCreateRepoFiles(STsdbRepo *pRepo);
#define TSDB_GET_TABLE_BY_ID(pRepo, sid) (((STSDBRepo *)pRepo)->pTableList)[sid]
#define TSDB_GET_TABLE_BY_NAME(pRepo, name)
#define TSDB_IS_REPO_ACTIVE(pRepo) ((pRepo)->state == TSDB_REPO_STATE_ACTIVE)
#define TSDB_IS_REPO_CLOSED(pRepo) ((pRepo)->state == TSDB_REPO_STATE_CLOSED)
tsdb_repo_t *tsdbCreateRepo(char *rootDir, STsdbCfg *pCfg, void *limiter) {
if (rootDir == NULL) return NULL;
tsdb_repo_t *tsdbCreateRepo(STsdbCfg *pCfg) {
if (access(rootDir, F_OK|R_OK|W_OK) == -1) return NULL;
// Check the configuration
if (tsdbCheckCfg(pCfg) < 0) {
if (tsdbCheckAndSetDefaultCfg(pCfg) < 0) {
return NULL;
}
STsdbRepo *pRepo = (STsdbRepo *)malloc(sizeof(STsdbRepo));
if (pRepo == NULL) {
// TODO: deal with error
return NULL;
}
// TODO: Initailize pMetahandle
pRepo->tsdbMeta = tsdbCreateMetaHandle(pCfg->maxTables);
pRepo->config = *pCfg;
pRepo->limiter = limiter;
pRepo->tsdbMeta = tsdbCreateMeta(pCfg->maxTables);
if (pRepo->tsdbMeta == NULL) {
// TODO: deal with error
free(pRepo);
......@@ -77,11 +82,8 @@ tsdb_repo_t *tsdbCreateRepo(STsdbCfg *pCfg) {
return NULL;
}
// Set configuration
pRepo->pCfg = pCfg;
// Create the Meta data file and data directory
if (tsdbCreateFiles(pRepo) < 0) {
if (tsdbCreateRepoFiles(pRepo) < 0) {
// Failed to create and save files
tsdbFreeMetaHandle(pRepo->tsdbCache);
free(pRepo);
......@@ -110,8 +112,7 @@ int32_t tsdbDropRepo(tsdb_repo_t *repo) {
}
tsdb_repo_t *tsdbOpenRepo(char *tsdbDir) {
if (access(tsdbDir, F_OK|W_OK|R_OK) < 0) {
if (access(tsdbDir, F_OK | W_OK | R_OK) < 0) {
return NULL;
}
......@@ -159,7 +160,7 @@ int32_t tsdbCloseRepo(tsdb_repo_t *repo) {
int32_t tsdbConfigRepo(tsdb_repo_t *repo, STsdbCfg *pCfg) {
STsdbRepo *pRepo = (STsdbRepo *)repo;
pRepo->pCfg = pCfg;
pRepo->config = pCfg;
// TODO
return 0;
}
......@@ -185,18 +186,13 @@ int32_t tsdbInsertData(tsdb_repo_t *pRepo, STableId tid, char *pData, int32_t *e
// TODO
}
// Check the correctness of the TSDB configuration
static int32_t tsdbCheckCfg(STsdbCfg *pCfg) {
if (pCfg->rootDir == NULL) return -1;
if (access(pCfg->rootDir, F_OK|R_OK|W_OK) == -1) {
return -1;
}
// Check the configuration and set default options
static int32_t tsdbCheckAndSetDefaultCfg(STsdbCfg *pCfg) {
// TODO
return 0;
}
static int32_t tsdbCreateFiles(STsdbRepo *pRepo) {
static int32_t tsdbCreateRepoFiles(STsdbRepo *pRepo) {
// TODO
}
......
......@@ -4,39 +4,39 @@
#include "tsdb.h"
#include "tsdbMeta.h"
SMetaHandle *tsdbCreateMetaHandle(int32_t numOfTables) {
SMetaHandle *pMetahandle = (SMetaHandle *)malloc(sizeof(SMetaHandle));
if (pMetahandle == NULL) {
STsdbMeta *tsdbCreateMeta(int32_t maxNumOfTables) {
STsdbMeta *pMeta = (STsdbMeta *)malloc(sizeof(STsdbMeta));
if (pMeta == NULL) {
return NULL;
}
pMetahandle->numOfTables = 0;
pMetahandle->numOfSuperTables = 0;
pMetahandle->pTables = calloc(sizeof(STable *), numOfTables);
if (pMetahandle->pTables == NULL) {
free(pMetahandle);
pMeta->numOfTables = 0;
pMeta->numOfSuperTables = 0;
pMeta->pTables = calloc(sizeof(STable *), numOfTables);
if (pMeta->pTables == NULL) {
free(pMeta);
return NULL;
}
// TODO : initialize the map
// pMetahandle->pNameTableMap = ;
if (pMetahandle->pNameTableMap == NULL) {
free(pMetahandle->pTables);
free(pMetahandle);
if (pMeta->pNameTableMap == NULL) {
free(pMeta->pTables);
free(pMeta);
return NULL;
}
return pMetahandle;
return pMeta;
}
int32_t tsdbFreeMetaHandle(SMetaHandle *pMetaHandle) {
int32_t tsdbFreeMetaHandle(STsdbMeta *pMetaHandle) {
// TODO
}
static int32_t tsdbCheckTableCfg(STableCfg *pCfg) { return 0; }
int32_t tsdbCreateTableImpl(SMetaHandle *pHandle, STableCfg *pCfg) {
int32_t tsdbCreateTableImpl(STsdbMeta *pHandle, STableCfg *pCfg) {
if (tsdbCheckTableCfg(pCfg) < 0) {
return -1;
}
......@@ -53,10 +53,10 @@ int32_t tsdbCreateTableImpl(SMetaHandle *pHandle, STableCfg *pCfg) {
return 0;
}
SMetaHandle * tsdbOpenMetaHandle(char *tsdbDir) {
STsdbMeta * tsdbOpenMetaHandle(char *tsdbDir) {
// Open meta file for reading
SMetaHandle *pHandle = (SMetaHandle *)malloc(sizeof(SMetaHandle));
STsdbMeta *pHandle = (STsdbMeta *)malloc(sizeof(STsdbMeta));
if (pHandle == NULL) {
return NULL;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册