diff --git a/manifest b/manifest index 3c10bc3c41..26366f9ee3 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\sassert()\sstatements\sto\smore\stightly\sconstrain\sthe\sstate\sof\spager.c.\nRemove\sthe\sthree\spager*.test\sscripts\ssince\sthey\sviolate\sthe\sconstraints\nasserted\sabove\sby\smodifying\sthe\sstate\sof\sthe\ssystem\sin\sways\sthat\sit\scannot\nbe\smodified\sin\sa\slive\ssystem.\s(CVS\s6933) -D 2009-07-25T04:12:02 +C Add\sa\scomplex\sassert()\sthat\schecks\sa\spager\sinvariant.\s(CVS\s6934) +D 2009-07-25T11:40:08 F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0 F Makefile.in df9359da7a726ccb67a45db905c5447d5c00c6ef F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654 @@ -147,7 +147,7 @@ F src/os_common.h 8c61457df58f1a4bd5f5adc3e90e01b37bf7afbc F src/os_os2.c bed77dc26e3a95ce4a204936b9a1ca6fe612fcc5 F src/os_unix.c cdb2a08b9ce4aa13b3f7b91d4dd60fb48be9f56a F src/os_win.c 725c38a524d168ce280446ad8761d731bc516405 -F src/pager.c e26d9c5d881435b83551a07cd7e38396518582bc +F src/pager.c 2ccb1152741996d3f6125232f14dfcf654bdd29f F src/pager.h 11852d044c86cf5a9d6e34171fb0c4fcf1f6265f F src/parse.y bcd46d43fbd23a22b8c020a3eb1806b794794ed5 F src/pcache.c 1dae135b70a029f81ed66f6e9b5d0db91480d5d0 @@ -738,7 +738,7 @@ F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224 F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e F tool/vdbe-compress.tcl 672f81d693a03f80f5ae60bfefacd8a349e76746 -P 788aa9dde9e76f67f22c07a904faf03e97e032c6 -R 4116dfd49c9a3af1d9a66719263f82dc -U drh -Z 51e179b626e42eaf6ce7a289270b3c19 +P 3b6d370ed68eaf9636b26c7240a8b3a43d2edd70 +R 6427dd1fa4bac8adebaeed3a85e8f4b9 +U danielk1977 +Z ea5eb9c594b637c9c13eaf08f55c7f0a diff --git a/manifest.uuid b/manifest.uuid index 2b5cda4c4a..5251103dbf 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -3b6d370ed68eaf9636b26c7240a8b3a43d2edd70 \ No newline at end of file +2e08ad7bf629485a79ccebcf4c413e9dcc0d3ccf \ No newline at end of file diff --git a/src/pager.c b/src/pager.c index 7998b6bd5f..397d4886a0 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.620 2009/07/25 04:12:02 drh Exp $ +** @(#) $Id: pager.c,v 1.621 2009/07/25 11:40:08 danielk1977 Exp $ */ #ifndef SQLITE_OMIT_DISKIO #include "sqliteInt.h" @@ -2625,6 +2625,40 @@ static int pager_wait_on_lock(Pager *pPager, int locktype){ return rc; } +/* +** Function assertTruncateConstraint(pPager) checks that one of the +** following is true for all dirty pages currently in the page-cache: +** +** a) The page number is less than or equal to the size of the +** current database image, in pages, OR +** +** b) if the page content were written at this time, it would not +** be necessary to write the current content out to the sub-journal +** (as determined by function subjRequiresPage()). +** +** If the condition asserted by this function were not true, and the +** dirty page were to be discarded from the cache via the pagerStress() +** routine, pagerStress() would not write the current page content to +** the database file. If a savepoint transaction were rolled back after +** this happened, the correct behaviour would be to restore the current +** content of the page. However, since this content is not present in either +** the database file or the portion of the rollback journal and +** sub-journal rolled back the content could not be restored and the +** database image would become corrupt. It is therefore fortunate that +** this circumstance cannot arise. +*/ +#if defined(SQLITE_DEBUG) +static void assertTruncateConstraintCb(PgHdr *pPg){ + assert( pPg->flags&PGHDR_DIRTY ); + assert( !subjRequiresPage(pPg) || pPg->pgno<=pPg->pPager->dbSize ); +} +static void assertTruncateConstraint(Pager *pPager){ + sqlite3PcacheIterateDirty(pPager->pPCache, assertTruncateConstraintCb); +} +#else +# define assertTruncateConstraint(pPager) +#endif + /* ** Truncate the in-memory database file image to nPage pages. This ** function does not actually modify the database file on disk. It @@ -2636,6 +2670,7 @@ void sqlite3PagerTruncateImage(Pager *pPager, Pgno nPage){ assert( pPager->dbSize>=nPage ); assert( pPager->state>=PAGER_RESERVED ); pPager->dbSize = nPage; + assertTruncateConstraint(pPager); } /* @@ -4963,6 +4998,7 @@ int sqlite3PagerOpenSavepoint(Pager *pPager, int nSavepoint){ /* Open the sub-journal, if it is not already opened. */ rc = openSubJournal(pPager); + assertTruncateConstraint(pPager); } return rc;