From 6211f281029c6f33c63af03f1a6de5a2a740f8db Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Mon, 13 Jun 2022 12:47:32 +0000 Subject: [PATCH] more work --- include/common/tdataformat.h | 4 +- source/common/src/tdataformat.c | 14 +++--- source/dnode/vnode/src/inc/tsdb.h | 60 ++++++++++++++++-------- source/dnode/vnode/src/tsdb/tsdbCommit.c | 4 +- source/dnode/vnode/src/tsdb/tsdbUtil.c | 39 ++++++++++++++- 5 files changed, 90 insertions(+), 31 deletions(-) diff --git a/include/common/tdataformat.h b/include/common/tdataformat.h index 6a73d3d678..9ce39e7966 100644 --- a/include/common/tdataformat.h +++ b/include/common/tdataformat.h @@ -42,7 +42,9 @@ int32_t tTSchemaCreate(int32_t sver, SSchema *pSchema, int32_t nCols, STSchema * void tTSchemaDestroy(STSchema *pTSchema); // SValue -int tValueCmprFn(const SValue *pValue1, const SValue *pValue2, int8_t type); +int32_t tPutValue(uint8_t *p, SValue *pValue, int8_t type); +int32_t tGetValue(uint8_t *p, SValue *pValue, int8_t type); +int tValueCmprFn(const SValue *pValue1, const SValue *pValue2, int8_t type); // STSRow2 #define COL_VAL_NONE(CID) ((SColVal){.cid = (CID), .isNone = 1}) diff --git a/source/common/src/tdataformat.c b/source/common/src/tdataformat.c index 1ddb606ccf..d2206735b4 100644 --- a/source/common/src/tdataformat.c +++ b/source/common/src/tdataformat.c @@ -37,7 +37,7 @@ typedef struct { #define GET_BIT2(p, i) (((p)[(i) / 4] >> ((i) % 4)) & ((uint8_t)3)) // SValue -static FORCE_INLINE int32_t tPutValue(uint8_t *p, SValue *pValue, int8_t type) { +int32_t tPutValue(uint8_t *p, SValue *pValue, int8_t type) { int32_t n = 0; if (IS_VAR_DATA_TYPE(type)) { @@ -88,7 +88,7 @@ static FORCE_INLINE int32_t tPutValue(uint8_t *p, SValue *pValue, int8_t type) { return n; } -static FORCE_INLINE int32_t tGetValue(uint8_t *p, SValue *pValue, int8_t type) { +int32_t tGetValue(uint8_t *p, SValue *pValue, int8_t type) { int32_t n = 0; if (IS_VAR_DATA_TYPE(type)) { @@ -421,7 +421,7 @@ int32_t tTSRowNew(STSRowBuilder *pBuilder, SArray *pArray, STSchema *pTSchema, S _set_none: if ((flags & 0xf0) == 0) { setBitMap(pb, 0, iColumn - 1, flags); - if (flags & TSROW_HAS_VAL) { // set 0 + if (flags & TSROW_HAS_VAL) { // set 0 if (IS_VAR_DATA_TYPE(pTColumn->type)) { *(VarDataOffsetT *)(pf + pTColumn->offset) = 0; } else { @@ -434,7 +434,7 @@ int32_t tTSRowNew(STSRowBuilder *pBuilder, SArray *pArray, STSchema *pTSchema, S _set_null: if ((flags & 0xf0) == 0) { setBitMap(pb, 1, iColumn - 1, flags); - if (flags & TSROW_HAS_VAL) { // set 0 + if (flags & TSROW_HAS_VAL) { // set 0 if (IS_VAR_DATA_TYPE(pTColumn->type)) { *(VarDataOffsetT *)(pf + pTColumn->offset) = 0; } else { @@ -1109,9 +1109,9 @@ _err: #if 1 // =================================================================================================================== static void dataColSetNEleNull(SDataCol *pCol, int nEle); int tdAllocMemForCol(SDataCol *pCol, int maxPoints) { - int spaceNeeded = pCol->bytes * maxPoints; - if (IS_VAR_DATA_TYPE(pCol->type)) { - spaceNeeded += sizeof(VarDataOffsetT) * maxPoints; + int spaceNeeded = pCol->bytes * maxPoints; + if (IS_VAR_DATA_TYPE(pCol->type)) { + spaceNeeded += sizeof(VarDataOffsetT) * maxPoints; } #ifdef TD_SUPPORT_BITMAP int32_t nBitmapBytes = (int32_t)TD_BITMAP_BYTES(maxPoints); diff --git a/source/dnode/vnode/src/inc/tsdb.h b/source/dnode/vnode/src/inc/tsdb.h index d3e66dc3df..cb4c04eec5 100644 --- a/source/dnode/vnode/src/inc/tsdb.h +++ b/source/dnode/vnode/src/inc/tsdb.h @@ -31,22 +31,23 @@ extern "C" { #define tsdbDebug(...) do { if (tsdbDebugFlag & DEBUG_DEBUG) { taosPrintLog("TSDB ", DEBUG_DEBUG, tsdbDebugFlag, __VA_ARGS__); }} while(0) #define tsdbTrace(...) do { if (tsdbDebugFlag & DEBUG_TRACE) { taosPrintLog("TSDB ", DEBUG_TRACE, tsdbDebugFlag, __VA_ARGS__); }} while(0) // clang-format on -typedef struct TSDBROW TSDBROW; -typedef struct TSDBKEY TSDBKEY; -typedef struct TABLEID TABLEID; -typedef struct SDelOp SDelOp; -typedef struct SDelDataItem SDelDataItem; -typedef struct SDelData SDelData; -typedef struct SDelIdxItem SDelIdxItem; -typedef struct SDelIdx SDelIdx; -typedef struct STbData STbData; -typedef struct SMemTable SMemTable; -typedef struct STbDataIter STbDataIter; -typedef struct SMergeInfo SMergeInfo; -typedef struct STable STable; -typedef struct SOffset SOffset; -typedef struct SMapData SMapData; -typedef struct SVDataCols SVDataCols; +typedef struct TSDBROW TSDBROW; +typedef struct TSDBKEY TSDBKEY; +typedef struct TABLEID TABLEID; +typedef struct SDelOp SDelOp; +typedef struct SDelDataItem SDelDataItem; +typedef struct SDelData SDelData; +typedef struct SDelIdxItem SDelIdxItem; +typedef struct SDelIdx SDelIdx; +typedef struct STbData STbData; +typedef struct SMemTable SMemTable; +typedef struct STbDataIter STbDataIter; +typedef struct SMergeInfo SMergeInfo; +typedef struct STable STable; +typedef struct SOffset SOffset; +typedef struct SMapData SMapData; +typedef struct SColData SColData; +typedef struct SColDataBlock SColDataBlock; // tsdbMemTable ============================================================================================== @@ -270,8 +271,16 @@ int tsdbLockRepo(STsdb *pTsdb); int tsdbUnlockRepo(STsdb *pTsdb); struct TSDBROW { - int64_t version; - STSRow *pTSRow; + union { + struct { + int64_t version; + STSRow *pTSRow; + }; + struct { + SColDataBlock *pColDataBlock; + int32_t iRow; + }; + }; }; struct SBlockIdxItem { @@ -449,8 +458,19 @@ struct SMapData { uint8_t *pData; }; -struct SVDataCols { - int64_t *aVersion; +struct SColData { + int16_t cid; + uint8_t flags; + uint32_t nData; + uint8_t *pData; +}; + +struct SColDataBlock { + int32_t nRow; + int64_t *aVersion; + TSKEY *aTSKey; + int32_t nColData; + SColData *aColData; }; #ifdef __cplusplus diff --git a/source/dnode/vnode/src/tsdb/tsdbCommit.c b/source/dnode/vnode/src/tsdb/tsdbCommit.c index 1655f222ac..8aabd6dcd8 100644 --- a/source/dnode/vnode/src/tsdb/tsdbCommit.c +++ b/source/dnode/vnode/src/tsdb/tsdbCommit.c @@ -40,8 +40,8 @@ struct SCommitter { SBlockIdx *pBlockIdx; SMapData oBlock; SMapData nBlock; - SColDataBatch oBatch; - SColDataBatch nBatch; + SColDataBlock oColDataBlock; + SColDataBlock nColDataBlock; /* commit del */ SDelFReader *pDelFReader; SDelFWriter *pDelFWriter; diff --git a/source/dnode/vnode/src/tsdb/tsdbUtil.c b/source/dnode/vnode/src/tsdb/tsdbUtil.c index 950b1fbd11..15782256f8 100644 --- a/source/dnode/vnode/src/tsdb/tsdbUtil.c +++ b/source/dnode/vnode/src/tsdb/tsdbUtil.c @@ -726,4 +726,41 @@ int32_t tsdbKeyFid(TSKEY key, int32_t minutes, int8_t precision) { } } -// SColDataBlock ====================================================== \ No newline at end of file +// TSDBROW ====================================================== +void tsdbRowGetColVal(TSDBROW *pRow, STSchema *pTSchema, int32_t iCol, SColVal *pColVal) { + // TODO +} + +// SColDataBlock ====================================================== +int32_t tsdbColDataBlockAppend(SColDataBlock *pColDataBlock, TSDBROW *pRow, STSchema *pTSchema) { + int32_t code = 0; + int32_t nRow = pColDataBlock->nRow; + STColumn *pTColumn; + SColData *pColData; + SColVal colVal; + + pColDataBlock->nRow++; + + // version + pColDataBlock->aVersion[nRow] = pRow->version; // TODO + + // ts + pColDataBlock->aTSKey[nRow] = pRow->pTSRow->ts; // TODO + + // other rows + for (int32_t iCol = 1; iCol < pTSchema->numOfCols; iCol++) { + pTColumn = &pTSchema->columns[iCol]; + + tsdbRowGetColVal(pRow, pTSchema, iCol, &colVal); + + if (colVal.isNone) { + // TODO + } else if (colVal.isNull) { + // TODO + } else { + pColData->nData += tPutValue(pColData->pData + pColData->nData, &colVal.value, pTColumn->type); + } + } + + return code; +} \ No newline at end of file