more TDB
This commit is contained in:
parent
59e7f147c3
commit
b4a2bed4dd
|
@ -25,6 +25,7 @@ int tdbDbOpen(const char *fname, int keyLen, int valLen, FKeyComparator keyCmprF
|
||||||
SPFile *pFile;
|
SPFile *pFile;
|
||||||
int ret;
|
int ret;
|
||||||
char fFullName[TDB_FILENAME_LEN];
|
char fFullName[TDB_FILENAME_LEN];
|
||||||
|
SPage * pPage;
|
||||||
|
|
||||||
*ppDb = NULL;
|
*ppDb = NULL;
|
||||||
|
|
||||||
|
@ -45,6 +46,16 @@ int tdbDbOpen(const char *fname, int keyLen, int valLen, FKeyComparator keyCmprF
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ASSERT(pFile != NULL);
|
||||||
|
|
||||||
|
// TODO: Search if the DB already in the file
|
||||||
|
if (1 /*todo: db should be created*/) {
|
||||||
|
ret = tdbPFileAllocPage(pFile, &pPage);
|
||||||
|
if (ret < 0) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// pDb->pBt
|
// pDb->pBt
|
||||||
ret = tdbBtreeOpen(&(pDb->pBt));
|
ret = tdbBtreeOpen(&(pDb->pBt));
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
|
|
|
@ -103,7 +103,7 @@ SPage *tdbPFileGet(SPFile *pFile, SPgno pgno) {
|
||||||
ASSERT(pPage->isLoad);
|
ASSERT(pPage->isLoad);
|
||||||
|
|
||||||
return pPage;
|
return pPage;
|
||||||
}
|
|
||||||
|
|
||||||
int tdbPFileWrite(SPFile *pFile, SPage *pPage) {
|
int tdbPFileWrite(SPFile *pFile, SPage *pPage) {
|
||||||
// TODO: if the page is not in journal, write to journal
|
// TODO: if the page is not in journal, write to journal
|
||||||
|
@ -112,8 +112,18 @@ int tdbPFileWrite(SPFile *pFile, SPage *pPage) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int tdbPFileAllocPage(SPFile *pFile, SPage **ppPage) {
|
int tdbPFileAllocPage(SPFile *pFile, SPage **ppPage) {
|
||||||
// TODO
|
SPage *pPage;
|
||||||
*ppPage = NULL;
|
SPgno pgno;
|
||||||
|
|
||||||
|
if (1 /*TODO: no free page*/) {
|
||||||
|
pgno = ++pFile->dbFileSize;
|
||||||
|
pPage = tdbPFileGet(pFile, pgno);
|
||||||
|
ASSERT(pPage != NULL);
|
||||||
|
} else {
|
||||||
|
ASSERT(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
*ppPage = pPage;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue