From fd94249ffdb649800e114d6ce216e34c9a91155d Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Mon, 7 Feb 2022 02:55:26 +0000 Subject: [PATCH] refact --- source/libs/tdb/src/db/btree.c | 4 +- source/libs/tdb/src/db/pgcache.c | 16 ++++++ source/libs/tdb/src/db/pgfile.c | 4 +- source/libs/tdb/src/db/tdb.c | 94 ++++++++++++++++---------------- source/libs/tdb/src/inc/btree.h | 2 + source/libs/tdb/src/inc/pgfile.h | 9 +++ source/libs/tdb/src/inc/tdbInt.h | 4 ++ source/libs/tdb/src/inc/tdb_db.h | 45 --------------- 8 files changed, 84 insertions(+), 94 deletions(-) delete mode 100644 source/libs/tdb/src/inc/tdb_db.h diff --git a/source/libs/tdb/src/db/btree.c b/source/libs/tdb/src/db/btree.c index 6dea4a4e57..2ce1e62c16 100644 --- a/source/libs/tdb/src/db/btree.c +++ b/source/libs/tdb/src/db/btree.c @@ -11,4 +11,6 @@ * * 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 + */ + +#include "tdbInt.h" \ No newline at end of file diff --git a/source/libs/tdb/src/db/pgcache.c b/source/libs/tdb/src/db/pgcache.c index e69de29bb2..2ce1e62c16 100644 --- a/source/libs/tdb/src/db/pgcache.c +++ b/source/libs/tdb/src/db/pgcache.c @@ -0,0 +1,16 @@ +/* + * 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 "tdbInt.h" \ No newline at end of file diff --git a/source/libs/tdb/src/db/pgfile.c b/source/libs/tdb/src/db/pgfile.c index 6dea4a4e57..2ce1e62c16 100644 --- a/source/libs/tdb/src/db/pgfile.c +++ b/source/libs/tdb/src/db/pgfile.c @@ -11,4 +11,6 @@ * * 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 + */ + +#include "tdbInt.h" \ No newline at end of file diff --git a/source/libs/tdb/src/db/tdb.c b/source/libs/tdb/src/db/tdb.c index 112fade741..0a24331a36 100644 --- a/source/libs/tdb/src/db/tdb.c +++ b/source/libs/tdb/src/db/tdb.c @@ -13,61 +13,61 @@ * along with this program. If not, see . */ -#include "tdb_db.h" +#include "tdbInt.h" -static int tdbOpenImpl(TDB *dbp); +// static int tdbOpenImpl(TDB *dbp); -int tdbOpen(TDB **dbpp, const char *fname, const char *dbname, uint32_t flags) { - TDB * dbp; - TDB_MPFILE *mpf; - uint8_t fileid[TDB_FILE_ID_LEN]; +// int tdbOpen(TDB **dbpp, const char *fname, const char *dbname, uint32_t flags) { +// TDB * dbp; +// TDB_MPFILE *mpf; +// uint8_t fileid[TDB_FILE_ID_LEN]; - if ((dbp = (TDB *)calloc(1, sizeof(*dbp))) == NULL) { - return -1; - } +// if ((dbp = (TDB *)calloc(1, sizeof(*dbp))) == NULL) { +// return -1; +// } - if ((dbp->fname = strdup(fname)) == NULL) { - free(dbp); - return -1; - } +// if ((dbp->fname = strdup(fname)) == NULL) { +// free(dbp); +// return -1; +// } - if ((dbname) && ((dbp->dbname = strdup(dbname)) == NULL)) { - free(dbp->fname); - free(dbp); - return -1; - } +// if ((dbname) && ((dbp->dbname = strdup(dbname)) == NULL)) { +// free(dbp->fname); +// free(dbp); +// return -1; +// } - // if (tdbGnrtFileID(fname, fileid) < 0) { - // // todo - // return -1; - // } +// // if (tdbGnrtFileID(fname, fileid) < 0) { +// // // todo +// // return -1; +// // } - // TODO: mpf = tdbGetMPFileByID(fileid); - if (mpf == NULL) { - // todoerr: maybe we need to create one - return -1; - } +// // TODO: mpf = tdbGetMPFileByID(fileid); +// if (mpf == NULL) { +// // todoerr: maybe we need to create one +// return -1; +// } - if (tdbOpenImpl(dbp) < 0) { - // todoerr - return -1; - } +// if (tdbOpenImpl(dbp) < 0) { +// // todoerr +// return -1; +// } - *dbpp = dbp; - return 0; -} +// *dbpp = dbp; +// return 0; +// } -int tdbClose(TDB *dbp, uint32_t flags) { - // TODO - return 0; -} +// int tdbClose(TDB *dbp, uint32_t flags) { +// // TODO +// return 0; +// } -static int tdbOpenImpl(TDB *dbp) { - if (dbp->dbname == NULL) { - // todo: open the DB as a master DB - } else { - // todo: open the DB as a sub-db - } - // TODO - return 0; -} \ No newline at end of file +// static int tdbOpenImpl(TDB *dbp) { +// if (dbp->dbname == NULL) { +// // todo: open the DB as a master DB +// } else { +// // todo: open the DB as a sub-db +// } +// // TODO +// return 0; +// } \ No newline at end of file diff --git a/source/libs/tdb/src/inc/btree.h b/source/libs/tdb/src/inc/btree.h index 7b1b6cd2ef..01658d5e00 100644 --- a/source/libs/tdb/src/inc/btree.h +++ b/source/libs/tdb/src/inc/btree.h @@ -16,6 +16,8 @@ #ifndef _TD_BTREE_H_ #define _TD_BTREE_H_ +#include "tdbInt.h" + #ifdef __cplusplus extern "C" { #endif diff --git a/source/libs/tdb/src/inc/pgfile.h b/source/libs/tdb/src/inc/pgfile.h index f9a7435b3d..9c502fed9e 100644 --- a/source/libs/tdb/src/inc/pgfile.h +++ b/source/libs/tdb/src/inc/pgfile.h @@ -16,12 +16,21 @@ #ifndef _TD_PAGE_FILE_H_ #define _TD_PAGE_FILE_H_ +#include "tdbInt.h" + +#include "pgcache.h" + #ifdef __cplusplus extern "C" { #endif typedef struct SPgFile SPgFile; +struct SPgFile { + char * fname; // backend file name + SPgCache *pPgCache; // page cache underline +}; + #ifdef __cplusplus } #endif diff --git a/source/libs/tdb/src/inc/tdbInt.h b/source/libs/tdb/src/inc/tdbInt.h index c2ca7b0cfb..3746c5f077 100644 --- a/source/libs/tdb/src/inc/tdbInt.h +++ b/source/libs/tdb/src/inc/tdbInt.h @@ -20,6 +20,8 @@ #include "tlist.h" #include "tlockfree.h" +#include "tdb.h" + #ifdef __cplusplus extern "C" { #endif @@ -51,6 +53,8 @@ typedef int32_t pgsize_t; // tdb_log #define tdbError(var) +#include "pgcache.h" + // tdb util int tdbGnrtFileID(const char *fname, uint8_t *fileid); diff --git a/source/libs/tdb/src/inc/tdb_db.h b/source/libs/tdb/src/inc/tdb_db.h deleted file mode 100644 index 5f0529462b..0000000000 --- a/source/libs/tdb/src/inc/tdb_db.h +++ /dev/null @@ -1,45 +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_DB_H_ -#define _TD_TDB_DB_H_ - -#include "tdb_mpool.h" - -#ifdef __cplusplus -extern "C" { -#endif - -typedef struct TDB TDB; - -struct TDB { - char * fname; - char * dbname; - TDB_MPFILE *mpf; - // union { - // TDB_BTREE *btree; - // TDB_HASH * hash; - // TDB_HEAP * heap; - // } dbam; // db access method -}; - -int tdbOpen(TDB **dbpp, const char *fname, const char *dbname, uint32_t flags); -int tdbClose(TDB *dbp, uint32_t flags); - -#ifdef __cplusplus -} -#endif - -#endif /*_TD_TDB_DB_H_*/ \ No newline at end of file -- GitLab