From 9fee49831598669a3e5b9c4035c5980523dbda4c Mon Sep 17 00:00:00 2001 From: hzcheng Date: Mon, 30 Mar 2020 22:48:53 +0800 Subject: [PATCH] TD-34 --- src/vnode/tsdb/inc/tsdbMeta.h | 1 + src/vnode/tsdb/src/tsdbMain.c | 4 ++-- src/vnode/tsdb/src/tsdbMeta.c | 12 ++++++++++++ src/vnode/tsdb/tests/tsdbTests.cpp | 4 ++-- 4 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/vnode/tsdb/inc/tsdbMeta.h b/src/vnode/tsdb/inc/tsdbMeta.h index 059ec87e91..aa25e08444 100644 --- a/src/vnode/tsdb/inc/tsdbMeta.h +++ b/src/vnode/tsdb/inc/tsdbMeta.h @@ -80,6 +80,7 @@ typedef struct { STsdbMeta *tsdbInitMeta(const char *rootDir, int32_t maxTables); int32_t tsdbFreeMeta(STsdbMeta *pMeta); +STSchema * tsdbGetTableSchema(STsdbMeta *pMeta, STable *pTable); // ---- Operation on STable #define TSDB_TABLE_ID(pTable) ((pTable)->tableId) diff --git a/src/vnode/tsdb/src/tsdbMain.c b/src/vnode/tsdb/src/tsdbMain.c index 6d675d300a..6510c02940 100644 --- a/src/vnode/tsdb/src/tsdbMain.c +++ b/src/vnode/tsdb/src/tsdbMain.c @@ -988,7 +988,7 @@ static int tsdbCommitToFile(STsdbRepo *pRepo, int fid, SSkipListIterator **iters if (tsdbLoadCompBlocks(pGroup, pIdx, (void *)pCompInfo) < 0) { /* TODO */ } - tdInitDataCols(pCols, pTable->schema); + tdInitDataCols(pCols, tsdbGetTableSchema(pMeta, pTable)); SCompBlock *pTBlock = TSDB_COMPBLOCK_AT(pCompInfo, pIdx->numOfSuperBlocks); int nBlocks = 0; @@ -1040,7 +1040,7 @@ static int tsdbCommitToFile(STsdbRepo *pRepo, int fid, SSkipListIterator **iters } } - tdInitDataCols(pCols, pTable->schema); + tdInitDataCols(pCols, tsdbGetTableSchema(pMeta, pTable)); int maxRowsToRead = pCfg->maxRowsPerFileBlock * 4 / 5; while (1) { diff --git a/src/vnode/tsdb/src/tsdbMeta.c b/src/vnode/tsdb/src/tsdbMeta.c index 22680a839b..12e2dbcb56 100644 --- a/src/vnode/tsdb/src/tsdbMeta.c +++ b/src/vnode/tsdb/src/tsdbMeta.c @@ -185,6 +185,18 @@ int32_t tsdbFreeMeta(STsdbMeta *pMeta) { return 0; } +STSchema *tsdbGetTableSchema(STsdbMeta *pMeta, STable *pTable) { + if (pTable->type == TSDB_NORMAL_TABLE || pTable->type == TSDB_SUPER_TABLE) { + return pTable->schema; + } else if (pTable->type == TSDB_CHILD_TABLE) { + STable *pSuper = tsdbGetTableByUid(pMeta, pTable->superUid); + if (pSuper == NULL) return NULL; + return pSuper->schema; + } else { + return NULL; + } +} + int32_t tsdbCreateTableImpl(STsdbMeta *pMeta, STableCfg *pCfg) { if (tsdbCheckTableCfg(pCfg) < 0) return -1; diff --git a/src/vnode/tsdb/tests/tsdbTests.cpp b/src/vnode/tsdb/tests/tsdbTests.cpp index 6cfe0e626d..9849ffe8fa 100644 --- a/src/vnode/tsdb/tests/tsdbTests.cpp +++ b/src/vnode/tsdb/tests/tsdbTests.cpp @@ -80,7 +80,7 @@ TEST(TsdbTest, createRepo) { // // 3. Loop to write some simple data int nRows = 10000000; - int rowsPerSubmit = 10; + int rowsPerSubmit = 100; int64_t start_time = 1584081000000; SSubmitMsg *pMsg = (SSubmitMsg *)malloc(sizeof(SSubmitMsg) + sizeof(SSubmitBlk) + tdMaxRowBytesFromSchema(schema) * rowsPerSubmit); @@ -96,7 +96,7 @@ TEST(TsdbTest, createRepo) { pBlock->len = 0; for (int i = 0; i < rowsPerSubmit; i++) { // start_time += 1000; - start_time -= 1000; + start_time += 1000; SDataRow row = (SDataRow)(pBlock->data + pBlock->len); tdInitDataRow(row, schema); -- GitLab