From 83e238d01cba34cbf58d0163f73e735bbacd0e54 Mon Sep 17 00:00:00 2001 From: hzcheng Date: Tue, 31 Mar 2020 22:55:23 +0800 Subject: [PATCH] TD-34 --- src/vnode/tsdb/src/tsdbFile.c | 3 ++- src/vnode/tsdb/src/tsdbMain.c | 1 + src/vnode/tsdb/src/tsdbMeta.c | 2 +- src/vnode/tsdb/tests/tsdbTests.cpp | 25 ++++++++++++++++++++----- 4 files changed, 24 insertions(+), 7 deletions(-) diff --git a/src/vnode/tsdb/src/tsdbFile.c b/src/vnode/tsdb/src/tsdbFile.c index 208ebf1653..1d6e429423 100644 --- a/src/vnode/tsdb/src/tsdbFile.c +++ b/src/vnode/tsdb/src/tsdbFile.c @@ -183,9 +183,10 @@ int tsdbLoadDataBlock(SFile *pFile, SCompBlock *pStartBlock, int numOfBlocks, SD SCompBlock *pBlock = pStartBlock; for (int i = 0; i < numOfBlocks; i++) { if (tsdbLoadCompCols(pFile, pBlock, (void *)pCompData) < 0) return -1; + pCols->numOfPoints += (pCompData->cols[0].len / 8); for (int iCol = 0; iCol < pBlock->numOfCols; iCol++) { SCompCol *pCompCol = &(pCompData->cols[iCol]); - pCols->numOfPoints += pBlock->numOfPoints; + // pCols->numOfPoints += pBlock->numOfPoints; int k = 0; for (; k < pCols->numOfCols; k++) { if (pCompCol->colId == pCols->cols[k].colId) break; diff --git a/src/vnode/tsdb/src/tsdbMain.c b/src/vnode/tsdb/src/tsdbMain.c index cb69ff4528..8fece70c90 100644 --- a/src/vnode/tsdb/src/tsdbMain.c +++ b/src/vnode/tsdb/src/tsdbMain.c @@ -1031,6 +1031,7 @@ static int tsdbCommitToFile(STsdbRepo *pRepo, int fid, SSkipListIterator **iters pTBlock->numOfPoints = pCols->numOfPoints; pTBlock->sversion = pTable->sversion; pTBlock->numOfSubBlocks = 1; + pTBlock->numOfCols = pCols->numOfCols; if (dataColsKeyLast(pCols) > pIdx->maxKey) pIdx->maxKey = dataColsKeyLast(pCols); diff --git a/src/vnode/tsdb/src/tsdbMeta.c b/src/vnode/tsdb/src/tsdbMeta.c index 2d25aba71c..745b6049bd 100644 --- a/src/vnode/tsdb/src/tsdbMeta.c +++ b/src/vnode/tsdb/src/tsdbMeta.c @@ -74,7 +74,7 @@ STable *tsdbDecodeTable(void *cont, int contLen) { T_READ_MEMBER(ptr, int8_t, pTable->type); T_READ_MEMBER(ptr, int64_t, pTable->tableId.uid); T_READ_MEMBER(ptr, int32_t, pTable->tableId.tid); - T_READ_MEMBER(ptr, int32_t, pTable->superUid); + T_READ_MEMBER(ptr, int64_t, pTable->superUid); T_READ_MEMBER(ptr, int32_t, pTable->sversion); if (pTable->type == TSDB_SUPER_TABLE) { diff --git a/src/vnode/tsdb/tests/tsdbTests.cpp b/src/vnode/tsdb/tests/tsdbTests.cpp index 2bead0a51d..d3a5b680aa 100644 --- a/src/vnode/tsdb/tests/tsdbTests.cpp +++ b/src/vnode/tsdb/tests/tsdbTests.cpp @@ -12,6 +12,7 @@ double getCurTime() { } TEST(TsdbTest, DISABLED_tableEncodeDecode) { +// TEST(TsdbTest, tableEncodeDecode) { STable *pTable = (STable *)malloc(sizeof(STable)); pTable->type = TSDB_NORMAL_TABLE; @@ -47,8 +48,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 +140,12 @@ TEST(TsdbTest, DISABLED_createRepo) { // TEST(TsdbTest, DISABLED_openRepo) { TEST(TsdbTest, openRepo) { - tsdb_repo_t *repo = tsdbOpenRepo("/home/ubuntu/work/build/test/data/vnode/vnode1/tsdb"); + tsdb_repo_t *repo = tsdbOpenRepo("/home/ubuntu/work/ttest/vnode0"); ASSERT_NE(repo, nullptr); STsdbRepo *pRepo = (STsdbRepo *)repo; - SFileGroup *pGroup = tsdbSearchFGroup(pRepo->tsdbFileH, 1835); + SFileGroup *pGroup = tsdbSearchFGroup(pRepo->tsdbFileH, 1833); for (int type = TSDB_FILE_TYPE_HEAD; type < TSDB_FILE_TYPE_MAX; type++) { tsdbOpenFile(&pGroup->files[type], O_RDONLY); @@ -155,7 +156,21 @@ TEST(TsdbTest, openRepo) { SCompInfo *pCompInfo = (SCompInfo *)malloc(sizeof(SCompInfo) + pIdx[1].len); - tsdbLoadCompBlocks(pGroup, &pIdx[1], (void *)pCompInfo); + tsdbLoadCompBlocks(pGroup, &pIdx[0], (void *)pCompInfo); + + int blockIdx = 0; + SCompBlock *pBlock = &(pCompInfo->blocks[blockIdx]); + + SCompData *pCompData = (SCompData *)malloc(sizeof(SCompData) + sizeof(SCompCol) * pBlock->numOfCols); + + tsdbLoadCompCols(&pGroup->files[TSDB_FILE_TYPE_DATA], pBlock, (void *)pCompData); + + STable *pTable = tsdbGetTableByUid(pRepo->tsdbMeta, pCompData->uid); + SDataCols *pDataCols = tdNewDataCols(tdMaxRowBytesFromSchema(pTable->schema), 5, 10); + tdInitDataCols(pDataCols, pTable->schema); + + tsdbLoadDataBlock(&pGroup->files[TSDB_FILE_TYPE_DATA], pBlock, 1, pDataCols, pCompData); + int k = 0; -- GitLab