From c9118a52e6776db03c854afadc9d4c77f0c9fa82 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Thu, 13 Jan 2022 06:13:10 +0000 Subject: [PATCH 1/3] more tkv and refact --- source/dnode/mgmt/impl/src/dndEnv.c | 2 +- source/dnode/vnode/inc/vnode.h | 18 ---------------- source/libs/tdb/inc/tdb.h | 15 +++++++++++-- source/libs/tdb/src/inc/tdbDB.h | 11 +++------- source/libs/tdb/src/inc/tdbEnv.h | 31 --------------------------- source/libs/tdb/test/tDiskMgrTest.cpp | 10 --------- source/libs/tdb/test/tdbTest.cpp | 5 +++++ source/libs/tdb/test/tkvTests.cpp | 0 8 files changed, 22 insertions(+), 70 deletions(-) delete mode 100644 source/libs/tdb/src/inc/tdbEnv.h delete mode 100644 source/libs/tdb/test/tDiskMgrTest.cpp create mode 100644 source/libs/tdb/test/tdbTest.cpp delete mode 100644 source/libs/tdb/test/tkvTests.cpp diff --git a/source/dnode/mgmt/impl/src/dndEnv.c b/source/dnode/mgmt/impl/src/dndEnv.c index 1bf1ea2b92..23fc643abe 100644 --- a/source/dnode/mgmt/impl/src/dndEnv.c +++ b/source/dnode/mgmt/impl/src/dndEnv.c @@ -293,7 +293,7 @@ int32_t dndInit(const SDnodeEnvCfg *pCfg) { if (vnodeInit(&vnodeOpt) != 0) { dError("failed to init vnode since %s", terrstr()); dndCleanup(); - return NULL; + return -1; } memcpy(&dndEnv.cfg, pCfg, sizeof(SDnodeEnvCfg)); diff --git a/source/dnode/vnode/inc/vnode.h b/source/dnode/vnode/inc/vnode.h index 6113d0a536..7ff02309ec 100644 --- a/source/dnode/vnode/inc/vnode.h +++ b/source/dnode/vnode/inc/vnode.h @@ -37,36 +37,18 @@ typedef int32_t (*PutReqToVQueryQFp)(SDnode *pDnode, struct SRpcMsg *pReq); typedef struct SVnodeCfg { int32_t vgId; SDnode *pDnode; - - /** vnode buffer pool options */ struct { - /** write buffer size */ uint64_t wsize; uint64_t ssize; uint64_t lsize; - /** use heap allocator or arena allocator */ bool isHeapAllocator; }; - - /** time to live of tables in this vnode */ uint32_t ttl; - - /** data to keep in this vnode */ uint32_t keep; - - /** if TS data is eventually consistency */ bool isWeak; - - /** TSDB config */ STsdbCfg tsdbCfg; - - /** META config */ SMetaCfg metaCfg; - - /** TQ config */ STqCfg tqCfg; - - /** WAL config */ SWalCfg walCfg; } SVnodeCfg; diff --git a/source/libs/tdb/inc/tdb.h b/source/libs/tdb/inc/tdb.h index 2f47f545b1..40d79de821 100644 --- a/source/libs/tdb/inc/tdb.h +++ b/source/libs/tdb/inc/tdb.h @@ -22,9 +22,15 @@ extern "C" { #endif +typedef enum { + TDB_BTREE = 0, + TDB_HASH, + TDB_HEAP, +} tdb_db_t; + // Forward declaration -typedef struct TDB TDB; -typedef struct TDB_ENV TDB_ENV; +typedef struct TDB TDB; +typedef struct TDB_CURSOR TDB_CURSOR; // SKey typedef struct { @@ -32,6 +38,11 @@ typedef struct { uint32_t size; } TDB_KEY, TDB_VALUE; +// TDB Operations +int tdbCreateDB(TDB** dbpp); +int tdbOpenDB(TDB* dbp, tdb_db_t type, uint32_t flags); +int tdbCloseDB(TDB* dbp, uint32_t flags); + #ifdef __cplusplus } #endif diff --git a/source/libs/tdb/src/inc/tdbDB.h b/source/libs/tdb/src/inc/tdbDB.h index 40ddb1eb31..479ef77711 100644 --- a/source/libs/tdb/src/inc/tdbDB.h +++ b/source/libs/tdb/src/inc/tdbDB.h @@ -23,19 +23,14 @@ extern "C" { #endif -typedef enum { - TDB_BTREE = 0, - TDB_HASH, - TDB_HEAP, -} tdb_db_t; struct TDB { pgsize_t pageSize; tdb_db_t type; union { - STkvBtree btree; - STkvhash hash; - } dbimpl; + TDB_BTREE btree; + TDB_HASH hash; + } dbam; // Different access methods }; #ifdef __cplusplus diff --git a/source/libs/tdb/src/inc/tdbEnv.h b/source/libs/tdb/src/inc/tdbEnv.h deleted file mode 100644 index f3e4ef5888..0000000000 --- a/source/libs/tdb/src/inc/tdbEnv.h +++ /dev/null @@ -1,31 +0,0 @@ -/* - * 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 . - */ - -#ifndef _TD_TDB_ENV_H_ -#define _TD_TDB_ENV_H_ - -#ifdef __cplusplus -extern "C" { -#endif - -struct TDB_ENV { - char *homeDir; -}; - -#ifdef __cplusplus -} -#endif - -#endif /*_TD_TDB_ENV_H_*/ \ No newline at end of file diff --git a/source/libs/tdb/test/tDiskMgrTest.cpp b/source/libs/tdb/test/tDiskMgrTest.cpp deleted file mode 100644 index a735fdb33d..0000000000 --- a/source/libs/tdb/test/tDiskMgrTest.cpp +++ /dev/null @@ -1,10 +0,0 @@ -#include "gtest/gtest.h" - -#include "iostream" - -#include "tDiskMgr.h" - -TEST(tDiskMgrTest, simple_test) { - // TODO - std::cout << "This is in tDiskMgrTest::simple_test" << std::endl; -} \ No newline at end of file diff --git a/source/libs/tdb/test/tdbTest.cpp b/source/libs/tdb/test/tdbTest.cpp new file mode 100644 index 0000000000..ee91c7669b --- /dev/null +++ b/source/libs/tdb/test/tdbTest.cpp @@ -0,0 +1,5 @@ +#include "gtest/gtest.h" + +TEST(tdb_api_test, tdb_create_open_close_db_test) { + +} \ No newline at end of file diff --git a/source/libs/tdb/test/tkvTests.cpp b/source/libs/tdb/test/tkvTests.cpp deleted file mode 100644 index e69de29bb2..0000000000 From ac87dcf9661c1b2c2793add1219a15dbec2b8ffa Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Thu, 13 Jan 2022 08:04:43 +0000 Subject: [PATCH 2/3] more --- source/libs/tdb/CMakeLists.txt | 6 +++++- source/libs/tdb/test/CMakeLists.txt | 0 source/libs/tdb/test/tdbTest.cpp | 11 ++++++++++- 3 files changed, 15 insertions(+), 2 deletions(-) create mode 100644 source/libs/tdb/test/CMakeLists.txt diff --git a/source/libs/tdb/CMakeLists.txt b/source/libs/tdb/CMakeLists.txt index 1832ea0b5d..68aa40c072 100644 --- a/source/libs/tdb/CMakeLists.txt +++ b/source/libs/tdb/CMakeLists.txt @@ -14,4 +14,8 @@ target_link_libraries( tdb PUBLIC os PUBLIC util -) \ No newline at end of file +) + +if(${BUILD_TEST}) + add_subdirectory(test) +endif(${BUILD_TEST}) diff --git a/source/libs/tdb/test/CMakeLists.txt b/source/libs/tdb/test/CMakeLists.txt new file mode 100644 index 0000000000..e69de29bb2 diff --git a/source/libs/tdb/test/tdbTest.cpp b/source/libs/tdb/test/tdbTest.cpp index ee91c7669b..3ff43fdd69 100644 --- a/source/libs/tdb/test/tdbTest.cpp +++ b/source/libs/tdb/test/tdbTest.cpp @@ -1,5 +1,14 @@ #include "gtest/gtest.h" -TEST(tdb_api_test, tdb_create_open_close_db_test) { +#include "tdb.h" +TEST(tdb_api_test, tdb_create_open_close_db_test) { + int ret; + TDB *dbp; + + tdbCreateDB(&dbp); + + tdbOpenDB(dbp, TDB_BTREE, 0); + + tdbCloseDB(dbp, 0); } \ No newline at end of file From a20724f46eda6f4dcb9bfeedf5e9c8c93a2370fc Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Thu, 13 Jan 2022 08:15:28 +0000 Subject: [PATCH 3/3] more --- source/dnode/vnode/src/vnd/vnodeWrite.c | 1 + source/libs/tdb/CMakeLists.txt | 2 +- source/libs/tdb/test/CMakeLists.txt | 3 +++ 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/source/dnode/vnode/src/vnd/vnodeWrite.c b/source/dnode/vnode/src/vnd/vnodeWrite.c index 185487757f..01619b5c77 100644 --- a/source/dnode/vnode/src/vnd/vnodeWrite.c +++ b/source/dnode/vnode/src/vnd/vnodeWrite.c @@ -83,6 +83,7 @@ int vnodeApplyWMsg(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) { if (metaCreateTable(pVnode->pMeta, pCreateTbReq) < 0) { // TODO: handle error } + vTrace("vgId:%d process create table %s", pVnode->vgId, pCreateTbReq->name); if (pCreateTbReq->type == TD_SUPER_TABLE) { free(pCreateTbReq->stbCfg.pSchema); free(pCreateTbReq->stbCfg.pTagSchema); diff --git a/source/libs/tdb/CMakeLists.txt b/source/libs/tdb/CMakeLists.txt index 68aa40c072..647771fd2d 100644 --- a/source/libs/tdb/CMakeLists.txt +++ b/source/libs/tdb/CMakeLists.txt @@ -17,5 +17,5 @@ target_link_libraries( ) if(${BUILD_TEST}) - add_subdirectory(test) + # add_subdirectory(test) endif(${BUILD_TEST}) diff --git a/source/libs/tdb/test/CMakeLists.txt b/source/libs/tdb/test/CMakeLists.txt index e69de29bb2..2d77c1f4e9 100644 --- a/source/libs/tdb/test/CMakeLists.txt +++ b/source/libs/tdb/test/CMakeLists.txt @@ -0,0 +1,3 @@ +# tdbTest +add_executable(tdbTest "tdbTest.cpp") +target_link_libraries(tdbTest tdb gtest gtest_main) \ No newline at end of file