提交 4be337db 编写于 作者: H Hongze Cheng

more

上级 0c487338
...@@ -17,8 +17,6 @@ ...@@ -17,8 +17,6 @@
#define BTREE_MAX_DEPTH 20 #define BTREE_MAX_DEPTH 20
typedef int (*FKeyComparator)(const void *pKey1, int kLen1, const void *pKey2, int kLen2);
struct SBTree { struct SBTree {
SPgno root; SPgno root;
int keyLen; int keyLen;
......
...@@ -16,15 +16,24 @@ ...@@ -16,15 +16,24 @@
#include "tdbInt.h" #include "tdbInt.h"
struct STDb { struct STDb {
STEnv *pEnv; STEnv * pEnv;
/* TODO */ SBTree *pBt;
}; };
int tdbDbOpen(STDb **ppDb) { int tdbDbOpen(const char *fname, int keyLen, int valLen, FKeyComparator keyCmprFn, STEnv *pEnv, STDb **ppDb) {
STDb *pDb; STDb * pDb;
SPFile *pFile;
*ppDb = NULL; *ppDb = NULL;
/* TODO */
pDb = (STDb *)calloc(1, sizeof(*pDb));
if (pDb == NULL) {
return -1;
}
pDb->pEnv = pEnv;
*ppDb = pDb;
return 0; return 0;
} }
......
...@@ -22,10 +22,11 @@ struct STEnv { ...@@ -22,10 +22,11 @@ struct STEnv {
}; };
int tdbEnvOpen(const char *rootDir, int pageSize, int cacheSize, STEnv **ppEnv) { int tdbEnvOpen(const char *rootDir, int pageSize, int cacheSize, STEnv **ppEnv) {
STEnv * pEnv; STEnv *pEnv;
int dsize; int dsize;
int zsize; int zsize;
uint8_t *pPtr; u8 * pPtr;
int ret;
*ppEnv = NULL; *ppEnv = NULL;
...@@ -45,7 +46,12 @@ int tdbEnvOpen(const char *rootDir, int pageSize, int cacheSize, STEnv **ppEnv) ...@@ -45,7 +46,12 @@ int tdbEnvOpen(const char *rootDir, int pageSize, int cacheSize, STEnv **ppEnv)
pEnv->jfd = -1; pEnv->jfd = -1;
tdbPCacheOpen(pageSize, cacheSize, 0, &(pEnv->pCache)); ret = tdbPCacheOpen(pageSize, cacheSize, 0, &(pEnv->pCache));
if (ret < 0) {
return -1;
}
mkdir(rootDir, 0755);
*ppEnv = pEnv; *ppEnv = pEnv;
return 0; return 0;
......
...@@ -22,7 +22,7 @@ extern "C" { ...@@ -22,7 +22,7 @@ extern "C" {
typedef struct STDb STDb; typedef struct STDb STDb;
int tdbDbOpen(STDb **ppDb); int tdbDbOpen(const char *fname, int keyLen, int valLen, FKeyComparator keyCmprFn, STEnv *pEnv, STDb **ppDb);
int tdbDbClose(STDb *pDb); int tdbDbClose(STDb *pDb);
int tdbDbInsert(STDb *pDb, const void *pKey, int keyLen, const void *pVal, int valLen); int tdbDbInsert(STDb *pDb, const void *pKey, int keyLen, const void *pVal, int valLen);
......
...@@ -121,6 +121,8 @@ typedef TD_DLIST_NODE(SPgFile) SPgFileListNode; ...@@ -121,6 +121,8 @@ typedef TD_DLIST_NODE(SPgFile) SPgFileListNode;
/* TODO */ \ /* TODO */ \
} while (0) } while (0)
typedef int (*FKeyComparator)(const void *pKey1, int kLen1, const void *pKey2, int kLen2);
#define TDB_JOURNAL_NAME "tdb.journal" #define TDB_JOURNAL_NAME "tdb.journal"
#include "tdbUtil.h" #include "tdbUtil.h"
......
...@@ -5,14 +5,14 @@ ...@@ -5,14 +5,14 @@
TEST(tdb_test, simple_test) { TEST(tdb_test, simple_test) {
int ret; int ret;
STEnv *pEnv; STEnv *pEnv;
STDb *pDb; STDb * pDb;
// Open Env // Open Env
ret = tdbEnvOpen("tdb", 1024, 20, &pEnv); ret = tdbEnvOpen("tdb", 1024, 20, &pEnv);
GTEST_ASSERT_EQ(ret, 0); GTEST_ASSERT_EQ(ret, 0);
// Create a database // Create a database
ret = tdbDbOpen(&pDb); ret = tdbDbOpen("db.db", TDB_VARIANT_LEN, TDB_VARIANT_LEN, NULL, pEnv, &pDb);
GTEST_ASSERT_EQ(ret, 0); GTEST_ASSERT_EQ(ret, 0);
// Insert some data // Insert some data
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册