diff --git a/source/libs/tdb/src/db/tdb_mpool.c b/source/libs/tdb/src/db/tdb_mpool.c index 9b67f405a92781b709cd237335a85120cf8b0b78..1b591a5c3fd84d7fab30bdd5b335a04fc99c2db2 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 0000000000000000000000000000000000000000..9a5df604c464f2decfd264e7cc8dc0393bd18153 --- /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 0000000000000000000000000000000000000000..a593c3b4e8d37623a10943c9fecf8086c58fd4d2 --- /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 885191477cfd3e760959a4f81d1dce7f5ba4475e..9e13f779e721af1ea65f99200a8a64f835310068 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 0000000000000000000000000000000000000000..42981a5e8b90d6b68a51a4fd1879e3b655f85fc1 --- /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