From 1793f616cafa5b8e28931df2b86626d4f15e7cd7 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Wed, 19 Jan 2022 08:31:35 +0000 Subject: [PATCH] refact --- source/libs/tdb/CMakeLists.txt | 4 +- source/libs/tdb/inc/tdb.h | 38 +++++----- source/libs/tdb/src/db/tdbDB.c | 4 +- source/libs/tdb/src/devinc/tdb_inc.h | 27 ------- source/libs/tdb/src/dmgr/tdbDiskMgr.c | 74 ------------------- source/libs/tdb/src/inc/tdbBtree.h | 35 --------- source/libs/tdb/src/inc/tdbDB.h | 12 ++- source/libs/tdb/src/inc/tdbDiskMgr.h | 40 ---------- source/libs/tdb/src/inc/tdbHash.h | 35 --------- source/libs/tdb/src/inc/tdbHeap.h | 35 --------- source/libs/tdb/src/inc/tdbPage.h | 43 ----------- .../libs/tdb/src/inc/{tdbDef.h => tdb_inc.h} | 7 +- .../libs/tdb/src/{devinc => inc}/tdb_mpfile.h | 0 .../libs/tdb/src/{devinc => inc}/tdb_mpool.h | 2 +- source/libs/tdb/src/mpool/tdb_mpool.c | 14 ---- 15 files changed, 33 insertions(+), 337 deletions(-) delete mode 100644 source/libs/tdb/src/devinc/tdb_inc.h delete mode 100644 source/libs/tdb/src/dmgr/tdbDiskMgr.c delete mode 100644 source/libs/tdb/src/inc/tdbBtree.h delete mode 100644 source/libs/tdb/src/inc/tdbDiskMgr.h delete mode 100644 source/libs/tdb/src/inc/tdbHash.h delete mode 100644 source/libs/tdb/src/inc/tdbHeap.h delete mode 100644 source/libs/tdb/src/inc/tdbPage.h rename source/libs/tdb/src/inc/{tdbDef.h => tdb_inc.h} (92%) rename source/libs/tdb/src/{devinc => inc}/tdb_mpfile.h (100%) rename source/libs/tdb/src/{devinc => inc}/tdb_mpool.h (97%) delete mode 100644 source/libs/tdb/src/mpool/tdb_mpool.c diff --git a/source/libs/tdb/CMakeLists.txt b/source/libs/tdb/CMakeLists.txt index eb63f2b144..bb8904117c 100644 --- a/source/libs/tdb/CMakeLists.txt +++ b/source/libs/tdb/CMakeLists.txt @@ -1,5 +1,5 @@ -set(TDB_SUBDIRS "btree" "db" "hash" "mpool" "dmgr") +set(TDB_SUBDIRS "db") foreach(TDB_SUBDIR ${TDB_SUBDIRS}) aux_source_directory("src/${TDB_SUBDIR}" TDB_SRC) endforeach() @@ -18,5 +18,5 @@ target_link_libraries( ) if(${BUILD_TEST}) - add_subdirectory(test) + # add_subdirectory(test) endif(${BUILD_TEST}) diff --git a/source/libs/tdb/inc/tdb.h b/source/libs/tdb/inc/tdb.h index 5264707eb8..faf9208f8f 100644 --- a/source/libs/tdb/inc/tdb.h +++ b/source/libs/tdb/inc/tdb.h @@ -22,29 +22,29 @@ extern "C" { #endif -#define TDB_EXTERN -#define TDB_PUBLIC -#define TDB_STATIC static +// #define TDB_EXTERN +// #define TDB_PUBLIC +// #define TDB_STATIC static -typedef enum { TDB_BTREE_T = 0, TDB_HASH_T = 1, TDB_HEAP_T = 2 } tdb_db_t; +// typedef enum { TDB_BTREE_T = 0, TDB_HASH_T = 1, TDB_HEAP_T = 2 } tdb_db_t; -// Forward declarations -typedef struct TDB TDB; -// typedef struct TDB_MPOOL TDB_MPOOL; -// typedef struct TDB_MPFILE TDB_MPFILE; -// typedef struct TDB_CURSOR TDB_CURSOR; +// // Forward declarations +// typedef struct TDB TDB; +// // typedef struct TDB_MPOOL TDB_MPOOL; +// // typedef struct TDB_MPFILE TDB_MPFILE; +// // typedef struct TDB_CURSOR TDB_CURSOR; -typedef struct { - void* bdata; - uint32_t size; -} TDB_KEY, TDB_VALUE; +// typedef struct { +// void* bdata; +// uint32_t size; +// } TDB_KEY, TDB_VALUE; -// TDB Operations -int tdbCreateDB(TDB** dbpp, tdb_db_t type); -int tdbOpenDB(TDB* dbp, const char* fname, const char* dbname, uint32_t flags); -int tdbCloseDB(TDB* dbp, uint32_t flags); -int tdbPut(TDB* dbp, const TDB_KEY* key, const TDB_VALUE* value, uint32_t flags); -int tdbGet(TDB* dbp, const TDB_KEY* key, TDB_VALUE* value, uint32_t flags); +// // TDB Operations +// int tdbCreateDB(TDB** dbpp, tdb_db_t type); +// int tdbOpenDB(TDB* dbp, const char* fname, const char* dbname, uint32_t flags); +// int tdbCloseDB(TDB* dbp, uint32_t flags); +// int tdbPut(TDB* dbp, const TDB_KEY* key, const TDB_VALUE* value, uint32_t flags); +// int tdbGet(TDB* dbp, const TDB_KEY* key, TDB_VALUE* value, uint32_t flags); // // TDB_MPOOL // int tdbOpenMPool(TDB_MPOOL** mp); diff --git a/source/libs/tdb/src/db/tdbDB.c b/source/libs/tdb/src/db/tdbDB.c index eaf85ea4a1..9fac9887d0 100644 --- a/source/libs/tdb/src/db/tdbDB.c +++ b/source/libs/tdb/src/db/tdbDB.c @@ -13,6 +13,7 @@ * along with this program. If not, see . */ +#if 0 #include "tdbDB.h" #include "tdb.h" @@ -83,4 +84,5 @@ TDB_EXTERN int tdbOpenDB(TDB* dbp, const char* fname, const char* dbname, uint32 TDB_EXTERN int tdbCloseDB(TDB* dbp, uint32_t flags) { // TODO return 0; -} \ No newline at end of file +} +#endif \ No newline at end of file diff --git a/source/libs/tdb/src/devinc/tdb_inc.h b/source/libs/tdb/src/devinc/tdb_inc.h deleted file mode 100644 index c05247c44a..0000000000 --- a/source/libs/tdb/src/devinc/tdb_inc.h +++ /dev/null @@ -1,27 +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_INC_H_ -#define _TD_TDB_INC_H_ - -#ifdef __cplusplus -extern "C" { -#endif - -#ifdef __cplusplus -} -#endif - -#endif /*_TD_TDB_INC_H_*/ diff --git a/source/libs/tdb/src/dmgr/tdbDiskMgr.c b/source/libs/tdb/src/dmgr/tdbDiskMgr.c deleted file mode 100644 index 71ab5f2589..0000000000 --- a/source/libs/tdb/src/dmgr/tdbDiskMgr.c +++ /dev/null @@ -1,74 +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 . - */ - -#include "tdbDiskMgr.h" - -struct STkvDiskMgr { - char * fname; - uint16_t pgsize; - FileFd fd; - pgid_t npgid; -}; - -#define PAGE_OFFSET(PGID, PGSIZE) ((PGID) * (PGSIZE)) - -int tdmOpen(STkvDiskMgr **ppDiskMgr, const char *fname, uint16_t pgsize) { - STkvDiskMgr *pDiskMgr; - - pDiskMgr = malloc(sizeof(*pDiskMgr)); - if (pDiskMgr == NULL) { - return -1; - } - - pDiskMgr->fname = strdup(fname); - if (pDiskMgr->fname == NULL) { - free(pDiskMgr); - return -1; - } - pDiskMgr->pgsize = pgsize; - pDiskMgr->fd = open(fname, O_CREAT | O_RDWR, 0755); - if (pDiskMgr->fd < 0) { - free(pDiskMgr->fname); - free(pDiskMgr); - return -1; - } - - *ppDiskMgr = pDiskMgr; - - return 0; -} - -int tdmClose(STkvDiskMgr *pDiskMgr) { - close(pDiskMgr->fd); - free(pDiskMgr->fname); - free(pDiskMgr); - return 0; -} - -int tdmReadPage(STkvDiskMgr *pDiskMgr, pgid_t pgid, void *pData) { - taosLSeekFile(pDiskMgr->fd, PAGE_OFFSET(pgid, pDiskMgr->pgsize), SEEK_SET); - taosReadFile(pDiskMgr->fd, pData, pDiskMgr->pgsize); - return 0; -} - -int tdmWritePage(STkvDiskMgr *pDiskMgr, pgid_t pgid, const void *pData) { - taosLSeekFile(pDiskMgr->fd, PAGE_OFFSET(pgid, pDiskMgr->pgsize), SEEK_SET); - taosWriteFile(pDiskMgr->fd, pData, pDiskMgr->pgsize); - return 0; -} - -int tdmFlush(STkvDiskMgr *pDiskMgr) { return taosFsyncFile(pDiskMgr->fd); } - -int32_t tdmAllocPage(STkvDiskMgr *pDiskMgr) { return pDiskMgr->npgid++; } \ No newline at end of file diff --git a/source/libs/tdb/src/inc/tdbBtree.h b/source/libs/tdb/src/inc/tdbBtree.h deleted file mode 100644 index 28258b8e60..0000000000 --- a/source/libs/tdb/src/inc/tdbBtree.h +++ /dev/null @@ -1,35 +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_BTREE_H_ -#define _TD_TDB_BTREE_H_ - -#include "tdbDef.h" - -#ifdef __cplusplus -extern "C" { -#endif - -typedef struct { - pgid_t root; // root page number -} TDB_BTREE; - -TDB_PUBLIC int tdbInitBtreeDB(TDB *dbp); - -#ifdef __cplusplus -} -#endif - -#endif /*_TD_TDB_BTREE_H_*/ \ No newline at end of file diff --git a/source/libs/tdb/src/inc/tdbDB.h b/source/libs/tdb/src/inc/tdbDB.h index c246c18775..7607580d3e 100644 --- a/source/libs/tdb/src/inc/tdbDB.h +++ b/source/libs/tdb/src/inc/tdbDB.h @@ -18,8 +18,6 @@ #include "tdb.h" #include "tdbBtree.h" -#include "tdbHash.h" -#include "tdbHeap.h" #ifdef __cplusplus extern "C" { @@ -34,11 +32,11 @@ struct TDB { tdb_db_t type; char * fname; char * dbname; - union { - TDB_BTREE *btree; - TDB_HASH * hash; - TDB_HEAP * heap; - } dbam; // db access method + // union { + // TDB_BTREE *btree; + // TDB_HASH * hash; + // TDB_HEAP * heap; + // } dbam; // db access method // TDB_FH * fhp; // The backup file handle // TDB_MPOOL *mph; // The memory pool handle diff --git a/source/libs/tdb/src/inc/tdbDiskMgr.h b/source/libs/tdb/src/inc/tdbDiskMgr.h deleted file mode 100644 index b83a147437..0000000000 --- a/source/libs/tdb/src/inc/tdbDiskMgr.h +++ /dev/null @@ -1,40 +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_TDISK_MGR_H_ -#define _TD_TDISK_MGR_H_ - -#ifdef __cplusplus -extern "C" { -#endif - -#include "os.h" - -#include "tdbDef.h" - -typedef struct STkvDiskMgr STkvDiskMgr; - -int tdmOpen(STkvDiskMgr **ppDiskMgr, const char *fname, uint16_t pgsize); -int tdmClose(STkvDiskMgr *pDiskMgr); -int tdmReadPage(STkvDiskMgr *pDiskMgr, pgid_t pgid, void *pData); -int tdmWritePage(STkvDiskMgr *pDiskMgr, pgid_t pgid, const void *pData); -int tdmFlush(STkvDiskMgr *pDiskMgr); -pgid_t tdmAllocPage(STkvDiskMgr *pDiskMgr); - -#ifdef __cplusplus -} -#endif - -#endif /*_TD_TDISK_MGR_H_*/ \ No newline at end of file diff --git a/source/libs/tdb/src/inc/tdbHash.h b/source/libs/tdb/src/inc/tdbHash.h deleted file mode 100644 index 8219bda2f8..0000000000 --- a/source/libs/tdb/src/inc/tdbHash.h +++ /dev/null @@ -1,35 +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_HASH_H_ -#define _TD_TDB_HASH_H_ - -#include "tdbDef.h" - -#ifdef __cplusplus -extern "C" { -#endif - -typedef struct { - // TODO -} TDB_HASH; - -TDB_PUBLIC int tdbInitHashDB(TDB *dbp); - -#ifdef __cplusplus -} -#endif - -#endif /*_TD_TDB_HASH_H_*/ \ No newline at end of file diff --git a/source/libs/tdb/src/inc/tdbHeap.h b/source/libs/tdb/src/inc/tdbHeap.h deleted file mode 100644 index 25a812fa5f..0000000000 --- a/source/libs/tdb/src/inc/tdbHeap.h +++ /dev/null @@ -1,35 +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_HEAP_H_ -#define _TD_TDB_HEAP_H_ - -#include "tdbDef.h" - -#ifdef __cplusplus -extern "C" { -#endif - -typedef struct { - // TODO -} TDB_HEAP; - -TDB_PUBLIC int tdbInitHeapDB(TDB *dbp); - -#ifdef __cplusplus -} -#endif - -#endif /*_TD_TDB_HEAP_H_*/ \ No newline at end of file diff --git a/source/libs/tdb/src/inc/tdbPage.h b/source/libs/tdb/src/inc/tdbPage.h deleted file mode 100644 index e7245b6c39..0000000000 --- a/source/libs/tdb/src/inc/tdbPage.h +++ /dev/null @@ -1,43 +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_TKV_PAGE_H_ -#define _TD_TKV_PAGE_H_ - -#include "os.h" -#include "tdbDef.h" - -#ifdef __cplusplus -extern "C" { -#endif - -typedef struct { - pgid_t pgid; - int32_t pinCount; - bool idDirty; - char* pData; -} STdbPage; - -typedef struct { - uint16_t dbver; - uint16_t pgsize; - uint32_t cksm; -} STdbPgHdr; - -#ifdef __cplusplus -} -#endif - -#endif /*_TD_TKV_PAGE_H_*/ \ No newline at end of file diff --git a/source/libs/tdb/src/inc/tdbDef.h b/source/libs/tdb/src/inc/tdb_inc.h similarity index 92% rename from source/libs/tdb/src/inc/tdbDef.h rename to source/libs/tdb/src/inc/tdb_inc.h index 48a6831f86..1e9c3dd8cc 100644 --- a/source/libs/tdb/src/inc/tdbDef.h +++ b/source/libs/tdb/src/inc/tdb_inc.h @@ -13,11 +13,10 @@ * along with this program. If not, see . */ -#ifndef _TD_TDB_DEF_H_ -#define _TD_TDB_DEF_H_ +#ifndef _TD_TDB_INC_H_ +#define _TD_TDB_INC_H_ #include "os.h" -#include "tlist.h" #ifdef __cplusplus extern "C" { @@ -41,4 +40,4 @@ typedef int32_t pgsize_t; } #endif -#endif /*_TD_TDB_DEF_H_*/ \ No newline at end of file +#endif /*_TD_TDB_INC_H_*/ diff --git a/source/libs/tdb/src/devinc/tdb_mpfile.h b/source/libs/tdb/src/inc/tdb_mpfile.h similarity index 100% rename from source/libs/tdb/src/devinc/tdb_mpfile.h rename to source/libs/tdb/src/inc/tdb_mpfile.h diff --git a/source/libs/tdb/src/devinc/tdb_mpool.h b/source/libs/tdb/src/inc/tdb_mpool.h similarity index 97% rename from source/libs/tdb/src/devinc/tdb_mpool.h rename to source/libs/tdb/src/inc/tdb_mpool.h index 4acf8bef8c..1023b14a50 100644 --- a/source/libs/tdb/src/devinc/tdb_mpool.h +++ b/source/libs/tdb/src/inc/tdb_mpool.h @@ -16,7 +16,7 @@ #ifndef _TD_TDB_MPOOL_H_ #define _TD_TDB_MPOOL_H_ -#include "tdbDef.h" +#include "tdb_inc.h" #ifdef __cplusplus extern "C" { diff --git a/source/libs/tdb/src/mpool/tdb_mpool.c b/source/libs/tdb/src/mpool/tdb_mpool.c deleted file mode 100644 index 6dea4a4e57..0000000000 --- a/source/libs/tdb/src/mpool/tdb_mpool.c +++ /dev/null @@ -1,14 +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 . - */ \ No newline at end of file -- GitLab