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

more TDB

上级 7ca2cf2e
......@@ -26,6 +26,7 @@ int tdbDbOpen(const char *fname, int keyLen, int valLen, FKeyComparator keyCmprF
int ret;
char fFullName[TDB_FILENAME_LEN];
SPage * pPage;
SPgno pgno;
*ppDb = NULL;
......@@ -50,7 +51,12 @@ int tdbDbOpen(const char *fname, int keyLen, int valLen, FKeyComparator keyCmprF
// TODO: Search if the DB already in the file
if (1 /*todo: db should be created*/) {
ret = tdbPFileAllocPage(pFile, &pPage);
ret = tdbPFileAllocPage(pFile, &pPage, &pgno);
if (ret < 0) {
return -1;
}
ret = tdbPFileWrite(pFile, pPage);
if (ret < 0) {
return -1;
}
......
......@@ -109,14 +109,13 @@ SPage *tdbPFileGet(SPFile *pFile, SPgno pgno) {
return pPage;
}
int tdbPFileWrite(SPFile *pFile, SPage *pPage) {
// TODO: if the page is not in journal, write to journal
// mark the page as dirty
return 0;
}
int tdbPFileAllocPage(SPFile *pFile, SPage **ppPage) {
int tdbPFileAllocPage(SPFile *pFile, SPage **ppPage, SPgno *ppgno) {
SPage *pPage;
SPgno pgno;
......@@ -125,10 +124,12 @@ int tdbPFileAllocPage(SPFile *pFile, SPage **ppPage) {
pPage = tdbPFileGet(pFile, pgno);
ASSERT(pPage != NULL);
} else {
/* TODO: allocate from the free list */
ASSERT(0);
}
*ppPage = pPage;
*ppgno = pgno;
return 0;
}
......
......@@ -124,8 +124,11 @@ typedef TD_DLIST_NODE(SPgFile) SPgFileListNode;
typedef int (*FKeyComparator)(const void *pKey1, int kLen1, const void *pKey2, int kLen2);
#define TDB_JOURNAL_NAME "tdb.journal"
#define TDB_FILENAME_LEN 128
#define TDB_DEFAULT_FANOUT 6
#include "tdbUtil.h"
#include "tdbBtree.h"
......
......@@ -26,7 +26,7 @@ int tdbPFileOpen(SPCache *pCache, const char *fileName, SPFile **ppFile);
int tdbPFileClose(SPFile *pFile);
SPage *tdbPFileGet(SPFile *pFile, SPgno pgno);
int tdbPFileWrite(SPFile *pFile, SPage *pPage);
int tdbPFileAllocPage(SPFile *pFile, SPage **ppPage);
int tdbPFileAllocPage(SPFile *pFile, SPage **ppPage, SPgno *ppgno);
int tdbPFileBegin(SPFile *pFile);
int tdbPFileCommit(SPFile *pFile);
int tdbPFileRollback(SPFile *pFile);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册