From 0230a529f74d9dfefe12de2229fcb6f00922e523 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Thu, 20 Jan 2022 05:12:50 +0000 Subject: [PATCH] refact tdb --- source/libs/tdb/src/db/tdb_mpfile.c | 14 ------ source/libs/tdb/src/db/tdb_mpool.c | 2 +- source/libs/tdb/src/inc/tdb_inc.h | 6 +-- source/libs/tdb/src/inc/tdb_mpfile.h | 46 ------------------- .../tdb/src/inc/{tdb_mp.h => tdb_mpool.h} | 22 +++++++-- 5 files changed, 22 insertions(+), 68 deletions(-) delete mode 100644 source/libs/tdb/src/db/tdb_mpfile.c delete mode 100644 source/libs/tdb/src/inc/tdb_mpfile.h rename source/libs/tdb/src/inc/{tdb_mp.h => tdb_mpool.h} (72%) diff --git a/source/libs/tdb/src/db/tdb_mpfile.c b/source/libs/tdb/src/db/tdb_mpfile.c deleted file mode 100644 index 6dea4a4e57..0000000000 --- a/source/libs/tdb/src/db/tdb_mpfile.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 diff --git a/source/libs/tdb/src/db/tdb_mpool.c b/source/libs/tdb/src/db/tdb_mpool.c index f9a939b5e9..d61c0de2c3 100644 --- a/source/libs/tdb/src/db/tdb_mpool.c +++ b/source/libs/tdb/src/db/tdb_mpool.c @@ -13,7 +13,7 @@ * along with this program. If not, see . */ -#include "tdb_mp.h" +#include "tdb_mpool.h" int tdbOpenMP(TDB_MPOOL **mpp, uint64_t cachesize, pgsize_t pgsize) { TDB_MPOOL *mp; diff --git a/source/libs/tdb/src/inc/tdb_inc.h b/source/libs/tdb/src/inc/tdb_inc.h index 2eed9a8dc7..3e16036722 100644 --- a/source/libs/tdb/src/inc/tdb_inc.h +++ b/source/libs/tdb/src/inc/tdb_inc.h @@ -23,9 +23,9 @@ extern "C" { #endif -// pgid_t -typedef int32_t pgid_t; -#define TDB_IVLD_PGID ((pgid_t)-1) +// pgno_t +typedef int32_t pgno_t; +#define TDB_IVLD_PGID ((pgno_t)-1) // framd_id_t typedef int32_t frame_id_t; diff --git a/source/libs/tdb/src/inc/tdb_mpfile.h b/source/libs/tdb/src/inc/tdb_mpfile.h deleted file mode 100644 index cd4823081a..0000000000 --- a/source/libs/tdb/src/inc/tdb_mpfile.h +++ /dev/null @@ -1,46 +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_MPFILE_H_ -#define _TD_TDB_MPFILE_H_ - -#include "tdb_mpool.h" - -#ifdef __cplusplus -extern "C" { -#endif - -// Exposed handle -typedef struct TDB_MPFILE TDB_MPFILE; - -// Exposed apis -int tdbMPFOpen(TDB_MPFILE **mpfp, const char *fname, TDB_MPOOL *mp); -int tdbMPFClose(TDB_MPFILE *mpf); -int tdbMPFGet(TDB_MPFILE *mpf, pgid_t pgid, void *addr); -int tdbMPFPut(TDB_MPOOL *mpf, pgid_t pgid, void *addr); - -// Hidden structures -struct TDB_MPFILE { - uint8_t fuid[20]; // file unique ID - TDB_MPOOL *mp; // underlying memory pool - char * fname; // file name - int fd; // fd -}; - -#ifdef __cplusplus -} -#endif - -#endif /*_TD_TDB_MPFILE_H_*/ \ No newline at end of file diff --git a/source/libs/tdb/src/inc/tdb_mp.h b/source/libs/tdb/src/inc/tdb_mpool.h similarity index 72% rename from source/libs/tdb/src/inc/tdb_mp.h rename to source/libs/tdb/src/inc/tdb_mpool.h index 4a53c7b8d7..d84c2ffaeb 100644 --- a/source/libs/tdb/src/inc/tdb_mp.h +++ b/source/libs/tdb/src/inc/tdb_mpool.h @@ -23,11 +23,12 @@ extern "C" { #endif // Exposed handle -typedef struct TDB_MPOOL TDB_MPOOL; +typedef struct TDB_MPOOL TDB_MPOOL; +typedef struct TDB_MPFILE TDB_MPFILE; typedef struct { uint8_t fuid[TDB_FILE_UID_LEN]; - pgid_t pgid; + pgno_t pgid; } mp_pgid_t; typedef struct MP_PAGE { @@ -55,15 +56,28 @@ struct TDB_MPOOL { // TODO: TD_DLIST(TD_MPFILE) mpfList; // MPFILE registered on this memory pool }; -#define MP_PAGE_AT(mp, idx) ((char *)((mp)->pages) + MP_PAGE_SIZE((mp)->pgsize) * (idx)) +struct TDB_MPFILE { + uint8_t fuid[20]; // file unique ID + TDB_MPOOL *mp; // underlying memory pool + char * fname; // file name + int fd; // fd +}; -// Exposed apis ===================================================================================================== +#define MP_PAGE_AT(mp, idx) ((char *)((mp)->pages) + MP_PAGE_SIZE((mp)->pgsize) * (idx)) +/*=================================================== Exposed apis ==================================================*/ +// TDB_MPOOL int tdbOpenMP(TDB_MPOOL **mpp, uint64_t cachesize, pgsize_t pgsize); int tdbCloseMP(TDB_MPOOL *mp); int tdbMPFetchPage(TDB_MPOOL *mp, mp_pgid_t mpgid, void *p); int tdbMpUnfetchPage(TDB_MPOOL *mp, mp_pgid_t mpgid, void *p); +// TDB_MPFILE +int tdbMPFOpen(TDB_MPFILE **mpfp, const char *fname, TDB_MPOOL *mp); +int tdbMPFClose(TDB_MPFILE *mpf); +int tdbMPFGet(TDB_MPFILE *mpf, pgno_t pgid, void *addr); +int tdbMPFPut(TDB_MPOOL *mpf, pgno_t pgid, void *addr); + #ifdef __cplusplus } #endif -- GitLab