From 065f3d96820fcdb3301aab6bed14a91416a3ed14 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Mon, 24 Jan 2022 13:27:32 +0000 Subject: [PATCH] more tdb --- source/libs/tdb/src/db/tdb_mpool.c | 17 ------------- source/libs/tdb/src/db/tdb_util.c | 33 +++++++++++++++++++++++++ source/libs/tdb/src/inc/tdb_btree.h | 33 +++++++++++++++++++++++++ source/libs/tdb/src/inc/tdb_inc.h | 3 +++ source/libs/tdb/src/inc/tdb_page.h | 37 +++++++++++++++++++++++++++++ 5 files changed, 106 insertions(+), 17 deletions(-) create mode 100644 source/libs/tdb/src/db/tdb_util.c create mode 100644 source/libs/tdb/src/inc/tdb_btree.h create mode 100644 source/libs/tdb/src/inc/tdb_page.h diff --git a/source/libs/tdb/src/db/tdb_mpool.c b/source/libs/tdb/src/db/tdb_mpool.c index 9b67f405a9..1b591a5c3f 100644 --- a/source/libs/tdb/src/db/tdb_mpool.c +++ b/source/libs/tdb/src/db/tdb_mpool.c @@ -15,7 +15,6 @@ #include "tdb_mpool.h" -static int tdbGnrtFileID(const char *fname, uint8_t *fileid); static void tdbMPoolRegFile(TDB_MPOOL *mp, TDB_MPFILE *mpf); static void tdbMPoolUnregFile(TDB_MPOOL *mp, TDB_MPFILE *mpf); static TDB_MPFILE *tdbMPoolGetFile(TDB_MPOOL *mp, uint8_t *fileid); @@ -230,22 +229,6 @@ int tdbMPoolFilePutPage(TDB_MPFILE *mpf, pgno_t pgno, void *addr) { return 0; } -static int tdbGnrtFileID(const char *fname, uint8_t *fileid) { - struct stat statbuf; - - if (stat(fname, &statbuf) < 0) { - return -1; - } - - memset(fileid, 0, TDB_FILE_ID_LEN); - - ((uint64_t *)fileid)[0] = (uint64_t)statbuf.st_ino; - ((uint64_t *)fileid)[1] = (uint64_t)statbuf.st_dev; - ((uint64_t *)fileid)[2] = rand(); - - return 0; -} - #define MPF_GET_BUCKETID(fileid) \ ({ \ uint64_t *tmp = (uint64_t *)fileid; \ diff --git a/source/libs/tdb/src/db/tdb_util.c b/source/libs/tdb/src/db/tdb_util.c new file mode 100644 index 0000000000..9a5df604c4 --- /dev/null +++ b/source/libs/tdb/src/db/tdb_util.c @@ -0,0 +1,33 @@ +/* + * 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 "tdb_inc.h" + +int tdbGnrtFileID(const char *fname, uint8_t *fileid) { + struct stat statbuf; + + if (stat(fname, &statbuf) < 0) { + return -1; + } + + memset(fileid, 0, TDB_FILE_ID_LEN); + + ((uint64_t *)fileid)[0] = (uint64_t)statbuf.st_ino; + ((uint64_t *)fileid)[1] = (uint64_t)statbuf.st_dev; + ((uint64_t *)fileid)[2] = rand(); + + return 0; +} + diff --git a/source/libs/tdb/src/inc/tdb_btree.h b/source/libs/tdb/src/inc/tdb_btree.h new file mode 100644 index 0000000000..a593c3b4e8 --- /dev/null +++ b/source/libs/tdb/src/inc/tdb_btree.h @@ -0,0 +1,33 @@ +/* + * 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 _TDB_BTREE_H_ +#define _TDB_BTREE_H_ + +#include "tdb_inc.h" + +#ifdef __cplusplus +extern "C" { +#endif + +struct SBTree { + pgno_t root; // root page number +}; + +#ifdef __cplusplus +} +#endif + +#endif /*_TDB_BTREE_H_*/ \ No newline at end of file diff --git a/source/libs/tdb/src/inc/tdb_inc.h b/source/libs/tdb/src/inc/tdb_inc.h index 885191477c..9e13f779e7 100644 --- a/source/libs/tdb/src/inc/tdb_inc.h +++ b/source/libs/tdb/src/inc/tdb_inc.h @@ -51,6 +51,9 @@ typedef int32_t pgsize_t; // tdb_log #define tdbError(var) +// tdb util +int tdbGnrtFileID(const char *fname, uint8_t *fileid); + #ifdef __cplusplus } #endif diff --git a/source/libs/tdb/src/inc/tdb_page.h b/source/libs/tdb/src/inc/tdb_page.h new file mode 100644 index 0000000000..42981a5e8b --- /dev/null +++ b/source/libs/tdb/src/inc/tdb_page.h @@ -0,0 +1,37 @@ +/* + * 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 _TDB_PAGE_H_ +#define _TDB_PAGE_H_ + +#include "tdb_inc.h" + +#ifdef __cplusplus +extern "C" { +#endif + +// Page header +typedef struct { + uint32_t magic; + pgno_t pgno; // current page number + pgno_t npgno; // next page number + pgno_t ppgno; // prev page number +} SPgHdr; + +#ifdef __cplusplus +} +#endif + +#endif /*_TDB_PAGE_H_*/ \ No newline at end of file