From 52873e2294dbb8e23f176c32bb1b5739654181d5 Mon Sep 17 00:00:00 2001 From: hzcheng Date: Thu, 5 Mar 2020 06:03:14 +0000 Subject: [PATCH] add more code --- src/vnode/common/inc/dataformat.h | 1 + src/vnode/common/src/dataformat.c | 7 +++++++ src/vnode/tsdb/inc/tsdbCache.h | 4 ++-- src/vnode/tsdb/inc/tsdbMeta.h | 2 ++ src/vnode/tsdb/src/tsdbMain.c | 23 +++++++++++++++++++++-- src/vnode/tsdb/src/tsdbMeta.c | 5 +++++ 6 files changed, 38 insertions(+), 4 deletions(-) diff --git a/src/vnode/common/inc/dataformat.h b/src/vnode/common/inc/dataformat.h index 45a76bb328..30246bc16c 100644 --- a/src/vnode/common/inc/dataformat.h +++ b/src/vnode/common/inc/dataformat.h @@ -74,6 +74,7 @@ typedef struct { #define TD_DATAROW_DATA(pDataRow) ((pDataRow) + sizeof(int32_t)) SDataRow tdSDataRowDup(SDataRow rdata); +void tdSDataRowCpy(SDataRow src, void *dst); void tdFreeSDataRow(SDataRow rdata); // ---- operation on SDataRows diff --git a/src/vnode/common/src/dataformat.c b/src/vnode/common/src/dataformat.c index 79a58ac45a..1e4d083f43 100644 --- a/src/vnode/common/src/dataformat.c +++ b/src/vnode/common/src/dataformat.c @@ -52,3 +52,10 @@ int32_t tdRdataIterEnd(SDataRowsIter *pIter) { return pIter->rowCounter >= pIter->totalRows; } + +/** + * Copy it + */ +void tdSDataRowCpy(SDataRow src, void *dst) { + // TODO +} \ No newline at end of file diff --git a/src/vnode/tsdb/inc/tsdbCache.h b/src/vnode/tsdb/inc/tsdbCache.h index 7f018d2b0b..8a78a6b19e 100644 --- a/src/vnode/tsdb/inc/tsdbCache.h +++ b/src/vnode/tsdb/inc/tsdbCache.h @@ -54,8 +54,8 @@ typedef struct STSDBCache { #define TSDB_PREV_CACHE_BLOCK(pBlock) ((pBlock)->prev) STsdbCache *tsdbCreateCache(int32_t numOfBlocks); -int32_t tsdbFreeCache(STsdbCache *pCache); -void *tsdbAllocFromCache(STsdbCache *pCache, int64_t bytes); +int32_t tsdbFreeCache(STsdbCache *pCache); +void * tsdbAllocFromCache(STsdbCache *pCache, int64_t bytes); #ifdef __cplusplus } diff --git a/src/vnode/tsdb/inc/tsdbMeta.h b/src/vnode/tsdb/inc/tsdbMeta.h index bedcf17d7d..833e5b134a 100644 --- a/src/vnode/tsdb/inc/tsdbMeta.h +++ b/src/vnode/tsdb/inc/tsdbMeta.h @@ -19,6 +19,7 @@ #include "tsdb.h" #include "dataformat.h" +#include "tskiplist.h" #ifdef __cplusplus extern "C" { @@ -114,6 +115,7 @@ STsdbMeta *tsdbOpenMeta(char *tsdbDir); int32_t tsdbCreateTableImpl(STsdbMeta *pMeta, STableCfg *pCfg); int32_t tsdbDropTableImpl(STsdbMeta *pMeta, STableId tableId); STable *tsdbIsValidTableToInsert(STsdbMeta *pMeta, STableId tableId); +int32_t tsdbInsertRowToTableImpl(SSkipListNode *pNode, STable *pTable); #ifdef __cplusplus } diff --git a/src/vnode/tsdb/src/tsdbMain.c b/src/vnode/tsdb/src/tsdbMain.c index aabae2b14d..c6e696e765 100644 --- a/src/vnode/tsdb/src/tsdbMain.c +++ b/src/vnode/tsdb/src/tsdbMain.c @@ -17,6 +17,7 @@ #include "tsdbFile.h" #include "tsdbMeta.h" #include "tutil.h" +#include "tskiplist.h" #define TSDB_DEFAULT_PRECISION TSDB_PRECISION_MILLI // default precision #define IS_VALID_PRECISION(precision) (((precision) >= TSDB_PRECISION_MILLI) && ((precision) <= TSDB_PRECISION_NANO)) @@ -403,7 +404,25 @@ static int tsdbRecoverRepo(int fd, STsdbCfg *pCfg) { return 0; } -static FORCE_INLINE int32_t tdInsertRowToTable(SDataRow row, STable *pTable) { return 0; } +static int32_t tdInsertRowToTable(STsdbRepo *pRepo, SDataRow row, STable *pTable) { + // TODO + int32_t level = 0; + int32_t headSize = 0; + + // Copy row into the memory + SSkipListNode *pNode = tsdbAllocFromCache(pRepo->tsdbCache, headSize + TD_DATAROW_LEN(row)); + if (pNode == NULL) { + // TODO: deal with allocate failure + } + + pNode->level = level; + tdSDataRowCpy(row, SL_GET_NODE_DATA(pNode)); + + // Insert the skiplist node into the data + tsdbInsertRowToTableImpl(pNode, pTable); + + return 0; +} static int32_t tsdbInsertDataToTable(tsdb_repo_t *repo, SSubmitBlock *pBlock) { STsdbRepo *pRepo = (STsdbRepo *)repo; @@ -418,7 +437,7 @@ static int32_t tsdbInsertDataToTable(tsdb_repo_t *repo, SSubmitBlock *pBlock) { tdInitSDataRowsIter(rows, pIter); while (!tdRdataIterEnd(pIter)) { - if (tdInsertRowToTable(pIter->row, pTable) < 0) { + if (tdInsertRowToTable(pRepo, pIter->row, pTable) < 0) { // TODO: deal with the error here } diff --git a/src/vnode/tsdb/src/tsdbMeta.c b/src/vnode/tsdb/src/tsdbMeta.c index 7a5d7b9f62..d942bf3a8e 100644 --- a/src/vnode/tsdb/src/tsdbMeta.c +++ b/src/vnode/tsdb/src/tsdbMeta.c @@ -175,6 +175,11 @@ int32_t tsdbDropTableImpl(STsdbMeta *pMeta, STableId tableId) { } } +int32_t tsdbInsertRowToTableImpl(SSkipListNode *pNode, STable *pTable) { + tSkipListPut(pTable->content.pData, pNode); + return 0; +} + static int tsdbFreeTable(STable *pTable) { // TODO: finish this function if (pTable->type == TSDB_STABLE) { -- GitLab