提交 6e995780 编写于 作者: H Hongze Cheng

more TDB

上级 f1e2ca50
......@@ -65,6 +65,7 @@ int tdbOpen(TDB *pDb, const char *fname, const char *dbname, TENV *pEnv) {
SBTree * pBt;
bool fileExist;
size_t dbNameLen;
pgno_t dbRootPgno;
char dbfname[128]; // TODO: make this as a macro or malloc on the heap
ASSERT(pDb != NULL);
......@@ -104,10 +105,19 @@ int tdbOpen(TDB *pDb, const char *fname, const char *dbname, TENV *pEnv) {
}
// TODO: open the database (an existing or a new one)
// Search the page file master DB to check if the db exists
// If DB exists, get the root page number
// If DB not exists, create a new DB
if (0) {
// Search the page file master DB to check if the db exists
// If exists, run this branch (TODO)
} else {
ret = pgFileAllocatePage(pPgFile, &dbRootPgno);
if (ret != 0) {
// TODO: handle error
}
}
pDb->pBt->root = dbRootPgno;
// register
pDb->pPgFile = pPgFile;
tdbEnvRgstDB(pEnv, pDb);
pDb->pEnv = pEnv;
......
......@@ -110,6 +110,19 @@ int pgFileWrite(SPage *pPage) {
return 0;
}
int pgFileAllocatePage(SPgFile *pPgFile, pgno_t *pPgno) {
pgno_t pgno;
if (0) {
// TODO: allocate from the free list
} else {
pgno = ++pPgFile->dbNewSize;
}
*pPgno = pgno;
return 0;
}
static int pgFileRead(SPgFile *pPgFile, pgno_t pgno, uint8_t *pData) {
pgsz_t pgSize;
ssize_t rsize;
......
......@@ -46,10 +46,12 @@ struct SPgFile {
int pgFileOpen(SPgFile **ppPgFile, const char *fname, TENV *pEnv);
int pgFileClose(SPgFile *pPgFile);
SPage *pgFileFetch(SPgFile *pPgFile, pgno_t pgno);
int pgFileRelease(SPage *pPage);
int pgFileWrite(SPage *pPage);
int pgFileAllocatePage(SPgFile *pPgFile, pgno_t *pPgno);
#ifdef __cplusplus
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册