diff --git a/source/dnode/vnode/src/meta/metaTDBImpl.c b/source/dnode/vnode/src/meta/metaTDBImpl.c index 3a5b55925b87a6217ba47fde7229ecf60793d1d1..4a65cf277b9dd11aeb9a0ee47cea6e19f314d10c 100644 --- a/source/dnode/vnode/src/meta/metaTDBImpl.c +++ b/source/dnode/vnode/src/meta/metaTDBImpl.c @@ -54,6 +54,11 @@ int metaOpenDB(SMeta *pMeta) { // Create and open the ENV A((tdbEnvCreate(&pEnv)), _err); +#if 0 + // Set options of the environment + A(tdbEnvSetPageSize(pEnv, 8192), _err); + A(tdbEnvSetCacheSize(pEnv, 16 * 1024 * 1024), _err); +#endif A((tdbEnvOpen(&pEnv)), _err); // Create and open each DB diff --git a/source/libs/tdb/inc/tdb.h b/source/libs/tdb/inc/tdb.h index 5bbaf2ac88eec561b3066eb8e2ac8f628f7e9cd6..9a168c53117f93ff38e9cd6add5b076d4d0ce884 100644 --- a/source/libs/tdb/inc/tdb.h +++ b/source/libs/tdb/inc/tdb.h @@ -26,11 +26,19 @@ typedef struct STDb TDB; typedef struct STDbEnv TENV; typedef struct STDbCurosr TDBC; +typedef int32_t pgsize_t; +typedef int32_t cachesz_t; + // TEVN int tdbEnvCreate(TENV **ppEnv); int tdbEnvOpen(TENV **ppEnv); int tdbEnvClose(TENV *pEnv); +int tdbEnvSetPageSize(TENV *pEnv, pgsize_t szPage); +int tdbEnvSetCacheSize(TENV *pEnv, cachesz_t szCache); +pgsize_t tdbEnvGetPageSize(TENV *pEnv); +cachesz_t tdbEnvGetCacheSize(TENV *pEnv); + // TDB int tdbCreate(TDB **ppDb); int tdbOpen(TDB **ppDb, const char *fname, const char *dbname, TENV *pEnv); diff --git a/source/libs/tdb/src/db/pgfile.c b/source/libs/tdb/src/db/pgfile.c index 1c3e2700b4b6ca109fbff588753f199e63bf3c6a..7f0ab55b000eb7f4f072300e44a6f11987b8ad43 100644 --- a/source/libs/tdb/src/db/pgfile.c +++ b/source/libs/tdb/src/db/pgfile.c @@ -44,7 +44,7 @@ int pgFileOpen(SPgFile **ppPgFile, const char *fname, SPgCache *pPgCache) { return -1; } - if (tdbGnrtFileID(fname, pPgFile->fileid) < 0) { + if (tdbGnrtFileID(fname, pPgFile->fileid, false) < 0) { pgFileClose(pPgFile); return -1; } diff --git a/source/libs/tdb/src/db/tdb.c b/source/libs/tdb/src/db/tdb.c index ffaef0addd5f625e50f2d6ae92d8ffb31d0b4614..bd8d7ec1f76b743767d16bc5ea8a058b33e24e3d 100644 --- a/source/libs/tdb/src/db/tdb.c +++ b/source/libs/tdb/src/db/tdb.c @@ -70,7 +70,12 @@ int tdbOpen(TDB **ppDb, const char *fname, const char *dbname, TENV *pEnv) { ASSERT(fname != NULL); - // Check if file exists (TODO) + // Check if file exists + if (tdbCheckFileAccess(fname, TDB_F_OK) != 0) { + if (1) { + // create the file + } + } // Check if the SPgFile already opened pPgFile = tdbEnvGetPageFile(pEnv, fileid); diff --git a/source/libs/tdb/src/db/tdbEnv.c b/source/libs/tdb/src/db/tdbEnv.c index 3d7e98f477387d09d35f3e7260659a1f2f4d629d..fe9238e1eb850621d21a5f1e33a7a7dd7e794926 100644 --- a/source/libs/tdb/src/db/tdbEnv.c +++ b/source/libs/tdb/src/db/tdbEnv.c @@ -57,6 +57,8 @@ int tdbEnvOpen(TENV **ppEnv) { pEnv = *ppEnv; TERR_A(ret, pgCacheCreate(&pPgCache, pEnv->pgSize, pEnv->cacheSize / pEnv->pgSize), _err); + TERR_A(ret, pgCacheOpen(&pPgCache), _err); + pEnv->pPgCache = pPgCache; return 0; @@ -72,6 +74,22 @@ int tdbEnvClose(TENV *pEnv) { return 0; } +int tdbEnvSetPageSize(TENV *pEnv, pgsize_t szPage) { + /* TODO */ + pEnv->pgSize = szPage; + return 0; +} + +int tdbEnvSetCacheSize(TENV *pEnv, cachesz_t szCache) { + /* TODO */ + pEnv->cacheSize = szCache; + return 0; +} + +pgsize_t tdbEnvGetPageSize(TENV *pEnv) { return pEnv->pgSize; } + +cachesz_t tdbEnvGetCacheSize(TENV *pEnv) { return pEnv->cacheSize; } + SPgFile *tdbEnvGetPageFile(TENV *pEnv, const uint8_t fileid[]) { // TODO return NULL; diff --git a/source/libs/tdb/src/db/tdbUtil.c b/source/libs/tdb/src/db/tdbUtil.c index 6391397efd08db111c95b4dad3c2dfb33d983a31..856a54a2da3bf76ecc7d3056fed6a3f72c3b1de3 100644 --- a/source/libs/tdb/src/db/tdbUtil.c +++ b/source/libs/tdb/src/db/tdbUtil.c @@ -15,7 +15,7 @@ #include "tdbInt.h" -int tdbGnrtFileID(const char *fname, uint8_t *fileid) { +int tdbGnrtFileID(const char *fname, uint8_t *fileid, bool unique) { struct stat statbuf; if (stat(fname, &statbuf) < 0) { @@ -26,8 +26,27 @@ int tdbGnrtFileID(const char *fname, uint8_t *fileid) { ((uint64_t *)fileid)[0] = (uint64_t)statbuf.st_ino; ((uint64_t *)fileid)[1] = (uint64_t)statbuf.st_dev; - ((uint64_t *)fileid)[2] = rand(); + if (unique) { + ((uint64_t *)fileid)[2] = rand(); + } return 0; } +int tdbCheckFileAccess(const char *pathname, int mode) { + int flags = 0; + + if (mode & TDB_F_OK) { + flags |= F_OK; + } + + if (mode & TDB_R_OK) { + flags |= R_OK; + } + + if (mode & TDB_W_OK) { + flags |= W_OK; + } + + return access(pathname, flags); +} \ 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 1b591a5c3fd84d7fab30bdd5b335a04fc99c2db2..cc7927d51b0256de3f0edb6ccc0e401647d75f14 100644 --- a/source/libs/tdb/src/db/tdb_mpool.c +++ b/source/libs/tdb/src/db/tdb_mpool.c @@ -119,7 +119,7 @@ int tdbMPoolFileOpen(TDB_MPFILE **mpfp, const char *fname, TDB_MPOOL *mp) { goto _err; } - if (tdbGnrtFileID(fname, mpf->fileid) < 0) { + if (tdbGnrtFileID(fname, mpf->fileid, false) < 0) { goto _err; } diff --git a/source/libs/tdb/src/inc/tdbInt.h b/source/libs/tdb/src/inc/tdbInt.h index 1500fee6dc44a63f58fb4f3bf11ae745fe0bdb67..74fed019e7dda0c42c15a8a05d8c4ee08d3387cf 100644 --- a/source/libs/tdb/src/inc/tdbInt.h +++ b/source/libs/tdb/src/inc/tdbInt.h @@ -16,7 +16,6 @@ #ifndef _TD_TDB_INTERNAL_H_ #define _TD_TDB_INTERNAL_H_ -#include "os.h" #include "tlist.h" #include "tlockfree.h" @@ -64,14 +63,12 @@ static FORCE_INLINE int tdbCmprPgId(const void *p1, const void *p2) { typedef int32_t frame_id_t; // pgsize_t -typedef int32_t pgsize_t; #define TDB_MIN_PGSIZE 512 #define TDB_MAX_PGSIZE 16384 #define TDB_DEFAULT_PGSIZE 4096 #define TDB_IS_PGSIZE_VLD(s) (((s) >= TDB_MIN_PGSIZE) && ((s) <= TDB_MAX_PGSIZE)) // cache -typedef int32_t cachesz_t; #define TDB_DEFAULT_CACHE_SIZE (256 * 1024) // 256K // tdb_log diff --git a/source/libs/tdb/src/inc/tdbUtil.h b/source/libs/tdb/src/inc/tdbUtil.h index 6ffb9dd3d4f362bfb870d5a3af1d2faa0000dbd1..8e1fe013e8110512bce570bc25916b5b277280b2 100644 --- a/source/libs/tdb/src/inc/tdbUtil.h +++ b/source/libs/tdb/src/inc/tdbUtil.h @@ -22,7 +22,12 @@ extern "C" { #define TDB_ROUND8(x) (((x) + 7) & ~7) -int tdbGnrtFileID(const char *fname, uint8_t *fileid); +int tdbGnrtFileID(const char *fname, uint8_t *fileid, bool unique); + +#define TDB_F_OK 0x1 +#define TDB_R_OK 0x2 +#define TDB_W_OK 0x4 +int tdbCheckFileAccess(const char *pathname, int mode); #ifdef __cplusplus }