From 1e84bce89fac773651535066a54239a56572e4ab Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Tue, 18 Jan 2022 07:53:02 +0000 Subject: [PATCH] more tkv --- source/libs/tdb/inc/tdb.h | 14 +++++ source/libs/tdb/src/inc/tdbDB.h | 4 -- source/libs/tdb/src/inc/tdbDef.h | 1 + .../src/inc/{tdbBufPool.h => tdb_mpfile.h} | 22 ++++---- source/libs/tdb/src/inc/tdb_mpool.h | 35 ++++++++++++ source/libs/tdb/src/mpool/tdbBufPool.c | 54 ------------------- source/libs/tdb/src/mpool/tdb_mpool.c | 14 +++++ 7 files changed, 74 insertions(+), 70 deletions(-) rename source/libs/tdb/src/inc/{tdbBufPool.h => tdb_mpfile.h} (57%) create mode 100644 source/libs/tdb/src/inc/tdb_mpool.h delete mode 100644 source/libs/tdb/src/mpool/tdbBufPool.c create mode 100644 source/libs/tdb/src/mpool/tdb_mpool.c diff --git a/source/libs/tdb/inc/tdb.h b/source/libs/tdb/inc/tdb.h index 02b4422882..3a1523e6c6 100644 --- a/source/libs/tdb/inc/tdb.h +++ b/source/libs/tdb/inc/tdb.h @@ -30,6 +30,8 @@ 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; typedef struct { @@ -44,6 +46,18 @@ 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); +int tdbCloseMPool(TDB_MPOOL* mp); + +// TDB_MPFILE +int tdbOpenMPFile(TDB_MPFILE** mpf, TDB_MPOOL* mp); +int tdbCloseMPFile(TDB_MPFILE** mpf); + +// TDB_CURSOR +int tdbOpenCursor(TDB* dbp, TDB_CURSOR** tdbcpp); +int tdbCloseCurosr(TDB_CURSOR* tdbcp); + #ifdef __cplusplus } #endif diff --git a/source/libs/tdb/src/inc/tdbDB.h b/source/libs/tdb/src/inc/tdbDB.h index d0ef9e22d0..261fb587b4 100644 --- a/source/libs/tdb/src/inc/tdbDB.h +++ b/source/libs/tdb/src/inc/tdbDB.h @@ -25,10 +25,6 @@ extern "C" { #endif -typedef struct { - // TODO -} TDB_MPOOL; - typedef struct { int fd; } TDB_FH; diff --git a/source/libs/tdb/src/inc/tdbDef.h b/source/libs/tdb/src/inc/tdbDef.h index 4b5e54368b..48a6831f86 100644 --- a/source/libs/tdb/src/inc/tdbDef.h +++ b/source/libs/tdb/src/inc/tdbDef.h @@ -17,6 +17,7 @@ #define _TD_TDB_DEF_H_ #include "os.h" +#include "tlist.h" #ifdef __cplusplus extern "C" { diff --git a/source/libs/tdb/src/inc/tdbBufPool.h b/source/libs/tdb/src/inc/tdb_mpfile.h similarity index 57% rename from source/libs/tdb/src/inc/tdbBufPool.h rename to source/libs/tdb/src/inc/tdb_mpfile.h index 5200d22faa..8eaafafd41 100644 --- a/source/libs/tdb/src/inc/tdbBufPool.h +++ b/source/libs/tdb/src/inc/tdb_mpfile.h @@ -13,27 +13,25 @@ * along with this program. If not, see . */ -#ifndef _TD_TDB_BUF_POOL_H_ -#define _TD_TDB_BUF_POOL_H_ +#ifndef _TD_TDB_MPFILE_H_ +#define _TD_TDB_MPFILE_H_ -#include "tdbPage.h" +#include "tdbDef.h" +#include "tdb_mpool.h" #ifdef __cplusplus extern "C" { #endif -typedef struct STdbBufPool STdbBufPool; +struct TDB_MPFILE { + TDB_MPOOL *mp; // memory pool used to get/put pages in this file -int tbpOpen(STdbBufPool **ppTkvBufPool); -int tbpClose(STdbBufPool *pTkvBufPool); -STdbPage *tbpNewPage(STdbBufPool *pTkvBufPool); -int tbpDelPage(STdbBufPool *pTkvBufPool); -STdbPage *tbpFetchPage(STdbBufPool *pTkvBufPool, pgid_t pgid); -int tbpUnpinPage(STdbBufPool *pTkvBufPool, pgid_t pgid); -void tbpFlushPages(STdbBufPool *pTkvBufPool); + char *fname; + int fd; +}; #ifdef __cplusplus } #endif -#endif /*_TD_TDB_BUF_POOL_H_*/ \ No newline at end of file +#endif /*_TD_TDB_MPFILE_H_*/ \ No newline at end of file diff --git a/source/libs/tdb/src/inc/tdb_mpool.h b/source/libs/tdb/src/inc/tdb_mpool.h new file mode 100644 index 0000000000..9e34362c40 --- /dev/null +++ b/source/libs/tdb/src/inc/tdb_mpool.h @@ -0,0 +1,35 @@ +/* + * 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_MPOOL_H_ +#define _TD_TDB_MPOOL_H_ + +#include "tdbDef.h" + +#ifdef __cplusplus +extern "C" { +#endif + +struct TDB_MPOOL { + pthread_mutex_t mutex; + int64_t cachesize; + pgsize_t pgsize; +}; + +#ifdef __cplusplus +} +#endif + +#endif /*_TD_TDB_MPOOL_H_*/ \ No newline at end of file diff --git a/source/libs/tdb/src/mpool/tdbBufPool.c b/source/libs/tdb/src/mpool/tdbBufPool.c deleted file mode 100644 index bc3c386b0f..0000000000 --- a/source/libs/tdb/src/mpool/tdbBufPool.c +++ /dev/null @@ -1,54 +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 "thash.h" -#include "tlist.h" - -#include "tdbBufPool.h" -#include "tdbDiskMgr.h" -#include "tdbPage.h" - -struct SFrameIdWrapper { - TD_SLIST_NODE(SFrameIdWrapper); - frame_id_t id; -}; - -struct STdbBufPool { - STdbPage* pages; - STkvDiskMgr* pDiskMgr; - SHashObj* pgTb; // page_id_t --> frame_id_t - TD_SLIST(SFrameIdWrapper) freeList; - pthread_mutex_t mutex; -}; - -typedef struct STkvLRUReplacer { -} STkvLRUReplacer; - -typedef struct STkvLFUReplacer { -} STkvLFUReplacer; - -typedef struct STkvCLKReplacer { -} STkvCLKReplacer; - -typedef enum { TKV_LRU_REPLACER = 0, TKV_LFU_REPLACER, TVK_CLK_REPLACER } tkv_replacer_t; - -typedef struct STkvReplacer { - tkv_replacer_t type; - union { - STkvLRUReplacer lruRep; - STkvLFUReplacer lfuRep; - STkvCLKReplacer clkRep; - }; -} STkvReplacer; \ No newline at end of file diff --git a/source/libs/tdb/src/mpool/tdb_mpool.c b/source/libs/tdb/src/mpool/tdb_mpool.c new file mode 100644 index 0000000000..6dea4a4e57 --- /dev/null +++ b/source/libs/tdb/src/mpool/tdb_mpool.c @@ -0,0 +1,14 @@ +/* + * 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