more
This commit is contained in:
parent
b2e189178d
commit
3b940a6bea
|
@ -29,7 +29,7 @@ typedef struct {
|
||||||
|
|
||||||
// Submit message for one table
|
// Submit message for one table
|
||||||
typedef struct {
|
typedef struct {
|
||||||
STableId tid;
|
STableId tableId;
|
||||||
int32_t sversion; // data schema version
|
int32_t sversion; // data schema version
|
||||||
int32_t numOfRows; // number of rows data
|
int32_t numOfRows; // number of rows data
|
||||||
char data[];
|
char data[];
|
||||||
|
@ -47,20 +47,20 @@ typedef struct {
|
||||||
} STsdbCfg;
|
} STsdbCfg;
|
||||||
|
|
||||||
// the TSDB repository info
|
// the TSDB repository info
|
||||||
typedef struct STSDBRepoInfo {
|
typedef struct STsdbRepoInfo {
|
||||||
STsdbCfg tsdbCfg;
|
STsdbCfg tsdbCfg;
|
||||||
int64_t version; // version of the repository
|
int64_t version; // version of the repository
|
||||||
int64_t tsdbTotalDataSize; // the original inserted data size
|
int64_t tsdbTotalDataSize; // the original inserted data size
|
||||||
int64_t tsdbTotalDiskSize; // the total disk size taken by this TSDB repository
|
int64_t tsdbTotalDiskSize; // the total disk size taken by this TSDB repository
|
||||||
// TODO: Other informations to add
|
// TODO: Other informations to add
|
||||||
} STSDBRepoInfo;
|
} STsdbRepoInfo;
|
||||||
|
|
||||||
// the meter configuration
|
// the meter configuration
|
||||||
typedef struct {
|
typedef struct {
|
||||||
char * tableName;
|
char * tableName;
|
||||||
STableId tableId;
|
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.
|
// table exists in this TSDB.
|
||||||
int64_t stableUid;
|
int64_t stableUid;
|
||||||
|
|
||||||
|
@ -83,6 +83,7 @@ typedef struct {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new TSDB repository
|
* Create a new TSDB repository
|
||||||
|
* @param rootDir the TSDB repository root directory
|
||||||
* @param pCfg the TSDB repository configuration, upper layer to free the pointer
|
* @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
|
* @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
|
* @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
|
* 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
|
// -- For table manipulation
|
||||||
|
|
||||||
|
|
|
@ -51,17 +51,16 @@ typedef struct STable {
|
||||||
// A handle to deal with stream
|
// A handle to deal with stream
|
||||||
void *streamHandle;
|
void *streamHandle;
|
||||||
|
|
||||||
|
struct STable *next;
|
||||||
|
|
||||||
} STable;
|
} STable;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int32_t numOfTables; // Number of tables not including TSDB_SUPER_TABLE (#TSDB_NTABLE + #TSDB_STABLE)
|
int32_t maxTables;
|
||||||
int32_t numOfSuperTables; // Number of super tables (#TSDB_SUPER_TABLE)
|
int32_t numOfSuperTables; // Number of super tables (#TSDB_SUPER_TABLE)
|
||||||
// An array of tables (TSDB_NTABLE and TSDB_STABLE) in this TSDB repository
|
STable ** tables; // array of normal tables
|
||||||
STable **pTables;
|
STable * stables; // linked list of super tables
|
||||||
|
void * tableMap; // table map of name ==> table
|
||||||
// A map of tableName->tableId
|
|
||||||
// TODO: May use hash table
|
|
||||||
void *pNameTableMap;
|
|
||||||
} STsdbMeta;
|
} STsdbMeta;
|
||||||
|
|
||||||
// ---- Operation on STable
|
// ---- Operation on STable
|
||||||
|
@ -84,10 +83,10 @@ SSchema *tsdbGetTableSchema(STable *pTable);
|
||||||
#define TSDB_GET_TABLE_OF_NAME(pHandle, name) /* TODO */
|
#define TSDB_GET_TABLE_OF_NAME(pHandle, name) /* TODO */
|
||||||
|
|
||||||
// Create a new meta handle with configuration
|
// Create a new meta handle with configuration
|
||||||
STsdbMeta * tsdbCreateMeta (int32_t maxTables);
|
STsdbMeta *tsdbCreateMeta(int32_t maxTables);
|
||||||
int32_t tsdbFreeMeta(STsdbMeta *pMeta);
|
int32_t tsdbFreeMeta(STsdbMeta *pMeta);
|
||||||
|
|
||||||
// Recover the meta handle from the file
|
// Recover the meta handle from the file
|
||||||
STsdbMeta * tsdbOpenMetaHandle(char *tsdbDir);
|
STsdbMeta *tsdbOpenMetaHandle(char *tsdbDir);
|
||||||
|
|
||||||
int32_t tsdbCreateTableImpl(STsdbMeta *pHandle, STableCfg *pCfg);
|
int32_t tsdbCreateTableImpl(STsdbMeta *pHandle, STableCfg *pCfg);
|
||||||
|
|
|
@ -175,7 +175,7 @@ int32_t tsdbConfigRepo(tsdb_repo_t *repo, STsdbCfg *pCfg) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
STSDBRepoInfo *tsdbGetStatus(tsdb_repo_t *pRepo) {
|
STsdbRepoInfo *tsdbGetStatus(tsdb_repo_t *pRepo) {
|
||||||
// TODO
|
// TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,24 +4,34 @@
|
||||||
#include "tsdb.h"
|
#include "tsdb.h"
|
||||||
#include "tsdbMeta.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) {
|
STsdbMeta *tsdbCreateMeta(int32_t maxTables) {
|
||||||
|
if (!IS_VALID_MAX_TABLES(maxTables)) return NULL;
|
||||||
|
|
||||||
STsdbMeta *pMeta = (STsdbMeta *)malloc(sizeof(STsdbMeta));
|
STsdbMeta *pMeta = (STsdbMeta *)malloc(sizeof(STsdbMeta));
|
||||||
if (pMeta == NULL) {
|
if (pMeta == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
pMeta->numOfTables = 0;
|
pMeta->maxTables = maxTables;
|
||||||
pMeta->numOfSuperTables = 0;
|
pMeta->numOfSuperTables = 0;
|
||||||
pMeta->pTables = calloc(sizeof(STable *), maxTables);
|
pMeta->stables = NULL;
|
||||||
if (pMeta->pTables == NULL) {
|
pMeta->tables = (STable **)calloc(maxTables, sizeof(STable *));
|
||||||
|
if (pMeta->tables == NULL) {
|
||||||
free(pMeta);
|
free(pMeta);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO : initialize the map
|
// TODO : initialize the map
|
||||||
// pMetahandle->pNameTableMap = ;
|
if (pMeta->tableMap == NULL) {
|
||||||
if (pMeta->pNameTableMap == NULL) {
|
free(pMeta->tables);
|
||||||
free(pMeta->pTables);
|
|
||||||
free(pMeta);
|
free(pMeta);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -30,11 +40,32 @@ STsdbMeta *tsdbCreateMeta(int32_t maxTables) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t tsdbFreeMeta(STsdbMeta *pMeta) {
|
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; }
|
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) {
|
if (tsdbCheckTableCfg(pCfg) < 0) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -45,19 +76,21 @@ int32_t tsdbCreateTableImpl(STsdbMeta *pHandle, STableCfg *pCfg) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
pHandle->pTables[pCfg->tableId.tid] = pTable;
|
pMeta->tables[pCfg->tableId.tid] = pTable;
|
||||||
|
|
||||||
// TODO: add name to it
|
// TODO: add name to it
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
STsdbMeta * tsdbOpenMetaHandle(char *tsdbDir) {
|
STsdbMeta *tsdbOpenMetaHandle(char *tsdbDir) {
|
||||||
// Open meta file for reading
|
// Open meta file for reading
|
||||||
|
|
||||||
STsdbMeta *pHandle = (STsdbMeta *)malloc(sizeof(STsdbMeta));
|
STsdbMeta *pMeta = (STsdbMeta *)malloc(sizeof(STsdbMeta));
|
||||||
if (pHandle == NULL) {
|
if (pMeta == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
return pHandle;
|
return pMeta;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int tsdbFreeTable(STable *pTable) { return 0; }
|
Loading…
Reference in New Issue