diff --git a/src/vnode/tsdb/inc/tsdbCache.h b/src/vnode/tsdb/inc/tsdbCache.h index 3b9aab027b0356c101e20763ee7e466286e6e798..b0993c1e093be67e1267c3bc897f25cf40d50c01 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 49963b32930737c580657469a05080acc5eb828d..a8fdef3d2ea40399798003a04793e6959143ae8f 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 689121673d2a1412acbd1ea966e56b78e63da9b5..ba13c83883289b615253a0b6ec0c8bbe881c7eec 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 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..feb70dc23ccb0183733b6f56e78ef30e3928bbf1 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 a1ddc308a5b15a9a400dc48e32fb3526e0bce6e4..2ed8d63b930bd486d180510124324ef35fe97847 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