提交 5d746c95 编写于 作者: H hzcheng

more

上级 3b940a6b
......@@ -18,7 +18,6 @@ typedef enum {
typedef struct STable {
int32_t tableId;
int64_t uid;
char * tableName;
TSDB_TABLE_TYPE type;
int64_t createdTime;
......@@ -60,7 +59,7 @@ typedef struct {
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
void * tableMap; // hash map of uid ==> STable *
} STsdbMeta;
// ---- Operation on STable
......
......@@ -47,6 +47,8 @@ typedef struct _tsdb_repo {
static int32_t tsdbCheckAndSetDefaultCfg(STsdbCfg *pCfg);
static int32_t tsdbSetRepoEnv(STsdbRepo *pRepo);
static int32_t tsdbDestroyRepoEnv(STsdbRepo *pRepo);
static int tsdbOpenMetaFile(char *tsdbDir);
static int tsdbRecoverRepo(int fd, STsdbCfg *pCfg);
#define TSDB_GET_TABLE_BY_ID(pRepo, sid) (((STSDBRepo *)pRepo)->pTableList)[sid]
#define TSDB_GET_TABLE_BY_NAME(pRepo, name)
......@@ -131,9 +133,14 @@ tsdb_repo_t *tsdbOpenRepo(char *tsdbDir) {
return NULL;
}
// TODO: Initialize configuration from the file
pRepo->tsdbMeta = tsdbCreateMeta(pRepo->config.maxTables);
if (pRepo->tsdbMeta == NULL) {
int fd = tsdbOpenMetaFile(tsdbDir);
if (fd < 0) {
free(pRepo);
return NULL;
}
if (tsdbRecoverRepo(fd, &(pRepo->config)) < 0) {
close(fd);
free(pRepo);
return NULL;
}
......@@ -144,6 +151,7 @@ tsdb_repo_t *tsdbOpenRepo(char *tsdbDir) {
return NULL;
}
pRepo->rootDir = strdup(tsdbDir);
pRepo->state = TSDB_REPO_STATE_ACTIVE;
return (tsdb_repo_t *)pRepo;
......@@ -155,11 +163,12 @@ static int32_t tsdbFlushCache(STsdbRepo *pRepo) {
int32_t tsdbCloseRepo(tsdb_repo_t *repo) {
STsdbRepo *pRepo = (STsdbRepo *)repo;
tsdbFlushCache(pRepo);
if (pRepo == NULL) return 0;
pRepo->state = TSDB_REPO_STATE_CLOSED;
tsdbFlushCache(pRepo);
tsdbFreeMeta(pRepo->tsdbMeta);
tsdbFreeCache(pRepo->tsdbCache);
......@@ -258,5 +267,16 @@ static int32_t tsdbDestroyRepoEnv(STsdbRepo *pRepo) {
char *metaFname = tsdbGetFileName(pRepo->rootDir, "tsdb", TSDB_FILE_TYPE_META);
remove(metaFname);
return 0;
}
static int tsdbOpenMetaFile(char *tsdbDir) {
// TODO
return 0
}
static int tsdbRecoverRepo(int fd, STsdbCfg *pCfg) {
// TODO: read tsdb configuration from file
// recover tsdb meta
return 0;
}
\ No newline at end of file
......@@ -3,6 +3,7 @@
// #include "taosdef.h"
#include "tsdb.h"
#include "tsdbMeta.h"
#include "hash.h"
#define TSDB_MIN_TABLES 10
#define TSDB_MAX_TABLES 100000
......@@ -29,7 +30,7 @@ STsdbMeta *tsdbCreateMeta(int32_t maxTables) {
return NULL;
}
// TODO : initialize the map
pMeta->tableMap = taosInitHashTable(maxTables + maxTables / 10, taosGetDefaultHashFunction, false);
if (pMeta->tableMap == NULL) {
free(pMeta->tables);
free(pMeta);
......@@ -56,7 +57,8 @@ int32_t tsdbFreeMeta(STsdbMeta *pMeta) {
pTable = pTemp->next;
tsdbFreeTable(pTemp);
}
// TODO close the map
taosCleanUpHashTable(pMeta->tableMap);
free(pMeta);
......@@ -70,7 +72,6 @@ int32_t tsdbCreateTableImpl(STsdbMeta *pMeta, STableCfg *pCfg) {
return -1;
}
// TODO:
STable *pTable = (STable *)malloc(sizeof(STable));
if (pTable == NULL) {
return -1;
......@@ -78,7 +79,6 @@ int32_t tsdbCreateTableImpl(STsdbMeta *pMeta, STableCfg *pCfg) {
pMeta->tables[pCfg->tableId.tid] = pTable;
// TODO: add name to it
return 0;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册