From d1f7112e3ee0a3526d993e8dbcec7e5a8007763b Mon Sep 17 00:00:00 2001 From: hzcheng Date: Thu, 13 Feb 2020 05:37:25 +0000 Subject: [PATCH] more --- src/vnode/tsdb/inc/tsdbMeta.h | 2 + src/vnode/tsdb/src/tsdb.c | 155 ++++++++++++++++++++++++---------- src/vnode/tsdb/src/tsdbMeta.c | 65 +++++++++----- 3 files changed, 155 insertions(+), 67 deletions(-) diff --git a/src/vnode/tsdb/inc/tsdbMeta.h b/src/vnode/tsdb/inc/tsdbMeta.h index a8fdef3d2e..dc697d52fe 100644 --- a/src/vnode/tsdb/inc/tsdbMeta.h +++ b/src/vnode/tsdb/inc/tsdbMeta.h @@ -88,3 +88,5 @@ SMetaHandle * tsdbCreateMetaHandle (int32_t numOfTables); // Recover the meta handle from the file SMetaHandle * tsdbOpenMetaHandle(int fd); + +int32_t tsdbCreateMeterImpl(SMetaHandle *pHandle, STableCfg *pCfg); diff --git a/src/vnode/tsdb/src/tsdb.c b/src/vnode/tsdb/src/tsdb.c index ba13c83883..a50c674001 100644 --- a/src/vnode/tsdb/src/tsdb.c +++ b/src/vnode/tsdb/src/tsdb.c @@ -1,30 +1,29 @@ -#include #include +#include #include #include "tsdb.h" // #include "disk.h" -#include "tsdbMeta.h" #include "tsdbCache.h" +#include "tsdbMeta.h" -typedef struct STSDBRepo -{ - // TSDB configuration - STSDBcfg *pCfg; +typedef struct STSDBRepo { + // TSDB configuration + STSDBcfg *pCfg; - // The meter meta handle of this TSDB repository - SMetaHandle *pMetaHandle; + // The meter meta handle of this TSDB repository + SMetaHandle *pMetaHandle; - // The cache Handle - SCacheHandle *pCacheHandle; + // The cache Handle + SCacheHandle *pCacheHandle; - // Disk tier handle for multi-tier storage - SDiskTier *pDiskTier; + // Disk tier handle for multi-tier storage + SDiskTier *pDiskTier; - // File Store - void *pFileStore; + // File Store + void *pFileStore; - pthread_mutext_t tsdbMutex; + pthread_mutext_t tsdbMutex; } STSDBRepo; @@ -33,36 +32,104 @@ typedef struct STSDBRepo // Check the correctness of the TSDB configuration static int32_t tsdbCheckCfg(STSDBCfg *pCfg) { - // TODO - return 0; + // 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; + 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 + return NULL; + } + + // 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; +} + +int32_t tsdbDropRepo(tsdb_repo_t *pRepo, int32_t *error) { + STSDBRepo *pTRepo = (STSDBRepo *)pRepo; + + // TODO: Close the metaHandle + + // TODO: Close the cache + + return 0; +} + +tsdb_repo_t *tsdbOpenRepo(char *tsdbDir, int32_t *error) { + STSDBRepo *pRepo = (STSDBRepo *)malloc(sizeof(STSDBRepo)); + if (pRepo == NULL) { + return NULL; + } + + // TODO: Initialize configuration from the file + + { + // TODO: Initialize the pMetaHandle + } + if (pRepo->pMetaHandle == NULL) { + free(pRepo); + return NULL; + } + + { + // TODO: initialize the pCacheHandle + } + if (pRepo->pCacheHandle == NULL) { + // TODO: deal with error + return NULL; + } + + return (tsdb_repo_t *)pRepo; +} + +int32_t tsdbCloseRepo(tsdb_repo_t *pRepo, int32_t *error) { + STSDBRepo *pTRepo = (STSDBRepo *)pRepo; + + return 0; +} + +int32_t tsdbConfigRepo(STSDBCfg *pCfg, int32_t *error) { + // TODO +} + +STSDBRepoInfo *tsdbGetStatus(tsdb_repo_t *pRepo, int32_t *error) { + // TODO +} + +int32_t tsdbCreateTable(tsdb_repo_t *pRepo, STableCfg *pCfg, int32_t *error) { + // TODO +} + +int32_t tsdbAlterTable(tsdb_repo_t *pRepo, STableCfg *pCfg, int32_t *error) { + // TODO +} + +STableInfo *tsdbGetTableInfo(tsdb_repo_t *pRepo, STableId tid, int32_t *error) { + // TODO +} + +int32_t tsdbInsertData(tsdb_repo_t *pRepo, STableId tid, char *pData, int32_t *error) { + // TODO } \ No newline at end of file diff --git a/src/vnode/tsdb/src/tsdbMeta.c b/src/vnode/tsdb/src/tsdbMeta.c index 2ed8d63b93..a5e4025108 100644 --- a/src/vnode/tsdb/src/tsdbMeta.c +++ b/src/vnode/tsdb/src/tsdbMeta.c @@ -3,27 +3,46 @@ #include "tsdb.h" #include "tsdbMeta.h" -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; +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; +} + +static int32_t tsdbCheckTableCfg(STableCfg *pCfg) { return 0; } + +int32_t tsdbCreateMeterImpl(SMetaHandle *pHandle, STableCfg *pCfg) { + if (tsdbCheckTableCfg(pCfg) < 0) { + return -1; + } + + // TODO: + STable *pTable = (STable *)malloc(sizeof(STable)); + if (pTable == NULL) { + return -1; + } + + pHandle->pTables[pCfg->tableId] = pTable; + + // TODO: add name to it + return 0; } \ No newline at end of file -- GitLab