From de32cab384d8eec3131e0230bfdbf3e618ed32e2 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Sat, 4 Jun 2022 08:27:55 +0000 Subject: [PATCH] more progress --- source/dnode/vnode/CMakeLists.txt | 1 + source/dnode/vnode/src/inc/tsdb.h | 14 +++ source/dnode/vnode/src/tsdb/tsdbCommit2.c | 104 ++++++++++++++++++++ source/dnode/vnode/src/tsdb/tsdbMemTable2.c | 24 ++--- 4 files changed, 129 insertions(+), 14 deletions(-) create mode 100644 source/dnode/vnode/src/tsdb/tsdbCommit2.c diff --git a/source/dnode/vnode/CMakeLists.txt b/source/dnode/vnode/CMakeLists.txt index f3aefdba02..05b4a270d6 100644 --- a/source/dnode/vnode/CMakeLists.txt +++ b/source/dnode/vnode/CMakeLists.txt @@ -36,6 +36,7 @@ target_sources( # tsdb "src/tsdb/tsdbCommit.c" + "src/tsdb/tsdbCommit2.c" "src/tsdb/tsdbFile.c" "src/tsdb/tsdbFS.c" "src/tsdb/tsdbOpen.c" diff --git a/source/dnode/vnode/src/inc/tsdb.h b/source/dnode/vnode/src/inc/tsdb.h index ab23b7506e..c9b8a26735 100644 --- a/source/dnode/vnode/src/inc/tsdb.h +++ b/source/dnode/vnode/src/inc/tsdb.h @@ -46,6 +46,10 @@ void tsdbMemTableDestroy2(SMemTable *pMemTable); int32_t tsdbInsertTableData2(STsdb *pTsdb, int64_t version, SVSubmitBlk *pSubmitBlk); int32_t tsdbDeleteTableData2(STsdb *pTsdb, int64_t version, tb_uid_t suid, tb_uid_t uid, TSKEY sKey, TSKEY eKey); +// tsdbCommit2.c ============================================================================================== +int32_t tsdbBegin2(STsdb *pTsdb); +int32_t tsdbCommit2(STsdb *pTsdb); + // tsdbMemTable ================ typedef struct STsdbRow STsdbRow; typedef struct STbData STbData; @@ -877,6 +881,16 @@ struct SDelOp { SDelOp *pNext; }; +struct SMemTable { + STsdb *pTsdb; + int32_t nRef; + TSDBKEY minKey; + TSDBKEY maxKey; + int64_t nRows; + SArray *aSkmInfo; + SArray *aMemData; +}; + static FORCE_INLINE int tsdbKeyCmprFn(const void *p1, const void *p2) { TSDBKEY *pKey1 = (TSDBKEY *)p1; TSDBKEY *pKey2 = (TSDBKEY *)p2; diff --git a/source/dnode/vnode/src/tsdb/tsdbCommit2.c b/source/dnode/vnode/src/tsdb/tsdbCommit2.c new file mode 100644 index 0000000000..3e87e4be43 --- /dev/null +++ b/source/dnode/vnode/src/tsdb/tsdbCommit2.c @@ -0,0 +1,104 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#include "tsdb.h" + +typedef struct { + SMemTable *pMemTable; + SArray *aBlkIdx; +} SCommitH; + +static int32_t tsdbStartCommit(SCommitH *pCHandle, STsdb *pTsdb); +static int32_t tsdbEndCommit(SCommitH *pCHandle); +static int32_t tsdbCommitToFile(SCommitH *pCHandle, int32_t fid); + +int32_t tsdbBegin2(STsdb *pTsdb) { + int32_t code = 0; + + ASSERT(pTsdb->mem == NULL); + code = tsdbMemTableCreate2(pTsdb, (SMemTable **)&pTsdb->mem); + if (code) { + tsdbError("vgId:%d failed to begin TSDB since %s", TD_VID(pTsdb->pVnode), tstrerror(code)); + goto _exit; + } + +_exit: + return code; +} + +int32_t tsdbCommit2(STsdb *pTsdb) { + int32_t code = 0; + SCommitH ch = {0}; + + // start to commit + code = tsdbStartCommit(&ch, pTsdb); + if (code) { + goto _exit; + } + + // commit + int32_t sfid; // todo + int32_t efid; // todo + for (int32_t fid = sfid; fid <= efid; fid++) { + code = tsdbCommitToFile(&ch, fid); + if (code) { + goto _err; + } + } + + // end commit + code = tsdbEndCommit(&ch); + if (code) { + goto _exit; + } + +_exit: + return code; + +_err: + // TODO: rollback + return code; +} + +static int32_t tsdbStartCommit(SCommitH *pCHandle, STsdb *pTsdb) { + int32_t code = 0; + + ASSERT(pTsdb->imem == NULL && pTsdb->mem); + pTsdb->imem = pTsdb->mem; + pTsdb->mem = NULL; + + return code; +} + +static int32_t tsdbEndCommit(SCommitH *pCHandle) { + int32_t code = 0; + // TODO + return code; +} + +static int32_t tsdbCommitToFile(SCommitH *pCHandle, int32_t fid) { + int32_t code = 0; + TSKEY fidSKey; + TSKEY fidEKey; + + // check if there are data in the time range + for (int32_t iMemData = 0; iMemData < taosArrayGetSize(pCHandle->pMemTable->aMemData); iMemData++) { + /* code */ + } + + // has data, do commit to file + + 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 b6d0747fe3..23f779ec88 100644 --- a/source/dnode/vnode/src/tsdb/tsdbMemTable2.c +++ b/source/dnode/vnode/src/tsdb/tsdbMemTable2.c @@ -43,14 +43,10 @@ struct SMemData { SMemSkipList sl; }; -struct SMemTable { - STsdb *pTsdb; - int32_t nRef; - TSDBKEY minKey; - TSDBKEY maxKey; - int64_t nRows; - SArray *pArray; // SArray -}; +typedef struct { + tb_uid_t uid; + STSchema *pTSchema; +} SSkmInfo; #define SL_MAX_LEVEL 5 @@ -85,8 +81,8 @@ int32_t tsdbMemTableCreate2(STsdb *pTsdb, SMemTable **ppMemTable) { pMemTable->minKey = (TSDBKEY){.version = INT64_MAX, .ts = TSKEY_MAX}; pMemTable->maxKey = (TSDBKEY){.version = -1, .ts = TSKEY_MIN}; pMemTable->nRows = 0; - pMemTable->pArray = taosArrayInit(512, sizeof(SMemData *)); - if (pMemTable->pArray == NULL) { + pMemTable->aMemData = taosArrayInit(512, sizeof(SMemData *)); + if (pMemTable->aMemData == NULL) { taosMemoryFree(pMemTable); code = TSDB_CODE_OUT_OF_MEMORY; goto _err; @@ -101,7 +97,7 @@ _err: } void tsdbMemTableDestroy2(SMemTable *pMemTable) { - taosArrayDestroyEx(pMemTable->pArray, NULL /*TODO*/); + taosArrayDestroyEx(pMemTable->aMemData, NULL /*TODO*/); taosMemoryFree(pMemTable); } @@ -196,9 +192,9 @@ static int32_t tsdbGetOrCreateMemData(SMemTable *pMemTable, tb_uid_t suid, tb_ui int8_t maxLevel = pMemTable->pTsdb->pVnode->config.tsdbCfg.slLevel; // get - idx = taosArraySearchIdx(pMemTable->pArray, &pMemDataT, memDataPCmprFn, TD_GE); + idx = taosArraySearchIdx(pMemTable->aMemData, &pMemDataT, memDataPCmprFn, TD_GE); if (idx >= 0) { - pMemData = (SMemData *)taosArrayGet(pMemTable->pArray, idx); + pMemData = (SMemData *)taosArrayGet(pMemTable->aMemData, idx); if (memDataPCmprFn(&pMemDataT, &pMemData) == 0) goto _exit; } @@ -230,7 +226,7 @@ static int32_t tsdbGetOrCreateMemData(SMemTable *pMemTable, tb_uid_t suid, tb_ui } if (idx < 0) idx = 0; - if (taosArrayInsert(pMemTable->pArray, idx, &pMemData) == NULL) { + if (taosArrayInsert(pMemTable->aMemData, idx, &pMemData) == NULL) { code = TSDB_CODE_OUT_OF_MEMORY; goto _err; } -- GitLab