more TDB
This commit is contained in:
parent
f1e2ca5074
commit
6e995780b5
|
@ -65,6 +65,7 @@ int tdbOpen(TDB *pDb, const char *fname, const char *dbname, TENV *pEnv) {
|
||||||
SBTree * pBt;
|
SBTree * pBt;
|
||||||
bool fileExist;
|
bool fileExist;
|
||||||
size_t dbNameLen;
|
size_t dbNameLen;
|
||||||
|
pgno_t dbRootPgno;
|
||||||
char dbfname[128]; // TODO: make this as a macro or malloc on the heap
|
char dbfname[128]; // TODO: make this as a macro or malloc on the heap
|
||||||
|
|
||||||
ASSERT(pDb != NULL);
|
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)
|
// TODO: open the database (an existing or a new one)
|
||||||
|
if (0) {
|
||||||
// Search the page file master DB to check if the db exists
|
// Search the page file master DB to check if the db exists
|
||||||
// If DB exists, get the root page number
|
// If exists, run this branch (TODO)
|
||||||
// If DB not exists, create a new DB
|
} else {
|
||||||
|
ret = pgFileAllocatePage(pPgFile, &dbRootPgno);
|
||||||
|
if (ret != 0) {
|
||||||
|
// TODO: handle error
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pDb->pBt->root = dbRootPgno;
|
||||||
|
|
||||||
|
// register
|
||||||
pDb->pPgFile = pPgFile;
|
pDb->pPgFile = pPgFile;
|
||||||
tdbEnvRgstDB(pEnv, pDb);
|
tdbEnvRgstDB(pEnv, pDb);
|
||||||
pDb->pEnv = pEnv;
|
pDb->pEnv = pEnv;
|
||||||
|
|
|
@ -110,6 +110,19 @@ int pgFileWrite(SPage *pPage) {
|
||||||
return 0;
|
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) {
|
static int pgFileRead(SPgFile *pPgFile, pgno_t pgno, uint8_t *pData) {
|
||||||
pgsz_t pgSize;
|
pgsz_t pgSize;
|
||||||
ssize_t rsize;
|
ssize_t rsize;
|
||||||
|
|
|
@ -46,10 +46,12 @@ struct SPgFile {
|
||||||
int pgFileOpen(SPgFile **ppPgFile, const char *fname, TENV *pEnv);
|
int pgFileOpen(SPgFile **ppPgFile, const char *fname, TENV *pEnv);
|
||||||
int pgFileClose(SPgFile *pPgFile);
|
int pgFileClose(SPgFile *pPgFile);
|
||||||
|
|
||||||
|
|
||||||
SPage *pgFileFetch(SPgFile *pPgFile, pgno_t pgno);
|
SPage *pgFileFetch(SPgFile *pPgFile, pgno_t pgno);
|
||||||
int pgFileRelease(SPage *pPage);
|
int pgFileRelease(SPage *pPage);
|
||||||
|
|
||||||
int pgFileWrite(SPage *pPage);
|
int pgFileWrite(SPage *pPage);
|
||||||
|
int pgFileAllocatePage(SPgFile *pPgFile, pgno_t *pPgno);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue