From e871eb8cf69d65cc3114b6aa6039cbab8c7e1ff8 Mon Sep 17 00:00:00 2001 From: hzcheng Date: Thu, 12 Mar 2020 12:17:44 +0800 Subject: [PATCH] add more code --- src/vnode/tsdb/inc/tsdbMeta.h | 7 +++-- src/vnode/tsdb/src/tsdbMeta.c | 56 +++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+), 2 deletions(-) diff --git a/src/vnode/tsdb/inc/tsdbMeta.h b/src/vnode/tsdb/inc/tsdbMeta.h index a86a206950..0a7f2a0bc6 100644 --- a/src/vnode/tsdb/inc/tsdbMeta.h +++ b/src/vnode/tsdb/inc/tsdbMeta.h @@ -39,6 +39,7 @@ typedef enum { #define IS_CREATE_STABLE(pCfg) ((pCfg)->tagValues != NULL) +// ---------- TSDB TABLE DEFINITION typedef struct STable { STableId tableId; TSDB_TABLE_TYPE type; @@ -79,6 +80,10 @@ typedef struct STable { } STable; +void * tsdbEncodeTable(STable *pTable, int *contLen); +STable *tsdbDecodeTable(void *cont, int contLen); +void * tsdbFreeEncode(void *cont); + // ---------- TSDB META HANDLE DEFINITION typedef struct { int32_t maxTables; // Max number of tables @@ -108,8 +113,6 @@ int32_t tsdbFreeMeta(STsdbMeta *pMeta); #define TSDB_TABLE_CACHE_DATA(pTable) ((pTable)->content.pData) #define TSDB_SUPER_TABLE_INDEX(pTable) ((pTable)->content.pIndex) -STSchema *tsdbGetTableSchema(STable *pTable); - // ---- Operation on SMetaHandle #define TSDB_NUM_OF_TABLES(pHandle) ((pHandle)->numOfTables) #define TSDB_NUM_OF_SUPER_TABLES(pHandle) ((pHandle)->numOfSuperTables) diff --git a/src/vnode/tsdb/src/tsdbMeta.c b/src/vnode/tsdb/src/tsdbMeta.c index 4f943c3b41..b0acd811ac 100644 --- a/src/vnode/tsdb/src/tsdbMeta.c +++ b/src/vnode/tsdb/src/tsdbMeta.c @@ -17,6 +17,57 @@ static int tsdbAddTableToMeta(STsdbMeta *pMeta, STable *pTable); static int tsdbAddTableIntoMap(STsdbMeta *pMeta, STable *pTable); static int tsdbAddTableIntoIndex(STsdbMeta *pMeta, STable *pTable); static int tsdbRemoveTableFromIndex(STsdbMeta *pMeta, STable *pTable); +static int tsdbEstimateTableEncodeSize(STable *pTable); + +/** + * Encode a TSDB table object as a binary content + * ASSUMPTIONS: VALID PARAMETERS + * + * @param pTable table object to encode + * @param contLen the encoded binary content length + * + * @return binary content for success + * NULL fro failure + */ +void *tsdbEncodeTable(STable *pTable, int *contLen) { + if (pTable == NULL) return NULL; + + *contLen = tsdbEstimateTableEncodeSize(pTable); + if (*contLen < 0) return NULL; + + void *ret = malloc(*contLen); + if (ret == NULL) return NULL; + + // TODO: encode the object to the memory + {} + + return ret; +} + +/** + * Decode from an encoded binary + * ASSUMPTIONS: valid parameters + * + * @param cont binary object + * @param contLen binary length + * + * @return TSDB table object for success + * NULL for failure + */ +STable *tsdbDecodeTable(void *cont, int contLen) { + STable *pTable = (STable *)calloc(1, sizeof(STable)); + if (pTable == NULL) return NULL; + + { + // TODO recover from the binary content + } + + return pTable; +} + +void *tsdbFreeEncode(void *cont) { + if (cont != NULL) free(cont); +} /** * Initialize the meta handle @@ -261,4 +312,9 @@ static int tsdbRemoveTableFromIndex(STsdbMeta *pMeta, STable *pTable) { assert(pTable->type == TSDB_STABLE); // TODO return 0; +} + +static int tsdbEstimateTableEncodeSize(STable *pTable) { + // TODO + return 0; } \ No newline at end of file -- GitLab