1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-08-07 02:42:48 +03:00

When rolling back page 1 from a journal, restore the "nReserve" setting

in case it has been corrupted by a prior crash.

FossilOrigin-Name: c0d124da88e84e68679c2f3f4b2b35c03aecc916
This commit is contained in:
drh
2010-07-05 17:43:32 +00:00
parent 92d516a221
commit 8220da7b8b
3 changed files with 43 additions and 33 deletions

View File

@@ -1517,6 +1517,21 @@ static u32 pager_cksum(Pager *pPager, const u8 *aData){
return cksum;
}
/*
** Report the current page size and number of reserved bytes back
** to the codec.
*/
#ifdef SQLITE_HAS_CODEC
static void pagerReportSize(Pager *pPager){
if( pPager->xCodecSizeChng ){
pPager->xCodecSizeChng(pPager->pCodec, pPager->pageSize,
(int)pPager->nReserve);
}
}
#else
# define pagerReportSize(X) /* No-op if we do not support a codec */
#endif
/*
** Read a single page from either the journal file (if isMainJrnl==1) or
** from the sub-journal (if isMainJrnl==0) and playback that page.
@@ -1609,12 +1624,21 @@ static int pager_playback_one_page(
}
}
/* If this page has already been played by before during the current
** rollback, then don't bother to play it back again.
*/
if( pDone && (rc = sqlite3BitvecSet(pDone, pgno))!=SQLITE_OK ){
return rc;
}
assert( pPager->state==PAGER_RESERVED || pPager->state>=PAGER_EXCLUSIVE );
/* When playing back page 1, restore the nReserve setting
*/
if( pgno==1 && pPager->nReserve!=((u8*)aData)[20] ){
pPager->nReserve = ((u8*)aData)[20];
pagerReportSize(pPager);
}
/* If the pager is in RESERVED state, then there must be a copy of this
** page in the pager cache. In this case just update the pager cache,
** not the database file. The page is left marked dirty in this case.
@@ -2751,21 +2775,6 @@ void sqlite3PagerSetBusyhandler(
pPager->pBusyHandlerArg = pBusyHandlerArg;
}
/*
** Report the current page size and number of reserved bytes back
** to the codec.
*/
#ifdef SQLITE_HAS_CODEC
static void pagerReportSize(Pager *pPager){
if( pPager->xCodecSizeChng ){
pPager->xCodecSizeChng(pPager->pCodec, pPager->pageSize,
(int)pPager->nReserve);
}
}
#else
# define pagerReportSize(X) /* No-op if we do not support a codec */
#endif
/*
** Change the page size used by the Pager object. The new page size
** is passed in *pPageSize.
@@ -2905,15 +2914,6 @@ int sqlite3PagerReadFileheader(Pager *pPager, int N, unsigned char *pDest){
** to WAL mode yet.
*/
assert( !pagerUseWal(pPager) );
#if 0
if( pagerUseWal(pPager) ){
int isInWal = 0;
rc = sqlite3WalRead(pPager->pWal, 1, &isInWal, N, pDest);
if( rc!=SQLITE_OK || isInWal ){
return rc;
}
}
#endif
if( isOpen(pPager->fd) ){
IOTRACE(("DBHDR %p 0 %d\n", pPager, N))