From 8284bf65d5a89b9f4139ff45482a381b893ec73b Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Mon, 28 Feb 2022 10:22:15 +0000 Subject: [PATCH] more --- source/libs/tdb/src/db/tdbPFile.c | 25 ++++++++++++++++++++++--- source/libs/tdb/src/inc/tdbPCache.h | 1 + 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/source/libs/tdb/src/db/tdbPFile.c b/source/libs/tdb/src/db/tdbPFile.c index 1e580b3262..80738e5b39 100644 --- a/source/libs/tdb/src/db/tdbPFile.c +++ b/source/libs/tdb/src/db/tdbPFile.c @@ -28,6 +28,7 @@ struct SPFile { int nDirty; SPage * pDirty; SPage * pDirtyTail; + u8 inTran; }; static int tdbPFileReadPage(SPFile *pFile, SPage *pPage); @@ -119,8 +120,23 @@ SPage *tdbPFileGet(SPFile *pFile, SPgno pgno) { } int tdbPFileWrite(SPFile *pFile, SPage *pPage) { - // TODO: if the page is not in journal, write to journal - // mark the page as dirty + int ret; + + if (pFile->inTran == 0) { + ret = tdbPFileBegin(pFile); + if (ret < 0) { + return -1; + } + + pFile->inTran; + } + + if (pPage->isDirty == 0) { + pPage->isDirty = 1; + // TODO: add the page to the dirty list + + // TODO: write the page to the journal + } return 0; } @@ -143,7 +159,10 @@ int tdbPFileAllocPage(SPFile *pFile, SPage **ppPage, SPgno *ppgno) { } int tdbPFileBegin(SPFile *pFile) { - // TODO + if (pFile->inTran) { + return 0; + } + /* TODO */ return 0; } diff --git a/source/libs/tdb/src/inc/tdbPCache.h b/source/libs/tdb/src/inc/tdbPCache.h index 84658a8aa5..7d9153b94a 100644 --- a/source/libs/tdb/src/inc/tdbPCache.h +++ b/source/libs/tdb/src/inc/tdbPCache.h @@ -30,6 +30,7 @@ struct SPage { u8 isAnchor; u8 isLocalPage; u8 isLoad; + u8 isDirty; i32 nRef; SPCache *pCache; SPage * pFreeNext; -- GitLab