From dd97a49c1a90e31dae5d47ee91e2618eb4b57eb8 Mon Sep 17 00:00:00 2001 From: danielk1977 Date: Wed, 22 Aug 2007 18:54:32 +0000 Subject: [PATCH] Fix a bug in the logic for journaling pages when the device sector-size is greater than the page size. (CVS 4270) FossilOrigin-Name: b6399dff1370449912391cc5925bdc468b5dade0 --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/pager.c | 29 ++++++++++++++++++++++++++--- 3 files changed, 34 insertions(+), 11 deletions(-) diff --git a/manifest b/manifest index 8718685b39..ceb3833f9c 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Get\sthe\squick.test\sscript\srunning\swith\sSQLITE_THREADSAFE\senabled.\s(CVS\s4269) -D 2007-08-22T11:41:18 +C Fix\sa\sbug\sin\sthe\slogic\sfor\sjournaling\spages\swhen\sthe\sdevice\ssector-size\sis\sgreater\sthan\sthe\spage\ssize.\s(CVS\s4270) +D 2007-08-22T18:54:33 F Makefile.in 0c0e53720f658c7a551046442dd7afba0b72bfbe F Makefile.linux-gcc 65241babba6faf1152bf86574477baab19190499 F README 9c4e2d6706bdcc3efdd773ce752a8cdab4f90028 @@ -115,7 +115,7 @@ F src/os_unix.c 7aad42b1ee70d68034a4ac45fa822edccdc3d9e6 F src/os_unix.h 5768d56d28240d3fe4537fac08cc85e4fb52279e F src/os_win.c 29c0e19c1072679a4c7818c49fab2f35d2ad7747 F src/os_win.h 41a946bea10f61c158ce8645e7646b29d44f122b -F src/pager.c 3568c1c557b2ff8faf054732abd32bc640116684 +F src/pager.c 029a441236e9f504e25a3e2d2944afeae48c297c F src/pager.h 53087c6fb9db01aed17c7fd044662a27507e89b8 F src/parse.y 2d2ce439dc6184621fb0b86f4fc5aca7f391a590 F src/pragma.c 9b989506a1b7c8aecd6befb8235e2f57a4aba7e5 @@ -559,7 +559,7 @@ F www/tclsqlite.tcl 8be95ee6dba05eabcd27a9d91331c803f2ce2130 F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0 F www/version3.tcl 890248cf7b70e60c383b0e84d77d5132b3ead42b F www/whentouse.tcl fc46eae081251c3c181bd79c5faef8195d7991a5 -P 581fadfe31757e3fb97b12f93c1e3c085e4b6009 -R 04edf60a36c6b67ded0e1d8395cfcdd2 -U drh -Z 751a55fa40ff7163f0ed16353fbe540e +P 1f28b7e47bba221c14a10a37e7425c9975bb2312 +R cf0de8a627c4e3c426ffb917c87f2598 +U danielk1977 +Z fbf5424b267fecb1d05194b85e3145a4 diff --git a/manifest.uuid b/manifest.uuid index 420d583237..199325d000 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -1f28b7e47bba221c14a10a37e7425c9975bb2312 \ No newline at end of file +b6399dff1370449912391cc5925bdc468b5dade0 \ No newline at end of file diff --git a/src/pager.c b/src/pager.c index 8384ed768e..b0fbcffb54 100644 --- a/src/pager.c +++ b/src/pager.c @@ -18,7 +18,7 @@ ** file simultaneously, or one process from reading the database while ** another is writing. ** -** @(#) $Id: pager.c,v 1.366 2007/08/22 11:22:04 danielk1977 Exp $ +** @(#) $Id: pager.c,v 1.367 2007/08/22 18:54:33 danielk1977 Exp $ */ #ifndef SQLITE_OMIT_DISKIO #include "sqliteInt.h" @@ -1928,7 +1928,7 @@ int sqlite3PagerOpen( return ((rc==SQLITE_OK)?SQLITE_NOMEM:rc); } - PAGERTRACE3("OPEN %d %s\n", FILEHANDLEID(fd), zFullPathname); + PAGERTRACE3("OPEN %d %s\n", FILEHANDLEID(pPager->fd), zFullPathname); IOTRACE(("OPEN %p %s\n", pPager, zFullPathname)) /* Fill in Pager.zDirectory[] */ @@ -3753,6 +3753,7 @@ static int pager_write(PgHdr *pPg){ }else{ u32 cksum, saved; char *pData2, *pEnd; + /* We should never write to the journal file the page that ** contains the database locks. The following assert verifies ** that we do not. */ @@ -3870,6 +3871,7 @@ int sqlite3PagerWrite(DbPage *pDbPage){ Pgno pg1; /* First page of the sector pPg is located on. */ int nPage; /* Number of pages starting at pg1 to journal */ int ii; + int needSync = 0; /* Set the doNotSync flag to 1. This is because we cannot allow a journal ** header to be written between the pages journaled by this function. @@ -3897,20 +3899,41 @@ int sqlite3PagerWrite(DbPage *pDbPage){ for(ii=0; iiaInJournal || pg==pPg->pgno || pg>pPager->origDbSize || !(pPager->aInJournal[pg/8]&(1<<(pg&7))) ) { if( pg!=PAGER_MJ_PGNO(pPager) ){ - PgHdr *pPage; rc = sqlite3PagerGet(pPager, pg, &pPage); if( rc==SQLITE_OK ){ rc = pager_write(pPage); + if( pPage->needSync ){ + needSync = 1; + } sqlite3PagerUnref(pPage); } } + }else if( (pPage = pager_lookup(pPager, pg)) ){ + if( pPage->needSync ){ + needSync = 1; + } } } + /* If the PgHdr.needSync flag is set for any of the nPage pages + ** starting at pg1, then it needs to be set for all of them. Because + ** writing to any of these nPage pages may damage the others, the + ** journal file must contain sync()ed copies of all of them + ** before any of them can be written out to the database file. + */ + if( needSync ){ + for(ii=0; iineedSync = 1; + } + assert(pPager->needSync); + } + assert( pPager->doNotSync==1 ); pPager->doNotSync = 0; }else{