From 4ac1fca01f56b39013bcab449ebd32694f936252 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Fri, 4 Mar 2022 02:46:25 +0000 Subject: [PATCH] more TDB --- source/libs/tdb/src/db/tdbBtree.c | 8 ++++---- source/libs/tdb/src/db/tdbPager.c | 14 +++++++------- source/libs/tdb/src/inc/tdbPager.h | 4 ++-- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/source/libs/tdb/src/db/tdbBtree.c b/source/libs/tdb/src/db/tdbBtree.c index 69294a1c1f..b309fce1b5 100644 --- a/source/libs/tdb/src/db/tdbBtree.c +++ b/source/libs/tdb/src/db/tdbBtree.c @@ -294,10 +294,10 @@ static int tdbBtreeOpenImpl(SBTree *pBt) { } // Try to create a new database - ret = tdbPagerNewPage(pBt->pPager, &pgno, &pPage); - if (ret < 0) { - return -1; - } + // ret = tdbPagerNewPage(pBt->pPager, &pgno, &pPage); + // if (ret < 0) { + // return -1; + // } ASSERT(pgno != 0); pBt->root = pgno; diff --git a/source/libs/tdb/src/db/tdbPager.c b/source/libs/tdb/src/db/tdbPager.c index 0a5a8abe82..5046ba2602 100644 --- a/source/libs/tdb/src/db/tdbPager.c +++ b/source/libs/tdb/src/db/tdbPager.c @@ -227,7 +227,7 @@ static int tdbPagerReadPage(SPager *pPager, SPage *pPage) { int tdbPagerGetPageSize(SPager *pPager) { return pPager->pageSize; } -int tdbPagerFetchPage(SPager *pPager, SPgno pgno, SPage **ppPage) { +int tdbPagerFetchPage(SPager *pPager, SPgno pgno, SPage **ppPage, int (*initPage)(SPage *, void *), void *arg) { SPage *pPage; SPgid pgid; int ret; @@ -251,10 +251,10 @@ int tdbPagerFetchPage(SPager *pPager, SPgno pgno, SPage **ppPage) { return -1; } - // ret = (*initPage)(pPage); - // if (ret < 0) { - // return -1; - // } + ret = (*initPage)(pPage, arg); + if (ret < 0) { + return -1; + } pPage->pPager = pPager; } @@ -268,7 +268,7 @@ int tdbPagerFetchPage(SPager *pPager, SPgno pgno, SPage **ppPage) { return 0; } -int tdbPagerNewPage(SPager *pPager, SPgno *ppgno, SPage **ppPage) { +int tdbPagerNewPage(SPager *pPager, SPgno *ppgno, SPage **ppPage, int (*initPage)(SPage *, void *), void *arg) { int ret; SPage *pPage; SPgid pgid; @@ -296,7 +296,7 @@ int tdbPagerNewPage(SPager *pPager, SPgno *ppgno, SPage **ppPage) { // tdbWLockPage(pPage); // TODO: zero init the new page - // (*initNewPage)(pPage, arg); + (*initPage)(pPage, arg); pPage->pPager = NULL; diff --git a/source/libs/tdb/src/inc/tdbPager.h b/source/libs/tdb/src/inc/tdbPager.h index a32439f30f..1122ed8e4e 100644 --- a/source/libs/tdb/src/inc/tdbPager.h +++ b/source/libs/tdb/src/inc/tdbPager.h @@ -28,8 +28,8 @@ int tdbPagerWrite(SPager *pPager, SPage *pPage); int tdbPagerBegin(SPager *pPager); int tdbPagerCommit(SPager *pPager); int tdbPagerGetPageSize(SPager *pPager); -int tdbPagerFetchPage(SPager *pPager, SPgno pgno, SPage **ppPage); -int tdbPagerNewPage(SPager *pPager, SPgno *ppgno, SPage **ppPage); +int tdbPagerFetchPage(SPager *pPager, SPgno pgno, SPage **ppPage, int (*initPage)(SPage *, void *), void *arg); +int tdbPagerNewPage(SPager *pPager, SPgno *ppgno, SPage **ppPage, int (*initPage)(SPage *, void *), void *arg); #ifdef __cplusplus } -- GitLab