From 4d6bf76760ec9465bec16994a1f262b7ebb11619 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Wed, 12 Feb 2020 15:37:36 +0800 Subject: [PATCH] more --- src/vnode/tsdb/inc/tsdbCache.h | 4 +- src/vnode/tsdb/inc/tsdbMeta.h | 8 +++- src/vnode/tsdb/src/tsdb.c | 67 ++++++++++++++++++++-------------- src/vnode/tsdb/src/tsdbCache.c | 15 ++++++++ src/vnode/tsdb/src/tsdbMeta.c | 26 ++++++++++++- 5 files changed, 88 insertions(+), 32 deletions(-) diff --git a/src/vnode/tsdb/inc/tsdbCache.h b/src/vnode/tsdb/inc/tsdbCache.h index 3b9aab027b..b0993c1e09 100644 --- a/src/vnode/tsdb/inc/tsdbCache.h +++ b/src/vnode/tsdb/inc/tsdbCache.h @@ -24,7 +24,7 @@ typedef struct { typedef struct STSDBCache { // Number of blocks the cache is allocated int32_t numOfBlocks; - SDList *cacheList; + STSDBCacheBlock *cacheList; void * current; } SCacheHandle; @@ -36,6 +36,6 @@ typedef struct STSDBCache { #define TSDB_NEXT_CACHE_BLOCK(pBlock) ((pBlock)->next) #define TSDB_PREV_CACHE_BLOCK(pBlock) ((pBlock)->prev) -STSDBCache *tsdbCreateCache(); +SCacheHandle *tsdbCreateCache(int32_t numOfBlocks); #endif // _TD_TSDBCACHE_H_ diff --git a/src/vnode/tsdb/inc/tsdbMeta.h b/src/vnode/tsdb/inc/tsdbMeta.h index 49963b3293..a8fdef3d2e 100644 --- a/src/vnode/tsdb/inc/tsdbMeta.h +++ b/src/vnode/tsdb/inc/tsdbMeta.h @@ -81,4 +81,10 @@ SVSchema *tsdbGetTableSchema(STable *pTable); #define TSDB_NUM_OF_TABLES(pHandle) ((pHandle)->numOfTables) #define TSDB_NUM_OF_SUPER_TABLES(pHandle) ((pHandle)->numOfSuperTables) #define TSDB_TABLE_OF_ID(pHandle, id) ((pHandle)->pTables)[id] -#define TSDB_GET_TABLE_OF_NAME(pHandle, name) /* TODO */ \ No newline at end of file +#define TSDB_GET_TABLE_OF_NAME(pHandle, name) /* TODO */ + +// Create a new meta handle with configuration +SMetaHandle * tsdbCreateMetaHandle (int32_t numOfTables); + +// Recover the meta handle from the file +SMetaHandle * tsdbOpenMetaHandle(int fd); diff --git a/src/vnode/tsdb/src/tsdb.c b/src/vnode/tsdb/src/tsdb.c index 689121673d..ba13c83883 100644 --- a/src/vnode/tsdb/src/tsdb.c +++ b/src/vnode/tsdb/src/tsdb.c @@ -1,8 +1,9 @@ #include #include +#include #include "tsdb.h" -#include "disk.h" +// #include "disk.h" #include "tsdbMeta.h" #include "tsdbCache.h" @@ -17,34 +18,10 @@ typedef struct STSDBRepo // The cache Handle SCacheHandle *pCacheHandle; - - /* Disk tier handle for multi-tier storage - * - * The handle is responsible for dealing with object-oriented - * storage. - */ + // Disk tier handle for multi-tier storage SDiskTier *pDiskTier; - /* Cache block list - */ - SCacheBlock *pCacheBloclList; - - /* Map from tableId-->STable - */ - STable *pTableList; - - /* Map from tableName->tableId - * TODO: may use dict - */ - void *pTableDict; - - /* Map from super tableName->table - * TODO: may use dict - */ - void *pSTableDict; - - /* File Store - */ + // File Store void *pFileStore; pthread_mutext_t tsdbMutex; @@ -53,3 +30,39 @@ typedef struct STSDBRepo #define TSDB_GET_TABLE_BY_ID(pRepo, sid) (((STSDBRepo *)pRepo)->pTableList)[sid] #define TSDB_GET_TABLE_BY_NAME(pRepo, name) + +// Check the correctness of the TSDB configuration +static int32_t tsdbCheckCfg(STSDBCfg *pCfg) { + // TODO + return 0; +} + +tsdb_repo_t *tsdbCreateRepo(STSDBCfg *pCfg, int32_t *error) { + int32_t err = 0; + err = tsdbCheckCfg(pCfg); + if (err != 0) { + // TODO: deal with the error here + } + + STSDBRepo *pRepo = (STSDBRepo *) malloc(sizeof(STSDBRepo)); + if (pRepo == NULL) { + // TODO: deal with error + } + + // TODO: Initailize pMetahandle + pRepo->pMetaHandle = tsdbCreateMetaHandle(pCfg->maxTables); + if (pRepo->pMetaHandle == NULL) { + // TODO: deal with error + free(pRepo); + return NULL; + } + + // TODO: Initialize cache handle + pRepo->pCacheHandle = tsdbCreateCache(5); + if (pRepo->pCacheHandle == NULL) { + // TODO: free the object and return error + return NULL; + } + + return (tsdb_repo_t *)pRepo; +} \ No newline at end of file diff --git a/src/vnode/tsdb/src/tsdbCache.c b/src/vnode/tsdb/src/tsdbCache.c index e69de29bb2..feb70dc23c 100644 --- a/src/vnode/tsdb/src/tsdbCache.c +++ b/src/vnode/tsdb/src/tsdbCache.c @@ -0,0 +1,15 @@ +#include + +#include "tsdbCache.h" + + +SCacheHandle *tsdbCreateCache(int32_t numOfBlocks) { + SCacheHandle *pCacheHandle = (SCacheHandle *)malloc(sizeof(SCacheHandle)); + if (pCacheHandle == NULL) { + // TODO : deal with the error + return NULL; + } + + return pCacheHandle; + +} \ No newline at end of file diff --git a/src/vnode/tsdb/src/tsdbMeta.c b/src/vnode/tsdb/src/tsdbMeta.c index a1ddc308a5..2ed8d63b93 100644 --- a/src/vnode/tsdb/src/tsdbMeta.c +++ b/src/vnode/tsdb/src/tsdbMeta.c @@ -1,7 +1,29 @@ +#include + #include "tsdb.h" #include "tsdbMeta.h" -SVSchema *tsdbGetTableSchema(STable *pTable) { +SMetaHandle * tsdbCreateMetaHandle (int32_t numOfTables) { + SMetaHandle * pMetahandle = (SMetaHandle *)malloc(sizeof(SMetaHandle)); + if (pMetahandle == NULL) { + return NULL; + } + + pMetahandle->numOfTables = 0; + pMetahandle->numOfSuperTables = 0; + pMetahandle->pTables = calloc(sizeof(STable *) * numOfTables); + if (pMetahandle->pTables == NULL) { + free(pMetahandle); + return NULL; + } -} + // TODO : initialize the map + // pMetahandle->pNameTableMap = ; + if (pMetahandle->pNameTableMap == NULL) { + free(pMetahandle->pTables); + free(pMetahandle); + return NULL; + } + return pMetahandle; +} \ No newline at end of file -- GitLab