diff --git a/src/util/inc/tlist.h b/src/util/inc/tlist.h index 2ea536ea3e90bbc60d94a91eee7917acedad1e8b..9e4dfe45801ed448e6c55a6e69c87b22e9e77b88 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 8844a5f787c1923310ac71a30cc39594ed7f04f8..badcb7802f510b2978abace6b21a1098e1cdc44d 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 34fca7e428e051be33d855af21949f0618b5aac1..ed95eac5bc9fc8c41b78fb2944932d4909415ab2 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 ed6a3bfcbb1645d1931b3e056e8a424b840f9725..9392ca5963bb744afa25701fc69d6b5195959f8c 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) {