From 5808cc499ce3fd81df938aec405236567774cf54 Mon Sep 17 00:00:00 2001 From: hzcheng Date: Sat, 21 Mar 2020 15:36:23 +0800 Subject: [PATCH] TD-34 --- src/util/inc/tlist.h | 1 + src/util/src/tlist.c | 10 ++++++++++ src/vnode/tsdb/src/tsdbMain.c | 29 ++++++++++++++++++++++++++++- src/vnode/tsdb/tests/tsdbTests.cpp | 3 ++- 4 files changed, 41 insertions(+), 2 deletions(-) diff --git a/src/util/inc/tlist.h b/src/util/inc/tlist.h index 2ea536ea3e..9e4dfe4580 100644 --- a/src/util/inc/tlist.h +++ b/src/util/inc/tlist.h @@ -56,6 +56,7 @@ int tdListAppend(SList *list, void *data); SListNode *tdListPopHead(SList *list); SListNode *tdListPopTail(SList *list); SListNode *tdListPopNode(SList *list, SListNode *node); +void tdListMove(SList *src, SList *dst); void tdListNodeGetData(SList *list, SListNode *node, void *target); void tdListInitIter(SList *list, SListIter *pIter, TD_LIST_DIRECTION_T direction); diff --git a/src/util/src/tlist.c b/src/util/src/tlist.c index 8844a5f787..badcb7802f 100644 --- a/src/util/src/tlist.c +++ b/src/util/src/tlist.c @@ -135,6 +135,16 @@ SListNode *tdListPopNode(SList *list, SListNode *node) { return node; } +// Move all node elements from src to dst, the dst is assumed as an empty list +void tdListMove(SList *src, SList *dst) { + // assert(dst->eleSize == src->eleSize); + dst->numOfEles = src->numOfEles; + dst->head = src->head; + dst->tail = src->tail; + src->numOfEles = 0; + src->head = src->tail = NULL; +} + void tdListNodeGetData(SList *list, SListNode *node, void *target) { memcpy(target, node->data, list->eleSize); } void tdListInitIter(SList *list, SListIter *pIter, TD_LIST_DIRECTION_T direction) { diff --git a/src/vnode/tsdb/src/tsdbMain.c b/src/vnode/tsdb/src/tsdbMain.c index 34fca7e428..ed95eac5bc 100644 --- a/src/vnode/tsdb/src/tsdbMain.c +++ b/src/vnode/tsdb/src/tsdbMain.c @@ -308,9 +308,23 @@ int32_t tsdbTriggerCommit(tsdb_repo_t *repo) { if (pthread_mutex_lock(&(pRepo->mutex)) < 0) return -1; if (pRepo->commit) return 0; pRepo->commit = 1; + // Loop to move pData to iData + for (int i = 0; i < pRepo->config.maxTables; i++) { + STable *pTable = pRepo->tsdbMeta->tables[i]; + if (pTable != NULL) { + void *pData = pTable->content.pData; + pTable->content.pData = NULL; + pTable->iData = pData; + } + } + // Loop to move mem to imem + tdListMove(pRepo->tsdbCache->mem, pRepo->tsdbCache->imem); + pthread_create(&(pRepo->commitThread), NULL, tsdbCommitToFile, (void *)repo); pthread_mutex_unlock(&(pRepo->mutex)); + pthread_join(pRepo->commitThread, NULL); + return 0; } @@ -692,7 +706,20 @@ static int32_t tsdbInsertDataToTable(tsdb_repo_t *repo, SSubmitBlk *pBlock) { } static void *tsdbCommitToFile(void *arg) { - STsdbRepo *pRepo = (STsdbRepo *)arg; // TODO + STsdbRepo *pRepo = (STsdbRepo *)arg; + STsdbMeta *pMeta = pRepo->tsdbMeta; + for (int i = 0; i < pRepo->config.maxTables; i++) { + STable *pTable = pMeta->tables[i]; + if (pTable == NULL) continue; + SSkipListIterator *pIter = tSkipListCreateIter(pTable->iData); + while (tSkipListIterNext(pIter)) { + SSkipListNode *node = tSkipListIterGet(pIter); + SDataRow row = SL_GET_NODE_DATA(node); + int k = 0; + + } + } + return NULL; } \ No newline at end of file diff --git a/src/vnode/tsdb/tests/tsdbTests.cpp b/src/vnode/tsdb/tests/tsdbTests.cpp index ed6a3bfcbb..9392ca5963 100644 --- a/src/vnode/tsdb/tests/tsdbTests.cpp +++ b/src/vnode/tsdb/tests/tsdbTests.cpp @@ -101,7 +101,8 @@ TEST(TsdbTest, createRepo) { tsdbInsertData(pRepo, pMsg); - int k = 0; + tsdbTriggerCommit(pRepo); + } TEST(TsdbTest, openRepo) { -- GitLab