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

more TDB

上级 5dca9744
......@@ -16,23 +16,53 @@
#include "tdbInt.h"
struct STDbEnv {
TDB * dbList; // TDB list
SPgFile *pgFileList; // SPgFile list
pgsize_t pgSize; // Page size
cachesz_t cacheSize; // Total cache size
STDbList dbList; // TDB List
SPgFileList pgfList; // SPgFile List
SPgCache * pPgCache; // page cache
struct {
} pgfht; // page file hash table;
SPgCache pgc; // page cache
} pgfht; // page file hash table;
};
static int tdbEnvDestroy(TENV *pEnv);
int tdbEnvCreate(TENV **ppEnv) {
TENV *pEnv;
pEnv = (TENV *)calloc(1, sizeof(*pEnv));
if (pEnv == NULL) {
return -1;
}
pEnv->pgSize = TDB_DEFAULT_PGSIZE;
pEnv->cacheSize = TDB_DEFAULT_CACHE_SIZE;
TD_DLIST_INIT(&(pEnv->dbList));
TD_DLIST_INIT(&(pEnv->pgfList));
// TODO
return 0;
}
int tdbEnvOpen(TENV **ppEnv) {
// TODO
TENV * pEnv;
SPgCache *pPgCache;
int ret;
// Create the ENV with default setting
if (ppEnv == NULL) {
TERR_A(ret, tdbEnvCreate(&pEnv), _err);
}
pEnv = *ppEnv;
TERR_A(ret, pgCacheCreate(&pPgCache, pEnv->pgSize, pEnv->cacheSize / pEnv->pgSize), _err);
pEnv->pPgCache = pPgCache;
return 0;
_err:
return -1;
}
int tdbEnvClose(TENV *pEnv) {
......@@ -47,7 +77,7 @@ SPgFile *tdbEnvGetPageFile(TENV *pEnv, const uint8_t fileid[]) {
return NULL;
}
SPgCache *tdbEnvGetPgCache(TENV *pEnv) { return &(pEnv->pgc); }
SPgCache *tdbEnvGetPgCache(TENV *pEnv) { return pEnv->pPgCache; }
static int tdbEnvDestroy(TENV *pEnv) {
// TODO
......
......@@ -71,11 +71,29 @@ typedef int32_t pgsize_t;
#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
#define tdbError(var)
typedef TD_DLIST(STDb) STDbList;
typedef TD_DLIST(SPgFile) SPgFileList;
#define TERR_A(val, op, flag) \
do { \
if (((val) = (op)) != 0) { \
goto flag; \
} \
} while (0)
#define TERR_B(val, op, flag) \
do { \
if (((val) = (op)) == NULL) { \
goto flag; \
} \
} while (0)
#include "btree.h"
#include "pgcache.h"
#include "pgfile.h"
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册