From b1a781cc09a6eac763c9689249c129fa60d13d4e Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Sat, 4 Jun 2022 12:42:25 +0000 Subject: [PATCH] more progress --- include/common/tdataformat.h | 7 +++ source/dnode/vnode/src/inc/tsdb.h | 26 ++++++++++ source/dnode/vnode/src/tsdb/tsdbCommit2.c | 55 +++++++++++++++++++++ source/dnode/vnode/src/tsdb/tsdbMemTable2.c | 22 --------- 4 files changed, 88 insertions(+), 22 deletions(-) diff --git a/include/common/tdataformat.h b/include/common/tdataformat.h index 6a73d3d678..2e69640a06 100644 --- a/include/common/tdataformat.h +++ b/include/common/tdataformat.h @@ -34,6 +34,7 @@ typedef struct SValue SValue; typedef struct SColVal SColVal; typedef struct STSRow2 STSRow2; typedef struct STSRowBuilder STSRowBuilder; +typedef struct SColData SColData; typedef struct STagVal STagVal; typedef struct STag STag; @@ -169,6 +170,12 @@ struct STag { }; #pragma pack(pop) +struct SColData { + int16_t cid; + uint32_t nData; + uint8_t *pData; +}; + #if 1 //================================================================================================================================================ // Imported since 3.0 and use bitmap to demonstrate None/Null/Norm, while use Null/Norm below 3.0 without of bitmap. #define TD_SUPPORT_BITMAP diff --git a/source/dnode/vnode/src/inc/tsdb.h b/source/dnode/vnode/src/inc/tsdb.h index 3a2eec30ba..cb12550d1f 100644 --- a/source/dnode/vnode/src/inc/tsdb.h +++ b/source/dnode/vnode/src/inc/tsdb.h @@ -34,6 +34,7 @@ extern "C" { typedef struct TSDBROW TSDBROW; typedef struct TSDBKEY TSDBKEY; +typedef struct TABLEID TABLEID; typedef struct SDelOp SDelOp; static int tsdbKeyCmprFn(const void *p1, const void *p2); @@ -883,6 +884,11 @@ struct TSDBKEY { TSKEY ts; }; +struct TABLEID { + tb_uid_t suid; + tb_uid_t uid; +}; + struct SDelOp { int64_t version; TSKEY sKey; // included @@ -919,6 +925,26 @@ static FORCE_INLINE int tsdbKeyCmprFn(const void *p1, const void *p2) { return 0; } +typedef struct SMemSkipListNode SMemSkipListNode; +typedef struct SMemSkipList { + uint32_t seed; + int32_t size; + int8_t maxLevel; + int8_t level; + SMemSkipListNode *pHead; + SMemSkipListNode *pTail; +} SMemSkipList; + +struct SMemData { + tb_uid_t suid; + tb_uid_t uid; + TSDBKEY minKey; + TSDBKEY maxKey; + SDelOp *delOpHead; + SDelOp *delOpTail; + SMemSkipList sl; +}; + struct SMemDataIter { SMemData *pMemData; TSDBROW row; diff --git a/source/dnode/vnode/src/tsdb/tsdbCommit2.c b/source/dnode/vnode/src/tsdb/tsdbCommit2.c index 6bb53a1263..5741da0e80 100644 --- a/source/dnode/vnode/src/tsdb/tsdbCommit2.c +++ b/source/dnode/vnode/src/tsdb/tsdbCommit2.c @@ -88,6 +88,30 @@ static int32_t tsdbEndCommit(SCommitH *pCHandle) { return code; } +static int32_t tsdbCommitTableData(SCommitH *pCHandle, SMemData *pMemData, SBlockIdx *pBlockIdx) { + int32_t code = 0; + // TODO + return code; +} + +static int32_t tsdbTableIdCmprFn(const void *p1, const void *p2) { + TABLEID *pId1 = (TABLEID *)p1; + TABLEID *pId2 = (TABLEID *)p2; + + if (pId1->suid < pId2->suid) { + return -1; + } else if (pId1->suid > pId2->suid) { + return 1; + } + + if (pId1->uid < pId2->uid) { + return -1; + } else if (pId1->uid > pId2->uid) { + return 1; + } + + return 0; +} static int32_t tsdbCommitToFile(SCommitH *pCHandle, int32_t fid) { int32_t code = 0; SMemDataIter iter = {0}; @@ -114,6 +138,8 @@ static int32_t tsdbCommitToFile(SCommitH *pCHandle, int32_t fid) { if (!hasData) return code; + // create or open the file to commit(todo) + // loop to commit each table data nBlockIdx = 0; for (;;) { @@ -127,7 +153,36 @@ static int32_t tsdbCommitToFile(SCommitH *pCHandle, int32_t fid) { if (iBlockIdx < nBlockIdx) { // pBlockIdx } + + if (pMemData && pBlockIdx) { + int32_t c = tsdbTableIdCmprFn(&(TABLEID){.suid = pMemData->suid, .uid = pMemData->uid}, + &(TABLEID){.suid = pBlockIdx->suid, .uid = pBlockIdx->uid}); + if (c == 0) { + iMemData++; + iBlockIdx++; + } else if (c < 0) { + pBlockIdx = NULL; + iMemData++; + } else { + pMemData = NULL; + iBlockIdx++; + } + } else { + if (pMemData) { + iMemData++; + } else { + iBlockIdx++; + } + } + + code = tsdbCommitTableData(pCHandle, pMemData, pBlockIdx); + if (code) { + goto _err; + } } return code; + +_err: + return code; } \ No newline at end of file diff --git a/source/dnode/vnode/src/tsdb/tsdbMemTable2.c b/source/dnode/vnode/src/tsdb/tsdbMemTable2.c index 1c28b086b3..dee025cae6 100644 --- a/source/dnode/vnode/src/tsdb/tsdbMemTable2.c +++ b/source/dnode/vnode/src/tsdb/tsdbMemTable2.c @@ -15,33 +15,11 @@ #include "tsdb.h" -typedef struct SMemSkipList SMemSkipList; -typedef struct SMemSkipListNode SMemSkipListNode; - struct SMemSkipListNode { int8_t level; SMemSkipListNode *forwards[0]; }; -struct SMemSkipList { - uint32_t seed; - int32_t size; - int8_t maxLevel; - int8_t level; - SMemSkipListNode *pHead; - SMemSkipListNode *pTail; -}; - -struct SMemData { - tb_uid_t suid; - tb_uid_t uid; - TSDBKEY minKey; - TSDBKEY maxKey; - SDelOp *delOpHead; - SDelOp *delOpTail; - SMemSkipList sl; -}; - typedef struct { tb_uid_t uid; STSchema *pTSchema; -- GitLab