提交 3b940a6b 编写于 作者: H hzcheng

more

上级 b2e18917
......@@ -29,7 +29,7 @@ typedef struct {
// Submit message for one table
typedef struct {
STableId tid;
STableId tableId;
int32_t sversion; // data schema version
int32_t numOfRows; // number of rows data
char data[];
......@@ -47,20 +47,20 @@ typedef struct {
} STsdbCfg;
// the TSDB repository info
typedef struct STSDBRepoInfo {
typedef struct STsdbRepoInfo {
STsdbCfg tsdbCfg;
int64_t version; // version of the repository
int64_t tsdbTotalDataSize; // the original inserted data size
int64_t tsdbTotalDiskSize; // the total disk size taken by this TSDB repository
// TODO: Other informations to add
} STSDBRepoInfo;
} STsdbRepoInfo;
// the meter configuration
typedef struct {
char * tableName;
STableId tableId;
char *stableName; // if not NULL, the table is created from a super table, need to make sure the super
char *superTable; // if not NULL, the table is created from a super table, need to make sure the super
// table exists in this TSDB.
int64_t stableUid;
......@@ -83,6 +83,7 @@ typedef struct {
/**
* Create a new TSDB repository
* @param rootDir the TSDB repository root directory
* @param pCfg the TSDB repository configuration, upper layer to free the pointer
*
* @return a TSDB repository handle on success, NULL for failure and the error number is set
......@@ -131,7 +132,7 @@ int32_t tsdbConfigRepo(tsdb_repo_t *repo, STsdbCfg *pCfg);
* @return a info struct handle on success, NULL for failure and the error number is set. The upper
* layers should free the info handle themselves or memory leak will occur
*/
STSDBRepoInfo *tsdbGetStatus(tsdb_repo_t *pRepo);
STsdbRepoInfo *tsdbGetStatus(tsdb_repo_t *pRepo);
// -- For table manipulation
......
......@@ -16,7 +16,7 @@ typedef enum {
} TSDB_TABLE_TYPE;
typedef struct STable {
int32_t tableId;
int32_t tableId;
int64_t uid;
char * tableName;
TSDB_TABLE_TYPE type;
......@@ -51,17 +51,16 @@ typedef struct STable {
// A handle to deal with stream
void *streamHandle;
struct STable *next;
} STable;
typedef struct {
int32_t numOfTables; // Number of tables not including TSDB_SUPER_TABLE (#TSDB_NTABLE + #TSDB_STABLE)
int32_t numOfSuperTables; // Number of super tables (#TSDB_SUPER_TABLE)
// An array of tables (TSDB_NTABLE and TSDB_STABLE) in this TSDB repository
STable **pTables;
// A map of tableName->tableId
// TODO: May use hash table
void *pNameTableMap;
int32_t maxTables;
int32_t numOfSuperTables; // Number of super tables (#TSDB_SUPER_TABLE)
STable ** tables; // array of normal tables
STable * stables; // linked list of super tables
void * tableMap; // table map of name ==> table
} STsdbMeta;
// ---- Operation on STable
......@@ -84,10 +83,10 @@ SSchema *tsdbGetTableSchema(STable *pTable);
#define TSDB_GET_TABLE_OF_NAME(pHandle, name) /* TODO */
// Create a new meta handle with configuration
STsdbMeta * tsdbCreateMeta (int32_t maxTables);
int32_t tsdbFreeMeta(STsdbMeta *pMeta);
STsdbMeta *tsdbCreateMeta(int32_t maxTables);
int32_t tsdbFreeMeta(STsdbMeta *pMeta);
// Recover the meta handle from the file
STsdbMeta * tsdbOpenMetaHandle(char *tsdbDir);
STsdbMeta *tsdbOpenMetaHandle(char *tsdbDir);
int32_t tsdbCreateTableImpl(STsdbMeta *pHandle, STableCfg *pCfg);
......@@ -175,7 +175,7 @@ int32_t tsdbConfigRepo(tsdb_repo_t *repo, STsdbCfg *pCfg) {
return 0;
}
STSDBRepoInfo *tsdbGetStatus(tsdb_repo_t *pRepo) {
STsdbRepoInfo *tsdbGetStatus(tsdb_repo_t *pRepo) {
// TODO
}
......
......@@ -4,24 +4,34 @@
#include "tsdb.h"
#include "tsdbMeta.h"
#define TSDB_MIN_TABLES 10
#define TSDB_MAX_TABLES 100000
#define TSDB_DEFAULT_NSTABLES 10
#define IS_VALID_MAX_TABLES(maxTables) (((maxTables) >= TSDB_MIN_TABLES) && ((maxTables) >= TSDB_MAX_TABLES))
static int tsdbFreeTable(STable *pTable);
STsdbMeta *tsdbCreateMeta(int32_t maxTables) {
if (!IS_VALID_MAX_TABLES(maxTables)) return NULL;
STsdbMeta *pMeta = (STsdbMeta *)malloc(sizeof(STsdbMeta));
if (pMeta == NULL) {
return NULL;
}
pMeta->numOfTables = 0;
pMeta->maxTables = maxTables;
pMeta->numOfSuperTables = 0;
pMeta->pTables = calloc(sizeof(STable *), maxTables);
if (pMeta->pTables == NULL) {
pMeta->stables = NULL;
pMeta->tables = (STable **)calloc(maxTables, sizeof(STable *));
if (pMeta->tables == NULL) {
free(pMeta);
return NULL;
}
// TODO : initialize the map
// pMetahandle->pNameTableMap = ;
if (pMeta->pNameTableMap == NULL) {
free(pMeta->pTables);
if (pMeta->tableMap == NULL) {
free(pMeta->tables);
free(pMeta);
return NULL;
}
......@@ -30,11 +40,32 @@ STsdbMeta *tsdbCreateMeta(int32_t maxTables) {
}
int32_t tsdbFreeMeta(STsdbMeta *pMeta) {
if (pMeta == NULL) return 0;
for (int i = 0; i < pMeta->maxTables; i++) {
if (pMeta->tables[i] != NULL) {
tsdbFreeTable(pMeta->tables[i]);
}
}
free(pMeta->tables);
STable *pTable = pMeta->stables;
while (pTable != NULL) {
STable *pTemp = pTable;
pTable = pTemp->next;
tsdbFreeTable(pTemp);
}
// TODO close the map
free(pMeta);
return 0;
}
static int32_t tsdbCheckTableCfg(STableCfg *pCfg) { return 0; }
int32_t tsdbCreateTableImpl(STsdbMeta *pHandle, STableCfg *pCfg) {
int32_t tsdbCreateTableImpl(STsdbMeta *pMeta, STableCfg *pCfg) {
if (tsdbCheckTableCfg(pCfg) < 0) {
return -1;
}
......@@ -45,19 +76,21 @@ int32_t tsdbCreateTableImpl(STsdbMeta *pHandle, STableCfg *pCfg) {
return -1;
}
pHandle->pTables[pCfg->tableId.tid] = pTable;
pMeta->tables[pCfg->tableId.tid] = pTable;
// TODO: add name to it
return 0;
}
STsdbMeta * tsdbOpenMetaHandle(char *tsdbDir) {
STsdbMeta *tsdbOpenMetaHandle(char *tsdbDir) {
// Open meta file for reading
STsdbMeta *pHandle = (STsdbMeta *)malloc(sizeof(STsdbMeta));
if (pHandle == NULL) {
STsdbMeta *pMeta = (STsdbMeta *)malloc(sizeof(STsdbMeta));
if (pMeta == NULL) {
return NULL;
}
return pHandle;
}
\ No newline at end of file
return pMeta;
}
static int tsdbFreeTable(STable *pTable) { return 0; }
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册