提交 59398ee2 编写于 作者: H Hongze Cheng

commit loop work now

上级 4e6ea0d2
......@@ -29,7 +29,7 @@ TDB_STATIC_ASSERT(sizeof(SFileHdr) == 128, "Size of file header is not correct")
static int tdbPagerReadPage(SPager *pPager, SPage *pPage);
static int tdbPagerAllocPage(SPager *pPager, SPgno *ppgno);
static int tdbPagerInitPage(SPager *pPager, SPage *pPage, int (*initPage)(SPage *, void *), void *arg);
static int tdbPagerInitPage(SPager *pPager, SPage *pPage, int (*initPage)(SPage *, void *), void *arg, u8 loadPage);
static int tdbPagerWritePageToJournal(SPager *pPager, SPage *pPage);
static int tdbPagerWritePageToDB(SPager *pPager, SPage *pPage);
......@@ -249,7 +249,7 @@ int tdbPagerFetchPage(SPager *pPager, SPgno pgno, SPage **ppPage, int (*initPage
// Initialize the page if need
if (!TDB_PAGE_INITIALIZED(pPage)) {
ret = tdbPagerInitPage(pPager, pPage, initPage, arg);
ret = tdbPagerInitPage(pPager, pPage, initPage, arg, 1);
if (ret < 0) {
return -1;
}
......@@ -286,7 +286,7 @@ int tdbPagerNewPage(SPager *pPager, SPgno *ppgno, SPage **ppPage, int (*initPage
ASSERT(!TDB_PAGE_INITIALIZED(pPage));
// Initialize the page if need
ret = tdbPagerInitPage(pPager, pPage, initPage, arg);
ret = tdbPagerInitPage(pPager, pPage, initPage, arg, 0);
if (ret < 0) {
return -1;
}
......@@ -334,10 +334,11 @@ static int tdbPagerAllocPage(SPager *pPager, SPgno *ppgno) {
return 0;
}
static int tdbPagerInitPage(SPager *pPager, SPage *pPage, int (*initPage)(SPage *, void *), void *arg) {
static int tdbPagerInitPage(SPager *pPager, SPage *pPage, int (*initPage)(SPage *, void *), void *arg, u8 loadPage) {
int ret;
int lcode;
int nLoops;
i64 nRead;
lcode = TDB_TRY_LOCK_PAGE(pPage);
if (lcode == P_LOCK_SUCC) {
......@@ -346,6 +347,19 @@ static int tdbPagerInitPage(SPager *pPager, SPage *pPage, int (*initPage)(SPage
return 0;
}
if (loadPage) {
nRead = tdbOsPRead(pPager->fd, pPage->pData, pPage->pageSize, ((i64)pPage->pageSize) * TDB_PAGE_PGNO(pPage));
if (nRead < 0) {
// TODO
ASSERT(0);
return -1;
} else if (nRead < pPage->pageSize) {
// TODO
ASSERT(0);
return -1;
}
}
ret = (*initPage)(pPage, arg);
if (ret < 0) {
TDB_UNLOCK_PAGE(pPage);
......
......@@ -121,7 +121,7 @@ TEST(tdb_test, simple_test) {
int nData = 1000000;
// Open Env
ret = tdbEnvOpen("tdb", 4096, 100, &pEnv);
ret = tdbEnvOpen("tdb", 4096, 8192, &pEnv);
GTEST_ASSERT_EQ(ret, 0);
// Create a database
......@@ -137,7 +137,7 @@ TEST(tdb_test, simple_test) {
for (int i = 1; i <= nData;) {
tdbBegin(pEnv);
for (int k = 0; k < 10; k++) {
for (int k = 0; k < 2000; k++) {
sprintf(key, "key%d", i);
sprintf(val, "value%d", i);
ret = tdbDbInsert(pDb, key, strlen(key), val, strlen(val));
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册