提交 2849a62c 编写于 作者: H Hongze Cheng

more TDB

上级 a8bcf128
...@@ -54,6 +54,11 @@ int metaOpenDB(SMeta *pMeta) { ...@@ -54,6 +54,11 @@ int metaOpenDB(SMeta *pMeta) {
// Create and open the ENV // Create and open the ENV
A((tdbEnvCreate(&pEnv)), _err); 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); A((tdbEnvOpen(&pEnv)), _err);
// Create and open each DB // Create and open each DB
......
...@@ -26,11 +26,19 @@ typedef struct STDb TDB; ...@@ -26,11 +26,19 @@ typedef struct STDb TDB;
typedef struct STDbEnv TENV; typedef struct STDbEnv TENV;
typedef struct STDbCurosr TDBC; typedef struct STDbCurosr TDBC;
typedef int32_t pgsize_t;
typedef int32_t cachesz_t;
// TEVN // TEVN
int tdbEnvCreate(TENV **ppEnv); int tdbEnvCreate(TENV **ppEnv);
int tdbEnvOpen(TENV **ppEnv); int tdbEnvOpen(TENV **ppEnv);
int tdbEnvClose(TENV *pEnv); 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 // TDB
int tdbCreate(TDB **ppDb); int tdbCreate(TDB **ppDb);
int tdbOpen(TDB **ppDb, const char *fname, const char *dbname, TENV *pEnv); int tdbOpen(TDB **ppDb, const char *fname, const char *dbname, TENV *pEnv);
......
...@@ -44,7 +44,7 @@ int pgFileOpen(SPgFile **ppPgFile, const char *fname, SPgCache *pPgCache) { ...@@ -44,7 +44,7 @@ int pgFileOpen(SPgFile **ppPgFile, const char *fname, SPgCache *pPgCache) {
return -1; return -1;
} }
if (tdbGnrtFileID(fname, pPgFile->fileid) < 0) { if (tdbGnrtFileID(fname, pPgFile->fileid, false) < 0) {
pgFileClose(pPgFile); pgFileClose(pPgFile);
return -1; return -1;
} }
......
...@@ -70,7 +70,12 @@ int tdbOpen(TDB **ppDb, const char *fname, const char *dbname, TENV *pEnv) { ...@@ -70,7 +70,12 @@ int tdbOpen(TDB **ppDb, const char *fname, const char *dbname, TENV *pEnv) {
ASSERT(fname != NULL); 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 // Check if the SPgFile already opened
pPgFile = tdbEnvGetPageFile(pEnv, fileid); pPgFile = tdbEnvGetPageFile(pEnv, fileid);
......
...@@ -57,6 +57,8 @@ int tdbEnvOpen(TENV **ppEnv) { ...@@ -57,6 +57,8 @@ int tdbEnvOpen(TENV **ppEnv) {
pEnv = *ppEnv; pEnv = *ppEnv;
TERR_A(ret, pgCacheCreate(&pPgCache, pEnv->pgSize, pEnv->cacheSize / pEnv->pgSize), _err); TERR_A(ret, pgCacheCreate(&pPgCache, pEnv->pgSize, pEnv->cacheSize / pEnv->pgSize), _err);
TERR_A(ret, pgCacheOpen(&pPgCache), _err);
pEnv->pPgCache = pPgCache; pEnv->pPgCache = pPgCache;
return 0; return 0;
...@@ -72,6 +74,22 @@ int tdbEnvClose(TENV *pEnv) { ...@@ -72,6 +74,22 @@ int tdbEnvClose(TENV *pEnv) {
return 0; 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[]) { SPgFile *tdbEnvGetPageFile(TENV *pEnv, const uint8_t fileid[]) {
// TODO // TODO
return NULL; return NULL;
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
#include "tdbInt.h" #include "tdbInt.h"
int tdbGnrtFileID(const char *fname, uint8_t *fileid) { int tdbGnrtFileID(const char *fname, uint8_t *fileid, bool unique) {
struct stat statbuf; struct stat statbuf;
if (stat(fname, &statbuf) < 0) { if (stat(fname, &statbuf) < 0) {
...@@ -26,8 +26,27 @@ int tdbGnrtFileID(const char *fname, uint8_t *fileid) { ...@@ -26,8 +26,27 @@ int tdbGnrtFileID(const char *fname, uint8_t *fileid) {
((uint64_t *)fileid)[0] = (uint64_t)statbuf.st_ino; ((uint64_t *)fileid)[0] = (uint64_t)statbuf.st_ino;
((uint64_t *)fileid)[1] = (uint64_t)statbuf.st_dev; ((uint64_t *)fileid)[1] = (uint64_t)statbuf.st_dev;
if (unique) {
((uint64_t *)fileid)[2] = rand(); ((uint64_t *)fileid)[2] = rand();
}
return 0; 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
...@@ -119,7 +119,7 @@ int tdbMPoolFileOpen(TDB_MPFILE **mpfp, const char *fname, TDB_MPOOL *mp) { ...@@ -119,7 +119,7 @@ int tdbMPoolFileOpen(TDB_MPFILE **mpfp, const char *fname, TDB_MPOOL *mp) {
goto _err; goto _err;
} }
if (tdbGnrtFileID(fname, mpf->fileid) < 0) { if (tdbGnrtFileID(fname, mpf->fileid, false) < 0) {
goto _err; goto _err;
} }
......
...@@ -16,7 +16,6 @@ ...@@ -16,7 +16,6 @@
#ifndef _TD_TDB_INTERNAL_H_ #ifndef _TD_TDB_INTERNAL_H_
#define _TD_TDB_INTERNAL_H_ #define _TD_TDB_INTERNAL_H_
#include "os.h"
#include "tlist.h" #include "tlist.h"
#include "tlockfree.h" #include "tlockfree.h"
...@@ -64,14 +63,12 @@ static FORCE_INLINE int tdbCmprPgId(const void *p1, const void *p2) { ...@@ -64,14 +63,12 @@ static FORCE_INLINE int tdbCmprPgId(const void *p1, const void *p2) {
typedef int32_t frame_id_t; typedef int32_t frame_id_t;
// pgsize_t // pgsize_t
typedef int32_t pgsize_t;
#define TDB_MIN_PGSIZE 512 #define TDB_MIN_PGSIZE 512
#define TDB_MAX_PGSIZE 16384 #define TDB_MAX_PGSIZE 16384
#define TDB_DEFAULT_PGSIZE 4096 #define TDB_DEFAULT_PGSIZE 4096
#define TDB_IS_PGSIZE_VLD(s) (((s) >= TDB_MIN_PGSIZE) && ((s) <= TDB_MAX_PGSIZE)) #define TDB_IS_PGSIZE_VLD(s) (((s) >= TDB_MIN_PGSIZE) && ((s) <= TDB_MAX_PGSIZE))
// cache // cache
typedef int32_t cachesz_t;
#define TDB_DEFAULT_CACHE_SIZE (256 * 1024) // 256K #define TDB_DEFAULT_CACHE_SIZE (256 * 1024) // 256K
// tdb_log // tdb_log
......
...@@ -22,7 +22,12 @@ extern "C" { ...@@ -22,7 +22,12 @@ extern "C" {
#define TDB_ROUND8(x) (((x) + 7) & ~7) #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 #ifdef __cplusplus
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册