diff --git a/source/libs/tdb/src/db/tdbBtree.c b/source/libs/tdb/src/db/tdbBtree.c index 16828808fc..f2003c5844 100644 --- a/source/libs/tdb/src/db/tdbBtree.c +++ b/source/libs/tdb/src/db/tdbBtree.c @@ -284,7 +284,7 @@ static int tdbBtreeOpenImpl(SBTree *pBt) { int ret; { - // TODO: Search the main DB to check if the DB exists + // 1. TODO: Search the main DB to check if the DB exists pgno = 0; } @@ -294,13 +294,16 @@ static int tdbBtreeOpenImpl(SBTree *pBt) { } // Try to create a new database - // ret = tdbPagerNewPage(pBt->pPager, &pgno, &pPage); - // if (ret < 0) { - // return -1; - // } + SBtreeZeroPageArg zArg = {.flags = TDB_BTREE_ROOT | TDB_BTREE_LEAF, .pBt = pBt}; + ret = tdbPagerNewPage(pBt->pPager, &pgno, &pPage, tdbBtreeZeroPage, &zArg); + if (ret < 0) { + return -1; + } - // ASSERT(pgno != 0); - // pBt->root = pgno; + // TODO: Unref the page + + ASSERT(pgno != 0); + pBt->root = pgno; return 0; } diff --git a/source/libs/tdb/src/db/tdbPCache.c b/source/libs/tdb/src/db/tdbPCache.c index d86442a8d7..b206fb8e90 100644 --- a/source/libs/tdb/src/db/tdbPCache.c +++ b/source/libs/tdb/src/db/tdbPCache.c @@ -235,6 +235,7 @@ static int tdbPCacheOpenImpl(SPCache *pCache) { } pPage = (SPage *)(&(pPtr[pCache->pageSize])); + TDB_INIT_PAGE_LOCK(pPage); pPage->pData = (void *)pPtr; // pPage->pgid = 0; pPage->isAnchor = 0;