提交 a10e0649 编写于 作者: H Hongze Cheng

refact TDB

上级 d83540ae
...@@ -26,7 +26,7 @@ typedef struct STDb TDB; ...@@ -26,7 +26,7 @@ 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 pgsz_t;
typedef int32_t cachesz_t; typedef int32_t cachesz_t;
// TEVN // TEVN
...@@ -34,9 +34,9 @@ int tdbEnvCreate(TENV **ppEnv); ...@@ -34,9 +34,9 @@ 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 tdbEnvSetPageSize(TENV *pEnv, pgsz_t szPage);
int tdbEnvSetCacheSize(TENV *pEnv, cachesz_t szCache); int tdbEnvSetCacheSize(TENV *pEnv, cachesz_t szCache);
pgsize_t tdbEnvGetPageSize(TENV *pEnv); pgsz_t tdbEnvGetPageSize(TENV *pEnv);
cachesz_t tdbEnvGetCacheSize(TENV *pEnv); cachesz_t tdbEnvGetCacheSize(TENV *pEnv);
// TDB // TDB
......
...@@ -22,8 +22,8 @@ struct SBtCursor { ...@@ -22,8 +22,8 @@ struct SBtCursor {
}; };
typedef struct { typedef struct {
pgno_t pgno; pgno_t pgno;
pgsize_t offset; pgsz_t offset;
} SBtIdx; } SBtIdx;
static int btreeCreate(SBTree **pBt); static int btreeCreate(SBTree **pBt);
......
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
static void pgCachePinPage(SPage *pPage); static void pgCachePinPage(SPage *pPage);
static void pgCacheUnpinPage(SPage *pPage); static void pgCacheUnpinPage(SPage *pPage);
int pgCacheCreate(SPgCache **ppPgCache, pgsize_t pgSize, int32_t npage) { int pgCacheCreate(SPgCache **ppPgCache, pgsz_t pgSize, int32_t npage) {
SPgCache *pPgCache; SPgCache *pPgCache;
SPage * pPage; SPage * pPage;
......
...@@ -107,7 +107,7 @@ int pgFileWrite(SPage *pPage) { ...@@ -107,7 +107,7 @@ int pgFileWrite(SPage *pPage) {
} }
static int pgFileRead(SPgFile *pPgFile, pgno_t pgno, uint8_t *pData) { static int pgFileRead(SPgFile *pPgFile, pgno_t pgno, uint8_t *pData) {
pgsize_t pgSize; pgsz_t pgSize;
ssize_t rsize; ssize_t rsize;
uint8_t *pTData; uint8_t *pTData;
size_t szToRead; size_t szToRead;
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
#include "tdbInt.h" #include "tdbInt.h"
struct STDbEnv { struct STDbEnv {
pgsize_t pgSize; // Page size pgsz_t pgSize; // Page size
cachesz_t cacheSize; // Total cache size cachesz_t cacheSize; // Total cache size
STDbList dbList; // TDB List STDbList dbList; // TDB List
SPgFileList pgfList; // SPgFile List SPgFileList pgfList; // SPgFile List
...@@ -74,7 +74,7 @@ int tdbEnvClose(TENV *pEnv) { ...@@ -74,7 +74,7 @@ int tdbEnvClose(TENV *pEnv) {
return 0; return 0;
} }
int tdbEnvSetPageSize(TENV *pEnv, pgsize_t szPage) { int tdbEnvSetPageSize(TENV *pEnv, pgsz_t szPage) {
/* TODO */ /* TODO */
pEnv->pgSize = szPage; pEnv->pgSize = szPage;
return 0; return 0;
...@@ -86,7 +86,7 @@ int tdbEnvSetCacheSize(TENV *pEnv, cachesz_t szCache) { ...@@ -86,7 +86,7 @@ int tdbEnvSetCacheSize(TENV *pEnv, cachesz_t szCache) {
return 0; return 0;
} }
pgsize_t tdbEnvGetPageSize(TENV *pEnv) { return pEnv->pgSize; } pgsz_t tdbEnvGetPageSize(TENV *pEnv) { return pEnv->pgSize; }
cachesz_t tdbEnvGetCacheSize(TENV *pEnv) { return pEnv->cacheSize; } cachesz_t tdbEnvGetCacheSize(TENV *pEnv) { return pEnv->cacheSize; }
......
...@@ -22,7 +22,7 @@ static int tdbMPoolFileReadPage(TDB_MPFILE *mpf, pgno_t pgno, void *p); ...@@ -22,7 +22,7 @@ static int tdbMPoolFileReadPage(TDB_MPFILE *mpf, pgno_t pgno, void *p);
static int tdbMPoolFileWritePage(TDB_MPFILE *mpf, pgno_t pgno, const void *p); static int tdbMPoolFileWritePage(TDB_MPFILE *mpf, pgno_t pgno, const void *p);
static void tdbMPoolClockEvictPage(TDB_MPOOL *mp, pg_t **pagepp); static void tdbMPoolClockEvictPage(TDB_MPOOL *mp, pg_t **pagepp);
int tdbMPoolOpen(TDB_MPOOL **mpp, uint64_t cachesize, pgsize_t pgsize) { int tdbMPoolOpen(TDB_MPOOL **mpp, uint64_t cachesize, pgsz_t pgsize) {
TDB_MPOOL *mp = NULL; TDB_MPOOL *mp = NULL;
size_t tsize; size_t tsize;
pg_t * pagep; pg_t * pagep;
...@@ -300,7 +300,7 @@ static void tdbMPoolUnregFile(TDB_MPOOL *mp, TDB_MPFILE *mpf) { ...@@ -300,7 +300,7 @@ static void tdbMPoolUnregFile(TDB_MPOOL *mp, TDB_MPFILE *mpf) {
} }
static int tdbMPoolFileReadPage(TDB_MPFILE *mpf, pgno_t pgno, void *p) { static int tdbMPoolFileReadPage(TDB_MPFILE *mpf, pgno_t pgno, void *p) {
pgsize_t pgsize; pgsz_t pgsize;
TDB_MPOOL *mp; TDB_MPOOL *mp;
off_t offset; off_t offset;
size_t rsize; size_t rsize;
...@@ -317,7 +317,7 @@ static int tdbMPoolFileReadPage(TDB_MPFILE *mpf, pgno_t pgno, void *p) { ...@@ -317,7 +317,7 @@ static int tdbMPoolFileReadPage(TDB_MPFILE *mpf, pgno_t pgno, void *p) {
} }
static int tdbMPoolFileWritePage(TDB_MPFILE *mpf, pgno_t pgno, const void *p) { static int tdbMPoolFileWritePage(TDB_MPFILE *mpf, pgno_t pgno, const void *p) {
pgsize_t pgsize; pgsz_t pgsize;
TDB_MPOOL *mp; TDB_MPOOL *mp;
off_t offset; off_t offset;
......
...@@ -24,7 +24,7 @@ typedef struct SPgCache SPgCache; ...@@ -24,7 +24,7 @@ typedef struct SPgCache SPgCache;
typedef struct SPage SPage; typedef struct SPage SPage;
// SPgCache // SPgCache
int pgCacheCreate(SPgCache **ppPgCache, pgsize_t pgSize, int32_t npage); int pgCacheCreate(SPgCache **ppPgCache, pgsz_t pgSize, int32_t npage);
int pgCacheDestroy(SPgCache *pPgCache); int pgCacheDestroy(SPgCache *pPgCache);
int pgCacheOpen(SPgCache **ppPgCache); int pgCacheOpen(SPgCache **ppPgCache);
int pgCacheClose(SPgCache *pPgCache); int pgCacheClose(SPgCache *pPgCache);
...@@ -46,9 +46,9 @@ struct SPage { ...@@ -46,9 +46,9 @@ struct SPage {
typedef TD_DLIST(SPage) SPgList; typedef TD_DLIST(SPage) SPgList;
struct SPgCache { struct SPgCache {
TENV * pEnv; // TENV containing this page cache TENV * pEnv; // TENV containing this page cache
SRWLatch mutex; SRWLatch mutex;
pgsize_t pgsize; pgsz_t pgsize;
int32_t npage; int32_t npage;
SPage * pages; SPage * pages;
SPgList freeList; SPgList freeList;
......
...@@ -24,7 +24,7 @@ struct SPgFile { ...@@ -24,7 +24,7 @@ struct SPgFile {
char * fname; // backend file name char * fname; // backend file name
uint8_t fileid[TDB_FILE_ID_LEN]; // file id uint8_t fileid[TDB_FILE_ID_LEN]; // file id
SPgCache *pPgCache; // page cache underline SPgCache *pPgCache; // page cache underline
pgsize_t pgSize; pgsz_t pgSize;
int fd; int fd;
pgno_t pgFileSize; pgno_t pgFileSize;
}; };
......
...@@ -64,9 +64,9 @@ static FORCE_INLINE int tdbCmprPgId(const void *p1, const void *p2) { ...@@ -64,9 +64,9 @@ static FORCE_INLINE int tdbCmprPgId(const void *p1, const void *p2) {
// framd_id_t // framd_id_t
typedef int32_t frame_id_t; typedef int32_t frame_id_t;
// pgsize_t // pgsz_t
#define TDB_MIN_PGSIZE 512 #define TDB_MIN_PGSIZE 512
#define TDB_MAX_PGSIZE 16384 #define TDB_MAX_PGSIZE 65536
#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))
......
...@@ -46,7 +46,7 @@ typedef struct { ...@@ -46,7 +46,7 @@ typedef struct {
} mpf_bucket_t; } mpf_bucket_t;
struct TDB_MPOOL { struct TDB_MPOOL {
int64_t cachesize; int64_t cachesize;
pgsize_t pgsize; pgsz_t pgsize;
int32_t npages; int32_t npages;
pg_t * pages; pg_t * pages;
pg_list_t freeList; pg_list_t freeList;
...@@ -74,7 +74,7 @@ struct TDB_MPFILE { ...@@ -74,7 +74,7 @@ struct TDB_MPFILE {
/*=================================================== Exposed apis ==================================================*/ /*=================================================== Exposed apis ==================================================*/
// TDB_MPOOL // TDB_MPOOL
int tdbMPoolOpen(TDB_MPOOL **mpp, uint64_t cachesize, pgsize_t pgsize); int tdbMPoolOpen(TDB_MPOOL **mpp, uint64_t cachesize, pgsz_t pgsize);
int tdbMPoolClose(TDB_MPOOL *mp); int tdbMPoolClose(TDB_MPOOL *mp);
int tdbMPoolSync(TDB_MPOOL *mp); int tdbMPoolSync(TDB_MPOOL *mp);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册