From 377517eec46cc5f3d12f6f38fdf3e589ccf67640 Mon Sep 17 00:00:00 2001 From: hzcheng Date: Tue, 24 Mar 2020 18:30:25 +0800 Subject: [PATCH] TD-34 --- src/vnode/tsdb/src/tsdbMain.c | 73 +++++++++++++++--------------- src/vnode/tsdb/tests/tsdbTests.cpp | 2 +- 2 files changed, 38 insertions(+), 37 deletions(-) diff --git a/src/vnode/tsdb/src/tsdbMain.c b/src/vnode/tsdb/src/tsdbMain.c index 07ea9bd11a..af3a923d90 100644 --- a/src/vnode/tsdb/src/tsdbMain.c +++ b/src/vnode/tsdb/src/tsdbMain.c @@ -818,6 +818,7 @@ static SSkipListIterator **tsdbCreateTableIters(STsdbMeta *pMeta, int maxTables) // Commit to file static void *tsdbCommitToFile(void *arg) { // TODO + printf("Starting to commit....\n"); STsdbRepo * pRepo = (STsdbRepo *)arg; STsdbMeta * pMeta = pRepo->tsdbMeta; STsdbCache *pCache = pRepo->tsdbCache; @@ -836,42 +837,42 @@ static void *tsdbCommitToFile(void *arg) { SDataCol **cols = (SDataCol **)malloc(sizeof(SDataCol *) * maxCols); void *buf = malloc((maxBytes + sizeof(SDataCol)) * pCfg->maxRowsPerFileBlock); - // int sfid = tsdbGetKeyFileId(pCache->imem->keyFirst, pCfg->daysPerFile, pCfg->precision); - // int efid = tsdbGetKeyFileId(pCache->imem->keyLast, pCfg->daysPerFile, pCfg->precision); - - // for (int fid = sfid; fid <= efid; fid++) { - // TSKEY minKey = 0, maxKey = 0; - // tsdbGetKeyRangeOfFileId(pCfg->daysPerFile, pCfg->precision, fid, &minKey, &maxKey); - - // // tsdbOpenFileForWrite(pRepo, fid); - - // for (int tid = 0; tid < pCfg->maxTables; tid++) { - // STable *pTable = pMeta->tables[tid]; - // if (pTable == NULL || pTable->imem == NULL) continue; - // if (iters[tid] == NULL) { // create table iterator - // iters[tid] = tSkipListCreateIter(pTable->imem->pData); - // // TODO: deal with the error - // if (iters[tid] == NULL) break; - // if (!tSkipListIterNext(iters[tid])) { - // // assert(0); - // } - // } - - // // Init row data part - // cols[0] = (SDataCol *)buf; - // for (int col = 1; col < schemaNCols(pTable->schema); col++) { - // cols[col] = (SDataCol *)((char *)(cols[col - 1]) + sizeof(SDataCol) + colBytes(schemaColAt(pTable->schema, col-1)) * pCfg->maxRowsPerFileBlock); - // } - - // // Loop the iterator - // int rowsRead = 0; - // while ((rowsRead = tsdbReadRowsFromCache(iters[tid], maxKey, pCfg->maxRowsPerFileBlock, cols, pTable->schema)) > - // 0) { - // // printf("rowsRead:%d-----------\n", rowsRead); - // int k = 0; - // } - // } - // } + int sfid = tsdbGetKeyFileId(pCache->imem->keyFirst, pCfg->daysPerFile, pCfg->precision); + int efid = tsdbGetKeyFileId(pCache->imem->keyLast, pCfg->daysPerFile, pCfg->precision); + + for (int fid = sfid; fid <= efid; fid++) { + TSKEY minKey = 0, maxKey = 0; + tsdbGetKeyRangeOfFileId(pCfg->daysPerFile, pCfg->precision, fid, &minKey, &maxKey); + + // tsdbOpenFileForWrite(pRepo, fid); + + for (int tid = 0; tid < pCfg->maxTables; tid++) { + STable *pTable = pMeta->tables[tid]; + if (pTable == NULL || pTable->imem == NULL) continue; + if (iters[tid] == NULL) { // create table iterator + iters[tid] = tSkipListCreateIter(pTable->imem->pData); + // TODO: deal with the error + if (iters[tid] == NULL) break; + if (!tSkipListIterNext(iters[tid])) { + // assert(0); + } + } + + // Init row data part + cols[0] = (SDataCol *)buf; + for (int col = 1; col < schemaNCols(pTable->schema); col++) { + cols[col] = (SDataCol *)((char *)(cols[col - 1]) + sizeof(SDataCol) + colBytes(schemaColAt(pTable->schema, col-1)) * pCfg->maxRowsPerFileBlock); + } + + // Loop the iterator + int rowsRead = 0; + while ((rowsRead = tsdbReadRowsFromCache(iters[tid], maxKey, pCfg->maxRowsPerFileBlock, cols, pTable->schema)) > + 0) { + // printf("rowsRead:%d-----------\n", rowsRead); + int k = 0; + } + } + } tsdbDestroyTableIters(iters, pCfg->maxTables); diff --git a/src/vnode/tsdb/tests/tsdbTests.cpp b/src/vnode/tsdb/tests/tsdbTests.cpp index a76aef2d41..bc6532984f 100644 --- a/src/vnode/tsdb/tests/tsdbTests.cpp +++ b/src/vnode/tsdb/tests/tsdbTests.cpp @@ -142,7 +142,7 @@ TEST(TsdbTest, DISABLED_openRepo) { TEST(TsdbTest, DISABLED_createFileGroup) { SFileGroup fGroup; - ASSERT_EQ(tsdbCreateFileGroup("/home/ubuntu/work/ttest/vnode0/data", 1820, &fGroup, 1000), 0); + // ASSERT_EQ(tsdbCreateFileGroup("/home/ubuntu/work/ttest/vnode0/data", 1820, &fGroup, 1000), 0); int k = 0; } \ No newline at end of file -- GitLab