提交 7c939b92 编写于 作者: H Hongze Cheng

more TDB

上级 e835a6cc
set(META_DB_IMPL_LIST "BDB" "TDB")
set(META_DB_IMPL "TDB" CACHE STRING "Use BDB as the default META implementation")
set(META_DB_IMPL "BDB" CACHE STRING "Use BDB as the default META implementation")
set_property(CACHE META_DB_IMPL PROPERTY STRINGS ${META_DB_IMPL_LIST})
if(META_DB_IMPL IN_LIST META_DB_IMPL_LIST)
......
......@@ -30,15 +30,14 @@ typedef int32_t pgsz_t;
typedef int32_t cachesz_t;
// TEVN
int tdbEnvCreate(TENV **ppEnv);
int tdbEnvOpen(TENV **ppEnv);
int tdbEnvCreate(TENV **ppEnv, const char *rootDir);
int tdbEnvOpen(TENV *ppEnv);
int tdbEnvClose(TENV *pEnv);
int tdbEnvBeginTxn(TENV *pEnv);
int tdbEnvCommit(TENV *pEnv);
int tdbEnvSetPageSize(TENV *pEnv, pgsz_t szPage);
int tdbEnvSetCacheSize(TENV *pEnv, cachesz_t szCache);
int tdbEnvSetCache(TENV *pEnv, pgsz_t pgSize, cachesz_t cacheSize);
pgsz_t tdbEnvGetPageSize(TENV *pEnv);
cachesz_t tdbEnvGetCacheSize(TENV *pEnv);
......
......@@ -64,9 +64,9 @@ int tdbOpen(TDB **ppDb, const char *fname, const char *dbname, TENV *pEnv) {
// Create a default ENV if pEnv is not set
if (pEnv == NULL) {
if ((ret = tdbEnvOpen(&pEnv)) != 0) {
return -1;
}
// if ((ret = tdbEnvOpen(&pEnv)) != 0) {
// return -1;
// }
}
pDb->pEnv = pEnv;
......
......@@ -16,8 +16,9 @@
#include "tdbInt.h"
struct STDbEnv {
pgsz_t pgSize; // Page size
cachesz_t cacheSize; // Total cache size
char * rootDir; // root directory of the environment
pgsz_t pgSize; // page size
cachesz_t cacheSize; // total cache size
STDbList dbList; // TDB List
SPgFileList pgfList; // SPgFile List
SPgCache * pPgCache; // page cache
......@@ -28,34 +29,39 @@ struct STDbEnv {
static int tdbEnvDestroy(TENV *pEnv);
int tdbEnvCreate(TENV **ppEnv) {
TENV *pEnv;
int tdbEnvCreate(TENV **ppEnv, const char *rootDir) {
TENV * pEnv;
size_t slen;
pEnv = (TENV *)calloc(1, sizeof(*pEnv));
ASSERT(rootDir != NULL);
*ppEnv = NULL;
slen = strlen(rootDir);
pEnv = (TENV *)calloc(1, sizeof(*pEnv) + slen + 1);
if (pEnv == NULL) {
return -1;
}
pEnv->rootDir = (char *)(&pEnv[1]);
pEnv->pgSize = TDB_DEFAULT_PGSIZE;
pEnv->cacheSize = TDB_DEFAULT_CACHE_SIZE;
memcpy(pEnv->rootDir, rootDir, slen);
TD_DLIST_INIT(&(pEnv->dbList));
TD_DLIST_INIT(&(pEnv->pgfList));
// TODO
/* TODO */
*ppEnv = pEnv;
return 0;
}
int tdbEnvOpen(TENV **ppEnv) {
TENV * pEnv;
int tdbEnvOpen(TENV *pEnv) {
SPgCache *pPgCache;
int ret;
// Create the ENV with default setting
if (ppEnv == NULL) {
TERR_A(ret, tdbEnvCreate(&pEnv), _err);
}
pEnv = *ppEnv;
ASSERT(pEnv != NULL);
TERR_A(ret, pgCacheCreate(&pPgCache, pEnv->pgSize, pEnv->cacheSize / pEnv->pgSize), _err);
TERR_A(ret, pgCacheOpen(&pPgCache), _err);
......@@ -75,15 +81,16 @@ int tdbEnvClose(TENV *pEnv) {
return 0;
}
int tdbEnvSetPageSize(TENV *pEnv, pgsz_t szPage) {
/* TODO */
pEnv->pgSize = szPage;
return 0;
}
int tdbEnvSetCache(TENV *pEnv, pgsz_t pgSize, cachesz_t cacheSize) {
if (!TDB_IS_PGSIZE_VLD(pgSize) || cacheSize / pgSize < 10) {
return -1;
}
int tdbEnvSetCacheSize(TENV *pEnv, cachesz_t szCache) {
/* TODO */
pEnv->cacheSize = szCache;
pEnv->pgSize = pgSize;
pEnv->cacheSize = cacheSize;
return 0;
}
......
......@@ -74,7 +74,7 @@ typedef int32_t frame_id_t;
typedef pgsz_t pgoff_t;
// cache
#define TDB_DEFAULT_CACHE_SIZE (256 * 1024) // 256K
#define TDB_DEFAULT_CACHE_SIZE (256 * 4096) // 1M
// tdb_log
#define tdbError(var)
......
......@@ -2,21 +2,28 @@
#include "tdb.h"
#define A_ASSERT(op) GTEST_ASSERT_EQ(op, 0)
TEST(tdb_test, simple_test) {
TENV *pEnv;
TDB * pDb1, *pDb2;
TENV* pEnv;
TDB * pDb1, *pDb2, *pDb3;
pgsz_t pgSize = 1024;
cachesz_t cacheSize = 10240;
// ENV
tdbEnvCreate(&pEnv);
tdbEnvSetPageSize(pEnv, 1024);
tdbEnvSetCacheSize(pEnv, 10240);
tdbEnvOpen(&pEnv);
GTEST_ASSERT_EQ(tdbEnvCreate(&pEnv, "./tdbtest"), 0);
GTEST_ASSERT_EQ(tdbEnvSetCache(pEnv, pgSize, cacheSize), 0);
GTEST_ASSERT_EQ(tdbEnvGetCacheSize(pEnv), cacheSize);
GTEST_ASSERT_EQ(tdbEnvGetPageSize(pEnv), pgSize);
GTEST_ASSERT_EQ(tdbEnvOpen(pEnv), 0);
#if 0
// DB
tdbOpen(&pDb1, "db.db", "db1", pEnv);
tdbOpen(&pDb2, "db.db", "db2", pEnv);
tdbOpen(&pDb3, "index.db", NULL, pEnv);
// Insert
......@@ -29,5 +36,6 @@ TEST(tdb_test, simple_test) {
// Close
tdbClose(pDb1);
tdbClose(pDb2);
#endif
tdbEnvClose(pEnv);
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册