From 40dfd72695fef3e9bf162fbca90c8bd6ae2fba0c Mon Sep 17 00:00:00 2001 From: hzcheng Date: Tue, 31 Mar 2020 14:56:12 +0800 Subject: [PATCH] TD-34 --- src/vnode/tsdb/src/tsdbMeta.c | 12 ++++++++---- src/vnode/tsdb/tests/tsdbTests.cpp | 12 ++++++------ 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/vnode/tsdb/src/tsdbMeta.c b/src/vnode/tsdb/src/tsdbMeta.c index 254119880f..2d25aba71c 100644 --- a/src/vnode/tsdb/src/tsdbMeta.c +++ b/src/vnode/tsdb/src/tsdbMeta.c @@ -247,10 +247,6 @@ int32_t tsdbCreateTableImpl(STsdbMeta *pMeta, STableCfg *pCfg) { table->type = TSDB_NORMAL_TABLE; table->superUid = -1; table->schema = tdDupSchema(pCfg->schema); - if (schemaNCols(table->schema) > pMeta->maxCols) pMeta->maxCols = schemaNCols(table->schema); - tdUpdateSchema(table->schema); - int bytes = tdMaxRowBytesFromSchema(table->schema); - if (bytes > pMeta->maxRowBytes) pMeta->maxRowBytes = bytes; } // Register to meta @@ -367,6 +363,14 @@ static int tsdbAddTableToMeta(STsdbMeta *pMeta, STable *pTable, bool addIdx) { pMeta->nTables++; } + // Update the pMeta->maxCols and pMeta->maxRowBytes + if (pTable->type == TSDB_SUPER_TABLE || pTable->type == TSDB_NORMAL_TABLE) { + if (schemaNCols(pTable->schema) > pMeta->maxCols) pMeta->maxCols = schemaNCols(pTable->schema); + int bytes = tdMaxRowBytesFromSchema(pTable->schema); + if (bytes > pMeta->maxRowBytes) pMeta->maxRowBytes = bytes; + tdUpdateSchema(pTable->schema); + } + return tsdbAddTableIntoMap(pMeta, pTable); } diff --git a/src/vnode/tsdb/tests/tsdbTests.cpp b/src/vnode/tsdb/tests/tsdbTests.cpp index bce3339b27..2bead0a51d 100644 --- a/src/vnode/tsdb/tests/tsdbTests.cpp +++ b/src/vnode/tsdb/tests/tsdbTests.cpp @@ -47,8 +47,8 @@ TEST(TsdbTest, DISABLED_tableEncodeDecode) { ASSERT_EQ(memcmp(pTable->schema, tTable->schema, sizeof(STSchema) + sizeof(STColumn) * nCols), 0); } -// TEST(TsdbTest, DISABLED_createRepo) { -TEST(TsdbTest, createRepo) { +TEST(TsdbTest, DISABLED_createRepo) { +// TEST(TsdbTest, createRepo) { STsdbCfg config; // 1. Create a tsdb repository @@ -139,12 +139,12 @@ TEST(TsdbTest, createRepo) { // TEST(TsdbTest, DISABLED_openRepo) { TEST(TsdbTest, openRepo) { - tsdb_repo_t *repo = tsdbOpenRepo("/home/ubuntu/work/ttest/vnode0"); + tsdb_repo_t *repo = tsdbOpenRepo("/home/ubuntu/work/build/test/data/vnode/vnode1/tsdb"); ASSERT_NE(repo, nullptr); STsdbRepo *pRepo = (STsdbRepo *)repo; - SFileGroup *pGroup = tsdbSearchFGroup(pRepo->tsdbFileH, 1833); + SFileGroup *pGroup = tsdbSearchFGroup(pRepo->tsdbFileH, 1835); for (int type = TSDB_FILE_TYPE_HEAD; type < TSDB_FILE_TYPE_MAX; type++) { tsdbOpenFile(&pGroup->files[type], O_RDONLY); @@ -153,9 +153,9 @@ TEST(TsdbTest, openRepo) { SCompIdx *pIdx = (SCompIdx *)calloc(pRepo->config.maxTables, sizeof(SCompIdx)); tsdbLoadCompIdx(pGroup, (void *)pIdx, pRepo->config.maxTables); - SCompInfo *pCompInfo = (SCompInfo *)malloc(sizeof(SCompInfo) + pIdx[0].len); + SCompInfo *pCompInfo = (SCompInfo *)malloc(sizeof(SCompInfo) + pIdx[1].len); - tsdbLoadCompBlocks(pGroup, pIdx, (void *)pCompInfo); + tsdbLoadCompBlocks(pGroup, &pIdx[1], (void *)pCompInfo); int k = 0; -- GitLab