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

more

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