diff --git a/source/libs/tdb/inc/tdb.h b/source/libs/tdb/inc/tdb.h index 136617322df742fca64dd2bcb4215e94b626b341..7784282a24e01c75f08f19478afa9abb97024e49 100644 --- a/source/libs/tdb/inc/tdb.h +++ b/source/libs/tdb/inc/tdb.h @@ -29,8 +29,7 @@ typedef struct STDbEnv TENV; // TDB int tdbCreate(TDB **ppDb); -int tdbDestroy(TDB *pDb); -int tdbOpen(TDB **pDb, const char *fname, const char *dbname); +int tdbOpen(TDB **ppDb, const char *fname, const char *dbname, TENV *pEnv); int tdbClose(TDB *pDb); #ifdef __cplusplus diff --git a/source/libs/tdb/src/db/tdb.c b/source/libs/tdb/src/db/tdb.c index 11f86dd17fb896d78d0296ec9b808a2e51899f22..b5b248eac3eca18cda749b487317090525523fa1 100644 --- a/source/libs/tdb/src/db/tdb.c +++ b/source/libs/tdb/src/db/tdb.c @@ -34,20 +34,39 @@ int tdbCreate(TDB **ppDb) { return 0; } -int tdbDestroy(TDB *pDb) { +static int tdbDestroy(TDB *pDb) { if (pDb) { free(pDb); } - /* TODO */ return 0; } -int tdbOpen(TDB **pDb, const char *fname, const char *dbname) { - // TODO +int tdbOpen(TDB **ppDb, const char *fname, const char *dbname, TENV *pEnv) { + TDB *pDb; + int ret; + + // Create DB if DB handle is not created yet + if (ppDb == NULL) { + if ((ret = tdbCreate(ppDb)) != 0) { + return -1; + } + } + + pDb = *ppDb; + + // Create a default ENV if pEnv is not set + if (pEnv == NULL) { + // if ((ret = tenvOpen(&pEnv)) != 0) { + // return -1; + // } + } + + /* TODO */ + return 0; } int tdbClose(TDB *pDb) { - // TODO - return 0; + if (pDb == NULL) return 0; + return tdbDestroy(pDb); } \ No newline at end of file diff --git a/source/libs/tdb/src/db/tdbEnv.c b/source/libs/tdb/src/db/tdbEnv.c index 7de52f36593e9a9a67d9e39eb7c1dcada5f1506d..c738b691c8e297f6d1d513d3a5fc6700b4564734 100644 --- a/source/libs/tdb/src/db/tdbEnv.c +++ b/source/libs/tdb/src/db/tdbEnv.c @@ -18,5 +18,7 @@ struct STDbEnv { TDB * dbList; // TDB list SPgFile *pgFileList; // SPgFile list - SPgCache pgc; // page cache + struct { + } pgfht; // page file hash table; + SPgCache pgc; // page cache }; \ No newline at end of file diff --git a/source/libs/tdb/src/inc/tdbInt.h b/source/libs/tdb/src/inc/tdbInt.h index cbab052049f8eb5151999803d4bffdb757fff112..c368b68465b28e5976229c007376dbcaf09c6239 100644 --- a/source/libs/tdb/src/inc/tdbInt.h +++ b/source/libs/tdb/src/inc/tdbInt.h @@ -80,9 +80,7 @@ typedef int32_t pgsize_t; #include "pgcache.h" #include "pgfile.h" #include "tdbEnv.h" - -// tdb util -int tdbGnrtFileID(const char *fname, uint8_t *fileid); +#include "tdbUtil.h" #ifdef __cplusplus } diff --git a/source/libs/tdb/src/inc/tdbUtil.h b/source/libs/tdb/src/inc/tdbUtil.h new file mode 100644 index 0000000000000000000000000000000000000000..eacd9e4a53e13433b634523659b70730fcecab9a --- /dev/null +++ b/source/libs/tdb/src/inc/tdbUtil.h @@ -0,0 +1,29 @@ +/* + * 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_UTIL_H_ +#define _TDB_UTIL_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +int tdbGnrtFileID(const char *fname, uint8_t *fileid); + +#ifdef __cplusplus +} +#endif + +#endif /*_TDB_UTIL_H_*/ \ No newline at end of file