提交 64f29040 编写于 作者: H Hongze Cheng

more

上级 081677b2
...@@ -108,19 +108,19 @@ int tdbPagerOpenDB(SPager *pPager, SPgno *ppgno, bool toCreate) { ...@@ -108,19 +108,19 @@ int tdbPagerOpenDB(SPager *pPager, SPgno *ppgno, bool toCreate) {
pgno = 0; pgno = 0;
} }
if (pgno == 0 && toCreate) { // if (pgno == 0 && toCreate) {
ret = tdbPagerAllocPage(pPager, &pPage, &pgno); // ret = tdbPagerAllocPage(pPager, &pPage, &pgno);
if (ret < 0) { // if (ret < 0) {
return -1; // return -1;
} // }
// TODO: Need to zero the page // // TODO: Need to zero the page
ret = tdbPagerWrite(pPager, pPage); // ret = tdbPagerWrite(pPager, pPage);
if (ret < 0) { // if (ret < 0) {
return -1; // return -1;
} // }
} // }
*ppgno = pgno; *ppgno = pgno;
return 0; return 0;
...@@ -186,23 +186,23 @@ int tdbPagerWrite(SPager *pPager, SPage *pPage) { ...@@ -186,23 +186,23 @@ int tdbPagerWrite(SPager *pPager, SPage *pPage) {
return 0; return 0;
} }
int tdbPagerAllocPage(SPager *pPager, SPage **ppPage, SPgno *ppgno) { // int tdbPagerAllocPage(SPager *pPager, SPage **ppPage, SPgno *ppgno) {
SPage *pPage; // SPage *pPage;
SPgno pgno; // SPgno pgno;
if (1 /*TODO: no free page*/) { // if (1 /*TODO: no free page*/) {
pgno = ++pPager->dbFileSize; // pgno = ++pPager->dbFileSize;
pPage = tdbPagerGet(pPager, pgno, false); // pPage = tdbPagerGet(pPager, pgno, false);
ASSERT(pPage != NULL); // ASSERT(pPage != NULL);
} else { // } else {
/* TODO: allocate from the free list */ // /* TODO: allocate from the free list */
ASSERT(0); // ASSERT(0);
} // }
*ppPage = pPage; // *ppPage = pPage;
*ppgno = pgno; // *ppgno = pgno;
return 0; // return 0;
} // }
int tdbPagerBegin(SPager *pPager) { int tdbPagerBegin(SPager *pPager) {
if (pPager->inTran) { if (pPager->inTran) {
...@@ -244,17 +244,101 @@ static int tdbPagerReadPage(SPager *pPager, SPage *pPage) { ...@@ -244,17 +244,101 @@ static int tdbPagerReadPage(SPager *pPager, SPage *pPage) {
int tdbPagerGetPageSize(SPager *pPager) { return pPager->pageSize; } int tdbPagerGetPageSize(SPager *pPager) { return pPager->pageSize; }
static void tdbPagerZeroPage(SPage *pPage, int flags) { int tdbPagerFetchPage(SPager *pPager, SPgno pgno, SPage **ppPage) {
SPager *pPager; SPage *pPage;
SPgid pgid;
int ret;
// Fetch a page container from the page cache
memcpy(&pgid, pPager->fid, TDB_FILE_ID_LEN);
pgid.pgno = pgno;
pPage = tdbPCacheFetch(pPager->pCache, &pgid, 1);
if (pPage == NULL) {
return -1;
}
if (pPage->pPager == NULL) {
ASSERT(pgno < pPager->dbOrigSize);
ret = tdbPagerReadPage(pPager, pPage);
if (ret < 0) {
return -1;
}
pPager = pPage->pPager; // ret = (*initPage)(pPage);
memset(pPage->pData, 0, pPager->pageSize); // if (ret < 0) {
pPage->pPageHdr = (SPageHdr *)(pPage->pData); // return -1;
pPage->aCellIdx = (u16 *)(&(pPage->pPageHdr[1])); // }
/* TODO */
pPage->pPager = pPager;
} else {
ASSERT(pPage->pPager == pPager);
}
*ppPage = pPage;
return 0;
} }
static int tdbPagerInitPage(SPage *pPage) { int tdbPagerNewPage(SPager *pPager, SPgno *ppgno, SPage **ppPage) {
// TODO int ret;
SPage *pPage;
SPgid pgid;
// Allocate a page number
ret = tdbPagerAllocPage(pPager, ppgno);
if (ret < 0) {
return -1;
}
ASSERT(*ppgno != 0);
// Fetch a page container from the page cache
memcpy(&pgid, pPager->fid, TDB_FILE_ID_LEN);
pgid.pgno = *ppgno;
pPage = tdbPCacheFetch(pPager->pCache, &pgid, 1);
if (pPage == NULL) {
return -1;
}
ASSERT(pPage->pPager == NULL);
// TODO: zero init the new page
// (*initNewPage)(pPage, arg);
*ppPage = pPage;
return 0;
}
static int tdbPagerAllocFreePage(SPager *pPager, SPgno *ppgno) {
// TODO: Allocate a page from the free list
return 0;
}
static int tdbPagerAllocNewPage(SPager *pPager, SPgno *ppgno) {
*ppgno = ++pPager->dbFileSize;
return 0;
}
static int tdbPagerAllocPage(SPager *pPager, SPgno *ppgno) {
int ret;
*ppgno = 0;
// Try to allocate from the free list of the pager
ret = tdbPagerAllocFreePage(pPager, ppgno);
if (ret < 0) {
return -1;
}
if (*ppgno != 0) return 0;
// Allocate the page by extending the pager
ret = tdbPagerAllocNewPage(pPager, ppgno);
if (ret < 0) {
return -1;
}
ASSERT(*ppgno != 0);
return 0; return 0;
} }
\ No newline at end of file
...@@ -25,7 +25,6 @@ int tdbPagerClose(SPager *pPager); ...@@ -25,7 +25,6 @@ int tdbPagerClose(SPager *pPager);
int tdbPagerOpenDB(SPager *pPager, SPgno *ppgno, bool toCreate); int tdbPagerOpenDB(SPager *pPager, SPgno *ppgno, bool toCreate);
SPage *tdbPagerGet(SPager *pPager, SPgno pgno, bool toLoad); SPage *tdbPagerGet(SPager *pPager, SPgno pgno, bool toLoad);
int tdbPagerWrite(SPager *pPager, SPage *pPage); int tdbPagerWrite(SPager *pPager, SPage *pPage);
int tdbPagerAllocPage(SPager *pPager, SPage **ppPage, SPgno *ppgno);
int tdbPagerBegin(SPager *pPager); int tdbPagerBegin(SPager *pPager);
int tdbPagerCommit(SPager *pPager); int tdbPagerCommit(SPager *pPager);
int tdbPagerGetPageSize(SPager *pPager); int tdbPagerGetPageSize(SPager *pPager);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册