diff --git a/source/dnode/vnode/src/inc/tsdb.h b/source/dnode/vnode/src/inc/tsdb.h index 227bbd798e04da6f16be0c37109df7c7d7631d24..98a50418303e1407a298b30d36081b1436e240cf 100644 --- a/source/dnode/vnode/src/inc/tsdb.h +++ b/source/dnode/vnode/src/inc/tsdb.h @@ -55,6 +55,10 @@ typedef struct SReadH SReadH; #define TSDB_MAX_SUBBLOCKS 8 +#define HAS_NONE ((int8_t)0x1) +#define HAS_NULL ((int8_t)0x2) +#define HAS_VALUE ((int8_t)0x4) + // tsdbMemTable ============================================================================================== // SMemTable @@ -185,6 +189,10 @@ int32_t tPutBlock(uint8_t *p, void *ph); int32_t tGetBlock(uint8_t *p, void *ph); int32_t tBlockCmprFn(const void *p1, const void *p2); +// SBlockCol +int32_t tPutBlockCol(uint8_t *p, void *ph); +int32_t tGetBlockCol(uint8_t *p, void *ph); + // SBlockData #define tsdbBlockDataCreate() ((SBlockData){0}) void tsdbBlockDataClear(SBlockData *pBlockData); @@ -306,9 +314,28 @@ struct SBlockIdx { int64_t size; }; +struct SMapData { + int32_t nItem; + uint8_t flag; + uint8_t *pOfst; + uint32_t nData; + uint8_t *pData; + uint8_t *pBuf; +}; + typedef struct { + int16_t cid; + int8_t type; + int8_t flag; int64_t offset; int64_t size; +} SBlockCol; + +typedef struct { + int64_t offset; + int64_t ksize; + int64_t bsize; + SMapData mBlockCol; // SMapData } SSubBlock; struct SBlock { @@ -317,9 +344,11 @@ struct SBlock { int8_t last; int8_t hasDup; int8_t nSubBlock; - SSubBlock sBlocks[TSDB_MAX_SUBBLOCKS]; + SSubBlock aSubBlock[TSDB_MAX_SUBBLOCKS]; }; +int a = sizeof(SBlock); + struct SAggrBlkCol { int16_t colId; int16_t maxIndex; @@ -393,15 +422,6 @@ struct SDelFile { int64_t offset; }; -struct SMapData { - int32_t nItem; - uint8_t flag; - uint8_t *pOfst; - uint32_t nData; - uint8_t *pData; - uint8_t *pBuf; -}; - typedef struct { int16_t colId; int16_t maxIndex; diff --git a/source/dnode/vnode/src/tsdb/tsdbReaderWriter.c b/source/dnode/vnode/src/tsdb/tsdbReaderWriter.c index 856a076e195c1a1415050ce46edef850ae635319..84c63a8192ab496f5cc0a48be5b1e15dfb2708ec 100644 --- a/source/dnode/vnode/src/tsdb/tsdbReaderWriter.c +++ b/source/dnode/vnode/src/tsdb/tsdbReaderWriter.c @@ -723,8 +723,48 @@ _err: int32_t tsdbWriteBlockData(SDataFWriter *pWriter, SBlockData *pBlockData, uint8_t **ppBuf, SBlockIdx *pBlockIdx, SBlock *pBlock) { - int32_t code = 0; - // TODO + int32_t code = 0; + SSubBlock *pSubBlock = &pBlock->aSubBlock[pBlock->nSubBlock++]; + SBlockCol bCol; + + pSubBlock->offset = 0; + pSubBlock->ksize = 0; + pSubBlock->bsize = 0; + tMapDataClear(&pSubBlock->mBlockCol); + + // TSDBKEY + + // other columns + for (int32_t iCol = 0; iCol < pBlockData->nCol; iCol++) { + SColData *pColData = &pBlockData->aColData[iCol]; + + ASSERT(pColData->flags); + + if (pColData->flags == HAS_NONE) continue; + + bCol.cid = pColData->cid; + bCol.type = pColData->type; + bCol.flag = pColData->flags; + + if (pColData->flags != HAS_NULL) { + if (pColData->flags != HAS_VALUE) { + // handle bitmap + } + + // handle real data + + // bCol.offset = ; + // bCol.size = ; + } + + code = tMapDataPutItem(&pSubBlock->mBlockCol, &bCol, tPutBlockCol); + if (code) goto _err; + } + + return code; + +_err: + tsdbError("vgId:%d write block data failed since %s", pWriter->pTsdb, tstrerror(code)); return code; } diff --git a/source/dnode/vnode/src/tsdb/tsdbUtil.c b/source/dnode/vnode/src/tsdb/tsdbUtil.c index e63dbb8ed0a3b161ee2c43610bcf63b6bb4883b1..181208f73cb731a16e060f414944a60f4180ffa3 100644 --- a/source/dnode/vnode/src/tsdb/tsdbUtil.c +++ b/source/dnode/vnode/src/tsdb/tsdbUtil.c @@ -277,14 +277,14 @@ int32_t tGetBlockIdx(uint8_t *p, void *ph) { // SBlock ====================================================== int32_t tPutBlock(uint8_t *p, void *ph) { int32_t n = 0; - ASSERT(0); + SBlock *pBlock = (SBlock *)ph; // TODO return n; } int32_t tGetBlock(uint8_t *p, void *ph) { int32_t n = 0; - ASSERT(0); + SBlock *pBlock = (SBlock *)ph; // TODO return n; } @@ -303,6 +303,43 @@ int32_t tBlockCmprFn(const void *p1, const void *p2) { return 0; } +// SBlockCol ====================================================== +int32_t tPutBlockCol(uint8_t *p, void *ph) { + int32_t n = 0; + SBlockCol *pBlockCol = (SBlockCol *)ph; + + ASSERT(pBlockCol->flag && (pBlockCol->flag != HAS_NONE)); + + n += tPutI16v(p ? p + n : p, pBlockCol->cid); + n += tPutI8(p ? p + n : p, pBlockCol->type); + n += tPutI8(p ? p + n : p, pBlockCol->flag); + + if (pBlockCol->flag != HAS_NULL) { + n += tPutI64v(p ? p + n : p, pBlockCol->offset); + n += tPutI64v(p ? p + n : p, pBlockCol->size); + } + + return n; +} + +int32_t tGetBlockCol(uint8_t *p, void *ph) { + int32_t n = 0; + SBlockCol *pBlockCol = (SBlockCol *)ph; + + n += tGetI16v(p + n, &pBlockCol->cid); + n += tGetI8(p + n, &pBlockCol->type); + n += tGetI8(p + n, &pBlockCol->flag); + + ASSERT(pBlockCol->flag && (pBlockCol->flag != HAS_NONE)); + + if (pBlockCol->flag != HAS_NULL) { + n += tGetI64v(p + n, &pBlockCol->offset); + n += tGetI64v(p + n, &pBlockCol->size); + } + + return n; +} + // SDelIdx ====================================================== int32_t tPutDelIdx(uint8_t *p, void *ph) { SDelIdx *pDelIdx = (SDelIdx *)ph;